From: Carl Worth Date: Tue, 3 Nov 2009 06:24:35 +0000 (-0800) Subject: notmuch.el: Hide email headers by default. X-Git-Tag: 0.1~614 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=f2a4c3e565511a543971da378227b8928a48ab36;p=notmuch.git notmuch.el: Hide email headers by default. The display of the header can be toggled with the 'h' key. --- diff --git a/TODO b/TODO index ec34cc43..68b43bc7 100644 --- a/TODO +++ b/TODO @@ -2,8 +2,8 @@ Emacs interface (notmuch.el) ---------------------------- Add support to compose a reply to the current messaage. -Selectively hide headers and bodies in notmuch-show mode. (for -example, for read messages). +Selectively hide bodies in notmuch-show mode. (for example, for read +messages). Remove "unread" tag from messages as they are read. diff --git a/notmuch.el b/notmuch.el index 00a03c0e..e98a3085 100644 --- a/notmuch.el +++ b/notmuch.el @@ -33,6 +33,7 @@ (defvar notmuch-show-mode-map (let ((map (make-sparse-keymap))) + (define-key map "h" 'notmuch-show-toggle-headers-visible) (define-key map "n" 'notmuch-show-next-message) (define-key map "p" 'notmuch-show-previous-message) (define-key map "q" 'kill-this-buffer) @@ -42,6 +43,11 @@ (fset 'notmuch-show-mode-map notmuch-show-mode-map) (defvar notmuch-show-message-begin-regexp " message{") +(defvar notmuch-show-message-end-regexp " message}") +(defvar notmuch-show-header-begin-regexp " header{") +(defvar notmuch-show-header-end-regexp " header}") + +(defvar notmuch-show-headers-visible t) (defun notmuch-show-next-message () "Advance point to the beginning of the next message in the buffer." @@ -65,11 +71,51 @@ (beginning-of-line) (recenter 0)) +(defun notmuch-show-markup-this-header () + (if (re-search-forward notmuch-show-header-begin-regexp nil t) + (progn + (overlay-put (make-overlay (match-beginning 0) (+ (match-end 0) 1)) + 'invisible 'notmuch-show-marker) + (next-line 1) + (beginning-of-line) + (let ((beg (point))) + (if (re-search-forward notmuch-show-header-end-regexp nil t) + (progn + (overlay-put (make-overlay beg (match-beginning 0)) + 'invisible 'notmuch-show-header) + (overlay-put (make-overlay (match-beginning 0) (+ (match-end 0) 1)) + 'invisible 'notmuch-show-marker))))) + (goto-char (point-max)))) + +(defun notmuch-show-markup-headers () + (save-excursion + (goto-char (point-min)) + (while (not (eobp)) + (notmuch-show-markup-this-header)))) + +(defun notmuch-show-toggle-headers-visible () + "Toggle visibility of header fields" + (interactive) + (if notmuch-show-headers-visible + (progn + (add-to-invisibility-spec 'notmuch-show-header) + (set 'notmuch-show-headers-visible nil) + ; Need to force the redisplay for some reason + (force-window-update) + (redisplay t)) + (remove-from-invisibility-spec 'notmuch-show-header) + (set 'notmuch-show-headers-visible t) + (force-window-update) + (redisplay t))) + ;;;###autoload (defun notmuch-show-mode () "Major mode for handling the output of \"notmuch show\"" (interactive) (kill-all-local-variables) + (set (make-local-variable 'notmuch-show-headers-visible) t) + (notmuch-show-toggle-headers-visible) + (add-to-invisibility-spec 'notmuch-show-marker) (use-local-map notmuch-show-mode-map) (setq major-mode 'notmuch-show-mode mode-name "notmuch-show") @@ -90,6 +136,7 @@ (goto-char (point-min)) (save-excursion (call-process "notmuch" nil t nil "show" thread-id) + (notmuch-show-markup-headers) ) )))