-(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-regexp "\\(-- ?\\|_+\\)$"
+ "Pattern to match a line that separates content from signature.
+
+The regexp can (and should) include $ to match the end of the
+line, but should not include ^ to match the beginning of the
+line. This is because notmuch may have inserted additional space
+for indentation at the beginning of the line. But notmuch will
+move past the indentation when testing this pattern, (so that the
+pattern can still test against the entire line).")
+
+(defvar notmuch-show-signature-lines-max 12
+ "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-depth-regexp " depth:\\([0-9]*\\) ")
+(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 ()
+ "Return whether the character at point is invisible.
+
+Here visibility is determined by `buffer-invisibility-spec' and
+the invisible property of any overlays for point. It doesn't have
+anything to do with whether point is currently being displayed
+within the current window."
+ (let ((prop (get-char-property (point) 'invisible)))
+ (if (eq buffer-invisibility-spec t)
+ prop
+ (or (memq prop buffer-invisibility-spec)
+ (assq prop buffer-invisibility-spec)))))
+
+(defun notmuch-show-next-line ()
+ "Like builtin `next-line' but ensuring we end on a visible character.
+
+By advancing forward until reaching a visible character.
+
+Unlike builtin `next-line' this version accepts no arguments."
+ (interactive)
+ (set 'this-command 'next-line)
+ (call-interactively 'next-line)
+ (while (point-invisible-p)
+ (forward-char)))
+
+(defun notmuch-show-previous-line ()
+ "Like builtin `previous-line' but ensuring we end on a visible character.
+
+By advancing forward until reaching a visible character.
+
+Unlike builtin `next-line' this version accepts no arguments."
+ (interactive)
+ (set 'this-command 'previous-line)
+ (call-interactively 'previous-line)
+ (while (point-invisible-p)
+ (forward-char)))