Function: setopt--set-local
setopt--set-local is an autoloaded and byte-compiled function defined
in cus-edit.el.gz.
Signature
(setopt--set-local VARIABLE VALUE)
Documentation
Set a buffer local VARIABLE to VALUE.
Consult setopt-local-type-mismatch.
Source Code
;; Defined in /usr/src/emacs/lisp/cus-edit.el.gz
;;;###autoload
(defun setopt--set-local (variable value)
"Set a buffer local VARIABLE to VALUE.
Consult `setopt-local-type-mismatch'."
(custom-load-symbol variable)
(let ((accept t))
;; Check that the type is correct.
(when-let* ((type (get variable 'custom-type)))
;; FIXME: If the var hasn't been initialized yet, `type' is nil and we
;; skip the type check altogether. Use `custom-check-values'?
(unless (widget-apply (widget-convert type) :match value)
(let ((msg (format-message
"Value does not match %S's type `%S': %S"
variable type value)))
;; FIXME: It's weird to do this `setopt-local-type-mismatch`
;; control for `setopt-local' and not for `setopt'.
(cond
;; Fall through and try anyway.
((eq setopt-local-type-mismatch 'accept))
;; Silently discard the mismatched value.
((eq setopt-local-type-mismatch 'discard)
(setq accept nil))
;; Prompt to accept or discard the value.
(setopt-local-type-mismatch
(setq accept (eq ?a (car (read-multiple-choice
msg
'((?a "accept" "Accept")
(?d "discard" "Discard")))))))
(t
(warn msg))))))
(when accept
(condition-case _
(funcall (or (get variable 'custom-set)
(lambda (x v &optional _) (set-local x v)))
variable value 'buffer-local)
(wrong-number-of-arguments
(warn "The setter of %S lacks support for setopt-local" variable)
(set-local variable value))))))