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 ULLJGtYI+198bwAA0tVLHw (envelope-from ) for ; Sun, 10 Jan 2021 14:01:58 +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 IPKuFtYI+19wcgAAB5/wlQ (envelope-from ) for ; Sun, 10 Jan 2021 14:01:58 +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 182C7940463 for ; Sun, 10 Jan 2021 14:01:58 +0000 (UTC) Received: from nmbug.tethera.net (localhost [127.0.0.1]) by mail.notmuchmail.org (Postfix) with ESMTP id C9F7429E28; Sun, 10 Jan 2021 09:01:27 -0500 (EST) Received: from mail.hostpark.net (mail.hostpark.net [212.243.197.30]) by mail.notmuchmail.org (Postfix) with ESMTPS id 0B7E629D06 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 3CE471665A 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=rU6IFXiwRHCM4t9 HdF5lW+5U0RS5IDZrbRziWQxVnPU=; b=rNRXoMNRkLV/RAaHEEqBkOXkh9nuEDD nUZS8l0Uy4mZ8Y2Llrsa3edETW9RWn8ExPgBbAGloCX6zvygIg7vhvjAee3a++Rk tGi8klPhyc2synxIboD6fOjBlF3ikDPWbvRudQPLRaIzryeWjzmNKxueMA6vvLQj jgQMtARsglSc= 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 BnZ1jTSdHbfa 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 06FB51660C for ; Sun, 10 Jan 2021 15:01:13 +0100 (CET) From: Jonas Bernoulli To: notmuch@notmuchmail.org Subject: [PATCH v2 03/36] emacs: define new notmuch-search-item widget type Date: Sun, 10 Jan 2021 15:00:39 +0100 Message-Id: <20210110140112.25930-4-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: A6JMZSZ4UBLSWT64SJ2H534PSH62YVK5 X-Message-ID-Hash: A6JMZSZ4UBLSWT64SJ2H534PSH62YVK5 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=rNRXoMNR; 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: 182C7940463 X-Spam-Score: 0.06 X-Migadu-Scanner: scn0.migadu.com X-TUID: 5NhOrYTKPqFP This is complex enough to warrant a dedicated widget type, which will make future improvements less messy to implement. --- emacs/notmuch-hello.el | 92 +++++++++++++++++++++--------------------- 1 file changed, 45 insertions(+), 47 deletions(-) diff --git a/emacs/notmuch-hello.el b/emacs/notmuch-hello.el index 767c6874..7bc713f3 100644 --- a/emacs/notmuch-hello.el +++ b/emacs/notmuch-hello.el @@ -385,6 +385,40 @@ (defun notmuch-hello-nice-number (n) (format "%s%03d" notmuch-hello-thousands-separator elem)) (cdr result))))) +(define-widget 'notmuch-search-item 'item + "A recent search." + :format "%v\n" + :value-create 'notmuch-search-item-value-create) + +(defun notmuch-search-item-value-create (widget) + (let ((value (widget-get widget :value))) + (widget-insert (make-string notmuch-hello-indent ?\s)) + (widget-create 'editable-field + :size (widget-get widget :size) + :parent widget + :action #'notmuch-hello-search + value) + (widget-insert " ") + (widget-create 'push-button + :parent widget + :notify #'notmuch-hello-add-saved-search + "save") + (widget-insert " ") + (widget-create 'push-button + :parent widget + :notify #'notmuch-hello-delete-search-from-history + "del"))) + +(defun notmuch-search-item-field-width () + (max 8 ; Don't let the search boxes be less than 8 characters wide. + (- (window-width) + notmuch-hello-indent ; space at bol + notmuch-hello-indent ; space at eol + 1 ; for the space before the [save] button + 6 ; for the [save] button + 1 ; for the space before the [del] button + 5))) ; for the [del] button + (defun notmuch-hello-search (widget &rest _event) (let ((search (widget-value widget))) (when search @@ -778,54 +812,18 @@ (defun notmuch-hello-insert-recent-searches () "Insert recent searches." (when notmuch-search-history (widget-insert "Recent searches: ") - (widget-create 'push-button - :notify (lambda (&rest ignore) - (when (y-or-n-p "Are you sure you want to clear the searches? ") - (setq notmuch-search-history nil) - (notmuch-hello-update))) - "clear") + (widget-create + 'push-button + :notify (lambda (&rest _ignore) + (when (y-or-n-p "Are you sure you want to clear the searches? ") + (setq notmuch-search-history nil) + (notmuch-hello-update))) + "clear") (widget-insert "\n\n") - (let ((start (point))) - (cl-loop for i from 1 to notmuch-hello-recent-searches-max - for search in notmuch-search-history do - (let ((widget-symbol (intern (format "notmuch-hello-search-%d" i)))) - (set widget-symbol - (widget-create 'editable-field - ;; Don't let the search boxes be - ;; less than 8 characters wide. - :size (max 8 - (- (window-width) - ;; Leave some space - ;; at the start and - ;; end of the - ;; boxes. - (* 2 notmuch-hello-indent) - ;; 1 for the space - ;; before the - ;; `[save]' button. 6 - ;; for the `[save]' - ;; button. - 1 6 - ;; 1 for the space - ;; before the `[del]' - ;; button. 5 for the - ;; `[del]' button. - 1 5)) - :action #'notmuch-hello-search - search)) - (widget-insert " ") - (widget-create 'push-button - :notify #'notmuch-hello-add-saved-search - :notmuch-saved-search-widget widget-symbol - "save") - (widget-insert " ") - (widget-create 'push-button - :notify #'notmuch-hello-delete-search-from-history - :notmuch-saved-search-widget widget-symbol - "del")) - (widget-insert "\n")) - (indent-rigidly start (point) notmuch-hello-indent)) - nil)) + (let ((width (notmuch-search-item-field-width))) + (dolist (search (seq-take notmuch-search-history + notmuch-hello-recent-searches-max)) + (widget-create 'notmuch-search-item :value search :size width))))) (defun notmuch-hello-insert-searches (title query-list &rest options) "Insert a section with TITLE showing a list of buttons made from QUERY-LIST. -- 2.29.1