[notmuch] [PATCH 2/2] notmuch.el: Replace inline function calls for body cleaning...
authorDavid Edmondson <dme@dme.org>
Wed, 17 Feb 2010 14:04:12 +0000 (14:04 +0000)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:36:13 +0000 (09:36 -0800)
28/8fa2a9a914fa5053fed2753953047d8b2313be [new file with mode: 0644]

diff --git a/28/8fa2a9a914fa5053fed2753953047d8b2313be b/28/8fa2a9a914fa5053fed2753953047d8b2313be
new file mode 100644 (file)
index 0000000..5031a89
--- /dev/null
@@ -0,0 +1,209 @@
+Return-Path: <dme@dme.org>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+       by olra.theworths.org (Postfix) with ESMTP id E36DF431FBF\r
+       for <notmuch@notmuchmail.org>; Wed, 17 Feb 2010 06:04:51 -0800 (PST)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -2.296\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-2.296 tagged_above=-999 required=5 tests=[AWL=0.303,\r
+       BAYES_00=-2.599] autolearn=ham\r
+Received: from olra.theworths.org ([127.0.0.1])\r
+       by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
+       with ESMTP id WTz9SvUyde2h for <notmuch@notmuchmail.org>;\r
+       Wed, 17 Feb 2010 06:04:51 -0800 (PST)\r
+Received: from fg-out-1718.google.com (fg-out-1718.google.com [72.14.220.152])\r
+       by olra.theworths.org (Postfix) with ESMTP id 9235C431FAE\r
+       for <notmuch@notmuchmail.org>; Wed, 17 Feb 2010 06:04:50 -0800 (PST)\r
+Received: by fg-out-1718.google.com with SMTP id e12so208449fga.2\r
+       for <notmuch@notmuchmail.org>; Wed, 17 Feb 2010 06:04:49 -0800 (PST)\r
+Received: by 10.86.125.32 with SMTP id x32mr14338636fgc.63.1266415483526;\r
+       Wed, 17 Feb 2010 06:04:43 -0800 (PST)\r
+Received: from aw.hh.sledj.net (gmp-ea-fw-1b.sun.com [192.18.8.1])\r
+       by mx.google.com with ESMTPS id 12sm14855123fgg.12.2010.02.17.06.04.42\r
+       (version=TLSv1/SSLv3 cipher=RC4-MD5);\r
+       Wed, 17 Feb 2010 06:04:42 -0800 (PST)\r
+Received: by aw.hh.sledj.net (Postfix, from userid 1000)\r
+       id CE36B3A099; Wed, 17 Feb 2010 14:04:25 +0000 (GMT)\r
+From: David Edmondson <dme@dme.org>\r
+To: notmuch@notmuchmail.org\r
+Date: Wed, 17 Feb 2010 14:04:12 +0000\r
+Message-Id: <1266415452-25108-2-git-send-email-dme@dme.org>\r
+X-Mailer: git-send-email 1.6.6.1\r
+In-Reply-To: <1266415452-25108-1-git-send-email-dme@dme.org>\r
+References: <1266415452-25108-1-git-send-email-dme@dme.org>\r
+Subject: [notmuch] [PATCH 2/2] notmuch.el: Replace inline function calls for\r
+       body cleaning with a hook mechanism.\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.13\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+       <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Wed, 17 Feb 2010 14:04:52 -0000\r
+\r
+In-lining every possible body cleaning function is difficult to\r
+maintain and doesn't allow users any flexibility. Rather, use a hook\r
+mechanism so that users can choose what cleaning takes place.\r
+\r
+notmuch-washing.el: Sample cleaning functions.\r
+---\r
+ Makefile.local     |    6 +++-\r
+ notmuch-washing.el |   65 ++++++++++++++++++++++++++++++++++++++++++++++++++++\r
+ notmuch.el         |   12 +++++----\r
+ 3 files changed, 76 insertions(+), 7 deletions(-)\r
+ create mode 100644 notmuch-washing.el\r
+\r
+diff --git a/Makefile.local b/Makefile.local\r
+index 0a1f203..7124af7 100644\r
+--- a/Makefile.local\r
++++ b/Makefile.local\r
+@@ -1,6 +1,6 @@\r
+ # -*- mode:makefile -*-\r
\r
+-emacs: notmuch.elc coolj.elc\r
++emacs: notmuch.elc coolj.elc notmuch-washing.elc\r
\r
+ notmuch_client_srcs =         \\r
+       $(notmuch_compat_srcs)  \\r
+@@ -46,6 +46,8 @@ install-emacs: install emacs\r
+       install -m0644 notmuch.elc $(DESTDIR)$(emacs_lispdir)\r
+       install -m0644 coolj.el $(DESTDIR)$(emacs_lispdir)\r
+       install -m0644 coolj.elc $(DESTDIR)$(emacs_lispdir)\r
++      install -m0644 notmuch-washing.el $(DESTDIR)$(emacs_lispdir)\r
++      install -m0644 notmuch-washing.elc $(DESTDIR)$(emacs_lispdir)\r
\r
+ install-desktop:\r
+       install -d $(DESTDIR)$(desktop_dir)\r
+@@ -62,4 +64,4 @@ install-zsh:\r
+               $(DESTDIR)$(zsh_completion_dir)/notmuch\r
\r
+ SRCS  := $(SRCS) $(notmuch_client_srcs)\r
+-CLEAN := $(CLEAN) notmuch $(notmuch_client_modules) notmuch.elc coolj.elc notmuch.1.gz\r
++CLEAN := $(CLEAN) notmuch $(notmuch_client_modules) notmuch.elc coolj.elc notmuch-washing.elc notmuch.1.gz\r
+diff --git a/notmuch-washing.el b/notmuch-washing.el\r
+new file mode 100644\r
+index 0000000..831eb00\r
+--- /dev/null\r
++++ b/notmuch-washing.el\r
+@@ -0,0 +1,65 @@\r
++; notmuch-washing.el --- functions to clean body parts\r
++;\r
++; Copyright © David Edmondson\r
++;\r
++; This file is not (yet) part of Notmuch.\r
++;\r
++; Notmuch is free software: you can redistribute it and/or modify it\r
++; under the terms of the GNU General Public License as published by\r
++; the Free Software Foundation, either version 3 of the License, or\r
++; (at your option) any later version.\r
++;\r
++; Notmuch is distributed in the hope that it will be useful, but\r
++; WITHOUT ANY WARRANTY; without even the implied warranty of\r
++; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\r
++; General Public License for more details.\r
++;\r
++; You should have received a copy of the GNU General Public License\r
++; along with Notmuch.  If not, see <http://www.gnu.org/licenses/>.\r
++;\r
++; Authors: David Edmondson <dme@dme.org>\r
++\r
++(require 'coolj)\r
++\r
++;; Add these functions to `notmuch-show-markup-body-hook' using\r
++;; `add-hook'. Something like:\r
++\r
++;; (eval-after-load "notmuch"\r
++;;   '(progn\r
++;;      (require 'notmuch-washing)\r
++;;      (add-hook 'notmuch-show-markup-body-hook 'notmuch-show-washing-coolj)\r
++;;      (add-hook 'notmuch-show-markup-body-hook 'notmuch-show-washing-compress-blank t)))\r
++\r
++;; Note that the ordering of the functions may well be significant.\r
++\r
++(defun notmuch-show-washing-coolj (begin end depth)\r
++  "Wrap text in the region whilst maintaining the correct prefix."\r
++  (coolj-wrap-region beg end))\r
++\r
++(defun notmuch-show-washing-compress-blank (begin end depth)\r
++  "Compress successive blank lines into one blank line."\r
++\r
++  ;; Algorithm derived from `article-strip-multiple-blank-lines' in\r
++  ;; `gnus-art.el'.\r
++  \r
++  (save-excursion\r
++    ;; Make all blank lines empty. **This also removes the prefix!**\r
++    (goto-char begin)\r
++    (while (re-search-forward "^[ \t]+$" end t)\r
++      (replace-match "" nil t))\r
++    ;; Replace multiple empty lines with a single empty line.\r
++    (goto-char begin)\r
++    (while (re-search-forward "\n\n\\(\n+\\)" end t)\r
++      (delete-region (match-beginning 1) (match-end 1)))\r
++    ;; dme - is this really the best way to generate a string of N\r
++    ;; spaces?\r
++    (let ((prefix (format (format "%%%ds" depth) "")))\r
++      (goto-char begin)\r
++      ;; Insert the relevant prefix.\r
++      (while (re-search-forward "^$" end t)\r
++      (insert prefix)\r
++      (forward-line)))))\r
++\r
++;;\r
++\r
++(provide 'notmuch-washing)\r
+diff --git a/notmuch.el b/notmuch.el\r
+index 040fb5e..e64ed25 100644\r
+--- a/notmuch.el\r
++++ b/notmuch.el\r
+@@ -50,7 +50,6 @@\r
+ (require 'cl)\r
+ (require 'mm-view)\r
+ (require 'message)\r
+-(require 'coolj)\r
\r
+ (defvar notmuch-show-mode-map\r
+   (let ((map (make-sparse-keymap)))\r
+@@ -157,6 +156,12 @@ collapse remaining lines into a button.")\r
+ (defvar notmuch-show-signatures-visible nil)\r
+ (defvar notmuch-show-headers-visible nil)\r
\r
++(defun notmuch-show-markup-body-hook '(notmuch-show-markup-citations-region)\r
++  "List of functions used to clean up body parts.\r
++\r
++Each is passed three arguments: the beginning of the region, the\r
++end of the region and the indetation depth.")\r
++\r
+ ; XXX: This should be a generic function in emacs somewhere, not here\r
+ (defun point-invisible-p ()\r
+   "Return whether the character at point is invisible.\r
+@@ -703,7 +708,6 @@ is what to put on the button."\r
+                    :type button-type)\r
+       )))\r
\r
+-\r
+ (defun notmuch-show-markup-citations-region (beg end depth)\r
+   "Markup citations, and up to one signature in the given region"\r
+   ;; it would be nice if the untabify was not required, but\r
+@@ -791,9 +795,7 @@ is what to put on the button."\r
+                           (mm-display-part mime-message))))\r
+                 )\r
+             (if (equal mime-type "text/plain")\r
+-                (progn\r
+-                  (coolj-wrap-region beg end)\r
+-                  (notmuch-show-markup-citations-region beg end depth)))\r
++                (run-hook-with-args 'notmuch-show-markup-body-hook beg end depth))\r
+               ; Advance to the next part (if any) (so the outer loop can\r
+               ; determine whether we've left the current message.\r
+               (if (re-search-forward notmuch-show-buttonize-begin-regexp nil t)\r
+-- \r
+1.6.6.1\r
+\r