Re: [PATCH] emacs: Avoid regexp overflow when tidying citations.

2010-11-16 Thread Carl Worth
On Fri, 12 Nov 2010 12:50:02 +, David Edmondson  wrote:
> Declare `notmuch-wash-tidy-citations-max', which is the largest region
> that `notmuch-wash-tidy-citations' will attempt to improve.

Hi David,

Could you add a test case for whatever bug is being fixed here?

I'm a little concerned about giving the user a tuning knob which appears
to have a somewhat arbitrary default, and also without providing much
guidance to the user on how to set that particular knob.

I'd feel better if the code could somehow "know" when it needs to stop
tidying well enough that we would feel fine just not offering the knob
at all.

Thanks,

-Carl


pgp8xq0JdEVDJ.pgp
Description: PGP signature
___
notmuch mailing list
notmuch@notmuchmail.org
http://notmuchmail.org/mailman/listinfo/notmuch


[PATCH] emacs: Avoid regexp overflow when tidying citations.

2010-11-16 Thread Carl Worth
On Fri, 12 Nov 2010 12:50:02 +, David Edmondson  wrote:
> Declare `notmuch-wash-tidy-citations-max', which is the largest region
> that `notmuch-wash-tidy-citations' will attempt to improve.

Hi David,

Could you add a test case for whatever bug is being fixed here?

I'm a little concerned about giving the user a tuning knob which appears
to have a somewhat arbitrary default, and also without providing much
guidance to the user on how to set that particular knob.

I'd feel better if the code could somehow "know" when it needs to stop
tidying well enough that we would feel fine just not offering the knob
at all.

Thanks,

-Carl
-- next part --
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
URL: 



[PATCH] emacs: Avoid regexp overflow when tidying citations.

2010-11-12 Thread David Edmondson
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



[PATCH] emacs: Avoid regexp overflow when tidying citations.

2010-11-12 Thread David Edmondson
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

___
notmuch mailing list
notmuch@notmuchmail.org
http://notmuchmail.org/mailman/listinfo/notmuch