summaryrefslogtreecommitdiffhomepage
path: root/attic
diff options
context:
space:
mode:
authorjao <jao@gnu.org>2022-09-23 00:59:24 +0100
committerjao <jao@gnu.org>2022-09-23 01:04:05 +0100
commit0db03a3d92fda3c0cf368826d0fe5a224ad688d0 (patch)
tree96d62b882b4cba7bc97f4c7fc7420052f6ae1d23 /attic
parent5a9447886f4930b93813a201bc7194fa183be54f (diff)
downloadelibs-0db03a3d92fda3c0cf368826d0fe5a224ad688d0.tar.gz
elibs-0db03a3d92fda3c0cf368826d0fe5a224ad688d0.tar.bz2
cleanups for pdf navigation
Diffstat (limited to 'attic')
-rw-r--r--attic/elisp/misc.el85
1 files changed, 85 insertions, 0 deletions
diff --git a/attic/elisp/misc.el b/attic/elisp/misc.el
index d448ae7..870bb37 100644
--- a/attic/elisp/misc.el
+++ b/attic/elisp/misc.el
@@ -319,6 +319,91 @@
(interactive)
(jao-notify "Volume" (format "%s%%" (jao-player-volume))))
+;;; outline mode for notmuch tree view
+
+(defun jao-notmuch-tree--msg-prefix (msg)
+ (insert (propertize (if (plist-get msg :first) "> " " ") 'display " ")))
+
+(defun jao-notmuch-tree--mode-setup ()
+ (setq-local outline-regexp "^> \\|^En")
+ (outline-minor-mode t))
+
+(defun jao-notmuch-tree-hide-others (&optional and-show)
+ (interactive)
+ (outline-hide-body)
+ (outline-show-entry)
+ (when and-show (notmuch-tree-show-message nil)))
+
+(defsubst jao-notmuch-tree--message-open ()
+ (and (buffer-live-p notmuch-tree-message-buffer)
+ (get-buffer-window notmuch-tree-message-buffer)))
+
+(defsubst jao-notmuch--get-prop (prop &optional props)
+ (or (and props (plist-get props prop))
+ (notmuch-tree-get-prop prop)
+ (notmuch-show-get-prop prop)))
+
+(defun jao-notmuch--looking-at-match-p ()
+ (and (jao-notmuch--get-prop :match)
+ (equal (jao-notmuch--get-prop :orig-tags)
+ (jao-notmuch--get-prop :tags))))
+
+(defun jao-notmuch-tree--next (prev thread no-exit &optional ignore-new)
+ (let ((line-move-ignore-invisible nil))
+ (cond ((and (not ignore-new)
+ (jao-notmuch--looking-at-match-p)
+ (not (jao-notmuch-tree--message-open))))
+ (thread
+ (notmuch-tree-next-thread prev)
+ (unless (or (not (notmuch-tree-get-message-properties))
+ (jao-notmuch--looking-at-match-p))
+ (notmuch-tree-matching-message prev (not no-exit))))
+ (t (notmuch-tree-matching-message prev (not no-exit)))))
+ (when (notmuch-tree-get-message-id)
+ (jao-notmuch-tree-hide-others t))
+ (when prev (forward-char 2)))
+
+(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)
+ (define-key m (kbd "n") #'outline-hide-other)
+ 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))
+
+(defun jao-notmuch-tree-next-thread (&optional exit)
+ "Next thread in forest, taking care of thread visibility."
+ (interactive "P")
+ (jao-notmuch-tree--next nil t 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))
+
+(defun jao-notmuch-tree-previous-thread (&optional exit)
+ "Previous thread in forest, taking care of thread visibility."
+ (interactive "P")
+ (jao-notmuch-tree--next t t exit))
+
+
;;; snippets
(defun jao-sway-run-or-focus-tidal ()
(interactive)