Re: [PATCH v2 4/7] emacs: Use result text properties for search result iteration
authorAustin Clements <amdragon@MIT.EDU>
Sat, 14 Jul 2012 20:01:58 +0000 (16:01 +2000)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:48:19 +0000 (09:48 -0800)
42/1c87027724c88e1f8018a6e6809ffe024a3c6c [new file with mode: 0644]

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