Change the buffer name to a uniquified subject of the thread (i.e. the
subject of the first message in the thread) instead of the thread-id. This
is more meaningful to the user, and will make it easier to scroll through
numerous open buffers.

Note that this patch adds an optional `buffer-name' argument to notmuch
show.

This version supersedes V1 and V2 of this patch. It is rebased on HEAD,
ensures that the buffer names are unique, and that the `notmuch-show'
command can still be used interactively (fixing a clumsy bug in V2 which
prevented that).

Signed-off-by: Jesse Rosenthal <jrosenthal at jhu.edu>
---
 notmuch.el |   21 +++++++++++++++++----
 1 files changed, 17 insertions(+), 4 deletions(-)

diff --git a/notmuch.el b/notmuch.el
index 6482170..685b2cd 100644
--- a/notmuch.el
+++ b/notmuch.el
@@ -1162,7 +1162,7 @@ All currently available key bindings:
          (lambda()
            (hl-line-mode 1) ))

-(defun notmuch-show (thread-id &optional parent-buffer query-context)
+(defun notmuch-show (thread-id &optional parent-buffer query-context 
buffer-name)
   "Run \"notmuch show\" with the given thread ID and display results.

 The optional PARENT-BUFFER is the notmuch-search buffer from
@@ -1172,7 +1172,10 @@ thread from that buffer can be show when done with this 
one).
 The optional QUERY-CONTEXT is a notmuch search term. Only messages from the 
thread
 matching this search term are shown if non-nil. "
   (interactive "sNotmuch show: ")
-  (let ((buffer (get-buffer-create (concat "*notmuch-show-" thread-id "*"))))
+  (when (null (buffer-name))
+    (setq buffer-name (concat "*notmuch-" thread-id "*")))
+  (let* ((thread-buffer-name (generate-new-buffer-name buffer-name))
+        (buffer (get-buffer-create thread-buffer-name)))
     (switch-to-buffer buffer)
     (notmuch-show-mode)
     (set (make-local-variable 'notmuch-show-parent-buffer) parent-buffer)
@@ -1363,9 +1366,19 @@ Complete list of currently available key bindings:
 (defun notmuch-search-show-thread ()
   "Display the currently selected thread."
   (interactive)
-  (let ((thread-id (notmuch-search-find-thread-id)))
+  (let ((thread-id (notmuch-search-find-thread-id))
+       (subject (notmuch-search-find-subject))
+       buffer-name)
+    (when (string-match "^[ \t]*$" subject)
+      (setq subject "[No Subject]"))
+    (setq buffer-name (concat "*"
+                             (truncate-string-to-width subject 32 nil nil t)
+                             "*"))
     (if (> (length thread-id) 0)
-       (notmuch-show thread-id (current-buffer) notmuch-search-query-string)
+       (notmuch-show thread-id
+                     (current-buffer)
+                     notmuch-search-query-string
+                     buffer-name)
       (error "End of search results"))))

 (defun notmuch-search-reply-to-thread ()
-- 
1.6.3.3

Reply via email to