Re: [feature request] emacs: use `notmuch insert` for FCC
[notmuch-archives.git] / 6c / 73a047923aed0e63cabb3752a89ab820767c20
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 EE2A5431FAE\r
6         for <notmuch@notmuchmail.org>; Thu, 12 Jul 2012 17:45:27 -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 apamxnf39+Wr for <notmuch@notmuchmail.org>;\r
16         Thu, 12 Jul 2012 17:45:26 -0700 (PDT)\r
17 Received: from dmz-mailsec-scanner-1.mit.edu (DMZ-MAILSEC-SCANNER-1.MIT.EDU\r
18         [18.9.25.12])\r
19         by olra.theworths.org (Postfix) with ESMTP id D0ABD431FC4\r
20         for <notmuch@notmuchmail.org>; Thu, 12 Jul 2012 17:45:25 -0700 (PDT)\r
21 X-AuditID: 1209190c-b7f806d000006b87-7e-4fff6fa5366f\r
22 Received: from mailhub-auth-2.mit.edu ( [18.7.62.36])\r
23         by dmz-mailsec-scanner-1.mit.edu (Symantec Messaging Gateway) with SMTP\r
24         id 8C.72.27527.5AF6FFF4; Thu, 12 Jul 2012 20:45:25 -0400 (EDT)\r
25 Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103])\r
26         by mailhub-auth-2.mit.edu (8.13.8/8.9.2) with ESMTP id q6D0jPLp010242; \r
27         Thu, 12 Jul 2012 20:45:25 -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 q6D0jNHG010665\r
33         (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT);\r
34         Thu, 12 Jul 2012 20:45:24 -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 1SpU0Z-0005S2-Jl; Thu, 12 Jul 2012 20:45:23 -0400\r
38 From: Austin Clements <amdragon@MIT.EDU>\r
39 To: notmuch@notmuchmail.org\r
40 Subject: [PATCH 4/7] emacs: Use result text properties for search result\r
41         iteration\r
42 Date: Thu, 12 Jul 2012 20:45:16 -0400\r
43 Message-Id: <1342140319-19859-5-git-send-email-amdragon@mit.edu>\r
44 X-Mailer: git-send-email 1.7.10\r
45 In-Reply-To: <1342140319-19859-1-git-send-email-amdragon@mit.edu>\r
46 References: <1342140319-19859-1-git-send-email-amdragon@mit.edu>\r
47 X-Brightmail-Tracker:\r
48  H4sIAAAAAAAAA+NgFtrIIsWRmVeSWpSXmKPExsUixG6nors0/7+/QeMpKYvrN2cyOzB6PFt1\r
49         izmAMYrLJiU1J7MstUjfLoEr49XFfpaCQwoV228KNjBOkupi5OSQEDCR2PjqJiOELSZx4d56\r
50         ti5GLg4hgX2MEo8PLodyNjBK9E7/zwLhPGKS+L3qACuEM5dRYmXrX3aQfjYBDYlt+5eDzRIR\r
51         kJbYeXc2UBEHB7OAmsSfLhUQU1ggSKJlbR5IBYuAqsSEdydZQGxeAQeJl/8PMkNcIS/x9H4f\r
52         G4jNKeAoseHLBVYQWwiopvHYTOYJjPwLGBlWMcqm5Fbp5iZm5hSnJusWJyfm5aUW6Rrq5WaW\r
53         6KWmlG5iBIUMpyTPDsY3B5UOMQpwMCrx8P6K/e8vxJpYVlyZe4hRkoNJSZTXJRsoxJeUn1KZ\r
54         kVicEV9UmpNafIhRgoNZSYR3nT1QjjclsbIqtSgfJiXNwaIkzns55aa/kEB6YklqdmpqQWoR\r
55         TFaGg0NJgpcTGBtCgkWp6akVaZk5JQhpJg5OkOE8QMO35YEMLy5IzC3OTIfIn2JUlBLnvQCS\r
56         EABJZJTmwfXCYvoVozjQK8K8O0GqeIDpAK77FdBgJqDBs37+AxlckoiQkmpgDHzov/Mwi8HE\r
57         tJd8nMX87E9f6VXE9LxwFXxv/NzM5j/7qmUXA65+qb/5WvaZrfXuzYwNIns36i3vKF5lk/6K\r
58         L3Tl6V3FvVff5OTN1uB2XWUkGRD+VVJx0rlj8Ud8ZaWZOuom/Ppx8Nzx7qd74paze72yUWzc\r
59         9OBZdbOlkOeMVdaxa7nmafpIKLEUZyQaajEXFScCAJzGl3fEAgAA\r
60 X-BeenThere: notmuch@notmuchmail.org\r
61 X-Mailman-Version: 2.1.13\r
62 Precedence: list\r
63 List-Id: "Use and development of the notmuch mail system."\r
64         <notmuch.notmuchmail.org>\r
65 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
66         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
67 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
68 List-Post: <mailto:notmuch@notmuchmail.org>\r
69 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
70 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
71         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
72 X-List-Received-Date: Fri, 13 Jul 2012 00:45:28 -0000\r
73 \r
74 This simplifies the traversal of regions of results and eliminates the\r
75 need for save-excursions (which tend to get in the way of maintaining\r
76 point when we make changes to the buffer).  It also fixes some strange\r
77 corner cases in the old line-based code where results that bordered\r
78 the region but were not included in it could be affected by region\r
79 commands.  Coincidentally, this also essentially enables multi-line\r
80 search result formats; the only remaining non-multi-line-capable\r
81 functions are notmuch-search-{next,previous}-thread, which are only\r
82 used interactively.\r
83 ---\r
84  emacs/notmuch.el |   61 ++++++++++++++++++++++++++++++------------------------\r
85  1 file changed, 34 insertions(+), 27 deletions(-)\r
86 \r
87 diff --git a/emacs/notmuch.el b/emacs/notmuch.el\r
88 index 2f83425..3f72427 100644\r
89 --- a/emacs/notmuch.el\r
90 +++ b/emacs/notmuch.el\r
91 @@ -427,17 +427,33 @@ returns nil"\r
92      (next-single-property-change (or pos (point)) 'notmuch-search-result\r
93                                  nil (point-max))))\r
94  \r
95 +(defmacro notmuch-search-do-results (beg end pos-sym &rest body)\r
96 +  "Invoke BODY for each result between BEG and END.\r
97 +\r
98 +POS-SYM will be bound to the point at the beginning of the\r
99 +current result."\r
100 +  (declare (indent 3))\r
101 +  (let ((end-sym (make-symbol "end"))\r
102 +       (first-sym (make-symbol "first")))\r
103 +    `(let ((,pos-sym (notmuch-search-result-beginning ,beg))\r
104 +          ;; End must be a marker in case body changes the text\r
105 +          (,end-sym (copy-marker ,end))\r
106 +          ;; Make sure we examine one result, even if (= beg end)\r
107 +          (,first-sym t))\r
108 +       ;; We have to be careful if the region extends beyond the\r
109 +       ;; results.  In this case, pos could be null or there could be\r
110 +       ;; no result at pos.\r
111 +       (while (and ,pos-sym (or (< ,pos-sym ,end-sym) ,first-sym))\r
112 +        (when (notmuch-search-get-result ,pos-sym)\r
113 +          ,@body)\r
114 +        (setq ,pos-sym (notmuch-search-result-end ,pos-sym)\r
115 +              ,first-sym nil)))))\r
116 +\r
117  (defun notmuch-search-properties-in-region (property beg end)\r
118 -  (save-excursion\r
119 -    (let ((output nil)\r
120 -         (last-line (line-number-at-pos end))\r
121 -         (max-line (- (line-number-at-pos (point-max)) 2)))\r
122 -      (goto-char beg)\r
123 -      (beginning-of-line)\r
124 -      (while (<= (line-number-at-pos) (min last-line max-line))\r
125 -       (setq output (cons (get-text-property (point) property) output))\r
126 -       (forward-line 1))\r
127 -      output)))\r
128 +  (let (output)\r
129 +    (notmuch-search-do-results beg end pos\r
130 +      (push (get-text-property pos property) output))\r
131 +    output))\r
132  \r
133  (defun notmuch-search-find-thread-id ()\r
134    "Return the thread for the current thread"\r
135 @@ -517,28 +533,19 @@ and will also appear in a buffer named \"*Notmuch errors*\"."\r
136    (plist-get (notmuch-search-get-result pos) :tags))\r
137  \r
138  (defun notmuch-search-get-tags-region (beg end)\r
139 -  (save-excursion\r
140 -    (let ((output nil)\r
141 -         (last-line (line-number-at-pos end))\r
142 -         (max-line (- (line-number-at-pos (point-max)) 2)))\r
143 -      (goto-char beg)\r
144 -      (while (<= (line-number-at-pos) (min last-line max-line))\r
145 -       (setq output (append output (notmuch-search-get-tags)))\r
146 -       (forward-line 1))\r
147 -      output)))\r
148 +  (let (output)\r
149 +    (notmuch-search-do-results beg end pos\r
150 +      (setq output (append output (notmuch-search-get-tags pos))))\r
151 +    output))\r
152  \r
153  (defun notmuch-search-tag-region (beg end &optional tag-changes)\r
154    "Change tags for threads in the given region."\r
155    (let ((search-string (notmuch-search-find-thread-id-region-search beg end)))\r
156      (setq tag-changes (funcall 'notmuch-tag search-string tag-changes))\r
157 -    (save-excursion\r
158 -      (let ((last-line (line-number-at-pos end))\r
159 -           (max-line (- (line-number-at-pos (point-max)) 2)))\r
160 -       (goto-char beg)\r
161 -       (while (<= (line-number-at-pos) (min last-line max-line))\r
162 -         (notmuch-search-set-tags\r
163 -          (notmuch-update-tags (notmuch-search-get-tags) tag-changes))\r
164 -         (forward-line))))))\r
165 +    (notmuch-search-do-results beg end pos\r
166 +      (notmuch-search-set-tags\r
167 +       (notmuch-update-tags (notmuch-search-get-tags pos) tag-changes)\r
168 +       pos))))\r
169  \r
170  (defun notmuch-search-tag (&optional tag-changes)\r
171    "Change tags for the currently selected thread or region.\r
172 -- \r
173 1.7.10\r
174 \r