From: Austin Clements Date: Sat, 14 Jul 2012 20:01:58 +0000 (+2000) Subject: Re: [PATCH v2 4/7] emacs: Use result text properties for search result iteration X-Git-Url: http://git.tremily.us/gitweb.cgi?a=commitdiff_plain;h=c9439443b5d5d14416fc9a38a6d024c686271330;p=notmuch-archives.git Re: [PATCH v2 4/7] emacs: Use result text properties for search result iteration --- diff --git a/42/1c87027724c88e1f8018a6e6809ffe024a3c6c b/42/1c87027724c88e1f8018a6e6809ffe024a3c6c new file mode 100644 index 000000000..449b9f29d --- /dev/null +++ b/42/1c87027724c88e1f8018a6e6809ffe024a3c6c @@ -0,0 +1,149 @@ +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 60BEF431E62 + for ; Sat, 14 Jul 2012 13:02:02 -0700 (PDT) +X-Virus-Scanned: Debian amavisd-new at olra.theworths.org +X-Spam-Flag: NO +X-Spam-Score: -0.7 +X-Spam-Level: +X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5 + tests=[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 8T+RK65LhF0n for ; + Sat, 14 Jul 2012 13:02:01 -0700 (PDT) +Received: from dmz-mailsec-scanner-7.mit.edu (DMZ-MAILSEC-SCANNER-7.MIT.EDU + [18.7.68.36]) + by olra.theworths.org (Postfix) with ESMTP id ADDE9431FBC + for ; Sat, 14 Jul 2012 13:02:01 -0700 (PDT) +X-AuditID: 12074424-b7f2a6d0000008bf-07-5001d038cc1c +Received: from mailhub-auth-1.mit.edu ( [18.9.21.35]) + by dmz-mailsec-scanner-7.mit.edu (Symantec Messaging Gateway) with SMTP + id 7A.9D.02239.830D1005; Sat, 14 Jul 2012 16:02:00 -0400 (EDT) +Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103]) + by mailhub-auth-1.mit.edu (8.13.8/8.9.2) with ESMTP id q6EK20UP004142; + Sat, 14 Jul 2012 16:02:00 -0400 +Received: from awakening.csail.mit.edu (awakening.csail.mit.edu [18.26.4.91]) + (authenticated bits=0) + (User authenticated as amdragon@ATHENA.MIT.EDU) + by outgoing.mit.edu (8.13.6/8.12.4) with ESMTP id q6EK1xou025107 + (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT); + Sat, 14 Jul 2012 16:01:59 -0400 (EDT) +Received: from amthrax by awakening.csail.mit.edu with local (Exim 4.77) + (envelope-from ) + id 1Sq8XO-0003d8-V4; Sat, 14 Jul 2012 16:01:59 -0400 +Date: Sat, 14 Jul 2012 16:01:58 -0400 +From: Austin Clements +To: Jameson Graef Rollins +Subject: Re: [PATCH v2 4/7] emacs: Use result text properties for search + result iteration +Message-ID: <20120714200158.GG31670@mit.edu> +References: <1342140319-19859-1-git-send-email-amdragon@mit.edu> + <1342237406-32507-1-git-send-email-amdragon@mit.edu> + <1342237406-32507-5-git-send-email-amdragon@mit.edu> + <87d33yf8bi.fsf@servo.finestructure.net> + <20120714195003.GF31670@mit.edu> +MIME-Version: 1.0 +Content-Type: text/plain; charset=us-ascii +Content-Disposition: inline +In-Reply-To: <20120714195003.GF31670@mit.edu> +User-Agent: Mutt/1.5.21 (2010-09-15) +X-Brightmail-Tracker: + H4sIAAAAAAAAA+NgFmpmleLIzCtJLcpLzFFi42IR4hRV1rW4wBhgcOCyvMWefV4W12/OZHZg + 8rh7msvj2apbzAFMUVw2Kak5mWWpRfp2CVwZP4/vYi3oEKuYOe8aawPjJYEuRk4OCQETid6F + rxkhbDGJC/fWs3UxcnEICexjlPjevgXK2cAoMfXcKxYI5ySTxIblU6CcJYwSH9ufg/WzCKhK + bJ1/jBXEZhPQkNi2fzlYXETATKLnyx8wm1lAWuLb72YmEFtYIFqip3cuG4jNK6AjsXpWFzPE + 0D+MEqumHoNKCEqcnPmEBaJZS+LGv5dAzRxgg5b/4wAJcwroSlyYvokdxBYVUJGYcnIb2wRG + oVlIumch6Z6F0L2AkXkVo2xKbpVubmJmTnFqsm5xcmJeXmqRrrlebmaJXmpK6SZGUFizu6js + YGw+pHSIUYCDUYmHN8mfIUCINbGsuDL3EKMkB5OSKK/rScYAIb6k/JTKjMTijPii0pzU4kOM + EhzMSiK8/J1AOd6UxMqq1KJ8mJQ0B4uSOO/1lJv+QgLpiSWp2ampBalFMFkZDg4lCd6k80CN + gkWp6akVaZk5JQhpJg5OkOE8QMN9QGp4iwsSc4sz0yHypxgVpcR5A0ESAiCJjNI8uF5Y2nnF + KA70ijBvJEgVDzBlwXW/AhrMBDR41s9//kCDSxIRUlINjCYXHZT/ugRG3QlV/HckQnb1/z9H + RK6sPM+rPPW9r+KHJueNav+1PzjdfCB/z+fOP/eydfKlvOms3qrS4q0FVl4f8u4EnuWcx3jg + 6aUlHFzzt3xY8uSutsxsryOlF9R3/SgTbv9k/nPTqv/1e5499E6X5xKtS7Ocde/D1d+qwQdr + jsufP3t8pZESS3FGoqEWc1FxIgAUiZU5FgMAAA== +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: Sat, 14 Jul 2012 20:02:02 -0000 + +Quoth myself on Jul 14 at 3:50 pm: +> Quoth Jameson Graef Rollins on Jul 14 at 12:31 pm: +> > On Fri, Jul 13 2012, Austin Clements wrote: +> > > +(defmacro notmuch-search-do-results (beg end pos-sym &rest body) +> > > + "Invoke BODY for each result between BEG and END. +> > > + +> > > +POS-SYM will be bound to the point at the beginning of the +> > > +current result." +> > > + (declare (indent 3)) +> > > + (let ((end-sym (make-symbol "end")) +> > > + (first-sym (make-symbol "first"))) +> > > + `(let ((,pos-sym (notmuch-search-result-beginning ,beg)) +> > > + ;; End must be a marker in case body changes the text +> > > + (,end-sym (copy-marker ,end)) +> > > + ;; Make sure we examine one result, even if (= beg end) +> > > + (,first-sym t)) +> > > + ;; We have to be careful if the region extends beyond the +> > > + ;; results. In this case, pos could be null or there could be +> > > + ;; no result at pos. +> > > + (while (and ,pos-sym (or (< ,pos-sym ,end-sym) ,first-sym)) +> > > + (when (notmuch-search-get-result ,pos-sym) +> > > + ,@body) +> > > + (setq ,pos-sym (notmuch-search-result-end ,pos-sym) +> > > + ,first-sym nil))))) +> > +> > Austin, can you explain why you use a defmacro here? I'm honestly have +> > a hard time parsing what's going on here. I understand in principle how +> > elisp macros work, but I don't see why it's needed here. +> > +> > I'm also trying to understand what the commas are doing +> > (e.g. ",pos-sym"). Are they doing some sort of escaping? +> > +> > Some sophisticated elisp here! +> +> I did this as a macro to parallel things like dolist and loop, I'll +> try this out with a higher-order procedure and see if the results are +> less opaque. + +Here's what it looks like as a higher-order procedure and an example +use: + +(defun notmuch-search-foreach-result (beg end function) + "Invoke FUNCTION with the position of each result between BEG and END." + + (lexical-let ((pos (notmuch-search-result-beginning beg)) + ;; End must be a marker in case function changes the + ;; text. + (end (copy-marker end)) + ;; Make sure we examine at least one result, even if + ;; (= beg end). + (first t)) + ;; We have to be careful if the region extends beyond the results. + ;; In this case, pos could be null or there could be no result at + ;; pos. + (while (and pos (or (< pos end) first)) + (when (notmuch-search-get-result pos) + (apply function pos)) + (setq pos (notmuch-search-result-end pos) + first nil)))) + +(defun notmuch-search-properties-in-region (property beg end) + (let (output) + (notmuch-search-foreach-result + beg end + (lambda (pos) + (push (plist-get (notmuch-search-get-result pos) property) output))) + output)) +