summaryrefslogtreecommitdiffhomepage
path: root/lib/net
diff options
context:
space:
mode:
authorjao <jao@gnu.org>2021-08-19 01:07:42 +0100
committerjao <jao@gnu.org>2021-08-19 01:07:42 +0100
commitdb6c56811e26affb096d6921fd57a8d4d051c916 (patch)
tree6731596274c641ed62e4b455fc854cd723bd6875 /lib/net
parent59664f4bc93864add8dd67ec5a64bda1cf73372b (diff)
downloadelibs-db6c56811e26affb096d6921fd57a8d4d051c916.tar.gz
elibs-db6c56811e26affb096d6921fd57a8d4d051c916.tar.bz2
jao-notmuch: simpler tree folding using outline mode
Diffstat (limited to 'lib/net')
-rw-r--r--lib/net/jao-notmuch.el128
1 files changed, 40 insertions, 88 deletions
diff --git a/lib/net/jao-notmuch.el b/lib/net/jao-notmuch.el
index 261d8ce..1bfabf6 100644
--- a/lib/net/jao-notmuch.el
+++ b/lib/net/jao-notmuch.el
@@ -278,112 +278,63 @@
(message n)))
-;; Show/hide threads
+;; Outline mode for tree view
-(defun jao-notmuch--tree-top () (notmuch-tree-get-prop :first))
+(defun jao-notmuch-tree--msg-prefix (msg)
+ (insert (if (plist-get msg :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)
- (save-excursion
- (forward-line 1)
- (when (not (jao-notmuch--tree-top))
- (let ((line-move-ignore-invisible nil)
- (inhibit-read-only t)
- (p (point)))
- (unless (notmuch-tree-next-thread-in-tree)
- (forward-line -1))
- (add-text-properties p (point) '(invisible t))))))
-
-(defun jao-notmuch-tree-show-thread ()
- (interactive)
- (when (or (jao-notmuch--tree-top) (invisible-p (point)))
- (let ((line-move-ignore-invisible nil))
- (notmuch-tree-thread-top)
- (let ((inhibit-read-only t)
- (p (point)))
- (notmuch-tree-next-thread-in-tree)
- (remove-text-properties p (point) '(invisible nil))
- (goto-char p)))))
-
-(defun jao-notmuch-tree-show-all ()
- (interactive)
- (let ((inhibit-read-only t))
- (put-text-property (point-min) (point-max) 'invisible nil)))
+(defun jao-notmuch-tree--mode-setup ()
+ (setq-local outline-regexp "^> \\|^En")
+ (outline-minor-mode t))
-(defun jao-notmuch-tree-hide-all ()
+(defun jao-notmuch-tree-hide-others (&optional and-show)
(interactive)
- (let ((inhibit-read-only t)
- (line-move-ignore-invisible nil))
- (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)))
+ (outline-hide-body)
+ (outline-show-entry)
+ (when and-show (notmuch-tree-show-message nil)))
-(defun jao-notmuch-tree-toggle-thread ()
- (interactive)
- (let ((line-move-ignore-invisible nil))
- (forward-line 1)
- (when (jao-notmuch--tree-top)
- (forward-line -1))
- (if (invisible-p (point))
- (jao-notmuch-tree-show-thread)
- (jao-notmuch-tree-hide-thread))))
-
-(defvar notmuch-tree-thread-map
- (let ((m (make-keymap "Thread operations")))
- (define-key m (kbd "TAB") #'jao-notmuch-tree-toggle-thread)
- (define-key m (kbd "t") #'jao-notmuch-tree-toggle-thread)
- (define-key m (kbd "s") #'jao-notmuch-tree-show-thread)
- (define-key m (kbd "S") #'jao-notmuch-tree-show-all)
- (define-key m (kbd "h") #'jao-notmuch-tree-hide-thread)
- (define-key m (kbd "H") #'jao-notmuch-tree-hide-all)
- m))
-
-(defun jao-notmuch--tree-next (prev thread no-exit)
+(defun jao-notmuch-tree--next (prev thread no-exit)
(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))
+ (cond ((jao-notmuch--looking-at-new-p))
(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))
+ (unless (jao-notmuch--looking-at-new-p)
+ (notmuch-tree-matching-message prev (not 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)
+ (jao-notmuch-tree-hide-others)
(notmuch-tree-show-message nil))
(jao-notmuch--tree-update-buffer-name))
+(defvar jao-notmuch-tree--prefix-map
+ (let ((m (make-keymap "Thread operations")))
+ (define-key m (kbd "TAB") #'outline-cycle)
+ (define-key m (kbd "t") #'outline-toggle-children)
+ (define-key m (kbd "s") #'outline-show-entry)
+ (define-key m (kbd "S") #'outline-show-all)
+ (define-key m (kbd "h") #'outline-hide-entry)
+ (define-key m (kbd "H") #'outline-hide-body)
+ (define-key m (kbd "o") #'jao-notmuch-tree-hide-others)
+ m))
+
+(defun jao-notmuch-tree-outline-setup (&optional prefix)
+ (define-key notmuch-tree-mode-map (kbd (or prefix "T"))
+ jao-notmuch-tree--prefix-map)
+ (define-key notmuch-tree-mode-map (kbd "TAB") #'outline-cycle)
+ (define-key notmuch-tree-mode-map (kbd "M-TAB") #'outline-cycle-buffer)
+ (add-hook 'notmuch-tree-mode-hook #'jao-notmuch-tree--mode-setup)
+ (advice-add 'notmuch-tree-insert-msg :before #'jao-notmuch-tree--msg-prefix))
+
(defun jao-notmuch-tree-next (thread &optional no-exit)
"Next message or thread in forest, taking care of thread visibility."
(interactive "P")
- (jao-notmuch--tree-next nil thread no-exit))
+ (jao-notmuch-tree--next nil thread no-exit))
(defun jao-notmuch-tree-previous (thread)
"Previous message or thread in forest, taking care of thread visibility.."
(interactive "P")
- (jao-notmuch--tree-next t thread t))
+ (jao-notmuch-tree--next t thread t))
;; Updating the tree window after insertion
@@ -391,10 +342,11 @@
(defun jao-notmuch--tree-sentinel (proc &rest _)
(when (eq (process-status proc) 'exit)
(jao-notmuch--tree-update-buffer-name)
- (jao-notmuch-tree-hide-all)))
+ (jao-notmuch-tree-hide-others t)))
-(defun jao-notmuch-tree-setup ()
- "Activate final display of trees adjustments."
+(defun jao-notmuch-tree-setup (&optional prefix)
+ "Set up display of trees, with PREFIX key for outline commands."
+ (jao-notmuch-tree-outline-setup prefix)
(advice-add 'notmuch-tree-process-sentinel :after #'jao-notmuch--tree-sentinel))