Re: [PATCH] emacs: wash: make word-wrap bound message width
[notmuch-archives.git] / dc / c14fd544e3780239acaa58f6955c2cbe74a7b6
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 55961431FD6\r
6         for <notmuch@notmuchmail.org>; Sat, 21 Jul 2012 10:37:23 -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 SJekj+QhNwDA for <notmuch@notmuchmail.org>;\r
16         Sat, 21 Jul 2012 10:37:21 -0700 (PDT)\r
17 Received: from dmz-mailsec-scanner-7.mit.edu (DMZ-MAILSEC-SCANNER-7.MIT.EDU\r
18         [18.7.68.36])\r
19         by olra.theworths.org (Postfix) with ESMTP id 2D468431FC3\r
20         for <notmuch@notmuchmail.org>; Sat, 21 Jul 2012 10:37:20 -0700 (PDT)\r
21 X-AuditID: 12074424-b7f2a6d0000008bf-77-500ae8ce4d48\r
22 Received: from mailhub-auth-1.mit.edu ( [18.9.21.35])\r
23         by dmz-mailsec-scanner-7.mit.edu (Symantec Messaging Gateway) with SMTP\r
24         id 46.3D.02239.EC8EA005; Sat, 21 Jul 2012 13:37:18 -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 q6LHbHDJ029419; \r
27         Sat, 21 Jul 2012 13:37:17 -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 q6LHbFrj008015\r
33         (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT);\r
34         Sat, 21 Jul 2012 13:37:16 -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 1SsdcB-0001Zi-9y; Sat, 21 Jul 2012 13:37:15 -0400\r
38 From: Austin Clements <amdragon@MIT.EDU>\r
39 To: notmuch@notmuchmail.org\r
40 Subject: [PATCH v4 3/8] emacs: Update tags by rewriting the search result line\r
41         in place\r
42 Date: Sat, 21 Jul 2012 13:37:07 -0400\r
43 Message-Id: <1342892232-5659-4-git-send-email-amdragon@mit.edu>\r
44 X-Mailer: git-send-email 1.7.10\r
45 In-Reply-To: <1342892232-5659-1-git-send-email-amdragon@mit.edu>\r
46 References: <1341354059-29396-1-git-send-email-amdragon@mit.edu>\r
47         <1342892232-5659-1-git-send-email-amdragon@mit.edu>\r
48 X-Brightmail-Tracker:\r
49  H4sIAAAAAAAAA+NgFjrKIsWRmVeSWpSXmKPExsUixCmqrHvuBVeAwYevkhZ79nlZrJ7LY3H9\r
50         5kxmB2aPu6e5PHbOusvu8WzVLeYA5igum5TUnMyy1CJ9uwSujLsd/9gLnspVrP/0j7WB8bJE\r
51         FyMnh4SAicS0l4uZIWwxiQv31rN1MXJxCAnsY5SYvWEGM4SzgVHi+KvzUJlHTBLTWjeyQjhz\r
52         GSWab7exg/SzCWhIbNu/nBHEFhGQlth5dzYriM0skCbxvf0tWFxYIFyi5+cqsHoWAVWJ+08n\r
53         soHYvAL2EltP9rND3CEv8fR+H1icU8BB4tHZAywgtpBAmcTijsOMExj5FzAyrGKUTcmt0s1N\r
54         zMwpTk3WLU5OzMtLLdI118vNLNFLTSndxAgKLXYXlR2MzYeUDjEKcDAq8fBaKnEFCLEmlhVX\r
55         5h5ilORgUhLl7bsPFOJLyk+pzEgszogvKs1JLT7EKMHBrCTCu+k0UI43JbGyKrUoHyYlzcGi\r
56         JM57PeWmv5BAemJJanZqakFqEUxWhoNDSYLXHRhDQoJFqempFWmZOSUIaSYOTpDhPEDDg0Fq\r
57         eIsLEnOLM9Mh8qcYFaXEee1AEgIgiYzSPLheWOy/YhQHekWY1wCkigeYNuC6XwENZgIaLJ0F\r
58         NrgkESEl1cCY+NTjXeZl7zf5Hds8DuSJnE9uMVYOmRAflMxqb8/l9m9+23yRddvXXfefsPLd\r
59         XM0LstePVpbcThG5bWtx7IFE5h6jSxy/WLc1vFG/d1RGo+fPMu+JvDyyop/b/rht+MPMc3bH\r
60         naSIT7mbpXq+hRlPnvXFul3D9e4DHq1ln2YG/DLewltpadmoxFKckWioxVxUnAgAGKRjldgC        AAA=\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, 21 Jul 2012 17:37:23 -0000\r
74 \r
75 Now that we keep the full thread result object, we can refresh a\r
76 result after any changes by simply deleting and reconstructing the\r
77 result line from scratch.\r
78 \r
79 A convenient side-effect of this wholesale replacement is that search\r
80 now re-applies notmuch-search-line-faces when tags change.\r
81 ---\r
82  emacs/notmuch.el |   61 +++++++++++++++++++++++++++++++++---------------------\r
83  1 file changed, 37 insertions(+), 24 deletions(-)\r
84 \r
85 diff --git a/emacs/notmuch.el b/emacs/notmuch.el\r
86 index 82c148d..6995482 100644\r
87 --- a/emacs/notmuch.el\r
88 +++ b/emacs/notmuch.el\r
89 @@ -509,28 +509,12 @@ and will also appear in a buffer named \"*Notmuch errors*\"."\r
90             (error (buffer-substring beg end))\r
91             ))))))\r
92  \r
93 -(defun notmuch-search-set-tags (tags)\r
94 -  (save-excursion\r
95 -    (end-of-line)\r
96 -    (re-search-backward "(")\r
97 -    (forward-char)\r
98 -    (let ((beg (point))\r
99 -         (inhibit-read-only t))\r
100 -      (re-search-forward ")")\r
101 -      (backward-char)\r
102 -      (let ((end (point)))\r
103 -       (delete-region beg end)\r
104 -       (insert (propertize (mapconcat  'identity tags " ")\r
105 -                           'face 'notmuch-tag-face))))))\r
106 -\r
107 -(defun notmuch-search-get-tags ()\r
108 -  (save-excursion\r
109 -    (end-of-line)\r
110 -    (re-search-backward "(")\r
111 -    (let ((beg (+ (point) 1)))\r
112 -      (re-search-forward ")")\r
113 -      (let ((end (- (point) 1)))\r
114 -       (split-string (buffer-substring-no-properties beg end))))))\r
115 +(defun notmuch-search-set-tags (tags &optional pos)\r
116 +  (let ((new-result (plist-put (notmuch-search-get-result pos) :tags tags)))\r
117 +    (notmuch-search-update-result new-result pos)))\r
118 +\r
119 +(defun notmuch-search-get-tags (&optional pos)\r
120 +  (plist-get (notmuch-search-get-result pos) :tags))\r
121  \r
122  (defun notmuch-search-get-tags-region (beg end)\r
123    (save-excursion\r
124 @@ -583,6 +567,34 @@ This function advances the next thread when finished."\r
125    (notmuch-search-tag '("-inbox"))\r
126    (notmuch-search-next-thread))\r
127  \r
128 +(defun notmuch-search-update-result (result &optional pos)\r
129 +  "Replace the result object of the thread at POS (or point) by\r
130 +RESULT and redraw it.\r
131 +\r
132 +This will keep point in a reasonable location.  However, if there\r
133 +are enclosing save-excursions and the saved point is in the\r
134 +result being updated, the point will be restored to the beginning\r
135 +of the result."\r
136 +  (let ((start (notmuch-search-result-beginning pos))\r
137 +       (end (notmuch-search-result-end pos))\r
138 +       (init-point (point))\r
139 +       (inhibit-read-only t))\r
140 +    ;; Delete the current thread\r
141 +    (delete-region start end)\r
142 +    ;; Insert the updated thread\r
143 +    (notmuch-search-show-result result start)\r
144 +    ;; If point was inside the old result, make an educated guess\r
145 +    ;; about where to place it now.  Unfortunately, this won't work\r
146 +    ;; with save-excursion (or any other markers that would be nice to\r
147 +    ;; preserve, such as the window start), but there's nothing we can\r
148 +    ;; do about that without a way to retrieve markers in a region.\r
149 +    (when (and (>= init-point start) (<= init-point end))\r
150 +      (let* ((new-end (notmuch-search-result-end start))\r
151 +            (new-point (if (= init-point end)\r
152 +                           new-end\r
153 +                         (min init-point (- new-end 1)))))\r
154 +       (goto-char new-point)))))\r
155 +\r
156  (defun notmuch-search-process-sentinel (proc msg)\r
157    "Add a message to let user know when \"notmuch search\" exits"\r
158    (let ((buffer (process-buffer proc))\r
159 @@ -745,10 +757,11 @@ non-authors is found, assume that all of the authors match."\r
160                          (mapconcat 'identity (plist-get result :tags) " ")\r
161                          'font-lock-face 'notmuch-tag-face) ")")))))\r
162  \r
163 -(defun notmuch-search-show-result (result)\r
164 +(defun notmuch-search-show-result (result &optional pos)\r
165 +  "Insert RESULT at POS or the end of the buffer if POS is null."\r
166    ;; Ignore excluded matches\r
167    (unless (= (plist-get result :matched) 0)\r
168 -    (let ((beg (point-max)))\r
169 +    (let ((beg (or pos (point-max))))\r
170        (save-excursion\r
171         (goto-char beg)\r
172         (dolist (spec notmuch-search-result-format)\r
173 -- \r
174 1.7.10\r
175 \r