From 7da7f5f627b9ba657f3fb08c8eacf2de9300d770 Mon Sep 17 00:00:00 2001 From: jao Date: Sat, 12 Jun 2021 22:15:15 +0100 Subject: jao-notmuch clean-ups --- lib/net/jao-notmuch.el | 50 ++++++++++++++++++++++++++++---------------------- 1 file changed, 28 insertions(+), 22 deletions(-) (limited to 'lib/net') diff --git a/lib/net/jao-notmuch.el b/lib/net/jao-notmuch.el index 5916840..fd2694f 100644 --- a/lib/net/jao-notmuch.el +++ b/lib/net/jao-notmuch.el @@ -24,6 +24,8 @@ ;;; Code: +(require 'eww) + (require 'notmuch) (require 'notmuch-tree) (require 'notmuch-show) @@ -41,7 +43,7 @@ (match-string 0 full-path) (user-error "Message not in any mailbox!"))) -(defun jao-notmuch-msg-props () +(defun jao-notmuch--msg-props () (if-let ((p (save-excursion (text-property-search-forward :notmuch-message-properties)))) (prop-match-value p) @@ -50,32 +52,30 @@ (defun jao-notmuch--move (full-path &optional d) (let* ((ff (jao-notmuch--path-to-mailbox full-path)) (d (or d (completing-read (format "From %s to: " ff) - (remove ff jao-notmuch-mailboxes) - nil - t))) + (remove ff jao-notmuch-mailboxes) nil t))) (dest (string-replace ff d full-path)) (dest (replace-regexp-in-string ",U=.+$" "" dest)) (fnd (file-name-nondirectory full-path)) - (dnd (file-name-nondirectory dest)) - (prompt (format "%s/%s -> %s/%s? " ff fnd d dnd))) - (when (y-or-n-p prompt) - (let ((c (notmuch-tag-change-list (split-string ff "/") t)) - (cc (notmuch-tag-change-list (split-string d "/")))) - (notmuch-tree-tag (append c cc))) + (dnd (file-name-nondirectory dest))) + (when (y-or-n-p (format "%s/%s -> %s/%s? " ff fnd d dnd)) + (notmuch-tree-tag (append (notmuch-tag-change-list (split-string ff "/") t) + (split-string d "/"))) (notmuch-tree-close-message-window) (rename-file full-path dest) (shell-command-to-string "notmuch new") (notmuch-refresh-this-buffer)))) (defun jao-notmuch-move-message () + "Move message at point to another folder." (interactive) - (let* ((p (jao-notmuch-msg-props)) + (let* ((p (jao-notmuch--msg-props)) (f (car (plist-get p :filename)))) (jao-notmuch--move (or f "")))) (defun jao-notmuch-tree-spam () - (interactive) - (let* ((p (jao-notmuch-msg-props)) + "Move message at point to the spam folder." + (interactive) + (let* ((p (jao-notmuch--msg-props)) (f (car (plist-get p :filename))) (mbox (car (split-string (jao-notmuch--path-to-mailbox f) "/")))) (notmuch-tree-tag '("-new" "-unread")) @@ -102,11 +102,11 @@ (unless (eq 'url (jao-notmuch-goto-message-buffer t)) (pop-to-buffer b)))) -(defun jao-notmuch-goto-index-buffer () +(defun jao-notmuch-goto-tree-buffer () (interactive) (if (buffer-live-p jao-notmuch--tree-buffer) (pop-to-buffer jao-notmuch--tree-buffer) - (user-error "No index for this buffer"))) + (user-error "No tree view for this buffer"))) (defun jao-notmuch-browse-urls () (interactive) @@ -125,7 +125,7 @@ (when (re-search-forward "\\[ multipart/alternative \\]" nil t) (while (forward-button 1 nil nil t) (notmuch-show-toggle-part-invisibility))))) - (jao-notmuch-goto-index-buffer))) + (jao-notmuch-goto-tree-buffer))) (defun jao-notmuch-toggle-images () (interactive) @@ -144,21 +144,27 @@ (save-excursion (goto-char (point-min)) (let ((p) (cnt)) - (while (setq p (text-property-search-forward - :notmuch-message-properties)) + (while (setq p (text-property-search-forward :notmuch-message-properties)) (unless cnt (setq cnt 0)) (let ((tags (plist-get (prop-match-value p) :tags))) (when (or (member "unread" tags) (member "new" tags)) (setq cnt (1+ cnt))))) cnt))) -(defun jao-notmuch-tree-update-buffer-name (&optional n) +(defun jao-notmuch--tree-update-buffer-name (&optional n) (when-let ((n (or n (jao-notmuch--unread-count)))) (rename-buffer (format "*%s - {%s messages left}*" notmuch-tree-basic-query n)) (jao-minibuffer-refresh))) +(defun jao-notmuch-echo-count () + "Show the number of unread messages left in this tree view." + (interactive) + (when-let ((n (jao-notmuch--unread-count))) + (jao-notmuch--tree-update-buffer-name n) + (message "%s messages left" n))) + (defun jao-notmuch-tree-next (thread &optional no-exit) "Next message or thread in forest or exit if none." (interactive "P") @@ -166,7 +172,7 @@ (progn (notmuch-tree-next-thread) (notmuch-tree-show-message nil)) (notmuch-tree-next-matching-message (not no-exit))) - (jao-notmuch-tree-update-buffer-name)) + (jao-notmuch--tree-update-buffer-name)) ;; Tagging @@ -201,7 +207,7 @@ (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)) + (jao-notmuch--tree-update-buffer-name)) (defun jao-notmuch-tree-show-or-scroll () "Show current message, or scroll it if visible." @@ -209,7 +215,7 @@ (if (window-live-p notmuch-tree-message-window) (scroll-other-window 1) (notmuch-tree-show-message nil) - (jao-notmuch-tree-update-buffer-name))) + (jao-notmuch--tree-update-buffer-name))) (provide 'jao-notmuch) -- cgit v1.2.3