--- /dev/null
+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 132B1431FAE\r
+ for <notmuch@notmuchmail.org>; Sat, 21 Jul 2012 10:37:21 -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 AXkZLTqCf9ZS for <notmuch@notmuchmail.org>;\r
+ Sat, 21 Jul 2012 10:37:19 -0700 (PDT)\r
+Received: from dmz-mailsec-scanner-3.mit.edu (DMZ-MAILSEC-SCANNER-3.MIT.EDU\r
+ [18.9.25.14])\r
+ by olra.theworths.org (Postfix) with ESMTP id B4051431FAF\r
+ for <notmuch@notmuchmail.org>; Sat, 21 Jul 2012 10:37:19 -0700 (PDT)\r
+X-AuditID: 1209190e-b7fb56d0000008b2-3b-500ae8ce825d\r
+Received: from mailhub-auth-3.mit.edu ( [18.9.21.43])\r
+ by dmz-mailsec-scanner-3.mit.edu (Symantec Messaging Gateway) with SMTP\r
+ id EA.13.02226.EC8EA005; Sat, 21 Jul 2012 13:37:18 -0400 (EDT)\r
+Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103])\r
+ by mailhub-auth-3.mit.edu (8.13.8/8.9.2) with ESMTP id q6LHbHRx018463; \r
+ Sat, 21 Jul 2012 13:37:17 -0400\r
+Received: from drake.dyndns.org\r
+ (209-6-116-242.c3-0.arl-ubr1.sbo-arl.ma.cable.rcn.com\r
+ [209.6.116.242]) (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 q6LHbFJu008016\r
+ (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT);\r
+ Sat, 21 Jul 2012 13:37:16 -0400 (EDT)\r
+Received: from amthrax by drake.dyndns.org with local (Exim 4.77)\r
+ (envelope-from <amdragon@mit.edu>)\r
+ id 1SsdcB-0001Zl-Ba; Sat, 21 Jul 2012 13:37:15 -0400\r
+From: Austin Clements <amdragon@MIT.EDU>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH v4 4/8] emacs: Use result text properties for search result\r
+ iteration\r
+Date: Sat, 21 Jul 2012 13:37:08 -0400\r
+Message-Id: <1342892232-5659-5-git-send-email-amdragon@mit.edu>\r
+X-Mailer: git-send-email 1.7.10\r
+In-Reply-To: <1342892232-5659-1-git-send-email-amdragon@mit.edu>\r
+References: <1341354059-29396-1-git-send-email-amdragon@mit.edu>\r
+ <1342892232-5659-1-git-send-email-amdragon@mit.edu>\r
+X-Brightmail-Tracker:\r
+ H4sIAAAAAAAAA+NgFjrMIsWRmVeSWpSXmKPExsUixCmqrXvuBVeAQdsrUYs9+7wsVs/lsbh+\r
+ cyazA7PH3dNcHjtn3WX3eLbqFnMAcxSXTUpqTmZZapG+XQJXxutPK5gK9mtU/F+9m7mB8aZC\r
+ FyMnh4SAiUT71FVsELaYxIV764FsLg4hgX2MEkuu3WSHcDYwSrSs+c0IUiUk8IhJ4vvjCojE\r
+ XEaJjp417CAJNgENiW37l4MViQhIS+y8O5sVxGYWSJP43v4WKM7BISwQKnH7lTtImEVAVeL1\r
+ 6YVg5bwC9hKHnj1kh7hCXuLp/T6wizgFHCQenT3AArG3TGJxx2HGCYz8CxgZVjHKpuRW6eYm\r
+ ZuYUpybrFicn5uWlFuka6+VmluilppRuYgSHlSTfDsavB5UOMQpwMCrx8HrM4gwQYk0sK67M\r
+ PcQoycGkJMrbd58rQIgvKT+lMiOxOCO+qDQntfgQowQHs5II76bTQDnelMTKqtSifJiUNAeL\r
+ kjjvlZSb/kIC6YklqdmpqQWpRTBZGQ4OJQled2D8CAkWpaanVqRl5pQgpJk4OEGG8wANDwap\r
+ 4S0uSMwtzkyHyJ9iVJQS57UDSQiAJDJK8+B6YXH/ilEc6BVh3m/Pgap4gCkDrvsV0GAmoMHS\r
+ WWCDSxIRUlINjAs/KgsKzuVtrnockMPhEcJT+1Sv9YfB4hu7Wo6xX/irpuTKmmeuqh/ee6ov\r
+ XsRUQjr//1vb/JWTg1zZppw/er3647amczpSN3mzVafH/4qQ2nbYZW6sQFPob40X5a7vN3+f\r
+ 1rr+xhGD54eNTqfWR34Rrj0aXeookaJhOsPkzel3EtLB93wPKLEUZyQaajEXFScCABHskUvW AgAA\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, 21 Jul 2012 17:37:21 -0000\r
+\r
+This simplifies the traversal of regions of results and eliminates the\r
+need for save-excursions (which tend to get in the way of maintaining\r
+point when we make changes to the buffer). It also fixes some strange\r
+corner cases in the old line-based code where results that bordered\r
+the region but were not included in it could be affected by region\r
+commands. Coincidentally, this also essentially enables multi-line\r
+search result formats; the only remaining non-multi-line-capable\r
+functions are notmuch-search-{next,previous}-thread, which are only\r
+used for interactive navigation.\r
+---\r
+ emacs/notmuch.el | 78 ++++++++++++++++++++++++++++++++++--------------------\r
+ 1 file changed, 50 insertions(+), 28 deletions(-)\r
+\r
+diff --git a/emacs/notmuch.el b/emacs/notmuch.el\r
+index 6995482..f79d004 100644\r
+--- a/emacs/notmuch.el\r
++++ b/emacs/notmuch.el\r
+@@ -69,7 +69,13 @@\r
+ date, count, authors, subject, tags\r
+ For example:\r
+ (setq notmuch-search-result-format \(\(\"authors\" . \"%-40s\"\)\r
+- \(\"subject\" . \"%s\"\)\)\)"\r
++ \(\"subject\" . \"%s\"\)\)\)\r
++Line breaks are permitted in format strings (though this is\r
++currently experimental). Note that a line break at the end of an\r
++\"authors\" field will get elided if the authors list is long;\r
++place it instead at the beginning of the following field. To\r
++enter a line break when setting this variable with setq, use \\n.\r
++To enter a line break in customize, press \\[quoted-insert] C-j."\r
+ :type '(alist :key-type (string) :value-type (string))\r
+ :group 'notmuch-search)\r
+ \r
+@@ -427,17 +433,40 @@ returns nil"\r
+ (next-single-property-change (or pos (point)) 'notmuch-search-result\r
+ nil (point-max))))\r
+ \r
++(defun notmuch-search-foreach-result (beg end function)\r
++ "Invoke FUNCTION for each result between BEG and END.\r
++\r
++FUNCTION should take one argument. It will be applied to the\r
++character position of the beginning of each result that overlaps\r
++the region between points BEG and END. As a special case, if (=\r
++BEG END), FUNCTION will be applied to the result containing point\r
++BEG."\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
++ (funcall function pos))\r
++ (setq pos (notmuch-search-result-end pos)\r
++ first nil))))\r
++;; Unindent the function argument of notmuch-search-foreach-result so\r
++;; the indentation of callers doesn't get out of hand.\r
++(put 'notmuch-search-foreach-result 'lisp-indent-function 2)\r
++\r
+ (defun notmuch-search-properties-in-region (property beg end)\r
+- (save-excursion\r
+- (let ((output nil)\r
+- (last-line (line-number-at-pos end))\r
+- (max-line (- (line-number-at-pos (point-max)) 2)))\r
+- (goto-char beg)\r
+- (beginning-of-line)\r
+- (while (<= (line-number-at-pos) (min last-line max-line))\r
+- (setq output (cons (get-text-property (point) property) output))\r
+- (forward-line 1))\r
+- output)))\r
++ (let (output)\r
++ (notmuch-search-foreach-result beg end\r
++ (lambda (pos)\r
++ (push (get-text-property pos property) output)))\r
++ output))\r
+ \r
+ (defun notmuch-search-find-thread-id ()\r
+ "Return the thread for the current thread"\r
+@@ -517,28 +546,21 @@ and will also appear in a buffer named \"*Notmuch errors*\"."\r
+ (plist-get (notmuch-search-get-result pos) :tags))\r
+ \r
+ (defun notmuch-search-get-tags-region (beg end)\r
+- (save-excursion\r
+- (let ((output nil)\r
+- (last-line (line-number-at-pos end))\r
+- (max-line (- (line-number-at-pos (point-max)) 2)))\r
+- (goto-char beg)\r
+- (while (<= (line-number-at-pos) (min last-line max-line))\r
+- (setq output (append output (notmuch-search-get-tags)))\r
+- (forward-line 1))\r
+- output)))\r
++ (let (output)\r
++ (notmuch-search-foreach-result beg end\r
++ (lambda (pos)\r
++ (setq output (append output (notmuch-search-get-tags pos)))))\r
++ output))\r
+ \r
+ (defun notmuch-search-tag-region (beg end &optional tag-changes)\r
+ "Change tags for threads in the given region."\r
+ (let ((search-string (notmuch-search-find-thread-id-region-search beg end)))\r
+ (setq tag-changes (funcall 'notmuch-tag search-string tag-changes))\r
+- (save-excursion\r
+- (let ((last-line (line-number-at-pos end))\r
+- (max-line (- (line-number-at-pos (point-max)) 2)))\r
+- (goto-char beg)\r
+- (while (<= (line-number-at-pos) (min last-line max-line))\r
+- (notmuch-search-set-tags\r
+- (notmuch-update-tags (notmuch-search-get-tags) tag-changes))\r
+- (forward-line))))))\r
++ (notmuch-search-foreach-result beg end\r
++ (lambda (pos)\r
++ (notmuch-search-set-tags\r
++ (notmuch-update-tags (notmuch-search-get-tags pos) tag-changes)\r
++ pos)))))\r
+ \r
+ (defun notmuch-search-tag (&optional tag-changes)\r
+ "Change tags for the currently selected thread or region.\r
+-- \r
+1.7.10\r
+\r