unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
* notmuch-emacs: WISH: command notmuch-show-message-up with key bindung u
@ 2019-08-25 10:02 Gregor Zattler
  2019-08-26 14:12 ` David Bremner
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Gregor Zattler @ 2019-08-25 10:02 UTC (permalink / raw)
  To: notmuch

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

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

* Re: notmuch-emacs: WISH: command notmuch-show-message-up with key bindung u
  2019-08-25 10:02 notmuch-emacs: WISH: command notmuch-show-message-up with key bindung u Gregor Zattler
@ 2019-08-26 14:12 ` David Bremner
  2019-08-29 14:16 ` Daniel Kahn Gillmor
  2019-08-29 17:24 ` [PATCH v1 0/2] emacs/show: Add a binding to go up David Edmondson
  2 siblings, 0 replies; 7+ messages in thread
From: David Bremner @ 2019-08-26 14:12 UTC (permalink / raw)
  To: Gregor Zattler, notmuch

Gregor Zattler <telegraph@gmx.net> 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

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

* Re: notmuch-emacs: WISH: command notmuch-show-message-up with key bindung u
  2019-08-25 10:02 notmuch-emacs: WISH: command notmuch-show-message-up with key bindung u Gregor Zattler
  2019-08-26 14:12 ` David Bremner
@ 2019-08-29 14:16 ` Daniel Kahn Gillmor
  2019-08-29 17:24 ` [PATCH v1 0/2] emacs/show: Add a binding to go up David Edmondson
  2 siblings, 0 replies; 7+ messages in thread
From: Daniel Kahn Gillmor @ 2019-08-29 14:16 UTC (permalink / raw)
  To: Gregor Zattler, notmuch

[-- Attachment #1: Type: text/plain, Size: 596 bytes --]

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

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

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

* [PATCH v1 0/2] emacs/show: Add a binding to go up.
  2019-08-25 10:02 notmuch-emacs: WISH: command notmuch-show-message-up with key bindung u Gregor Zattler
  2019-08-26 14:12 ` David Bremner
  2019-08-29 14:16 ` Daniel Kahn Gillmor
@ 2019-08-29 17:24 ` David Edmondson
  2019-08-29 17:24   ` [PATCH v1 1/2] emacs: Stash the currently shown forest in a buffer local variable David Edmondson
  2019-08-29 17:24   ` [PATCH v1 2/2] emacs: Bind "u" to jump to the parent message in a thread David Edmondson
  2 siblings, 2 replies; 7+ messages in thread
From: David Edmondson @ 2019-08-29 17:24 UTC (permalink / raw)
  To: notmuch


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

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

* [PATCH v1 1/2] emacs: Stash the currently shown forest in a buffer local variable
  2019-08-29 17:24 ` [PATCH v1 0/2] emacs/show: Add a binding to go up David Edmondson
@ 2019-08-29 17:24   ` David Edmondson
  2019-08-29 17:24   ` [PATCH v1 2/2] emacs: Bind "u" to jump to the parent message in a thread David Edmondson
  1 sibling, 0 replies; 7+ messages in thread
From: David Edmondson @ 2019-08-29 17:24 UTC (permalink / raw)
  To: notmuch

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

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

* [PATCH v1 2/2] emacs: Bind "u" to jump to the parent message in a thread
  2019-08-29 17:24 ` [PATCH v1 0/2] emacs/show: Add a binding to go up David Edmondson
  2019-08-29 17:24   ` [PATCH v1 1/2] emacs: Stash the currently shown forest in a buffer local variable David Edmondson
@ 2019-08-29 17:24   ` David Edmondson
  2019-08-29 18:50     ` Tomi Ollila
  1 sibling, 1 reply; 7+ messages in thread
From: David Edmondson @ 2019-08-29 17:24 UTC (permalink / raw)
  To: notmuch

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

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

* Re: [PATCH v1 2/2] emacs: Bind "u" to jump to the parent message in a thread
  2019-08-29 17:24   ` [PATCH v1 2/2] emacs: Bind "u" to jump to the parent message in a thread David Edmondson
@ 2019-08-29 18:50     ` Tomi Ollila
  0 siblings, 0 replies; 7+ messages in thread
From: Tomi Ollila @ 2019-08-29 18:50 UTC (permalink / raw)
  To: David Edmondson, notmuch

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
> notmuch@notmuchmail.org
> https://notmuchmail.org/mailman/listinfo/notmuch

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

end of thread, other threads:[~2019-08-29 18:50 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-08-25 10:02 notmuch-emacs: WISH: command notmuch-show-message-up with key bindung u Gregor Zattler
2019-08-26 14:12 ` David Bremner
2019-08-29 14:16 ` Daniel Kahn Gillmor
2019-08-29 17:24 ` [PATCH v1 0/2] emacs/show: Add a binding to go up David Edmondson
2019-08-29 17:24   ` [PATCH v1 1/2] emacs: Stash the currently shown forest in a buffer local variable David Edmondson
2019-08-29 17:24   ` [PATCH v1 2/2] emacs: Bind "u" to jump to the parent message in a thread David Edmondson
2019-08-29 18:50     ` Tomi Ollila

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