From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp10.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id UFHoG/yu5GEbbwEAgWs5BA (envelope-from ) for ; Mon, 17 Jan 2022 00:49:16 +0100 Received: from aspmx1.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp10.migadu.com with LMTPS id MC2OFPyu5GGikwAAG6o9tA (envelope-from ) for ; Mon, 17 Jan 2022 00:49:16 +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 0BDF62237D for ; Mon, 17 Jan 2022 00:49:16 +0100 (CET) Received: from yantan.tethera.net (localhost [127.0.0.1]) by mail.notmuchmail.org (Postfix) with ESMTP id CE4335F5E1; Sun, 16 Jan 2022 23:49:11 +0000 (UTC) Received: from eggs.gnu.org (eggs.gnu.org [209.51.188.92]) by mail.notmuchmail.org (Postfix) with ESMTPS id A735E5F419 for ; Sun, 16 Jan 2022 23:49:08 +0000 (UTC) Received: from [2001:470:142:3::e] (port=55296 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 1n9FGk-0006tS-QP; Sun, 16 Jan 2022 18:49:06 -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=gF+q/z0r3QJkiYJqiOj/fV/n8kDGwAmL3MkxurVYR/k=; b=mrgTtYx999pz3v O60C9WoGWMgr/bO7jYqNAzXCBIeRZsf0oeOPfigq9Y7UHRvKEaOe+rUpOJqQM83rYiY1jlzjRd4FX 1lPL5MR+ZvrrSduV7siIMUSflJcjHI3syhQoCCLxKaI7utuHFGemnUz4/ddyBCDhssQbLrZdygjh2 HySrK0+rRs0gOiin7cUPkyCoxdCQzdHDqm7OFZqZx1bYRB4wL2JzwtcjX7sIrsSFljQ2Z2rNiH40W EfCkgF1V5AuhiE9Gtvi+k08jVWZvtQVynC4EICgWXtJ3vt4LXDQm9MAY2TMMPWgSvnYmvWg0u0oK6 F+dB68tcI1PVK17SGnBg==; Received: from cpc103048-sgyl39-2-0-cust502.18-2.cable.virginm.net ([92.233.85.247]:33560 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 1n9FGl-0003tm-1O; Sun, 16 Jan 2022 18:49:07 -0500 From: jao To: notmuch@notmuchmail.org Subject: [PATCH v6] emacs: customizable names for search buffers Date: Sun, 16 Jan 2022 23:48:59 +0000 Message-Id: <20220116234859.619981-1-jao@gnu.org> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Message-ID-Hash: 2YN3AYTSJNPZABHRXYU3VY6RIYMC3CZ6 X-Message-ID-Hash: 2YN3AYTSJNPZABHRXYU3VY6RIYMC3CZ6 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=1642376956; 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=iK35QR6AyWrSvj2JDyUEOggQLDO5ZblRKOl2tRs7gBM=; b=gYdqIRONfbV0Vjw9j58IH8h+xw3EjoKalHEvlDccK9JQC6n1f+klIRsfbCMhjeVme18Ce7 TotXHK5aPm9KMI7t/YWVrU7WpP5SzlxJmwX4XIaX746wdsEg6c0UC1EjUwg68S5Z3igi1+ muCxX5A3WTiRfLjWdvoB4IihA7naYsHis2OXQqmdxp+MsouczRf/h00uwox4XMy80oOuHc NDAiCB09gKPcEABedRGV8IIQ+nzulR4WF8oIrCAwDyq//ubcLWOQZBF4vZlrkSNvKRWsQL C389yRe4HpBzpUs2wCH0PnKAsj7f+V/QXTvNucJqnHOiVNTtBbzIXOW4pfAGWA== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1642376956; a=rsa-sha256; cv=none; b=IFW8rngsvoGoyW6GY0puTL6ZEP58Sg/hEdEbDjaJOPkE0BTesoukt5LmU+01aOP4txqo/Z X/5UodbAc610mlQ/pI2lgrER6yY/qkw8JiMLfefOpS0ZPOOeJgAQkmOudinMsVzldVKL6K gqvcsSDT5ExIzZyW6Vj1dsCeSol15aUHO3PKQZLs3WW5CDS4Nz/331VlslCduKGvKic9GY 9OfVUppkcfqrpGYjGoIONsC7Go6AFkgG3zswmncfKAObQv1EJ/J5xnD1xm99F5hkABuILA 3jh8mwKIRDt/NXG7j3YsncfvEej9GfDJM8KXjrwvVbk9m6UkvCJZ7+ICVVzJVw== 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=mrgTtYx9; 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: -0.65 Authentication-Results: aspmx1.migadu.com; dkim=fail ("body hash did not verify") header.d=gnu.org header.s=fencepost-gnu-org header.b=mrgTtYx9; 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: 0BDF62237D X-Spam-Score: -0.65 X-Migadu-Scanner: scn1.migadu.com X-TUID: APPlGnYz+f2l 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 always uses format-spec, since it's available since ancient times (see discussion in id:875yqjmgaq.fsf@kyleam.com). Signed-off-by: jao --- emacs/notmuch-hello.el | 11 +++++---- emacs/notmuch-tree.el | 10 ++++---- emacs/notmuch.el | 53 ++++++++++++++++++++++++++++++++++-------- 3 files changed, 55 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..ef3af899 100644 --- a/emacs/notmuch.el +++ b/emacs/notmuch.el @@ -915,7 +915,39 @@ 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). The +buffer name is formatted using `format-spec': see its docstring +for additional parameters for the s and t format specifiers. + +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). The buffer name is +formatted using `format-spec': see its docstring for additional +parameters for the s and t format specifiers. + +See also `notmuch-search-buffer-name-format'" + :type 'string + :group 'notmuch-search) + +(defun notmuch-search-format-buffer-name (query type saved) + "Compose a buffer name for the given QUERY, TYPE (search, tree, +unthreaded) and whether it's SAVED (t or nil)." + (let ((fmt (if saved + notmuch-saved-search-buffer-name-format + notmuch-search-buffer-name-format))) + (format-spec fmt `((?t . ,(or type "search")) (?s . ,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 +962,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