]> git.eshelyaron.com Git - emacs.git/commitdiff
Ensure that setq-local take an even number of symbol/value pairs
authorLars Ingebrigtsen <larsi@gnus.org>
Fri, 11 Oct 2019 06:27:50 +0000 (08:27 +0200)
committerLars Ingebrigtsen <larsi@gnus.org>
Fri, 11 Oct 2019 06:27:50 +0000 (08:27 +0200)
* doc/lispref/variables.texi (Creating Buffer-Local): Document the
new syntax for setq-local.

* lisp/subr.el (setq-local): Ensure that there's an even number of
variable/value pairs, and expand the doc string by taking some
text from `setq'.

doc/lispref/variables.texi
etc/NEWS
lisp/subr.el

index 89dac4f7a4d090ea4d238d2b9b75a1ccd627d987..76bda7874e382f25b117d3e8d2233a9d8d62dfa5 100644 (file)
@@ -1430,11 +1430,17 @@ needed if you use the @var{local} argument to @code{add-hook} or
 @code{remove-hook}.
 @end deffn
 
-@defmac setq-local variable value
-This macro creates a buffer-local binding in the current buffer for
-@var{variable}, and gives it the buffer-local value @var{value}.  It
-is equivalent to calling @code{make-local-variable} followed by
-@code{setq}.  @var{variable} should be an unquoted symbol.
+@defmac setq-local &rest pairs
+@var{pairs} is a list of variable and value pairs.  This macro creates
+a buffer-local binding in the current buffer for each of the
+variables, and gives them a buffer-local value.  It is equivalent to
+calling @code{make-local-variable} followed by @code{setq} for each of
+the variables.  The variables should be unquoted symbols.
+
+@lisp
+(setq-local var1 "value1"
+            var2 "value2")
+@end lisp
 @end defmac
 
 @deffn Command make-variable-buffer-local variable
index b680e180043f7021a98ab424f34efb02be0ab493..4135d47ee18a34e0920ef99a95e16d8080457e3c 100644 (file)
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -2351,6 +2351,9 @@ scrolling.
 \f
 * Lisp Changes in Emacs 27.1
 
+** 'setq-local' can now set an arbitrary number of variables, which
+makes the syntax more like 'setq'.
+
 ** 'reveal-mode' can now also be used for more than to toggle between
 invisible and visible: It can also toggle 'display' properties in
 overlays.  This is only done on 'display' properties that have the
index 2acac3a0518f0513190d0469c86adf88c6c21935..e50a52e2f5386b0ff805aad6796a8e8f0de647c4 100644 (file)
@@ -143,22 +143,35 @@ of previous VARs.
       (push `(set-default ',(pop args) ,(pop args)) exps))
     `(progn . ,(nreverse exps))))
 
-(defmacro setq-local (&rest args)
-  "Set each SYM to the value of its VAL in the current buffer.
+(defmacro setq-local (&rest pairs)
+  "Make variables in PAIRS buffer-local and assign them the corresponding values.
 
-\(fn [SYM VAL]...)"
-  ;; Can't use backquote here, it's too early in the bootstrap.
-  (declare (debug (symbolp form)))
-  (let ((expr))
-    (while args
+PAIRS is a list of variable/value pairs.  For each variable, make
+it buffer-local and assign it the corresponding value.  The
+variables are literal symbols and should not be quoted.
+
+The second VALUE is not computed until after the first VARIABLE
+is set, and so on; each VALUE can use the new value of variables
+set earlier in the ‘setq-local’.  The return value of the
+‘setq-local’ form is the value of the last VALUE.
+
+\(fn [VARIABLE VALUE]...)"
+  (declare (debug setq))
+  (unless (zerop (mod (length pairs) 2))
+    (error "PAIRS must have an even number of variable/value members"))
+  (let ((expr nil))
+    (while pairs
+      (unless (symbolp (car pairs))
+        (error "Attempting to set a non-symbol: %s" (car pairs)))
+      ;; Can't use backquote here, it's too early in the bootstrap.
       (setq expr
             (cons
              (list 'set
-                   (list 'make-local-variable (list 'quote (car args)))
-                   (car (cdr args)))
+                   (list 'make-local-variable (list 'quote (car pairs)))
+                   (car (cdr pairs)))
              expr))
-      (setq args (cdr (cdr args))))
-    (cons 'progn (nreverse expr))))
+      (setq pairs (cdr (cdr pairs))))
+    (macroexp-progn (nreverse expr))))
 
 (defmacro defvar-local (var val &optional docstring)
   "Define VAR as a buffer-local variable with default value VAL.