diff options
Diffstat (limited to 'custom/jao-custom-notmuch.el')
| -rw-r--r-- | custom/jao-custom-notmuch.el | 521 |
1 files changed, 310 insertions, 211 deletions
diff --git a/custom/jao-custom-notmuch.el b/custom/jao-custom-notmuch.el index 42d9e12..ca2664c 100644 --- a/custom/jao-custom-notmuch.el +++ b/custom/jao-custom-notmuch.el @@ -1,62 +1,86 @@ -;; -*- lexical-binding: t; -*- +;;; -*- lexical-binding: t; -*- ;;; minibuffer (defvar jao-notmuch-minibuffer-string "") (defvar jao-notmuch-minibuffer-queries `((:name "" :query "tag:new and not tag:draft" :face jao-themes-f00) - (:name "B" :query "tag:new and tag:bigml and tag:inbox" :face default) - (:name "A" :query "tag:new and tag:alba" :face default) - (:name "b" :query "tag:new and tag:bigml and tag:bugs" - :face jao-themes-error) - (:name "S" :query "tag:new and tag:bigml and tag:support" :face default) - (:name "W" - :query "tag:new and tag:bigml and not tag:\"/support|bugs|inbox/\"" - :face default) - (:name "I" :query "tag:new and tag:jao and tag:inbox" :face jao-themes-warning) - (:name "W" :query "tag:new and tag:jao and tag:write" :face jao-themes-warning) + (:name "I" :query "tag:new and tag:jao and tag:inbox" + :face jao-themes-warning) + (:name "W" :query "tag:new and tag:jao and tag:write" + :face jao-themes-warning) (:name "J" - :query ,(concat "tag:new and tag:jao and not " - "tag:\"/local|hacking|draft|inbox|prog|words|write/\"") + :query + ,(concat "tag:new and tag:jao and not " + "tag:\"/feeds|local|hacking|draft|inbox|prog|words|write/\"") :face default) (:name "H" :query "tag:new and tag:hacking and not tag:\"/emacs/\"") (:name "E" :query "tag:new and tag:\"/emacs/\"") (:name "l" :query "tag:new and tag:local") (:name "F" :query "tag:new and tag:feeds and not tag:\"/emacs/\""))) +(defvar jao-notmuch-xbar-queries + `((:name "" :query "tag:new and not tag:draft" :face jao-themes-f00) + (:name "i" :query "tag:new and tag:/inbox|write|drivel/" + :face jao-themes-warning))) + +(defsubst jao-notmuch--qstr (c) + (format "%s%s" (plist-get c :name) (plist-get c :count))) + +(defvar jao-notmuch-mac-xbar t) +(defvar jao-notmuch-mac-mail-badge nil) + +(defun jao-notmuch-xbar () + (let ((cnts (notmuch-hello-query-counts jao-notmuch-xbar-queries))) + (jao-shell-exec (format "echo '%s | color=#8b3626 | size=11' >/tmp/xbar" + (mapconcat 'jao-notmuch--qstr cnts " "))))) + (defun jao-notmuch-notify () - (let ((cnts (notmuch-hello-query-counts jao-notmuch-minibuffer-queries))) + (interactive) + (let* ((cnts (notmuch-hello-query-counts jao-notmuch-minibuffer-queries)) + (mc (jao-d-l + (when jao-notmuch-mac-mail-badge (jao-mac-app-badge "Mail")) + 0)) + (cnts (if (> (or mc 0) 0) (cons `(:name "" :count ,mc) cnts) cnts))) (setq jao-notmuch-minibuffer-string (mapconcat (lambda (c) - (propertize (format "%s%s" - (plist-get c :name) - (plist-get c :count)) + (propertize (jao-notmuch--qstr c) 'face (or (plist-get c :face) 'jao-themes-dimm))) cnts " ")) + (jao-when-darwin (when jao-notmuch-mac-xbar (jao-notmuch-xbar))) (jao-minibuffer-refresh))) +(defun jao-notmuch-notify-and-update () + (jao-notmuch-notify) + (with-current-buffer "*notmuch-hello*" + (notmuch-hello-update) + (jao-notmuch-hello-first))) + (when jao-notmuch-enabled (jao-minibuffer-add-variable 'jao-notmuch-minibuffer-string -20)) ;;; saved searches -(defvar jao-notmuch--new "tag:\"/^(unread|new)$/\"") -(defvar jao-notmuch--newa (concat jao-notmuch--new " AND ")) +(defvar jao-notmuch--new nil) +(defvar jao-notmuch--new-rx nil) +(defvar jao-notmuch--newa nil) -(defun jao-notmuch--q (d0 d1 &optional k qs st) +(defun jao-notmuch--set-new-search (s) + (setq jao-notmuch--new s + jao-notmuch--new-rx (regexp-quote jao-notmuch--new) + jao-notmuch--newa (concat jao-notmuch--new " AND "))) + +(defun jao-notmuch--q (d0 &optional k d1 qs st) (let ((q (or (when qs (mapconcat #'identity qs " AND ")) - (concat jao-notmuch--newa - (mapconcat (lambda (d) (when d (concat "tag:" d))) - (list d0 d1) " AND "))))) + (concat jao-notmuch--new + (mapconcat (lambda (d) (when d (concat " AND tag:" d))) + (list d0 d1)))))) (list :name (concat d0 (when (and d1 (not (string= "" d1))) "/") d1) :key k :query q :search-type (or st 'tree) :sort-order 'oldest-first))) -(defun jao-notmuch--qn (d0 d1 k qs &optional st) - (jao-notmuch--q d0 d1 k (cons jao-notmuch--new qs) st)) - -(defun jao-notmuch--sq (tag &optional k d0 d1) - (jao-notmuch--qn (or d0 "feeds") (or d1 tag) k (list (concat "tag:" tag)))) +(defun jao-notmuch--q-feed (q) + (apply #'jao-notmuch--q (cons "feeds" q))) (defun jao-notmuch-tree-widen-search () (interactive) @@ -65,12 +89,13 @@ (notmuch-tree-close-message-window) (notmuch-tree (string-replace jao-notmuch--newa "" query))))) +(defun jao-notmuch--widen (s &optional extra) + (let* ((q (plist-get s :query)) + (qs (string-replace jao-notmuch--newa "" q))) + (plist-put (copy-sequence s) :query (concat qs extra)))) + (defun jao-notmuch-widen-searches (searches &optional extra) - (mapcar (lambda (s) - (let* ((q (plist-get s :query)) - (qs (string-replace jao-notmuch--newa "" q))) - (plist-put (copy-sequence s) :query (concat qs extra)))) - searches)) + (mapcar (lambda (s) (jao-notmuch--widen s extra)) searches)) (defun jao-notmuch-hello--insert-searches (searches title) (when-let (searches (notmuch-hello-query-counts searches)) @@ -84,95 +109,105 @@ (widget-insert (propertize title 'face 'jao-themes-f00)) (notmuch-hello-insert-buttons searches)))) -(defmacro jao-notmuch-def-searches (name searches) +(defun jao-notmuch--replace (lst s) + (let ((name (plist-get s :name))) + (set lst (seq-remove (lambda (s0) (string= name (plist-get s0 :name))) + (symbol-value lst))) + (add-to-list lst s t))) + +(defun jao-notmuch--def-searches (name searches &optional no-save) (declare (indent 1)) - (let ((name (and name (format "%s" name))) - (id (intern (format "jao-notmuch-%s-searches" (or name (gensym)))))) - `(progn (defvar ,id ,searches) - (defun ,id () (jao-notmuch-hello--insert-searches ,id ,name)) - (setq notmuch-saved-searches (append notmuch-saved-searches ,id)) - (add-to-list 'notmuch-hello-sections ',id t)))) - -(setq notmuch-hello-sections nil notmuch-saved-searches nil) - -(jao-notmuch-def-searches bigml - `(,(jao-notmuch--q "bigml" "inbox" "bi") - ,(jao-notmuch--q "bigml" "alba" "ba") - ,(jao-notmuch--q "bigml" "support" "bs") - ,(jao-notmuch--q "bigml" "bugs" "bb") - ,(jao-notmuch--q "bigml" "drivel" "bd") - ,(jao-notmuch--q "bigml" "lists" "bl"))) - -(jao-notmuch-def-searches inbox - `(,(jao-notmuch--q "jao" "inbox" "ji") - ,(jao-notmuch--qn "jao" "bills" "jb" '("tag:bills")) - ,(jao-notmuch--qn "jao" "write" "jw" '("tag:write")) - ,(jao-notmuch--q "jao" "drivel" "jd") - ,(jao-notmuch--q "jao" "mdk" "jm") - ,(jao-notmuch--qn "jao" "hacking" "jh" '("tag:hacking" "not tag:\"/emacs/\"")) - ,(jao-notmuch--qn "jao" "local" "jl" '("tag:local")))) - -(jao-notmuch-def-searches news - (mapcar #'jao-notmuch--sq '("news" "noticias" "fun" "words" "computers"))) - -(jao-notmuch-def-searches hacking - (mapcar #'jao-notmuch--sq '("xmobar" "geiser" "mdk" "mailutils" "notmuch"))) - -(jao-notmuch-def-searches prog - (append (mapcar #'jao-notmuch--sq - '( "lobsters" "clojure" "lisp" "scheme" - "haskell" "idris" "erlang" "pharo")) - `(,(jao-notmuch--qn "feeds" "prog" "fp" - '("tag:prog" "not tag:\"/emacs/\""))))) - -(jao-notmuch-def-searches emacs - `(,(jao-notmuch--sq "emacs" "ee" "emacs" "feeds") - ,(jao-notmuch--sq "emacs-help" "eh" "emacs" "help") - ,(jao-notmuch--sq "emacs-github" "eg" "emacs" "github") - ,(jao-notmuch--sq "emacs-devel" "ed" "emacs" "devel") - ,(jao-notmuch--sq "emacs-bugs" "eb" "emacs" "bugs") - ,(jao-notmuch--sq "emacs-diffs" "ec" "emacs" "diffs"))) - -(jao-notmuch-def-searches sci - (mapcar #'jao-notmuch--sq - '("philosophy" "math" "physics" "sci" "gr-qc" "quant-ph"))) - -(jao-notmuch-def-searches flags - (jao-notmuch-widen-searches notmuch-saved-searches " AND tag:flagged")) - -(jao-notmuch-def-searches nil - `(,(jao-notmuch--q "bml" "flagged" "rb" '("tag:flagged" "tag:bigml")) - ,(jao-notmuch--q "jao" "flagged" "rj" '("tag:flagged" "tag:jao")) - ,(jao-notmuch--q "feeds" "flagged" "rf" '("tag:flagged" "tag:feeds")))) - -(jao-notmuch-def-searches today - `(,(jao-notmuch--q "new" nil "nn" '("tag:new" "not tag:draft")) - ,(jao-notmuch--q "jao" "drafts" "d" '("tag:draft")) - ,(jao-notmuch--q "bml" "sent" "ts" - '("tag:bigml" "date:1d.." "tag:sent")) - ,(jao-notmuch--q "jao" "sent" "tS" - '("tag:\"/jao|hacking/\"" "date:1d.." "tag:sent")) - ,(jao-notmuch--q "bml" "today" "tb" - '("not tag:sent" "tag:bigml" "date:24h..")) - ,(jao-notmuch--q "jao" "today" "tj" - '("tag:jao" "date:24h.." - "not tag:\"/(sent|feeds|spam|local)/\"")))) - -(jao-notmuch-def-searches trove - (mapcar (lambda (m) (list :query (concat "tag:trove and tag:" m) - :name (concat "trove/" m) - :key (concat "t" (substring m 0 1)) - :search-type 'tree)) - '("jao" "hacking" "feeds" "bills"))) - -(jao-notmuch-def-searches nil - '((:query "not tag:trove and not tag:bigml" :name "jao/untroved" :search-type tree) - (:query "tag:sent and tag:bigml" :name "bigml/sent" :search-type tree) - (:query "tag:sent and not tag:bigml" :name "jao/sent" :search-type tree) - (:query "*" :name "messages" :search-type tree))) - -(defvar jao-notmuch-widened-searches - (jao-notmuch-widen-searches notmuch-saved-searches)) + (unless no-save + (dolist (s searches) + (jao-notmuch--replace 'jao-notmuch-widened-searches + (jao-notmuch--widen s)) + (jao-notmuch--replace 'notmuch-saved-searches s))) + (add-to-list 'notmuch-hello-sections + `(jao-notmuch-hello--insert-searches ,searches ,name) + t)) + +(defvar jao-notmuch-widened-searches nil) + +(defun jao-notmuch-define-searches (s &optional other) + (jao-notmuch--set-new-search s) + + (setq notmuch-hello-sections nil + notmuch-saved-searches nil + jao-notmuch-widened-searches nil) + + (when other (jao-notmuch--def-searches (car other) (cdr other))) + + (jao-notmuch--def-searches "inbox" + `(,(jao-notmuch--q "inbox" "i") + ,(jao-notmuch--q "write" "w") + ,(jao-notmuch--q "drivel" "d") + ,(jao-notmuch--q "trove" "t") + ,(jao-notmuch--q "local" "x"))) + + (jao-notmuch--def-searches "news" + (mapcar 'jao-notmuch--q-feed + '(("fn" "news") + ("fd" "noticias") + ("ff" "fun") + ("fw" "words") + ("fc" "computers") + ("fp" "pens")))) + + (jao-notmuch--def-searches "hacking" + `(,(jao-notmuch--q "hacking" "h") + ,(jao-notmuch--q "prog" "p") + ,@(mapcar 'jao-notmuch--q-feed + '(("lc" "clojure") + ("le" "emacs") + ("lg" "geiser") + ("lh" "haskell") + ("ll" "lisp") + ("ln" "notmuch") + ("lr" "rust") + ("ls" "scheme") + ("lx" "xmobar"))))) + + (jao-notmuch--def-searches "sci" + (mapcar 'jao-notmuch--q-feed + '(("sp" "philosophy") + ("sm" "math") + ("sp" "physics") + ("ss" "sci") + ("sg" "gr-qc") + ("sq" "quant-ph")))) + + (jao-notmuch--def-searches "flags" + (jao-notmuch-widen-searches notmuch-saved-searches " AND tag:flagged") + t) + + (jao-notmuch--def-searches nil + `(,(jao-notmuch--q "flagged" "F" nil '("tag:flagged")))) + + (jao-notmuch--def-searches "today" + `(,(jao-notmuch--q "new" "N" nil (list jao-notmuch--new "not tag:draft")) + ,(jao-notmuch--q "drafts" "D" nil '("tag:draft") t) + ,(jao-notmuch--q "sent" "S" nil '("date:1d.." "tag:sent") t) + ,(jao-notmuch--q "today" "T" nil + '("tag:jao" "date:24h.." + "not tag:\"/(sent|feeds|spam|local)/\"") + t))) + + (jao-notmuch--def-searches "trove" + '((:query "tag:trove" :name "trove" :search-type tree) + (:query "tag:hacking" :name "hacking" :search-type tree) + (:query "not tag:trove and not tag:hacking" :name "untroved" + :search-type tree) + (:query "tag:sent" :name "sent"))) + + (jao-notmuch--def-searches nil + '((:query "*" :name "messages" :search-type tree))) + + ;; (add-to-list 'notmuch-hello-sections 'notmuch-hello-insert-alltags t) + + (when (display-graphic-p) + (add-to-list 'notmuch-hello-sections '(insert " ")))) + +(jao-notmuch-define-searches "tag:\"/^(unread|new)$/\"") (defun jao-notmuch-jump-search (&optional widen) (interactive "P") @@ -180,34 +215,59 @@ (if widen jao-notmuch-widened-searches notmuch-saved-searches))) (notmuch-jump-search))) +(defun jao-notmuch--searches-w/new (searches) + (seq-filter (lambda (s) + (string-match-p jao-notmuch--new-rx (plist-get s :query))) + (notmuch-hello-query-counts searches))) + +(defconst jao-notmuch--search-keys '("a" "s" "d" "f" "g" "h" "j" "k" "l")) + +(defun jao-notmuch--index-searches (searches) + (seq-map-indexed (lambda (q i) + (plist-put q :key (or (elt jao-notmuch--search-keys i) + (format "%s" i)))) + searches)) + +(defun jao-notmuch-jump () + "Jump to a saved, non-zero count search." + (interactive) + (if-let* ((searches (jao-notmuch--searches-w/new notmuch-saved-searches))) + (if (= 2 (length searches)) + (let* ((q (seq-remove (lambda (q) (string= "new" (plist-get q :name))) + searches)) + (q (car q)) + (of (eq 'oldest-first (plist-get q :sort-order))) + (query (plist-get q :query))) + (notmuch-tree query nil nil nil nil nil nil of t)) + (let ((notmuch-saved-searches (jao-notmuch--index-searches searches))) + (notmuch-jump-search))) + (jao-notmuch-jump-search t))) + ;;; tags (defvar jao-notmuch--shared-tags '("new" "unread" "flagged" "signed" "sent" "attachment" "forwarded" "inbox" "encrypted" "gmane" "gnus" "feeds" "rss" "mce" "trove" "prog" "emacs")) -(defun jao-notmuch--subtags (tag &rest excl) - (let* ((cmd (concat "notmuch search --output=tags tag:" tag)) - (ts (split-string (shell-command-to-string cmd)))) - (seq-difference ts (append jao-notmuch--shared-tags (cons tag excl))))) - -(setq notmuch-archive-tags '("+trove" "-new" "-drivel" "-words" "-inbox") +(setq notmuch-archive-tags + '("+trove" "-hacking" "-new" "-drivel" "-words" "-inbox") notmuch-show-mark-read-tags '("-new" "-unread") notmuch-tag-formats (let (;; (d `(:foreground ,(face-attribute 'jao-themes-dimm :foreground))) (e `(:foreground ,(face-attribute 'jao-themes-error :foreground)))) - `(("unread") - ("signed") - ("new" "ยท") - ("replied" "โฉ" (propertize tag 'face '(:family "Fira Code"))) - ("sent" "๐ช") - ("attachment" "๐") - ("deleted" "๐" (propertize tag 'face '(:underline nil ,@e))) - ("flagged" "โ") - ("jao" "j") + `(("attachment" "โงบ") ("bigml" "b") + ("deleted" "โ" (propertize tag 'face '(:underline nil ,@e))) ("feeds" "f") + ("flagged" "โ") + ("forwarded" "โ") + ("gmane" "g") + ("jao" "j") ("lists" "l") - ("gmane" "g"))) + ("new" "ยท") + ("replied" "โฉ" (propertize tag 'face '(:family "Fira Code"))) + ("sent" "โ") + ("signed") + ("unread"))) notmuch-tag-deleted-formats '(("unread") ("new") @@ -230,11 +290,7 @@ notmuch-always-prompt-for-sender t notmuch-draft-folder "drafts" notmuch-draft-quoted-tags '("part") - notmuch-fcc-dirs - '(("\\(support\\|education\\)@bigml.com" . nil) - ("mail@jao.io" . nil) - (".*@bigml.com" . "bigml -new -unread +sent +bigml") - (".*" . "jao -new -unread +sent +jao")) + notmuch-fcc-dirs '((".*" . "sent -new -unread +sent +jao")) notmuch-maildir-use-notmuch-insert t) :custom ((notmuch-address-internal-completion '(sent nil))) @@ -245,7 +301,7 @@ (when jao-notmuch-enabled (define-key message-mode-map (kbd "C-c C-d") #'notmuch-draft-postpone) - (setq message-directory "~/var/mail/" + (setq message-directory (file-name-as-directory jao-maildir) message-auto-save-directory "/tmp" mail-user-agent 'message-user-agent)) @@ -257,12 +313,6 @@ (use-package jao-notmuch :demand t) ;;; hello -(defun jao-notmuch-hello--header () (insert " ")) -(when (display-graphic-p) - (add-to-list 'notmuch-hello-sections 'jao-notmuch-hello--header)) - -(add-to-list 'notmuch-hello-sections 'notmuch-hello-insert-alltags t) - (defun jao-notmuch-refresh-agenda () (interactive) (save-window-excursion (calendar) (jao-org-agenda))) @@ -328,8 +378,10 @@ (when jao-notmuch-enabled (add-hook 'jao-afio-switch-hook #'jao-notmuch-refresh-hello)) - :bind (:map notmuch-hello-mode-map + :bind (("s-j" . jao-notmuch-jump) + :map notmuch-hello-mode-map (("a" . jao-notmuch-refresh-agenda) + ("A" . jao-afio-open-mail) ("g" . jao-notmuch-refresh-hello) ("j" . jao-notmuch-jump-search) ("n" . jao-notmuch-hello-next) @@ -357,16 +409,25 @@ (error "Found an enclosure, but not a link!"))))) (defconst jao-mail-clean-rx - (regexp-opt '("ElDiario.es - ElDiario.es: " "The Guardian: " + (regexp-opt '("ElDiario.es - ElDiario.es: " + "The Guardian: " "The Conversation โ Articles (UK): " "gr-qc updates on arXiv.org: " - "quant-ph updates on arXiv.org: "))) + "quant-ph updates on arXiv.org: " + " via The Rust Programming Language Forum"))) (defun jao-mail-clean-address (args) (when-let ((address (car args))) (list (thread-last (replace-regexp-in-string jao-mail-clean-rx "" address) (replace-regexp-in-string " " ", "))))) +(defun jao-notmuch-open-in-mac-mail () + (interactive) + (jao-d-l + (when-let* ((id (ignore-errors (notmuch-show-get-message-id)))) + (jao-mac-open "message://%%3C%s%%3E" (substring id 3))) + (message "Only available in macs!"))) + (use-package notmuch-show :init (setq gnus-blocked-images "." @@ -389,12 +450,13 @@ :bind (:map notmuch-show-mode-map - (("h" . jao-notmuch-goto-tree-buffer) - ("r" . notmuch-show-reply) - ("R" . notmuch-show-reply-sender) - ("TAB" . jao-notmuch-show-next-button) - ([backtab] . jao-notmuch-show-previous-button) - ("RET" . jao-notmuch-show-ret)))) + (("h" . jao-notmuch-goto-tree-buffer) + ("r" . notmuch-show-reply) + ("R" . notmuch-show-reply-sender) + ("TAB" . jao-notmuch-show-next-button) + ([backtab] . jao-notmuch-show-previous-button) + ("RET" . jao-notmuch-show-ret) + ("M" . jao-notmuch-open-in-mac-mail)))) ;;; search (use-package notmuch-search @@ -424,16 +486,25 @@ (defun jao-notmuch--via-url () (when (window-live-p notmuch-tree-message-window) (with-selected-window notmuch-tree-message-window - (goto-char (point-min)) - (when (re-search-forward "^Via: http" nil t) - (thing-at-point-url-at-point))))) + (jao-url-email-url)))) (defun jao-notmuch-browse-url (ext) (interactive "P") - (when-let (url (or (jao-notmuch--via-url) - (car (last (jao-notmuch-message-urls))))) - (funcall (if ext browse-url-secondary-browser-function #'browse-url) - url))) + (when-let* ((url (or (jao-notmuch--via-url) + (car (last (jao-notmuch-message-urls)))))) + (if ext + (funcall browse-url-secondary-browser-function url) + (window-configuration-to-register ?G) + (select-window notmuch-tree-message-window)t + (eww url)))) + +(defun jao-notmuch-from-eww (keep-eww-buffer) + (interactive "P") + (unless keep-eww-buffer (jao-eww-close)) + (jump-to-register ?G)) + +(with-eval-after-load 'eww + (define-key eww-mode-map (kbd "h") #'jao-notmuch-from-eww)) (defun jao-notmuch-adjust-tree-fonts (&optional family) (let ((fg (face-attribute 'jao-themes-dimm :foreground))) @@ -478,17 +549,24 @@ (when (string-prefix-p "Hack" jao-themes-default-face) "Source Code Pro"))) (defun jao-notmuch-before-tree (&rest _args) + (window-configuration-to-register ?G) (when (string= (buffer-name) "*notmuch-hello*") - (window-configuration-to-register ?G) + (when (< (frame-width) 230) (delete-other-windows)) (split-window-right 40) (other-window 1))) - (defvar jao-notmuch--visits 0) - (defun jao-notmuch-after-tree-quit (&optional _both) (when (not (derived-mode-p 'notmuch-tree-mode 'notmuch-hello-mode)) - (jump-to-register ?G)) - (jao-notmuch-refresh-hello (= 0 (mod (cl-incf jao-notmuch--visits) 50)))) + (jump-to-register ?G) + (when (not (derived-mode-p 'notmuch-hello-mode)) + (jao-notmuch-notify-and-update)))) + + (defvar jao-notmuch--visits 0) + + (defun jao-notmuch--maybe-notify-and-update (&optional _both) + (when (not (derived-mode-p 'notmuch-hello-mode 'notmuch-tree-mode)) + (jao-notmuch-notify-and-update)) + (jao-notmuch-refresh-hello)) (defun jao-notmuch-tree--sentinel (proc) (when (eq (process-status proc) 'exit) @@ -500,9 +578,21 @@ (jao-notmuch-thread-info-mode))) (add-hook 'notmuch-tree-process-exit-functions #'jao-notmuch-tree--sentinel) + (advice-add 'notmuch-tree-quit :after #'jao-notmuch--maybe-notify-and-update) + + (defun jao-notmuch-use-two-panes () + (interactive) + (advice-add 'notmuch-tree :before #'jao-notmuch-before-tree) + (advice-add 'notmuch-tree-quit :after #'jao-notmuch-after-tree-quit)) - (advice-add 'notmuch-tree :before #'jao-notmuch-before-tree) - (advice-add 'notmuch-tree-quit :after #'jao-notmuch-after-tree-quit) + (defun jao-notmuch-use-one-pane () + (interactive) + (jao-afio-add-frame-parameters mail (width . 120)) + (advice-remove 'notmuch-tree #'jao-notmuch-before-tree) + (advice-remove 'notmuch-tree-quit #'jao-notmuch-after-tree-quit)) + + (when jao-notmuch-enabled + (jao-d-l (jao-notmuch-use-one-pane) (jao-notmuch-use-two-panes))) :bind (:map notmuch-tree-mode-map (("b" . jao-notmuch-browse-urls) @@ -511,7 +601,9 @@ ("h" . jao-notmuch-goto-message-buffer) ("i" . jao-notmuch-toggle-images) ("k" . jao-notmuch-tree-read-thread) + ("K" . jao-notmuch-tree-mark-all-read) ("N" . jao-notmuch-tree--forward) + ("M" . jao-notmuch-open-in-mac-mail) ("O" . notmuch-tree-toggle-order) ("o" . jao-notmuch-tree-widen-search) ("P" . jao-notmuch-tree--backward) @@ -610,49 +702,56 @@ (org-capture nil "X")))) ;;; html renderer -(when jao-notmuch-enabled (setq mm-text-html-renderer 'shr)) - -;;; consult -(jao-load-path "consult-notmuch") -(require 'consult-notmuch) -(setq consult-notmuch-newest-first t) -(consult-customize consult-notmuch :preview-key 'any) -(defvar jao-consult-notmuch-history nil) +;; we can use the default defined in jao-custom-ewww +;; (when jao-notmuch-enabled (setq mm-text-html-renderer 'shr)) -(defvar jao-mailbox-folders '("bigml" "jao")) +;;; consult +(jao-when-linux + (jao-load-path "consult-notmuch") + (require 'consult-notmuch) + (setq consult-notmuch-newest-first t) + (consult-customize consult-notmuch :preview-key 'any) + + (defvar jao-consult-notmuch-history nil) + + (defvar jao-mailbox-folders '("bigml" "jao")) + + (defun jao-consult-notmuch-folder (&optional tree folder) + (interactive "P") + (let* ((folder (if folder + (file-name-as-directory folder) + (completing-read "Group: " + jao-mailbox-folders + nil nil nil + jao-consult-notmuch-history + "."))) + (folder (replace-regexp-in-string "/\\(.\\)" ".\\1" folder)) + (init (read-string "Initial query: ")) + (init (format "folder:/%s/ %s" folder init))) + (if tree (consult-notmuch-tree init) (consult-notmuch init)))) + + (with-eval-after-load "notmuch-hello" + (define-key notmuch-hello-mode-map "f" #'jao-consult-notmuch-folder))) +;;; org +(when jao-notmuch-enabled (jao-notmuch-org-links)) -(defun jao-consult-notmuch-folder (&optional tree folder) - (interactive "P") - (let* ((folder (if folder - (file-name-as-directory folder) - (completing-read "Group: " - jao-mailbox-folders - nil nil nil - jao-consult-notmuch-history - "."))) - (folder (replace-regexp-in-string "/\\(.\\)" ".\\1" folder)) - (init (read-string "Initial query: ")) - (init (format "folder:/%s/ %s" folder init))) - (if tree (consult-notmuch-tree init) (consult-notmuch init)))) - -(with-eval-after-load "notmuch-hello" - (define-key notmuch-hello-mode-map "f" #'jao-consult-notmuch-folder)) ;;; recoll -(defun jao-notmuch-open-file (fname &optional _page) - (with-temp-buffer - (insert-file-contents-literally fname) - (goto-char (point-min)) - (and (re-search-forward "^Message-ID: <\\([^>]+\\)>$" nil t) - (notmuch-show (concat "id:" (match-string 1)))))) - -(when jao-notmuch-enabled - (with-eval-after-load "org" - (org-link-set-parameters "message" :follow #'jao-notmuch-open-file)) - - (with-eval-after-load "consult-recoll" - (add-to-list 'consult-recoll-open-fns - '("message/rfc822" . jao-notmuch-open-file)))) +(jao-when-linux + (defun jao-notmuch-open-file (fname &optional _page) + (with-temp-buffer + (insert-file-contents-literally fname) + (goto-char (point-min)) + (and (re-search-forward "^Message-ID: <\\([^>]+\\)>$" nil t) + (notmuch-show (concat "id:" (match-string 1)))))) + + (when jao-notmuch-enabled + (with-eval-after-load "org" + (org-link-set-parameters "message" :follow #'jao-notmuch-open-file)) + + (with-eval-after-load "consult-recoll" + (add-to-list 'consult-recoll-open-fns + '("message/rfc822" . jao-notmuch-open-file))))) ;;; . (provide 'jao-custom-notmuch) |
