From f31b9d86a67f1b3fd70339f277dff52478890351 Mon Sep 17 00:00:00 2001 From: Philip Kaludercic Date: Tue, 6 Sep 2022 20:53:35 +0200 Subject: Add new command 'toggle-theme' * doc/emacs/custom.texi (Custom Themes): Mention it. * etc/themes/leuven-dark-theme.el (leuven-dark): Add dual theme. * etc/themes/leuven-theme.el (leuven): Add dual theme. * etc/themes/tango-dark-theme.el (tango-dark): Add dual theme. * etc/themes/tango-theme.el (tango): Add dual theme. * etc/themes/tsdh-dark-theme.el (tsdh-dark): Add dual theme. * etc/themes/tsdh-light-theme.el (tsdh-light): Add dual theme. * lisp/cus-theme.el (describe-theme-1): Say if a theme has a dual. * lisp/custom.el (toggle-theme): Add new command. --- lisp/custom.el | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'lisp/custom.el') diff --git a/lisp/custom.el b/lisp/custom.el index 352b5b0e160..b4d1ba7317f 100644 --- a/lisp/custom.el +++ b/lisp/custom.el @@ -1372,6 +1372,25 @@ Return t if THEME was successfully loaded, nil otherwise." (enable-theme theme)) t) +(defun toggle-theme (&optional no-confirm no-enable) + "Toggle the current active theme by enabling its dual pair. +The current theme will be immediately disabled before the dual +theme has been enabled. If THEME is not active an error will be +raised. If theme is nil For NO-CONFIRM and NO-ENABLE, see +`load-theme'." + (interactive) + (cond + ((length= custom-enabled-themes 0) + (user-error "No theme is active, cannot toggle")) + ((length> custom-enabled-themes 1) + (user-error "More than one theme active, cannot unambiguously toggle"))) + (let* ((theme (car custom-enabled-themes)) + (dual (get theme 'dual-theme))) + (unless dual + (error "`%s' has no dual theme to toggle between" theme)) + (disable-theme theme) + (load-theme dual no-confirm no-enable))) + (defun custom-theme-load-confirm (hash) "Query the user about loading a Custom theme that may not be safe. The theme should be in the current buffer. If the user agrees, -- cgit v1.2.3