unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
* [PATCH] emacs: notmuch-tree: customizable strings for drawing trees
@ 2021-08-21  1:55 jao
  0 siblings, 0 replies; 5+ messages in thread
From: jao @ 2021-08-21  1:55 UTC (permalink / raw)
  To: notmuch; +Cc: jao

New customizable variable, notmuch-tree-tread-symbols, that allows
tweaking how trees in a forest are represented.  For instance, one can
now choose to use an hyphen rather than a white space as a prefix, or
remove pointy arrows.
---
 emacs/notmuch-tree.el | 35 +++++++++++++++++++++++++----------
 1 file changed, 25 insertions(+), 10 deletions(-)

diff --git a/emacs/notmuch-tree.el b/emacs/notmuch-tree.el
index 01a77b71..27e5ac3a 100644
--- a/emacs/notmuch-tree.el
+++ b/emacs/notmuch-tree.el
@@ -74,6 +74,21 @@
       notmuch-unthreaded-show-out
     notmuch-tree-show-out))
 
+(defcustom notmuch-tree-thread-symbols '(" " "─" "┬" "│" "├" "╰" "►")
+  "List of strings used to draw trees.
+The first element is used at the top of the tree, followed by the
+second if it has no direct children or the third if it does.  The
+fourth is a bar connecting with a response down the list skipping
+the current one, while the fifth does not skip.  The sixth and
+the bottom of the thread.  Finally, the last one is a pointer to
+every messages.
+
+Common customizations include setting the first element of the
+list to \"-\", to see equal-length prefixes, or the last and
+empty string or a different kind of arrow point."
+  :type '(list string)
+  :group 'notmuch-tree)
+
 (defcustom notmuch-tree-result-format
   `(("date" . "%12s  ")
     ("authors" . "%-20s")
@@ -968,20 +983,20 @@ message together with all its descendents."
 	(replies (cadr tree)))
     (cond
      ((and (< 0 depth) (not last))
-      (push "├" tree-status))
+      (push (elt notmuch-tree-thread-symbols 4) tree-status))
      ((and (< 0 depth) last)
-      (push "╰" tree-status))
+      (push (elt notmuch-tree-thread-symbols 5) tree-status))
      ((and (eq 0 depth) first last)
-      ;; Choice between these two variants is a matter of taste.
-      ;; (push "─" tree-status))
-      (push " " tree-status))
+      (push (elt notmuch-tree-thread-symbols 0) tree-status))
      ((and (eq 0 depth) first (not last))
-      (push "┬" tree-status))
+      (push (elt notmuch-tree-thread-symbols 2) tree-status))
      ((and (eq 0 depth) (not first) last)
-      (push "╰" tree-status))
+      (push (elt notmuch-tree-thread-symbols 5) tree-status))
      ((and (eq 0 depth) (not first) (not last))
-      (push "├" tree-status)))
-    (push (concat (if replies "┬" "─") "►") tree-status)
+      (push (elt notmuch-tree-thread-symbols 4) tree-status)))
+    (push (concat (elt notmuch-tree-thread-symbols (if replies 2 1))
+		  (elt notmuch-tree-thread-symbols 6))
+	  tree-status)
     (setq msg (plist-put msg :first (and first (eq 0 depth))))
     (setq msg (plist-put msg :tree-status tree-status))
     (setq msg (plist-put msg :orig-tags (plist-get msg :tags)))
@@ -990,7 +1005,7 @@ message together with all its descendents."
     (pop tree-status)
     (if last
 	(push " " tree-status)
-      (push "│" tree-status))
+      (push (elt notmuch-tree-thread-symbols 3) tree-status))
     (notmuch-tree-insert-thread replies (1+ depth) tree-status)))
 
 (defun notmuch-tree-insert-thread (thread depth tree-status)
-- 
2.33.0\r

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

* [PATCH] emacs: notmuch-tree: customizable strings for drawing trees
@ 2021-08-22 23:58 jao
  2021-08-23  0:06 ` Jose Antonio Ortega Ruiz
  2021-08-30 15:37 ` David Bremner
  0 siblings, 2 replies; 5+ messages in thread
From: jao @ 2021-08-22 23:58 UTC (permalink / raw)
  To: notmuch; +Cc: jao

New customizable variable, notmuch-tree-thread-symbols, that allows
tweaking of how trees in a forest are represented.  For instance, one
can now choose to use an hyphen rather than a white space as a prefix,
or replace the character(s) used to draw arrows.
---
 emacs/notmuch-tree.el | 36 ++++++++++++++++++++++++++----------
 1 file changed, 26 insertions(+), 10 deletions(-)

diff --git a/emacs/notmuch-tree.el b/emacs/notmuch-tree.el
index 2f508128..a1dfa7b1 100644
--- a/emacs/notmuch-tree.el
+++ b/emacs/notmuch-tree.el
@@ -74,6 +74,22 @@
       notmuch-unthreaded-show-out
     notmuch-tree-show-out))
 
+(defcustom notmuch-tree-thread-symbols '(" " "─" "┬" "│" "├" "╰" "►")
+  "List of strings used to draw trees in notmuch tree results.
+The first element is used at the top of the tree, followed by the
+second if it has no children or the third if it does.  The fourth
+is a bar connecting with a response down the list skipping the
+current one, while the fifth marks the current message as a reply
+to the previous.  The sixth string is used at the bottom of
+threads.  Finally, the last string in the list is used as a
+pointer to every message.
+
+Common customizations include setting the first element of the
+list to \"-\", to see equal-length prefixes, or the last to an
+empty string or to a different kind of arrow point."
+  :type '(list string)
+  :group 'notmuch-tree)
+
 (defcustom notmuch-tree-result-format
   `(("date" . "%12s  ")
     ("authors" . "%-20s")
@@ -968,20 +984,20 @@ message together with all its descendents."
 	(replies (cadr tree)))
     (cond
      ((and (< 0 depth) (not last))
-      (push "├" tree-status))
+      (push (elt notmuch-tree-thread-symbols 4) tree-status))
      ((and (< 0 depth) last)
-      (push "╰" tree-status))
+      (push (elt notmuch-tree-thread-symbols 5) tree-status))
      ((and (eq 0 depth) first last)
-      ;; Choice between these two variants is a matter of taste.
-      ;; (push "─" tree-status))
-      (push " " tree-status))
+      (push (elt notmuch-tree-thread-symbols 0) tree-status))
      ((and (eq 0 depth) first (not last))
-      (push "┬" tree-status))
+      (push (elt notmuch-tree-thread-symbols 2) tree-status))
      ((and (eq 0 depth) (not first) last)
-      (push "╰" tree-status))
+      (push (elt notmuch-tree-thread-symbols 5) tree-status))
      ((and (eq 0 depth) (not first) (not last))
-      (push "├" tree-status)))
-    (push (concat (if replies "┬" "─") "►") tree-status)
+      (push (elt notmuch-tree-thread-symbols 4) tree-status)))
+    (push (concat (elt notmuch-tree-thread-symbols (if replies 2 1))
+		  (elt notmuch-tree-thread-symbols 6))
+	  tree-status)
     (setq msg (plist-put msg :first (and first (eq 0 depth))))
     (setq msg (plist-put msg :tree-status tree-status))
     (setq msg (plist-put msg :orig-tags (plist-get msg :tags)))
