unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
From: David Edmondson <dme@dme.org>
To: notmuch@notmuchmail.org
Subject: [PATCH] emacs: Avoid regexp overflow when tidying citations.
Date: Fri, 12 Nov 2010 12:50:02 +0000	[thread overview]
Message-ID: <1289566202-24148-1-git-send-email-dme@dme.org> (raw)

Declare `notmuch-wash-tidy-citations-max', which is the largest region
that `notmuch-wash-tidy-citations' will attempt to improve.
---
 emacs/notmuch-wash.el |   61 ++++++++++++++++++++++++++++---------------------
 1 files changed, 35 insertions(+), 26 deletions(-)

diff --git a/emacs/notmuch-wash.el b/emacs/notmuch-wash.el
index cfcfb21..a7ea5e9 100644
--- a/emacs/notmuch-wash.el
+++ b/emacs/notmuch-wash.el
@@ -187,6 +187,11 @@ is what to put on the button."
 
 ;;
 
+(defcustom notmuch-wash-tidy-citations-max (* 10 1024)
+  "Maximum size of region to tidy."
+  :group 'notmuch
+  :type 'int)
+
 (defun notmuch-wash-tidy-citations (depth)
   "Improve the display of cited regions of a message.
 
@@ -199,32 +204,36 @@ Perform four transformations on the message body:
 - Remove citation trailers standing alone after a block of cited
   text."
 
-  ;; Remove lines of repeated citation leaders with no other content.
-  (goto-char (point-min))
-  (while (re-search-forward "\\(^>[> ]*\n\\)\\{2,\\}" nil t)
-    (replace-match "\\1"))
-
-  ;; Remove citation leaders standing alone before a block of cited
-  ;; text.
-  (goto-char (point-min))
-  (while (re-search-forward "\\(\n\\|^[^>].*\\)\n\\(^>[> ]*\n\\)" nil t)
-    (replace-match "\\1\n"))
-
-  ;; Remove citation trailers standing alone after a block of cited
-  ;; text.
-  (goto-char (point-min))
-  (while (re-search-forward "\\(^>[> ]*\n\\)\\(^$\\|^[^>].*\\)" nil t)
-    (replace-match "\\2"))
-
-  ;; Insert a blank line before a citation if there isn't one.
-  (goto-char (point-min))
-  (while (re-search-forward "\\(^[^>]+\\)\n>" nil t)
-    (replace-match "\\1\n\n>"))
-
-  ;; Insert a blank line after a citation if there isn't one.
-  (goto-char (point-min))
-  (while (re-search-forward "\\(^>.+\\)\n\\([^>]\\)" nil t)
-    (replace-match "\\1\n\n\\2")))
+  ;; If the message is long, don't bother.
+  (unless (> (- (point-max) (point-min))
+	     notmuch-wash-tidy-citations-max)
+
+    ;; Remove lines of repeated citation leaders with no other content.
+    (goto-char (point-min))
+    (while (re-search-forward "\\(^>[> ]*\n\\)\\{2,\\}" nil t)
+      (replace-match "\\1"))
+
+    ;; Remove citation leaders standing alone before a block of cited
+    ;; text.
+    (goto-char (point-min))
+    (while (re-search-forward "\\(\n\\|^[^>].*\\)\n\\(^>[> ]*\n\\)" nil t)
+      (replace-match "\\1\n"))
+
+    ;; Remove citation trailers standing alone after a block of cited
+    ;; text.
+    (goto-char (point-min))
+    (while (re-search-forward "\\(^>[> ]*\n\\)\\(^$\\|^[^>].*\\)" nil t)
+      (replace-match "\\2"))
+
+    ;; Insert a blank line before a citation if there isn't one.
+    (goto-char (point-min))
+    (while (re-search-forward "\\(^[^>]+\\)\n>" nil t)
+      (replace-match "\\1\n\n>"))
+
+    ;; Insert a blank line after a citation if there isn't one.
+    (goto-char (point-min))
+    (while (re-search-forward "\\(^>.+\\)\n\\([^>]\\)" nil t)
+      (replace-match "\\1\n\n\\2"))))
 
 ;;
 
-- 
1.7.2.3

             reply	other threads:[~2010-11-12 12:52 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-11-12 12:50 David Edmondson [this message]
2010-11-16 19:57 ` [PATCH] emacs: Avoid regexp overflow when tidying citations Carl Worth
2010-11-17 13:32   ` [PATCH] emacs: Remove over-eager regular expressions from notmuch-wash-tidy-citations David Edmondson
2010-12-07 22:11     ` Carl Worth

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://notmuchmail.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1289566202-24148-1-git-send-email-dme@dme.org \
    --to=dme@dme.org \
    --cc=notmuch@notmuchmail.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://yhetil.org/notmuch.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).