]> git.eshelyaron.com Git - emacs.git/commitdiff
(define-minor-mode): Add keywords ':on' and ':off'
authorEshel Yaron <me@eshelyaron.com>
Sat, 19 Oct 2024 12:20:23 +0000 (14:20 +0200)
committerEshel Yaron <me@eshelyaron.com>
Sat, 19 Oct 2024 12:20:23 +0000 (14:20 +0200)
lisp/emacs-lisp/easy-mmode.el

index f47352988f8a3b8c94de8be2d47188139b801b0f..1466ccb8e8990ce9cdc5386c532203761da1b8e9 100644 (file)
@@ -253,7 +253,7 @@ INIT-VALUE LIGHTER KEYMAP.
                         (format-message
                          "Use keywords rather than deprecated positional arguments to `define-minor-mode'")
                         exp))))
-        keyw keymap-sym tmp)
+        keyw keymap-sym tmp on off)
 
     ;; Allow BODY to start with the old INIT-VALUE LIGHTER KEYMAP triplet.
     (unless (keywordp (car body))
@@ -290,6 +290,12 @@ INIT-VALUE LIGHTER KEYMAP.
                      (setq getter (car variable))
                      (setq setter `(funcall #',(cdr variable)))))
        (:after-hook (setq after-hook (pop body)))
+       (:on (while (and body (not (keywordp (car body))))
+               (push (pop body) on))
+             (setq on (nreverse on)))
+       (:off (while (and body (not (keywordp (car body))))
+               (push (pop body) off))
+             (setq off(nreverse off)))
        (_ (push keyw extra-keywords) (push (pop body) extra-keywords))))
 
     (setq pretty-name (easy-mmode-pretty-mode-name mode lighter))
@@ -304,6 +310,12 @@ INIT-VALUE LIGHTER KEYMAP.
     ;; TODO? Mark booleans as safe if booleanp?  Eg abbrev-mode.
     (unless type (setq type '(:type 'boolean)))
 
+    (when (or on off)
+      (setq body
+            `((if ,mode
+                  (progn ,@on)
+                ,@off))))
+
     `(progn
        ;; Define the variable to enable or disable the mode.
        ,(cond