unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
* [PATCH v3] emacs: customizable names for search buffers
@ 2022-01-10 17:58 jao
  0 siblings, 0 replies; only message in thread
From: jao @ 2022-01-10 17:58 UTC (permalink / raw)
  To: notmuch; +Cc: jao

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 <jao@gnu.org>
---
 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

^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2022-01-10 17:58 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-10 17:58 [PATCH v3] emacs: customizable names for search buffers jao

Code repositories for project(s) associated with this public inbox

	https://yhetil.org/notmuch.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).