aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLars Ingebrigtsen2019-10-11 08:27:50 +0200
committerLars Ingebrigtsen2019-10-11 08:27:50 +0200
commitdf713b9344e978eff4f0a6aff506932fcdb1a39c (patch)
treecfdfca95826646ff493764177fcd00c84361fcb3
parent88f0c5662d7ace5e1dd770f8f0cc489d02a5876b (diff)
downloademacs-df713b9344e978eff4f0a6aff506932fcdb1a39c.tar.gz
emacs-df713b9344e978eff4f0a6aff506932fcdb1a39c.zip
Ensure that setq-local take an even number of symbol/value pairs
* 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'.
-rw-r--r--doc/lispref/variables.texi16
-rw-r--r--etc/NEWS3
-rw-r--r--lisp/subr.el35
3 files changed, 38 insertions, 16 deletions
diff --git a/doc/lispref/variables.texi b/doc/lispref/variables.texi
index 89dac4f7a4d..76bda7874e3 100644
--- a/doc/lispref/variables.texi
+++ b/doc/lispref/variables.texi
@@ -1430,11 +1430,17 @@ needed if you use the @var{local} argument to @code{add-hook} or
1430@code{remove-hook}. 1430@code{remove-hook}.
1431@end deffn 1431@end deffn
1432 1432
1433@defmac setq-local variable value 1433@defmac setq-local &rest pairs
1434This macro creates a buffer-local binding in the current buffer for 1434@var{pairs} is a list of variable and value pairs. This macro creates
1435@var{variable}, and gives it the buffer-local value @var{value}. It 1435a buffer-local binding in the current buffer for each of the
1436is equivalent to calling @code{make-local-variable} followed by 1436variables, and gives them a buffer-local value. It is equivalent to
1437@code{setq}. @var{variable} should be an unquoted symbol. 1437calling @code{make-local-variable} followed by @code{setq} for each of
1438the variables. The variables should be unquoted symbols.
1439
1440@lisp
1441(setq-local var1 "value1"
1442 var2 "value2")
1443@end lisp
1438@end defmac 1444@end defmac
1439 1445
1440@deffn Command make-variable-buffer-local variable 1446@deffn Command make-variable-buffer-local variable
diff --git a/etc/NEWS b/etc/NEWS
index b680e180043..4135d47ee18 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -2351,6 +2351,9 @@ scrolling.
2351 2351
2352* Lisp Changes in Emacs 27.1 2352* Lisp Changes in Emacs 27.1
2353 2353
2354** 'setq-local' can now set an arbitrary number of variables, which
2355makes the syntax more like 'setq'.
2356
2354** 'reveal-mode' can now also be used for more than to toggle between 2357** 'reveal-mode' can now also be used for more than to toggle between
2355invisible and visible: It can also toggle 'display' properties in 2358invisible and visible: It can also toggle 'display' properties in
2356overlays. This is only done on 'display' properties that have the 2359overlays. This is only done on 'display' properties that have the
diff --git a/lisp/subr.el b/lisp/subr.el
index 2acac3a0518..e50a52e2f53 100644
--- a/lisp/subr.el
+++ b/lisp/subr.el
@@ -143,22 +143,35 @@ of previous VARs.
143 (push `(set-default ',(pop args) ,(pop args)) exps)) 143 (push `(set-default ',(pop args) ,(pop args)) exps))
144 `(progn . ,(nreverse exps)))) 144 `(progn . ,(nreverse exps))))
145 145
146(defmacro setq-local (&rest args) 146(defmacro setq-local (&rest pairs)
147 "Set each SYM to the value of its VAL in the current buffer. 147 "Make variables in PAIRS buffer-local and assign them the corresponding values.
148 148
149\(fn [SYM VAL]...)" 149PAIRS is a list of variable/value pairs. For each variable, make
150 ;; Can't use backquote here, it's too early in the bootstrap. 150it buffer-local and assign it the corresponding value. The
151 (declare (debug (symbolp form))) 151variables are literal symbols and should not be quoted.
152 (let ((expr)) 152
153 (while args 153The second VALUE is not computed until after the first VARIABLE
154is set, and so on; each VALUE can use the new value of variables
155set earlier in the ‘setq-local’. The return value of the
156‘setq-local’ form is the value of the last VALUE.
157
158\(fn [VARIABLE VALUE]...)"
159 (declare (debug setq))
160 (unless (zerop (mod (length pairs) 2))
161 (error "PAIRS must have an even number of variable/value members"))
162 (let ((expr nil))
163 (while pairs
164 (unless (symbolp (car pairs))
165 (error "Attempting to set a non-symbol: %s" (car pairs)))
166 ;; Can't use backquote here, it's too early in the bootstrap.
154 (setq expr 167 (setq expr
155 (cons 168 (cons
156 (list 'set 169 (list 'set
157 (list 'make-local-variable (list 'quote (car args))) 170 (list 'make-local-variable (list 'quote (car pairs)))
158 (car (cdr args))) 171 (car (cdr pairs)))
159 expr)) 172 expr))
160 (setq args (cdr (cdr args)))) 173 (setq pairs (cdr (cdr pairs))))
161 (cons 'progn (nreverse expr)))) 174 (macroexp-progn (nreverse expr))))
162 175
163(defmacro defvar-local (var val &optional docstring) 176(defmacro defvar-local (var val &optional docstring)
164 "Define VAR as a buffer-local variable with default value VAL. 177 "Define VAR as a buffer-local variable with default value VAL.