From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp1 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms11 with LMTPS id 8OEuLMeR119ycwAA0tVLHw (envelope-from ) for ; Mon, 14 Dec 2020 16:24:39 +0000 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp1 with LMTPS id aKwiKMeR11+yHwAAbx9fmQ (envelope-from ) for ; Mon, 14 Dec 2020 16:24:39 +0000 Received: from mail.notmuchmail.org (nmbug.tethera.net [144.217.243.247]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (2048 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 58DA5940111 for ; Mon, 14 Dec 2020 16:24:39 +0000 (UTC) Received: from nmbug.tethera.net (localhost [127.0.0.1]) by mail.notmuchmail.org (Postfix) with ESMTP id B008E29C88; Mon, 14 Dec 2020 11:24:19 -0500 (EST) Received: from mail.hostpark.net (mail.hostpark.net [212.243.197.30]) by mail.notmuchmail.org (Postfix) with ESMTPS id 62FA02853B for ; Mon, 14 Dec 2020 11:24:05 -0500 (EST) Received: from localhost (localhost [127.0.0.1]) by mail.hostpark.net (Postfix) with ESMTP id 85BA0165D1 for ; Mon, 14 Dec 2020 17:24:02 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=bernoul.li; h= content-transfer-encoding:mime-version:references:in-reply-to :x-mailer:message-id:date:date:subject:subject:from:from :received:received; s=sel2011a; t=1607963042; bh=+bg4nXimJZ3aFe0 fbEY0aAQ3exUoA7Hkjnu81QweNX0=; b=VL71lYiGng2/fU+3YrCsusHxiUWyeHW j77+LYTaNRewtvIcjV6rV/Exgx0B3mY4794wUdqiJUcQEt+7WCmYnFmXFeWOM7Cz w9YpoqR4zmTlawywI9OxAnkSmzQf5SGytHFZ12xZ//SrcpbHVekZDe8ZOLKO1AhU FclkfAky38IU= X-Virus-Scanned: by Hostpark/NetZone Mailprotection at hostpark.net Received: from mail.hostpark.net ([127.0.0.1]) by localhost (mail0.hostpark.net [127.0.0.1]) (amavisd-new, port 10224) with ESMTP id nDNpT5gE9Wjh for ; Mon, 14 Dec 2020 17:24:02 +0100 (CET) Received: from customer (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mail.hostpark.net (Postfix) with ESMTPSA id 405E5165D6 for ; Mon, 14 Dec 2020 17:24:02 +0100 (CET) From: Jonas Bernoulli To: notmuch@notmuchmail.org Subject: [PATCH 02/32] emacs: sanitize dedicated widget action/notify functions Date: Mon, 14 Dec 2020 17:23:31 +0100 Message-Id: <20201214162401.19569-3-jonas@bernoul.li> X-Mailer: git-send-email 2.29.1 In-Reply-To: <20201214162401.19569-1-jonas@bernoul.li> References: <20201214162401.19569-1-jonas@bernoul.li> MIME-Version: 1.0 Message-ID-Hash: CDEQ4UBE22FP6OCWJH3633NRYPY4E5MP X-Message-ID-Hash: CDEQ4UBE22FP6OCWJH3633NRYPY4E5MP X-MailFrom: jonas@bernoul.li X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-notmuch.notmuchmail.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header X-Mailman-Version: 3.2.1 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Help: List-Post: List-Subscribe: List-Unsubscribe: Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Migadu-Flow: FLOW_IN X-Migadu-Spam-Score: 1.42 Authentication-Results: aspmx1.migadu.com; dkim=fail (body hash did not verify) header.d=bernoul.li header.s=sel2011a header.b=VL71lYiG; dmarc=none; spf=pass (aspmx1.migadu.com: domain of notmuch-bounces@notmuchmail.org designates 144.217.243.247 as permitted sender) smtp.mailfrom=notmuch-bounces@notmuchmail.org X-Migadu-Queue-Id: 58DA5940111 X-Spam-Score: 1.42 X-Migadu-Scanner: scn0.migadu.com X-TUID: gM8By20FOfyh 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 incompatibilities. 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: " notmuch-saved-searches))) ;; 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) (notmuch-hello-update))) -(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))) (notmuch-hello-update))) (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 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 "save") (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 "del")) (widget-insert "\n")) -- 2.29.1