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 9F3DE431FB6 for ; Thu, 3 Feb 2011 09:06:24 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: -0.699 X-Spam-Level: X-Spam-Status: No, score=-0.699 tagged_above=-999 required=5 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7] 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 opQVcF6LNAmG for ; Thu, 3 Feb 2011 09:06:23 -0800 (PST) Received: from mail-qy0-f181.google.com (mail-qy0-f181.google.com [209.85.216.181]) (using TLSv1 with cipher RC4-MD5 (128/128 bits)) (No client certificate requested) by olra.theworths.org (Postfix) with ESMTPS id 96113431FB5 for ; Thu, 3 Feb 2011 09:06:23 -0800 (PST) Received: by qyk12 with SMTP id 12so1247915qyk.5 for ; Thu, 03 Feb 2011 09:06:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:cc:content-type :content-transfer-encoding; bh=TeJOGpmgjNAW4mjfcHl6TwHQztSm1M49W0cZL6j2GbI=; b=daF/fAE9H1FB+glOex55Rzmfgh9HPgEL4RYdPi6lZcZ7MN1kNK+jmkR6m9vT6mbzH4 GxTHOWdyTQ+zJhymAI/zLEcArb8ctEsGobd3chYlNBx0AsvpJBh3JqxELfCUah7XPecg sqhyXcSzX5visVL4efPHTf17X19KQOa25ZOEQ= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:cc:content-type :content-transfer-encoding; b=ViYqLrQeDHRb+66tfi2bj6KKsMmDkScooGi522RADB+NsH8ExNYgK/43wewsj9GAXS QPOjGTePtGllM6CQTQc9eysUe7wQQpxTFAQ0gKNDSEaXjYaWNQt5YcDTsp2SxobTlzR8 eatFG8ya6HXkmwoiHVl1ds5AmElNislpEnL9U= MIME-Version: 1.0 Received: by 10.229.240.85 with SMTP id kz21mr9451701qcb.2.1296752780472; Thu, 03 Feb 2011 09:06:20 -0800 (PST) Sender: amdragon@gmail.com Received: by 10.229.97.143 with HTTP; Thu, 3 Feb 2011 09:06:20 -0800 (PST) In-Reply-To: <1296690999-16542-3-git-send-email-thomas@schwinge.name> References: <87zkqeiffj.fsf@kepler.schwinge.homeip.net> <1296690999-16542-3-git-send-email-thomas@schwinge.name> Date: Thu, 3 Feb 2011 12:06:20 -0500 X-Google-Sender-Auth: VAZt2cAqYEe_iKK1w-IeAiVHq2o Message-ID: Subject: Re: [PATCH 2/2] notmuch.el:notmuch-search-process-filter: Rewritten. Cope with incomplete lines. From: Austin Clements To: Thomas Schwinge Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Cc: notmuch@notmuchmail.org 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: Thu, 03 Feb 2011 17:06:24 -0000 Nice catch. Is there a reason you keep the remaining data in a string instead of taking the more idiomatic elisp approach of leaving it in the process buffer? In fact, the code would probably be simpler if you immediately appended the string to the process buffer like a normal process-filter and then peeled things away using buffer-oriented regexp functions like looking-at. Elisp is a lot better at manipulating buffers than it is at manipulating strings. On Wed, Feb 2, 2011 at 6:56 PM, Thomas Schwinge wrot= e: > This issue has been lying in ambush as of 2009-11-24's commit > 93af7b574598637c2766dd1f8ef343962c9a8efb. > > Signed-off-by: Thomas Schwinge > --- > =A0emacs/notmuch.el | =A0 70 +++++++++++++++++++++++++++++++-------------= --------- > =A01 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." > =A0 =A0 (propertize authors 'face 'notmuch-search-matching-authors))) > > =A0(defun notmuch-search-insert-authors (format-string authors) > - =A0;; Save the match data to avoid interfering with > - =A0;; `notmuch-search-process-filter'. > - =A0(save-match-data > =A0 =A0 (let* ((formatted-authors (format format-string authors)) > =A0 =A0 =A0 =A0 =A0 (formatted-sample (format format-string "")) > =A0 =A0 =A0 =A0 =A0 (visible-string formatted-authors) > @@ -709,7 +706,7 @@ non-authors is found, assume that all of the authors = match." > =A0 =A0 =A0 =A0 =A0(setq overlay (make-overlay start (point))) > =A0 =A0 =A0 =A0 =A0(overlay-put overlay 'invisible invis-spec) > =A0 =A0 =A0 =A0 =A0(overlay-put overlay 'isearch-open-invisible #'notmuch= -search-isearch-authors-show))) > - =A0 =A0 =A0(insert padding)))) > + =A0 =A0 =A0(insert padding))) > > =A0(defun notmuch-search-insert-field (field date count authors subject t= ags) > =A0 (cond > @@ -736,6 +733,10 @@ non-authors is found, assume that all of the authors= match." > =A0 =A0 =A0 =A0 =A0do (notmuch-search-insert-field field date count autho= rs subject tags))) > =A0 (insert "\n")) > > +(defvar notmuch-search-process-filter-data nil > + =A0"Data that has not yet been processed.") > +(make-variable-buffer-local 'notmuch-search-process-filter-data) > + > =A0(defun notmuch-search-process-filter (proc string) > =A0 "Process and filter the output of \"notmuch search\"" > =A0 (let ((buffer (process-buffer proc)) > @@ -743,31 +744,41 @@ non-authors is found, assume that all of the author= s match." > =A0 =A0 (if (buffer-live-p buffer) > =A0 =A0 =A0 =A0(with-current-buffer buffer > =A0 =A0 =A0 =A0 =A0(save-excursion > - =A0 =A0 =A0 =A0 =A0 (let ((line 0) > - =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 (more t) > - =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 (inhibit-read-only t)) > - =A0 =A0 =A0 =A0 =A0 =A0 (while more > - =A0 =A0 =A0 =A0 =A0 =A0 =A0 (if (string-match "^\\(thread:[0-9A-Fa-f]*\= \) \\([^][]*\\) \\(\\[[0-9/]*\\]\\) \\([^;]*\\); \\(.*\\) (\\([^()]*\\))$" = string line) > - =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 (let* ((thread-id (match-string 1 s= tring)) > - =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0(date (match-string = 2 string)) > - =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0(count (match-string= 3 string)) > - =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0(authors (match-stri= ng 4 string)) > - =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0(subject (match-stri= ng 5 string)) > - =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0(tags (match-string = 6 string)) > - =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0(tag-list (if tags (= save-match-data (split-string tags))))) > - =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 (goto-char (point-max)) > - =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 (let ((beg (point-marker))) > - =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 (notmuch-search-show-result= date count authors subject tags) > - =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 (notmuch-search-color-line = beg (point-marker) tag-list) > - =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 (put-text-property beg (poi= nt-marker) 'notmuch-search-thread-id thread-id) > - =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 (put-text-property beg (poi= nt-marker) 'notmuch-search-authors authors) > - =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 (put-text-property beg (poi= nt-marker) 'notmuch-search-subject subject) > - =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 (if (string=3D thread-id no= tmuch-search-target-thread) > - =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 (progn > - =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 (set 'found-tar= get beg) > - =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 (set 'notmuch-s= earch-target-thread "found")))) > - =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 (set 'line (match-end 0))) > - =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 (set 'more nil))))) > + =A0 =A0 =A0 =A0 =A0 (let ((inhibit-read-only t) > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 ;; We may have a partial line saved fro= m the last iteration. > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 (string (concat notmuch-search-process-= filter-data string)) > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 (start 0)) > + =A0 =A0 =A0 =A0 =A0 =A0 (goto-char (point-max)) > + =A0 =A0 =A0 =A0 =A0 =A0 ;; Split `string' into lines. > + =A0 =A0 =A0 =A0 =A0 =A0 (while (string-match "\n" string start) > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 (let ((line (substring string start (match-= beginning 0)))) > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 ;; Save the beginning of the next line = already here, so that > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 ;; we can mangle the match data later o= n. > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 (setq start (match-end 0)) > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 (if (string-match > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0"^\\(thread:[0-9A-Fa-f]*\\) = \\([^][]*\\) \\(\\[[0-9/]*\\]\\) \\([^;]*\\); \\(.*\\) (\\([^()]*\\))$" > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0line) > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 (let* ((thread-id (match-string= 1 line)) > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0(date (match-str= ing 2 line)) > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0(count (match-st= ring 3 line)) > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0(authors (match-= string 4 line)) > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0(subject (match-= string 5 line)) > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0(tags (match-str= ing 6 line)) > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0(tag-list (if ta= gs (split-string tags)))) > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 (let ((beg (point-marker))) > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 (notmuch-search-show-re= sult date count authors subject tags) > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 (notmuch-search-color-l= ine beg (point-marker) tag-list) > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 (put-text-property beg = (point-marker) 'notmuch-search-thread-id thread-id) > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 (put-text-property beg = (point-marker) 'notmuch-search-authors authors) > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 (put-text-property beg = (point-marker) 'notmuch-search-subject subject) > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 (if (string=3D thread-i= d notmuch-search-target-thread) > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 (setq found-tar= get beg > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 not= much-search-target-thread "found")))) > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 ;; Non-conforming line. > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 (insert (concat "Non-conforming lin= e (ignored): <" line ">.\n"))))) > + =A0 =A0 =A0 =A0 =A0 =A0 ;; Save the remainder after the last line break= for the next > + =A0 =A0 =A0 =A0 =A0 =A0 ;; interation. > + =A0 =A0 =A0 =A0 =A0 =A0 (setq notmuch-search-process-filter-data (subst= ring string start)))) > =A0 =A0 =A0 =A0 =A0(if found-target > =A0 =A0 =A0 =A0 =A0 =A0 =A0(goto-char found-target))) > =A0 =A0 =A0 (delete-process proc)))) > @@ -858,6 +869,7 @@ The optional parameters are used as follows: > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 "--sort=3Dnewest-first") > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 query))) > =A0 =A0 =A0 =A0 =A0(set-process-sentinel proc 'notmuch-search-process-sen= tinel) > + =A0 =A0 =A0 =A0 (setq notmuch-search-process-filter-data nil) > =A0 =A0 =A0 =A0 =A0(set-process-filter proc 'notmuch-search-process-filte= r)))) > =A0 =A0 (run-hooks 'notmuch-search-hook))) > > -- > 1.7.1 > > _______________________________________________ > notmuch mailing list > notmuch@notmuchmail.org > http://notmuchmail.org/mailman/listinfo/notmuch >