From 96084932aa3a9216f3a89003b466106e36f04dd3 Mon Sep 17 00:00:00 2001 From: Pierre Neidhardt Date: Fri, 3 Apr 2020 11:12:18 +0200 Subject: [PATCH] notmuch: Poll new mails asynchronously and fix GPG decrypt issue. --- .emacs.d/lisp/init-notmuch.el | 36 +++++++++++++++++++++++++++-------- 1 file changed, 28 insertions(+), 8 deletions(-) diff --git a/.emacs.d/lisp/init-notmuch.el b/.emacs.d/lisp/init-notmuch.el index b06651c7..cde5d76e 100644 --- a/.emacs.d/lisp/init-notmuch.el +++ b/.emacs.d/lisp/init-notmuch.el @@ -84,19 +84,39 @@ " "))) (notmuch-search (format "%s %s" address merged-addresses))))) -;; (advice-add 'debbugs-gnu-select-report :override #'debbugs-notmuch-select-report) +(defun ambrevar/notmuch-poll-async () + "Like `notmuch-poll' but asynchronous." + (notmuch-start-notmuch + "notmuch-new" + nil + (lambda (_proc change) + (with-current-buffer (find-if (lambda (b) + (with-current-buffer b + (eq major-mode 'notmuch-search-mode))) + (buffer-list)) + (notmuch-refresh-this-buffer)) + (message "notmuch-new: %s" change)) + "new")) -;; TODO: This is a bit brittle since it only works if ~/.authinfo.gpg exists. +;; TODO: This is a bit brittle since it only works if the given gpg file exists. ;; Is there a way to unlock gpg manually without a file? -(defun ambrevar/gpg-unlock () - "Unlock GPG." +(defun ambrevar/notmuch-poll-after-gpg-unlock () + "Unlock GPG and get Notmuch mail." + ;; The gpg unlock needs to be asynchronous for EXWM, or else pinentry-emacs + ;; will be blocked. (let ((sentinel (lambda (_process _args) - (notmuch-poll) - (notmuch-refresh-this-buffer)))) + (ambrevar/notmuch-poll-async)))) (make-process :name "gpg" :buffer nil - :command (list "gpg" "--decrypt" (expand-file-name "~/.authinfo.gpg")) + :command (list "gpg" "--decrypt" + (expand-file-name + (or (find-if (lambda (agenda) (string-suffix-p ".gpg" agenda)) + org-agenda-files) + (error "No .gpg file in `org-agenda-files'.")))) :sentinel sentinel))) -(advice-add 'notmuch-poll-and-refresh-this-buffer :override #'ambrevar/gpg-unlock) +(advice-add 'notmuch-poll-and-refresh-this-buffer + :override #'ambrevar/notmuch-poll-after-gpg-unlock) + +;; (advice-add 'debbugs-gnu-select-report :override #'debbugs-notmuch-select-report) (provide 'init-notmuch)