Subject: bug#75714: 31.0.50; Empty search string gives error in Customize buffer

From: Mauro Aranda <[email-masked]>
Date: Mon, 20 Jan 2025 21:24:32 -0300

tags 75714 patch
quit

Drew Adams <[email-masked]> writes:

 >> After emacs -Q do:
 >> M-x customize-group RET RET
 >> C-n 3 times, to get to the Search field.
 >> RET
 >>
 >> This gives an error:
 >> apropos-parse-pattern: Wrong type argument: stringp, nil
 >>
 >> It'd be a tiny improvement to message the user instead.
 >
 > Good catch.

Thanks Drew.  Although it was pure luck: I was trying to improve other
aspects of the editable-field widget.

 > FWIW, this goes back to Emacs 24, when
 > the Search field was introduced.

Let's not let it turn 15 years old.  I attach a patch.

From a4c67889b0d56684982b9254bd8ed8865756abad Mon Sep 17 00:00:00 2001
From: Mauro Aranda <[email-masked]>
Date: Mon, 20 Jan 2025 21:16:48 -0300
Subject: [PATCH] Avoid error with empty search string in Customize

* lisp/cus-edit.el (custom-buffer-create-internal): Only call
customize-apropos if the string is not empty.  (Bug#75714)
---
 lisp/cus-edit.el | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/lisp/cus-edit.el b/lisp/cus-edit.el
index 95dd4c9e354..febbc8d1b8b 100644
--- a/lisp/cus-edit.el
+++ b/lisp/cus-edit.el
@@ -1774,14 +1774,17 @@ custom-buffer-create-internal
 	       'editable-field
 	       :size 40 :help-echo echo
 	       :action (lambda (widget &optional _event)
-                         (customize-apropos (split-string (widget-value widget)))))))
+                         (let ((value (widget-value widget)))
+                           (if (string= value "")
+                               (message "Empty search field")
+                             (customize-apropos (split-string value))))))))
 	(widget-insert " ")
 	(widget-create-child-and-convert
 	 search-widget 'push-button
 	 :tag " Search "
 	 :help-echo echo :action
 	 (lambda (widget &optional _event)
-	   (customize-apropos (split-string (widget-value (widget-get widget :parent))))))
+           (widget-apply (widget-get widget :parent) :action)))
 	(widget-insert "\n")))
 
     ;; The custom command buttons are also in the toolbar, so for a
-- 
2.34.1