Re: [PATCH] emacs: wash: make word-wrap bound message width
[notmuch-archives.git] / 4f / 8518d8acc8110b331309a37af2a8e6f2fc1321
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 BF31D431FBF\r
6         for <notmuch@notmuchmail.org>; Tue, 11 Mar 2014 07:47:11 -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 ML7WzdCWlT1E for <notmuch@notmuchmail.org>;\r
16         Tue, 11 Mar 2014 07:47:07 -0700 (PDT)\r
17 Received: from dmz-mailsec-scanner-3.mit.edu (dmz-mailsec-scanner-3.mit.edu\r
18         [18.9.25.14])\r
19         (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits))\r
20         (No client certificate requested)\r
21         by olra.theworths.org (Postfix) with ESMTPS id B2544431FBD\r
22         for <notmuch@notmuchmail.org>; Tue, 11 Mar 2014 07:47:06 -0700 (PDT)\r
23 X-AuditID: 1209190e-f79ee6d000000c40-67-531f21e8383f\r
24 Received: from mailhub-auth-3.mit.edu ( [18.9.21.43])\r
25         (using TLS with cipher AES256-SHA (256/256 bits))\r
26         (Client did not present a certificate)\r
27         by dmz-mailsec-scanner-3.mit.edu (Symantec Messaging Gateway) with SMTP\r
28         id F6.ED.03136.8E12F135; Tue, 11 Mar 2014 10:47:04 -0400 (EDT)\r
29 Received: from outgoing.mit.edu (outgoing-auth-1.mit.edu [18.9.28.11])\r
30         by mailhub-auth-3.mit.edu (8.13.8/8.9.2) with ESMTP id s2BEl2XA001010; \r
31         Tue, 11 Mar 2014 10:47:02 -0400\r
32 Received: from drake.dyndns.org\r
33         (216-15-114-40.c3-0.arl-ubr1.sbo-arl.ma.cable.rcn.com\r
34         [216.15.114.40]) (authenticated bits=0)\r
35         (User authenticated as amdragon@ATHENA.MIT.EDU)\r
36         by outgoing.mit.edu (8.13.8/8.12.4) with ESMTP id s2BEkxON024934\r
37         (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT);\r
38         Tue, 11 Mar 2014 10:47:01 -0400\r
39 Received: from amthrax by drake.dyndns.org with local (Exim 4.77)\r
40         (envelope-from <amdragon@mit.edu>)\r
41         id 1WNNxL-0005t1-ML; Tue, 11 Mar 2014 10:46:59 -0400\r
42 From: Austin Clements <amdragon@MIT.EDU>\r
43 To: notmuch@notmuchmail.org\r
44 Subject: [PATCH] emacs: Combine notmuch-combine-face-text-property{,-string}\r
45 Date: Tue, 11 Mar 2014 10:46:55 -0400\r
46 Message-Id: <1394549215-22508-1-git-send-email-amdragon@mit.edu>\r
47 X-Mailer: git-send-email 1.8.4.rc3\r
48 In-Reply-To: <8761nl31gl.fsf@awakening.csail.mit.edu>\r
49 References: <8761nl31gl.fsf@awakening.csail.mit.edu>\r
50 X-Brightmail-Tracker:\r
51  H4sIAAAAAAAAA+NgFtrNIsWRmVeSWpSXmKPExsUixCmqrftCUT7Y4PpBE4vVc3ksrt+cyezA\r
52         5LFz1l12j2erbjEHMEVx2aSk5mSWpRbp2yVwZew8tZalYJdmxd/JO5kbGLcodjFyckgImEhs\r
53         X7+KCcIWk7hwbz1bFyMXh5DAbCaJ7w87oJyNjBJrd69kBakSErjDJNF7ghMiMZdR4sSRn8wg\r
54         CTYBDYlt+5czgtgiAtISO+/OBmtgFnCU+Lx/EdAkDg5hAR+JWa18IGEWAVWJE68bwDbzCjhI\r
55         /PzUCXWFksTCU9vAWjkFTCUOvf/NDrHXRGLC36tsExj5FzAyrGKUTcmt0s1NzMwpTk3WLU5O\r
56         zMtLLdI11svNLNFLTSndxAgOI0m+HYxfDyodYhTgYFTi4Q3wlQsWYk0sK67MPcQoycGkJMr7\r
57         R0I+WIgvKT+lMiOxOCO+qDQntfgQowQHs5IIb7I4UI43JbGyKrUoHyYlzcGiJM7bd1YiWEgg\r
58         PbEkNTs1tSC1CCYrw8GhJME7VwGoUbAoNT21Ii0zpwQhzcTBCTKcB2g4WA1vcUFibnFmOkT+\r
59         FKOilDjvDnmghABIIqM0D64XFuevGMWBXhHmTQdp5wGmCLjuV0CDmYAGf9wqBzK4JBEhJdXA\r
60         ODXOb3qa/cwPuyOWBr9XPb/jwlTBuGXvpDN8Fs6Qivwcb3GYpbRhTQSjh6FQ7IG/Z08re8Xs\r
61         5DyyL8pR+Ejpac+VbrahXs+ebq2ILJITW5CwIyRqksPTu5uuxXGIdezZ/9Hk1f6kFZcTu5/7\r
62         /5S+ci+Y0WnWX58OYx2Hrv9XZ9svD1zcc+npUSWW4oxEQy3mouJEADdtqTHOAgAA\r
63 X-BeenThere: notmuch@notmuchmail.org\r
64 X-Mailman-Version: 2.1.13\r
65 Precedence: list\r
66 List-Id: "Use and development of the notmuch mail system."\r
67         <notmuch.notmuchmail.org>\r
68 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
69         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
70 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
71 List-Post: <mailto:notmuch@notmuchmail.org>\r
72 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
73 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
74         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
75 X-List-Received-Date: Tue, 11 Mar 2014 14:47:12 -0000\r
76 \r
77 This combines our two face combining functions into one, easy to use\r
78 function with a much shorter name: `notmuch-apply-face'.  This\r
79 function takes the full set of arguments that\r
80 `notmuch-combine-face-text-property' took, but takes them in a more\r
81 convenient order and provides smarter defaults that make the function\r
82 easy to use on both strings and buffers.\r
83 ---\r
84 \r
85 Here's the combined, cleaned up face combiner interface I mentioned on\r
86 IRC.  I think the new `notmuch-apply-face' function introduced here\r
87 would be ideal for use in notmuch-tag-formats to fix the problem with\r
88 propertize overriding the entire face.\r
89 \r
90  emacs/notmuch-lib.el  | 35 ++++++++++++++++++-----------------\r
91  emacs/notmuch-tag.el  |  4 ++--\r
92  emacs/notmuch-tree.el |  2 +-\r
93  emacs/notmuch.el      |  2 +-\r
94  4 files changed, 22 insertions(+), 21 deletions(-)\r
95 \r
96 diff --git a/emacs/notmuch-lib.el b/emacs/notmuch-lib.el\r
97 index 2fefdad..05be5b8 100644\r
98 --- a/emacs/notmuch-lib.el\r
99 +++ b/emacs/notmuch-lib.el\r
100 @@ -578,23 +578,32 @@ single element face list."\r
101        face\r
102      (list face)))\r
103  \r
104 -(defun notmuch-combine-face-text-property (start end face &optional below object)\r
105 -  "Combine FACE into the 'face text property between START and END.\r
106 +(defun notmuch-apply-face (object face &optional start end below)\r
107 +  "Combine FACE into the 'face text property of OBJECT between START and END.\r
108  \r
109  This function combines FACE with any existing faces between START\r
110 -and END in OBJECT (which defaults to the current buffer).\r
111 -Attributes specified by FACE take precedence over existing\r
112 -attributes unless BELOW is non-nil.  FACE must be a face name (a\r
113 -symbol or string), a property list of face attributes, or a list\r
114 -of these.  For convenience when applied to strings, this returns\r
115 -OBJECT."\r
116 +and END in OBJECT.  Attributes specified by FACE take precedence\r
117 +over existing attributes unless BELOW is non-nil.\r
118 +\r
119 +OBJECT may be a string, a buffer, or nil (which means the current\r
120 +buffer).  If object is a string, START and END are 0-based;\r
121 +otherwise they are buffer positions (integers or markers).  FACE\r
122 +must be a face name (a symbol or string), a property list of face\r
123 +attributes, or a list of these.  If START and/or END are omitted,\r
124 +they default to the beginning/end of OBJECT.  For convenience\r
125 +when applied to strings, this returns OBJECT."\r
126  \r
127    ;; A face property can have three forms: a face name (a string or\r
128    ;; symbol), a property list, or a list of these two forms.  In the\r
129    ;; list case, the faces will be combined, with the earlier faces\r
130    ;; taking precedent.  Here we canonicalize everything to list form\r
131    ;; to make it easy to combine.\r
132 -  (let ((pos start)\r
133 +  (let ((pos (cond (start start)\r
134 +                  ((stringp object) 0)\r
135 +                  (t 1)))\r
136 +       (end (cond (end end)\r
137 +                  ((stringp object) (length object))\r
138 +                  (t (1+ (buffer-size object)))))\r
139         (face-list (notmuch-face-ensure-list-form face)))\r
140      (while (< pos end)\r
141        (let* ((cur (get-text-property pos 'face object))\r
142 @@ -607,14 +616,6 @@ OBJECT."\r
143         (setq pos next))))\r
144    object)\r
145  \r
146 -(defun notmuch-combine-face-text-property-string (string face &optional below)\r
147 -  (notmuch-combine-face-text-property\r
148 -   0\r
149 -   (length string)\r
150 -   face\r
151 -   below\r
152 -   string))\r
153 -\r
154  (defun notmuch-map-text-property (start end prop func &optional object)\r
155    "Transform text property PROP using FUNC.\r
156  \r
157 diff --git a/emacs/notmuch-tag.el b/emacs/notmuch-tag.el\r
158 index 908e7ad..d7deaf0 100644\r
159 --- a/emacs/notmuch-tag.el\r
160 +++ b/emacs/notmuch-tag.el\r
161 @@ -151,13 +151,13 @@ This can be used with `notmuch-tag-format-image-data'."\r
162  (defun notmuch-tag-format-tags (tags &optional face)\r
163    "Return a string representing formatted TAGS."\r
164    (let ((face (or face 'notmuch-tag-face)))\r
165 -    (notmuch-combine-face-text-property-string\r
166 +    (notmuch-apply-face\r
167       (mapconcat #'identity\r
168                 ;; nil indicated that the tag was deliberately hidden\r
169                 (delq nil (mapcar #'notmuch-tag-format-tag tags))\r
170                 " ")\r
171       face\r
172 -     t)))\r
173 +     nil nil t)))\r
174  \r
175  (defcustom notmuch-before-tag-hook nil\r
176    "Hooks that are run before tags of a message are modified.\r
177 diff --git a/emacs/notmuch-tree.el b/emacs/notmuch-tree.el\r
178 index 4f2ac02..bc4c0b0 100644\r
179 --- a/emacs/notmuch-tree.el\r
180 +++ b/emacs/notmuch-tree.el\r
181 @@ -715,7 +715,7 @@ unchanged ADDRESS if parsing fails."\r
182      (dolist (spec field-list result-string)\r
183        (let ((field-string (notmuch-tree-format-field (car spec) (cdr spec) msg)))\r
184         (setq result-string (concat result-string field-string))))\r
185 -    (notmuch-combine-face-text-property-string result-string face t)))\r
186 +    (notmuch-apply-face result-string face nil nil t)))\r
187  \r
188  (defun notmuch-tree-insert-msg (msg)\r
189    "Insert the message MSG according to notmuch-tree-result-format"\r
190 diff --git a/emacs/notmuch.el b/emacs/notmuch.el\r
191 index 0471750..222d8b1 100644\r
192 --- a/emacs/notmuch.el\r
193 +++ b/emacs/notmuch.el\r
194 @@ -649,7 +649,7 @@ foreground and blue background."\r
195           (let ((tag (car elem))\r
196                 (attributes (cdr elem)))\r
197             (when (member tag line-tag-list)\r
198 -             (notmuch-combine-face-text-property start end attributes))))\r
199 +             (notmuch-apply-face nil attributes start end))))\r
200         ;; Reverse the list so earlier entries take precedence\r
201         (reverse notmuch-search-line-faces)))\r
202  \r
203 -- \r
204 1.8.4.rc3\r
205 \r