aboutsummaryrefslogtreecommitdiffhomepage
path: root/notmuch.el
diff options
context:
space:
mode:
authorGravatar Carl Worth <cworth@cworth.org>2009-11-02 22:24:35 -0800
committerGravatar Carl Worth <cworth@cworth.org>2009-11-02 22:24:35 -0800
commitf2a4c3e565511a543971da378227b8928a48ab36 (patch)
tree7d2fe893bb349273d047bea5cf9203526a5d2002 /notmuch.el
parenta81849b5e21632cfca7d634d718501f67219bb60 (diff)
notmuch.el: Hide email headers by default.
The display of the header can be toggled with the 'h' key.
Diffstat (limited to 'notmuch.el')
-rw-r--r--notmuch.el47
1 files changed, 47 insertions, 0 deletions
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)
)
)))