From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by arlo.cworth.org (Postfix) with ESMTP id 79C6D6DE0A5B for ; Sun, 27 Aug 2017 06:46:32 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at cworth.org X-Spam-Flag: NO X-Spam-Score: 0.461 X-Spam-Level: X-Spam-Status: No, score=0.461 tagged_above=-999 required=5 tests=[AWL=-0.172, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_NEUTRAL=0.652, UNPARSEABLE_RELAY=0.001] autolearn=disabled Received: from arlo.cworth.org ([127.0.0.1]) by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id WiRRWhWxO6q8 for ; Sun, 27 Aug 2017 06:46:32 -0700 (PDT) Received: from mail-wm0-f65.google.com (mail-wm0-f65.google.com [74.125.82.65]) by arlo.cworth.org (Postfix) with ESMTPS id 99FED6DE012F for ; Sun, 27 Aug 2017 06:46:31 -0700 (PDT) Received: by mail-wm0-f65.google.com with SMTP id j72so4433896wmi.3 for ; Sun, 27 Aug 2017 06:46:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dme-org.20150623.gappssmtp.com; s=20150623; h=from:to:subject:date:message-id:in-reply-to:references; bh=BYWz5Aq6QGty0VAB8I1WAvfQgvbsx47J1u0xYZUpmkM=; b=UO38ffIp4LXbzTq6IAz1DRIF1+Jf/8XbsCfvngKq06+hWyNtQ1JDexBrqbJRqpWaW2 GbFhnNyktCc08sjCInkp6AUszg9bvF4or/GRe2PdBee0Nbppdfi1LYbPGB4Ro/kMGCfv U6Wf4XPMNIu6oYPxxUFRm0NqsrQNliFkkdpOwSDFzQlrRbuJ/Z93i5qRYWBQiBSWhhUC jdiv+de/ovmZmUpNMZWALAzpZhL86L01HzsovPQpI+ROHFbs0wCJ0nsU7yCQb0ouQG6K BKkGDDRZQa1XqI/uwt053yklVF9tX8tlcv79maOAtn++Zs2h6U5Vd17MbKWFI2S3n+Uk PPnQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=BYWz5Aq6QGty0VAB8I1WAvfQgvbsx47J1u0xYZUpmkM=; b=XjVjvL7LX2B46H0+aZj3JxRFYgaQKX3gybWwc6AB3ehquehuZ/F/zywH3nTSHRqo2i lyBgUFH+Go0Q5Q4x12lPmlSw8si9f/u8TzLodNkYRv3s/my6R3x+1hPZZ/zM/JGpI1Aa wvH7CauTZiJ87VZXcBhfbk1O+pPsXrF4LSIBAUBVd2J38OgFQmiFw6xzhod6hlvSBT6y G2NMbD7e4SrYhbA9lzujmYcQRLsoQes5eWxQNJWgF6E81ILPVBIqGU6grnbI3YwkMoz0 sO6gVsQUa8m2tZCWHDjL+ubev3pjsYt7apf1Bl3d2HriinwnwuOWgCRAdqPrvZqVI1ze gQJw== X-Gm-Message-State: AHYfb5gWY0vHdA72iJWz6ID38wSBkTOSxtkB3jm7Y7IIoIHkDACJi0H5 SqP0Xf1fTF8ADcLiKKarZA== X-Received: by 10.80.152.70 with SMTP id h6mr4021297edb.73.1503841589888; Sun, 27 Aug 2017 06:46:29 -0700 (PDT) Received: from disaster-area.hh.sledj.net (disaster-area.hh.sledj.net. [81.149.164.25]) by smtp.gmail.com with ESMTPSA id g44sm7459411eda.4.2017.08.27.06.46.28 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 27 Aug 2017 06:46:28 -0700 (PDT) Received: from localhost (disaster-area.hh.sledj.net [local]) by disaster-area.hh.sledj.net (OpenSMTPD) with ESMTPA id c7b83492 for ; Sun, 27 Aug 2017 13:46:24 +0000 (UTC) From: David Edmondson To: notmuch@notmuchmail.org Subject: [PATCH v1 2/4] emacs: wash: Improved citation tidying Date: Sun, 27 Aug 2017 14:46:21 +0100 Message-Id: <20170827134623.20041-3-dme@dme.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170827134623.20041-1-dme@dme.org> References: <20170827134623.20041-1-dme@dme.org> X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 27 Aug 2017 13:46:32 -0000 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