[PATCH] Fix clash of company mode and async harvest

Mark Walters markwalters1009 at gmail.com
Sun Oct 25 02:16:58 PDT 2015


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



More information about the notmuch mailing list