unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
From: David Edmondson <dme@dme.org>
To: notmuch@notmuchmail.org
Subject: [PATCH v1 2/4] emacs: wash: Improved citation tidying
Date: Sun, 27 Aug 2017 14:46:21 +0100	[thread overview]
Message-ID: <20170827134623.20041-3-dme@dme.org> (raw)
In-Reply-To: <20170827134623.20041-1-dme@dme.org>

Improve the citation tidying by being more aggressive about the
changes made:
- collapse all citation leaders to the canonical form (stripping out
  intervening spaces, for example),
- ensure that a blank line exists before and after every block of
  cited text.
---
 emacs/notmuch-wash.el | 42 ++++++++++++++++++++++++++++++++++--------
 1 file changed, 34 insertions(+), 8 deletions(-)

diff --git a/emacs/notmuch-wash.el b/emacs/notmuch-wash.el
index 5f8b9267..c449163f 100644
--- a/emacs/notmuch-wash.el
+++ b/emacs/notmuch-wash.el
@@ -300,29 +300,55 @@ that PREFIX should not include a newline."
 
 Perform several transformations on the message body:
 
+- Remove any leading space from lines with citation leaders,
+- Collapse citation leaders to their minimal form (repeated >
+  followed by a space),
 - Remove lines of repeated citation leaders with no other
   content,
-- Remove citation leaders standing alone before a block of cited
-  text,
-- Remove citation trailers standing alone after a block of cited
-  text."
+- Remove citation leaders standing alone before and after a block
+  of cited text,
+- Ensure that a blank line separates a block of cited text from
+  non-cited text."
+
+  ;; Remove any leading spaces on citation lines.
+  (goto-char (point-min))
+  (while (re-search-forward "^ +>" nil t)
+    (replace-match ">"))
+
+  ;; Collapse all citation leaders to the minimal form.
+  (goto-char (point-min))
+  (while (re-search-forward "^>[> ]*>" nil t)
+    (replace-match (remove ?  (match-string 0))))
 
   ;; Remove lines of repeated citation leaders with no other content.
   (goto-char (point-min))
-  (while (re-search-forward "\\(^>[> ]*\n\\)\\{2,\\}" nil t)
+  (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)
+  (while (re-search-forward "\\(\n\\|^[^>\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")))
+  (while (re-search-forward "\\(^>+ ?\n\\)\\(^$\\|^[^>].*\\)" nil t)
+    (replace-match "\\2"))
+
+  ;; Ensure that a blank line separates a citation and any following
+  ;; text.
+  (goto-char (point-min))
+  (while (re-search-forward "\\(^>+ .*?\n\\)\\([^>\n]\\)" nil t)
+    (replace-match "\\1\n\\2"))
+
+  ;; Ensure that a blank line separates any text and a following
+  ;; citation.
+  (goto-char (point-min))
+  (while (re-search-forward "\\(^[^>\n].+?\n\\)>" nil t)
+    (replace-match "\\1\n>" ""))
+  )
 
 ;;
 
-- 
2.11.0

  parent reply	other threads:[~2017-08-27 13:46 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-08-27 13:46 [PATCH v1 0/4] Improved citation washing David Edmondson
2017-08-27 13:46 ` [PATCH v1 1/4] emacs: wash: Wrap long lines after tidying citations David Edmondson
2017-09-04 11:31   ` David Bremner
2017-08-27 13:46 ` David Edmondson [this message]
2017-08-27 13:46 ` [PATCH v1 3/4] emacs: test: Update expected output David Edmondson
2017-09-04 11:34   ` David Bremner
2017-08-27 13:46 ` [PATCH v1 4/4] emacs: reply: Allow washing of inserted text parts during reply David Edmondson
2017-09-04 11:45 ` [PATCH v1 0/4] Improved citation washing David Bremner

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=20170827134623.20041-3-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).