emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

giving `setq-local' the same signature as `setq'


From: Jordon Biondo
Subject: giving `setq-local' the same signature as `setq'
Date: Wed, 18 Mar 2015 11:26:01 -0400

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  <address@hidden>
+
+       * lisp/subr.el (setq-local): Can now set multiple local variables
+       like `setq'.
+
 2015-03-18  Dima Kogan  <address@hidden>
 
        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.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]