From: Antono Vasiljev <self@antono.info>
To: notmuch@notmuchmail.org
Subject: [PATCH] Perform mail polling asynchronously
Date: Mon, 5 Sep 2011 07:14:36 +0300 [thread overview]
Message-ID: <1315196076-9254-1-git-send-email-self@antono.info> (raw)
* 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
next reply other threads:[~2011-09-05 4:14 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-09-05 4:14 Antono Vasiljev [this message]
2012-01-03 16:02 ` [PATCH] Perform mail polling asynchronously 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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://notmuchmail.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1315196076-9254-1-git-send-email-self@antono.info \
--to=self@antono.info \
--cc=notmuch@notmuchmail.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).