[PATCH 2/2] emacs: fix `notmuch-wash-region-to-button' to work at beginning of buffer
authorDmitry Kurochkin <dmitry.kurochkin@gmail.com>
Mon, 30 Jan 2012 12:24:46 +0000 (16:24 +0400)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:43:39 +0000 (09:43 -0800)
5e/5f29a06a202b1870caec2b7c9eeb5ee851a19c [new file with mode: 0644]

diff --git a/5e/5f29a06a202b1870caec2b7c9eeb5ee851a19c b/5e/5f29a06a202b1870caec2b7c9eeb5ee851a19c
new file mode 100644 (file)
index 0000000..aff676d
--- /dev/null
@@ -0,0 +1,162 @@
+Return-Path: <dmitry.kurochkin@gmail.com>\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 411C941ED81\r
+       for <notmuch@notmuchmail.org>; Mon, 30 Jan 2012 04:26:11 -0800 (PST)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -0.799\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-0.799 tagged_above=-999 required=5\r
+       tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1,\r
+       FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled\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 yXM8tcPiQJf5 for <notmuch@notmuchmail.org>;\r
+       Mon, 30 Jan 2012 04:26:09 -0800 (PST)\r
+Received: from mail-bk0-f53.google.com (mail-bk0-f53.google.com\r
+       [209.85.214.53]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
+       (No client certificate requested)\r
+       by olra.theworths.org (Postfix) with ESMTPS id 3ABA5429E54\r
+       for <notmuch@notmuchmail.org>; Mon, 30 Jan 2012 04:26:05 -0800 (PST)\r
+Received: by mail-bk0-f53.google.com with SMTP id 11so1334291bke.26\r
+       for <notmuch@notmuchmail.org>; Mon, 30 Jan 2012 04:26:04 -0800 (PST)\r
+DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma;\r
+       h=from:to:subject:date:message-id:x-mailer:in-reply-to:references;\r
+       bh=fqAnqCvQC2ewoLsKIaOU+SrpGYlVP7DRsx06mtWLLZs=;\r
+       b=NSqsd8MiMUxcxiKa0+pyi18V+8FUeLVtKwTewbsAXXlvf7MaRwTCKB5u/SZRmfYbBl\r
+       bUoHLbHrVyvje0727qz+hHbMudONJ9Zkd7t+ZmjhfQDRbMFeguumTr0cU1Xgy7Rn+ZPN\r
+       ByU/ygRVBBTpTVYrqJ3DOjN5N9wbWstO7Zp0A=\r
+Received: by 10.204.151.218 with SMTP id d26mr8702346bkw.64.1327926364839;\r
+       Mon, 30 Jan 2012 04:26:04 -0800 (PST)\r
+Received: from localhost ([91.144.186.21])\r
+       by mx.google.com with ESMTPS id cz3sm37301847bkb.3.2012.01.30.04.26.03\r
+       (version=TLSv1/SSLv3 cipher=OTHER);\r
+       Mon, 30 Jan 2012 04:26:04 -0800 (PST)\r
+From: Dmitry Kurochkin <dmitry.kurochkin@gmail.com>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH 2/2] emacs: fix `notmuch-wash-region-to-button' to work at\r
+       beginning of buffer\r
+Date: Mon, 30 Jan 2012 16:24:46 +0400\r
+Message-Id: <1327926286-16680-3-git-send-email-dmitry.kurochkin@gmail.com>\r
+X-Mailer: git-send-email 1.7.8.3\r
+In-Reply-To: <1327926286-16680-1-git-send-email-dmitry.kurochkin@gmail.com>\r
+References: <1327926286-16680-1-git-send-email-dmitry.kurochkin@gmail.com>\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: Mon, 30 Jan 2012 12:26:11 -0000\r
+\r
+`Notmuch-wash-region-to-button' is the function that creates hidden\r
+regions with buttons for signatures, citations and original messages.\r
+Before the change, it did not work correctly if the to-be-hidden\r
+region started at the beginning of a message: the visibility toggle\r
+button was hidden as well.  The patch fixes this.  There are two parts\r
+in the fix:\r
+\r
+* Use `insert-before-markers' instead of `insert' for creating the\r
+  button, so that it does not get added to the hidden overlay.\r
+\r
+* Stop using PREFIX argument for adding a newline before the button.\r
+  The newline should not be added before a button at the beginning of\r
+  buffer.\r
+\r
+The corresponding test is fixed now.\r
+---\r
+ emacs/notmuch-wash.el |   24 ++++++++++++++----------\r
+ test/emacs-show       |    1 -\r
+ 2 files changed, 14 insertions(+), 11 deletions(-)\r
+\r
+diff --git a/emacs/notmuch-wash.el b/emacs/notmuch-wash.el\r
+index 5c1e830..9d3d13f 100644\r
+--- a/emacs/notmuch-wash.el\r
++++ b/emacs/notmuch-wash.el\r
+@@ -136,12 +136,13 @@ collapse the remaining lines into a button.")\r
+        (lines-count (count-lines (overlay-start overlay) (overlay-end overlay))))\r
+     (format label-format lines-count)))\r
\r
+-(defun notmuch-wash-region-to-button (msg beg end type prefix)\r
++(defun notmuch-wash-region-to-button (msg beg end type &optional prefix)\r
+   "Auxiliary function to do the actual making of overlays and buttons\r
\r
+ BEG and END are buffer locations. TYPE should a string, either\r
+-\"citation\" or \"signature\". PREFIX is some arbitrary text to\r
+-insert before the button, probably for indentation."\r
++\"citation\" or \"signature\". Optional PREFIX is some arbitrary\r
++text to insert before the button, probably for indentation.  Note\r
++that PREFIX should not include a newline."\r
\r
+   ;; This uses some slightly tricky conversions between strings and\r
+   ;; symbols because of the way the button code works. Note that\r
+@@ -160,12 +161,15 @@ insert before the button, probably for indentation."\r
+     (overlay-put overlay 'type type)\r
+     (goto-char (1+ end))\r
+     (save-excursion\r
+-      (goto-char (1- beg))\r
+-      (insert prefix)\r
+-      (insert-button (notmuch-wash-button-label overlay)\r
++      (goto-char beg)\r
++      (if prefix\r
++        (insert-before-markers prefix))\r
++      (let ((button-beg (point)))\r
++      (insert-before-markers (notmuch-wash-button-label overlay) "\n")\r
++      (make-button button-beg (1- (point))\r
+                    'invisibility-spec invis-spec\r
+                    'overlay overlay\r
+-                   :type button-type))))\r
++                   :type button-type)))))\r
\r
+ (defun notmuch-wash-excerpt-citations (msg depth)\r
+   "Excerpt citations and up to one signature."\r
+@@ -177,7 +181,7 @@ insert before the button, probably for indentation."\r
+            (msg-end (point-max))\r
+            (msg-lines (count-lines msg-start msg-end)))\r
+       (notmuch-wash-region-to-button\r
+-       msg msg-start msg-end "original" "\n")))\r
++       msg msg-start msg-end "original")))\r
+   (while (and (< (point) (point-max))\r
+             (re-search-forward notmuch-wash-citation-regexp nil t))\r
+     (let* ((cite-start (match-beginning 0))\r
+@@ -194,7 +198,7 @@ insert before the button, probably for indentation."\r
+         (forward-line (- notmuch-wash-citation-lines-suffix))\r
+         (notmuch-wash-region-to-button\r
+          msg hidden-start (point-marker)\r
+-         "citation" "\n")))))\r
++         "citation")))))\r
+   (if (and (not (eobp))\r
+          (re-search-forward notmuch-wash-signature-regexp nil t))\r
+       (let* ((sig-start (match-beginning 0))\r
+@@ -208,7 +212,7 @@ insert before the button, probably for indentation."\r
+             (overlay-put (make-overlay sig-start-marker sig-end-marker) 'face 'message-cited-text)\r
+             (notmuch-wash-region-to-button\r
+              msg sig-start-marker sig-end-marker\r
+-             "signature" "\n"))))))\r
++             "signature"))))))\r
\r
+ ;;\r
\r
+diff --git a/test/emacs-show b/test/emacs-show\r
+index 9800575..5700d2e 100755\r
+--- a/test/emacs-show\r
++++ b/test/emacs-show\r
+@@ -4,7 +4,6 @@ test_description="Testing emacs notmuch-show view"\r
+ . test-lib.sh\r
\r
+ test_begin_subtest "Hiding Original Message region at beginning of a message"\r
+-test_subtest_known_broken\r
+ message_id='OriginalMessageHiding.1@notmuchmail.org'\r
+ add_message \\r
+     [id]="$message_id" \\r
+-- \r
+1.7.8.3\r
+\r