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 E90D6429E20 for ; Thu, 10 Mar 2011 18:09:52 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: -0.99 X-Spam-Level: X-Spam-Status: No, score=-0.99 tagged_above=-999 required=5 tests=[ALL_TRUSTED=-1, T_MIME_NO_TEXT=0.01] 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 S1BJqQ-rj18y; Thu, 10 Mar 2011 18:09:52 -0800 (PST) Received: from yoom.home.cworth.org (localhost [127.0.0.1]) by olra.theworths.org (Postfix) with ESMTP id 4E490431FB5; Thu, 10 Mar 2011 18:09:52 -0800 (PST) Received: by yoom.home.cworth.org (Postfix, from userid 1000) id DED5454C0C4; Thu, 10 Mar 2011 18:09:51 -0800 (PST) From: Carl Worth To: Austin Clements , Thomas Schwinge Subject: Re: [PATCH 2/2] notmuch.el:notmuch-search-process-filter: Rewritten. Cope with incomplete lines. In-Reply-To: References: <87zkqeiffj.fsf@kepler.schwinge.homeip.net> <1296690999-16542-3-git-send-email-thomas@schwinge.name> User-Agent: Notmuch/0.5 (http://notmuchmail.org) Emacs/23.2.1 (i486-pc-linux-gnu) Date: Thu, 10 Mar 2011 18:09:51 -0800 Message-ID: <87oc5i8l1s.fsf@yoom.home.cworth.org> MIME-Version: 1.0 Content-Type: multipart/signed; boundary="=-=-="; micalg=pgp-sha1; protocol="application/pgp-signature" 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: Fri, 11 Mar 2011 02:09:53 -0000 --=-=-= Content-Transfer-Encoding: quoted-printable On Thu, 3 Feb 2011 12:06:20 -0500, Austin Clements wrote: > Nice catch. >=20 > 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? Thomas is excused since he was just modifying my code originally. And now I've gone and made it even worse by adding a bunch of hideously non-idiomatic expressions like: (while (and (< line (length string)) (=3D (elt string line) ?\n)) (setq line (1+ line))) The rough equivalent in C would be quite natural (where we actually have pointers): while (*s && *s =3D=3D '\n') s++; but the above elisp is quite nasty. > 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. I spent a bit of time trying this. Using looking-at is definitely better than string-match since we can then use things like (match-string 1) rather than (match-string 1 string). And getting rid of the "line" variable means that all of the ugly expressions like the one I showed above went away. The approach I tried was to use a temporary buffer for the unparsed data and the process buffer for the resulting parsed data. The code got a bit awkward as I kept having to jump back and for between (with-temp-buffer) and (with-current-buffer buffer)---particularly due to the buffer-local variable to hold the trailing data from the past run. A better approach might be to use a single buffer, leave the unparse data at the end, and just make it hidden. But I'll leave this alone for now since fighting elisp has left me annoyed. If anyone wants to clean up my hideous elisp here, then that would be fine with me. =2DCarl =2D-=20 carl.d.worth@intel.com --=-=-= Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.10 (GNU/Linux) iD8DBQFNeYRv6JDdNq8qSWgRAo6rAJkBq1/ECsairoUAV9ZiKzCzZbF25ACfTdaD yuEIt9J/DdmcbfAVQJjVe0k= =K5J8 -----END PGP SIGNATURE----- --=-=-=--