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 7FA0E40DDD5
\r
6 for <notmuch@notmuchmail.org>; Fri, 12 Nov 2010 04:52:04 -0800 (PST)
\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org
\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 RKfDMg-cH8Df for <notmuch@notmuchmail.org>;
\r
16 Fri, 12 Nov 2010 04:51:54 -0800 (PST)
\r
17 Received: from mail-ww0-f53.google.com (mail-ww0-f53.google.com
\r
18 [74.125.82.53]) by olra.theworths.org (Postfix) with ESMTP id CC07440DDCF for
\r
19 <notmuch@notmuchmail.org>; Fri, 12 Nov 2010 04:51:53 -0800 (PST)
\r
20 Received: by wwe15 with SMTP id 15so2321450wwe.34
\r
21 for <notmuch@notmuchmail.org>; Fri, 12 Nov 2010 04:51:53 -0800 (PST)
\r
22 Received: by 10.216.24.206 with SMTP id x56mr2022490wex.2.1289566311213;
\r
23 Fri, 12 Nov 2010 04:51:51 -0800 (PST)
\r
24 Received: from ut.hh.sledj.net (host81-149-164-25.in-addr.btopenworld.com
\r
26 by mx.google.com with ESMTPS id y15sm2119092weq.6.2010.11.12.04.51.49
\r
27 (version=TLSv1/SSLv3 cipher=RC4-MD5);
\r
28 Fri, 12 Nov 2010 04:51:50 -0800 (PST)
\r
29 Received: by ut.hh.sledj.net (Postfix, from userid 1000)
\r
30 id 2C25959405B; Fri, 12 Nov 2010 12:50:05 +0000 (GMT)
\r
31 From: David Edmondson <dme@dme.org>
\r
32 To: notmuch@notmuchmail.org
\r
33 Subject: [PATCH] emacs: Avoid regexp overflow when tidying citations.
\r
34 Date: Fri, 12 Nov 2010 12:50:02 +0000
\r
35 Message-Id: <1289566202-24148-1-git-send-email-dme@dme.org>
\r
36 X-Mailer: git-send-email 1.7.2.3
\r
37 X-BeenThere: notmuch@notmuchmail.org
\r
38 X-Mailman-Version: 2.1.13
\r
40 List-Id: "Use and development of the notmuch mail system."
\r
41 <notmuch.notmuchmail.org>
\r
42 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
43 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
44 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
45 List-Post: <mailto:notmuch@notmuchmail.org>
\r
46 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
47 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
48 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
49 X-List-Received-Date: Fri, 12 Nov 2010 12:52:04 -0000
\r
51 Declare `notmuch-wash-tidy-citations-max', which is the largest region
\r
52 that `notmuch-wash-tidy-citations' will attempt to improve.
\r
54 emacs/notmuch-wash.el | 61 ++++++++++++++++++++++++++++---------------------
\r
55 1 files changed, 35 insertions(+), 26 deletions(-)
\r
57 diff --git a/emacs/notmuch-wash.el b/emacs/notmuch-wash.el
\r
58 index cfcfb21..a7ea5e9 100644
\r
59 --- a/emacs/notmuch-wash.el
\r
60 +++ b/emacs/notmuch-wash.el
\r
61 @@ -187,6 +187,11 @@ is what to put on the button."
\r
65 +(defcustom notmuch-wash-tidy-citations-max (* 10 1024)
\r
66 + "Maximum size of region to tidy."
\r
70 (defun notmuch-wash-tidy-citations (depth)
\r
71 "Improve the display of cited regions of a message.
\r
73 @@ -199,32 +204,36 @@ Perform four transformations on the message body:
\r
74 - Remove citation trailers standing alone after a block of cited
\r
77 - ;; Remove lines of repeated citation leaders with no other content.
\r
78 - (goto-char (point-min))
\r
79 - (while (re-search-forward "\\(^>[> ]*\n\\)\\{2,\\}" nil t)
\r
80 - (replace-match "\\1"))
\r
82 - ;; Remove citation leaders standing alone before a block of cited
\r
84 - (goto-char (point-min))
\r
85 - (while (re-search-forward "\\(\n\\|^[^>].*\\)\n\\(^>[> ]*\n\\)" nil t)
\r
86 - (replace-match "\\1\n"))
\r
88 - ;; Remove citation trailers standing alone after a block of cited
\r
90 - (goto-char (point-min))
\r
91 - (while (re-search-forward "\\(^>[> ]*\n\\)\\(^$\\|^[^>].*\\)" nil t)
\r
92 - (replace-match "\\2"))
\r
94 - ;; Insert a blank line before a citation if there isn't one.
\r
95 - (goto-char (point-min))
\r
96 - (while (re-search-forward "\\(^[^>]+\\)\n>" nil t)
\r
97 - (replace-match "\\1\n\n>"))
\r
99 - ;; Insert a blank line after a citation if there isn't one.
\r
100 - (goto-char (point-min))
\r
101 - (while (re-search-forward "\\(^>.+\\)\n\\([^>]\\)" nil t)
\r
102 - (replace-match "\\1\n\n\\2")))
\r
103 + ;; If the message is long, don't bother.
\r
104 + (unless (> (- (point-max) (point-min))
\r
105 + notmuch-wash-tidy-citations-max)
\r
107 + ;; Remove lines of repeated citation leaders with no other content.
\r
108 + (goto-char (point-min))
\r
109 + (while (re-search-forward "\\(^>[> ]*\n\\)\\{2,\\}" nil t)
\r
110 + (replace-match "\\1"))
\r
112 + ;; Remove citation leaders standing alone before a block of cited
\r
114 + (goto-char (point-min))
\r
115 + (while (re-search-forward "\\(\n\\|^[^>].*\\)\n\\(^>[> ]*\n\\)" nil t)
\r
116 + (replace-match "\\1\n"))
\r
118 + ;; Remove citation trailers standing alone after a block of cited
\r
120 + (goto-char (point-min))
\r
121 + (while (re-search-forward "\\(^>[> ]*\n\\)\\(^$\\|^[^>].*\\)" nil t)
\r
122 + (replace-match "\\2"))
\r
124 + ;; Insert a blank line before a citation if there isn't one.
\r
125 + (goto-char (point-min))
\r
126 + (while (re-search-forward "\\(^[^>]+\\)\n>" nil t)
\r
127 + (replace-match "\\1\n\n>"))
\r
129 + ;; Insert a blank line after a citation if there isn't one.
\r
130 + (goto-char (point-min))
\r
131 + (while (re-search-forward "\\(^>.+\\)\n\\([^>]\\)" nil t)
\r
132 + (replace-match "\\1\n\n\\2"))))
\r