Function: customize-create-theme
customize-create-theme is an autoloaded, interactive and byte-compiled
function defined in cus-theme.el.gz.
Signature
(customize-create-theme &optional THEME BUFFER)
Documentation
Create or edit a custom theme.
THEME, if non-nil, should be an existing theme to edit. If THEME
is user, the resulting *Custom Theme* buffer also contains a
checkbox for removing the theme settings specified in the buffer
from the Custom save file.
BUFFER, if non-nil, should be a buffer to use; the default is
named *Custom Theme*.
Probably introduced at or before Emacs version 22.1.
Key Bindings
Source Code
;; Defined in /usr/src/emacs/lisp/cus-theme.el.gz
;;;###autoload
(defun customize-create-theme (&optional theme buffer)
"Create or edit a custom theme.
THEME, if non-nil, should be an existing theme to edit. If THEME
is `user', the resulting *Custom Theme* buffer also contains a
checkbox for removing the theme settings specified in the buffer
from the Custom save file.
BUFFER, if non-nil, should be a buffer to use; the default is
named *Custom Theme*."
(interactive)
(switch-to-buffer (get-buffer-create (or buffer "*Custom Theme*")))
(let ((inhibit-read-only t))
(erase-buffer)
(delete-all-overlays))
(custom-new-theme-mode)
(make-local-variable 'custom-theme-name)
(setq-local custom-theme--save-name theme)
(setq-local custom-theme-faces nil)
(setq-local custom-theme-variables nil)
(setq-local custom-theme-description "")
(setq-local custom-theme--migrate-settings nil)
(make-local-variable 'custom-theme-insert-face-marker)
(make-local-variable 'custom-theme-insert-variable-marker)
(make-local-variable 'custom-theme--listed-faces)
(when (called-interactively-p 'interactive)
(unless (y-or-n-p "Include basic face customizations in this theme? ")
(setq custom-theme--listed-faces nil)))
(let (vars values faces face-specs)
;; Load the theme settings.
(when theme
(if (eq theme 'user)
(widget-insert "This buffer contains all the Custom settings you have made.
You can convert them into a new custom theme, and optionally
remove them from your saved Custom file.\n\n")
(load-theme theme nil t))
(dolist (setting (get theme 'theme-settings))
(if (eq (car setting) 'theme-value)
(progn (push (nth 1 setting) vars)
(push (nth 3 setting) values))
(push (nth 1 setting) faces)
(push (nth 3 setting) face-specs))))
(widget-create 'push-button
:tag " Visit Theme "
:help-echo "Insert the settings of a pre-defined theme."
:action (lambda (_widget &optional _event)
(call-interactively #'custom-theme-visit-theme)))
(widget-insert " ")
(widget-create 'push-button
:tag " Merge Theme "
:help-echo "Merge in the settings of a pre-defined theme."
:action (lambda (_widget &optional _event)
(call-interactively #'custom-theme-merge-theme)))
(widget-insert " ")
(widget-create 'push-button
:tag " Revert "
:help-echo "Revert this buffer to its original state."
:action (lambda (&rest _ignored) (revert-buffer)))
(widget-insert "\n\nTheme name : ")
(setq custom-theme-name
(widget-create 'editable-field
:value (if (and theme (not (eq theme 'user)))
(symbol-name theme)
"")))
(widget-insert "Description: ")
(setq custom-theme-description
(widget-create 'text :format "%v"
:value (or (get theme 'theme-documentation)
(format-time-string "Created %Y-%m-%d."))))
(widget-create 'push-button
:notify #'custom-theme-write
" Save Theme ")
(when (eq theme 'user)
(setq custom-theme--migrate-settings t)
(widget-insert " ")
(widget-create 'checkbox
:value custom-theme--migrate-settings
:action (lambda (widget &optional event)
(when (widget-value widget)
(widget-toggle-action widget event)
(setq custom-theme--migrate-settings
(widget-value widget)))))
(widget-insert (propertize " Remove saved theme settings from Custom save file."
'face '(variable-pitch (:height 0.9)))))
;; If THEME is non-nil, insert all of that theme's faces.
;; Otherwise, insert those in `custom-theme--listed-faces'.
(widget-insert "\n\n Theme faces:\n ")
(if theme
(while faces
(custom-theme-add-face-1 (pop faces) (pop face-specs)))
(dolist (face custom-theme--listed-faces)
(custom-theme-add-face-1 face nil)))
(setq custom-theme-insert-face-marker (point-marker))
(widget-insert " ")
(widget-create 'push-button
:tag "Insert Additional Face"
:help-echo "Add another face to this theme."
:follow-link 'mouse-face
:button-face 'custom-link
:mouse-face 'highlight
:pressed-face 'highlight
:action (lambda (_widget &optional _event)
(call-interactively #'custom-theme-add-face)))
;; If THEME is non-nil, insert all of that theme's variables.
(widget-insert "\n\n Theme variables:\n ")
(if theme
(while vars
(if (eq (car vars) 'custom-enabled-themes)
(progn (pop vars) (pop values))
(custom-theme-add-var-1 (pop vars) (eval (pop values))))))
(setq custom-theme-insert-variable-marker (point-marker))
(widget-insert " ")
(widget-create 'push-button
:tag "Insert Variable"
:help-echo "Add another variable to this theme."
:follow-link 'mouse-face
:button-face 'custom-link
:mouse-face 'highlight
:pressed-face 'highlight
:action (lambda (_widget &optional _event)
(call-interactively #'custom-theme-add-variable)))
(widget-insert ?\n)
(widget-setup)
(goto-char (point-min))
(message "")))