unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* giving `setq-local' the same signature as `setq'
@ 2015-03-18 15:26 Jordon Biondo
  2015-03-18 16:24 ` Stefan Monnier
  0 siblings, 1 reply; 9+ messages in thread
From: Jordon Biondo @ 2015-03-18 15:26 UTC (permalink / raw)
  To: emacs-devel

I’ve often run into an issue when assuming `setq-local’ behave like `setq’ by accepting multiple [SYM VAL] pairs and returning the value assigned to the last symbol rather than only accepting one symbol and one value.

This is my patch that modifies `setq-local’ to behave this way. Please advise on why this can or shouldn’t be applied.

Note that I have not filled out the copyright assignment paperwork, so if it is to be applied, please send send in the right direction to get the paperwork taken care of.

Thank You

- Jordon Biondo



diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index d61a0a6..8154d60 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,8 @@
+2015-03-18  Jordon Biondo  <jordonbiondo@gmail.com>
+
+	* lisp/subr.el (setq-local): Can now set multiple local variables
+	like `setq'.
+
 2015-03-18  Dima Kogan  <dima@secretsauce.net>
 
 	Have gud-display-line not display source buffer in gud window.
diff --git a/lisp/subr.el b/lisp/subr.el
index deadca6..41340f0 100644
--- a/lisp/subr.el
+++ b/lisp/subr.el
@@ -116,10 +116,21 @@ BODY should be a list of Lisp expressions.
   ;; depend on backquote.el.
   (list 'function (cons 'lambda cdr)))
 
-(defmacro setq-local (var val)
-  "Set variable VAR to value VAL in current buffer."
+(defmacro setq-local (&rest args)
+  "Set each SYM to the value of its VAL in the current buffer.
+
+\(fn [SYM VAL]...)"
   ;; Can't use backquote here, it's too early in the bootstrap.
-  (list 'set (list 'make-local-variable (list 'quote var)) val))
+  (let ((expr))
+    (while args
+      (setq expr
+            (cons
+             (list 'set
+                   (list 'make-local-variable (list 'quote (car args)))
+                   (car (cdr args)))
+             expr))
+      (setq args (cdr (cdr args))))
+    (cons 'progn (nreverse expr))))
 
 (defmacro defvar-local (var val &optional docstring)
   "Define VAR as a buffer-local variable with default value VAL.




^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2015-03-19 17:25 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-03-18 15:26 giving `setq-local' the same signature as `setq' Jordon Biondo
2015-03-18 16:24 ` Stefan Monnier
2015-03-19 14:08   ` Richard Stallman
2015-03-19 14:48     ` Jordon Biondo
2015-03-19 15:11       ` Drew Adams
2015-03-19 15:17         ` Oleh Krehel
2015-03-19 15:39           ` Drew Adams
2015-03-19 15:55             ` Oleh Krehel
2015-03-19 17:25               ` Drew Adams

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).