From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by arlo.cworth.org (Postfix) with ESMTP id C65D86DE1766 for ; Sun, 25 Oct 2015 02:17:13 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at cworth.org X-Spam-Flag: NO X-Spam-Score: -0.099 X-Spam-Level: X-Spam-Status: No, score=-0.099 tagged_above=-999 required=5 tests=[AWL=0.471, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_PASS=-0.001] autolearn=disabled Received: from arlo.cworth.org ([127.0.0.1]) by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 1v1BwuIPwDSA for ; Sun, 25 Oct 2015 02:17:12 -0700 (PDT) Received: from mail-wi0-f177.google.com (mail-wi0-f177.google.com [209.85.212.177]) by arlo.cworth.org (Postfix) with ESMTPS id BBB056DE1405 for ; Sun, 25 Oct 2015 02:17:11 -0700 (PDT) Received: by wicll6 with SMTP id ll6so78436637wic.1 for ; Sun, 25 Oct 2015 02:17:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=ZtLixrTPzwaSU0obzuHnb1d7sDo+v553YyniA8qzwKk=; b=Jry1bn2iXQ8u64difrdBvgAwIma3ITgQ62ias00qEelye299awj25b518Q/icdOZwu U6I0WgypIP/685Qp9qcYwgOOaYUnAWwLSMH86JlJ+VGQ1Z2+hBuvwSMFO+QpIZ4FuSl4 H2dXuw+E43q/iNzQzgzN68+TanVa5W1G2g1dCXSihfQm4nOUbI3C9hAA/y52eeqOpoJ5 tSmHkMsHpSWdURn6eQsVOpggK6YJeIcUBegFU+WAWMV9LMJNBwb0NWExpzgaqo6Z0qsY 1mBd/9rR7uAjNzDtajAGuJHZe7Wwy4HnVxPOnc+OjnoSMHLndazfbInQXMpZeke5QhQZ PW6g== X-Received: by 10.28.87.1 with SMTP id l1mr1347836wmb.72.1445764627732; Sun, 25 Oct 2015 02:17:07 -0700 (PDT) Received: from localhost (5751dfa2.skybroadband.com. [87.81.223.162]) by smtp.gmail.com with ESMTPSA id bh5sm32506514wjb.42.2015.10.25.02.17.05 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 25 Oct 2015 02:17:06 -0700 (PDT) From: Mark Walters To: notmuch@notmuchmail.org Subject: [PATCH] Fix clash of company mode and async harvest Date: Sun, 25 Oct 2015 09:16:58 +0000 Message-Id: <1445764618-29250-1-git-send-email-markwalters1009@gmail.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <87lhardeo6.fsf@qmul.ac.uk> References: <87lhardeo6.fsf@qmul.ac.uk> X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.20 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: Sun, 25 Oct 2015 09:17:13 -0000 The current code has a bug such that an async partial harvest kills the full harvest, and marks the full harvest complete. This means the full harvest is not reattempted for another 24 hours (during which time the user will only get partial results). Fix this by using separate buffers for full and partial harvests. Also check the return value of the full harvest and only mark the harvest complete if it finishes successfully. --- This seems to fix the bug mentioned in my previous email. It works under light testing in both emacs 23 and emacs 24. Best wishes Mark emacs/notmuch-address.el | 41 +++++++++++++++++++++++++++++------------ 1 file changed, 29 insertions(+), 12 deletions(-) diff --git a/emacs/notmuch-address.el b/emacs/notmuch-address.el index d82c2aa..228135e 100644 --- a/emacs/notmuch-address.el +++ b/emacs/notmuch-address.el @@ -161,7 +161,10 @@ (defun notmuch-address-harvest-filter (proc string) (notmuch-sexp-parse-partial-list 'notmuch-address-harvest-handle-result (process-buffer proc))))) -(defvar notmuch-address-harvest-proc nil) ; the process of a harvest underway +(defvar notmuch-address-harvest-procs '(nil . nil) + "The currently running harvests. + +The car is a partial harvest, and the cdr is a full harvest") (defun notmuch-address-harvest (&optional filter-query synchronous callback) "Collect addresses completion candidates. It queries the @@ -184,16 +187,25 @@ (defun notmuch-address-harvest (&optional filter-query synchronous callback) (mapc #'notmuch-address-harvest-addr (apply 'notmuch-call-notmuch-sexp args)) ;; Asynchronous - (when notmuch-address-harvest-proc - (kill-buffer (process-buffer notmuch-address-harvest-proc))) ; this also kills the process - (setq notmuch-address-harvest-proc - (apply 'notmuch-start-notmuch - "notmuch-address-harvest" ; process name - " *notmuch-address-harvest*" ; process buffer - callback ; process sentinel - args)) - (set-process-filter notmuch-address-harvest-proc 'notmuch-address-harvest-filter) - (set-process-query-on-exit-flag notmuch-address-harvest-proc nil))) + (let* ((current-proc (if filter-query + (car notmuch-address-harvest-procs) + (cdr notmuch-address-harvest-procs))) + (proc-name (format "notmuch-address-%s-harvest" + (if filter-query "partial" "full"))) + (proc-buf (concat " *" proc-name "*"))) + ;; Kill any existing process + (when current-proc + (kill-buffer (process-buffer current-proc))) ; this also kills the process + + (setq current-proc + (apply 'notmuch-start-notmuch proc-name proc-buf + callback ; process sentinel + args)) + (set-process-filter current-proc 'notmuch-address-harvest-filter) + (set-process-query-on-exit-flag current-proc nil) + (if filter-query + (setcar notmuch-address-harvest-procs current-proc) + (setcdr notmuch-address-harvest-procs current-proc))))) ;; return value nil) @@ -203,7 +215,12 @@ (defun notmuch-address-harvest-trigger () (setq notmuch-address-last-harvest now) (notmuch-address-harvest nil nil (lambda (proc event) - (setq notmuch-address-full-harvest-finished t)))))) + ;; If harvest fails, we want to try + ;; again when the trigger is next + ;; called + (if (string= event "finished\n") + (setq notmuch-address-full-harvest-finished t) + (setq notmuch-address-last-harvest 0))))))) ;; -- 2.1.4