Re: [PATCH] emacs: wash: make word-wrap bound message width
[notmuch-archives.git] / 5c / d09f7b6635b458b06deda5f8011a113a0285c6
1 Return-Path: <dme@dme.org>\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 9BC5040DEFD\r
6         for <notmuch@notmuchmail.org>; Wed, 17 Nov 2010 04:08:00 -0800 (PST)\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
8 X-Spam-Flag: NO\r
9 X-Spam-Score: -1.9\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=-1.9 tagged_above=-999 required=5\r
12         tests=[BAYES_00=-1.9, RCVD_IN_DNSWL_NONE=-0.0001] autolearn=ham\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 mLNoX7I1QfQL for <notmuch@notmuchmail.org>;\r
16         Wed, 17 Nov 2010 04:07:49 -0800 (PST)\r
17 Received: from mail-ey0-f181.google.com (mail-ey0-f181.google.com\r
18         [209.85.215.181])\r
19         by olra.theworths.org (Postfix) with ESMTP id A6C5E40DEED\r
20         for <notmuch@notmuchmail.org>; Wed, 17 Nov 2010 04:07:48 -0800 (PST)\r
21 Received: by eyb6 with SMTP id 6so1122558eyb.26\r
22         for <notmuch@notmuchmail.org>; Wed, 17 Nov 2010 04:07:45 -0800 (PST)\r
23 Received: by 10.216.171.19 with SMTP id q19mr1487028wel.53.1289995664740;\r
24         Wed, 17 Nov 2010 04:07:44 -0800 (PST)\r
25 Received: from ut.hh.sledj.net (host81-149-164-25.in-addr.btopenworld.com\r
26         [81.149.164.25])\r
27         by mx.google.com with ESMTPS id y15sm1102938weq.30.2010.11.17.04.07.42\r
28         (version=TLSv1/SSLv3 cipher=RC4-MD5);\r
29         Wed, 17 Nov 2010 04:07:43 -0800 (PST)\r
30 Received: by ut.hh.sledj.net (Postfix, from userid 1000)\r
31         id 8CF32594058; Wed, 17 Nov 2010 12:05:06 +0000 (GMT)\r
32 From: David Edmondson <dme@dme.org>\r
33 To: notmuch@notmuchmail.org\r
34 Subject: [PATCH] emacs: Improve the display of truncated authors.\r
35 Date: Wed, 17 Nov 2010 12:05:04 +0000\r
36 Message-Id: <1289995504-13010-1-git-send-email-dme@dme.org>\r
37 X-Mailer: git-send-email 1.7.2.3\r
38 X-BeenThere: notmuch@notmuchmail.org\r
39 X-Mailman-Version: 2.1.13\r
40 Precedence: list\r
41 List-Id: "Use and development of the notmuch mail system."\r
42         <notmuch.notmuchmail.org>\r
43 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
44         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
45 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
46 List-Post: <mailto:notmuch@notmuchmail.org>\r
47 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
48 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
49         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
50 X-List-Received-Date: Wed, 17 Nov 2010 12:08:00 -0000\r
51 \r
52 Incremental search does not match strings that span a\r
53 visible/invisible boundary. This results in failure to correctly\r
54 isearch for authors in `notmuch-search' mode if the name of the author\r
55 is split between the visible and invisible components of the authors\r
56 string. To avoid this, attempt to truncate the visible component of\r
57 the authors string on a boundary between authors, such that the\r
58 entirety of an author's name is either visible or invisible.\r
59 ---\r
60  emacs/notmuch.el                                   |  122 +++++++++++++-------\r
61  .../emacs.expected-output/notmuch-hello-view-inbox |   28 +++---\r
62  .../emacs.expected-output/notmuch-search-tag-inbox |   28 +++---\r
63  3 files changed, 108 insertions(+), 70 deletions(-)\r
64 \r
65 diff --git a/emacs/notmuch.el b/emacs/notmuch.el\r
66 index 5933747..3d82f0d 100644\r
67 --- a/emacs/notmuch.el\r
68 +++ b/emacs/notmuch.el\r
69 @@ -629,49 +629,87 @@ foreground and blue background."\r
70  (defun notmuch-search-isearch-authors-show (overlay)\r
71    (remove-from-invisibility-spec (cons (overlay-get overlay 'invisible) t)))\r
72  \r
73 +(defun notmuch-search-author-propertize (authors)\r
74 +  "Split `authors' into matching and non-matching authors and\r
75 +propertize appropriately. If no boundary between authors and\r
76 +non-authors is found, assume that all of the authors match."\r
77 +  (if (string-match "\\(.*\\)|\\(.*\\)" authors)\r
78 +      (concat (propertize (concat (match-string 1 authors) ",")\r
79 +                         'face 'notmuch-search-matching-authors)\r
80 +             (propertize (match-string 2 authors)\r
81 +                         'face 'notmuch-search-non-matching-authors))\r
82 +    (propertize authors 'face 'notmuch-search-matching-authors)))\r
83 +\r
84  (defun notmuch-search-insert-authors (format-string authors)\r
85 -  (let* ((propertized-authors\r
86 -         ;; Need to save the match data to avoid interfering with\r
87 -         ;; `notmuch-search-process-filter'.\r
88 -         (save-match-data\r
89 -           ;; Authors that don't match the search query are shown in a\r
90 -           ;; different font.\r
91 -           (if (string-match "\\(.*\\)|\\(..*\\)" authors)\r
92 -               (concat (propertize (concat (match-string 1 authors) ",")\r
93 -                                   'face 'notmuch-search-matching-authors)\r
94 -                       (propertize (match-string 2 authors)\r
95 -                                   'face 'notmuch-search-non-matching-authors))\r
96 -             (propertize authors 'face 'notmuch-search-matching-authors))))\r
97 -\r
98 -        (formatted-sample (format format-string ""))\r
99 -        (formatted-authors (format format-string propertized-authors))\r
100 -        visible-string invisible-string)\r
101 -\r
102 -    ;; Determine the part of the authors that will be visible by\r
103 -    ;; default.\r
104 -    (if (> (length formatted-authors)\r
105 -          (length formatted-sample))\r
106 -       ;; 4 is `(length "... ")'.\r
107 -       (let ((visible-length (- (length formatted-sample) 4)))\r
108 -         (setq visible-string (substring propertized-authors 0 visible-length)\r
109 -               invisible-string (substring propertized-authors visible-length)))\r
110 -      (setq visible-string formatted-authors\r
111 -           invisible-string nil))\r
112 -\r
113 -    ;; Insert both the visible and invisible author strings.\r
114 -    (insert visible-string)\r
115 -    (when invisible-string\r
116 -      (let ((start (point))\r
117 -           (invis-spec (make-symbol "notmuch-search-authors"))\r
118 -           overlay)\r
119 -       (insert invisible-string)\r
120 -       ;; Using a cons-cell here causes an ellipsis to be inserted\r
121 -       ;; instead of the invisible text.\r
122 -       (add-to-invisibility-spec (cons invis-spec t))\r
123 -       (setq overlay (make-overlay start (point)))\r
124 -       (overlay-put overlay 'invisible invis-spec)\r
125 -       (overlay-put overlay 'isearch-open-invisible #'notmuch-search-isearch-authors-show)\r
126 -       (insert " ")))))\r
127 +  ;; Save the match data to avoid interfering with\r
128 +  ;; `notmuch-search-process-filter'.\r
129 +  (save-match-data\r
130 +    (let* ((formatted-authors (format format-string authors))\r
131 +          (formatted-sample (format format-string ""))\r
132 +          (visible-string formatted-authors)\r
133 +          (invisible-string "")\r
134 +          (padding ""))\r
135 +\r
136 +      ;; Truncate the author string to fit the specification.\r
137 +      (if (> (length formatted-authors)\r
138 +            (length formatted-sample))\r
139 +         (let ((visible-length (- (length formatted-sample)\r
140 +                                  (length "... "))))\r
141 +           ;; Truncate the visible string according to the width of\r
142 +           ;; the display string.\r
143 +           (setq visible-string (substring formatted-authors 0 visible-length)\r
144 +                 invisible-string (substring formatted-authors visible-length))\r
145 +           ;; If possible, truncate the visible string at a natural\r
146 +           ;; break (comma or pipe), as incremental search doesn't\r
147 +           ;; match across the visible/invisible border.\r
148 +           (when (string-match "\\(.*\\)\\([,|] \\)\\([^,|]*\\)" visible-string)\r
149 +             ;; Second clause is destructive on `visible-string', so\r
150 +             ;; order is important.\r
151 +             (setq invisible-string (concat (match-string 3 visible-string)\r
152 +                                            invisible-string)\r
153 +                   visible-string (concat (match-string 1 visible-string)\r
154 +                                          (match-string 2 visible-string))))\r
155 +           ;; `visible-string' may be shorter than the space allowed\r
156 +           ;; by `format-string'. If so we must insert some padding\r
157 +           ;; after `invisible-string'.\r
158 +           (setq padding (make-string (- (length formatted-sample)\r
159 +                                         (length visible-string)\r
160 +                                         (length "..."))\r
161 +                                      ? ))))\r
162 +\r
163 +      ;; Use different faces to show matching and non-matching authors.\r
164 +      (if (string-match "\\(.*\\)|\\(.*\\)" visible-string)\r
165 +         ;; The visible string contains both matching and\r
166 +         ;; non-matching authors.\r
167 +         (setq visible-string (notmuch-search-author-propertize visible-string)\r
168 +               ;; The invisible string must contain only non-matching\r
169 +               ;; authors, as the visible-string contains both.\r
170 +               invisible-string (propertize invisible-string\r
171 +                                            'face 'notmuch-search-non-matching-authors))\r
172 +       ;; The visible string contains only matching authors.\r
173 +       (setq visible-string (propertize visible-string\r
174 +                                        'face 'notmuch-search-matching-authors)\r
175 +             ;; The invisible string may contain both matching and\r
176 +             ;; non-matching authors.\r
177 +             invisible-string (notmuch-search-author-propertize invisible-string)))\r
178 +\r
179 +      ;; If there is any invisible text, add it as a tooltip to the\r
180 +      ;; visible text.\r
181 +      (when (not (string= invisible-string ""))\r
182 +       (setq visible-string (propertize visible-string 'help-echo (concat "..." invisible-string))))\r
183 +\r
184 +      ;; Insert the visible and, if present, invisible author strings.\r
185 +      (insert visible-string)\r
186 +      (when (not (string= invisible-string ""))\r
187 +       (let ((start (point))\r
188 +             (invis-spec (make-symbol "notmuch-search-authors"))\r
189 +             overlay)\r
190 +         (insert invisible-string)\r
191 +         (add-to-invisibility-spec (cons invis-spec t))\r
192 +         (setq overlay (make-overlay start (point)))\r
193 +         (overlay-put overlay 'invisible invis-spec)\r
194 +         (overlay-put overlay 'isearch-open-invisible #'notmuch-search-isearch-authors-show)))\r
195 +      (insert padding))))\r
196  \r
197  (defun notmuch-search-insert-field (field date count authors subject tags)\r
198    (cond\r
199 diff --git a/test/emacs.expected-output/notmuch-hello-view-inbox b/test/emacs.expected-output/notmuch-hello-view-inbox\r
200 index 3ba2b29..924f7ef 100644\r
201 --- a/test/emacs.expected-output/notmuch-hello-view-inbox\r
202 +++ b/test/emacs.expected-output/notmuch-hello-view-inbox\r
203 @@ -1,23 +1,23 @@\r
204 -  2009-11-17 [5/5]   Carl Worth, Keith Packard, Mikhail Gusarov [notmuch] [PATCH 1/2] Close message file after parsing message headers (inbox unread)\r
205 -  2009-11-17 [7/7]   Carl Worth, Lars Kellogg-Stedman, Keith Packard, Mikhail Gusarov [notmuch] Working with Maildir storage? (inbox unread)\r
206 -  2009-11-17 [2/2]   Carl Worth, Alex Botero-Lowry [notmuch] preliminary FreeBSD support (attachment inbox unread)\r
207 +  2009-11-17 [5/5]   Carl Worth, Keith Packard, Mikhail Gusarov       [notmuch] [PATCH 1/2] Close message file after parsing message headers (inbox unread)\r
208 +  2009-11-17 [7/7]   Carl Worth, Lars Kellogg-Stedman, Keith Packard, Mikhail Gusarov       [notmuch] Working with Maildir storage? (inbox unread)\r
209 +  2009-11-17 [2/2]   Carl Worth, Alex Botero-Lowry       [notmuch] preliminary FreeBSD support (attachment inbox unread)\r
210    2009-11-17 [1/1]   Mikhail Gusarov      [notmuch] [PATCH] Handle rename of message file (inbox unread)\r
211 -  2009-11-17 [2/2]   Carl Worth, Keith Packard [notmuch] [PATCH] Make notmuch-show 'X' (and 'x') commands remove inbox (and unread) tags (inbox unread)\r
212 -  2009-11-17 [2/2]   Carl Worth, Jan Janak [notmuch] [PATCH] Older versions of install do not support -C. (inbox unread)\r
213 -  2009-11-17 [3/3]   Carl Worth, Jan Janak [notmuch] What a great idea! (inbox unread)\r
214 -  2009-11-17 [3/3]   Carl Worth, Keith Packard, Israel Herraiz [notmuch] New to the list (inbox unread)\r
215 -  2009-11-17 [3/3]   Carl Worth, Keith Packard, Adrian Perez de Castro [notmuch] Introducing myself (inbox unread)\r
216 -  2009-11-17 [3/3]   Carl Worth, Keith Packard, Aron Griffis [notmuch] archive (inbox unread)\r
217 -  2009-11-17 [2/2]   Carl Worth, Ingmar Vanhassel [notmuch] [PATCH] Typsos (inbox unread)\r
218 -  2009-11-18 [2/2]   Carl Worth, Alex Botero-Lowry [notmuch] [PATCH] Error out if no query is supplied to search instead of going into an infinite loop (attachment inbox unread)\r
219 +  2009-11-17 [2/2]   Carl Worth, Keith Packard       [notmuch] [PATCH] Make notmuch-show 'X' (and 'x') commands remove inbox (and unread) tags (inbox unread)\r
220 +  2009-11-17 [2/2]   Carl Worth, Jan Janak       [notmuch] [PATCH] Older versions of install do not support -C. (inbox unread)\r
221 +  2009-11-17 [3/3]   Carl Worth, Jan Janak       [notmuch] What a great idea! (inbox unread)\r
222 +  2009-11-17 [3/3]   Carl Worth, Keith Packard, Israel Herraiz       [notmuch] New to the list (inbox unread)\r
223 +  2009-11-17 [3/3]   Carl Worth, Keith Packard, Adrian Perez de Castro       [notmuch] Introducing myself (inbox unread)\r
224 +  2009-11-17 [3/3]   Carl Worth, Keith Packard, Aron Griffis       [notmuch] archive (inbox unread)\r
225 +  2009-11-17 [2/2]   Carl Worth, Ingmar Vanhassel       [notmuch] [PATCH] Typsos (inbox unread)\r
226 +  2009-11-18 [2/2]   Carl Worth, Alex Botero-Lowry       [notmuch] [PATCH] Error out if no query is supplied to search instead of going into an infinite loop (attachment inbox unread)\r
227    2009-11-18 [2/2]   Lars Kellogg-Stedman [notmuch] "notmuch help" outputs to stderr? (attachment inbox unread)\r
228    2009-11-18 [1/1]   Stewart Smith        [notmuch] [PATCH] Fix linking with gcc to use g++ to link in C++ libs. (inbox unread)\r
229    2009-11-18 [1/1]   Stewart Smith        [notmuch] [PATCH 2/2] Read mail directory in inode number order (inbox unread)\r
230    2009-11-18 [1/1]   Stewart Smith        [notmuch] [PATCH] count_files: sort directory in inode order before statting (inbox unread)\r
231 -  2009-11-18 [4/4]   Alexander Botero-Lowry, Jjgod Jiang [notmuch] Mac OS X/Darwin compatibility issues (inbox unread)\r
232 +  2009-11-18 [4/4]   Alexander Botero-Lowry, Jjgod Jiang  [notmuch] Mac OS X/Darwin compatibility issues (inbox unread)\r
233    2009-11-18 [1/1]   Jan Janak            [notmuch] [PATCH] notmuch new: Support for conversion of spool subdirectories into tags (inbox unread)\r
234    2009-11-18 [1/1]   Rolland Santimano    [notmuch] Link to mailing list archives ? (inbox unread)\r
235 -  2009-11-18 [1/1]   Alexander Botero-Lowry [notmuch] request for pull (inbox unread)\r
236 -  2009-11-18 [2/2]   Alexander Botero-Lowry, Keith Packard [notmuch] [PATCH] Create a default notmuch-show-hook that highlights URLs and uses word-wrap (inbox unread)\r
237 +  2009-11-18 [1/1]   Alexander Botero-Lowry  [notmuch] request for pull (inbox unread)\r
238 +  2009-11-18 [2/2]   Alexander Botero-Lowry, Keith Packard  [notmuch] [PATCH] Create a default notmuch-show-hook that highlights URLs and uses word-wrap (inbox unread)\r
239    2009-11-18 [1/1]   Chris Wilson         [notmuch] [PATCH 1/2] Makefile: evaluate pkg-config once (inbox unread)\r
240  End of search results.\r
241 diff --git a/test/emacs.expected-output/notmuch-search-tag-inbox b/test/emacs.expected-output/notmuch-search-tag-inbox\r
242 index 146f63a..15a0d2b 100644\r
243 --- a/test/emacs.expected-output/notmuch-search-tag-inbox\r
244 +++ b/test/emacs.expected-output/notmuch-search-tag-inbox\r
245 @@ -1,17 +1,17 @@\r
246    2009-11-18 [1/1]   Chris Wilson         [notmuch] [PATCH 1/2] Makefile: evaluate pkg-config once (inbox unread)\r
247 -  2009-11-18 [2/2]   Carl Worth, Alex Botero-Lowry [notmuch] [PATCH] Error out if no query is supplied to search instead of going into an infinite loop (attachment inbox unread)\r
248 -  2009-11-18 [2/2]   Carl Worth, Ingmar Vanhassel [notmuch] [PATCH] Typsos (inbox unread)\r
249 -  2009-11-18 [3/3]   Carl Worth, Keith Packard, Adrian Perez de Castro [notmuch] Introducing myself (inbox unread)\r
250 -  2009-11-18 [3/3]   Carl Worth, Keith Packard, Israel Herraiz [notmuch] New to the list (inbox unread)\r
251 -  2009-11-18 [3/3]   Carl Worth, Jan Janak [notmuch] What a great idea! (inbox unread)\r
252 -  2009-11-18 [2/2]   Carl Worth, Jan Janak [notmuch] [PATCH] Older versions of install do not support -C. (inbox unread)\r
253 -  2009-11-18 [3/3]   Carl Worth, Keith Packard, Aron Griffis [notmuch] archive (inbox unread)\r
254 -  2009-11-18 [2/2]   Carl Worth, Keith Packard [notmuch] [PATCH] Make notmuch-show 'X' (and 'x') commands remove inbox (and unread) tags (inbox unread)\r
255 -  2009-11-18 [7/7]   Carl Worth, Lars Kellogg-Stedman, Keith Packard, Mikhail Gusarov [notmuch] Working with Maildir storage? (inbox unread)\r
256 -  2009-11-18 [5/5]   Carl Worth, Keith Packard, Mikhail Gusarov [notmuch] [PATCH 1/2] Close message file after parsing message headers (inbox unread)\r
257 -  2009-11-18 [2/2]   Alexander Botero-Lowry, Keith Packard [notmuch] [PATCH] Create a default notmuch-show-hook that highlights URLs and uses word-wrap (inbox unread)\r
258 -  2009-11-18 [1/1]   Alexander Botero-Lowry [notmuch] request for pull (inbox unread)\r
259 -  2009-11-18 [4/4]   Alexander Botero-Lowry, Jjgod Jiang [notmuch] Mac OS X/Darwin compatibility issues (inbox unread)\r
260 +  2009-11-18 [2/2]   Carl Worth, Alex Botero-Lowry       [notmuch] [PATCH] Error out if no query is supplied to search instead of going into an infinite loop (attachment inbox unread)\r
261 +  2009-11-18 [2/2]   Carl Worth, Ingmar Vanhassel       [notmuch] [PATCH] Typsos (inbox unread)\r
262 +  2009-11-18 [3/3]   Carl Worth, Keith Packard, Adrian Perez de Castro       [notmuch] Introducing myself (inbox unread)\r
263 +  2009-11-18 [3/3]   Carl Worth, Keith Packard, Israel Herraiz       [notmuch] New to the list (inbox unread)\r
264 +  2009-11-18 [3/3]   Carl Worth, Jan Janak       [notmuch] What a great idea! (inbox unread)\r
265 +  2009-11-18 [2/2]   Carl Worth, Jan Janak       [notmuch] [PATCH] Older versions of install do not support -C. (inbox unread)\r
266 +  2009-11-18 [3/3]   Carl Worth, Keith Packard, Aron Griffis       [notmuch] archive (inbox unread)\r
267 +  2009-11-18 [2/2]   Carl Worth, Keith Packard       [notmuch] [PATCH] Make notmuch-show 'X' (and 'x') commands remove inbox (and unread) tags (inbox unread)\r
268 +  2009-11-18 [7/7]   Carl Worth, Lars Kellogg-Stedman, Keith Packard, Mikhail Gusarov       [notmuch] Working with Maildir storage? (inbox unread)\r
269 +  2009-11-18 [5/5]   Carl Worth, Keith Packard, Mikhail Gusarov       [notmuch] [PATCH 1/2] Close message file after parsing message headers (inbox unread)\r
270 +  2009-11-18 [2/2]   Alexander Botero-Lowry, Keith Packard  [notmuch] [PATCH] Create a default notmuch-show-hook that highlights URLs and uses word-wrap (inbox unread)\r
271 +  2009-11-18 [1/1]   Alexander Botero-Lowry  [notmuch] request for pull (inbox unread)\r
272 +  2009-11-18 [4/4]   Alexander Botero-Lowry, Jjgod Jiang  [notmuch] Mac OS X/Darwin compatibility issues (inbox unread)\r
273    2009-11-18 [1/1]   Rolland Santimano    [notmuch] Link to mailing list archives ? (inbox unread)\r
274    2009-11-18 [1/1]   Jan Janak            [notmuch] [PATCH] notmuch new: Support for conversion of spool subdirectories into tags (inbox unread)\r
275    2009-11-18 [1/1]   Stewart Smith        [notmuch] [PATCH] count_files: sort directory in inode order before statting (inbox unread)\r
276 @@ -19,5 +19,5 @@\r
277    2009-11-18 [1/1]   Stewart Smith        [notmuch] [PATCH] Fix linking with gcc to use g++ to link in C++ libs. (inbox unread)\r
278    2009-11-18 [2/2]   Lars Kellogg-Stedman [notmuch] "notmuch help" outputs to stderr? (attachment inbox unread)\r
279    2009-11-17 [1/1]   Mikhail Gusarov      [notmuch] [PATCH] Handle rename of message file (inbox unread)\r
280 -  2009-11-17 [2/2]   Carl Worth, Alex Botero-Lowry [notmuch] preliminary FreeBSD support (attachment inbox unread)\r
281 +  2009-11-17 [2/2]   Carl Worth, Alex Botero-Lowry       [notmuch] preliminary FreeBSD support (attachment inbox unread)\r
282  End of search results.\r
283 -- \r
284 1.7.2.3\r
285 \r