unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
* [PATCH 1/3] emacs/tree: introduce notmuch-tree-parent-buffer variable
@ 2020-04-23 23:47 William Casarin
  2020-04-23 23:47 ` [PATCH 2/3] emacs/tree: enable moving to next thread in search results William Casarin
  2020-04-23 23:47 ` [PATCH 3/3] emacs/tree: add notmuch-tree-archive-thread-then-next William Casarin
  0 siblings, 2 replies; 5+ messages in thread
From: William Casarin @ 2020-04-23 23:47 UTC (permalink / raw)
  To: notmuch

This variable will be used in a similar fashion to
notmuch-show-parent-buffer. It will be used to navigate between
threads from the parent search buffer.

Signed-off-by: William Casarin <jb55@jb55.com>
---
 emacs/notmuch-tree.el | 7 ++++++-
 emacs/notmuch.el      | 4 +++-
 2 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/emacs/notmuch-tree.el b/emacs/notmuch-tree.el
index 701d12f8..f38fef98 100644
--- a/emacs/notmuch-tree.el
+++ b/emacs/notmuch-tree.el
@@ -219,6 +219,9 @@ Note the author string should not contain
   "A buffer local copy of argument open-target to the function notmuch-tree")
 (make-variable-buffer-local 'notmuch-tree-open-target)
 
+(defvar notmuch-tree-parent-buffer nil)
+(make-variable-buffer-local 'notmuch-tree-parent-buffer)
+
 (defvar notmuch-tree-message-window nil
   "The window of the message pane.
 
@@ -1037,7 +1040,7 @@ the same as for the function notmuch-tree."
 	      ")")
     notmuch-tree-basic-query))
 
-(defun notmuch-tree (&optional query query-context target buffer-name open-target unthreaded)
+(defun notmuch-tree (&optional query query-context target buffer-name open-target unthreaded parent-buffer)
   "Display threads matching QUERY in Tree View.
 
 The arguments are:
@@ -1070,6 +1073,8 @@ The arguments are:
 
   (notmuch-tree-worker query query-context target open-target unthreaded)
 
+  (setq notmuch-tree-parent-buffer parent-buffer)
+
   (setq truncate-lines t))
 
 (defun notmuch-unthreaded (&optional query query-context target buffer-name open-target)
diff --git a/emacs/notmuch.el b/emacs/notmuch.el
index f5f03244..a7cdd893 100644
--- a/emacs/notmuch.el
+++ b/emacs/notmuch.el
@@ -536,7 +536,9 @@ thread."
                 notmuch-search-query-string
 		nil
                 (notmuch-prettify-subject (notmuch-search-find-subject))
-		t))
+		t
+		nil
+		(current-buffer)))
 
 (defun notmuch-search-reply-to-thread (&optional prompt-for-sender)
   "Begin composing a reply-all to the entire current thread in a new buffer."
-- 
2.25.1

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 2/3] emacs/tree: enable moving to next thread in search results
  2020-04-23 23:47 [PATCH 1/3] emacs/tree: introduce notmuch-tree-parent-buffer variable William Casarin
@ 2020-04-23 23:47 ` William Casarin
  2020-04-24  0:07   ` William Casarin
  2020-04-23 23:47 ` [PATCH 3/3] emacs/tree: add notmuch-tree-archive-thread-then-next William Casarin
  1 sibling, 1 reply; 5+ messages in thread
From: William Casarin @ 2020-04-23 23:47 UTC (permalink / raw)
  To: notmuch

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@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

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 3/3] emacs/tree: add notmuch-tree-archive-thread-then-next
  2020-04-23 23:47 [PATCH 1/3] emacs/tree: introduce notmuch-tree-parent-buffer variable William Casarin
  2020-04-23 23:47 ` [PATCH 2/3] emacs/tree: enable moving to next thread in search results William Casarin
