diff options
| author | Helmut Eller | 2026-04-04 20:59:46 +0200 |
|---|---|---|
| committer | Helmut Eller | 2026-04-04 20:59:46 +0200 |
| commit | 6eec001187e8551f32b6498e6dc60cdc58c2e515 (patch) | |
| tree | 13233de9f0a05ef86a51500e8b1870b75ff20c81 /lisp/cus-edit.el | |
| parent | e4ea27119e79012f9d651cb61d1115589d91ef39 (diff) | |
| parent | 01a9d78a7e4c7d7fa5b799e4fdc2caf77a012734 (diff) | |
| download | emacs-feature/igc3.tar.gz emacs-feature/igc3.zip | |
Merge branch 'master' into feature/igc3feature/igc3
Diffstat (limited to 'lisp/cus-edit.el')
| -rw-r--r-- | lisp/cus-edit.el | 48 |
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. | ||
| 1110 | This is like `setq-local', but is meant for user options instead of | ||
| 1111 | plain 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 | |||
| 1115 | Note that `setopt-local' will emit a warning if the type of a VALUE does | ||
| 1116 | not match the type of the corresponding VARIABLE as declared by | ||
| 1117 | `defcustom'. (VARIABLE will be assigned the value even if it doesn't | ||
| 1118 | match the type.) | ||
| 1119 | |||
| 1120 | Signal 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. |
| 1111 | Return VALUE. | 1153 | Return VALUE. |