[PATCH v2] emacs: Add more processing of displayed headers.
David Edmondson
dme at dme.org
Mon Feb 6 07:39:05 PST 2012
Wrap headers to the width of the window and indent continuations.
---
emacs/notmuch-show.el | 43 ++++++++++++++++++++++++++++++++++++-------
1 files changed, 36 insertions(+), 7 deletions(-)
diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el
index 7469e2e..a589d37 100644
--- a/emacs/notmuch-show.el
+++ b/emacs/notmuch-show.el
@@ -68,9 +68,16 @@ any given message."
:type 'boolean
:group 'notmuch-show)
-(defvar notmuch-show-markup-headers-hook '(notmuch-show-colour-headers)
+(defcustom notmuch-show-markup-headers-hook '(notmuch-show-colour-headers
+ notmuch-show-fill-headers
+ notmuch-show-indent-continuations)
"A list of functions called to decorate the headers listed in
-`notmuch-message-headers'.")
+`notmuch-message-headers'."
+ :type 'hook
+ :options '(notmuch-show-colour-headers
+ notmuch-show-fill-headers
+ notmuch-show-indent-continuations)
+ :group 'notmuch-show)
(defcustom notmuch-show-hook '(notmuch-show-turn-on-visual-line-mode)
"Functions called after populating a `notmuch-show' buffer."
@@ -269,13 +276,35 @@ operation on the contents of the current buffer."
(overlay-put (make-overlay (point) (re-search-forward ".*$"))
'face face)))
-(defun notmuch-show-colour-headers ()
+(defun notmuch-show-colour-headers (depth)
"Apply some colouring to the current headers."
(goto-char (point-min))
(while (looking-at "^[A-Za-z][-A-Za-z0-9]*:")
(notmuch-show-fontify-header)
(forward-line)))
+(defun notmuch-show-fill-headers (depth)
+ "Wrap the text of the current headers."
+
+ ;; '-5' to allow for the indentation code.
+ (let ((fill-column (- (window-width) depth 5)))
+ (goto-char (point-min))
+ (while (not (eobp))
+ (let ((start (point)))
+ (end-of-line)
+ ;; We're left at the start of the next line, so there's no need
+ ;; to move forward after filling.
+ (fill-region-as-paragraph start (point))))))
+
+(defun notmuch-show-indent-continuations (depth)
+ "Indent any continuation lines."
+ (goto-char (point-min))
+ (while (not (eobp))
+ (if (not (looking-at "^[A-Za-z][-A-Za-z0-9]*:"))
+ ;; Four spaces tends to work well with 'To' and 'Cc' headers.
+ (insert " "))
+ (forward-line)))
+
(defun notmuch-show-spaces-n (n)
"Return a string comprised of `n' spaces."
(make-string n ? ))
@@ -366,7 +395,7 @@ message at DEPTH in the current thread."
"Insert a single header."
(insert header ": " header-value "\n"))
-(defun notmuch-show-insert-headers (headers)
+(defun notmuch-show-insert-headers (headers depth)
"Insert the headers of the current message."
(let ((start (point)))
(mapc (lambda (header)
@@ -379,7 +408,7 @@ message at DEPTH in the current thread."
(save-excursion
(save-restriction
(narrow-to-region start (point-max))
- (run-hooks 'notmuch-show-markup-headers-hook)))))
+ (run-hook-with-args 'notmuch-show-markup-headers-hook depth)))))
(define-button-type 'notmuch-show-part-button-type
'action 'notmuch-show-part-button-default
@@ -671,7 +700,7 @@ current buffer, if possible."
;; Override `notmuch-message-headers' to force `From' to be
;; displayed.
(let ((notmuch-message-headers '("From" "Subject" "To" "Cc" "Date")))
- (notmuch-show-insert-headers (plist-get message :headers)))
+ (notmuch-show-insert-headers (plist-get message :headers) 0))
;; Blank line after headers to be compatible with the normal
;; message display.
@@ -864,7 +893,7 @@ current buffer, if possible."
;; Set `headers-start' to point after the 'Subject:' header to be
;; compatible with the existing implementation. This just sets it
;; to after the first header.
- (notmuch-show-insert-headers headers)
+ (notmuch-show-insert-headers headers depth)
(save-excursion
(goto-char content-start)
;; If the subject of this message is the same as that of the
--
1.7.8.3
More information about the notmuch
mailing list