]> git.notmuchmail.org Git - notmuch/blobdiff - emacs/notmuch.el
emacs: Move definition of notmuch-folders to earlier in the file.
[notmuch] / emacs / notmuch.el
index 66958a6c577876244c1e904a6d8f970af19b8835..57b7fcf40e0bf790131a2871316fcebdba17adc8 100644 (file)
@@ -56,7 +56,8 @@
 
 (defcustom notmuch-search-authors-width 20
   "Number of columns to use to display authors in a notmuch-search buffer."
-  :type 'integer)
+  :type 'integer
+  :group 'notmuch)
 
 (defcustom notmuch-search-result-format
   `(("date" . "%s ")
@@ -664,6 +665,32 @@ characters as well as `_.+-'.
     (apply 'notmuch-call-notmuch-process "tag"
           (append action-split (list notmuch-search-query-string) nil))))
 
+(defcustom notmuch-folders (quote (("inbox" . "tag:inbox") ("unread" . "tag:unread")))
+  "List of searches for the notmuch folder view"
+  :type '(alist :key-type (string) :value-type (string))
+  :group 'notmuch)
+
+(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.
@@ -676,7 +703,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)
@@ -786,11 +813,6 @@ current search results AND that are tagged with the given tag."
 
 (fset 'notmuch-folder-mode-map notmuch-folder-mode-map)
 
-(defcustom notmuch-folders (quote (("inbox" . "tag:inbox") ("unread" . "tag:unread")))
-  "List of searches for the notmuch folder view"
-  :type '(alist :key-type (string) :value-type (string))
-  :group 'notmuch)
-
 (defun notmuch-folder-mode ()
   "Major mode for showing notmuch 'folders'.