Return-Path: X-Original-To: notmuch@notmuchmail.org Delivered-To: notmuch@notmuchmail.org Received: from localhost (localhost [127.0.0.1]) by olra.theworths.org (Postfix) with ESMTP id 07CE9431FD0 for ; Sun, 4 Sep 2011 21:14:50 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: 1.363 X-Spam-Level: * X-Spam-Status: No, score=1.363 tagged_above=-999 required=5 tests=[RDNS_DYNAMIC=0.363, TO_NO_BRKTS_DYNIP=1] autolearn=disabled Received: from olra.theworths.org ([127.0.0.1]) by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id S7lbjL54rjSu for ; Sun, 4 Sep 2011 21:14:49 -0700 (PDT) Received: from mail.antono.info (ec2-50-19-243-116.compute-1.amazonaws.com [50.19.243.116]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by olra.theworths.org (Postfix) with ESMTPS id 8807E431FB6 for ; Sun, 4 Sep 2011 21:14:49 -0700 (PDT) Received: by mail.antono.info (Postfix, from userid 1003) id A543261477; Mon, 5 Sep 2011 04:15:19 +0000 (UTC) Received: from localhost.localdomain (unknown [178.121.201.33]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.antono.info (Postfix) with ESMTPSA id 2DEE660381; Mon, 5 Sep 2011 04:15:18 +0000 (UTC) From: Antono Vasiljev To: notmuch@notmuchmail.org Subject: [PATCH] Perform mail polling asynchronously Date: Mon, 5 Sep 2011 07:14:36 +0300 Message-Id: <1315196076-9254-1-git-send-email-self@antono.info> X-Mailer: git-send-email 1.7.5.4 X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 05 Sep 2011 04:14:50 -0000 * 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