[PATCH 2/3] emacs/tree: enable moving to next thread in search results

William Casarin jb55 at jb55.com
Thu Apr 23 16:47:14 PDT 2020


This introduces a new function called
notmuch-tree-next-thread-from-search which is analogous to
notmuch-show-next-thread. It will switch to the next or previous
thread from the parent search results.

We rename notmuch-tree-{prev,next}-thread to a more descriptive
notmuch-tree-{prev,next}-thread-in-tree to reflect the fact that it
only moves to the next thread in the current tree.

notmuch-tree-next-thread now switches to the next thread in the
current tree first, but if there are none, it looks for the next tree
in the search results.

This makes notmuch-tree feel more like notmuch-show when using the
M-Enter, M-n and M-p bindings.

Signed-off-by: William Casarin <jb55 at jb55.com>
---
 emacs/notmuch-tree.el | 36 ++++++++++++++++++++++++++++++++++--
 1 file changed, 34 insertions(+), 2 deletions(-)

diff --git a/emacs/notmuch-tree.el b/emacs/notmuch-tree.el
index f38fef98..dcd335e5 100644
--- a/emacs/notmuch-tree.el
+++ b/emacs/notmuch-tree.el
@@ -710,12 +710,13 @@ nil otherwise."
     (while (not (or (notmuch-tree-get-prop :first) (eobp)))
       (forward-line -1))))
 
-(defun notmuch-tree-prev-thread ()
+(defun notmuch-tree-prev-thread-in-tree ()
+  "Move to the next thread in the current tree"
   (interactive)
   (forward-line -1)
   (notmuch-tree-thread-top))
 
-(defun notmuch-tree-next-thread ()
+(defun notmuch-tree-next-thread-in-tree ()
   "Get the next thread in the current tree. Returns t if a thread was
 found or nil if not."
   (interactive)
@@ -724,6 +725,37 @@ found or nil if not."
     (forward-line 1))
   (not (eobp)))
 
+(defun notmuch-tree-next-thread-from-search (&optional previous)
+  "Move to the next thread in the parent search results, if any.
+
+If PREVIOUS is non-nil, move to the previous item in the
+search results instead."
+  (interactive "P")
+  (let ((parent-buffer notmuch-tree-parent-buffer))
+    (notmuch-tree-quit t)
+    (when (buffer-live-p parent-buffer)
+      (switch-to-buffer parent-buffer)
+      (if previous
+	  (notmuch-search-previous-thread)
+	(notmuch-search-next-thread))
+      (notmuch-tree-from-search-thread))))
+
+(defun notmuch-tree-next-thread (&optional previous)
+  "Move to the next thread in the current tree or parent search
+results
+
+If PREVIOUS is non-nil, move to the previous thread in the tree or
+search results instead."
+  (interactive)
+  (unless (notmuch-tree-next-thread-in-tree)
+    (notmuch-tree-next-thread-from-search previous)))
+
+(defun notmuch-tree-prev-thread ()
+  "Move to the previous thread in the current tree or parent search
+results"
+  (interactive)
+  (notmuch-tree-next-thread t))
+
 (defun notmuch-tree-thread-mapcar (function)
   "Iterate through all messages in the current thread
  and call FUNCTION for side effects."
-- 
2.25.1



More information about the notmuch mailing list