[notmuch] [PATCH 2/2] notmuch.el: Replace inline function calls for body cleaning with a hook mechanism.

2010-02-18 Thread David Edmondson
This, and any other patches that I'm using, are now in a repository at
  git://gitorious.org/notmuch/notmuch.git

dme.
-- 
David Edmondson, http://dme.org


[notmuch] [PATCH 2/2] notmuch.el: Replace inline function calls for body cleaning with a hook mechanism.

2010-02-18 Thread David Edmondson
On Wed, 17 Feb 2010 14:04:12 +, David Edmondson  wrote:
> In-lining every possible body cleaning function is difficult to
> maintain and doesn't allow users any flexibility. Rather, use a hook
> mechanism so that users can choose what cleaning takes place.

Improved version attached, including a new washing function to clean up
citation blocks (suggested by Sebastian in #notmuch, though perhaps I
went a bit further than he intended).

-- next part --
A non-text attachment was scrubbed...
Name: 0001-notmuch.el-Replace-inline-function-calls-for-body-cl.patch
Type: text/x-diff
Size: 11289 bytes
Desc: not available
URL: 

-- next part --

dme.
-- 
David Edmondson, http://dme.org


Re: [notmuch] [PATCH 2/2] notmuch.el: Replace inline function calls for body cleaning with a hook mechanism.

2010-02-18 Thread David Edmondson
On Wed, 17 Feb 2010 14:04:12 +, David Edmondson d...@dme.org wrote:
 In-lining every possible body cleaning function is difficult to
 maintain and doesn't allow users any flexibility. Rather, use a hook
 mechanism so that users can choose what cleaning takes place.

Improved version attached, including a new washing function to clean up
citation blocks (suggested by Sebastian in #notmuch, though perhaps I
went a bit further than he intended).

From 545e2a0936a19620bf4f91282ca2aca1da0504b7 Mon Sep 17 00:00:00 2001
From: David Edmondson d...@dme.org
Date: Wed, 17 Feb 2010 14:03:24 +
Subject: [PATCH] notmuch.el: Replace inline function calls for body cleaning with a
 hook mechanism.

In-lining every possible body cleaning function is difficult to
maintain and doesn't allow users any flexibility. Rather, use a hook
mechanism so that users can choose what cleaning takes place.

notmuch-washing.el: Sample cleaning functions.
---
 Makefile.local |6 ++-
 notmuch-washing.el |  113 
 notmuch.el |  104 +---
 3 files changed, 171 insertions(+), 52 deletions(-)
 create mode 100644 notmuch-washing.el

diff --git a/Makefile.local b/Makefile.local
index 0a1f203..7124af7 100644
--- a/Makefile.local
+++ b/Makefile.local
@@ -1,6 +1,6 @@
 # -*- mode:makefile -*-
 
-emacs: notmuch.elc coolj.elc
+emacs: notmuch.elc coolj.elc notmuch-washing.elc
 
 notmuch_client_srcs =		\
 	$(notmuch_compat_srcs)	\
@@ -46,6 +46,8 @@ install-emacs: install emacs
 	install -m0644 notmuch.elc $(DESTDIR)$(emacs_lispdir)
 	install -m0644 coolj.el $(DESTDIR)$(emacs_lispdir)
 	install -m0644 coolj.elc $(DESTDIR)$(emacs_lispdir)
+	install -m0644 notmuch-washing.el $(DESTDIR)$(emacs_lispdir)
+	install -m0644 notmuch-washing.elc $(DESTDIR)$(emacs_lispdir)
 
 install-desktop:
 	install -d $(DESTDIR)$(desktop_dir)
@@ -62,4 +64,4 @@ install-zsh:
 		$(DESTDIR)$(zsh_completion_dir)/notmuch
 
 SRCS  := $(SRCS) $(notmuch_client_srcs)
