emacs-diffs
[Top][All Lists]
Advanced

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

master 6a480c830b: * lisp/emacs-lisp/macroexp.el (macroexp-let2*): Allow


From: Stefan Monnier
Subject: master 6a480c830b: * lisp/emacs-lisp/macroexp.el (macroexp-let2*): Allow common shorthand
Date: Mon, 11 Apr 2022 15:11:01 -0400 (EDT)

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

    * lisp/emacs-lisp/macroexp.el (macroexp-let2*): Allow common shorthand
---
 doc/lispref/variables.texi  | 10 +++++-----
 etc/NEWS                    |  3 +++
 lisp/emacs-lisp/macroexp.el | 14 +++++++++++---
 3 files changed, 19 insertions(+), 8 deletions(-)

diff --git a/doc/lispref/variables.texi b/doc/lispref/variables.texi
index f85ed847c4..f0e3f337a6 100644
--- a/doc/lispref/variables.texi
+++ b/doc/lispref/variables.texi
@@ -2789,13 +2789,13 @@ implemented this way:
 (gv-define-expander substring
   (lambda (do place from &optional to)
     (gv-letplace (getter setter) place
-      (macroexp-let2* nil ((start from) (end to))
-        (funcall do `(substring ,getter ,start ,end)
+      (macroexp-let2* (from to)
+        (funcall do `(substring ,getter ,from ,to)
                  (lambda (v)
-                   (macroexp-let2 nil v v
+                   (macroexp-let2* (v)
                      `(progn
                         ,(funcall setter `(cl--set-substring
-                                           ,getter ,start ,end ,v))
+                                           ,getter ,from ,to ,v))
                         ,v))))))))
 @end example
 @end defmac
@@ -2808,7 +2808,7 @@ of Common Lisp could be implemented this way:
 @example
 (defmacro incf (place &optional n)
   (gv-letplace (getter setter) place
-    (macroexp-let2 nil v (or n 1)
+    (macroexp-let2* ((v (or n 1)))
       (funcall setter `(+ ,v ,getter)))))
 @end example
 
diff --git a/etc/NEWS b/etc/NEWS
index 3c4dacf912..79c27da549 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -1360,6 +1360,9 @@ functions.
 
 * Lisp Changes in Emacs 29.1
 
++++
+** 'macroexp-let2*' can omit 'test' arg and use single-var bindings.
+
 +++
 ** New variable 'last-event-device' and new function 'device-class'.
 On X Windows, 'last-event-device' specifies the input extension device
diff --git a/lisp/emacs-lisp/macroexp.el b/lisp/emacs-lisp/macroexp.el
index e91b302af1..e4bc2df280 100644
--- a/lisp/emacs-lisp/macroexp.el
+++ b/lisp/emacs-lisp/macroexp.el
@@ -567,12 +567,20 @@ cases where EXP is a constant."
 (defmacro macroexp-let2* (test bindings &rest body)
   "Multiple binding version of `macroexp-let2'.
 
-BINDINGS is a list of elements of the form (SYM EXP).  Each EXP
-can refer to symbols specified earlier in the binding list."
+BINDINGS is a list of elements of the form (SYM EXP) or just SYM,
+which then stands for (SYM SYM).
+Each EXP can refer to symbols specified earlier in the binding list.
+
+TEST has to be a symbol, and if it is nil it can be omitted."
   (declare (indent 2) (debug (sexp (&rest (sexp form)) body)))
+  (when (consp test) ;; `test' was omitted.
+    (push bindings body)
+    (setq bindings test)
+    (setq test nil))
   (pcase-exhaustive bindings
     ('nil (macroexp-progn body))
-    (`((,var ,exp) . ,tl)
+    (`(,(or `(,var ,exp) (and (pred symbolp) var (let exp var)))
+       . ,tl)
      `(macroexp-let2 ,test ,var ,exp
         (macroexp-let2* ,test ,tl ,@body)))))
 



reply via email to

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