aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKyle Meyer <kyle@kyleam.com>2021-06-05 17:13:47 -0400
committerKyle Meyer <kyle@kyleam.com>2021-06-07 00:12:06 -0400
commit7b51ed76fdbea12fe98b03e9ebaacf18fa16e8be (patch)
treecc2392efb4edd566083006e7bca2185093a3f574
parent2526059d47ca4645976ca2bc91900ebcf5bb2f48 (diff)
downloadpiem-7b51ed76fdbea12fe98b03e9ebaacf18fa16e8be.tar.gz
piem-lei-show: Highlight headers and quoted text
Piggyback off of message-* faces to hopefully fit in nicely with themes and expectations. Leave other highlighting (e.g., of diffs), until later. Message-Id: <20210605211402.20304-4-kyle@kyleam.com>
-rw-r--r--piem-lei.el83
1 files changed, 82 insertions, 1 deletions
diff --git a/piem-lei.el b/piem-lei.el
index fe6ab79..291964f 100644
--- a/piem-lei.el
+++ b/piem-lei.el
@@ -21,6 +21,7 @@
;;; Code:
+(require 'message)
(require 'piem)
(defgroup piem-lei nil
@@ -30,6 +31,77 @@
;;;; Message display
+(defface piem-lei-show-header-name
+ '((t :inherit message-header-name))
+ "Face for header names in `piem-lei-show-mode' buffers.")
+
+(defface piem-lei-show-header-from
+ ;; Given it's focused on sending, message.el unsurprisingly doesn't
+ ;; define a -from.
+ '((t :inherit message-header-to))
+ "Face for From headers in `piem-lei-show-mode' buffers.")
+
+(defface piem-lei-show-header-to
+ '((t :inherit message-header-to))
+ "Face for To headers in `piem-lei-show-mode' buffers.")
+
+(defface piem-lei-show-header-cc
+ '((t :inherit message-header-cc))
+ "Face for Cc headers in `piem-lei-show-mode' buffers.")
+
+(defface piem-lei-show-header-other
+ '((t :inherit message-header-other))
+ "Face for all other headers in `piem-lei-show-mode' buffers.")
+
+(defface piem-lei-show-header-subject
+ '((t :inherit message-header-subject))
+ "Face for Subject headers in `piem-lei-show-mode' buffers.")
+
+(defface piem-lei-show-cited-text-1
+ '((t :inherit message-cited-text-1))
+ "Face for 1st-level cited text in `piem-lei-show-mode' buffers.")
+
+(defface piem-lei-show-cited-text-2
+ '((t :inherit message-cited-text-2))
+ "Face for 2nd-level cited text in `piem-lei-show-mode' buffers.")
+
+(defface piem-lei-show-cited-text-3
+ '((t :inherit message-cited-text-3))
+ "Face for 3rd-level cited text in `piem-lei-show-mode' buffers.")
+
+(defface piem-lei-show-cited-text-4
+ '((t :inherit message-cited-text-4))
+ "Face for 4th-level cited text in `piem-lei-show-mode' buffers.")
+
+(defun piem-lei-show--fontify-headers ()
+ (save-excursion
+ (let (last-value-face)
+ (while (looking-at
+ (rx line-start
+ (group (one-or-more (not (or ":" "\n"))) ":")
+ (group (one-or-more not-newline))))
+ (put-text-property
+ (match-beginning 1) (match-end 1)
+ 'font-lock-face 'piem-lei-show-header-name)
+ (put-text-property
+ (match-beginning 2) (match-end 2)
+ 'font-lock-face
+ (setq last-value-face
+ (pcase (downcase (match-string 1))
+ ("cc:" 'piem-lei-show-header-cc)
+ ("from:" 'piem-lei-show-header-from)
+ ("subject:" 'piem-lei-show-header-subject)
+ ("to:" 'piem-lei-show-header-to)
+ (_ 'piem-lei-show-header-other))))
+ (forward-line)
+ ;; Handle values that continue onto next line.
+ (while (eq (char-after) ?\t)
+ (save-excursion
+ (skip-chars-forward "\t")
+ (put-text-property (point) (line-end-position)
+ 'font-lock-face last-value-face))
+ (forward-line))))))
+
(defun piem-lei-show (mid &optional display)
"Show message for MID.
When called non-interactively, return the buffer but do not display it
@@ -46,17 +118,26 @@ unless DISPLAY is non-nil."
(when (looking-at-p "# blob:")
(delete-region (line-beginning-position)
(1+ (line-end-position))))
- (piem-lei-show-mode))
+ (piem-lei-show-mode)
+ (piem-lei-show--fontify-headers))
(if display
(pop-to-buffer (current-buffer))
(current-buffer))))
+(defvar piem-lei-show-mode-font-lock-keywords
+ '(("^> \\(.*\\)" 0 'piem-lei-show-cited-text-1)
+ ("^>> \\(.*\\)" 0 'piem-lei-show-cited-text-2)
+ ("^>>> \\(.*\\)" 0 'piem-lei-show-cited-text-3)
+ ("^>>>> \\(.*\\)" 0 'piem-lei-show-cited-text-4))
+ "Font lock keywords for `piem-lei-show-mode'.")
+
(define-derived-mode piem-lei-show-mode special-mode "lei-show"
"Major mode for displaying message via lei."
:group 'piem-lei
(buffer-disable-undo)
(setq truncate-lines t)
(setq buffer-read-only t)
+ (setq font-lock-defaults (list piem-lei-show-mode-font-lock-keywords t))
(setq-local line-move-visual t))
;;; piem-lei.el ends here