[PATCH 02/32] emacs: sanitize dedicated widget action/notify functions

Subject: [PATCH 02/32] emacs: sanitize dedicated widget action/notify functions

Date: Mon, 14 Dec 2020 17:23:31 +0100

To: notmuch@notmuchmail.org


From: Jonas Bernoulli

These functions are used as action/notify functions.  That dictates
the appropriate function signatures but even though these functions
are not used for anything else they use incompatible signatures,
forcing the callers to use lambda expressions to deal with these

Fix that by adjusting the function signatures to the needs of the
only intended callers.

Two of these functions were defined as commands but because the
interactive form did not return the mandatory arguments, we know
that nobody (successfully) used these as commands.

In one case we move the location of a y-or-n-p prompt.
 emacs/notmuch-hello.el | 47 +++++++++++++++++-------------------------
 1 file changed, 19 insertions(+), 28 deletions(-)

diff --git a/emacs/notmuch-hello.el b/emacs/notmuch-hello.el
index fa31694f..767c6874 100644
--- a/emacs/notmuch-hello.el
+++ b/emacs/notmuch-hello.el
@@ -385,18 +385,16 @@ (defun notmuch-hello-nice-number (n)
 		     (format "%s%03d" notmuch-hello-thousands-separator elem))
 		   (cdr result)))))
-(defun notmuch-hello-search (&optional search)
-  (unless (null search)
-    (setq search (string-trim search))
-    (let ((history-delete-duplicates t))
-      (add-to-history 'notmuch-search-history search)))
-  (notmuch-search search notmuch-search-oldest-first))
-(defun notmuch-hello-add-saved-search (widget)
-  (interactive)
-  (let ((search (widget-value
-		 (symbol-value
-		  (widget-get widget :notmuch-saved-search-widget))))
+(defun notmuch-hello-search (widget &rest _event)
+  (let ((search (widget-value widget)))
+    (when search
+      (setq search (string-trim search))
+      (let ((history-delete-duplicates t))
+	(add-to-history 'notmuch-search-history search)))
+    (notmuch-search search notmuch-search-oldest-first)))
+(defun notmuch-hello-add-saved-search (widget &rest _event)
+  (let ((search (widget-value (widget-get widget :parent)))
 	(name (completing-read "Name for saved search: "
     ;; If an existing saved search with this name exists, remove it.
@@ -412,13 +410,11 @@ (defun notmuch-hello-add-saved-search (widget)
     (message "Saved '%s' as '%s'." search name)
-(defun notmuch-hello-delete-search-from-history (widget)
-  (interactive)
-  (let ((search (widget-value
-		 (symbol-value
-		  (widget-get widget :notmuch-saved-search-widget)))))
-    (setq notmuch-search-history (delete search
-					 notmuch-search-history))
+(defun notmuch-hello-delete-search-from-history (widget &rest _event)
+  (when (y-or-n-p "Are you sure you want to delete this search? ")
+    (let ((search (widget-value (widget-get widget :parent))))
+      (setq notmuch-search-history
+	    (delete search notmuch-search-history)))
 (defun notmuch-hello-longest-label (searches-alist)
@@ -768,8 +764,7 @@ (defun notmuch-hello-insert-search ()
 		 ;; search boxes.
 		 :size (max 8 (- (window-width) notmuch-hello-indent
 				 (length "Search: ")))
-		 :action (lambda (widget &rest ignore)
-			   (notmuch-hello-search (widget-value widget))))
+		 :action #'notmuch-hello-search)
   ;; Add an invisible dot to make `widget-end-of-line' ignore
   ;; trailing spaces in the search widget field.  A dot is used
   ;; instead of a space to make `show-trailing-whitespace'
@@ -816,20 +811,16 @@ (defun notmuch-hello-insert-recent-searches ()
 						   ;; button. 5 for the
 						   ;; `[del]' button.
 						   1 5))
-				     :action (lambda (widget &rest ignore)
-					       (notmuch-hello-search (widget-value widget)))
+				     :action #'notmuch-hello-search
 		 (widget-insert " ")
 		 (widget-create 'push-button
-				:notify (lambda (widget &rest ignore)
-					  (notmuch-hello-add-saved-search widget))
+				:notify #'notmuch-hello-add-saved-search
 				:notmuch-saved-search-widget widget-symbol
 		 (widget-insert " ")
 		 (widget-create 'push-button
-				:notify (lambda (widget &rest ignore)
-					  (when (y-or-n-p "Are you sure you want to delete this search? ")
-					    (notmuch-hello-delete-search-from-history widget)))
+				:notify #'notmuch-hello-delete-search-from-history
 				:notmuch-saved-search-widget widget-symbol
 	       (widget-insert "\n"))
notmuch mailing list -- notmuch@notmuchmail.org
To unsubscribe send an email to notmuch-leave@notmuchmail.org