doomemacs/core/autoload/themes.el

67 lines
2.5 KiB
EmacsLisp
Raw Normal View History

2019-08-06 14:45:55 -04:00
;;; core/autoload/themes.el -*- lexical-binding: t; -*-
2019-07-23 14:31:00 +02: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)))
(defun doom--custom-theme-set-face (spec)
(cond ((listp (car spec))
(cl-loop for face in (car spec)
collect
(car (doom--custom-theme-set-face (cons face (cdr spec))))))
((keywordp (cadr spec))
`((,(car spec) ((t ,(cdr spec))))))
(`((,(car spec) ,(cdr spec))))))
2019-07-23 14:31:00 +02:00
;;;###autoload
(defun custom-theme-set-faces! (theme &rest specs)
"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
all themes. It will apply to all themes once they are loaded."
(declare (indent defun))
(let ((fn (gensym "doom--customize-themes-h-")))
(fset
fn (lambda ()
(let (custom--inhibit-theme-enable)
(dolist (theme (doom-enlist (or ,theme 'doom)))
(when (or (memq theme '(user doom))
(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))
;; TODO Append to `doom-load-theme-hook' with DEPTH instead when Emacs 26.x
;; support is dropped.
(add-hook 'doom-customize-theme-hook fn 'append)))
2019-07-23 14:31:00 +02:00
;;;###autoload
(defun custom-set-faces! (&rest specs)
"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."
(declare (indent defun))
(apply #'custom-theme-set-faces! 'doom specs))
2019-07-23 14:31:00 +02:00
;;;###autoload
(defun doom/reload-theme ()
"Reload the current color theme."
(interactive)
(let ((themes (copy-sequence custom-enabled-themes)))
(load-theme doom-theme t)
(doom/reload-font)
(message "%s %s"
(propertize "Reloaded themes:" 'face 'bold)
(mapconcat #'prin1-to-string themes ", "))))