2022-07-30 21:49:00 +02:00
|
|
|
;;; lisp/lib/themes.el -*- lexical-binding: t; -*-
|
2019-07-23 14:31:00 +02:00
|
|
|
|
2021-05-06 15:54:10 -04:00
|
|
|
;;;###autoload
|
|
|
|
(defconst doom-customize-theme-hook nil)
|
|
|
|
|
|
|
|
(add-hook! 'doom-load-theme-hook
|
|
|
|
(defun doom-apply-customized-faces-h ()
|
|
|
|
"Run `doom-customize-theme-hook'."
|
|
|
|
(run-hooks 'doom-customize-theme-hook)))
|
|
|
|
|
2019-07-25 12:21:26 +02:00
|
|
|
(defun doom--custom-theme-set-face (spec)
|
|
|
|
(cond ((listp (car spec))
|
|
|
|
(cl-loop for face in (car spec)
|
2019-07-28 14:09:31 +02:00
|
|
|
collect
|
2019-09-15 02:09:58 +10:00
|
|
|
(car (doom--custom-theme-set-face (cons face (cdr spec))))))
|
2019-07-28 14:09:31 +02:00
|
|
|
((keywordp (cadr spec))
|
2019-07-25 12:21:26 +02:00
|
|
|
`((,(car spec) ((t ,(cdr spec))))))
|
|
|
|
(`((,(car spec) ,(cdr spec))))))
|
|
|
|
|
2019-07-23 14:31:00 +02:00
|
|
|
;;;###autoload
|
2021-05-09 12:25:19 -04:00
|
|
|
(defmacro custom-theme-set-faces! (theme &rest specs)
|
2019-07-25 12:21:26 +02:00
|
|
|
"Apply a list of face SPECS as user customizations for THEME.
|
2019-07-23 14:31:00 +02:00
|
|
|
|
|
|
|
THEME can be a single symbol or list thereof. If nil, apply these settings to
|
2019-07-28 14:10:25 +02:00
|
|
|
all themes. It will apply to all themes once they are loaded."
|
2019-10-24 19:42:07 -04:00
|
|
|
(declare (indent defun))
|
2020-05-28 17:36:16 -04:00
|
|
|
(let ((fn (gensym "doom--customize-themes-h-")))
|
2021-05-09 12:25:19 -04:00
|
|
|
`(progn
|
|
|
|
(defun ,fn ()
|
|
|
|
(let (custom--inhibit-theme-enable)
|
2021-05-09 20:12:45 -04:00
|
|
|
(dolist (theme (doom-enlist (or ,theme 'user)))
|
|
|
|
(when (or (eq theme 'user)
|
2021-05-09 12:25:19 -04:00
|
|
|
(custom-theme-enabled-p theme))
|
|
|
|
(apply #'custom-theme-set-faces theme
|
|
|
|
(mapcan #'doom--custom-theme-set-face
|
|
|
|
(list ,@specs)))))))
|
|
|
|
;; Apply the changes immediately if the user is using the default theme
|
|
|
|
;; or the theme has already loaded. This allows you to evaluate these
|
|
|
|
;; macros on the fly and customize your faces iteratively.
|
|
|
|
(when (or (get 'doom-theme 'previous-themes)
|
|
|
|
(null doom-theme))
|
|
|
|
(funcall #',fn))
|
2022-06-21 14:40:15 +02:00
|
|
|
;; FIXME Prevent clobbering this on-the-fly
|
Drop Emacs 26.x support
Emacs 27.x has been the stable version of Emacs for nearly a year, and
introduces a litany of bugfixes, performance, and quality-of-life
improvements that significantly reduce Doom's maintenance burden (like
XDG support, early-init.el, image manipulation without imagemagick, a
native JSON library, harfbuzz support, pdumper, and others).
With so many big changes on Doom's horizon, I like having one less (big)
thing to worry about.
Also reverts bb677cf7a (#5232) as it is no longer needed.
2021-07-06 01:54:32 -04:00
|
|
|
(add-hook 'doom-customize-theme-hook #',fn 100))))
|
2019-07-23 14:31:00 +02:00
|
|
|
|
|
|
|
;;;###autoload
|
2021-05-09 12:25:19 -04:00
|
|
|
(defmacro custom-set-faces! (&rest specs)
|
2019-07-25 12:21:26 +02:00
|
|
|
"Apply a list of face SPECS as user customizations.
|
2019-07-23 14:31:00 +02:00
|
|
|
|
2020-03-27 01:25:30 -04:00
|
|
|
This is a convenience macro alternative to `custom-set-face' which allows for a
|
|
|
|
simplified face format, and takes care of load order issues, so you can use
|
|
|
|
doom-themes' API without worry."
|
2019-10-24 19:42:07 -04:00
|
|
|
(declare (indent defun))
|
2021-05-09 20:12:45 -04:00
|
|
|
`(custom-theme-set-faces! 'user ,@specs))
|
2019-07-23 14:31:00 +02:00
|
|
|
|
|
|
|
;;;###autoload
|
|
|
|
(defun doom/reload-theme ()
|
2021-09-30 14:47:25 +02:00
|
|
|
"Reload the current Emacs theme."
|
2019-07-23 14:31:00 +02:00
|
|
|
(interactive)
|
2021-09-30 14:47:25 +02:00
|
|
|
(unless doom-theme
|
|
|
|
(user-error "No theme is active"))
|
2021-05-01 14:34:31 -04:00
|
|
|
(let ((themes (copy-sequence custom-enabled-themes)))
|
2021-09-30 14:47:25 +02:00
|
|
|
(mapc #'disable-theme custom-enabled-themes)
|
|
|
|
(let (doom-load-theme-hook)
|
|
|
|
(mapc #'enable-theme (reverse themes)))
|
|
|
|
(doom-run-hooks 'doom-load-theme-hook)
|
2021-05-07 16:33:07 -04:00
|
|
|
(doom/reload-font)
|
|
|
|
(message "%s %s"
|
2021-09-30 14:47:25 +02:00
|
|
|
(propertize
|
|
|
|
(format "Reloaded %d theme%s:"
|
|
|
|
(length themes)
|
|
|
|
(if (cdr themes) "s" ""))
|
|
|
|
'face 'bold)
|
2021-05-07 16:33:07 -04:00
|
|
|
(mapconcat #'prin1-to-string themes ", "))))
|
2022-07-30 21:22:39 +02:00
|
|
|
|
|
|
|
|
|
|
|
;;
|
|
|
|
;;; Helpers
|
|
|
|
|
|
|
|
;;;###autoload
|
|
|
|
(defun doom-theme-face-attribute (theme face attribute &optional recursive)
|
|
|
|
"Read a FACE's ATTRIBUTE for a loaded THEME.
|
|
|
|
|
|
|
|
This is different from `face-attribute', which reads the attribute of an active
|
|
|
|
face for the current theme, but an active theme can change (or fail to load) in
|
|
|
|
non-interactive or frame-less sessions."
|
|
|
|
(let* ((spec
|
|
|
|
(cl-loop for (type f _ spec) in (get theme 'theme-settings)
|
|
|
|
if (and (eq type 'theme-face) (eq face f))
|
|
|
|
return spec))
|
|
|
|
(spec
|
|
|
|
(letf! ((defun window-system (_frame) 'x)
|
|
|
|
(defun display-color-cells (_frame) 257)
|
|
|
|
(defun frame-parameter (frame parameter)
|
|
|
|
(pcase parameter
|
|
|
|
(`display-type 'color)
|
|
|
|
(`background-mode 'dark)
|
|
|
|
(_ (funcall frame-parameter frame parameter))))
|
|
|
|
(#'display-supports-face-attributes-p #'always))
|
|
|
|
(face-spec-choose spec)))
|
|
|
|
(inherit (if recursive (plist-get spec :inherit)))
|
|
|
|
(value (if (plist-member spec attribute)
|
|
|
|
(plist-get spec attribute)
|
|
|
|
'unspecified)))
|
|
|
|
(when (and inherit (not (eq inherit 'unspecified)))
|
|
|
|
(letf! (defun face-attribute (face attribute &optional _frame inherit)
|
|
|
|
(doom-theme-face-attribute theme face attribute inherit))
|
|
|
|
(setq value (face-attribute-merged-with attribute value inherit))))
|
|
|
|
value))
|