Function: setq-local

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

Signature

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

Documentation

Make each VARIABLE local to current buffer and set it to corresponding VALUE.

The arguments are variable/value pairs. For each VARIABLE in a pair, make VARIABLE buffer-local in the current buffer and assign to it the corresponding VALUE of the pair. The VARIABLEs are literal symbols and should not be quoted.

The VALUE of the Nth pair is not computed until after the VARIABLE of the (N-1)th pair is set; thus, each VALUE can use the new VALUEs of VARIABLEs set by earlier pairs.

The return value of the setq-local form is the VALUE of the last pair.

In some corner cases you may need to resort to set-buffer-local-toplevel-value instead, which see.

View in manual

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 each VARIABLE local to current buffer and set it to corresponding VALUE.

The arguments are variable/value pairs.  For each VARIABLE in a pair,
make VARIABLE buffer-local in the current buffer and assign to it the
corresponding VALUE of the pair.  The VARIABLEs are literal symbols
and should not be quoted.

The VALUE of the Nth pair is not computed until after the VARIABLE
of the (N-1)th pair is set; thus, each VALUE can use the new VALUEs
of VARIABLEs set by earlier pairs.

The return value of the `setq-local' form is the VALUE of the last
pair.

In some corner cases you may need to resort to
`set-buffer-local-toplevel-value' instead, which see.

\(fn [VARIABLE VALUE]...)"
  (declare (debug setq))
  (unless (evenp (length pairs))
    (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 'setq (car pairs)
                   (list 'prog1
                    (car (cdr pairs))
                    (list 'make-local-variable (list 'quote (car pairs)))))
             expr))
      (setq pairs (cdr (cdr pairs))))
    (macroexp-progn (nreverse expr))))