emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master 22ae842b34: Add new hooks when enabling and disabling themes


From: Lars Ingebrigtsen
Subject: master 22ae842b34: Add new hooks when enabling and disabling themes
Date: Sat, 21 May 2022 08:57:02 -0400 (EDT)

branch: master
commit 22ae842b346621095223213621f2244a5a59d3b8
Author: Lars Ingebrigtsen <larsi@gnus.org>
Commit: Lars Ingebrigtsen <larsi@gnus.org>

    Add new hooks when enabling and disabling themes
    
    * lisp/custom.el (enable-theme-hook, disable-theme-hook): New
    hooks (bug#37802).
    (enable-theme, disable-theme): Call them.
---
 etc/NEWS       | 16 +++++++++++-----
 lisp/custom.el | 32 ++++++++++++++++++++++++++++----
 2 files changed, 39 insertions(+), 9 deletions(-)

diff --git a/etc/NEWS b/etc/NEWS
index 564f7c4458..223f87ebfb 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -1856,6 +1856,17 @@ functions.
 
 * Lisp Changes in Emacs 29.1
 
+** Themes
+
+---
+*** New hooks 'enable-theme-hook' and 'disable-theme-hook'.
+These are run after enabling and disabling a theme, respectively.
+
+---
+*** Themes can now be made obsolete.
+Using 'make-obsolete' on a theme is now supported.  This will make
+'load-theme' issue a warning when loading the theme.
+
 +++
 ** New hook 'display-monitors-changed-functions'.
 It is called whenever the configuration of different monitors on a
@@ -2366,11 +2377,6 @@ local variables.
 ** Third 'mapconcat' argument SEPARATOR is now optional.
 An explicit nil always meant the empty string, now it can be left out.
 
----
-** Themes can now be made obsolete.
-Using 'make-obsolete' on a theme is now supported.  This will make
-'load-theme' issue a warning when loading the theme.
-
 +++
 ** New function 'define-keymap'.
 This function allows defining a number of keystrokes with one form.
diff --git a/lisp/custom.el b/lisp/custom.el
index 76c14831ca..181711967d 100644
--- a/lisp/custom.el
+++ b/lisp/custom.el
@@ -1422,6 +1422,22 @@ are not directories are omitted from the expansion."
 
 ;;; Enabling and disabling loaded themes.
 
+(defcustom enable-theme-hook nil
+  "Atypical hook run after a theme has been enabled.
+The functions in the hook are called with one parameter -- the
+ name of the theme that's been enabled (as a symbol)."
+  :type 'hook
+  :group 'customize
+  :version "29.1")
+
+(defcustom disable-theme-hook nil
+  "Atypical hook run after a theme has been disabled.
+The functions in the hook are called with one parameter -- the
+ name of the theme that's been disabled (as a symbol)."
+  :type 'hook
+  :group 'customize
+  :version "29.1")
+
 (defun enable-theme (theme)
   "Reenable all variable and face settings defined by THEME.
 THEME should be either `user', or a theme loaded via `load-theme'.
@@ -1430,7 +1446,9 @@ After this function completes, THEME will have the highest
 precedence (after `user') among enabled themes.
 
 Note that any already-enabled themes remain enabled after this
-function runs.  To disable other themes, use `disable-theme'."
+function runs.  To disable other themes, use `disable-theme'.
+
+After THEME has been enabled, `enable-theme-hook' is run."
   (interactive (list (intern
                      (completing-read
                       "Enable custom theme: "
@@ -1478,7 +1496,9 @@ function runs.  To disable other themes, use 
`disable-theme'."
     (setq custom-enabled-themes
          (cons theme (remq theme custom-enabled-themes)))
     ;; Give the `user' theme the highest priority.
-    (enable-theme 'user)))
+    (enable-theme 'user))
+  ;; Allow callers to react to the enabling.
+  (run-hook-with-args 'enable-theme-hook theme))
 
 (defcustom custom-enabled-themes nil
   "List of enabled Custom Themes, highest precedence first.
@@ -1523,7 +1543,9 @@ Setting this variable through Customize calls 
`enable-theme' or
 
 (defun disable-theme (theme)
   "Disable all variable and face settings defined by THEME.
-See `custom-enabled-themes' for a list of enabled themes."
+See `custom-enabled-themes' for a list of enabled themes.
+
+After THEME has been disabled, `disable-theme-hook' is run."
   (interactive (list (intern
                      (completing-read
                       "Disable custom theme: "
@@ -1567,7 +1589,9 @@ See `custom-enabled-themes' for a list of enabled themes."
                             "unspecified-fg" "black"))
       (face-set-after-frame-default frame))
     (setq custom-enabled-themes
-          (delq theme custom-enabled-themes))))
+          (delq theme custom-enabled-themes))
+    ;; Allow callers to react to the disabling.
+    (run-hook-with-args 'disable-theme-hook theme)))
 
 ;; Only used if window-system not null.
 (declare-function x-get-resource "frame.c"



reply via email to

[Prev in Thread] Current Thread [Next in Thread]