From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp2 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms11 with LMTPS id IN10AdEI+198bwAA0tVLHw (envelope-from ) for ; Sun, 10 Jan 2021 14:01:53 +0000 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp2 with LMTPS id KP3TONAI+18XcQAAB5/wlQ (envelope-from ) for ; Sun, 10 Jan 2021 14:01:52 +0000 Received: from mail.notmuchmail.org (nmbug.tethera.net [IPv6:2607:5300:201:3100::1657]) (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 85E9E9403A2 for ; Sun, 10 Jan 2021 14:01:52 +0000 (UTC) Received: from nmbug.tethera.net (localhost [127.0.0.1]) by mail.notmuchmail.org (Postfix) with ESMTP id EC22F29DDF; Sun, 10 Jan 2021 09:01:25 -0500 (EST) Received: from mail.hostpark.net (mail.hostpark.net [212.243.197.30]) by mail.notmuchmail.org (Postfix) with ESMTPS id 094C829D05 for ; Sun, 10 Jan 2021 09:01:15 -0500 (EST) Received: from localhost (localhost [127.0.0.1]) by mail.hostpark.net (Postfix) with ESMTP id 3A393165E8 for ; Sun, 10 Jan 2021 15:01:13 +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=1610287273; bh=+bg4nXimJZ3aFe0 fbEY0aAQ3exUoA7Hkjnu81QweNX0=; b=Ny12mAaIZYy0EKXh3Xwt8I76zdvFtoc z1AriPeaN9wT2D1uRnz37dvIUBAF5wo+tfQfp6p/4htvnHD7/KxyeEbUkL48Nrtg 1m5nl/TEht2izakm57oiBPOIantNRyhGQ8V8EUUCcrReaYvpJQAYfn0IlTaCNheI QqX8BHnSf9pQ= 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 sQ3LNFCE2cUH for ; Sun, 10 Jan 2021 15:01:13 +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 EF4D81660A for ; Sun, 10 Jan 2021 15:01:12 +0100 (CET) From: Jonas Bernoulli To: notmuch@notmuchmail.org Subject: [PATCH v2 02/36] emacs: sanitize dedicated widget action/notify functions Date: Sun, 10 Jan 2021 15:00:38 +0100 Message-Id: <20210110140112.25930-3-jonas@bernoul.li> X-Mailer: git-send-email 2.29.1 In-Reply-To: <20210110140112.25930-1-jonas@bernoul.li> References: <20201214162401.19569-1-jonas@bernoul.li> <20210110140112.25930-1-jonas@bernoul.li> MIME-Version: 1.0 Message-ID-Hash: GMMDYHTC6H2X7KOUVLGXJC3ONVPYJU5F X-Message-ID-Hash: GMMDYHTC6H2X7KOUVLGXJC3ONVPYJU5F 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: 0.06 Authentication-Results: aspmx1.migadu.com; dkim=fail (body hash did not verify) header.d=bernoul.li header.s=sel2011a header.b=Ny12mAaI; dmarc=none; spf=pass (aspmx1.migadu.com: domain of notmuch-bounces@notmuchmail.org designates 2607:5300:201:3100::1657 as permitted sender) smtp.mailfrom=notmuch-bounces@notmuchmail.org X-Migadu-Queue-Id: 85E9E9403A2 X-Spam-Score: 0.06 X-Migadu-Scanner: scn1.migadu.com X-TUID: wZvlEj5V9j9r 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