From 07d219a3003e4e1de7716e04b85a88a730b909ee Mon Sep 17 00:00:00 2001 From: Max Nickel Date: Wed, 23 Oct 2019 22:58:06 -0400 Subject: [PATCH 1/9] add support for deleting messages in notmuch-show --- modules/email/notmuch/autoload.el | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/modules/email/notmuch/autoload.el b/modules/email/notmuch/autoload.el index ab7ae5610..5a4917c6f 100644 --- a/modules/email/notmuch/autoload.el +++ b/modules/email/notmuch/autoload.el @@ -56,6 +56,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) From 5324cb2fc8a2f55f302310b2fce504995c018d05 Mon Sep 17 00:00:00 2001 From: Max Nickel Date: Wed, 23 Oct 2019 22:58:51 -0400 Subject: [PATCH 2/9] only show unread messages in notmuch-show threads (fold read msgs) --- modules/email/notmuch/autoload.el | 19 +++++++++++++++++++ modules/email/notmuch/config.el | 3 +++ 2 files changed, 22 insertions(+) diff --git a/modules/email/notmuch/autoload.el b/modules/email/notmuch/autoload.el index 5a4917c6f..174df2dc4 100644 --- a/modules/email/notmuch/autoload.el +++ b/modules/email/notmuch/autoload.el @@ -92,6 +92,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-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/expand-only-unread-hook 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..95a7e2400 100644 --- a/modules/email/notmuch/config.el +++ b/modules/email/notmuch/config.el @@ -42,6 +42,9 @@ ;; (setq-hook! 'notmuch-show-mode-hook line-spacing 0) + ;; only unfold unread messages in thread by default + (add-hook 'notmuch-show-hook '+notmuch-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) From d73ebf0815d08287d351a3f7464a631a05461c79 Mon Sep 17 00:00:00 2001 From: Max Nickel Date: Wed, 23 Oct 2019 23:24:56 -0400 Subject: [PATCH 3/9] refresh notmuch buffers after sync and add support for custom sync --- modules/email/notmuch/autoload.el | 33 ++++++++++++++++++++----------- modules/email/notmuch/config.el | 3 +++ 2 files changed, 25 insertions(+), 11 deletions(-) diff --git a/modules/email/notmuch/autoload.el b/modules/email/notmuch/autoload.el index 174df2dc4..25a3f1e3b 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 () diff --git a/modules/email/notmuch/config.el b/modules/email/notmuch/config.el index 95a7e2400..6f200dbd3 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).") From 00ec885eaaead670037a51756fe75b51b11eb502 Mon Sep 17 00:00:00 2001 From: Max Nickel Date: Wed, 23 Oct 2019 23:25:32 -0400 Subject: [PATCH 4/9] add command to select From email via ivy prior to composing --- modules/email/notmuch/autoload.el | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/modules/email/notmuch/autoload.el b/modules/email/notmuch/autoload.el index 25a3f1e3b..6c273e526 100644 --- a/modules/email/notmuch/autoload.el +++ b/modules/email/notmuch/autoload.el @@ -86,6 +86,14 @@ (notmuch-tree-add-tag (list "+spam" "-inbox" "-unread")) (notmuch-tree-next-message)) +;;;###autoload +(defun +notmuch/ivy-compose () + "Compose new mail" + (interactive) + (ivy-read "From: " + (notmuch-user-emails) + :action (lambda (selection) (notmuch-mua-mail nil nil (list (cons 'From selection)))))) + ;;;###autoload (defun +notmuch/open-message-with-mail-app-notmuch-tree () (interactive) From 5b3989f3e17e20c6ee148077dd6fb3ed53ff9efc Mon Sep 17 00:00:00 2001 From: Max Nickel Date: Thu, 24 Oct 2019 18:33:38 -0400 Subject: [PATCH 5/9] fix removal of unread hook when filtering messages --- modules/email/notmuch/autoload.el | 4 ++-- modules/email/notmuch/config.el | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/email/notmuch/autoload.el b/modules/email/notmuch/autoload.el index 6c273e526..12203587f 100644 --- a/modules/email/notmuch/autoload.el +++ b/modules/email/notmuch/autoload.el @@ -119,7 +119,7 @@ (notmuch-show-refresh-view t)) ;;;###autoload -(defun +notmuch-expand-only-unread-h () +(defun +notmuch-show-expand-only-unread-h () (interactive) (let ((unread nil) (open (notmuch-show-get-message-ids-for-open-messages))) @@ -127,7 +127,7 @@ (when (member "unread" (notmuch-show-get-tags)) (setq unread t)))) (when unread - (let ((notmuch-show-hook (remove '+notmuch/expand-only-unread-hook notmuch-show-hook))) + (let ((notmuch-show-hook (remove '+notmuch-show-expand-only-unread-h notmuch-show-hook))) (notmuch-show-filter-thread "tag:unread"))))) ;; diff --git a/modules/email/notmuch/config.el b/modules/email/notmuch/config.el index 6f200dbd3..75b660351 100644 --- a/modules/email/notmuch/config.el +++ b/modules/email/notmuch/config.el @@ -46,7 +46,7 @@ ;; (setq-hook! 'notmuch-show-mode-hook line-spacing 0) ;; only unfold unread messages in thread by default - (add-hook 'notmuch-show-hook '+notmuch-expand-only-unread-h) + (add-hook 'notmuch-show-hook '+notmuch-show-expand-only-unread-h) (add-hook 'doom-real-buffer-functions #'notmuch-interesting-buffer) From e279409bbd53ad887d272d38c742c97e83500c39 Mon Sep 17 00:00:00 2001 From: Max Nickel Date: Sat, 26 Oct 2019 13:38:06 -0400 Subject: [PATCH 6/9] sharp-quote notmuch-show hook --- modules/email/notmuch/config.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/email/notmuch/config.el b/modules/email/notmuch/config.el index 75b660351..4a6536359 100644 --- a/modules/email/notmuch/config.el +++ b/modules/email/notmuch/config.el @@ -46,7 +46,7 @@ ;; (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 'notmuch-show-hook #'+notmuch-show-expand-only-unread-h) (add-hook 'doom-real-buffer-functions #'notmuch-interesting-buffer) From a4050a153d8f39e6043d5af0a8ee45464e6cb2b0 Mon Sep 17 00:00:00 2001 From: Max Nickel Date: Sat, 26 Oct 2019 14:02:56 -0400 Subject: [PATCH 7/9] generalize notmuch/ivy-compose to notmuch/compose (completing-read) --- modules/email/notmuch/autoload.el | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/modules/email/notmuch/autoload.el b/modules/email/notmuch/autoload.el index 12203587f..211e45957 100644 --- a/modules/email/notmuch/autoload.el +++ b/modules/email/notmuch/autoload.el @@ -87,12 +87,13 @@ (notmuch-tree-next-message)) ;;;###autoload -(defun +notmuch/ivy-compose () +(defun +notmuch/compose () "Compose new mail" (interactive) - (ivy-read "From: " - (notmuch-user-emails) - :action (lambda (selection) (notmuch-mua-mail nil nil (list (cons 'From selection)))))) + (notmuch-mua-mail + nil + nil + (list (cons 'From (completing-read "From: " (notmuch-user-emails)))))) ;;;###autoload (defun +notmuch/open-message-with-mail-app-notmuch-tree () From e122c557187991309eae129884e3d0b663b8c836 Mon Sep 17 00:00:00 2001 From: Max Nickel Date: Sat, 26 Oct 2019 14:05:40 -0400 Subject: [PATCH 8/9] add basic bindings for notmuch --- modules/email/notmuch/config.el | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/modules/email/notmuch/config.el b/modules/email/notmuch/config.el index 4a6536359..1c5c1416c 100644 --- a/modules/email/notmuch/config.el +++ b/modules/email/notmuch/config.el @@ -56,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" "d" #'+notmuch/search-spam + :map notmuch-tree-mode-map + :desc "mark as deleted" "d" #'+notmuch/tree-delete + :desc "mark as spam" "d" #'+notmuch/tree-spam)) (use-package! org-mime @@ -73,4 +86,3 @@ :when (featurep! :completion helm) :commands helm-notmuch :after notmuch) - From 3a20e09eab8dc0958951a324431e8a1a3b24737b Mon Sep 17 00:00:00 2001 From: Max Nickel Date: Sat, 26 Oct 2019 15:42:25 -0400 Subject: [PATCH 9/9] fix notmuch keybind typo --- modules/email/notmuch/config.el | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/email/notmuch/config.el b/modules/email/notmuch/config.el index 1c5c1416c..1bf57da94 100644 --- a/modules/email/notmuch/config.el +++ b/modules/email/notmuch/config.el @@ -66,10 +66,10 @@ :desc "quit notmuch" "q" #'+notmuch/quit :map notmuch-search-mode-map :desc "mark as deleted" "d" #'+notmuch/search-delete - :desc "mark as spam" "d" #'+notmuch/search-spam + :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" "d" #'+notmuch/tree-spam)) + :desc "mark as spam" "s" #'+notmuch/tree-spam)) (use-package! org-mime