From 3d4962e9857d9ba04c475868614b002a09d18615 Mon Sep 17 00:00:00 2001 From: Stefan Monnier Date: Tue, 1 Apr 2025 18:06:31 -0400 Subject: [PATCH] (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`. (cherry picked from commit 71b3298c0e813ba1432e75370c460eea5caf72d5) --- lisp/cus-edit.el | 22 ++++++++++++---------- lisp/custom.el | 22 ++++++++++------------ lisp/help-fns.el | 2 +- 3 files changed, 23 insertions(+), 23 deletions(-) diff --git a/lisp/cus-edit.el b/lisp/cus-edit.el index a5cf5f93385..1f3eab78d6a 100644 --- a/lisp/cus-edit.el +++ b/lisp/cus-edit.el @@ -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. @@ -3055,7 +3057,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)) @@ -3399,8 +3401,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) @@ -5221,7 +5223,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))) @@ -5381,9 +5383,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.") @@ -5509,7 +5511,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 diff --git a/lisp/custom.el b/lisp/custom.el index 1cbc1f53eed..048e4a55c72 100644 --- a/lisp/custom.el +++ b/lisp/custom.el @@ -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 @@ -634,7 +631,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." @@ -679,6 +676,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. @@ -776,12 +778,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) @@ -964,12 +964,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) diff --git a/lisp/help-fns.el b/lisp/help-fns.el index dedafb74073..8937e567b44 100644 --- a/lisp/help-fns.el +++ b/lisp/help-fns.el @@ -1472,7 +1472,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) -- 2.39.5