From a596961fe1d8405ac3f810ce18177823bcecde11 Mon Sep 17 00:00:00 2001 From: djcb Date: Wed, 8 Feb 2012 22:18:34 +0200 Subject: [PATCH] * mu4e.el, mu4e-view.el: colorize cited message parts --- emacs/mu4e-view.el | 35 ++++++++++++++++++++++++++++++++++- emacs/mu4e.el | 22 +++++++++++++++++++++- 2 files changed, 55 insertions(+), 2 deletions(-) diff --git a/emacs/mu4e-view.el b/emacs/mu4e-view.el index de4da050..217bbbb3 100644 --- a/emacs/mu4e-view.el +++ b/emacs/mu4e-view.el @@ -120,6 +120,7 @@ marking if it still had that." (switch-to-buffer buf) (goto-char (point-min)) + (mu4e-color-cited) (mu4e-mark-footer) (mu4e-make-urls-clickable) @@ -158,7 +159,6 @@ marking if it still had that." "*internal* Hash which maps a number to a (part-id name mime-type).") - (defun mu4e-open-save-attach-func (num is-open) "Return a function that offers to extracts (saves) attachment NUM if IS-OPEN is nil, and otherwise open it." @@ -373,6 +373,39 @@ Seen; if the message is not New/Unread, do nothing." (mu4e-proc-flag docid "+S-u-N"))))) +(defun mu4e-color-cited () + "Colorize message content based on the citation level." + (save-excursion + (let ((more-lines t)) + (goto-char (point-min)) + (while more-lines + ;; Get the citation level at point -- ie., the number of '>' + ;; prefixes, starting with 0 for 'no citation' + (beginning-of-line 1) + (let* ((text (re-search-forward "[[:word:]]" (line-end-position 1) t 1)) + (level (or (and text + (how-many ">" (line-beginning-position 1) text)) 0)) + (face + (cond + ((= 0 level) nil) ;; don't do anything + ((= 1 level) 'mu4e-cited-1-face) + ((= 2 level) 'mu4e-cited-2-face) + ((= 3 level) 'mu4e-cited-3-face) + ((= 4 level) 'mu4e-cited-4-face) + (t nil)))) + (when face + (add-text-properties (line-beginning-position 1) + (line-end-position 1) `(face ,face)))) + (setq more-lines + (and (= 0 (forward-line 1)) + ;; we need to add this weird check below; it seems in some cases + ;; `forward-line' continues to return 0, even when at the end, which + ;; would lead to an infinite loop + (not (= (point-max) (line-end-position))))))))) + + + + (defun mu4e-mark-footer () "Give the message footers a distinctive color." (let ((inhibit-read-only t)) diff --git a/emacs/mu4e.el b/emacs/mu4e.el index 07054ad3..0cdb39ac 100644 --- a/emacs/mu4e.el +++ b/emacs/mu4e.el @@ -264,7 +264,7 @@ flag set)." :group 'mu4e-faces) (defface mu4e-view-header-key-face - '((t :inherit font-lock-builtin-face)) + '((t :inherit font-lock-builtin-face :bold t)) "Face for the header title (such as \"Subject\" in the message view)." :group 'mu4e-faces) @@ -293,6 +293,26 @@ flag set)." "Face for the number tags for attachments." :group 'mu4e-faces) +(defface mu4e-cited-1-face + '((t :inherit font-lock-builtin-face :bold nil :italic t)) + "Face for cited message parts (level 1)." + :group 'mu4e-faces) + +(defface mu4e-cited-2-face + '((t :inherit font-lock-type-face :bold nil :italic t)) + "Face for cited message parts (level 2)." + :group 'mu4e-faces) + +(defface mu4e-cited-3-face + '((t :inherit font-lock-variable-name-face :bold nil :italic t)) + "Face for cited message parts (level 3)." + :group 'mu4e-faces) + +(defface mu4e-cited-4-face + '((t :inherit font-lock-pseudo-keyword-face :bold nil :italic t)) + "Face for cited message parts (level 4)." + :group 'mu4e-faces) + (defface mu4e-view-footer-face '((t :inherit font-lock-comment-face)) "Face for message footers (signatures)."