summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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 ()