summaryrefslogtreecommitdiff
path: root/lisp
diff options
context:
space:
mode:
authorKyle Meyer <kyle@kyleam.com>2019-06-27 00:36:16 -0400
committerKyle Meyer <kyle@kyleam.com>2019-06-27 00:36:16 -0400
commit85a2182911eb350249727e319012d57ecf212744 (patch)
tree0c0c19cc3f78c6ddc086e7684ca15e9231ee6d71 /lisp
parent7c8cfda245fef3751e5892249d5584bd88b595ca (diff)
downloademacs.d-85a2182911eb350249727e319012d57ecf212744.tar.gz
notmuch: Try harder to find thread ID when showing tree
In some cases, for example showing a message based on an ID, notmuch-show-thread-id is set to the message ID. This means that the context for the tree is restricted to the message. I find navigating such a tree inconvenient, so avoid this by getting the corresponding thread ID with 'notmuch search' if notmuch-show-thread-id doesn't look like a proper thread ID (i.e. "thread:*").
Diffstat (limited to 'lisp')
-rw-r--r--lisp/km-mail.el33
1 files changed, 30 insertions, 3 deletions
diff --git a/lisp/km-mail.el b/lisp/km-mail.el
index a63c8bc..38e9eee 100644
--- a/lisp/km-mail.el
+++ b/lisp/km-mail.el
@@ -57,12 +57,39 @@
(mark-whole-buffer)
(call-interactively #'notmuch-search-archive-thread))
+(defun km/notmuch-thread-id-from-message-id (message-id)
+ (let ((threads (with-temp-buffer
+ (call-process "notmuch" nil t nil
+ "search" "--format=sexp" "--output=threads"
+ message-id)
+ (goto-char (point-min))
+ (read (current-buffer)))))
+ (cl-case (length threads)
+ (0
+ (user-error "No thread found for %S" message-id))
+ (1
+ (concat "thread:" (car threads)))
+ (t
+ (error "Got multiple threads for %S" message-id)))))
+
;;;###autoload
(defun km/notmuch-tree-from-show-current-query (&optional ignore-context)
(interactive "P")
- (let ((notmuch-show-query-context (and (not ignore-context)
- notmuch-show-query-context)))
- (call-interactively #'notmuch-tree-from-show-current-query)))
+ (let* ((mid (or (notmuch-show-get-message-id)
+ (error "No message ID found")))
+ (tid (if (and notmuch-show-thread-id
+ ;; notmuch's variant works with
+ ;; notmuch-show-thread-id ...
+ (string-prefix-p "thread:" notmuch-show-thread-id))
+ notmuch-show-thread-id
+ ;; ... but there are cases where this is set to the
+ ;; message ID, leading to the tree result that is
+ ;; always narrowed to the message. Try harder to get
+ ;; the actual thread ID.
+ (km/notmuch-thread-id-from-message-id mid)))
+ (notmuch-show-query-context (and (not ignore-context)
+ notmuch-show-query-context)))
+ (notmuch-tree tid notmuch-show-query-context mid)))
;;;###autoload
(defun km/notmuch-show-at-point ()