Function: setq-local

setq-local is a macro defined in subr.el.gz.

Signature

(setq-local [VARIABLE VALUE]...)

Documentation

Make variables in PAIRS buffer-local and assign them the corresponding values.

PAIRS is a list of variable/value pairs. For each variable, make it buffer-local and assign it the corresponding value. The variables are literal symbols and should not be quoted.

The second VALUE is not computed until after the first VARIABLE is set, and so on; each VALUE can use the new value of variables set earlier in the setq-local. The return value of the setq-local form is the value of the last VALUE.

Probably introduced at or before Emacs version 24.3.

Source Code

;; Defined in /usr/src/emacs/lisp/subr.el.gz
(defmacro setq-local (&rest pairs)
  "Make variables in PAIRS buffer-local and assign them the corresponding values.

PAIRS is a list of variable/value pairs.  For each variable, make
it buffer-local and assign it the corresponding value.  The
variables are literal symbols and should not be quoted.

The second VALUE is not computed until after the first VARIABLE
is set, and so on; each VALUE can use the new value of variables
set earlier in the `setq-local'.  The return value of the
`setq-local' form is the value of the last VALUE.

\(fn [VARIABLE VALUE]...)"
  (declare (debug setq))
  (unless (zerop (mod (length pairs) 2))
    (error "PAIRS must have an even number of variable/value members"))
  (let ((expr nil))
    (while pairs
      (unless (symbolp (car pairs))
        (error "Attempting to set a non-symbol: %s" (car pairs)))
      ;; Can't use backquote here, it's too early in the bootstrap.
      (setq expr
            (cons
             (list 'set
                   (list 'make-local-variable (list 'quote (car pairs)))
                   (car (cdr pairs)))
             expr))
      (setq pairs (cdr (cdr pairs))))
    (macroexp-progn (nreverse expr))))