Re: [PATCH] emacs: wash: make word-wrap bound message width
[notmuch-archives.git] / 99 / b13e0dbc73767309d60e08c058abf5b38a3359
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 64350431FD8\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 i3xXvnbdH4b8 for <notmuch@notmuchmail.org>;\r
16         Sat, 21 Jul 2012 10:37:21 -0700 (PDT)\r
17 Received: from dmz-mailsec-scanner-8.mit.edu (DMZ-MAILSEC-SCANNER-8.MIT.EDU\r
18         [18.7.68.37])\r
19         by olra.theworths.org (Postfix) with ESMTP id E0DF9431FC0\r
20         for <notmuch@notmuchmail.org>; Sat, 21 Jul 2012 10:37:19 -0700 (PDT)\r
21 X-AuditID: 12074425-b7f9b6d0000008c4-d5-500ae8ceb185\r
22 Received: from mailhub-auth-3.mit.edu ( [18.9.21.43])\r
23         by dmz-mailsec-scanner-8.mit.edu (Symantec Messaging Gateway) with SMTP\r
24         id B0.FE.02244.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-3.mit.edu (8.13.8/8.9.2) with ESMTP id q6LHbHpj018462; \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 q6LHbF0g008012\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-0001Zg-8M; 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 2/8] emacs: Use text properties instead of overlays for tag\r
41         coloring\r
42 Date: Sat, 21 Jul 2012 13:37:06 -0400\r
43 Message-Id: <1342892232-5659-3-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+NgFjrCIsWRmVeSWpSXmKPExsUixCmqrXvuBVeAwc4j4hZ79nlZrJ7LY3H9\r
50         5kxmB2aPu6e5PHbOusvu8WzVLeYA5igum5TUnMyy1CJ9uwSujNkbUwpmSFes2d3N2sDYJdbF\r
51         yMkhIWAisWDSBHYIW0ziwr31bF2MXBxCAvsYJRq6pjNCOBsYJe7v3gSVecQkcfz9JKjMXEaJ\r
52         twsmMYH0swloSGzbv5wRxBYRkJbYeXc2K4jNLJAm8b39LVhcWCBcYsu0lWwgNouAqsSXhoNg\r
53         u3kF7CWm/F7BCHGHvMTT+31gNZwCDhKPzh5gAbGFBMokFnccZpzAyL+AkWEVo2xKbpVubmJm\r
54         TnFqsm5xcmJeXmqRroVebmaJXmpK6SZGUGCxu6juYJxwSOkQowAHoxIPr4USV4AQa2JZcWXu\r
55         IUZJDiYlUd6++0AhvqT8lMqMxOKM+KLSnNTiQ4wSHMxKIrybTgPleFMSK6tSi/JhUtIcLEri\r
56         vDdSbvoLCaQnlqRmp6YWpBbBZGU4OJQkePmAESQkWJSanlqRlplTgpBm4uAEGc4DNFwMpIa3\r
57         uCAxtzgzHSJ/ilFRSpz333OghABIIqM0D64XFvmvGMWBXhHmNQBp5wEmDbjuV0CDmYAGS2eB\r
58         DS5JREhJNTCKc9277lF5emtb+w7t0oiv6nKXJy19stzScsv6otryTWK2e67LZO5+bR39SUzq\r
59         YJLm4UufakN9P81bMMHItaVuZs/Tv8fbTomw76zedj9W9mNy31ExFp37xwXur75uUnN9sUDP\r
60         mi/LZx7TX/1ecys7O6virKBJmlNq/4v/jT3ypvvI/oQcv1ZTJZbijERDLeai4kQA1d+d3tcC        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 Previously, tag-based search result highlighting was done by creating\r
76 an overlay over each search result.  However, overlays have annoying\r
77 front- and rear-advancement semantics that make it difficult to\r
78 manipulate text at their boundaries, which the next patch will do.\r
79 They also have performance problems (creating an overlay is linear in\r
80 the number of overlays between point and the new overlay, making\r
81 highlighting a search buffer quadratic in the number of results).\r
82 \r
83 Text properties have neither problem.  However, text properties make\r
84 it more difficult to apply multiple faces since, unlike with overlays,\r
85 a given character can only have a single 'face text property.  Hence,\r
86 we introduce a utility function that combines faces into any existing\r
87 'face text properties.\r
88 \r
89 Using this utility function, it's straightforward to apply all of the\r
90 appropriate tag faces in notmuch-search-color-line.\r
91 ---\r
92  emacs/notmuch-lib.el |   15 +++++++++++++++\r
93  emacs/notmuch.el     |   21 +++++++--------------\r
94  2 files changed, 22 insertions(+), 14 deletions(-)\r
95 \r
96 diff --git a/emacs/notmuch-lib.el b/emacs/notmuch-lib.el\r
97 index aa25513..30db58f 100644\r
98 --- a/emacs/notmuch-lib.el\r
99 +++ b/emacs/notmuch-lib.el\r
100 @@ -269,6 +269,21 @@ current buffer, if possible."\r
101    (loop for (key value . rest) on plist by #'cddr\r
102         collect (cons (intern (substring (symbol-name key) 1)) value)))\r
103  \r
104 +(defun notmuch-combine-face-text-property (start end face)\r
105 +  "Combine FACE into the 'face text property between START and END.\r
106 +\r
107 +This function combines FACE with any existing faces between START\r
108 +and END.  Attributes specified by FACE take precedence over\r
109 +existing attributes.  FACE must be a face name (a symbol or\r
110 +string), a property list of face attributes, or a list of these."\r
111 +\r
112 +  (let ((pos start))\r
113 +    (while (< pos end)\r
114 +      (let ((cur (get-text-property pos 'face))\r
115 +           (next (next-single-property-change pos 'face nil end)))\r
116 +       (put-text-property pos next 'face (cons face cur))\r
117 +       (setq pos next)))))\r
118 +\r
119  ;; Compatibility functions for versions of emacs before emacs 23.\r
120  ;;\r
121  ;; Both functions here were copied from emacs 23 with the following copyright:\r
122 diff --git a/emacs/notmuch.el b/emacs/notmuch.el\r
123 index ef18927..82c148d 100644\r
124 --- a/emacs/notmuch.el\r
125 +++ b/emacs/notmuch.el\r
126 @@ -633,20 +633,13 @@ foreground and blue background."\r
127  \r
128  (defun notmuch-search-color-line (start end line-tag-list)\r
129    "Colorize lines in `notmuch-show' based on tags."\r
130 -  ;; Create the overlay only if the message has tags which match one\r
131 -  ;; of those specified in `notmuch-search-line-faces'.\r
132 -  (let (overlay)\r
133 -    (mapc (lambda (elem)\r
134 -           (let ((tag (car elem))\r
135 -                 (attributes (cdr elem)))\r
136 -             (when (member tag line-tag-list)\r
137 -               (when (not overlay)\r
138 -                 (setq overlay (make-overlay start end)))\r
139 -               ;; Merge the specified properties with any already\r
140 -               ;; applied from an earlier match.\r
141 -               (overlay-put overlay 'face\r
142 -                            (append (overlay-get overlay 'face) attributes)))))\r
143 -         notmuch-search-line-faces)))\r
144 +  (mapc (lambda (elem)\r
145 +         (let ((tag (car elem))\r
146 +               (attributes (cdr elem)))\r
147 +           (when (member tag line-tag-list)\r
148 +             (notmuch-combine-face-text-property start end attributes))))\r
149 +       ;; Reverse the list so earlier entries take precedence\r
150 +       (reverse notmuch-search-line-faces)))\r
151  \r
152  (defun notmuch-search-author-propertize (authors)\r
153    "Split `authors' into matching and non-matching authors and\r
154 -- \r
155 1.7.10\r
156 \r