From 7b2face8d62761f2c659d1497c02053b28432c5e Mon Sep 17 00:00:00 2001 From: jao Date: Thu, 22 Apr 2021 04:18:16 +0100 Subject: refactorings --- email.org | 289 ++++++++++++++++++++++++++++++++++++-------------------------- 1 file changed, 169 insertions(+), 120 deletions(-) (limited to 'email.org') diff --git a/email.org b/email.org index d01eb13..29b3a0e 100644 --- a/email.org +++ b/email.org @@ -344,55 +344,6 @@ nnrss-directory (jao-gnus-dir "rss")) #+end_src * notmuch -*** hello page - #+begin_src emacs-lisp - (defun jao-notmuch--and (frags) - (when frags (mapconcat #'identity frags " AND "))) - - (defun jao-notmuch--q (d0 d1 &optional k qs) - (list :name (concat d0 (when d1 "/") d1) :search-type 'tree :key k - :query (or (jao-notmuch--and qs) - (format "folder:%s/%s and tag:unread" d0 d1)))) - - (defun jao-notmuch--mboxes-search (box &rest excluded) - (let ((ms (seq-difference (jao-list-mailboxes box) excluded)) - (bp (substring box 0 1))) - (mapcar `(lambda (m) - (jao-notmuch--q ,box (car m) (concat ,bp (cdr m)))) - (shorten-strings (sort ms #'string<))))) - - (defun jao--refresh-agenda () (save-window-excursion (org-agenda-list))) - - (defun jao-notmuch-refresh-hello () - (interactive) - (notmuch-refresh-this-buffer) - (let ((inhibit-message t)) - (beginning-of-buffer) - (widget-forward 2))) - - (with-eval-after-load "notmuch-hello" - (setq notmuch-saved-searches - `(,(jao-notmuch--q "bigml" "inbox" "bi") - ,@(jao-notmuch--mboxes-search "bigml" "inbox" "deploys") - ,(jao-notmuch--q "jao" "inbox" "ji") - ,@(jao-notmuch--mboxes-search "jao" "inbox") - ,@(jao-notmuch--mboxes-search "feeds") - ,(jao-notmuch--q "bml/today" nil "tb" '("tag:bigml" "date:1d..")) - ,(jao-notmuch--q "jao/today" nil "tj" '("tag:jao" "date:1d..")) - ,(jao-notmuch--q "toread" nil "r" '("tag:toread")) - ,(jao-notmuch--q "new" nil "n" '("tag:new")))) - (add-hook 'notmuch-hello-refresh-hook #'jao--refresh-agenda)) - - (setq notmuch-hello-sections '(notmuch-hello-insert-saved-searches - notmuch-hello-insert-alltags - ;; notmuch-hello-insert-recent-searches - notmuch-hello-insert-header) - notmuch-hello-thousands-separator "," - notmuch-hello-recent-searches-max 5 - notmuch-show-all-tags-list t - notmuch-show-logo nil - notmuch-show-empty-saved-searches nil) - #+end_src *** jumping from/to index #+begin_src emacs-lisp (defvar-local jao-notmuch--tree-buffer nil) @@ -434,37 +385,38 @@ (notmuch-refresh-this-buffer))))) #+end_src -*** commands +*** shared commands #+begin_src emacs-lisp - (defun jao-notmuch-jump () + (defun jao-notmuch-saved-search-jump () + "Jump to a saved search, using its key, and ensuring minibuffer can grow." (interactive) (let ((resize-mini-windows t)) (notmuch-jump-search))) (defun jao-notmuch-tag-jump (reverse) + "Create a jump menu for tagging operations, ensuring minibuffer can grow." (interactive "P") (let ((resize-mini-windows t)) (notmuch-tag-jump reverse))) - (defun jao-notmuch-tree-tag (&optional new) + (defun jao-notmuch-tree-by-tag (&optional new) + "Jump to a tag tree search, using its key, and ensuring minibuffer can grow." (interactive "P") (when-let (tag (notmuch-select-tag-with-completion "Forest of tag: ")) (notmuch-tree (concat "tag:" tag) (when new "tag:/unread|new/")))) - (defun jao-notmuch-tree-delete-next (reverse) - (interactive "P") - (notmuch-tree-tag - (notmuch-tag-change-list '("+deleted" "-unread" "-new") reverse)) + (defun jao-notmuch-tree--tag-next (tags reverse &optional thread) + (if thread + (notmuch-tree-tag-thread (notmuch-tag-change-list tags reverse)) + (notmuch-tree-tag (notmuch-tag-change-list tags reverse))) (notmuch-tree-next-matching-message)) - (defun jao-mail-clean-address (fun address) - (let ((address (if (string-match ".+ updates on arXiv.org: \\(.+\\)" - address) - (with-temp-buffer - (insert (match-string 1 address)) - (let ((shr-width 1000)) - (shr-render-region (point-min) (point-max))) - (buffer-string)) - address))) - (funcall fun address))) + (defun jao-notmuch-tree-delete-next (thread) + "Mark as deleted current message (or thread, with prefix) and move to next." + (interactive "P") + (jao-notmuch-tree--tag-next '("+deleted" "-unread" "-new") nil thread)) + + (defun jao-notmuch-tree-flagged-next (reverse) + (interactive "P") + (jao-notmuch-tree--tag-next '("+flagged") reverse)) (defun jao-notmuch-follow-link (&optional external) (interactive "P") @@ -497,38 +449,107 @@ (jao-emms-echo))) (error "Found an enclosure, but not a link!"))))) + #+end_src -*** package +*** hello #+begin_src emacs-lisp - (use-package notmuch - :ensure t - :demand t + (use-package notmuch-hello + :config + (defun jao-notmuch--and (frags) + (when frags (mapconcat #'identity frags " AND "))) + + (defun jao-notmuch--q (d0 d1 &optional k qs) + (list :name (concat d0 (when d1 "/") d1) :search-type 'tree :key k + :query (or (jao-notmuch--and qs) + (format "folder:%s/%s and tag:unread" d0 d1)))) + + (defun jao-notmuch--mboxes-search (box &rest excluded) + (let ((ms (seq-difference (jao-list-mailboxes box) excluded)) + (bp (substring box 0 1))) + (mapcar `(lambda (m) + (jao-notmuch--q ,box (car m) (concat ,bp (cdr m)))) + (shorten-strings (sort ms #'string<))))) + + (setq notmuch-saved-searches + `(,(jao-notmuch--q "bigml" "inbox" "bi") + ,@(jao-notmuch--mboxes-search "bigml" "inbox" "deploys") + ,(jao-notmuch--q "jao" "inbox" "ji") + ,@(jao-notmuch--mboxes-search "jao" "inbox") + ,@(jao-notmuch--mboxes-search "feeds") + ,(jao-notmuch--q "bml/today" nil "tb" '("tag:bigml" "date:1d..")) + ,(jao-notmuch--q "jao/today" nil "tj" '("tag:jao" "date:1d..")) + ,(jao-notmuch--q "flagged" nil "r" '("tag:flagged")) + ,(jao-notmuch--q "new" nil "n" '("tag:new")))) :init - (setq notmuch-fcc-dirs - '(("jao@bigml.com" . "bigml/sent") (".*" . "jao/sent")) - notmuch-message-headers-visible t - jao-notmuch-message-headers '("Subject" "To" "Cc" "Date" - "List-Id" "List-ID" "Reply-To" - "X-Mailer" "User-Agent" "X-User-Agent") - notmuch-message-headers jao-notmuch-message-headers - notmuch-show-mark-read-tags '("-new" "-unread") - notmuch-archive-tags '("+trove" "-new" "-unread" "-inbox") - notmuch-tagging-keys - '(("a" notmuch-archive-tags "Archive") - ("d" notmuch-show-mark-read-tags "Mark read") - ("u" ("+new" "+unread") "Mark unred read") - ("f" ("+flagged") "Flag") - ("r" ("+toread") "Read later") - ("x" ("+deleted" "-new" "-flagged" "-unread") "Deleted")) - notmuch-show-all-multipart/alternative-parts nil - notmuch-show-indent-messages-width 2 + (setq notmuch-hello-sections '(notmuch-hello-insert-saved-searches + notmuch-hello-insert-alltags + ;; notmuch-hello-insert-recent-searches + notmuch-hello-insert-header) + notmuch-hello-thousands-separator "," + notmuch-hello-recent-searches-max 5 + notmuch-show-all-tags-list t + notmuch-show-logo nil + notmuch-show-empty-saved-searches nil) + (defun jao--refresh-agenda () (save-window-excursion (org-agenda-list))) + + (defun jao-notmuch-refresh-hello () + (interactive) + (notmuch-refresh-this-buffer) + (let ((inhibit-message t)) + (beginning-of-buffer) + (widget-forward 2))) + + :hook (notmuch-hello-refresh-hook . jao--refresh-agenda) + :bind (:map notmuch-hello-mode-map + (("g" . jao-notmuch-refresh-hello) + ("S" . consut-notmuch) + ("k" . nil)))) + + #+end_src +*** show + #+begin_src emacs-lisp + (use-package notmuch-show + :init + (setq notmuch-show-all-multipart/alternative-parts nil + notmuch-show-indent-messages-width 0 notmuch-show-imenu-indent t notmuch-show-part-button-default-action 'notmuch-show-view-part notmuch-show-only-matching-messages t - notmuch-tree-result-format + notmuch-wash-signature-lines-max 0 + notmuch-wash-wrap-lines-length 80 + notmuch-wash-citation-lines-prefix 10 + notmuch-wash-citation-lines-suffix 20) + + :config + + (defun jao-mail-clean-address (fun address) + (let ((address (if (string-match ".+ updates on arXiv.org: \\(.+\\)" + address) + (with-temp-buffer + (insert (match-string 1 address)) + (let ((shr-width 1000)) + (shr-render-region (point-min) (point-max))) + (buffer-string)) + address))) + (funcall fun address))) + + (advice-add 'notmuch-clean-address :around #'jao-mail-clean-address) + + :bind (:map notmuch-show-mode-map + (("h" . jao-notmuch-goto-index-buffer) + ("i" . jao-notmuch-toggle-images) + ("j" . jao-notmuch-saved-search-jump) + ("k" . jao-notmuch-tag-jump) + ("C-c C-c" . jao-notmuch-goto-message-in-gnus)))) + #+end_src +*** tree + #+begin_src emacs-lisp + (use-package notmuch-tree + :init + (setq notmuch-tree-result-format '(("date" . "%12s ") ("authors" . "%-35s") - ((("subject" . "%.95s")) . " %-95s") + ((("tree" . "%s ")("subject" . "%s")) . " %-95s") ("tags" . " (%s)")) notmuch-search-result-format '(("date" . "%12s ") @@ -536,45 +557,72 @@ ("authors" . "%-35s") ("subject" . "%-95s") ("tags" . "(%s)")) - notmuch-unthreaded-result-format notmuch-tree-result-format - notmuch-wash-signature-lines-max 0 - notmuch-wash-wrap-lines-length 80 - notmuch-wash-citation-lines-prefix 10 - notmuch-wash-citation-lines-suffix 20) + notmuch-unthreaded-result-format notmuch-tree-result-format) + :config - (when (eq 'notmuch jao-afio-mail-function) - (setq mm-text-html-renderer 'shr)) + (defun jao-notmuch--format-field (fun field &rest args) + (let ((rs (apply fun field args))) + (if (and (stringp field) (string= field "tree")) + (thread-last (replace-regexp-in-string "►" "➤" rs) + (replace-regexp-in-string "╰" "├")) + ;; (thread-last (replace-regexp-in-string "►" "➤" rs) + rs))) - (advice-add 'notmuch-clean-address :around #'jao-mail-clean-address) + (advice-add 'notmuch-tree-format-field :around #'jao-notmuch--format-field) - :bind (:map - notmuch-common-keymap (("T" . jao-notmuch-tree-tag) - ("E" . jao-notmuch-open-enclosure) - ("B" . jao-notmuch-browse-urls) - ("M-g" . jao-notmuch-follow-link) - ("d" . jao-notmuch-tree-delete-next) - ("k" . jao-notmuch-tag-jump) - ("j" . jao-notmuch-jump)) - :map notmuch-message-mode-map - (("C-c C-d" . notmuch-draft-postpone)) - :map notmuch-show-mode-map - (("h" . jao-notmuch-goto-index-buffer) - ("i" . jao-notmuch-toggle-images) - ("j" . jao-notmuch-jump) - ("k" . jao-notmuch-tag-jump) - ("C-c C-c" . jao-notmuch-goto-message-in-gnus)) - :map notmuch-hello-mode-map - (("g" . jao-notmuch-refresh-hello) - ("S" . consult-notmuch)) - :map notmuch-tree-mode-map + :bind (:map notmuch-tree-mode-map (("." . jao-notmuch-toggle-mime-parts) ("i" . jao-notmuch-toggle-images) ("h" . jao-notmuch-goto-message-buffer) ("k" . jao-notmuch-tag-jump)))) #+end_src +*** message + #+begin_src emacs-lisp + (use-package notmuch-message + :init (setq notmuch-fcc-dirs '(("jao@bigml.com" . "bigml/sent") + (".*" . "jao/sent"))) + :bind (:map notmuch-message-mode-map + (("C-c C-d" . notmuch-draft-postpone)))) + + #+end_src +*** main + #+begin_src emacs-lisp + (use-package notmuch + :ensure t + :demand t + + :init + (setq notmuch-show-mark-read-tags '("-new" "-unread") + notmuch-archive-tags '("+trove" "-new" "-unread" "-flagged") + notmuch-tagging-keys + '(("a" notmuch-archive-tags "Archive") + ("d" notmuch-show-mark-read-tags "Mark read") + ("u" ("+new" "+unread") "Mark unred read") + ("f" ("+flagged") "Flag") + ("x" ("+deleted" "-new" "-flagged" "-unread") "Deleted"))) + + :config + + (when (eq 'notmuch jao-afio-mail-function) + (setq mm-text-html-renderer 'shr)) + + :bind (:map notmuch-common-keymap + (("B" . jao-notmuch-browse-urls) + ("E" . jao-notmuch-open-enclosure) + ("M-g" . jao-notmuch-follow-link) + ("T" . notmuch-search-by-tag) + ("U" . notmuch-unthreaded) + ("d" . jao-notmuch-tree-delete-next) + ("j" . jao-notmuch-saved-search-jump) + ("k" . jao-notmuch-tag-jump) + ("s" . notmuch-tree) + ("t" . jao-notmuch-tree-by-tag) + ("u" . jao-notmuch-tree-flagged-next) + ("z" . notmuch-search)))) + #+end_src *** org mode integration - Stolen and adapted from [[https://gist.github.com/fedxa/fac592424473f1b70ea489cc64e08911][Fedor Bezrukov]].] + Stolen and adapted from [[https://gist.github.com/fedxa/fac592424473f1b70ea489cc64e08911][Fedor Bezrukov]]. #+begin_src emacs-lisp (with-eval-after-load "org" (with-eval-after-load "notmuch" @@ -636,9 +684,10 @@ tag_deleted "bigml.(drivel|lists|deploys|bugs)" 3d tag_deleted "bigml.reports" 1d + tag_deleted "bigml.inbox$" 1y + tag_deleted "bigml.support$" 7d tag_deleted "jao.(drivel|lists|books|think)" 3d tag_deleted "feeds.+" 3d - tag_deleted "bigml.inbox$" 1y #+end_src *** expire shell script #+begin_src bash :tangle ./bin/notmuch-expire.sh :tangle-mode (identity #o755) -- cgit v1.2.3