diff --git a/doc/emacs/custom.texi b/doc/emacs/custom.texi index 72779d32168..e540ff01c91 100644 --- a/doc/emacs/custom.texi +++ b/doc/emacs/custom.texi @@ -656,12 +656,17 @@ theme, its @samp{State} display shows @samp{THEMED} instead of @findex load-theme @findex enable-theme @findex disable-theme +@findex copy-theme-options You can enable a specific Custom theme in the current Emacs session by typing @kbd{M-x load-theme}. This prompts for a theme name, loads the theme from the theme file, and enables it. If a theme file has been loaded before, you can enable the theme without loading its file by typing @kbd{M-x enable-theme}. To disable a Custom theme, -type @kbd{M-x disable-theme}. +type @kbd{M-x disable-theme}. Some themes provide a set of user options +(@pxref{Newcomers Theme}), that might vary over time. If you want to +persist the current set of options, you can copy the user option of a +theme into your own configuration, you can use the +@code{copy-theme-options} command. @findex describe-theme To see a description of a Custom theme, type @kbd{?} on its line in @@ -3249,4 +3254,6 @@ conventions from other programs trying to learn Emacs. Keep in mind that the functionality enabled by this theme may change between releases, including adding new functionality that is expected to be of value for new users or removing old functionality that is regarded -to be confusing or superseded. +to be confusing or superseded. You can use a command like +@code{copy-theme-options} to copy the options from +@code{newcomers-presets} directly into your own configuration. diff --git a/etc/NEWS b/etc/NEWS index c76af281763..f5a0296affb 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -865,6 +865,11 @@ on graphical displays then when this option is enabled Emacs will use a purple bar cursor on compatible terminals as well. See the Info node "(emacs) Cursor Display" for more information. +--- +** New command 'copy-theme-options' +You can use this command to copy options from a theme into your user +configuration. + * Editing Changes in Emacs 31.1 diff --git a/lisp/custom.el b/lisp/custom.el index a369dd626bf..2a92f070096 100644 --- a/lisp/custom.el +++ b/lisp/custom.el @@ -1821,6 +1821,33 @@ If a choice with the same tag already exists, no action is taken." (push load loads))) (put symbol 'custom-loads loads)) +;;;###autoload +(defun copy-theme-options (theme) + "Copy settings from THEME into the user theme." + (interactive (list (intern (completing-read "Copy from theme: " + (custom-available-themes) + nil t)))) + (load-theme theme nil t) + (when (null (get theme 'theme-settings)) + (message "Theme `%s' has no user options" theme)) + (pcase-dolist (`(theme-value ,var ,(pred (eq theme _)) ,val) + (get theme 'theme-settings)) + ;; If the proposed value is already the current value, then we + ;; ignore the value from the theme and don't overwrite any comments. + ;; Otherwise we check if the current value is the default value, and + ;; if not we prompt the user if they are OK with overwriting their + ;; previous configuration. + (when (let ((val* (funcall (or (get var 'custom-get) #'default-value) var)) + (val (eval (with-demoted-errors "%S" val) t))) + (and (not (equal val val*)) + (or (custom--standard-value-p var val*) + (yes-or-no-p (format "You have customized `%s' to %S, \ +overwrite with %S?" + var (symbol-value var) val))))) + (customize-save-variable + var val + (format "Copied from %s by `copy-theme-options'" theme))))) + (provide 'custom) ;;; custom.el ends here