Merge pull request #1950 from mnick/notmuch

email/notmuch: general improvements

- Filter read messages in notmuch show (by folding them automatically)
- Refresh all notmuch buffers after sync (via process sentinel)
- Support custom sync commands (introduces an additional defvar)
- Add command to select From email prior to composing via ivy
This commit is contained in:
Henrik Lissner 2019-10-26 22:42:02 -04:00 committed by GitHub
commit 515fba2fda
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 77 additions and 13 deletions

View file

@ -32,8 +32,14 @@
;;;###autoload ;;;###autoload
(defun +notmuch/update () (defun +notmuch/update ()
(interactive) (interactive)
;; 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 (start-process-shell-command
"notmuch update" nil "notmuch update" buf
(pcase +notmuch-sync-backend (pcase +notmuch-sync-backend
(`gmi (`gmi
(concat "cd " +notmuch-mail-folder " && gmi push && gmi pull && notmuch new && afew -a -t")) (concat "cd " +notmuch-mail-folder " && gmi push && gmi pull && notmuch new && afew -a -t"))
@ -42,7 +48,12 @@
(`mbsync-xdg (`mbsync-xdg
"mbsync -c \"$XDG_CONFIG_HOME\"/isync/mbsyncrc -a && notmuch new && afew -a -t") "mbsync -c \"$XDG_CONFIG_HOME\"/isync/mbsyncrc -a && notmuch new && afew -a -t")
(`offlineimap (`offlineimap
"offlineimap && notmuch new && afew -a -t")))) "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 ;;;###autoload
(defun +notmuch/search-delete () (defun +notmuch/search-delete ()
@ -56,6 +67,13 @@
(notmuch-tree-add-tag (list "+trash" "-inbox" "-unread")) (notmuch-tree-add-tag (list "+trash" "-inbox" "-unread"))
(notmuch-tree-next-message)) (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 ;;;###autoload
(defun +notmuch/search-spam () (defun +notmuch/search-spam ()
(interactive) (interactive)
@ -68,6 +86,15 @@
(notmuch-tree-add-tag (list "+spam" "-inbox" "-unread")) (notmuch-tree-add-tag (list "+spam" "-inbox" "-unread"))
(notmuch-tree-next-message)) (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 ;;;###autoload
(defun +notmuch/open-message-with-mail-app-notmuch-tree () (defun +notmuch/open-message-with-mail-app-notmuch-tree ()
(interactive) (interactive)
@ -85,6 +112,25 @@
(start-process-shell-command "email" nil (format "xdg-open '%s'" temp)))) (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 ;; Advice

View file

@ -5,6 +5,9 @@
(defvar +notmuch-sync-backend 'gmi (defvar +notmuch-sync-backend 'gmi
"Which backend to use. Can be either gmi, mbsync, offlineimap or nil (manual).") "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" (defvar +notmuch-mail-folder "~/.mail/account.gmail"
"Where your email folder is located (for use with gmailieer).") "Where your email folder is located (for use with gmailieer).")
@ -42,6 +45,9 @@
;; (setq-hook! 'notmuch-show-mode-hook line-spacing 0) ;; (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) (add-hook 'doom-real-buffer-functions #'notmuch-interesting-buffer)
(advice-add #'notmuch-start-notmuch-sentinel :around #'+notmuch-dont-confirm-on-kill-process-a) (advice-add #'notmuch-start-notmuch-sentinel :around #'+notmuch-dont-confirm-on-kill-process-a)
@ -50,7 +56,20 @@
(add-hook! '(notmuch-show-mode-hook (add-hook! '(notmuch-show-mode-hook
notmuch-tree-mode-hook notmuch-tree-mode-hook
notmuch-search-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 (use-package! org-mime
@ -67,4 +86,3 @@
:when (featurep! :completion helm) :when (featurep! :completion helm)
:commands helm-notmuch :commands helm-notmuch
:after notmuch) :after notmuch)