forked from doomemacs/themes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdoom-themes.el
244 lines (214 loc) · 8.9 KB
/
doom-themes.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
;;; doom-themes.el --- an opinionated pack of modern color-themes -*- lexical-binding: t; -*-
;;
;; Copyright (C) 2016-2018 Henrik Lissner
;;
;; Author: Henrik Lissner <http://github/hlissner>
;; Maintainer: Henrik Lissner <[email protected]>
;; Created: May 22, 2016
;; Modified: March 01, 2018
;; Version: 2.1.1
;; Keywords: dark light blue atom one theme neotree icons faces nova
;; Homepage: https://github.com./hlissner/emacs-doom-theme
;; Package-Requires: ((emacs "24.4") (all-the-icons "1.0.0") (cl-lib "0.5"))
;;
;; This file is not part of GNU Emacs.
;;
;;; Commentary:
;;
;; DOOM Themes is an opinionated UI plugin and pack of themes extracted from my
;; [emacs.d], inspired by some of my favorite color themes including:
;;
;; [X] `doom-one': inspired by Atom's One Dark themes
;; [X] `doom-vibrant': a more vibrant version of `doom-one`
;; [X] `doom-molokai': based on Textmate's monokai
;; [X] `doom-nova': adapted from Nova (thanks to bigardone)
;; [X] `doom-one-light': light version of doom-one
;; [X] `doom-peacock': based on Peacock from daylerees' themes (thanks to teesloane)
;; [X] `doom-tomorrow-night': by Chris Kempson
;; [X] `doom-spacegrey': I'm sure you've heard of it (thanks to teesloane)
;; [X] `doom-solarized-light': light variant of Solarized (thanks to fuxialexander)
;; [ ] `doom-tomorrow-day': by Chris Kempson
;; [ ] `doom-x': reads your colors from ~/.Xresources
;; [ ] `doom-mono-dark' / `doom-mono-light': a minimalistic, monochromatic theme
;; [ ] `doom-tron': based on Tron Legacy from daylerees' themes
;;
;; ## Install
;;
;; `M-x package-install RET doom-themes`
;;
;; A comprehensive configuration example:
;;
;; (require 'doom-themes)
;;
;; ;; Global settings (defaults)
;; (setq doom-themes-enable-bold t ; if nil, bold is universally disabled
;; doom-themes-enable-italic t) ; if nil, italics is universally disabled
;;
;; ;; Load the theme (doom-one, doom-molokai, etc); keep in mind that each
;; ;; theme may have their own settings.
;; (load-theme 'doom-one t)
;;
;; ;; Enable flashing mode-line on errors
;; (doom-themes-visual-bell-config)
;;
;; ;; Enable custom neotree theme
;; (doom-themes-neotree-config) ; all-the-icons fonts must be installed!
;;
;;; Code:
(require 'cl-lib)
(require 'doom-themes-common)
(defgroup doom-themes nil
"Options for doom-themes."
:group 'faces)
(defface doom-modeline-error '((t (:inherit error :inverse-video t)))
"Face to use for the mode-line when `doom-themes-visual-bell-config' is used."
:group 'doom-themes)
;;
(defcustom doom-themes-enable-bold t
"If nil, bold will be disabled across all faces."
:group 'doom-themes
:type 'boolean)
(defcustom doom-themes-enable-italic t
"If nil, italics will be disabled across all faces."
:group 'doom-themes
:type 'boolean)
(define-obsolete-variable-alias 'doom-enable-italic 'doom-themes-enable-italic "1.2.9")
(define-obsolete-variable-alias 'doom-enable-bold 'doom-themes-enable-bold "1.2.9")
(defvar doom-themes--colors nil)
(defvar doom-themes--inhibit-warning nil)
(defvar doom-themes--bell-p nil)
;; Color helper functions
;; Shamelessly *borrowed* from solarized
(defun doom-name-to-rgb (color &optional frame)
"Retrieves the hexidecimal string repesented the named COLOR (e.g. \"red\")
for FRAME (defaults to the current frame)."
(cl-loop for x in (color-values color frame)
collect (/ x (float (car (color-values "#ffffff"))))))
(defun doom-blend (color1 color2 alpha)
"Blend two colors (hexidecimal strings) together by a coefficient ALPHA (a
float between 0 and 1)"
(when (and color1 color2)
(cond ((and color1 color2 (symbolp color1) (symbolp color2))
(doom-blend (doom-color color1) (doom-color color2) alpha))
((or (listp color1) (listp color2))
(cl-loop for x in color1
when (if (listp color2) (pop color2) color2)
collect (doom-blend x it alpha)))
((and (string-prefix-p "#" color1) (string-prefix-p "#" color2))
(apply (lambda (r g b) (format "#%02x%02x%02x" (* r 255) (* g 255) (* b 255)))
(cl-loop for it in (doom-name-to-rgb color1)
for other in (doom-name-to-rgb color2)
collect (+ (* alpha it) (* other (- 1 alpha))))))
(t color1))))
(defun doom-darken (color alpha)
"Darken a COLOR (a hexidecimal string) by a coefficient ALPHA (a float between
0 and 1)."
(cond ((and color (symbolp color))
(doom-darken (doom-color color) alpha))
((listp color)
(cl-loop for c in color collect (doom-darken c alpha)))
(t
(doom-blend color "#000000" (- 1 alpha)))))
(defun doom-lighten (color alpha)
"Brighten a COLOR (a hexidecimal string) by a coefficient ALPHA (a float
between 0 and 1)."
(cond ((and color (symbolp color))
(doom-lighten (doom-color color) alpha))
((listp color)
(cl-loop for c in color collect (doom-lighten c alpha)))
(t
(doom-blend color "#FFFFFF" (- 1 alpha)))))
;;;###autoload
(defun doom-color (name &optional type)
"Retrieve a specific color named NAME (a symbol) from the current theme."
(let ((colors (if (listp name)
name
(cdr-safe (assq name doom-themes--colors)))))
(and colors
(cond ((listp colors)
(let ((i (or (plist-get '(256 1 16 2 8 3) type) 0)))
(if (> i (1- (length colors)))
(car (last colors))
(nth i colors))))
(t colors)))))
;;;###autoload
(defun doom-ref (face prop &optional class)
"TODO"
(let ((spec (or (cdr (assq face doom-themes--faces))
(error "Couldn't find the '%s' face" face))))
(when (memq (car spec) '(quote backquote \`))
(user-error "Can't fetch the literal spec for '%s'" face))
(when class
(setq spec (cdr (assq class spec)))
(unless spec
(error "Couldn't find the '%s' class in the '%s' face"
class face)))
(unless (plist-member spec prop)
(error "Couldn't find the '%s' property in the '%s' face%s"
prop face (if class (format "'s '%s' class" class) "")))
(plist-get spec prop)))
;;;###autoload
(defmacro doom-themes-set-faces (theme &rest faces)
"Customize THEME (a symbol) with FACES."
(declare (indent defun))
`(custom-theme-set-faces
,theme
,@(mapcar #'doom-themes--build-face faces)))
(defmacro def-doom-theme (name docstring defs &optional extra-faces extra-vars)
"Define a DOOM theme, named NAME (a symbol)."
(declare (doc-string 2))
(let ((doom-themes--colors defs))
`(let* ((bold doom-themes-enable-bold)
(italic doom-themes-enable-italic)
,@defs)
(setq doom-themes--colors
(cl-loop for (var val) in ',defs
collect (cons var (eval val))))
(deftheme ,name ,docstring)
(custom-theme-set-faces ',name ,@(doom-themes-common-faces extra-faces))
(custom-theme-set-variables ',name ,@(doom-themes-common-variables extra-vars))
(provide-theme ',name))))
;;;###autoload
(defun doom-themes-org-config ()
"Enable custom fontification and improves doom-themes integration with org-mode."
(require 'doom-themes-org))
;;;###autoload
(defun doom-themes-neotree-config ()
"Install doom-themes' neotree configuration.
Includes an Atom-esque icon theme and highlighting based on filetype."
(let ((doom-themes--inhibit-warning t))
(require 'doom-themes-neotree)))
;;;###autoload
(defun doom-themes-visual-bell-config ()
"Enable flashing the mode-line on error."
(setq ring-bell-function #'doom-themes-visual-bell-fn
visible-bell t))
;;;###autoload
(defun doom-themes-visual-bell-fn ()
"Blink the mode-line red briefly. Set `ring-bell-function' to this to use it."
(unless doom-themes--bell-p
(let ((old-remap (copy-alist face-remapping-alist)))
(setq doom-themes--bell-p t)
(setq face-remapping-alist
(append (delete (assq 'mode-line face-remapping-alist)
face-remapping-alist)
'((mode-line doom-modeline-error))))
(force-mode-line-update)
(run-with-timer 0.15 nil
(lambda (remap buf)
(with-current-buffer buf
(when (assq 'mode-line face-remapping-alist)
(setq face-remapping-alist remap
doom-themes--bell-p nil))
(force-mode-line-update)))
old-remap
(current-buffer)))))
;;;###autoload
(when (and (boundp 'custom-theme-load-path) load-file-name)
(let* ((base (file-name-directory load-file-name))
(dir (expand-file-name "themes/" base)))
(add-to-list 'custom-theme-load-path
(or (and (file-directory-p dir) dir)
base))))
(provide 'doom-themes)
;;; doom-themes.el ends here