@@ -990,7 +1006,7 @@ message together with all its descendents."
     (pop tree-status)
     (if last
 	(push " " tree-status)
-      (push "│" tree-status))
+      (push (elt notmuch-tree-thread-symbols 3) tree-status))
     (notmuch-tree-insert-thread replies (1+ depth) tree-status)))
 
 (defun notmuch-tree-insert-thread (thread depth tree-status)
-- 
2.33.0\r

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

* Re: [PATCH] emacs: notmuch-tree: customizable strings for drawing trees
  2021-08-22 23:58 [PATCH] emacs: notmuch-tree: customizable strings for drawing trees jao
@ 2021-08-23  0:06 ` Jose Antonio Ortega Ruiz
  2021-08-30 15:37 ` David Bremner
  1 sibling, 0 replies; 5+ messages in thread
From: Jose Antonio Ortega Ruiz @ 2021-08-23  0:06 UTC (permalink / raw)
  To: notmuch


This one should have been sent with a version 3 mark, sorry.  It's
essentially the previous version (with yet another doc typo corrected),
but rebased against today's master.

Cheers,
jao

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

* Re: [PATCH] emacs: notmuch-tree: customizable strings for drawing trees
  2021-08-22 23:58 [PATCH] emacs: notmuch-tree: customizable strings for drawing trees jao
  2021-08-23  0:06 ` Jose Antonio Ortega Ruiz
@ 2021-08-30 15:37 ` David Bremner
  2021-08-30 18:43   ` Jose Antonio Ortega Ruiz
  1 sibling, 1 reply; 5+ messages in thread
From: David Bremner @ 2021-08-30 15:37 UTC (permalink / raw)
  To: jao, notmuch; +Cc: jao

jao <jao@gnu.org> writes:

> +(defcustom notmuch-tree-thread-symbols '(" " "─" "┬" "│" "├" "╰" "►")

How hard would it be to use a plist or an alist, and allow the user to
overide only the symbols they are interested in?

> +      (push (elt notmuch-tree-thread-symbols 4) tree-status))

As hinted above, I don't love the intriduction of magic indices,
although I guess it might be tolerable if they are used only in one place.

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

* Re: [PATCH] emacs: notmuch-tree: customizable strings for drawing trees
  2021-08-30 15:37 ` David Bremner
@ 2021-08-30 18:43   ` Jose Antonio Ortega Ruiz
  0 siblings, 0 replies; 5+ messages in thread
From: Jose Antonio Ortega Ruiz @ 2021-08-30 18:43 UTC (permalink / raw)
  To: David Bremner, notmuch

On Mon, Aug 30 2021, David Bremner wrote:

> jao <jao@gnu.org> writes:
>
>> +(defcustom notmuch-tree-thread-symbols '(" " "─" "┬" "│" "├" "╰" "►")
>
> How hard would it be to use a plist or an alist, and allow the user to
> overide only the symbols they are interested in?

not hard at all... we just need to figure out good names (suggestions
welcome).  i think i'd prefer an alist, but it's not a strong preference
if you'd rather have a plist.

>> +      (push (elt notmuch-tree-thread-symbols 4) tree-status))
>
> As hinted above, I don't love the intriduction of magic indices,
> although I guess it might be tolerable if they are used only in one place.

yes, i agree.  i even had some code where i had variables for those
indices, but felt a bit overkill for things used in just one place.  but
using a plist/alist would give us what we need here.

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

end of thread, other threads:[~2021-08-30 18:43 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-08-22 23:58 [PATCH] emacs: notmuch-tree: customizable strings for drawing trees jao
2021-08-23  0:06 ` Jose Antonio Ortega Ruiz
2021-08-30 15:37 ` David Bremner
2021-08-30 18:43   ` Jose Antonio Ortega Ruiz
  -- strict thread matches above, loose matches on Subject: below --
2021-08-21  1:55 jao

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