unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
From: William Casarin <jb55@jb55.com>
To: notmuch@notmuchmail.org
Subject: [PATCH v4 2/7] emacs/tree: add notmuch-tree-goto-matching-message
Date: Sat,  4 Apr 2020 13:41:37 -0700	[thread overview]
Message-ID: <20200404204142.2526-7-jb55@jb55.com> (raw)
In-Reply-To: <20200404204142.2526-1-jb55@jb55.com>

This function captures some common logic when jumping to matching
messages in notmuch-tree mode.

We also add a new return value (t or nil), that indicates if there was
a next matching message in the thread to show.

Signed-off-by: William Casarin <jb55@jb55.com>
---
 emacs/notmuch-tree.el | 18 ++++++++++++++----
 1 file changed, 14 insertions(+), 4 deletions(-)

diff --git a/emacs/notmuch-tree.el b/emacs/notmuch-tree.el
index 1bcf6cf9..7f68efba 100644
--- a/emacs/notmuch-tree.el
+++ b/emacs/notmuch-tree.el
@@ -631,12 +631,23 @@ message will be \"unarchived\", i.e. the tag changes in
   (when (window-live-p notmuch-tree-message-window)
     (notmuch-tree-show-message-in)))
 
+(defun notmuch-tree-goto-matching-message (&optional prev)
+  "Move to the next or previous matching message.
+
+Returns t if there was a next matching message in the thread to show,
+nil otherwise."
+  (let ((dir (if prev -1 nil))
+	(eobfn (if prev #'bobp #'eobp)))
+    (while (and (not (funcall eobfn))
+		(not (notmuch-tree-get-match)))
+      (forward-line dir))
+    (not (funcall eobfn))))
+
 (defun notmuch-tree-prev-matching-message ()
   "Move to previous matching message."
   (interactive)
   (forward-line -1)
-  (while (and (not (bobp)) (not (notmuch-tree-get-match)))
-    (forward-line -1))
+  (notmuch-tree-goto-matching-message t)
   (when (window-live-p notmuch-tree-message-window)
     (notmuch-tree-show-message-in)))
 
@@ -644,8 +655,7 @@ message will be \"unarchived\", i.e. the tag changes in
   "Move to next matching message."
   (interactive)
   (forward-line)
-  (while (and (not (eobp)) (not (notmuch-tree-get-match)))
-    (forward-line))
+  (notmuch-tree-goto-matching-message)
   (when (window-live-p notmuch-tree-message-window)
     (notmuch-tree-show-message-in)))
 
-- 
2.25.1

  parent reply	other threads:[~2020-04-04 20:41 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-04 20:41 [PATCH 1/7] emacs/tree: return true if a thread was found in next-thread William Casarin
2020-04-04 20:41 ` [PATCH 2/7] emacs/tree: add notmuch-tree-goto-matching-message William Casarin
2020-04-04 20:41 ` [PATCH 3/7] emacs/tree: add notmuch-tree-matching-message William Casarin
2020-04-04 20:41 ` [PATCH 4/7] emacs/tree: add kill-both prefix argument to notmuch-tree-quit William Casarin
2020-04-04 20:41 ` [PATCH 5/7] emacs/tree: add notmuch-tree-archive-message-than-next-or-exit William Casarin
2020-04-04 20:41 ` [PATCH v4 1/7] emacs/tree: return true if a thread was found in next-thread William Casarin
2020-04-04 20:41 ` William Casarin [this message]
2020-04-04 20:41 ` [PATCH v4 3/7] emacs/tree: add notmuch-tree-matching-message William Casarin
2020-04-04 20:41 ` [PATCH v4 4/7] emacs/tree: add kill-both prefix argument to notmuch-tree-quit William Casarin
2020-04-04 20:41 ` [PATCH v4 5/7] emacs/tree: add notmuch-tree-archive-message-than-next-or-exit William Casarin
2020-04-04 20:41 ` [PATCH v4 6/7] emacs/tree: add notmuch-tree-archive-thread-then-exit William Casarin
2020-04-04 20:41 ` [PATCH v4 7/7] emacs/tree: add x/X bindings William Casarin
2020-04-04 20:44 ` [PATCH 1/7] emacs/tree: return true if a thread was found in next-thread William Casarin
2020-04-06 11:26   ` David Bremner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://notmuchmail.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200404204142.2526-7-jb55@jb55.com \
    --to=jb55@jb55.com \
    --cc=notmuch@notmuchmail.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://yhetil.org/notmuch.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).