diff options
| author | Lars Ingebrigtsen | 2019-10-11 08:27:50 +0200 |
|---|---|---|
| committer | Lars Ingebrigtsen | 2019-10-11 08:27:50 +0200 |
| commit | df713b9344e978eff4f0a6aff506932fcdb1a39c (patch) | |
| tree | cfdfca95826646ff493764177fcd00c84361fcb3 | |
| parent | 88f0c5662d7ace5e1dd770f8f0cc489d02a5876b (diff) | |
| download | emacs-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.texi | 16 | ||||
| -rw-r--r-- | etc/NEWS | 3 | ||||
| -rw-r--r-- | lisp/subr.el | 35 |
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 |
| 1434 | This 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 | 1435 | a buffer-local binding in the current buffer for each of the |
| 1436 | is equivalent to calling @code{make-local-variable} followed by | 1436 | variables, and gives them a buffer-local value. It is equivalent to |
| 1437 | @code{setq}. @var{variable} should be an unquoted symbol. | 1437 | calling @code{make-local-variable} followed by @code{setq} for each of |
| 1438 | the 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 |
| @@ -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 | ||
| 2355 | makes 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 |
| 2355 | invisible and visible: It can also toggle 'display' properties in | 2358 | invisible and visible: It can also toggle 'display' properties in |
| 2356 | overlays. This is only done on 'display' properties that have the | 2359 | overlays. 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]...)" | 149 | PAIRS is a list of variable/value pairs. For each variable, make |
| 150 | ;; Can't use backquote here, it's too early in the bootstrap. | 150 | it buffer-local and assign it the corresponding value. The |
| 151 | (declare (debug (symbolp form))) | 151 | variables are literal symbols and should not be quoted. |
| 152 | (let ((expr)) | 152 | |
| 153 | (while args | 153 | The second VALUE is not computed until after the first VARIABLE |
| 154 | is set, and so on; each VALUE can use the new value of variables | ||
| 155 | set 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. |