notmuch-emacs: WISH: command notmuch-show-message-up with key bindung u

classic Classic list List threaded Threaded
7 messages Options
Gregor Zattler Gregor Zattler
Reply | Threaded
Open this post in threaded view
|

notmuch-emacs: WISH: command notmuch-show-message-up with key bindung u

Dear notmuch developers, when reading a long going discussion
which is deeply threaded, it often would come in handy if it was
possible to jump up to the parent message of the message on is
reading, unfolding this message in notmuch-show if necessary.
This command notmuch-show-message-up or
notmuch-show-parent-message could be bound to "u" since this key
is not used in notmuch-show-mode-map.



Thanks for your attention, Gregor
--
 -... --- .-. . -.. ..--.. ...-.-

_______________________________________________
notmuch mailing list
[hidden email]
https://notmuchmail.org/mailman/listinfo/notmuch
David Bremner-2 David Bremner-2
Reply | Threaded
Open this post in threaded view
|

Re: notmuch-emacs: WISH: command notmuch-show-message-up with key bindung u

Gregor Zattler <[hidden email]> writes:

> Dear notmuch developers, when reading a long going discussion
> which is deeply threaded, it often would come in handy if it was
> possible to jump up to the parent message of the message on is
> reading, unfolding this message in notmuch-show if necessary.
> This command notmuch-show-message-up or
> notmuch-show-parent-message could be bound to "u" since this key
> is not used in notmuch-show-mode-map.

Hi Gregor;

The idea seems reasonable; I'm not sure how hard it would to impliment,
since iirc all of the data structures point from parent to child. I've
added it to the list at

    https://nmbug.notmuchmail.org/status/#Wish-list
_______________________________________________
notmuch mailing list
[hidden email]
https://notmuchmail.org/mailman/listinfo/notmuch
Daniel Kahn Gillmor Daniel Kahn Gillmor
Reply | Threaded
Open this post in threaded view
|

Re: notmuch-emacs: WISH: command notmuch-show-message-up with key bindung u

In reply to this post by Gregor Zattler
On Sun 2019-08-25 12:02:05 +0200, Gregor Zattler wrote:
> Dear notmuch developers, when reading a long going discussion
> which is deeply threaded, it often would come in handy if it was
> possible to jump up to the parent message of the message on is
> reading, unfolding this message in notmuch-show if necessary.
> This command notmuch-show-message-up or
> notmuch-show-parent-message could be bound to "u" since this key
> is not used in notmuch-show-mode-map.

I would also like this feature!  (sorry i don't have the elisp-fu to
implement it myself, just adding a +1 here)

          --dkg

_______________________________________________
notmuch mailing list
[hidden email]
https://notmuchmail.org/mailman/listinfo/notmuch

signature.asc (233 bytes) Download Attachment
David Edmondson David Edmondson
Reply | Threaded
Open this post in threaded view
|

[PATCH v1 0/2] emacs/show: Add a binding to go up.

In reply to this post by Gregor Zattler

emacs/show: Add a binding to go up when viewing a thread of messages.

The implementation is a bit ropey and perhaps expensive, but it seems
to work for me.


David Edmondson (2):
  emacs: Stash the currently shown forest in a buffer local variable
  emacs: Bind "u" to jump to the parent message in a thread

 emacs/notmuch-show.el | 59 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 59 insertions(+)

--
2.22.0

_______________________________________________
notmuch mailing list
[hidden email]
https://notmuchmail.org/mailman/listinfo/notmuch
David Edmondson David Edmondson
Reply | Threaded
Open this post in threaded view
|

[PATCH v1 1/2] emacs: Stash the currently shown forest in a buffer local variable

---
 emacs/notmuch-show.el | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el
index e13ca3d7..1e3834f2 100644
--- a/emacs/notmuch-show.el
+++ b/emacs/notmuch-show.el
@@ -1165,8 +1165,12 @@ is t, hide the part initially and show the button."
   "Insert the thread THREAD at depth DEPTH in the current forest."
   (mapc (lambda (tree) (notmuch-show-insert-tree tree depth)) thread))
 
