[PATCH 1/2] emacs: Re-implement advance/rewind functions of notmuch-show-mode.
authorDavid Edmondson <dme@dme.org>
Thu, 29 Dec 2011 12:08:09 +0000 (12:08 +0000)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:41:24 +0000 (09:41 -0800)
63/73e679bd0c4a902459cc42b040fc1a647cd730 [new file with mode: 0644]

diff --git a/63/73e679bd0c4a902459cc42b040fc1a647cd730 b/63/73e679bd0c4a902459cc42b040fc1a647cd730
new file mode 100644 (file)
index 0000000..5821b93
--- /dev/null
@@ -0,0 +1,252 @@
+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 B02CB429E25\r
+       for <notmuch@notmuchmail.org>; Thu, 29 Dec 2011 04:08:18 -0800 (PST)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -0.7\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5\r
+       tests=[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 ET2v3gw7SuG0 for <notmuch@notmuchmail.org>;\r
+       Thu, 29 Dec 2011 04:08:17 -0800 (PST)\r
+Received: from mail-qw0-f53.google.com (mail-qw0-f53.google.com\r
+       [209.85.216.53]) (using TLSv1 with cipher RC4-SHA (128/128 bits))\r
+       (No client certificate requested)\r
+       by olra.theworths.org (Postfix) with ESMTPS id A983E431FB6\r
+       for <notmuch@notmuchmail.org>; Thu, 29 Dec 2011 04:08:17 -0800 (PST)\r
+Received: by qadb15 with SMTP id b15so10219471qad.5\r
+       for <notmuch@notmuchmail.org>; Thu, 29 Dec 2011 04:08:16 -0800 (PST)\r
+Received: by 10.224.212.10 with SMTP id gq10mr41984240qab.75.1325160495953;\r
+       Thu, 29 Dec 2011 04:08:15 -0800 (PST)\r
+Received: from hotblack-desiato.hh.sledj.net\r
+       (host81-149-164-25.in-addr.btopenworld.com. [81.149.164.25])\r
+       by mx.google.com with ESMTPS id ha3sm64862572qab.2.2011.12.29.04.08.14\r
+       (version=TLSv1/SSLv3 cipher=OTHER);\r
+       Thu, 29 Dec 2011 04:08:15 -0800 (PST)\r
+Received: by hotblack-desiato.hh.sledj.net (Postfix, from userid 30000)\r
+       id 60F96A0B37; Thu, 29 Dec 2011 12:08:12 +0000 (GMT)\r
+From: David Edmondson <dme@dme.org>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH 1/2] emacs: Re-implement advance/rewind functions of\r
+       notmuch-show-mode.\r
+Date: Thu, 29 Dec 2011 12:08:09 +0000\r
+Message-Id: <1325160490-23472-1-git-send-email-dme@dme.org>\r
+X-Mailer: git-send-email 1.7.7.3\r
+In-Reply-To: <1324665712-2419-1-git-send-email-dme@dme.org>\r
+References: <1324665712-2419-1-git-send-email-dme@dme.org>\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: Thu, 29 Dec 2011 12:08:18 -0000\r
+\r
+The advance/rewind functions had become complex, which made it hard to\r
+determine how they are expected to behave. Re-implement them simply\r
+(!) in order to poll user-experience and expectation.\r
+---\r
+\r
+Rework re-wind in light of discussion.\r
+\r
+ emacs/notmuch-show.el |  156 +++++++++++++++++++++++++++++++------------------\r
+ 1 files changed, 99 insertions(+), 57 deletions(-)\r
+\r
+diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el\r
+index 5502efd..60af88b 100644\r
+--- a/emacs/notmuch-show.el\r
++++ b/emacs/notmuch-show.el\r
+@@ -1151,39 +1151,57 @@ Some useful entries are:\r
+ ;; Commands typically bound to keys.\r
\r
+ (defun notmuch-show-advance ()\r
+-  "Advance through thread.\r
++  "Advance through the current thread.\r
\r
+-If the current message in the thread is not yet fully visible,\r
+-scroll by a near screenful to read more of the message.\r
++Scroll the current message if the end of it is not visible,\r
++otherwise move to the next message.\r
\r
+-Otherwise, (the end of the current message is already within the\r
+-current window), advance to the next open message."\r
++Return `t' if we are at the end of the last message, otherwise\r
++`nil'."\r
+   (interactive)\r
+-  (let* ((end-of-this-message (notmuch-show-message-bottom))\r
+-       (visible-end-of-this-message (1- end-of-this-message))\r
+-       (ret nil))\r
+-    (while (invisible-p visible-end-of-this-message)\r
+-      (setq visible-end-of-this-message\r
+-          (max (point-min)\r
+-               (1- (previous-single-char-property-change\r
+-                    visible-end-of-this-message 'invisible)))))\r
+-    (cond\r
+-     ;; Ideally we would test `end-of-this-message' against the result\r
+-     ;; of `window-end', but that doesn't account for the fact that\r
+-     ;; the end of the message might be hidden.\r
+-     ((and visible-end-of-this-message\r
+-         (> visible-end-of-this-message (window-end)))\r
+-      ;; The bottom of this message is not visible - scroll.\r
+-      (scroll-up nil))\r
+-\r
+-     ((not (= end-of-this-message (point-max)))\r
+-      ;; This is not the last message - move to the next visible one.\r
+-      (notmuch-show-next-open-message))\r
+-\r
+-     (t\r
+-      ;; This is the last message - change the return value\r
+-      (setq ret t)))\r
+-    ret))\r
++  (cond\r
++   ((eobp)\r
++    ;; We are at the end of the buffer - move to the next thread.\r
++    t)\r
++\r
++   ;; Ideally we would simply do:\r
++   ;;\r
++   ;;         ((> (notmuch-show-message-bottom) (window-end))\r
++   ;;\r
++   ;; here, but that fails if the trailing text in the buffer is\r
++   ;; invisible (`window-end' returns the last _visible_ character,\r
++   ;; which can then be smaller than `notmuch-show-message-bottom').\r
++   ;;\r
++   ;; So we need to find the last visible character of the message. We\r
++   ;; do this by searching backwards from `(1-\r
++   ;; notmuch-show-message-bottom)' for changes in the `invisible'\r
++   ;; property until we find a non-invisible character. When we find\r
++   ;; such a character we test to see whether it is visible in the\r
++   ;; window.\r
++   ;;\r
++   ;; Properties change between characters - the return value of\r
++   ;; `previous-single-char-property-change' points to the first\r
++   ;; character _inside_ the region with the `invisible' property\r
++   ;; set. To allow for this we step backwards one character upon\r
++   ;; finding the start of the invisible region and also at the start\r
++   ;; of the search.\r
++\r
++   ((let ((visible-bottom (1- (notmuch-show-message-bottom))))\r
++      (while (invisible-p visible-bottom)\r
++      (setq visible-bottom (max (point-min)\r
++                                (1- (previous-single-char-property-change\r
++                                     visible-bottom 'invisible)))))\r
++      (> visible-bottom (window-end)))\r
++    ;; The end of this message is not visible - scroll to show more of\r
++    ;; it.\r
++    (scroll-up)\r
++    nil)\r
++\r
++   (t\r
++    ;; All of the current message has been seen - show the start of\r
++    ;; the next open message.\r
++    (notmuch-show-next-open-message)\r
++    nil)))\r
\r
+ (defun notmuch-show-advance-and-archive ()\r
+   "Advance through thread and archive.\r
+@@ -1201,40 +1219,64 @@ shown."\r
+       (notmuch-show-archive-thread)))\r
\r
+ (defun notmuch-show-rewind ()\r
+-  "Backup through the thread, (reverse scrolling compared to \\[notmuch-show-advance-and-archive]).\r
++  "Move backwards through a thread, the counterpart to \\[notmuch-show-advance-and-archive]."\r
\r
+-Specifically, if the beginning of the previous email is fewer\r
+-than `window-height' lines from the current point, move to it\r
+-just like `notmuch-show-previous-message'.\r
+-\r
+-Otherwise, just scroll down a screenful of the current message.\r
+-\r
+-This command does not modify any message tags, (it does not undo\r
+-any effects from previous calls to\r
+-`notmuch-show-advance-and-archive'."\r
+   (interactive)\r
+-  (let ((start-of-message (notmuch-show-message-top))\r
+-      (start-of-window (window-start)))\r
++  (let ((start-of-message (notmuch-show-message-top)))\r
+     (cond\r
+-      ;; Either this message is properly aligned with the start of the\r
+-      ;; window or the start of this message is not visible on the\r
+-      ;; screen - scroll.\r
+-     ((or (= start-of-message start-of-window)\r
+-        (< start-of-message start-of-window))\r
++     ((= start-of-message (point))\r
++      ;; The cursor is at the start of the current message.\r
++      (let ((start-of-previous (save-excursion\r
++                               (while (and (notmuch-show-goto-message-previous)\r
++                                           (not (notmuch-show-message-visible-p))))\r
++                               (notmuch-show-message-top))))\r
++      ;; If the start of the previous open message is visible on\r
++      ;; screen, move the cursor there, but do not adjust or scroll\r
++      ;; the display.\r
++      (if (> start-of-previous (window-start))\r
++          (goto-char start-of-previous)\r
++\r
++        ;; Otherwise, the start of the previous open message is\r
++        ;; _not_ visible on screen.\r
++        ;;\r
++        ;; Scroll the window to show (some (more) of) the previous\r
++        ;; message and move up into it.\r
++        (scroll-down)\r
++        (forward-line -1)\r
++\r
++        ;; If the start of the previous message became visible on\r
++        ;; screen due to the scrolling, align it with the top of the\r
++        ;; window.\r
++        (if (> start-of-previous (window-start))\r
++            (progn\r
++              (goto-char start-of-previous)\r
++              (notmuch-show-message-adjust))\r
++          ;; Otherwise leave the cursor at the start of the window.\r
++          (goto-char (window-start))))))\r
++\r
++     ((< start-of-message (window-start))\r
++      ;; The start of the current message is not visible - scroll\r
++      ;; down.\r
+       (scroll-down)\r
+-      ;; If a small number of lines from the previous message are\r
+-      ;; visible, realign so that the top of the current message is at\r
+-      ;; the top of the screen.\r
+-      (if (<= (count-screen-lines (window-start) start-of-message)\r
+-            next-screen-context-lines)\r
++      ;; If the start of the current message became visible, align it\r
++      ;; with the top of the window.\r
++      (if (> start-of-message (window-start))\r
+         (progn\r
+-          (goto-char (notmuch-show-message-top))\r
+-          (notmuch-show-message-adjust)))\r
+-      ;; Move to the top left of the window.\r
+-      (goto-char (window-start)))\r
++          (goto-char start-of-message)\r
++          (notmuch-show-message-adjust))\r
++      ;; Otherwise leave the cursor at the start of the window.\r
++      (goto-char (window-start))))\r
++\r
++     ((>= start-of-message (window-start))\r
++      ;; The start of the current message is visible in the window.\r
++      ;;\r
++      ;; Move the cursor to the start of the current message, but do\r
++      ;; not adjust or scroll the display.\r
++      (goto-char start-of-message))\r
++\r
+      (t\r
+       ;; Move to the previous message.\r
+-      (notmuch-show-previous-message)))))\r
++      (notmuch-show-previous-open-message)))))\r
\r
+ (defun notmuch-show-reply (&optional prompt-for-sender)\r
+   "Reply to the current message."\r
+-- \r
+1.7.7.3\r
+\r