Re: Applying patches directly from emails?
[notmuch-archives.git] / 8d / 77d53825e6443efab9686a28456796385578a9
1 Return-Path: <markwalters1009@gmail.com>\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 123DE431FC3\r
6         for <notmuch@notmuchmail.org>; Tue, 22 Apr 2014 13:12:12 -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.201\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=0.201 tagged_above=-999 required=5\r
12         tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1,\r
13         FREEMAIL_ENVFROM_END_DIGIT=1, FREEMAIL_FROM=0.001,\r
14         RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled\r
15 Received: from olra.theworths.org ([127.0.0.1])\r
16         by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
17         with ESMTP id m6vSpttSWi+4 for <notmuch@notmuchmail.org>;\r
18         Tue, 22 Apr 2014 13:12:08 -0700 (PDT)\r
19 Received: from mail-wi0-f173.google.com (mail-wi0-f173.google.com\r
20         [209.85.212.173]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
21         (No client certificate requested)\r
22         by olra.theworths.org (Postfix) with ESMTPS id 4AA13431FBF\r
23         for <notmuch@notmuchmail.org>; Tue, 22 Apr 2014 13:12:08 -0700 (PDT)\r
24 Received: by mail-wi0-f173.google.com with SMTP id z2so3903824wiv.0\r
25         for <notmuch@notmuchmail.org>; Tue, 22 Apr 2014 13:12:05 -0700 (PDT)\r
26 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113;\r
27         h=from:to:cc:subject:date:message-id:in-reply-to:references;\r
28         bh=weUmrjQ6ICY+xSyHDhBDPP4hsICP4Gq9OTL/Kk5Cp10=;\r
29         b=zUFs1qnHTlzm3cUP9jyOeutQT2ySmu6ngPEy5UTorE571O+LaLJ3lYhkSt5jFVBV6p\r
30         R8awIPrUxi9qWSJaDP3t+7dB9Lnx1n1hmaAKkChV0We6aiESqCFpPzG4NuHzwzNnm61S\r
31         +uKdvsK5fzSnpua2WzOGW8/Tb7ji9EkE9qeabDls+jpxyEj06vFTs2JhNuxLmawFZK1S\r
32         Wo9fMBOssGn9WkZ1VLZqclcJ38Z0kNoUCp5rkG+AMRvSx1t3jWwEjcuVg8vccnZgc4gA\r
33         IbNO7mHLu9OzVjJMO7+HR83pYJCnN/wpz/kcZXTGtYRzTwdZTJYBEP16F2dzXS1S9bm5\r
34         eYbQ==\r
35 X-Received: by 10.180.149.143 with SMTP id ua15mr5304wib.36.1398197525869;\r
36         Tue, 22 Apr 2014 13:12:05 -0700 (PDT)\r
37 Received: from localhost (5751dfa2.skybroadband.com. [87.81.223.162])\r
38         by mx.google.com with ESMTPSA id\r
39         by1sm63298495wjc.26.2014.04.22.13.12.05 for <multiple recipients>\r
40         (version=TLSv1.2 cipher=RC4-SHA bits=128/128);\r
41         Tue, 22 Apr 2014 13:12:05 -0700 (PDT)\r
42 From: Mark Walters <markwalters1009@gmail.com>\r
43 To: notmuch@notmuchmail.org\r
44 Subject: [WIP PATCH 1/4] emacs: search: tidy notmuch-search-foreach-result\r
45 Date: Tue, 22 Apr 2014 21:11:47 +0100\r
46 Message-Id: <1398197510-28224-2-git-send-email-markwalters1009@gmail.com>\r
47 X-Mailer: git-send-email 1.7.10.4\r
48 In-Reply-To: <1398197510-28224-1-git-send-email-markwalters1009@gmail.com>\r
49 References: <1398197510-28224-1-git-send-email-markwalters1009@gmail.com>\r
50 X-BeenThere: notmuch@notmuchmail.org\r
51 X-Mailman-Version: 2.1.13\r
52 Precedence: list\r
53 List-Id: "Use and development of the notmuch mail system."\r
54         <notmuch.notmuchmail.org>\r
55 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
56         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
57 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
58 List-Post: <mailto:notmuch@notmuchmail.org>\r
59 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
60 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
61         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
62 X-List-Received-Date: Tue, 22 Apr 2014 20:12:12 -0000\r
63 \r
64 notmuch-search-foreach-result is cumbersome as it applies the callback\r
65 function with the position of the start of the thread as the\r
66 argument. It is more natural to move point to the start of each\r
67 relevant thread and not pass any arguments to the callback function.\r
68 ---\r
69  emacs/notmuch.el |   52 ++++++++++++++++++++++++----------------------------\r
70  1 file changed, 24 insertions(+), 28 deletions(-)\r
71 \r
72 diff --git a/emacs/notmuch.el b/emacs/notmuch.el\r
73 index 6c0bc1b..cb7c006 100644\r
74 --- a/emacs/notmuch.el\r
75 +++ b/emacs/notmuch.el\r
76 @@ -378,27 +378,24 @@ (defun notmuch-search-result-end (&optional pos)\r
77  (defun notmuch-search-foreach-result (beg end function)\r
78    "Invoke FUNCTION for each result between BEG and END.\r
79  \r
80 -FUNCTION should take one argument.  It will be applied to the\r
81 -character position of the beginning of each result that overlaps\r
82 -the region between points BEG and END.  As a special case, if (=\r
83 -BEG END), FUNCTION will be applied to the result containing point\r
84 -BEG."\r
85 -\r
86 -  (lexical-let ((pos (notmuch-search-result-beginning beg))\r
87 -               ;; End must be a marker in case function changes the\r
88 -               ;; text.\r
89 -               (end (copy-marker end))\r
90 -               ;; Make sure we examine at least one result, even if\r
91 -               ;; (= beg end).\r
92 -               (first t))\r
93 -    ;; We have to be careful if the region extends beyond the results.\r
94 -    ;; In this case, pos could be null or there could be no result at\r
95 -    ;; pos.\r
96 -    (while (and pos (or (< pos end) first))\r
97 -      (when (notmuch-search-get-result pos)\r
98 -       (funcall function pos))\r
99 -      (setq pos (notmuch-search-result-end pos)\r
100 -           first nil))))\r
101 +FUNCTION should take no arguments.  It will be applied at the\r
102 +beginning of each result that overlaps the region between points\r
103 +BEG and END.  As a special case, if (= BEG END), FUNCTION will be\r
104 +applied to the result containing point BEG."\r
105 +\r
106 +  (when (notmuch-search-get-result)\r
107 +    (save-excursion\r
108 +      ;; End must be a marker in case function changes the text.\r
109 +      (lexical-let ((end (copy-marker end)))\r
110 +       ;; We always apply function at least once: even if (= BEG END).\r
111 +       (goto-char (notmuch-search-result-beginning beg))\r
112 +       (funcall function)\r
113 +       (notmuch-search-next-thread)\r
114 +       (while (and (notmuch-search-get-result)\r
115 +                   (< (notmuch-search-result-beginning) end))\r
116 +         (funcall function)\r
117 +         (notmuch-search-next-thread))))))\r
118 +\r
119  ;; Unindent the function argument of notmuch-search-foreach-result so\r
120  ;; the indentation of callers doesn't get out of hand.\r
121  (put 'notmuch-search-foreach-result 'lisp-indent-function 2)\r
122 @@ -406,8 +403,8 @@ (defun notmuch-search-foreach-result (beg end function)\r
123  (defun notmuch-search-properties-in-region (property beg end)\r
124    (let (output)\r
125      (notmuch-search-foreach-result beg end\r
126 -      (lambda (pos)\r
127 -       (push (plist-get (notmuch-search-get-result pos) property) output)))\r
128 +      (lambda ()\r
129 +       (push (plist-get (notmuch-search-get-result) property) output)))\r
130      output))\r
131  \r
132  (defun notmuch-search-find-thread-id (&optional bare)\r
133 @@ -503,8 +500,8 @@ (defun notmuch-search-get-tags (&optional pos)\r
134  (defun notmuch-search-get-tags-region (beg end)\r
135    (let (output)\r
136      (notmuch-search-foreach-result beg end\r
137 -      (lambda (pos)\r
138 -       (setq output (append output (notmuch-search-get-tags pos)))))\r
139 +      (lambda ()\r
140 +       (setq output (append output (notmuch-search-get-tags)))))\r
141      output))\r
142  \r
143  (defun notmuch-search-interactive-region ()\r
144 @@ -543,10 +540,9 @@ (defun notmuch-search-tag (tag-changes &optional beg end only-matched)\r
145                         beg end only-matched)))\r
146      (notmuch-tag search-string tag-changes)\r
147      (notmuch-search-foreach-result beg end\r
148 -      (lambda (pos)\r
149 +      (lambda ()\r
150         (notmuch-search-set-tags\r
151 -        (notmuch-update-tags (notmuch-search-get-tags pos) tag-changes)\r
152 -        pos)))))\r
153 +        (notmuch-update-tags (notmuch-search-get-tags) tag-changes))))))\r
154  \r
155  (defun notmuch-search-add-tag (tag-changes &optional beg end)\r
156    "Change tags for the current thread or region (defaulting to add).\r
157 -- \r
158 1.7.10.4\r
159 \r