(define-key map (kbd "C-p") 'notmuch-show-previous-line)
(define-key map "q" 'kill-this-buffer)
(define-key map "s" 'notmuch-show-toggle-signatures-visible)
+ (define-key map "w" 'notmuch-show-view-raw-message)
(define-key map "x" 'kill-this-buffer)
(define-key map "+" 'notmuch-show-add-tag)
(define-key map "-" 'notmuch-show-remove-tag)
+ (define-key map (kbd "DEL") 'notmuch-show-rewind)
(define-key map " " 'notmuch-show-advance-marking-read-and-archiving)
map)
"Keymap for \"notmuch show\" buffers.")
(fset 'notmuch-show-mode-map notmuch-show-mode-map)
-(defvar notmuch-show-message-begin-regexp "\fmessage{")
-(defvar notmuch-show-message-end-regexp "\fmessage}")
-(defvar notmuch-show-header-begin-regexp "\fheader{")
-(defvar notmuch-show-header-end-regexp "\fheader}")
-(defvar notmuch-show-body-begin-regexp "\fbody{")
-(defvar notmuch-show-body-end-regexp "\fbody}")
-(defvar notmuch-show-attachment-begin-regexp "\fattachment{")
-(defvar notmuch-show-attachment-end-regexp "\fattachment}")
-(defvar notmuch-show-part-begin-regexp "\fpart{")
-(defvar notmuch-show-part-end-regexp "\fpart}")
-(defvar notmuch-show-marker-regexp "\f\\(message\\|header\\|body\\|attachment\\|part\\)[{}].*$")
-
-(defvar notmuch-show-id-regexp "ID: \\(.*\\)$")
-(defvar notmuch-show-tags-regexp "(\\([^)]*\\))$")
+(defvar notmuch-show-signature-lines-max 6
+ "Maximum length of signature that will be hidden by default.")
+
+(set 'notmuch-show-message-begin-regexp "\fmessage{")
+(set 'notmuch-show-message-end-regexp "\fmessage}")
+(set 'notmuch-show-header-begin-regexp "\fheader{")
+(set 'notmuch-show-header-end-regexp "\fheader}")
+(set 'notmuch-show-body-begin-regexp "\fbody{")
+(set 'notmuch-show-body-end-regexp "\fbody}")
+(set 'notmuch-show-attachment-begin-regexp "\fattachment{")
+(set 'notmuch-show-attachment-end-regexp "\fattachment}")
+(set 'notmuch-show-part-begin-regexp "\fpart{")
+(set 'notmuch-show-part-end-regexp "\fpart}")
+(set 'notmuch-show-marker-regexp "\f\\(message\\|header\\|body\\|attachment\\|part\\)[{}].*$")
+
+(set 'notmuch-show-id-regexp "ID: \\([^ ]*\\)")
+(set 'notmuch-show-filename-regexp "Filename: \\(.*\\)$")
+(set 'notmuch-show-tags-regexp "(\\([^)]*\\))$")
; XXX: This should be a generic function in emacs somewhere, not here
(defun point-invisible-p ()
(re-search-forward notmuch-show-id-regexp)
(buffer-substring (match-beginning 1) (match-end 1))))
+(defun notmuch-show-get-filename ()
+ (save-excursion
+ (beginning-of-line)
+ (if (not (looking-at notmuch-show-message-begin-regexp))
+ (re-search-backward notmuch-show-message-begin-regexp))
+ (re-search-forward notmuch-show-filename-regexp)
+ (buffer-substring (match-beginning 1) (match-end 1))))
+
(defun notmuch-show-set-tags (tags)
(save-excursion
(beginning-of-line)
(switch-to-buffer parent-buffer)
(notmuch-search-show-thread)))))
+(defun notmuch-show-view-raw-message ()
+ "View the raw email of the current message."
+ (interactive)
+ (view-file (notmuch-show-get-filename)))
+
(defun notmuch-show-move-to-current-message-summary-line ()
"Move to the beginning of the one-line summary of the current message.
))
(recenter 0)))
+(defun notmuch-show-find-previous-message ()
+ "Returns the position of the previous message in the buffer.
+
+Or the position of the beginning of the current message if point
+is originally within the message rather than at the beginning of
+it."
+ ; save-excursion doesn't save our window position
+ ; save-window-excursion doesn't save point
+ ; Looks like we have to use both.
+ (save-excursion
+ (save-window-excursion
+ (notmuch-show-previous-message)
+ (point))))
+
(defun notmuch-show-mark-read-then-next-unread-message ()
"Remove unread tag from current message, then advance to next unread message."
(interactive)
(notmuch-show-remove-tag "unread")
(notmuch-show-next-unread-message))
+(defun notmuch-show-rewind ()
+ "Do reverse scrolling compared to `notmuch-show-advance-marking-read-and-archiving'
+
+Specifically, if the beginning of the previous email is fewer
+than `window-height' lines from the current point, move to it
+just like `notmuch-show-previous-message'.
+
+Otherwise, just scroll down a screenful of the current message.
+
+This command does not modify any message tags, (it does not undo
+any effects from previous calls to
+`notmuch-show-advance-marking-read-and-archiving'."
+ (interactive)
+ (let ((previous (notmuch-show-find-previous-message)))
+ (if (> (count-lines previous (point)) (- (window-height) next-screen-context-lines))
+ (progn
+ (condition-case nil
+ (scroll-down nil)
+ ((beginning-of-buffer) nil))
+ (goto-char (window-start)))
+ (notmuch-show-previous-message))))
+
(defun notmuch-show-advance-marking-read-and-archiving ()
"Advance through buffer, marking read and archiving.
(if (looking-at ">")
(progn
(while (looking-at ">")
- (next-line))
+ (forward-line))
(let ((overlay (make-overlay beg-sub (point))))
(overlay-put overlay 'invisible 'notmuch-show-citation)
(overlay-put overlay 'before-string
(concat "[" (number-to-string (count-lines beg-sub (point)))
- " quoted lines.]")))))
+ " quoted lines.]\n")))))
(if (looking-at "--[ ]?$")
- (let ((overlay (make-overlay beg-sub end)))
- (overlay-put overlay 'invisible 'notmuch-show-signature)
- (overlay-put overlay 'before-string
- (concat "[" (number-to-string (count-lines beg-sub (point)))
- "-line signature.]"))
- (goto-char end)))
- (next-line))))
+ (let ((sig-lines (count-lines beg-sub end)))
+ (if (<= sig-lines notmuch-show-signature-lines-max)
+ (progn
+ (overlay-put (make-overlay beg-sub (+ beg-sub 1))
+ 'before-string
+ (concat "[" (number-to-string sig-lines)
+ "-line signature.]"))
+ (overlay-put (make-overlay (+ beg-sub 2) end)
+ 'invisible 'notmuch-show-signature)
+ (goto-char end)))))
+ (forward-line))))
(defun notmuch-show-markup-body ()
(re-search-forward notmuch-show-body-begin-regexp)
(progn
(notmuch-show-next-unread-message)
; But if there are no unread messages, go back to the
- ; beginning of the buffer.
+ ; beginning of the buffer, and open up the bodies of all
+ ; read message.
(if (not (notmuch-show-message-unread-p))
- (goto-char (point-min)))))
+ (progn
+ (goto-char (point-min))
+ (notmuch-show-toggle-body-read-visible)))))
)))
(defvar notmuch-search-mode-map
(let ((map (make-sparse-keymap)))
(define-key map "a" 'notmuch-search-archive-thread)
- (define-key map "b" 'scroll-down)
+ (define-key map "b" 'notmuch-search-scroll-down)
(define-key map "f" 'notmuch-search-filter)
(define-key map "n" 'next-line)
(define-key map "p" 'previous-line)
(define-key map ">" 'notmuch-search-goto-last-thread)
(define-key map "=" 'notmuch-search-refresh-view)
(define-key map "\M->" 'notmuch-search-goto-last-thread)
- (define-key map " " 'scroll-up)
- (define-key map (kbd "<DEL>") 'scroll-down)
+ (define-key map " " 'notmuch-search-scroll-up)
+ (define-key map (kbd "<DEL>") 'notmuch-search-scroll-down)
map)
"Keymap for \"notmuch search\" buffers.")
(fset 'notmuch-search-mode-map notmuch-search-mode-map)
+(defun notmuch-search-scroll-up ()
+ "Scroll up, moving point to last message in thread if at end."
+ (interactive)
+ (condition-case nil
+ (scroll-up nil)
+ ((end-of-buffer) (notmuch-search-goto-last-thread))))
+
+(defun notmuch-search-scroll-down ()
+ "Scroll down, moving point to first message in thread if at beginning."
+ (interactive)
+ ; I don't know why scroll-down doesn't signal beginning-of-buffer
+ ; the way that scroll-up signals end-of-buffer, but c'est la vie.
+ ;
+ ; So instead of trapping a signal we instead check whether the
+ ; window begins on the first line of the buffer and if so, move
+ ; directly to that position. (We have to count lines since the
+ ; window-start position is not the same as point-min due to the
+ ; invisible thread-ID characters on the first line.
+ (if (equal (count-lines (point-min) (window-start)) 1)
+ (goto-char (window-start))
+ (scroll-down nil)))
+
(defun notmuch-search-goto-last-thread (&optional arg)
"Move point to the last thread in the buffer."
(interactive "^P")