]> git.eshelyaron.com Git - emacs.git/commitdiff
(custom--standard-value-p): New function
authorStefan Monnier <monnier@iro.umontreal.ca>
Tue, 1 Apr 2025 22:06:31 +0000 (18:06 -0400)
committerEshel Yaron <me@eshelyaron.com>
Thu, 3 Apr 2025 16:50:47 +0000 (18:50 +0200)
* 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
lisp/custom.el
lisp/help-fns.el

index a5cf5f933856c540fd4288027f4785f3bc1a29ab..1f3eab78d6a872ea6096b2db1e2e7543daaec497 100644 (file)
 
 (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
index 1cbc1f53eeda988be59191e8ccebe02a282ad261..048e4a55c72baf9f5365611a28a2d48a4f248dbe 100644 (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
@@ -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)
index dedafb74073055adcc226806b9f68b457db3d281..8937e567b444e6c732b64a6196e7c8f3acd36801 100644 (file)
@@ -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)