From bfa005de36f4f80f34d622276676a629ca7918f9 Mon Sep 17 00:00:00 2001 From: jao Date: Wed, 18 Aug 2021 22:17:34 +0100 Subject: notmuch: tree folding improvements --- lib/net/jao-notmuch.el | 62 ++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 48 insertions(+), 14 deletions(-) (limited to 'lib/net') diff --git a/lib/net/jao-notmuch.el b/lib/net/jao-notmuch.el index 1bcdaef..ad5657f 100644 --- a/lib/net/jao-notmuch.el +++ b/lib/net/jao-notmuch.el @@ -282,6 +282,13 @@ (defun jao-notmuch--tree-top () (notmuch-tree-get-prop :first)) +(defun jao-notmuch--tree-bottom () + (let ((line-move-ignore-invisible t)) + (save-excursion + (when (zerop (forward-line 1)) + (or (not (notmuch-tree-get-message-properties)) + (jao-notmuch--tree-top)))))) + (defun jao-notmuch-tree-hide-thread () (interactive) (notmuch-tree-thread-top) @@ -313,15 +320,12 @@ (defun jao-notmuch-tree-hide-all () (interactive) - (goto-char (point-min)) (let ((inhibit-read-only t) (line-move-ignore-invisible nil)) - (while (not (eobp)) - (forward-line) - (unless (jao-notmuch--tree-top) - (put-text-property (point) - (min (1+ (line-end-position)) (point-max)) - 'invisible t)))) + (goto-char (point-min)) + (jao-notmuch-tree-hide-thread) + (while (notmuch-tree-next-thread-in-tree) + (jao-notmuch-tree-hide-thread))) (goto-char (point-min))) (defun jao-notmuch-tree-toggle-thread () @@ -345,13 +349,30 @@ m)) (defun jao-notmuch--tree-next (prev thread no-exit) - (save-excursion (jao-notmuch-tree-hide-thread)) - (let ((line-move-ignore-invisible nil)) - (when thread (notmuch-tree-next-thread prev)) - (unless (jao-notmuch--looking-at-new-p) - (notmuch-tree-matching-message prev (not no-exit)))) - (save-excursion (jao-notmuch-tree-show-thread)) - (notmuch-tree-show-message nil) + (let ((line-move-ignore-invisible t)) + (cond ((looking-at-p "^End of search results") + (unless no-exit + (notmuch-tree-close-message-window) + (notmuch-tree-quit))) + ((jao-notmuch--looking-at-new-p) + (save-excursion (jao-notmuch-tree-show-thread)) + (notmuch-tree-show-message nil)) + (thread + (save-excursion (jao-notmuch-tree-hide-thread)) + (when (notmuch-tree-next-thread prev) + (save-excursion (jao-notmuch-tree-show-thread))) + (unless (jao-notmuch--looking-at-new-p) + (notmuch-tree-matching-message prev (not no-exit)))) + ((or (and (not prev) (jao-notmuch--tree-bottom)) + (and prev (jao-notmuch--tree-top))) + (save-excursion (jao-notmuch-tree-hide-thread)) + (forward-line (if prev -1 1)) + (jao-notmuch--tree-next prev nil no-exit)) + ((notmuch-tree-get-message-id) + (save-excursion (jao-notmuch-tree-show-thread)) + (notmuch-tree-matching-message prev (not no-exit))))) + (when (notmuch-tree-get-message-id) + (notmuch-tree-show-message nil)) (jao-notmuch--tree-update-buffer-name)) (defun jao-notmuch-tree-next (thread &optional no-exit) @@ -364,6 +385,19 @@ (interactive "P") (jao-notmuch--tree-next t thread t)) + +;; Updating the tree window after insertion + +(defun jao-notmuch--tree-sentinel (proc &rest _) + (when (eq (process-status proc) 'exit) + (jao-notmuch--tree-update-buffer-name) + (jao-notmuch-tree-hide-all))) + +(defun jao-notmuch-tree-setup () + "Activate final display of trees adjustments." + (advice-add 'notmuch-tree-process-sentinel :after #'jao-notmuch--tree-sentinel)) + + ;; Tagging (defun jao-notmuch-tag-jump-and-next (reverse) -- cgit v1.2.3