@ 2020-04-23 23:47 ` William Casarin
  1 sibling, 0 replies; 5+ messages in thread
From: William Casarin @ 2020-04-23 23:47 UTC (permalink / raw)
  To: notmuch

Now that notmuch-tree-next-thread acts more like its notmuch-show
counterpart, let's update the binding to move to the next thread after
archiving.

Signed-off-by: William Casarin <jb55@jb55.com>
---
 emacs/notmuch-tree.el | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/emacs/notmuch-tree.el b/emacs/notmuch-tree.el
index dcd335e5..6661b12e 100644
--- a/emacs/notmuch-tree.el
+++ b/emacs/notmuch-tree.el
@@ -325,7 +325,7 @@ FUNC."
     (define-key map [mouse-1] 'notmuch-tree-show-message)
     (define-key map "x" 'notmuch-tree-archive-message-then-next-or-exit)
     (define-key map "X" 'notmuch-tree-archive-thread-then-exit)
-    (define-key map "A" 'notmuch-tree-archive-thread)
+    (define-key map "A" 'notmuch-tree-archive-thread-then-next)
     (define-key map "a" 'notmuch-tree-archive-message-then-next)
     (define-key map "z" 'notmuch-tree-to-tree)
     (define-key map "n" 'notmuch-tree-next-matching-message)
@@ -481,6 +481,12 @@ NOT change the database."
     (notmuch-tree-close-message-window)
     (notmuch-tree query)))
 
+(defun notmuch-tree-archive-thread-then-next ()
+  "Archive all messages in the current buffer, then show next thread from search."
+  (interactive)
+  (notmuch-tree-archive-thread)
+  (notmuch-tree-next-thread))
+
 (defun notmuch-unthreaded-from-tree-current-query ()
   "Switch from tree view to unthreaded view"
   (interactive)
-- 
2.25.1

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH 2/3] emacs/tree: enable moving to next thread in search results
  2020-04-23 23:47 ` [PATCH 2/3] emacs/tree: enable moving to next thread in search results William Casarin
@ 2020-04-24  0:07   ` William Casarin
  2020-08-07 11:49     ` Teemu Likonen
  0 siblings, 1 reply; 5+ messages in thread
From: William Casarin @ 2020-04-24  0:07 UTC (permalink / raw)
  To: notmuch

William Casarin <jb55@jb55.com> writes:

> 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@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)))

I only have one more small fix for this in multi-threaded tree mode:


diff --git a/emacs/notmuch-tree.el b/emacs/notmuch-tree.el
index 6661b12e..20dd1141 100644
--- a/emacs/notmuch-tree.el
+++ b/emacs/notmuch-tree.el
@@ -717,10 +717,11 @@ nil otherwise."
       (forward-line -1))))
 
 (defun notmuch-tree-prev-thread-in-tree ()
-  "Move to the next thread in the current tree"
+  "Move to the previous thread in the current tree"
   (interactive)
   (forward-line -1)
-  (notmuch-tree-thread-top))
+  (notmuch-tree-thread-top)
+  (not (bobp)))
 
 (defun notmuch-tree-next-thread-in-tree ()
   "Get the next thread in the current tree. Returns t if a thread was
@@ -753,7 +754,8 @@ 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)
+  (unless (if previous (notmuch-tree-prev-thread-in-tree)
+	    (notmuch-tree-next-thread-in-tree))
     (notmuch-tree-next-thread-from-search previous)))
 
 (defun notmuch-tree-prev-thread ()



which I will send in a v2 once this gets some Concept ACKs. Feel free to
test in the meantime! Hopefully this makes tree-mode more usable for
people who only use notmuch-show.

Basic usage following the previous emacs/tree improvements:

Press M-Enter on a thread from search-mode to enter that thread in
notmuch-tree mode. With these patches, M-n and M-p move between search
result threads, and A works as you would expect as well (archive and
then move to next thread)

Let me know what ya'll think!

Cheers,
Will

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH 2/3] emacs/tree: enable moving to next thread in search results
  2020-04-24  0:07   ` William Casarin
@ 2020-08-07 11:49     ` Teemu Likonen
  0 siblings, 0 replies; 5+ messages in thread
From: Teemu Likonen @ 2020-08-07 11:49 UTC (permalink / raw)
  To: William Casarin, notmuch


[-- Attachment #1.1: Type: text/plain, Size: 801 bytes --]

* 2020-04-23 17:07:04-07, William Casarin wrote:

> which I will send in a v2 once this gets some Concept ACKs. Feel free
> to test in the meantime! Hopefully this makes tree-mode more usable
> for people who only use notmuch-show.
>
> Basic usage following the previous emacs/tree improvements:
>
> Press M-Enter on a thread from search-mode to enter that thread in
> notmuch-tree mode. With these patches, M-n and M-p move between search
> result threads, and A works as you would expect as well (archive and
> then move to next thread)

This is a good improvement and I would like to test it but the patches
don't apply anymore. Would you like to send updated series?

-- 
/// Teemu Likonen - .-.. http://www.iki.fi/tlikonen/
// OpenPGP: 4E1055DC84E9DFF613D78557719D69D324539450

[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 251 bytes --]

[-- Attachment #2: Type: text/plain, Size: 0 bytes --]



^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2020-08-07 11:49 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-23 23:47 [PATCH 1/3] emacs/tree: introduce notmuch-tree-parent-buffer variable William Casarin
2020-04-23 23:47 ` [PATCH 2/3] emacs/tree: enable moving to next thread in search results William Casarin
2020-04-24  0:07   ` William Casarin
2020-08-07 11:49     ` Teemu Likonen
2020-04-23 23:47 ` [PATCH 3/3] emacs/tree: add notmuch-tree-archive-thread-then-next William Casarin

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).