aboutsummaryrefslogtreecommitdiffstats
path: root/lisp/cus-edit.el
diff options
context:
space:
mode:
Diffstat (limited to 'lisp/cus-edit.el')
-rw-r--r--lisp/cus-edit.el48
1 files changed, 45 insertions, 3 deletions
diff --git a/lisp/cus-edit.el b/lisp/cus-edit.el
index 52677f435ee..87d8ecade54 100644
--- a/lisp/cus-edit.el
+++ b/lisp/cus-edit.el
@@ -1084,7 +1084,7 @@ even if it doesn't match the type.)
1084\(fn [VARIABLE VALUE]...)" 1084\(fn [VARIABLE VALUE]...)"
1085 (declare (debug setq)) 1085 (declare (debug setq))
1086 (unless (evenp (length pairs)) 1086 (unless (evenp (length pairs))
1087 (error "PAIRS must have an even number of variable/value members")) 1087 (signal 'wrong-number-of-arguments (list 'setopt (length pairs))))
1088 (let ((expr nil)) 1088 (let ((expr nil))
1089 (while pairs 1089 (while pairs
1090 (unless (symbolp (car pairs)) 1090 (unless (symbolp (car pairs))
@@ -1100,12 +1100,54 @@ even if it doesn't match the type.)
1100 ;; Check that the type is correct. 1100 ;; Check that the type is correct.
1101 (when-let* ((type (get variable 'custom-type))) 1101 (when-let* ((type (get variable 'custom-type)))
1102 (unless (widget-apply (widget-convert type) :match value) 1102 (unless (widget-apply (widget-convert type) :match value)
1103 (warn "Value `%S' for variable `%s' does not match its type \"%s\"" 1103 (warn "Value does not match %S's type `%S': %S" variable type value)))
1104 value variable type)))
1105 (put variable 'custom-check-value (list value)) 1104 (put variable 'custom-check-value (list value))
1106 (funcall (or (get variable 'custom-set) #'set-default) variable value)) 1105 (funcall (or (get variable 'custom-set) #'set-default) variable value))
1107 1106
1108;;;###autoload 1107;;;###autoload
1108(defmacro setopt-local (&rest pairs)
1109 "Set buffer local VARIABLE/VALUE pairs, and return the final VALUE.
1110This is like `setq-local', but is meant for user options instead of
1111plain variables. This means that `setopt-local' will execute any
1112`custom-set' form associated with VARIABLE. Unlike `setopt',
1113`setopt-local' does not affect a user option's global value.
1114
1115Note that `setopt-local' will emit a warning if the type of a VALUE does
1116not match the type of the corresponding VARIABLE as declared by
1117`defcustom'. (VARIABLE will be assigned the value even if it doesn't
1118match the type.)
1119
1120Signal an error if a `custom-set' form does not support the
1121`buffer-local' argument.
1122
1123\(fn [VARIABLE VALUE]...)"
1124 (declare (debug setq))
1125 (unless (evenp (length pairs))
1126 (signal 'wrong-number-of-arguments (list 'setopt-local (length pairs))))
1127 (let ((expr nil))
1128 (while pairs
1129 (unless (symbolp (car pairs))
1130 (error "Attempting to set a non-symbol: %s" (car pairs)))
1131 (push `(setopt--set-local ',(car pairs) ,(cadr pairs))
1132 expr)
1133 (setq pairs (cddr pairs)))
1134 (macroexp-progn (nreverse expr))))
1135
1136;;;###autoload
1137(defun setopt--set-local (variable value)
1138 (custom-load-symbol variable)
1139 ;; Check that the type is correct.
1140 (when-let* ((type (get variable 'custom-type)))
1141 (unless (widget-apply (widget-convert type) :match value)
1142 (warn "Value does not match %S's type `%S': %S" variable type value)))
1143 (condition-case _
1144 (funcall (or (get variable 'custom-set)
1145 (lambda (x v &optional _) (set-local x v)))
1146 variable value 'buffer-local)
1147 (wrong-number-of-arguments
1148 (error "The setter of %S does not support setopt-local" variable))))
1149
1150;;;###autoload
1109(defun customize-save-variable (variable value &optional comment) 1151(defun customize-save-variable (variable value &optional comment)
1110 "Set the default for VARIABLE to VALUE, and save it for future sessions. 1152 "Set the default for VARIABLE to VALUE, and save it for future sessions.
1111Return VALUE. 1153Return VALUE.