From 696bf570e3a070d8b15e65575ec95a7865076668 Mon Sep 17 00:00:00 2001 From: Dmitry Kurochkin Date: Sat, 4 Feb 2012 11:36:37 +0400 Subject: [PATCH] [PATCH v2 2/2] emacs: fix `notmuch-wash-region-to-button' to work at beginning of buffer --- b6/8784c87d88b79ba7224ea9fcd29c157fb4844c | 163 ++++++++++++++++++++++ 1 file changed, 163 insertions(+) create mode 100644 b6/8784c87d88b79ba7224ea9fcd29c157fb4844c diff --git a/b6/8784c87d88b79ba7224ea9fcd29c157fb4844c b/b6/8784c87d88b79ba7224ea9fcd29c157fb4844c new file mode 100644 index 000000000..80b435ded --- /dev/null +++ b/b6/8784c87d88b79ba7224ea9fcd29c157fb4844c @@ -0,0 +1,163 @@ +Return-Path: +X-Original-To: notmuch@notmuchmail.org +Delivered-To: notmuch@notmuchmail.org +Received: from localhost (localhost [127.0.0.1]) + by olra.theworths.org (Postfix) with ESMTP id 37131431FBF + for ; Fri, 3 Feb 2012 23:38:08 -0800 (PST) +X-Virus-Scanned: Debian amavisd-new at olra.theworths.org +X-Spam-Flag: NO +X-Spam-Score: -0.799 +X-Spam-Level: +X-Spam-Status: No, score=-0.799 tagged_above=-999 required=5 + tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, + FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled +Received: from olra.theworths.org ([127.0.0.1]) + by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) + with ESMTP id bxOaV2hPmw1a for ; + Fri, 3 Feb 2012 23:38:06 -0800 (PST) +Received: from mail-bk0-f53.google.com (mail-bk0-f53.google.com + [209.85.214.53]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) + (No client certificate requested) + by olra.theworths.org (Postfix) with ESMTPS id A78BA431FBD + for ; Fri, 3 Feb 2012 23:38:01 -0800 (PST) +Received: by mail-bk0-f53.google.com with SMTP id 11so4129597bke.26 + for ; Fri, 03 Feb 2012 23:38:01 -0800 (PST) +DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; + h=from:to:subject:date:message-id:x-mailer:in-reply-to:references; + bh=aapfVS/zekS+J/nz9YvJRaJhbTb24pMJyTWE1Rky5Bs=; + b=Y0D3fdpe8TGR3I81aQPAxt08p0+p5F3PTBMhIjtZaRKGL/QFQAr7b/Xm4e/hTHd2HN + l6bs9c1C3Rjew1h7/UPtv2sWebmG8Fk2e4ejUjMVjmX6CUVnqnjCTxFJf3kPffe+tNp0 + D0+mvIgFFPLes1yUr+qoHLj7IrlSgdoLI62UM= +Received: by 10.204.128.202 with SMTP id l10mr4817540bks.116.1328341081326; + Fri, 03 Feb 2012 23:38:01 -0800 (PST) +Received: from localhost ([91.144.186.21]) + by mx.google.com with ESMTPS id 20sm23921774bkr.0.2012.02.03.23.38.00 + (version=TLSv1/SSLv3 cipher=OTHER); + Fri, 03 Feb 2012 23:38:00 -0800 (PST) +From: Dmitry Kurochkin +To: notmuch@notmuchmail.org +Subject: [PATCH v2 2/2] emacs: fix `notmuch-wash-region-to-button' to work at + beginning of buffer +Date: Sat, 4 Feb 2012 11:36:37 +0400 +Message-Id: <1328340997-29004-3-git-send-email-dmitry.kurochkin@gmail.com> +X-Mailer: git-send-email 1.7.9 +In-Reply-To: <1328340997-29004-1-git-send-email-dmitry.kurochkin@gmail.com> +References: <1327926286-16680-1-git-send-email-dmitry.kurochkin@gmail.com> + <1328340997-29004-1-git-send-email-dmitry.kurochkin@gmail.com> +X-BeenThere: notmuch@notmuchmail.org +X-Mailman-Version: 2.1.13 +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: Sat, 04 Feb 2012 07:38:08 -0000 + +`Notmuch-wash-region-to-button' is the function that creates hidden +regions with buttons for signatures, citations and original messages. +Before the change, it did not work correctly if the to-be-hidden +region started at the beginning of a message: the visibility toggle +button was hidden as well. The patch fixes this. There are two parts +in the fix: + +* Use `insert-before-markers' instead of `insert' for creating the + button, so that it does not get added to the hidden overlay. + +* Stop using PREFIX argument for adding a newline before the button. + The newline should not be added before a button at the beginning of + buffer. + +The corresponding test is fixed now. +--- + emacs/notmuch-wash.el | 24 ++++++++++++++---------- + test/emacs-show | 1 - + 2 files changed, 14 insertions(+), 11 deletions(-) + +diff --git a/emacs/notmuch-wash.el b/emacs/notmuch-wash.el +index 67143e5..56981d0 100644 +--- a/emacs/notmuch-wash.el ++++ b/emacs/notmuch-wash.el +@@ -136,12 +136,13 @@ collapse the remaining lines into a button.") + (lines-count (count-lines (overlay-start overlay) (overlay-end overlay)))) + (format label-format lines-count))) + +-(defun notmuch-wash-region-to-button (msg beg end type prefix) ++(defun notmuch-wash-region-to-button (msg beg end type &optional prefix) + "Auxiliary function to do the actual making of overlays and buttons + + BEG and END are buffer locations. TYPE should a string, either +-\"citation\" or \"signature\". PREFIX is some arbitrary text to +-insert before the button, probably for indentation." ++\"citation\" or \"signature\". Optional PREFIX is some arbitrary ++text to insert before the button, probably for indentation. Note ++that PREFIX should not include a newline." + + ;; This uses some slightly tricky conversions between strings and + ;; symbols because of the way the button code works. Note that +@@ -160,12 +161,15 @@ insert before the button, probably for indentation." + (overlay-put overlay 'type type) + (goto-char (1+ end)) + (save-excursion +- (goto-char (1- beg)) +- (insert prefix) +- (insert-button (notmuch-wash-button-label overlay) ++ (goto-char beg) ++ (if prefix ++ (insert-before-markers prefix)) ++ (let ((button-beg (point))) ++ (insert-before-markers (notmuch-wash-button-label overlay) "\n") ++ (make-button button-beg (1- (point)) + 'invisibility-spec invis-spec + 'overlay overlay +- :type button-type)))) ++ :type button-type))))) + + (defun notmuch-wash-excerpt-citations (msg depth) + "Excerpt citations and up to one signature." +@@ -177,7 +181,7 @@ insert before the button, probably for indentation." + (msg-end (point-max)) + (msg-lines (count-lines msg-start msg-end))) + (notmuch-wash-region-to-button +- msg msg-start msg-end "original" "\n"))) ++ msg msg-start msg-end "original"))) + (while (and (< (point) (point-max)) + (re-search-forward notmuch-wash-citation-regexp nil t)) + (let* ((cite-start (match-beginning 0)) +@@ -194,7 +198,7 @@ insert before the button, probably for indentation." + (forward-line (- notmuch-wash-citation-lines-suffix)) + (notmuch-wash-region-to-button + msg hidden-start (point-marker) +- "citation" "\n"))))) ++ "citation"))))) + (if (and (not (eobp)) + (re-search-forward notmuch-wash-signature-regexp nil t)) + (let* ((sig-start (match-beginning 0)) +@@ -208,7 +212,7 @@ insert before the button, probably for indentation." + (overlay-put (make-overlay sig-start-marker sig-end-marker) 'face 'message-cited-text) + (notmuch-wash-region-to-button + msg sig-start-marker sig-end-marker +- "signature" "\n")))))) ++ "signature")))))) + + ;; + +diff --git a/test/emacs-show b/test/emacs-show +index 9800575..5700d2e 100755 +--- a/test/emacs-show ++++ b/test/emacs-show +@@ -4,7 +4,6 @@ test_description="Testing emacs notmuch-show view" + . test-lib.sh + + test_begin_subtest "Hiding Original Message region at beginning of a message" +-test_subtest_known_broken + message_id='OriginalMessageHiding.1@notmuchmail.org' + add_message \ + [id]="$message_id" \ +-- +1.7.9 + -- 2.26.2