diff --git a/modules/email/notmuch/autoload.el b/modules/email/notmuch/autoload.el index ab7ae5610..211e45957 100644 --- a/modules/email/notmuch/autoload.el +++ b/modules/email/notmuch/autoload.el @@ -32,17 +32,28 @@ ;;;###autoload (defun +notmuch/update () (interactive) - (start-process-shell-command - "notmuch update" nil - (pcase +notmuch-sync-backend - (`gmi - (concat "cd " +notmuch-mail-folder " && gmi push && gmi pull && notmuch new && afew -a -t")) - (`mbsync - "mbsync -a && notmuch new && afew -a -t") - (`mbsync-xdg - "mbsync -c \"$XDG_CONFIG_HOME\"/isync/mbsyncrc -a && notmuch new && afew -a -t") - (`offlineimap - "offlineimap && notmuch new && afew -a -t")))) + ;; create output buffer and jump to beginning + (let ((buf (get-buffer-create "*notmuch update*"))) + (with-current-buffer buf + (erase-buffer)) + (pop-to-buffer buf nil t) + (set-process-sentinel + (start-process-shell-command + "notmuch update" buf + (pcase +notmuch-sync-backend + (`gmi + (concat "cd " +notmuch-mail-folder " && gmi push && gmi pull && notmuch new && afew -a -t")) + (`mbsync + "mbsync -a && notmuch new && afew -a -t") + (`mbsync-xdg + "mbsync -c \"$XDG_CONFIG_HOME\"/isync/mbsyncrc -a && notmuch new && afew -a -t") + (`offlineimap + "offlineimap && notmuch new && afew -a -t") + (`custom +notmuch-sync-command))) + ;; refresh notmuch buffers if sync was successful + (lambda (_process event) + (if (string= event "finished\n") + (notmuch-refresh-all-buffers)))))) ;;;###autoload (defun +notmuch/search-delete () @@ -56,6 +67,13 @@ (notmuch-tree-add-tag (list "+trash" "-inbox" "-unread")) (notmuch-tree-next-message)) +;;;###autoload +(defun +notmuch/show-delete () + "Mark email for deletion in notmuch-show" + (interactive) + (notmuch-show-add-tag (list "+trash" "-inbox" "-unread")) + (notmuch-show-next-thread-show)) + ;;;###autoload (defun +notmuch/search-spam () (interactive) @@ -68,6 +86,15 @@ (notmuch-tree-add-tag (list "+spam" "-inbox" "-unread")) (notmuch-tree-next-message)) +;;;###autoload +(defun +notmuch/compose () + "Compose new mail" + (interactive) + (notmuch-mua-mail + nil + nil + (list (cons 'From (completing-read "From: " (notmuch-user-emails)))))) + ;;;###autoload (defun +notmuch/open-message-with-mail-app-notmuch-tree () (interactive) @@ -85,6 +112,25 @@ (start-process-shell-command "email" nil (format "xdg-open '%s'" temp)))) +;;;###autoload +(defun +notmuch/show-filter-thread () + "Show the current thread with a different filter" + (interactive) + (setq notmuch-show-query-context (notmuch-read-query "Filter thread: ")) + (notmuch-show-refresh-view t)) + +;;;###autoload +(defun +notmuch-show-expand-only-unread-h () + (interactive) + (let ((unread nil) + (open (notmuch-show-get-message-ids-for-open-messages))) + (notmuch-show-mapc (lambda () + (when (member "unread" (notmuch-show-get-tags)) + (setq unread t)))) + (when unread + (let ((notmuch-show-hook (remove '+notmuch-show-expand-only-unread-h notmuch-show-hook))) + (notmuch-show-filter-thread "tag:unread"))))) + ;; ;; Advice diff --git a/modules/email/notmuch/config.el b/modules/email/notmuch/config.el index 67656bea8..1bf57da94 100644 --- a/modules/email/notmuch/config.el +++ b/modules/email/notmuch/config.el @@ -5,6 +5,9 @@ (defvar +notmuch-sync-backend 'gmi "Which backend to use. Can be either gmi, mbsync, offlineimap or nil (manual).") +(defvar +notmuch-sync-command nil + "Command for custom notmuch sync") + (defvar +notmuch-mail-folder "~/.mail/account.gmail" "Where your email folder is located (for use with gmailieer).") @@ -42,6 +45,9 @@ ;; (setq-hook! 'notmuch-show-mode-hook line-spacing 0) + ;; only unfold unread messages in thread by default + (add-hook 'notmuch-show-hook #'+notmuch-show-expand-only-unread-h) + (add-hook 'doom-real-buffer-functions #'notmuch-interesting-buffer) (advice-add #'notmuch-start-notmuch-sentinel :around #'+notmuch-dont-confirm-on-kill-process-a) @@ -50,7 +56,20 @@ (add-hook! '(notmuch-show-mode-hook notmuch-tree-mode-hook notmuch-search-mode-hook) - #'hide-mode-line-mode)) + #'hide-mode-line-mode) + + (map! + :localleader + :map (notmuch-search-mode-map notmuch-tree-mode-map notmuch-show-mode-map) + :desc "compose email" "c" #'+notmuch/compose + :desc "fetch new email" "u" #'+notmuch/update + :desc "quit notmuch" "q" #'+notmuch/quit + :map notmuch-search-mode-map + :desc "mark as deleted" "d" #'+notmuch/search-delete + :desc "mark as spam" "s" #'+notmuch/search-spam + :map notmuch-tree-mode-map + :desc "mark as deleted" "d" #'+notmuch/tree-delete + :desc "mark as spam" "s" #'+notmuch/tree-spam)) (use-package! org-mime @@ -67,4 +86,3 @@ :when (featurep! :completion helm) :commands helm-notmuch :after notmuch) -