Function: set-variable
set-variable is an interactive and byte-compiled function defined in
simple.el.gz.
Signature
(set-variable VARIABLE VALUE &optional MAKE-LOCAL)
Documentation
Set VARIABLE to VALUE. VALUE is a Lisp object.
VARIABLE should be a user option variable name, a Lisp variable meant to be customized by users. You should enter VALUE in Lisp syntax, so if you want VALUE to be a string, you must surround it with doublequotes. VALUE is used literally, not evaluated.
If VARIABLE has a variable-interactive property, that is used as if
it were the arg to interactive (which see) to interactively read VALUE.
If VARIABLE has been defined with defcustom, then the type information
in the definition is used to check that VALUE is valid.
Note that this function is at heart equivalent to the basic set function.
For a variable defined with defcustom, it does not pay attention to
any :set property that the variable might have (if you want that, use
M-x customize-set-variable (customize-set-variable) instead).
With a prefix argument, set VARIABLE to VALUE buffer-locally.
When called interactively, the user is prompted for VARIABLE and
then VALUE. The current value of VARIABLE will be put in the
minibuffer history so that it can be accessed with \M-n, which
makes it easier to edit it.
Key Bindings
Aliases
Source Code
;; Defined in /usr/src/emacs/lisp/simple.el.gz
(defun set-variable (variable value &optional make-local)
"Set VARIABLE to VALUE. VALUE is a Lisp object.
VARIABLE should be a user option variable name, a Lisp variable
meant to be customized by users. You should enter VALUE in Lisp syntax,
so if you want VALUE to be a string, you must surround it with doublequotes.
VALUE is used literally, not evaluated.
If VARIABLE has a `variable-interactive' property, that is used as if
it were the arg to `interactive' (which see) to interactively read VALUE.
If VARIABLE has been defined with `defcustom', then the type information
in the definition is used to check that VALUE is valid.
Note that this function is at heart equivalent to the basic `set' function.
For a variable defined with `defcustom', it does not pay attention to
any :set property that the variable might have (if you want that, use
\\[customize-set-variable] instead).
With a prefix argument, set VARIABLE to VALUE buffer-locally.
When called interactively, the user is prompted for VARIABLE and
then VALUE. The current value of VARIABLE will be put in the
minibuffer history so that it can be accessed with \\`M-n', which
makes it easier to edit it."
(interactive
(let* ((default-var (variable-at-point))
(var (if (custom-variable-p default-var)
(read-variable (format-prompt "Set variable" default-var)
default-var)
(read-variable "Set variable: ")))
(minibuffer-help-form `(describe-variable ',var))
(prop (get var 'variable-interactive))
(obsolete (car (get var 'byte-obsolete-variable)))
(prompt (format "Set %s %s to value: " var
(cond ((local-variable-p var)
"(buffer-local)")
((or current-prefix-arg
(local-variable-if-set-p var))
"buffer-locally")
(t "globally"))))
(val (progn
(when obsolete
(message (concat "`%S' is obsolete; "
(if (symbolp obsolete) "use `%S' instead" "%s"))
var obsolete)
(sit-for 3))
(if prop
;; Use VAR's `variable-interactive' property
;; as an interactive spec for prompting.
(call-interactively `(lambda (arg)
(interactive ,prop)
arg))
(read-from-minibuffer prompt nil
read-expression-map t
'set-variable-value-history
(format "%S" (symbol-value var)))))))
(list var val current-prefix-arg)))
(and (custom-variable-p variable)
(not (get variable 'custom-type))
(custom-load-symbol variable))
(let ((type (get variable 'custom-type)))
(when type
;; Match with custom type.
(require 'cus-edit)
(setq type (widget-convert type))
(unless (widget-apply type :match value)
(user-error "Value `%S' does not match type %S of %S"
value (car type) variable))))
(if make-local
(make-local-variable variable))
(set variable value)
;; Force a thorough redisplay for the case that the variable
;; has an effect on the display, like `tab-width' has.
(force-mode-line-update))