diff options
author | jao <jao@gnu.org> | 2021-08-03 15:16:35 +0100 |
---|---|---|
committer | jao <jao@gnu.org> | 2021-08-03 15:16:48 +0100 |
commit | a812744c54681603ca07efddea749e210aee0511 (patch) | |
tree | 59271f5c164ddb075f91e8b498fe4d376f7c839f | |
parent | 8a3718bf2866dfa322a8b1d5c5f293a422154fa9 (diff) | |
download | elibs-a812744c54681603ca07efddea749e210aee0511.tar.gz elibs-a812744c54681603ca07efddea749e210aee0511.tar.bz2 |
notmuch: scrolling and closing message window
-rw-r--r-- | lib/net/jao-notmuch.el | 67 |
1 files changed, 42 insertions, 25 deletions
diff --git a/lib/net/jao-notmuch.el b/lib/net/jao-notmuch.el index 2a785b1..918171f 100644 --- a/lib/net/jao-notmuch.el +++ b/lib/net/jao-notmuch.el @@ -90,6 +90,12 @@ (cond ((eww--url-at-point) (shr-browse-url) 'url) ((button-at (point)) (push-button) 'button)))))) +(defun jao-notmuch-tree-toggle-message () + (interactive) + (if (window-live-p notmuch-tree-message-window) + (notmuch-tree-close-message-window) + (notmuch-tree-show-message nil))) + (defun jao-notmuch-click-message-buffer () (interactive) (let ((b (current-buffer))) @@ -102,6 +108,31 @@ (pop-to-buffer jao-notmuch--tree-buffer nil no-record) (user-error "No tree view for this buffer"))) +(defun jao-notmuch-tree-scroll-or-next () + "Scroll or next message in forest or exit if none." + (interactive) + (if (notmuch-tree-scroll-message-window) + (notmuch-tree-next-matching-message t) + (when (not (window-live-p notmuch-tree-message-window)) + (notmuch-tree-show-message nil))) + (jao-notmuch--tree-update-buffer-name)) + +(defun jao-notmuch-tree-show-or-scroll () + "Show current message, or scroll it if visible." + (interactive) + (if (window-live-p notmuch-tree-message-window) + (scroll-other-window 1) + (notmuch-tree-show-message nil) + (jao-notmuch--tree-update-buffer-name))) + +(notmuch-tree--define-do-in-message-window + jao-notmuch-tree-end-of-buffer + end-of-buffer) + +(notmuch-tree--define-do-in-message-window + jao-notmuch-tree-beginning-of-buffer + beginning-of-buffer) + (defun jao-notmuch-show-next-button () (interactive) (when (get-text-property (point) 'w3m-href-anchor) @@ -116,7 +147,7 @@ (goto-char (previous-single-property-change pos 'w3m-href-anchor)) (backward-button 1))) -(defun jao-w3m-get-page-urls (res) +(defun jao-notmuch--page-urls (res) (save-excursion (goto-char (point-min)) (let ((pos (point))) @@ -129,7 +160,7 @@ (interactive "P") (when (or (derived-mode-p 'notmuch-show-mode) (jao-notmuch-goto-message-buffer)) - (let ((urls (jao-w3m-get-page-urls (notmuch-show--gather-urls))) + (let ((urls (jao-notmuch--page-urls (notmuch-show--gather-urls))) (fn (if external browse-url-secondary-browser-function #'browse-url))) (if urls (funcall fn (completing-read "Browse URL: " urls)) @@ -199,16 +230,19 @@ notmuch-saved-searches))) (or (plist-get q :name) notmuch-tree-basic-query)))))) +(defun jao-notmuch--looking-at-new-p (&optional p) + (when-let (ts (if p (plist-get p :tags) (notmuch-show-get-tags))) + (or (member "unread" ts) (member "new" ts)))) + (defun jao-notmuch--unread-count () (save-excursion (goto-char (point-min)) (let ((p) (cnt) (total)) (while (setq p (text-property-search-forward :notmuch-message-properties)) (unless cnt (setq cnt 0 total 0)) - (let ((tags (plist-get (prop-match-value p) :tags))) - (setq total (1+ total)) - (when (or (member "unread" tags) (member "new" tags)) - (setq cnt (1+ cnt))))) + (setq total (1+ total)) + (when (jao-notmuch--looking-at-new-p (prop-match-value p)) + (setq cnt (1+ cnt)))) (when cnt (format "%s / %s messages" cnt total))))) (defun jao-notmuch--tree-update-buffer-name (&optional n) @@ -236,6 +270,8 @@ (interactive "P") (if thread (progn (notmuch-tree-next-thread) + (unless (jao-notmuch--looking-at-new-p) + (notmuch-tree-next-matching-message (not no-exit))) (notmuch-tree-show-message nil)) (notmuch-tree-next-matching-message (not no-exit))) (jao-notmuch--tree-update-buffer-name)) @@ -274,25 +310,6 @@ (let ((tags (if unmark '("-spam") '("-unread" "-new" "+spam")))) (jao-notmuch-tree--tag-and-next tags nil nil))) -;; Scrolling the shown message - -(defun jao-notmuch-tree-scroll-or-next () - "Scroll or next message in forest or exit if none." - (interactive) - (if (notmuch-tree-scroll-message-window) - (notmuch-tree-next-matching-message t) - (when (not (window-live-p notmuch-tree-message-window)) - (notmuch-tree-show-message nil))) - (jao-notmuch--tree-update-buffer-name)) - -(defun jao-notmuch-tree-show-or-scroll () - "Show current message, or scroll it if visible." - (interactive) - (if (window-live-p notmuch-tree-message-window) - (scroll-other-window 1) - (notmuch-tree-show-message nil) - (jao-notmuch--tree-update-buffer-name))) - (provide 'jao-notmuch) ;;; jao-notmuch.el ends here |