summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--lib/net/jao-notmuch.el67
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