From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp10.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id +GTiM8pz3GFrqQAAgWs5BA (envelope-from ) for ; Mon, 10 Jan 2022 18:58:34 +0100 Received: from aspmx1.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp10.migadu.com with LMTPS id AHFxLMpz3GFpkgAAG6o9tA (envelope-from ) for ; Mon, 10 Jan 2022 18:58:34 +0100 Received: from mail.notmuchmail.org (yantan.tethera.net [135.181.149.255]) (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 aspmx1.migadu.com (Postfix) with ESMTPS id 3EA3539501 for ; Mon, 10 Jan 2022 18:58:34 +0100 (CET) Received: from yantan.tethera.net (localhost [127.0.0.1]) by mail.notmuchmail.org (Postfix) with ESMTP id D54035F742; Mon, 10 Jan 2022 17:58:30 +0000 (UTC) Received: from eggs.gnu.org (eggs.gnu.org [209.51.188.92]) by mail.notmuchmail.org (Postfix) with ESMTPS id E26DD5F735 for ; Mon, 10 Jan 2022 17:58:27 +0000 (UTC) Received: from [2001:470:142:3::e] (port=52512 helo=fencepost.gnu.org) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1n6yw6-00073H-Du; Mon, 10 Jan 2022 12:58:26 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=MIME-Version:Date:Subject:To:From:in-reply-to: references; bh=vucgfjbGlc8F3xGD8hDhJvZuBJsI4YtlZdmMe0Bich4=; b=SZ4TcLMdWO0rwx Sv5GbJ3ZJ3CFO+e8QxO2oKJvXyfFRyALaOYU0LyvW6HxPN1wQqCIZRpcJd4NhVfa+9h9iPl87sUKq vIOZ9ND+gbYhPmGqYGHl5kYG4uo7+y70LBvEwWhUvKeHBpvX+QrqT/rb2ZB0PtrzF/jt6iG08o6Op UEBu6x+2ILdlDCjsE7WEKo/3LzcKnbNiYxhPHdBZwqIOaY619nCM+HdxbvXBT4uVPx+wHYQd+8q3g JEIhOZPcOIdSaSve+5LUpmnqRdaZwX8N26lXpCjB9sYsAA2TTvmnJFI90CYw8zRsxzblWbtOryu/5 hd0xND6ALN26ZezmaeDQ==; Received: from 92.40.179.55.threembb.co.uk ([92.40.179.55]:39319 helo=rivendell.localdomain) by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1n6yw6-0006YD-BR; Mon, 10 Jan 2022 12:58:26 -0500 From: jao To: notmuch@notmuchmail.org Subject: [PATCH v3] emacs: customizable names for search buffers Date: Mon, 10 Jan 2022 17:58:10 +0000 Message-Id: <20220110175810.1451553-1-jao@gnu.org> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Message-ID-Hash: YESXXYNQVKEPAIVGTXTVUP4D43E6SCVP X-Message-ID-Hash: YESXXYNQVKEPAIVGTXTVUP4D43E6SCVP X-MailFrom: jao@gnu.org 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; digests; suspicious-header CC: jao X-Mailman-Version: 3.3.3 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Migadu-Flow: FLOW_IN X-Migadu-Country: DE ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1641837514; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding:list-id:list-help: list-owner:list-unsubscribe:list-subscribe:list-post:dkim-signature; bh=MB1yUF9i/I3tCsBxuhGBStkNbSmrRORGUwG9scTOL/w=; b=ggFEEVyN9sQKz+olqqSaeI5g+cCU4EZU5mTpDnLz+0b/nfR6wt6heoeTkm3Jk1mSoyei6+ phN2Bi8G9eXbUrEL74mQ4ieDS9p4V1h+8auP+nSPbnMY58yxrICwRRTvEYw4cuEUzEWeTL DBxmw0mdti9sQfLrfsluZjAhol+jvVKh6IBJkN21QvfE7BvDgDx8K28QgSPkR0y5cR6nrT HHpB7eDZ8t6dtoJTOTWre3/xp1bRm/kk6DL+a9MymGx4e2JwdpwmuHjPVJmIsyjGTVdKoT A6xpXmEULdyZcfyYU7Vfr8dDH3lXbW5xwk8fowzbOiJfK4aVBnXDvlCwhfNVbw== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1641837514; a=rsa-sha256; cv=none; b=dML0DiDa5vgI93OXAYDkO72X86ecpZr4IHljrQooAtnJ/fVkPHnZHotp6gDDnke10rXctK iXyLS5jQ15ByA1wPyiww/bfZNml+0V2ViQ/UN1TZQa1BClFRSG4ooBQfH3nTGWUVXH5nAB 2s5hAxz8BZqFhJKwQC89jXzi7xown6XzqdLtlhLR2U8pA8m4GlI2gluC7h4EBlIOD1r24I 0+61K0psyT91LI8vBKQBUWAf+x4u4YHkhazQMZLChX3taWPajzUNiIULKZz0YQfJobuAWZ e4/Afe+pPnlyGiGAa82/njLf00TDMnfRN8fpyUShBDHWdxXROU80d8bMI+7EUQ== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("body hash did not verify") header.d=gnu.org header.s=fencepost-gnu-org header.b=SZ4TcLMd; dmarc=fail reason="SPF not aligned (relaxed)" header.from=gnu.org (policy=none); spf=pass (aspmx1.migadu.com: domain of notmuch-bounces@notmuchmail.org designates 135.181.149.255 as permitted sender) smtp.mailfrom=notmuch-bounces@notmuchmail.org X-Migadu-Spam-Score: -1.13 Authentication-Results: aspmx1.migadu.com; dkim=fail ("body hash did not verify") header.d=gnu.org header.s=fencepost-gnu-org header.b=SZ4TcLMd; dmarc=fail reason="SPF not aligned (relaxed)" header.from=gnu.org (policy=none); spf=pass (aspmx1.migadu.com: domain of notmuch-bounces@notmuchmail.org designates 135.181.149.255 as permitted sender) smtp.mailfrom=notmuch-bounces@notmuchmail.org X-Migadu-Queue-Id: 3EA3539501 X-Spam-Score: -1.13 X-Migadu-Scanner: scn0.migadu.com X-TUID: 4WXjSkTvb3hp Customizable names for buffers presenting search results, via two custom variables (notmuch-search-buffer-name-format and notmuch-saved-search-buffer-name-format), defaulting to values currently used for plain searches and including too tree and unthreaded search buffers. --- This is a much improved version of the patch in id:20220108204121.1053932-1-jao@gnu.org, according to discussion on that thread. This version just squashes together the two patches in v2. Signed-off-by: jao --- emacs/notmuch-hello.el | 11 ++++++---- emacs/notmuch-tree.el | 10 ++++----- emacs/notmuch.el | 50 +++++++++++++++++++++++++++++++++--------- 3 files changed, 52 insertions(+), 19 deletions(-) diff --git a/emacs/notmuch-hello.el b/emacs/notmuch-hello.el index fc007c4c..44341dd6 100644 --- a/emacs/notmuch-hello.el +++ b/emacs/notmuch-hello.el @@ -486,11 +486,14 @@ diagonal." (defun notmuch-hello-widget-search (widget &rest _ignore) (cl-case (widget-get widget :notmuch-search-type) (tree - (notmuch-tree (widget-get widget :notmuch-search-terms) - nil nil nil nil nil nil - (widget-get widget :notmuch-search-oldest-first))) + (let ((n (notmuch-search-format-buffer-name (widget-value widget) "tree" t))) + (notmuch-tree (widget-get widget :notmuch-search-terms) + nil nil n nil nil nil + (widget-get widget :notmuch-search-oldest-first)))) (unthreaded - (notmuch-unthreaded (widget-get widget :notmuch-search-terms))) + (let ((n (notmuch-search-format-buffer-name (widget-value widget) + "unthreaded" t))) + (notmuch-unthreaded (widget-get widget :notmuch-search-terms) nil nil n))) (t (notmuch-search (widget-get widget :notmuch-search-terms) (widget-get widget :notmuch-search-oldest-first))))) diff --git a/emacs/notmuch-tree.el b/emacs/notmuch-tree.el index d7486904..303c6fad 100644 --- a/emacs/notmuch-tree.el +++ b/emacs/notmuch-tree.el @@ -1191,11 +1191,11 @@ The arguments are: (setq query (notmuch-read-query (concat "Notmuch " (if unthreaded "unthreaded " "tree ") "view search: ")))) - (let ((buffer (get-buffer-create (generate-new-buffer-name - (or buffer-name - (concat "*notmuch-" - (if unthreaded "unthreaded-" "tree-") - query "*"))))) + (let* ((name + (or buffer-name + (notmuch-search-buffer-title query + (if unthreaded "unthreaded" "tree")))) + (buffer (get-buffer-create (generate-new-buffer-name name))) (inhibit-read-only t)) (pop-to-buffer-same-window buffer)) ;; Don't track undo information for this buffer diff --git a/emacs/notmuch.el b/emacs/notmuch.el index 85a54706..a30e3334 100644 --- a/emacs/notmuch.el +++ b/emacs/notmuch.el @@ -915,7 +915,36 @@ See `notmuch-tag' for information on the format of TAG-CHANGES." (notmuch-search-get-tags-region (point-min) (point-max)) "Tag all"))) (notmuch-search-tag tag-changes (point-min) (point-max) t)) -(defun notmuch-search-buffer-title (query) +(defcustom notmuch-search-buffer-name-format "*notmuch-%t-%s*" + "Format for the name of search results buffers. + +In this spec, %s will be replaced by a description of the search +query and %t by its type (search, tree or unthreaded). + +See also `notmuch-saved-search-buffer-name-format'" + :type 'string + :group 'notmuch-search) + +(defcustom notmuch-saved-search-buffer-name-format "*notmuch-saved-%t-%s*" + "Format for the name of search results buffers. + +In this spec, %s will be replaced by the saved search name and %t +by its type (search, tree or unthreaded). + +See also `notmuch-search-buffer-name-format'" + :type 'string + :group 'notmuch-search) + +(defun notmuch-search-format-buffer-name (query type saved) + "Use the FMT spec to provide a query buffer name." + (let ((fmt (if saved + notmuch-saved-search-buffer-name-format + notmuch-search-buffer-name-format))) + (if (fboundp 'format-spec) + (format-spec fmt `((?t . ,(or type "search")) (?s . ,query)))) + (format (replace-regexp-in-string "\\b%t\\b" (or type "search") fmt) query))) + +(defun notmuch-search-buffer-title (query &optional type) "Returns the title for a buffer with notmuch search results." (let* ((saved-search (let (longest @@ -930,19 +959,20 @@ See `notmuch-tag' for information on the format of TAG-CHANGES." do (setq longest tuple)) longest)) (saved-search-name (notmuch-saved-search-get saved-search :name)) + (saved-search-type (notmuch-saved-search-get saved-search :search-type)) (saved-search-query (notmuch-saved-search-get saved-search :query))) (cond ((and saved-search (equal saved-search-query query)) ;; Query is the same as saved search (ignoring case) - (concat "*notmuch-saved-search-" saved-search-name "*")) + (notmuch-search-format-buffer-name saved-search-name + saved-search-type + t)) (saved-search - (concat "*notmuch-search-" - (replace-regexp-in-string - (concat "^" (regexp-quote saved-search-query)) - (concat "[ " saved-search-name " ]") - query) - "*")) - (t - (concat "*notmuch-search-" query "*"))))) + (let ((query (replace-regexp-in-string + (concat "^" (regexp-quote saved-search-query)) + (concat "[ " saved-search-name " ]") + query))) + (notmuch-search-format-buffer-name query saved-search-type t))) + (t (notmuch-search-format-buffer-name query type nil))))) (defun notmuch-read-query (prompt) "Read a notmuch-query from the minibuffer with completion. -- 2.34.1