From f61db2a0378e2bedef209706c6a88da678d4a3f4 Mon Sep 17 00:00:00 2001 From: Mauro Aranda Date: Sat, 15 Feb 2025 09:26:46 -0300 Subject: [PATCH] Fix comparison of current values for the key-sequence :type * lisp/cus-edit.el (custom-variable-modified-p): Round-trip the option value before comparing it against the widget's value. This mostly fixes comparison against the obsolete key-sequence widget, but could fix other corner cases, when the widget accepts different types as values. (Bug#76156) * test/lisp/cus-edit-tests.el (cus-edit-test-bug76156) (cus-edit-test-bug76156-2): New test options. (cus-edit-test-unedited-option): New test. (cherry picked from commit f549cedaa2721bfc463fe714c00016aed21f7b5c) --- lisp/cus-edit.el | 17 ++++++++++++----- test/lisp/cus-edit-tests.el | 18 ++++++++++++++++++ 2 files changed, 30 insertions(+), 5 deletions(-) diff --git a/lisp/cus-edit.el b/lisp/cus-edit.el index 16985fb44d7..1bdc5a287d6 100644 --- a/lisp/cus-edit.el +++ b/lisp/cus-edit.el @@ -3105,11 +3105,18 @@ To check for other states, call `custom-variable-state'." (let* ((form (widget-get widget :custom-form)) (symbol (widget-get widget :value)) (get (or (get symbol 'custom-get) 'default-value)) - (value (if (default-boundp symbol) - (condition-case nil - (funcall get symbol) - (error (throw 'get-error t))) - (symbol-value symbol))) + (value-widget (car (widget-get widget :children))) + ;; Round-trip the value, for the sake of widgets that accept + ;; values of different types (e.g., the obsolete key-sequence widget + ;; which takes either strings or vectors. (Bug#76156) + (value + (widget-apply value-widget :value-to-external + (widget-apply value-widget :value-to-internal + (if (default-boundp symbol) + (condition-case nil + (funcall get symbol) + (error (throw 'get-error t))) + (symbol-value symbol))))) (orig-value (widget-value (car (widget-get widget :children))))) (not (equal (if (memq form '(lisp mismatch)) ;; Mimic `custom-variable-value-create'. diff --git a/test/lisp/cus-edit-tests.el b/test/lisp/cus-edit-tests.el index 2a122db9da9..f898607ba26 100644 --- a/test/lisp/cus-edit-tests.el +++ b/test/lisp/cus-edit-tests.el @@ -134,5 +134,23 @@ ;; No empty key/value pairs should show up. (should-not (search-forward "key" nil t))) +(defcustom cus-edit-test-bug76156 "\C-c " + "Key-sequence option that might show up as EDITED even though it's not." + :type 'key-sequence) + +(defcustom cus-edit-test-bug76156-2 [(control ?z)] + "Key-sequence option that might show up as EDITED even though it's not." + :type 'key-sequence) + +(ert-deftest cus-edit-test-unedited-option () + "Test that customizing unedited options doesn't show up as EDITED." + (dolist (option '(cus-edit-test-bug76156 + cus-edit-test-bug76156-2 + cus-edit-test-foo1)) + (customize-option option) + (let ((widget (car custom-options))) + (should (eq (widget-get widget :custom-state) 'standard))) + (kill-buffer))) + (provide 'cus-edit-tests) ;;; cus-edit-tests.el ends here -- 2.39.5