[PATCH] Perform mail polling asynchronously

Antono Vasiljev self at antono.info
Sun Sep 4 21:14:36 PDT 2011


  * reimplemented notmuch-poll(&optional callback) so that it
    calls process asynchronously and run callback after process
    finished
  * changed usage of notmuch-poll in notmuch-hello-poll-and-update
    and notmuch-search-poll-and-refresh-view
---
 emacs/notmuch-hello.el |    4 +---
 emacs/notmuch.el       |   33 +++++++++++++++++++++++++++------
 2 files changed, 28 insertions(+), 9 deletions(-)

diff --git a/emacs/notmuch-hello.el b/emacs/notmuch-hello.el
index 65fde75..03739e5 100644
--- a/emacs/notmuch-hello.el
+++ b/emacs/notmuch-hello.el
@@ -304,9 +304,7 @@ should be. Returns a cons cell `(tags-per-line width)'."
 (defun notmuch-hello-poll-and-update ()
   "Invoke `notmuch-poll' to import mail, then refresh the current view."
   (interactive)
-  (notmuch-poll)
-  (notmuch-hello-update))
-
+  (notmuch-poll 'notmuch-hello-update))
 
 (defvar notmuch-hello-mode-map
   (let ((map (make-sparse-keymap)))
diff --git a/emacs/notmuch.el b/emacs/notmuch.el
index f11ec24..2c3f8a8 100644
--- a/emacs/notmuch.el
+++ b/emacs/notmuch.el
@@ -954,19 +954,40 @@ the user's needs:
   :type 'string
   :group 'notmuch)
 
-(defun notmuch-poll ()
-  "Run external script to import mail.
 
-Invokes `notmuch-poll-script' if it is not set to an empty string."
+(defun notmuch-poll (&optional poll-callback)
+  "Asyncronously run external script to import mail.
+
+Invokes `notmuch-poll-script' if it is not set to an empty string.
+After script finished `callback' will be called.
+"
   (interactive)
   (if (not (string= notmuch-poll-script ""))
-      (call-process notmuch-poll-script nil nil)))
+      (message "Notmuch: starting mail poll script")
+      (progn
+        (defun notmuch-poll-sentinel (processs event)
+          (if (string-match "^finished" event)
+              (progn
+                (message "Notmuch: poll finished")
+                (if (boundp 'poll-callback)
+                    (poll-callback)))
+            (progn
+              ((message event)
+               (message "Notmuch: something gone wrong when polling mail...")))))
+        (set-process-sentinel
+         (start-process "notmuch-poll"
+                        "*notmuch-poll*"
+                        notmuch-poll-script)
+         'notmuch-poll-sentinel)
+        (switch-to-buffer "*notmuch-poll*")
+        (comint-mode)
+        (switch-to-buffer (other-buffer -1)))))
+
 
 (defun notmuch-search-poll-and-refresh-view ()
   "Invoke `notmuch-poll' to import mail, then refresh the current view."
   (interactive)
-  (notmuch-poll)
-  (notmuch-search-refresh-view))
+  (notmuch-poll 'notmuch-search-refresh-view))
 
 (defun notmuch-search-toggle-order ()
   "Toggle the current search order.
-- 
1.7.5.4



More information about the notmuch mailing list