aboutsummaryrefslogtreecommitdiffstats
path: root/lisp
diff options
context:
space:
mode:
authorLars Ingebrigtsen2019-10-11 08:27:50 +0200
committerLars Ingebrigtsen2019-10-11 08:27:50 +0200
commitdf713b9344e978eff4f0a6aff506932fcdb1a39c (patch)
treecfdfca95826646ff493764177fcd00c84361fcb3 /lisp
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'.
Diffstat (limited to 'lisp')
-rw-r--r--lisp/subr.el35
1 files changed, 24 insertions, 11 deletions
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.