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 6DF2F431FB6 for ; Wed, 2 Feb 2011 15:57:31 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: 0 X-Spam-Level: X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[RCVD_IN_DNSWL_NONE=-0.0001] 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 7blhMd43mQ7x for ; Wed, 2 Feb 2011 15:57:30 -0800 (PST) Received: from smtprelay03.ispgateway.de (smtprelay03.ispgateway.de [80.67.18.15]) by olra.theworths.org (Postfix) with ESMTP id 35D69431FB5 for ; Wed, 2 Feb 2011 15:57:30 -0800 (PST) Received: from [87.180.46.33] (helo=stokes.schwinge.homeip.net) by smtprelay03.ispgateway.de with esmtpa (Exim 4.68) (envelope-from ) id 1PkmZk-0000PV-TZ for notmuch@notmuchmail.org; Thu, 03 Feb 2011 00:57:29 +0100 Received: (qmail 7034 invoked from network); 2 Feb 2011 23:57:12 -0000 Received: from schwinge.homeip.net (87.180.46.33) by stokes.schwinge.homeip.net with QMQP; 2 Feb 2011 23:57:12 -0000 Received: (nullmailer pid 16862 invoked by uid 1000); Wed, 02 Feb 2011 23:57:11 -0000 From: Thomas Schwinge To: notmuch@notmuchmail.org Subject: [PATCH 2/2] notmuch.el:notmuch-search-process-filter: Rewritten. Cope with incomplete lines. Date: Thu, 3 Feb 2011 00:56:39 +0100 Message-Id: <1296690999-16542-3-git-send-email-thomas@schwinge.name> X-Mailer: git-send-email 1.7.1 In-Reply-To: <87zkqeiffj.fsf@kepler.schwinge.homeip.net> References: <87zkqeiffj.fsf@kepler.schwinge.homeip.net> X-Df-Sender: thomas@schwinge.name Cc: Thomas Schwinge 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: Wed, 02 Feb 2011 23:57:31 -0000 This issue has been lying in ambush as of 2009-11-24's commit 93af7b574598637c2766dd1f8ef343962c9a8efb. Signed-off-by: Thomas Schwinge --- emacs/notmuch.el | 70 +++++++++++++++++++++++++++++++---------------------- 1 files changed, 41 insertions(+), 29 deletions(-) diff --git a/emacs/notmuch.el b/emacs/notmuch.el index 3d82f0d..35ccee6 100644 --- a/emacs/notmuch.el +++ b/emacs/notmuch.el @@ -641,9 +641,6 @@ non-authors is found, assume that all of the authors match." (propertize authors 'face 'notmuch-search-matching-authors))) (defun notmuch-search-insert-authors (format-string authors) - ;; Save the match data to avoid interfering with - ;; `notmuch-search-process-filter'. - (save-match-data (let* ((formatted-authors (format format-string authors)) (formatted-sample (format format-string "")) (visible-string formatted-authors) @@ -709,7 +706,7 @@ non-authors is found, assume that all of the authors match." (setq overlay (make-overlay start (point))) (overlay-put overlay 'invisible invis-spec) (overlay-put overlay 'isearch-open-invisible #'notmuch-search-isearch-authors-show))) - (insert padding)))) + (insert padding))) (defun notmuch-search-insert-field (field date count authors subject tags) (cond @@ -736,6 +733,10 @@ non-authors is found, assume that all of the authors match." do (notmuch-search-insert-field field date count authors subject tags))) (insert "\n")) +(defvar notmuch-search-process-filter-data nil + "Data that has not yet been processed.") +(make-variable-buffer-local 'notmuch-search-process-filter-data) + (defun notmuch-search-process-filter (proc string) "Process and filter the output of \"notmuch search\"" (let ((buffer (process-buffer proc)) @@ -743,31 +744,41 @@ non-authors is found, assume that all of the authors match." (if (buffer-live-p buffer) (with-current-buffer buffer (save-excursion - (let ((line 0) - (more t) - (inhibit-read-only t)) - (while more - (if (string-match "^\\(thread:[0-9A-Fa-f]*\\) \\([^][]*\\) \\(\\[[0-9/]*\\]\\) \\([^;]*\\); \\(.*\\) (\\([^()]*\\))$" string line) - (let* ((thread-id (match-string 1 string)) - (date (match-string 2 string)) - (count (match-string 3 string)) - (authors (match-string 4 string)) - (subject (match-string 5 string)) - (tags (match-string 6 string)) - (tag-list (if tags (save-match-data (split-string tags))))) - (goto-char (point-max)) - (let ((beg (point-marker))) - (notmuch-search-show-result date count authors subject tags) - (notmuch-search-color-line beg (point-marker) tag-list) - (put-text-property beg (point-marker) 'notmuch-search-thread-id thread-id) - (put-text-property beg (point-marker) 'notmuch-search-authors authors) - (put-text-property beg (point-marker) 'notmuch-search-subject subject) - (if (string= thread-id notmuch-search-target-thread) - (progn - (set 'found-target beg) - (set 'notmuch-search-target-thread "found")))) - (set 'line (match-end 0))) - (set 'more nil))))) + (let ((inhibit-read-only t) + ;; We may have a partial line saved from the last iteration. + (string (concat notmuch-search-process-filter-data string)) + (start 0)) + (goto-char (point-max)) + ;; Split `string' into lines. + (while (string-match "\n" string start) + (let ((line (substring string start (match-beginning 0)))) + ;; Save the beginning of the next line already here, so that + ;; we can mangle the match data later on. + (setq start (match-end 0)) + (if (string-match + "^\\(thread:[0-9A-Fa-f]*\\) \\([^][]*\\) \\(\\[[0-9/]*\\]\\) \\([^;]*\\); \\(.*\\) (\\([^()]*\\))$" + line) + (let* ((thread-id (match-string 1 line)) + (date (match-string 2 line)) + (count (match-string 3 line)) + (authors (match-string 4 line)) + (subject (match-string 5 line)) + (tags (match-string 6 line)) + (tag-list (if tags (split-string tags)))) + (let ((beg (point-marker))) + (notmuch-search-show-result date count authors subject tags) + (notmuch-search-color-line beg (point-marker) tag-list) + (put-text-property beg (point-marker) 'notmuch-search-thread-id thread-id) + (put-text-property beg (point-marker) 'notmuch-search-authors authors) + (put-text-property beg (point-marker) 'notmuch-search-subject subject) + (if (string= thread-id notmuch-search-target-thread) + (setq found-target beg + notmuch-search-target-thread "found")))) + ;; Non-conforming line. + (insert (concat "Non-conforming line (ignored): <" line ">.\n"))))) + ;; Save the remainder after the last line break for the next + ;; interation. + (setq notmuch-search-process-filter-data (substring string start)))) (if found-target (goto-char found-target))) (delete-process proc)))) @@ -858,6 +869,7 @@ The optional parameters are used as follows: "--sort=newest-first") query))) (set-process-sentinel proc 'notmuch-search-process-sentinel) + (setq notmuch-search-process-filter-data nil) (set-process-filter proc 'notmuch-search-process-filter)))) (run-hooks 'notmuch-search-hook))) -- 1.7.1