emacs: notmuch-tree: customizable strings for drawing trees

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.

Amended-By: db; delete errant '3'
This commit is contained in:
jao 2021-08-31 02:21:06 +01:00 committed by David Bremner
parent 21e365f51a
commit 81cbffa65f

View file

@ -74,6 +74,30 @@
notmuch-unthreaded-show-out notmuch-unthreaded-show-out
notmuch-tree-show-out)) notmuch-tree-show-out))
(defcustom notmuch-tree-thread-symbols
'((prefix . " ")
(top . "")
(top-tee . "")
(vertical . "")
(vertical-tee . "")
(bottom . "")
(arrow . ""))
"Strings used to draw trees in notmuch tree results.
Symbol keys denote where the corresponding string value is used:
`prefix' is used at the top of the tree, followed by `top' if it
has no children or `top-tee' if it does; `vertical' is a bar
connecting with a response down the list skipping the current
one, while `vertical-tee' marks the current message as a reply to
the previous one; `bottom' is used at the bottom of threads.
Finally, the `arrrow' string in the list is used as a pointer to
every message.
Common customizations include setting `prefix' to \"-\", to see
equal-length prefixes, and `arrow' to an empty string or to a
different kind of arrow point."
:type '(alist :key-type symbol :value-type string)
:group 'notmuch-tree)
(defcustom notmuch-tree-result-format (defcustom notmuch-tree-result-format
`(("date" . "%12s ") `(("date" . "%12s ")
("authors" . "%-20s") ("authors" . "%-20s")
@ -983,20 +1007,20 @@ message together with all its descendents."
(replies (cadr tree))) (replies (cadr tree)))
(cond (cond
((and (< 0 depth) (not last)) ((and (< 0 depth) (not last))
(push "" tree-status)) (push (alist-get 'vertical-tee notmuch-tree-thread-symbols) tree-status))
((and (< 0 depth) last) ((and (< 0 depth) last)
(push "" tree-status)) (push (alist-get 'bottom notmuch-tree-thread-symbols) tree-status))
((and (eq 0 depth) first last) ((and (eq 0 depth) first last)
;; Choice between these two variants is a matter of taste. (push (alist-get 'prefix notmuch-tree-thread-symbols) tree-status))
;; (push "─" tree-status))
(push " " tree-status))
((and (eq 0 depth) first (not last)) ((and (eq 0 depth) first (not last))
(push "" tree-status)) (push (alist-get 'top-tee notmuch-tree-thread-symbols) tree-status))
((and (eq 0 depth) (not first) last) ((and (eq 0 depth) (not first) last)
(push "" tree-status)) (push (alist-get 'bottom notmuch-tree-thread-symbols) tree-status))
((and (eq 0 depth) (not first) (not last)) ((and (eq 0 depth) (not first) (not last))
(push "" tree-status))) (push (alist-get 'vertical-tee notmuch-tree-thread-symbols) tree-status)))
(push (concat (if replies "" "") "") tree-status) (push (concat (alist-get (if replies 'top-tee 'top) notmuch-tree-thread-symbols)
(alist-get 'arrow notmuch-tree-thread-symbols))
tree-status)
(setq msg (plist-put msg :first (and first (eq 0 depth)))) (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 :tree-status tree-status))
(setq msg (plist-put msg :orig-tags (plist-get msg :tags))) (setq msg (plist-put msg :orig-tags (plist-get msg :tags)))
@ -1005,7 +1029,7 @@ message together with all its descendents."
(pop tree-status) (pop tree-status)
(if last (if last
(push " " tree-status) (push " " tree-status)
(push "" tree-status)) (push (alist-get 'vertical notmuch-tree-thread-symbols) tree-status))
(notmuch-tree-insert-thread replies (1+ depth) tree-status))) (notmuch-tree-insert-thread replies (1+ depth) tree-status)))
(defun notmuch-tree-insert-thread (thread depth tree-status) (defun notmuch-tree-insert-thread (thread depth tree-status)