]> git.notmuchmail.org Git - notmuch/blobdiff - notmuch.el
emacs: Fix backspace to not scroll more than the previous message
[notmuch] / notmuch.el
index 7723730f3e92f3da198df9353ea296c6298154aa..c611dcc2cc72ebde11568b3e42f2fa6bb0f70f1c 100644 (file)
     (define-key map "+" 'notmuch-show-add-tag)
     (define-key map "x" 'notmuch-show-archive-thread-then-exit)
     (define-key map "a" 'notmuch-show-archive-thread)
     (define-key map "+" 'notmuch-show-add-tag)
     (define-key map "x" 'notmuch-show-archive-thread-then-exit)
     (define-key map "a" 'notmuch-show-archive-thread)
-    (define-key map "p" 'notmuch-show-previous-message)
-    (define-key map "n" 'notmuch-show-next-message)
+    (define-key map "P" 'notmuch-show-previous-message)
+    (define-key map "N" 'notmuch-show-next-message)
+    (define-key map "p" 'notmuch-show-previous-open-message)
+    (define-key map "n" 'notmuch-show-next-open-message)
     (define-key map (kbd "DEL") 'notmuch-show-rewind)
     (define-key map " " 'notmuch-show-advance-and-archive)
     map)
     (define-key map (kbd "DEL") 'notmuch-show-rewind)
     (define-key map " " 'notmuch-show-advance-and-archive)
     map)
@@ -523,7 +525,7 @@ Returns nil if already on the last message in the buffer."
     nil))
 
 (defun notmuch-show-next-message ()
     nil))
 
 (defun notmuch-show-next-message ()
-  "Advance to the beginning of the next message in the buffer.
+  "Advance to the next message (whether open or closed)
 and remove the unread tag from that message.
 
 Moves to the last visible character of the current message if
 and remove the unread tag from that message.
 
 Moves to the last visible character of the current message if
@@ -548,7 +550,7 @@ message if already within the last message in the buffer."
       (point))))
 
 (defun notmuch-show-next-unread-message ()
       (point))))
 
 (defun notmuch-show-next-unread-message ()
-  "Advance to the beginning of the next unread message in the buffer.
+  "Advance to the next unread message.
 
 Moves to the last visible character of the current message if
 there are no more unread messages past the current point."
 
 Moves to the last visible character of the current message if
 there are no more unread messages past the current point."
@@ -561,17 +563,22 @@ there are no more unread messages past the current point."
   (notmuch-show-mark-read))
 
 (defun notmuch-show-next-open-message ()
   (notmuch-show-mark-read))
 
 (defun notmuch-show-next-open-message ()
-  "Advance to the next open message (that is, body is not invisible)."
+  "Advance to the next open message (that is, body is visible).
+
+Moves to the last visible character of the final message in the buffer
+if there are no more open messages."
+  (interactive)
   (while (and (notmuch-show-next-message-without-marking-read)
              (not (notmuch-show-message-open-p))))
   (notmuch-show-mark-read))
 
   (while (and (notmuch-show-next-message-without-marking-read)
              (not (notmuch-show-message-open-p))))
   (notmuch-show-mark-read))
 
-(defun notmuch-show-previous-message ()
+(defun notmuch-show-previous-message-without-marking-read ()
   "Backup to the beginning of the previous message in the buffer.
 
 If within a message rather than at the beginning of it, then
   "Backup to the beginning of the previous message in the buffer.
 
 If within a message rather than at the beginning of it, then
-simply move to the beginning of the current message."
-  (interactive)
+simply move to the beginning of the current message.
+
+Returns nil if already on the first message in the buffer."
   (let ((start (point)))
     (notmuch-show-move-to-current-message-summary-line)
     (if (not (< (point) start))
   (let ((start (point)))
     (notmuch-show-move-to-current-message-summary-line)
     (if (not (< (point) start))
@@ -580,8 +587,22 @@ simply move to the beginning of the current message."
          (re-search-backward notmuch-show-message-begin-regexp nil t)
          (re-search-backward notmuch-show-message-begin-regexp nil t)
          (notmuch-show-move-to-current-message-summary-line)
          (re-search-backward notmuch-show-message-begin-regexp nil t)
          (re-search-backward notmuch-show-message-begin-regexp nil t)
          (notmuch-show-move-to-current-message-summary-line)
-         ))
-    (recenter 0)))
+         (recenter 0)
+         (if (= (point) start)
+             nil
+           t))
+      (recenter 0)
+      nil)))
+
+(defun notmuch-show-previous-message ()
+  "Backup to the previous message (whether open or closed)
+and remove the unread tag from that message.
+
+If within a message rather than at the beginning of it, then
+simply move to the beginning of the current message."
+  (interactive)
+  (notmuch-show-previous-message-without-marking-read)
+  (notmuch-show-mark-read))
 
 (defun notmuch-show-find-previous-message ()
   "Returns the position of the previous message in the buffer.
 
 (defun notmuch-show-find-previous-message ()
   "Returns the position of the previous message in the buffer.
@@ -594,9 +615,19 @@ it."
   ; Looks like we have to use both.
   (save-excursion
     (save-window-excursion
   ; Looks like we have to use both.
   (save-excursion
     (save-window-excursion
-      (notmuch-show-previous-message)
+      (notmuch-show-previous-message-without-marking-read)
       (point))))
 
       (point))))
 
+(defun notmuch-show-previous-open-message ()
+  "Backup to previous open message (that is, body is visible).
+
+Moves to the first message in the buffer if there are no previous
+open messages."
+  (interactive)
+  (while (and (notmuch-show-previous-message-without-marking-read)
+             (not (notmuch-show-message-open-p))))
+  (notmuch-show-mark-read))
+
 (defun notmuch-show-rewind ()
   "Backup through the thread, (reverse scrolling compared to \\[notmuch-show-advance-and-archive]).
 
 (defun notmuch-show-rewind ()
   "Backup through the thread, (reverse scrolling compared to \\[notmuch-show-advance-and-archive]).
 
@@ -616,7 +647,13 @@ any effects from previous calls to
          (condition-case nil
              (scroll-down nil)
            ((beginning-of-buffer) nil))
          (condition-case nil
              (scroll-down nil)
            ((beginning-of-buffer) nil))
-         (goto-char (window-start)))
+         (goto-char (window-start))
+         ; Because count-lines counts invivisible lines, we may have
+         ; scrolled to far. If so., notice this and fix it up.
+         (if (< (point) previous)
+             (progn
+               (goto-char previous)
+               (recenter 0))))
       (notmuch-show-previous-message))))
 
 (defun notmuch-show-advance-and-archive ()
       (notmuch-show-previous-message))))
 
 (defun notmuch-show-advance-and-archive ()
@@ -828,8 +865,8 @@ is what to put on the button."
 
 (defun notmuch-show-markup-body (depth match btn)
   "Markup a message body, (indenting, buttonizing citations,
 
 (defun notmuch-show-markup-body (depth match btn)
   "Markup a message body, (indenting, buttonizing citations,
-etc.), and conditionally hiding the body itself if the message
-has been read and does not match the current search.
+etc.), and hiding the body itself if the message does not match
+the current search.
 
 DEPTH specifies the depth at which this message appears in the
 tree of the current thread, (the top-level messages have depth 0
 
 DEPTH specifies the depth at which this message appears in the
 tree of the current thread, (the top-level messages have depth 0
@@ -850,7 +887,7 @@ before the delimiter marking the beginning of the body."
         (overlay-put (make-overlay beg end)
                      'invisible invis-spec)
         (button-put btn 'invisibility-spec invis-spec)
         (overlay-put (make-overlay beg end)
                      'invisible invis-spec)
         (button-put btn 'invisibility-spec invis-spec)
-        (if (not (or (notmuch-show-message-unread-p) match))
+        (if (not match)
             (add-to-invisibility-spec invis-spec)))
       (set-marker beg nil)
       (set-marker end nil)
             (add-to-invisibility-spec invis-spec)))
       (set-marker beg nil)
       (set-marker end nil)