From: Mauro Aranda <maurooaranda@gmail.com>
To: 63838@debbugs.gnu.org
Cc: Marco Antoniotti <marcoxa@gmail.com>
Subject: bug#63838: 28.2; 'wid-edit.el' problems with 'integer' (and 'sexp') widgets.
Date: Sat, 9 Sep 2023 12:13:53 -0300 [thread overview]
Message-ID: <93b7830c-edd5-3462-bdbd-2fd18c1fdb0f@gmail.com> (raw)
In-Reply-To: <174623a9-45bf-10d1-8b59-cb5b816026bc@gmail.com>
[-- Attachment #1: Type: text/plain, Size: 105 bytes --]
tags 63838 patch
quit
I attach a patch to handle an empty restricted sexp widget, together
with a test.
[-- Attachment #2: 0001-Avoid-errors-when-a-restricted-sexp-widget-is-empty.patch --]
[-- Type: text/x-patch, Size: 2048 bytes --]
From a43899c409703af4966e619a92bda123e80122e0 Mon Sep 17 00:00:00 2001
From: Mauro Aranda <maurooaranda@gmail.com>
Date: Sat, 9 Sep 2023 21:59:30 +0800
Subject: [PATCH] Avoid errors when a restricted-sexp widget is empty
* lisp/wid-edit.el (restricted-sexp): Don't try to read
an empty string when converting the current value to the
external format. (Bug#63838)
* test/lisp/wid-edit-tests.el (widget-test-restricted-sexp-empty-val):
New test.
---
lisp/wid-edit.el | 4 +++-
test/lisp/wid-edit-tests.el | 11 +++++++++++
2 files changed, 14 insertions(+), 1 deletion(-)
diff --git a/lisp/wid-edit.el b/lisp/wid-edit.el
index d18d721f7ed..74412414113 100644
--- a/lisp/wid-edit.el
+++ b/lisp/wid-edit.el
@@ -3681,7 +3681,9 @@ 'restricted-sexp
:warning)
;; Make sure we will `read' a string.
(setq value (prin1-to-string value)))
- (read value)))
+ (if (string-empty-p value)
+ value
+ (read value))))
(defun widget-restricted-sexp-match (widget value)
(let ((alternatives (widget-get widget :match-alternatives))
diff --git a/test/lisp/wid-edit-tests.el b/test/lisp/wid-edit-tests.el
index ebfe729bc9a..66bff4ad2e3 100644
--- a/test/lisp/wid-edit-tests.el
+++ b/test/lisp/wid-edit-tests.el
@@ -380,4 +380,15 @@ widget-test-alist-default-value-4
:value (("1" . 1) ("2" . 2))))))
(should (equal '(("1" . 1) ("2" . 2)) (widget-default-get w))))))
+(ert-deftest widget-test-restricted-sexp-empty-val ()
+ "Test that we handle an empty restricted-sexp widget just fine."
+ (with-temp-buffer
+ (let ((w (widget-create '(restricted-sexp
+ :value 3
+ :match-alternatives (integerp)))))
+ (widget-setup)
+ (widget-backward 1)
+ (delete-char 1)
+ (should (string= (widget-value w) "")))))
+
;;; wid-edit-tests.el ends here
--
2.34.1
next prev parent reply other threads:[~2023-09-09 15:13 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-06-02 9:49 bug#63838: 28.2; 'wid-edit.el' problems with 'integer' (and 'sexp') widgets Marco Antoniotti
2023-07-16 11:50 ` Mauro Aranda
2023-09-09 15:13 ` Mauro Aranda [this message]
2023-09-16 9:58 ` Eli Zaretskii
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=93b7830c-edd5-3462-bdbd-2fd18c1fdb0f@gmail.com \
--to=maurooaranda@gmail.com \
--cc=63838@debbugs.gnu.org \
--cc=marcoxa@gmail.com \
/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).