unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Mauro Aranda <maurooaranda@gmail.com>
To: Thomas Fitzsimmons <fitzsim@fitzsim.org>, 63290@debbugs.gnu.org
Subject: bug#63290: 30.0.50; Customize UI shows extra fields for (choice (const ...) (alist ...))
Date: Wed, 9 Aug 2023 09:19:37 -0300	[thread overview]
Message-ID: <c801df02-7018-dd3d-d0ab-1ee73987bbac@gmail.com> (raw)
In-Reply-To: <136334d9-262d-e290-cff3-159c2f827b87@gmail.com>

[-- Attachment #1: Type: text/plain, Size: 289 bytes --]

tags 63290 patch
quit


I ended up adding a custom :default-get function for the list widget, to
make it respect a nil value as the :value.  This should be backward
compatible with other widgets, and should fix these "ghost" elements
insertions.

I also added a test for cus-edit-tests.


[-- Attachment #2: 0001-Respect-the-value-property-in-a-list-widget-Bug-6329.patch --]
[-- Type: text/x-patch, Size: 2838 bytes --]

From e64f9c55e1a1e57de3783fbbac1bf239ac30babb Mon Sep 17 00:00:00 2001
From: Mauro Aranda <maurooaranda@gmail.com>
Date: Wed, 9 Aug 2023 09:17:43 -0300
Subject: [PATCH] Respect the :value property in a list widget (Bug#63290)

* lisp/wid-edit.el (widget-list-default-get): New function.
* test/lisp/cus-edit-tests.el (cus-edit-test-bug-63290-option): New
test option.
(cus-edit-test-bug63290): New test.
---
 lisp/wid-edit.el            | 11 +++++++++++
 test/lisp/cus-edit-tests.el | 24 ++++++++++++++++++++++++
 2 files changed, 35 insertions(+)

diff --git a/lisp/wid-edit.el b/lisp/wid-edit.el
index 47531113ba8..c604225f10a 100644
--- a/lisp/wid-edit.el
+++ b/lisp/wid-edit.el
@@ -3812,8 +3812,19 @@ widget-character-notify
 (define-widget 'list 'group
   "A Lisp list."
   :tag "List"
+  :default-get #'widget-list-default-get
   :format "%{%t%}:\n%v")
 
+(defun widget-list-default-get (widget)
+  "Return the default external value for a list WIDGET.
+
+The default value is the one stored in the :value property, even if it is nil,
+or a list with the default value of each component of the list WIDGET."
+  (widget-apply widget :value-to-external
+                (if (widget-member widget :value)
+                    (widget-get widget :value)
+                  (widget-group-default-get widget))))
+
 (define-widget 'vector 'group
   "A Lisp vector."
   :tag "Vector"
diff --git a/test/lisp/cus-edit-tests.el b/test/lisp/cus-edit-tests.el
index eca35d7c96a..75d5f32c421 100644
--- a/test/lisp/cus-edit-tests.el
+++ b/test/lisp/cus-edit-tests.el
@@ -92,5 +92,29 @@ test-setopt
             (buffer-substring-no-properties (point-min) (point-max)))))
     (should (string-search "Value `:foo' does not match type number"
                            warn-txt))))
+
+(defcustom cus-edit-test-bug63290-option nil
+  "Choice option for testing Bug#63290."
+  :type '(choice (alist
+                  :key-type (string :tag "key")
+                  :value-type (string :tag "value"))
+                 (const :tag "auto" auto)))
+
+(ert-deftest cus-edit-test-bug63290 ()
+  "Test that changing a choice value back to an alist respects its nil value."
+  (customize-variable 'cus-edit-test-bug63290-option)
+  (search-forward "Value")
+  ;; Simulate changing the value.
+  (let* ((choice (widget-at))
+         (args (widget-get choice :args))
+         (list-opt (car (widget-get choice :children)))
+         (const-opt (nth 1 args)))
+    (widget-put choice :explicit-choice const-opt)
+    (widget-value-set choice (widget-default-get const-opt))
+    (widget-put choice :explicit-choice list-opt)
+    (widget-value-set choice (widget-default-get list-opt)))
+  ;; No empty key/value pairs should show up.
+  (should-not (search-forward "key" nil t)))
+
 (provide 'cus-edit-tests)
 ;;; cus-edit-tests.el ends here
-- 
2.34.1


  parent reply	other threads:[~2023-08-09 12:19 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-05  6:02 bug#63290: 30.0.50; Customize UI shows extra fields for (choice (const ...) (alist ...)) Thomas Fitzsimmons
2023-07-16 13:15 ` Mauro Aranda
2023-07-17  2:37   ` Thomas Fitzsimmons
2023-08-09 12:19   ` Mauro Aranda [this message]
2023-08-09 12:53     ` Eli Zaretskii
2023-08-09 15:51     ` Thomas Fitzsimmons
2023-08-09 15:56       ` Mauro Aranda
2023-08-09 18:03       ` Mauro Aranda
2023-08-10 22:58       ` Mauro Aranda
2023-08-11 13:29         ` Thomas Fitzsimmons
2023-08-15 22:46           ` Mauro Aranda
2023-08-16 15:16             ` Thomas Fitzsimmons
2023-08-19  8:34             ` Eli Zaretskii
2023-08-21 12:23 ` Mattias Engdegård
2023-08-21 14:43   ` Mauro Aranda
2023-08-21 15:24     ` Mattias Engdegård

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=c801df02-7018-dd3d-d0ab-1ee73987bbac@gmail.com \
    --to=maurooaranda@gmail.com \
    --cc=63290@debbugs.gnu.org \
    --cc=fitzsim@fitzsim.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).