emacs-diffs
[Top][All Lists]
Advanced

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

master 9e5290a: * lisp/emacs-lisp/easy-mmode.el (define-minor-mode): Fix


From: Stefan Monnier
Subject: master 9e5290a: * lisp/emacs-lisp/easy-mmode.el (define-minor-mode): Fix bug#47925
Date: Tue, 20 Apr 2021 19:40:15 -0400 (EDT)

branch: master
commit 9e5290aecf6cafb422aa67ef891c90693c91fdbe
Author: Stefan Monnier <monnier@iro.umontreal.ca>
Commit: Stefan Monnier <monnier@iro.umontreal.ca>

    * lisp/emacs-lisp/easy-mmode.el (define-minor-mode): Fix bug#47925
    
    In order to correctly detect the case of the "new style" with an empty body,
    remove the old optional arguments `init-value`, `lighter`, and `keymap`,
    so we can distinguish the "nil arg" from the "absent arg" cases.
---
 lisp/emacs-lisp/easy-mmode.el | 23 ++++++++++++-----------
 1 file changed, 12 insertions(+), 11 deletions(-)

diff --git a/lisp/emacs-lisp/easy-mmode.el b/lisp/emacs-lisp/easy-mmode.el
index 2dd1524..0a6d4ec 100644
--- a/lisp/emacs-lisp/easy-mmode.el
+++ b/lisp/emacs-lisp/easy-mmode.el
@@ -118,7 +118,7 @@ it is disabled.")
 ;;;###autoload
 (defalias 'easy-mmode-define-minor-mode #'define-minor-mode)
 ;;;###autoload
-(defmacro define-minor-mode (mode doc &optional init-value lighter keymap 
&rest body)
+(defmacro define-minor-mode (mode doc &rest body)
   "Define a new minor mode MODE.
 This defines the toggle command MODE and (by default) a control variable
 MODE (you can override this with the :variable keyword, see below).
@@ -200,6 +200,9 @@ INIT-VALUE LIGHTER KEYMAP.
 
   (let* ((last-message (make-symbol "last-message"))
          (mode-name (symbol-name mode))
+         (init-value nil)
+         (keymap nil)
+         (lighter nil)
         (pretty-name nil)
         (globalp nil)
         (set nil)
@@ -216,22 +219,20 @@ INIT-VALUE LIGHTER KEYMAP.
         (hook-on (intern (concat mode-name "-on-hook")))
         (hook-off (intern (concat mode-name "-off-hook")))
          (interactive t)
-         (warnwrap (if (keywordp init-value) #'identity
+         (warnwrap (if (or (null body) (keywordp (car body))) #'identity
                      (lambda (exp)
                        (macroexp-warn-and-return
                         "Use keywords rather than deprecated positional 
arguments to `define-minor-mode'"
                         exp))))
         keyw keymap-sym tmp)
 
-    ;; Allow skipping the first three args.
-    (cond
-     ((keywordp init-value)
-      (setq body (if keymap `(,init-value ,lighter ,keymap ,@body)
-                  `(,init-value ,lighter))
-           init-value nil lighter nil keymap nil))
-     ((keywordp lighter)
-      (setq body `(,lighter ,keymap ,@body) lighter nil keymap nil))
-     ((keywordp keymap) (push keymap body) (setq keymap nil)))
+    ;; Allow BODY to start with the old INIT-VALUE LIGHTER KEYMAP triplet.
+    (unless (keywordp (car body))
+      (setq init-value (pop body))
+      (unless (keywordp (car body))
+        (setq lighter (pop body))
+        (unless (keywordp (car body))
+          (setq keymap (pop body)))))
 
     ;; Check keys.
     (while (keywordp (setq keyw (car body)))



reply via email to

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