custom-push-theme
code: custom.el
(defun custom-push-theme (prop symbol theme mode &optional value)
"Record VALUE for face or variable SYMBOL in custom theme THEME.
PROP is theme-face' for a face, theme-value' for a variable.
MODE can be either the symbol set' or the symbol reset'. If it is the
symbol `set', then VALUE is the value to use. If it is the symbol
`reset', then SYMBOL will be removed from THEME (VALUE is ignored).
See `custom-known-themes' for a list of known themes."
(unless (memq prop '(theme-value theme-face))
(error "Unknown theme property"))
(let* ((old (get symbol prop))
(setting (assq theme old)) ; '(theme value)
(theme-settings ; '(prop symbol theme value)
(get theme 'theme-settings)))
(cond
;; Remove a setting:
((eq mode 'reset)
(when setting
(let (res)
(dolist (theme-setting theme-settings)
(if (and (eq (car theme-setting) prop)
(eq (cadr theme-setting) symbol))
(setq res theme-setting)))
(put theme 'theme-settings (delq res theme-settings)))
(put symbol prop (delq setting old))))
;; Alter an existing setting:
(setting
(let (res)
(dolist (theme-setting theme-settings)
(if (and (eq (car theme-setting) prop)
(eq (cadr theme-setting) symbol))
(setq res theme-setting)))
(put theme 'theme-settings
(cons (list prop symbol theme value)
(delq res theme-settings)))
;; It's tempting to use setcar here, but that could
;; inadvertently modify other properties in SYMBOL's proplist,
;; if those just happen to share elements with the value of PROP.
(put symbol prop (cons (list theme value) (delq setting old)))))
;; Add a new setting:
(t
(when (custom--should-apply-setting theme)
(unless old
;; If the user changed a variable outside of Customize, save
;; the value to a fake theme, `changed'. If the theme is
;; later disabled, we use this to bring back the old value.
;;
;; For faces, we just use `face--new-frame-defaults' to
;; recompute when the theme is disabled.
(when (and (eq prop 'theme-value)
(boundp symbol))
(let ((sv (get symbol 'standard-value))
(val (symbol-value symbol)))
(unless (or
;; We only do this trick if the current value
;; is different from the standard value.
(and sv (equal (eval (car sv)) val))
;; And we don't do it if we would end up recording
;; the same value for the user theme. This way we avoid
;; having ((user VALUE) (changed VALUE)). That would be
;; useless, because we don't disable the user theme.
(and (eq theme 'user) (equal (custom-quote val) value)))
(setq old `((changed ,(custom-quote val))))))))
(put symbol prop (cons (list theme value) old)))
(put theme 'theme-settings
(cons (list prop symbol theme value) theme-settings))))))