+(defvar notmuch-show--forest nil)
+(make-variable-buffer-local 'notmuch-show--forest)
+
 (defun notmuch-show-insert-forest (forest)
   "Insert the forest of threads FOREST."
+  (setq notmuch-show--forest forest)
   (mapc (lambda (thread) (notmuch-show-insert-thread thread 0)) forest))
 
 (defvar notmuch-id-regexp
--
2.22.0

_______________________________________________
notmuch mailing list
[hidden email]
https://notmuchmail.org/mailman/listinfo/notmuch
David Edmondson David Edmondson
Reply | Threaded
Open this post in threaded view
|

[PATCH v1 2/2] emacs: Bind "u" to jump to the parent message in a thread

In reply to this post by David Edmondson
---
 emacs/notmuch-show.el | 55 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 55 insertions(+)

diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el
index 1e3834f2..7c50d2cd 100644
--- a/emacs/notmuch-show.el
+++ b/emacs/notmuch-show.el
@@ -1173,6 +1173,60 @@ is t, hide the part initially and show the button."
   (setq notmuch-show--forest forest)
   (mapc (lambda (thread) (notmuch-show-insert-thread thread 0)) forest))
 
+(defun notmuch-show--find-parent-in-thread-node (thread-node id)
+  (let* ((msg (car thread-node))
+ (reply-nodes (cadr thread-node))
+ ;; Is one of the replies to this message the one we are looking
+ ;; for?
+ (candidate
+  (catch 'found
+    (mapc (lambda (reply-node)
+    (let* ((reply-msg (car reply-node))
+   (reply-id (plist-get reply-msg :id)))
+      (when (string= reply-id id)
+ (throw 'found (plist-get msg :id)))))
+  reply-nodes)
+    nil)))
+    (if candidate
+ candidate
+      ;; Otherwise recurse down.
+      (notmuch-show--find-parent-in-thread reply-nodes id))))
+
+(defun notmuch-show--find-parent-in-thread (thread id)
+  (let ((msg (catch 'found
+       (mapc (lambda (thread-node)
+       (setq msg (notmuch-show--find-parent-in-thread-node thread-node id))
+       (when msg
+ (throw 'found msg)))
+     thread)
+       nil)))
+    msg))
+
+(defun notmuch-show--find-parent-in-thread-set (thread-set id)
+  (let ((msg (catch 'found
+       (mapc (lambda (thread)
+       (setq msg (notmuch-show--find-parent-in-thread thread id))
+       (when msg
+ (throw 'found msg)))
+     thread-set)
+       nil)))
+    msg))
+
+(defun notmuch-show--find-parent ()
+  "Find the parent of the current message."
+  (notmuch-show--find-parent-in-thread-set notmuch-show--forest
+   (notmuch-show-get-message-id t)))
+
+(defun notmuch-show--show-parent ()
+  "Jump to the parent of the current message, opening it if necessary."
+  (interactive)
+  (let ((parent (notmuch-show--find-parent)))
+    (unless parent
+      (error "The current message has no parent."))
+    (notmuch-show-goto-message (notmuch-id-to-query parent))
+    (unless (notmuch-show-message-visible-p)
+      (notmuch-show-toggle-message))))
+
 (defvar notmuch-id-regexp
   (concat
    ;; Match the id: prefix only if it begins a word (to disallow, for
@@ -1516,6 +1570,7 @@ reset based on the original query."
     (define-key map "t" 'toggle-truncate-lines)
     (define-key map "." 'notmuch-show-part-map)
     (define-key map "B" 'notmuch-show-browse-urls)
+    (define-key map "u" 'notmuch-show--show-parent)
     map)
   "Keymap for \"notmuch show\" buffers.")
 (fset 'notmuch-show-mode-map notmuch-show-mode-map)
--
2.22.0

_______________________________________________
notmuch mailing list
[hidden email]
https://notmuchmail.org/mailman/listinfo/notmuch
Tomi Ollila-2 Tomi Ollila-2
Reply | Threaded
Open this post in threaded view
|

Re: [PATCH v1 2/2] emacs: Bind "u" to jump to the parent message in a thread

On Thu, Aug 29 2019, David Edmondson wrote:

> ---
>  emacs/notmuch-show.el | 55 +++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 55 insertions(+)
>
> diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el
> index 1e3834f2..7c50d2cd 100644
> --- a/emacs/notmuch-show.el
> +++ b/emacs/notmuch-show.el
> @@ -1173,6 +1173,60 @@ is t, hide the part initially and show the button."
>    (setq notmuch-show--forest forest)
>    (mapc (lambda (thread) (notmuch-show-insert-thread thread 0)) forest))
>  
> +(defun notmuch-show--find-parent-in-thread-node (thread-node id)
> +  (let* ((msg (car thread-node))
> + (reply-nodes (cadr thread-node))
> + ;; Is one of the replies to this message the one we are looking
> + ;; for?
> + (candidate
> +  (catch 'found
> +    (mapc (lambda (reply-node)
> +    (let* ((reply-msg (car reply-node))
> +   (reply-id (plist-get reply-msg :id)))
> +      (when (string= reply-id id)
> + (throw 'found (plist-get msg :id)))))
> +  reply-nodes)
> +    nil)))
> +    (if candidate
> + candidate
> +      ;; Otherwise recurse down.
> +      (notmuch-show--find-parent-in-thread reply-nodes id))))
> +
> +(defun notmuch-show--find-parent-in-thread (thread id)
> +  (let ((msg (catch 'found
> +       (mapc (lambda (thread-node)
> +       (setq msg (notmuch-show--find-parent-in-thread-node thread-node id))
> +       (when msg
> + (throw 'found msg)))
> +     thread)
> +       nil)))
> +    msg))
> +
> +(defun notmuch-show--find-parent-in-thread-set (thread-set id)
> +  (let ((msg (catch 'found
> +       (mapc (lambda (thread)
> +       (setq msg (notmuch-show--find-parent-in-thread thread id))
> +       (when msg
> + (throw 'found msg)))
> +     thread-set)
> +       nil)))
> +    msg))
> +
> +(defun notmuch-show--find-parent ()
> +  "Find the parent of the current message."
> +  (notmuch-show--find-parent-in-thread-set notmuch-show--forest
> +   (notmuch-show-get-message-id t)))
> +
> +(defun notmuch-show--show-parent ()
> +  "Jump to the parent of the current message, opening it if necessary."
> +  (interactive)
> +  (let ((parent (notmuch-show--find-parent)))
> +    (unless parent
> +      (error "The current message has no parent."))

Would it be nicer to just message if there is no parent. do we have
similar (error) cases in after any other interactive command ?

Otherwise this looks good to me. I'd guess forest data structure
is robuse enough for these call paths to work...

dme: What do you think could be done differently to possibly
get less expensive implementation ?

Tomi

> +    (notmuch-show-goto-message (notmuch-id-to-query parent))
> +    (unless (notmuch-show-message-visible-p)
> +      (notmuch-show-toggle-message))))
> +
>  (defvar notmuch-id-regexp
>    (concat
>     ;; Match the id: prefix only if it begins a word (to disallow, for
> @@ -1516,6 +1570,7 @@ reset based on the original query."
>      (define-key map "t" 'toggle-truncate-lines)
>      (define-key map "." 'notmuch-show-part-map)
>      (define-key map "B" 'notmuch-show-browse-urls)
> +    (define-key map "u" 'notmuch-show--show-parent)
>      map)
>    "Keymap for \"notmuch show\" buffers.")
>  (fset 'notmuch-show-mode-map notmuch-show-mode-map)
> --
> 2.22.0
>
> _______________________________________________
> notmuch mailing list
> [hidden email]
> https://notmuchmail.org/mailman/listinfo/notmuch
_______________________________________________
notmuch mailing list
[hidden email]
https://notmuchmail.org/mailman/listinfo/notmuch