unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
* [PATCH] Perform mail polling asynchronously
@ 2011-09-05  4:14 Antono Vasiljev
  2012-01-03 16:02 ` David Edmondson
  0 siblings, 1 reply; 6+ messages in thread
From: Antono Vasiljev @ 2011-09-05  4:14 UTC (permalink / raw)
  To: notmuch

  * 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

^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2012-01-06 15:25 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-09-05  4:14 [PATCH] Perform mail polling asynchronously Antono Vasiljev
2012-01-03 16:02 ` David Edmondson
2012-01-06 11:09   ` Antono Vasiljev
2012-01-06 11:25     ` David Edmondson
2012-01-06 14:45   ` Jesse Rosenthal
2012-01-06 15:25     ` David Edmondson

Code repositories for project(s) associated with this public inbox

	https://yhetil.org/notmuch.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).