[PATCH] emacs: Try to name search buffers using info in notmuch-folders

Servilio Afre Puentes servilio at gmail.com
Sun Apr 18 20:55:50 PDT 2010


This patch obsoletes the one sent in message:

r2sb22065d01004150516jf099f3dcw180a7db0dc972c76 at mail.gmail.com

8<------

As the user has already defined aliases for certain searches in
notmuch-folders, search buffer names that use these aliases will
be easier to identify.
---
 emacs/notmuch.el |   23 ++++++++++++++++++++++-
 1 files changed, 22 insertions(+), 1 deletions(-)

diff --git a/emacs/notmuch.el b/emacs/notmuch.el
index 0adaf8b..f18b1ac 100644
--- a/emacs/notmuch.el
+++ b/emacs/notmuch.el
@@ -695,6 +695,27 @@ characters as well as `_.+-'.
     (apply 'notmuch-call-notmuch-process "tag"
 	   (append action-split (list notmuch-search-query-string) nil))))

+(defun notmuch-search-buffer-title (query)
+  "Returns the title for a buffer with notmuch search results."
+  (let* ((folder (rassoc-if (lambda (key)
+			      (string-match (concat "^" (regexp-quote key))
+					    query))
+			    notmuch-folders))
+	 (folder-name (car folder))
+	 (folder-query (cdr folder)))
+    (cond ((and folder (equal folder-query query))
+	   ;; Query is the same as folder search (ignoring case)
+	   (concat "*notmuch-folder-" folder-name "*"))
+	  (folder
+	   (concat "*notmuch-search-"
+		   (replace-regexp-in-string (concat "^" (regexp-quote folder-query))
+					     (concat "[ " folder-name " ]")
+					     query)
+		   "*"))
+	  (t
+	   (concat "*notmuch-search-" query "*"))
+	  )))
+
 ;;;###autoload
 (defun notmuch-search (query &optional oldest-first target-thread target-line)
   "Run \"notmuch search\" with the given query string and display results.
@@ -707,7 +728,7 @@ The optional parameters are used as follows:
   target-line: The line number to move to if the target thread does not
                appear in the search results."
   (interactive "sNotmuch search: ")
-  (let ((buffer (get-buffer-create (concat "*notmuch-search-" query "*"))))
+  (let ((buffer (get-buffer-create (notmuch-search-buffer-title query))))
     (switch-to-buffer buffer)
     (notmuch-search-mode)
     (set 'notmuch-search-query-string query)
-- 
1.7.0.4


More information about the notmuch mailing list