From 2f28e506323b55ab39f7bb7321b11a875fdfac6d Mon Sep 17 00:00:00 2001
From: Jon Rubens <jonrubens@jon-mbp.lan>
Date: Sat, 12 Aug 2023 09:56:36 -0700
Subject: [PATCH] async polling

---
 emacs/notmuch-lib.el | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/emacs/notmuch-lib.el b/emacs/notmuch-lib.el
index bf9c4a5..bba3ac9 100644
--- a/emacs/notmuch-lib.el
+++ b/emacs/notmuch-lib.el
@@ -288,19 +288,24 @@ displays both values separately."
 
 ;;; Commands
 
+;;;###autoload
 (defun notmuch-poll ()
   "Run \"notmuch new\" or an external script to import mail.
 
 Invokes `notmuch-poll-script', \"notmuch new\", or does nothing
 depending on the value of `notmuch-poll-script'."
   (interactive)
-  (message "Polling mail...")
+  ;; (message "Polling mail...")
   (if (stringp notmuch-poll-script)
       (unless (string-empty-p notmuch-poll-script)
 	(unless (equal (notmuch--call-process notmuch-poll-script nil nil) 0)
 	  (error "Notmuch: poll script `%s' failed!" notmuch-poll-script)))
-    (notmuch-call-notmuch-process "new"))
-  (message "Polling mail...done"))
+    (notmuch-start-notmuch "*notmuch-sync*"
+			   nil
+			   (lambda (proc string)
+				  (notmuch-refresh-this-buffer)
+				  ;; (message "Polling mail async...done")
+				  ) "new")))
 
 (defun notmuch-bury-or-kill-this-buffer ()
   "Undisplay the current buffer.
@@ -477,7 +482,8 @@ of its command symbol."
   "Invoke `notmuch-poll' to import mail, then refresh the current buffer."
   (interactive)
   (notmuch-poll)
-  (notmuch-refresh-this-buffer))
+  ;; (notmuch-refresh-this-buffer)
+  )
 
 (defun notmuch-refresh-all-buffers ()
   "Invoke `notmuch-refresh-this-buffer' on all notmuch major-mode buffers.
-- 
2.49.0

