Re: [PATCH] emacs: wash: make word-wrap bound message width
[notmuch-archives.git] / 60 / 939c2544e0bf388d4a365d41f14cd01c1e0544
1 Return-Path: <bremner@pivot.cs.unb.ca>\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 5A4DF431FBF\r
6         for <notmuch@notmuchmail.org>; Fri, 25 Dec 2009 12:09:33 -0800 (PST)\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
8 Received: from olra.theworths.org ([127.0.0.1])\r
9         by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
10         with ESMTP id 63373G-bW3yy for <notmuch@notmuchmail.org>;\r
11         Fri, 25 Dec 2009 12:09:32 -0800 (PST)\r
12 Received: from pivot.cs.unb.ca (pivot.cs.unb.ca [131.202.240.57])\r
13         by olra.theworths.org (Postfix) with ESMTP id B2B7E431FAE\r
14         for <notmuch@notmuchmail.org>; Fri, 25 Dec 2009 12:09:32 -0800 (PST)\r
15 Received: from\r
16         fctnnbsc30w-142167182194.pppoe-dynamic.high-speed.nb.bellaliant.net\r
17         ([142.167.182.194] helo=localhost)\r
18         by pivot.cs.unb.ca with esmtpsa (TLS1.0:RSA_AES_256_CBC_SHA1:32)\r
19         (Exim 4.69) (envelope-from <bremner@pivot.cs.unb.ca>)\r
20         id 1NOGTc-0004oe-9v; Fri, 25 Dec 2009 16:09:32 -0400\r
21 Received: from bremner by localhost with local (Exim 4.71)\r
22         (envelope-from <bremner@pivot.cs.unb.ca>)\r
23         id 1NOGTX-0006B5-0I; Fri, 25 Dec 2009 16:09:27 -0400\r
24 From: david@tethera.net\r
25 To: notmuch@notmuchmail.org\r
26 Date: Fri, 25 Dec 2009 16:09:07 -0400\r
27 Message-Id: <1261771748-23687-2-git-send-email-david@tethera.net>\r
28 X-Mailer: git-send-email 1.6.5.7\r
29 In-Reply-To: <1261771748-23687-1-git-send-email-david@tethera.net>\r
30 References: <87my17965l.fsf@anar.kanru.info>\r
31         <1261771748-23687-1-git-send-email-david@tethera.net>\r
32 X-Sender-Verified: bremner@pivot.cs.unb.ca\r
33 Cc: David Bremner <bremner@unb.ca>\r
34 Subject: [notmuch] [PATCH 1/2] notmuch.el: Refactor citation markup.\r
35         Variables for minimum size, button text.\r
36 X-BeenThere: notmuch@notmuchmail.org\r
37 X-Mailman-Version: 2.1.12\r
38 Precedence: list\r
39 List-Id: "Use and development of the notmuch mail system."\r
40         <notmuch.notmuchmail.org>\r
41 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
42         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
43 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
44 List-Post: <mailto:notmuch@notmuchmail.org>\r
45 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
46 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
47         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
48 X-List-Received-Date: Fri, 25 Dec 2009 20:09:33 -0000\r
49 \r
50 From: David Bremner <bremner@unb.ca>\r
51 \r
52 This is a fairly intrusive rewrite.\r
53 \r
54 - I pulled the common code for the signature and citation case out\r
55   into a separate function. This is not so much shorter, but I think it\r
56   will be easier to maintain.\r
57 \r
58 - I replaced the sequence of (looking-at blah) (forward-line)  with a single\r
59   re-search-forward per citation.\r
60 \r
61 New variables\r
62 \r
63 - notmuch-show-signature-button-format, notmuch-show-citation-button-format\r
64   Allow customization of button text.\r
65 \r
66 - notmuch-show-citation-lines-min\r
67   Do not buttonize citations below the given threshold.\r
68 ---\r
69  notmuch.el |  133 ++++++++++++++++++++++++++++++++++++++---------------------\r
70  1 files changed, 86 insertions(+), 47 deletions(-)\r
71 \r
72 diff --git a/notmuch.el b/notmuch.el\r
73 index 97914f2..8a51d27 100644\r
74 --- a/notmuch.el\r
75 +++ b/notmuch.el\r
76 @@ -92,9 +92,24 @@ for indentation at the beginning of the line. But notmuch will\r
77  move past the indentation when testing this pattern, (so that the\r
78  pattern can still test against the entire line).")\r
79  \r
80 +(defvar notmuch-show-signature-button-format \r
81 +  "[ %d-line hidden signature. Click/Enter to show ]"\r
82 +  "String used to construct button text for hidden signatures\r
83 +\r
84 +Can use up to one integer format parameter, i.e. %d")\r
85 +\r
86 +(defvar notmuch-show-citation-button-format \r
87 +  "[ %d-line hidden citation. Click/Enter to show ]"\r
88 +  "String used to construct button text for hidden citations.\r
89 +\r
90 +Can use up to one integer format parameter, i.e. %d")\r
91 +\r
92  (defvar notmuch-show-signature-lines-max 12\r
93    "Maximum length of signature that will be hidden by default.")\r
94  \r
95 +(defvar notmuch-show-citation-lines-min 4\r
96 +  "Minimum length of citation that will be hidden.")\r
97 +\r
98  (defvar notmuch-command "notmuch"\r
99    "Command to run the notmuch binary.")\r
100  \r
101 @@ -593,54 +608,78 @@ which this thread was originally shown."\r
102    'face 'notmuch-message-summary-face\r
103    :supertype 'notmuch-button-invisibility-toggle-type)\r
104  \r
105 +(defun notmuch-show-citation-regexp (depth)\r
106 +  "Build a regexp for matching citations at a given DEPTH (indent)"\r
107 +  (let ((line-regexp (format "[[:space:]]\\{%d\\}>.*\n" depth)))\r
108 +    (concat "\\(?:^" line-regexp \r
109 +           "\\(?:[[:space:]]*\n" line-regexp\r
110 +           "\\)?\\)+")))\r
111 +\r
112 +(defun notmuch-show-region-to-button (beg end type prefix button-text)\r
113 +  "Auxilary function to do the actual making of overlays and buttons\r
114 +\r
115 +BEG and END are buffer locations. TYPE should a string, either\r
116 +\"citation\" or \"signature\". PREFIX is some arbitrary text to\r
117 +insert before the button, probably for indentation.  BUTTON-TEXT\r
118 +is what to put on the button."\r
119 +\r
120 +;; This uses some slightly tricky conversions between strings and\r
121 +;; symbols because of the way the button code works. Note that\r
122 +;; replacing intern-soft with make-symbol will cause this to fail, \r
123 +;; since the newly created symbol has no plist.\r
124 +\r
125 +  (let ((overlay (make-overlay beg end))\r
126 +       (invis-spec (make-symbol (concat "notmuch-" type "-region")))\r
127 +       (button-type (intern-soft (concat "notmuch-button-" \r
128 +                                         type "-toggle-type"))))\r
129 +    (add-to-invisibility-spec invis-spec)\r
130 +    (overlay-put overlay 'invisible invis-spec)\r
131 +    (goto-char (1+ end))\r
132 +    (save-excursion \r
133 +      (goto-char (1- beg))\r
134 +      (insert prefix)\r
135 +      (insert-button button-text\r
136 +                    'invisibility-spec invis-spec\r
137 +                    :type button-type)\r
138 +      )))\r
139 +\r
140 +                                                \r
141  (defun notmuch-show-markup-citations-region (beg end depth)\r
142 -  (goto-char beg)\r
143 -  (beginning-of-line)\r
144 -  (while (< (point) end)\r
145 -    (let ((beg-sub (point-marker))\r
146 -         (indent (make-string depth ? ))\r
147 -         (citation ">"))\r
148 -      (move-to-column depth)\r
149 -      (if (looking-at citation)\r
150 -         (progn\r
151 -           (while (looking-at citation)\r
152 -             (forward-line)\r
153 -             (move-to-column depth))\r
154 -           (let ((overlay (make-overlay beg-sub (point)))\r
155 -                  (invis-spec (make-symbol "notmuch-citation-region")))\r
156 -              (add-to-invisibility-spec invis-spec)\r
157 -             (overlay-put overlay 'invisible invis-spec)\r
158 -              (let ((p (point-marker))\r
159 -                    (cite-button-text\r
160 -                     (concat "["  (number-to-string (count-lines beg-sub (point)))\r
161 -                             "-line citation. Click/Enter to show.]")))\r
162 -                (goto-char (- beg-sub 1))\r
163 -                (insert (concat "\n" indent))\r
164 -                (insert-button cite-button-text\r
165 -                               'invisibility-spec invis-spec\r
166 -                               :type 'notmuch-button-citation-toggle-type)\r
167 -                (forward-line)\r
168 -              ))))\r
169 -      (move-to-column depth)\r
170 -      (if (looking-at notmuch-show-signature-regexp)\r
171 -         (let ((sig-lines (- (count-lines beg-sub end) 1)))\r
172 -           (if (<= sig-lines notmuch-show-signature-lines-max)\r
173 -               (progn\r
174 -                  (let ((invis-spec (make-symbol "notmuch-signature-region")))\r
175 -                    (add-to-invisibility-spec invis-spec)\r
176 -                    (overlay-put (make-overlay beg-sub end)\r
177 -                                 'invisible invis-spec)\r
178 -                  \r
179 -                    (goto-char (- beg-sub 1))\r
180 -                    (insert (concat "\n" indent))\r
181 -                    (let ((sig-button-text (concat "[" (number-to-string sig-lines)\r
182 -                                                   "-line signature. Click/Enter to show.]")))\r
183 -                      (insert-button sig-button-text 'invisibility-spec invis-spec\r
184 -                                     :type 'notmuch-button-signature-toggle-type)\r
185 -                     )\r
186 -                    (insert "\n")\r
187 -                    (goto-char end))))))\r
188 -      (forward-line))))\r
189 +  "Markup citations, and up to one signature in the given region"\r
190 +  ;; it would be nice if the untabify was not required, but \r
191 +  ;; that would require notmuch to indent with spaces.\r
192 +  (untabify beg end)\r
193 +  (let ((citation-regexp (notmuch-show-citation-regexp depth))\r
194 +       (signature-regexp (concat (format "^[[:space:]]\\{%d\\}" depth) \r
195 +                                 notmuch-show-signature-regexp))\r
196 +       (indent (concat "\n" (make-string depth ? ))))\r
197 +    (goto-char beg)\r
198 +    (beginning-of-line)\r
199 +    (while (and (< (point) end) \r
200 +               (re-search-forward citation-regexp end t))\r
201 +      (let* ((cite-start (match-beginning 0))\r
202 +            (cite-end  (match-end 0))\r
203 +            (cite-lines (count-lines cite-start cite-end)))\r
204 +       (if (>= cite-lines notmuch-show-citation-lines-min)\r
205 +           (notmuch-show-region-to-button \r
206 +            cite-start cite-end\r
207 +            "citation"\r
208 +            indent\r
209 +            (format notmuch-show-citation-button-format cite-lines)\r
210 +            ))))\r
211 +    (if (and (< (point) end) \r
212 +            (re-search-forward signature-regexp end t))\r
213 +       (let* ((sig-start (match-beginning 0))\r
214 +              (sig-end (match-end 0))\r
215 +              (sig-lines (1- (count-lines sig-start end))))\r
216 +         (if (<= sig-lines notmuch-show-signature-lines-max)\r
217 +             (notmuch-show-region-to-button \r
218 +              sig-start\r
219 +              end\r
220 +              "signature"\r
221 +              indent\r
222 +              (format notmuch-show-signature-button-format sig-lines)\r
223 +              ))))))\r
224  \r
225  (defun notmuch-show-markup-part (beg end depth)\r
226    (if (re-search-forward notmuch-show-part-begin-regexp nil t)\r
227 -- \r
228 1.6.5.7\r
229 \r