(custom--standard-value-p): New function

* lisp/cus-edit.el (custom-variable-state)
(custom-variable-mark-to-reset-standard): Use `custom--standard-value-p`.

* lisp/custom.el (custom--standard-value-p): New function.
(customize-mark-to-save, custom-push-theme, enable-theme): Use it.

* lisp/help-fns.el (describe-variable): Use `custom--standard-value`.
Extracted from `customize-mark-to-save` by with `ignore-errors`
replaced by `with-demoted-errors`.
This commit is contained in:
Stefan Monnier 2025-04-01 18:06:31 -04:00
parent da6da5744b
commit 71b3298c0e
3 changed files with 23 additions and 23 deletions

View file

@ -448,11 +448,13 @@
(defvar custom-field-keymap
(let ((map (copy-keymap widget-field-keymap)))
(define-key map "\C-c\C-c" 'Custom-set)
(define-key map "\C-x\C-s" 'Custom-save)
(define-key map "\C-c\C-c" #'Custom-set)
(define-key map "\C-x\C-s" #'Custom-save)
map)
"Keymap used inside editable fields in customization buffers.")
;; FIXME: Doesn't this affect all `editable-field's ever? Why not set
;; the right keymap right away when we (define-widget 'editable-field ...)?
(widget-put (get 'editable-field 'widget-type) :keymap custom-field-keymap)
;;; Utilities.
@ -3004,7 +3006,7 @@ Possible return values are `standard', `saved', `set', `themed',
(and (equal value (eval (car tmp)))
(equal comment temp))
(error nil))
(if (equal value (eval (car (get symbol 'standard-value))))
(if (custom--standard-value-p symbol value)
'standard
'set)
'changed))
@ -3348,8 +3350,8 @@ If `custom-reset-standard-variables-list' is nil, save, reset and
redraw the widget immediately."
(let* ((symbol (widget-value widget)))
(if (get symbol 'standard-value)
(unless (equal (custom-variable-current-value widget)
(eval (car (get symbol 'standard-value))))
(unless (custom--standard-value-p
symbol (custom-variable-current-value widget))
(custom-variable-backup-value widget))
(user-error "No standard setting known for %S" symbol))
(put symbol 'variable-comment nil)
@ -5176,7 +5178,7 @@ This function does not save the buffer."
(defun custom-save-faces ()
"Save all customized faces in `custom-file'."
(save-excursion
(custom-save-delete 'custom-reset-faces)
(custom-save-delete 'custom-reset-faces) ;FIXME: Never written!?
(custom-save-delete 'custom-set-faces)
(let ((standard-output (current-buffer))
(saved-list (make-list 1 0)))
@ -5336,9 +5338,9 @@ The format is suitable for use with `easy-menu-define'."
(defvar tool-bar-map)
;;; `custom-tool-bar-map' used to be set up here. This will fail to
;;; DTRT when `display-graphic-p' returns nil during compilation. Hence
;;; we set this up lazily in `Custom-mode'.
;; `custom-tool-bar-map' used to be set up here. This will fail to
;; DTRT when `display-graphic-p' returns nil during compilation. Hence
;; we set this up lazily in `Custom-mode'.
(defvar custom-tool-bar-map nil
"Keymap for toolbar in Custom mode.")
@ -5464,7 +5466,7 @@ if that value is non-nil."
(make-local-variable 'custom-options)
(make-local-variable 'custom-local-buffer)
(custom--initialize-widget-variables)
(add-hook 'widget-edit-functions 'custom-state-buffer-message nil t))
(add-hook 'widget-edit-functions #'custom-state-buffer-message nil t))
(defun custom--revert-buffer (_ignore-auto _noconfirm)
(unless custom--invocation-options

View file

@ -390,9 +390,6 @@ See Info node `(elisp) Customization' in the Emacs Lisp manual
for more information."
(declare (doc-string 3) (debug (name body))
(indent defun))
;; It is better not to use backquote in this file,
;; because that makes a bootstrapping problem
;; if you need to recompile all the Lisp files using interpreted code.
`(custom-declare-variable
',symbol
,(if lexical-binding
@ -635,7 +632,7 @@ For other custom types, this has no effect."
(let ((options (get symbol 'custom-options)))
(unless (member option options)
(put symbol 'custom-options (cons option options)))))
(defalias 'custom-add-frequent-value 'custom-add-option)
(defalias 'custom-add-frequent-value #'custom-add-option)
(defun custom-add-link (symbol widget)
"To the custom option SYMBOL add the link WIDGET."
@ -680,6 +677,11 @@ property, or (ii) an alias for another customizable variable."
"Return the standard value of VARIABLE."
(eval (car (get variable 'standard-value)) t))
(defun custom--standard-value-p (variable value)
"Return non-nil if VALUE is `equal' to the standard value of VARIABLE."
(let ((sv (get variable 'standard-value)))
(and sv (equal value (eval (with-demoted-errors "%S" (car sv)) t)))))
(defun custom-note-var-changed (variable)
"Inform Custom that VARIABLE has been set (changed).
VARIABLE is a symbol that names a user option.
@ -777,12 +779,10 @@ Return non-nil if the `saved-value' property actually changed."
(let* ((get (or (get symbol 'custom-get) #'default-value))
(value (funcall get symbol))
(saved (get symbol 'saved-value))
(standard (get symbol 'standard-value))
(comment (get symbol 'customized-variable-comment)))
;; Save default value if different from standard value.
(put symbol 'saved-value
(unless (and standard
(equal value (ignore-errors (eval (car standard)))))
(unless (custom--standard-value-p symbol value)
(list (custom-quote value))))
;; Clear customized information (set, but not saved).
(put symbol 'customized-value nil)
@ -965,12 +965,11 @@ See `custom-known-themes' for a list of known themes."
;; recompute when the theme is disabled.
(when (and (eq prop 'theme-value)
(boundp symbol))
(let ((sv (get symbol 'standard-value))
(val (symbol-value symbol)))
(let ((val (symbol-value symbol)))
(unless (or
;; We only do this trick if the current value
;; is different from the standard value.
(and sv (equal (eval (car sv)) val))
(custom--standard-value-p symbol val)
;; And we don't do it if we would end up recording
;; the same value for the user theme. This way we avoid
;; having ((user VALUE) (changed VALUE)). That would be
@ -1560,7 +1559,6 @@ After THEME has been enabled, runs `enable-theme-functions'."
(let* ((prop (car s))
(symbol (cadr s))
(spec-list (get symbol prop))
(sv (get symbol 'standard-value))
(val (and (boundp symbol) (symbol-value symbol))))
;; We can't call `custom-push-theme' when enabling the theme: it's not
;; that the theme settings have changed, it's just that we want to
@ -1575,7 +1573,7 @@ After THEME has been enabled, runs `enable-theme-functions'."
(not (or spec-list
;; Only if the current value is different from
;; the standard value.
(and sv (equal (eval (car sv)) val))
(custom--standard-value-p symbol val)
;; And only if the changed value is different
;; from the new value under the user theme.
(and (eq theme 'user)

View file

@ -1455,7 +1455,7 @@ it is displayed along with the global value."
(let* ((sv (get variable 'standard-value))
(origval (and (consp sv)
(condition-case nil
(eval (car sv) t)
(custom--standard-value variable)
(error :help-eval-error))))
from)
(when (and (consp sv)