-CLEAN := $(CLEAN) notmuch $(notmuch_client_modules) notmuch.elc coolj.elc notmuch.1.gz
+CLEAN := $(CLEAN) notmuch $(notmuch_client_modules) notmuch.elc coolj.elc notmuch-washing.elc notmuch.1.gz
diff --git a/notmuch-washing.el b/notmuch-washing.el
new file mode 100644
index 000..fc7b257
--- /dev/null
+++ b/notmuch-washing.el
@@ -0,0 +1,113 @@
+;; notmuch-washing.el --- functions to clean body parts
+;;
+;; Copyright © David Edmondson
+;;
+;; This file is not (yet) part of Notmuch.
+;;
+;; Notmuch is free software: you can redistribute it and/or modify it
+;; under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+;;
+;; Notmuch is distributed in the hope that it will be useful, but
+;; WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+;; General Public License for more details.
+;;
+;; You should have received a copy of the GNU General Public License
+;; along with Notmuch.  If not, see http://www.gnu.org/licenses/.
+;;
+;; Authors: David Edmondson d...@dme.org
+
+(require 'coolj)
+
+;; Add these functions to `notmuch-show-markup-body-hook' using
+;; `add-hook'. Something like:
+
+;; (eval-after-load notmuch
+;;   '(progn
+;;  (require 'notmuch-washing)
+;;  (setq notmuch-show-markup-body-hook nil)
+;;  (add-hook 'notmuch-show-markup-body-hook 'notmuch-show-washing-coolj t)
+;;  (add-hook 'notmuch-show-markup-body-hook 'notmuch-show-washing-citations t)
+;;  (add-hook 'notmuch-show-markup-body-hook 'notmuch-show-washing-compress-blanks t)
+;;  (add-hook 'notmuch-show-markup-body-hook 'notmuch-show-markup-citations t)
+;;  ))
+
+;; Note that the ordering of the functions is significant, given that
+;; later functions operate on the results of the earlier functions.
+
+(defun notmuch-show-washing-coolj (depth)
+  Wrap text in the region whilst maintaining the correct prefix.
+  (coolj-wrap-region (point-min) (point-max)))
+
+;; Utility functions.
+(defun remove-prefix (depth)
+  (let ((prefix-regexp (format (format ^%%%ds depth) )))
+(while (and (not (eobp))
+		(re-search-forward prefix-regexp nil t))
+  (replace-match  nil nil)
+  (forward-line
+
+(defun insert-prefix (depth)
+  (let ((prefix (format (format %%%ds depth) )))
+(while (not (eobp))
+  (insert prefix)
+  (forward-line
+
+(defun notmuch-show-washing-compress-blanks (depth)
+  Compress successive blank lines into one blank line.
+
+  ;; Algorithm derived from `article-strip-multiple-blank-lines' in
+  ;; `gnus-art.el'.
+
+  (goto-char (point-min))
+  (remove-prefix depth)
+
+  ;; Make all blank lines empty.
+  (goto-char (point-min))
+  (while (re-search-forward ^[ \t]+$ nil t)
+(replace-match  nil t))
+
+  ;; Replace multiple empty lines with a single empty line.
+  (goto-char 

Re: [notmuch] [PATCH 2/2] notmuch.el: Replace inline function calls for body cleaning with a hook mechanism.

2010-02-18 Thread David Edmondson
This, and any other patches that I'm using, are now in a repository at
  git://gitorious.org/notmuch/notmuch.git

dme.
-- 
David Edmondson, http://dme.org
___
notmuch mailing list
notmuch@notmuchmail.org
http://notmuchmail.org/mailman/listinfo/notmuch


[notmuch] [PATCH 2/2] notmuch.el: Replace inline function calls for body cleaning with a hook mechanism.

2010-02-17 Thread David Edmondson
In-lining every possible body cleaning function is difficult to
maintain and doesn't allow users any flexibility. Rather, use a hook
mechanism so that users can choose what cleaning takes place.

notmuch-washing.el: Sample cleaning functions.
---
 Makefile.local |6 +++-
 notmuch-washing.el |   65 
 notmuch.el |   12 +
 3 files changed, 76 insertions(+), 7 deletions(-)
 create mode 100644 notmuch-washing.el

diff --git a/Makefile.local b/Makefile.local
index 0a1f203..7124af7 100644
--- a/Makefile.local
+++ b/Makefile.local
@@ -1,6 +1,6 @@
 # -*- mode:makefile -*-

-emacs: notmuch.elc coolj.elc
+emacs: notmuch.elc coolj.elc notmuch-washing.elc

 notmuch_client_srcs =  \
$(notmuch_compat_srcs)  \
@@ -46,6 +46,8 @@ install-emacs: install emacs
install -m0644 notmuch.elc $(DESTDIR)$(emacs_lispdir)
install -m0644 coolj.el $(DESTDIR)$(emacs_lispdir)
install -m0644 coolj.elc $(DESTDIR)$(emacs_lispdir)
+   install -m0644 notmuch-washing.el $(DESTDIR)$(emacs_lispdir)
+   install -m0644 notmuch-washing.elc $(DESTDIR)$(emacs_lispdir)

 install-desktop:
install -d $(DESTDIR)$(desktop_dir)
@@ -62,4 +64,4 @@ install-zsh:
$(DESTDIR)$(zsh_completion_dir)/notmuch

 SRCS  := $(SRCS) $(notmuch_client_srcs)
-CLEAN := $(CLEAN) notmuch $(notmuch_client_modules) notmuch.elc coolj.elc 
notmuch.1.gz
+CLEAN := $(CLEAN) notmuch $(notmuch_client_modules) notmuch.elc coolj.elc 
notmuch-washing.elc notmuch.1.gz
diff --git a/notmuch-washing.el b/notmuch-washing.el
new file mode 100644
index 000..831eb00
--- /dev/null
+++ b/notmuch-washing.el
@@ -0,0 +1,65 @@
+; notmuch-washing.el --- functions to clean body parts
+;
+; Copyright ?? David Edmondson
+;
+; This file is not (yet) part of Notmuch.
+;
+; Notmuch is free software: you can redistribute it and/or modify it
+; under the terms of the GNU General Public License as published by
+; the Free Software Foundation, either version 3 of the License, or
+; (at your option) any later version.
+;
+; Notmuch is distributed in the hope that it will be useful, but
+; WITHOUT ANY WARRANTY; without even the implied warranty of
+; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+; General Public License for more details.
+;
+; You should have received a copy of the GNU General Public License
+; along with Notmuch.  If not, see .
+;
+; Authors: David Edmondson 
+
+(require 'coolj)
+
+;; Add these functions to `notmuch-show-markup-body-hook' using
+;; `add-hook'. Something like:
+
+;; (eval-after-load "notmuch"
+;;   '(progn
+;;  (require 'notmuch-washing)
+;;  (add-hook 'notmuch-show-markup-body-hook 'notmuch-show-washing-coolj)
+;;  (add-hook 'notmuch-show-markup-body-hook 
'notmuch-show-washing-compress-blank t)))
+
+;; Note that the ordering of the functions may well be significant.
+
+(defun notmuch-show-washing-coolj (begin end depth)
+  "Wrap text in the region whilst maintaining the correct prefix."
+  (coolj-wrap-region beg end))
+
+(defun notmuch-show-washing-compress-blank (begin end depth)
+  "Compress successive blank lines into one blank line."
+
+  ;; Algorithm derived from `article-strip-multiple-blank-lines' in
+  ;; `gnus-art.el'.
+  
+  (save-excursion
+;; Make all blank lines empty. **This also removes the prefix!**
+(goto-char begin)
+(while (re-search-forward "^[ \t]+$" end t)
+  (replace-match "" nil t))
+;; Replace multiple empty lines with a single empty line.
+(goto-char begin)
+(while (re-search-forward "\n\n\\(\n+\\)" end t)
+  (delete-region (match-beginning 1) (match-end 1)))
+;; dme - is this really the best way to generate a string of N
+;; spaces?
+(let ((prefix (format (format "%%%ds" depth) "")))
+  (goto-char begin)
+  ;; Insert the relevant prefix.
+  (while (re-search-forward "^$" end t)
+   (insert prefix)
+   (forward-line)
+
+;;
+
+(provide 'notmuch-washing)
diff --git a/notmuch.el b/notmuch.el
index 040fb5e..e64ed25 100644
--- a/notmuch.el
+++ b/notmuch.el
@@ -50,7 +50,6 @@
 (require 'cl)
 (require 'mm-view)
 (require 'message)
-(require 'coolj)

 (defvar notmuch-show-mode-map
   (let ((map (make-sparse-keymap)))
@@ -157,6 +156,12 @@ collapse remaining lines into a button.")
 (defvar notmuch-show-signatures-visible nil)
 (defvar notmuch-show-headers-visible nil)

+(defun notmuch-show-markup-body-hook '(notmuch-show-markup-citations-region)
+  "List of functions used to clean up body parts.
+
+Each is passed three arguments: the beginning of the region, the
+end of the region and the indetation depth.")
+
 ; XXX: This should be a generic function in emacs somewhere, not here
 (defun point-invisible-p ()
   "Return whether the character at point is invisible.
@@ -703,7 +708,6 @@ is what to put on the button."
 :type button-type)
   )))

-
 (defun 

[notmuch] [PATCH 2/2] notmuch.el: Replace inline function calls for body cleaning with a hook mechanism.

2010-02-17 Thread David Edmondson
In-lining every possible body cleaning function is difficult to
maintain and doesn't allow users any flexibility. Rather, use a hook
mechanism so that users can choose what cleaning takes place.

notmuch-washing.el: Sample cleaning functions.
---
 Makefile.local |6 +++-
 notmuch-washing.el |   65 
 notmuch.el |   12 +
 3 files changed, 76 insertions(+), 7 deletions(-)
 create mode 100644 notmuch-washing.el

diff --git a/Makefile.local b/Makefile.local
index 0a1f203..7124af7 100644
--- a/Makefile.local
+++ b/Makefile.local
@@ -1,6 +1,6 @@
 # -*- mode:makefile -*-
 
-emacs: notmuch.elc coolj.elc
+emacs: notmuch.elc coolj.elc notmuch-washing.elc
 
 notmuch_client_srcs =  \
$(notmuch_compat_srcs)  \
@@ -46,6 +46,8 @@ install-emacs: install emacs
install -m0644 notmuch.elc $(DESTDIR)$(emacs_lispdir)
install -m0644 coolj.el $(DESTDIR)$(emacs_lispdir)
install -m0644 coolj.elc $(DESTDIR)$(emacs_lispdir)
+   install -m0644 notmuch-washing.el $(DESTDIR)$(emacs_lispdir)
+   install -m0644 notmuch-washing.elc $(DESTDIR)$(emacs_lispdir)
 
 install-desktop:
install -d $(DESTDIR)$(desktop_dir)
@@ -62,4 +64,4 @@ install-zsh:
$(DESTDIR)$(zsh_completion_dir)/notmuch
 
 SRCS  := $(SRCS) $(notmuch_client_srcs)
-CLEAN := $(CLEAN) notmuch $(notmuch_client_modules) notmuch.elc coolj.elc 
notmuch.1.gz
+CLEAN := $(CLEAN) notmuch $(notmuch_client_modules) notmuch.elc coolj.elc 
notmuch-washing.elc notmuch.1.gz
diff --git a/notmuch-washing.el b/notmuch-washing.el
new file mode 100644
index 000..831eb00
--- /dev/null
+++ b/notmuch-washing.el
@@ -0,0 +1,65 @@
+; notmuch-washing.el --- functions to clean body parts
+;
+; Copyright © David Edmondson
+;
+; This file is not (yet) part of Notmuch.
+;
+; Notmuch is free software: you can redistribute it and/or modify it
+; under the terms of the GNU General Public License as published by
+; the Free Software Foundation, either version 3 of the License, or
+; (at your option) any later version.
+;
+; Notmuch is distributed in the hope that it will be useful, but
+; WITHOUT ANY WARRANTY; without even the implied warranty of
+; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+; General Public License for more details.
+;
+; You should have received a copy of the GNU General Public License
+; along with Notmuch.  If not, see http://www.gnu.org/licenses/.
+;
+; Authors: David Edmondson d...@dme.org
+
+(require 'coolj)
+
+;; Add these functions to `notmuch-show-markup-body-hook' using
+;; `add-hook'. Something like:
+
+;; (eval-after-load notmuch
+;;   '(progn
+;;  (require 'notmuch-washing)
+;;  (add-hook 'notmuch-show-markup-body-hook 'notmuch-show-washing-coolj)
+;;  (add-hook 'notmuch-show-markup-body-hook 
'notmuch-show-washing-compress-blank t)))
+
+;; Note that the ordering of the functions may well be significant.
+
+(defun notmuch-show-washing-coolj (begin end depth)
+  Wrap text in the region whilst maintaining the correct prefix.
+  (coolj-wrap-region beg end))
+
+(defun notmuch-show-washing-compress-blank (begin end depth)
+  Compress successive blank lines into one blank line.
+
+  ;; Algorithm derived from `article-strip-multiple-blank-lines' in
+  ;; `gnus-art.el'.
+  
+  (save-excursion
+;; Make all blank lines empty. **This also removes the prefix!**
+(goto-char begin)
+(while (re-search-forward ^[ \t]+$ end t)
+  (replace-match  nil t))
+;; Replace multiple empty lines with a single empty line.
+(goto-char begin)
+(while (re-search-forward \n\n\\(\n+\\) end t)
+  (delete-region (match-beginning 1) (match-end 1)))
+;; dme - is this really the best way to generate a string of N
+;; spaces?
+(let ((prefix (format (format %%%ds depth) )))
+  (goto-char begin)
+  ;; Insert the relevant prefix.
+  (while (re-search-forward ^$ end t)
+   (insert prefix)
+   (forward-line)
+
+;;
+
+(provide 'notmuch-washing)
diff --git a/notmuch.el b/notmuch.el
index 040fb5e..e64ed25 100644
--- a/notmuch.el
+++ b/notmuch.el
@@ -50,7 +50,6 @@
 (require 'cl)
 (require 'mm-view)
 (require 'message)
-(require 'coolj)
 
 (defvar notmuch-show-mode-map
   (let ((map (make-sparse-keymap)))
@@ -157,6 +156,12 @@ collapse remaining lines into a button.)
 (defvar notmuch-show-signatures-visible nil)
 (defvar notmuch-show-headers-visible nil)
 
+(defun notmuch-show-markup-body-hook '(notmuch-show-markup-citations-region)
+  List of functions used to clean up body parts.
+
+Each is passed three arguments: the beginning of the region, the
+end of the region and the indetation depth.)
+
 ; XXX: This should be a generic function in emacs somewhere, not here
 (defun point-invisible-p ()
   Return whether the character at point is invisible.
@@ -703,7 +708,6 @@ is what to put on the button.
 :type button-type)
   )))
 
-
 (defun