[PATCH 0/2] emacs: wash: word-wrap bugfix and tweak
[notmuch-archives.git] / 36 / f76e64f3b0ae3b15352ecae3aba546f746b59b
1 Return-Path: <amdragon@mit.edu>\r
2 X-Original-To: notmuch@notmuchmail.org\r
3 Delivered-To: notmuch@notmuchmail.org\r
4 Received: from localhost (localhost [127.0.0.1])\r
5         by olra.theworths.org (Postfix) with ESMTP id 016B841ED7D\r
6         for <notmuch@notmuchmail.org>; Fri, 13 Jul 2012 20:43:45 -0700 (PDT)\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
8 X-Spam-Flag: NO\r
9 X-Spam-Score: -0.7\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5\r
12         tests=[RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled\r
13 Received: from olra.theworths.org ([127.0.0.1])\r
14         by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
15         with ESMTP id U1+YxoQzYFiy for <notmuch@notmuchmail.org>;\r
16         Fri, 13 Jul 2012 20:43:42 -0700 (PDT)\r
17 Received: from dmz-mailsec-scanner-2.mit.edu (DMZ-MAILSEC-SCANNER-2.MIT.EDU\r
18         [18.9.25.13])\r
19         by olra.theworths.org (Postfix) with ESMTP id EC362421163\r
20         for <notmuch@notmuchmail.org>; Fri, 13 Jul 2012 20:43:39 -0700 (PDT)\r
21 X-AuditID: 1209190d-b7fd56d000000933-f7-5000eaeb3535\r
22 Received: from mailhub-auth-1.mit.edu ( [18.9.21.35])\r
23         by dmz-mailsec-scanner-2.mit.edu (Symantec Messaging Gateway) with SMTP\r
24         id 75.89.02355.BEAE0005; Fri, 13 Jul 2012 23:43:39 -0400 (EDT)\r
25 Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103])\r
26         by mailhub-auth-1.mit.edu (8.13.8/8.9.2) with ESMTP id q6E3hcIW029858; \r
27         Fri, 13 Jul 2012 23:43:38 -0400\r
28 Received: from drake.dyndns.org\r
29         (209-6-116-242.c3-0.arl-ubr1.sbo-arl.ma.cable.rcn.com\r
30         [209.6.116.242]) (authenticated bits=0)\r
31         (User authenticated as amdragon@ATHENA.MIT.EDU)\r
32         by outgoing.mit.edu (8.13.6/8.12.4) with ESMTP id q6E3hbqA021330\r
33         (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT);\r
34         Fri, 13 Jul 2012 23:43:38 -0400 (EDT)\r
35 Received: from amthrax by drake.dyndns.org with local (Exim 4.77)\r
36         (envelope-from <amdragon@mit.edu>)\r
37         id 1SptGa-0000a2-Qa; Fri, 13 Jul 2012 23:43:36 -0400\r
38 From: Austin Clements <amdragon@MIT.EDU>\r
39 To: notmuch@notmuchmail.org\r
40 Subject: [PATCH v2 4/7] emacs: Use result text properties for search result\r
41         iteration\r
42 Date: Fri, 13 Jul 2012 23:43:23 -0400\r
43 Message-Id: <1342237406-32507-5-git-send-email-amdragon@mit.edu>\r
44 X-Mailer: git-send-email 1.7.10\r
45 In-Reply-To: <1342237406-32507-1-git-send-email-amdragon@mit.edu>\r
46 References: <1342140319-19859-1-git-send-email-amdragon@mit.edu>\r
47         <1342237406-32507-1-git-send-email-amdragon@mit.edu>\r
48 X-Brightmail-Tracker:\r
49  H4sIAAAAAAAAA+NgFtrLIsWRmVeSWpSXmKPExsUixCmqrPv6FUOAwZGPPBar5/JYXL85k9mB\r
50         yWPnrLvsHs9W3WIOYIrisklJzcksSy3St0vgylgz4yRbwSGFigNTFrA2ME6S6mLk5JAQMJE4\r
51         PHsNK4QtJnHh3nq2LkYuDiGBfYwSHV9msEM4GxglPr2dwwrhPGKS2NZ/A8qZyyixtPsKO0g/\r
52         m4CGxLb9yxlBbBEBaYmdd2eDzWUWcJT4vH8RG4gtLBAq8fXCDDCbRUBVYmfnIbBeXgEHiWtN\r
53         i1gg7pCXeHq/D6yGE6i3rfc22EwhgXKJ69/WME1g5F/AyLCKUTYlt0o3NzEzpzg1Wbc4OTEv\r
54         L7VI10gvN7NELzWldBMjOJQkeXcwvjuodIhRgINRiYc31Z8hQIg1say4MvcQoyQHk5IoLy8w\r
55         EIX4kvJTKjMSizPii0pzUosPMUpwMCuJ8Jq3AeV4UxIrq1KL8mFS0hwsSuK8V1Ju+gsJpCeW\r
56         pGanphakFsFkZTg4lCR4hUGGChalpqdWpGXmlCCkmTg4QYbzAA2XBqnhLS5IzC3OTIfIn2JU\r
57         lBLnvfwSKCEAksgozYPrhcX6K0ZxoFeEeW1A2nmAaQKu+xXQYCagwbN+/vMHGlySiJCSamD0\r
58         PtXabXji4lmX725RfCvZzEq1G82M4nOXqd7690A85qzVE9VJEkvta15mXrT0dO6M7D25qVPK\r
59         UODVVqnZlzMm6+/exmXwgNmP+WTvz5YYC17ZHy8F725tn1buvt5ioszzv4Wt8nfZDT6YPjHc\r
60         vmhFxiSLZQLPclbOiGe1LWld5f6qefuh5bxKLMUZiYZazEXFiQByvzDB0AIAAA==\r
61 X-BeenThere: notmuch@notmuchmail.org\r
62 X-Mailman-Version: 2.1.13\r
63 Precedence: list\r
64 List-Id: "Use and development of the notmuch mail system."\r
65         <notmuch.notmuchmail.org>\r
66 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
67         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
68 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
69 List-Post: <mailto:notmuch@notmuchmail.org>\r
70 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
71 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
72         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
73 X-List-Received-Date: Sat, 14 Jul 2012 03:43:45 -0000\r
74 \r
75 This simplifies the traversal of regions of results and eliminates the\r
76 need for save-excursions (which tend to get in the way of maintaining\r
77 point when we make changes to the buffer).  It also fixes some strange\r
78 corner cases in the old line-based code where results that bordered\r
79 the region but were not included in it could be affected by region\r
80 commands.  Coincidentally, this also essentially enables multi-line\r
81 search result formats; the only remaining non-multi-line-capable\r
82 functions are notmuch-search-{next,previous}-thread, which are only\r
83 used interactively.\r
84 ---\r
85  emacs/notmuch.el |   61 ++++++++++++++++++++++++++++++------------------------\r
86  1 file changed, 34 insertions(+), 27 deletions(-)\r
87 \r
88 diff --git a/emacs/notmuch.el b/emacs/notmuch.el\r
89 index 8e1a769..92ba2c1 100644\r
90 --- a/emacs/notmuch.el\r
91 +++ b/emacs/notmuch.el\r
92 @@ -427,17 +427,33 @@ returns nil"\r
93      (next-single-property-change (or pos (point)) 'notmuch-search-result\r
94                                  nil (point-max))))\r
95  \r
96 +(defmacro notmuch-search-do-results (beg end pos-sym &rest body)\r
97 +  "Invoke BODY for each result between BEG and END.\r
98 +\r
99 +POS-SYM will be bound to the point at the beginning of the\r
100 +current result."\r
101 +  (declare (indent 3))\r
102 +  (let ((end-sym (make-symbol "end"))\r
103 +       (first-sym (make-symbol "first")))\r
104 +    `(let ((,pos-sym (notmuch-search-result-beginning ,beg))\r
105 +          ;; End must be a marker in case body changes the text\r
106 +          (,end-sym (copy-marker ,end))\r
107 +          ;; Make sure we examine one result, even if (= beg end)\r
108 +          (,first-sym t))\r
109 +       ;; We have to be careful if the region extends beyond the\r
110 +       ;; results.  In this case, pos could be null or there could be\r
111 +       ;; no result at pos.\r
112 +       (while (and ,pos-sym (or (< ,pos-sym ,end-sym) ,first-sym))\r
113 +        (when (notmuch-search-get-result ,pos-sym)\r
114 +          ,@body)\r
115 +        (setq ,pos-sym (notmuch-search-result-end ,pos-sym)\r
116 +              ,first-sym nil)))))\r
117 +\r
118  (defun notmuch-search-properties-in-region (property beg end)\r
119 -  (save-excursion\r
120 -    (let ((output nil)\r
121 -         (last-line (line-number-at-pos end))\r
122 -         (max-line (- (line-number-at-pos (point-max)) 2)))\r
123 -      (goto-char beg)\r
124 -      (beginning-of-line)\r
125 -      (while (<= (line-number-at-pos) (min last-line max-line))\r
126 -       (setq output (cons (get-text-property (point) property) output))\r
127 -       (forward-line 1))\r
128 -      output)))\r
129 +  (let (output)\r
130 +    (notmuch-search-do-results beg end pos\r
131 +      (push (get-text-property pos property) output))\r
132 +    output))\r
133  \r
134  (defun notmuch-search-find-thread-id ()\r
135    "Return the thread for the current thread"\r
136 @@ -517,28 +533,19 @@ and will also appear in a buffer named \"*Notmuch errors*\"."\r
137    (plist-get (notmuch-search-get-result pos) :tags))\r
138  \r
139  (defun notmuch-search-get-tags-region (beg end)\r
140 -  (save-excursion\r
141 -    (let ((output nil)\r
142 -         (last-line (line-number-at-pos end))\r
143 -         (max-line (- (line-number-at-pos (point-max)) 2)))\r
144 -      (goto-char beg)\r
145 -      (while (<= (line-number-at-pos) (min last-line max-line))\r
146 -       (setq output (append output (notmuch-search-get-tags)))\r
147 -       (forward-line 1))\r
148 -      output)))\r
149 +  (let (output)\r
150 +    (notmuch-search-do-results beg end pos\r
151 +      (setq output (append output (notmuch-search-get-tags pos))))\r
152 +    output))\r
153  \r
154  (defun notmuch-search-tag-region (beg end &optional tag-changes)\r
155    "Change tags for threads in the given region."\r
156    (let ((search-string (notmuch-search-find-thread-id-region-search beg end)))\r
157      (setq tag-changes (funcall 'notmuch-tag search-string tag-changes))\r
158 -    (save-excursion\r
159 -      (let ((last-line (line-number-at-pos end))\r
160 -           (max-line (- (line-number-at-pos (point-max)) 2)))\r
161 -       (goto-char beg)\r
162 -       (while (<= (line-number-at-pos) (min last-line max-line))\r
163 -         (notmuch-search-set-tags\r
164 -          (notmuch-update-tags (notmuch-search-get-tags) tag-changes))\r
165 -         (forward-line))))))\r
166 +    (notmuch-search-do-results beg end pos\r
167 +      (notmuch-search-set-tags\r
168 +       (notmuch-update-tags (notmuch-search-get-tags pos) tag-changes)\r
169 +       pos))))\r
170  \r
171  (defun notmuch-search-tag (&optional tag-changes)\r
172    "Change tags for the currently selected thread or region.\r
173 -- \r
174 1.7.10\r
175 \r