discussion and development of piem
 help / color / mirror / code / Atom feed
From: Kyle Meyer <kyle@kyleam.com>
To: piem@inbox.kyleam.com
Subject: [PATCH 03/18] piem-lei-show: Highlight headers and quoted text
Date: Sat,  5 Jun 2021 17:13:47 -0400	[thread overview]
Message-ID: <20210605211402.20304-4-kyle@kyleam.com> (raw)
In-Reply-To: <20210605211402.20304-1-kyle@kyleam.com>

Piggyback off of message-* faces to hopefully fit in nicely with
themes and expectations.  Leave other highlighting (e.g., of diffs),
until later.
---
 piem-lei.el | 83 ++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 82 insertions(+), 1 deletion(-)

diff --git a/piem-lei.el b/piem-lei.el
index fe6ab79a..291964fc 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 @@ (defgroup piem-lei nil
 \f
 ;;;; 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 @@ (defun piem-lei-show (mid &optional display)
       (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
-- 
2.31.1


  parent reply	other threads:[~2021-06-05 21:14 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-05 21:13 [PATCH 00/18] Initial lei support Kyle Meyer
2021-06-05 21:13 ` [PATCH 01/18] lei: Add command and mode for displaying a message Kyle Meyer
2021-06-05 21:13 ` [PATCH 02/18] piem-lei-show: Let caller suppress displaying buffer Kyle Meyer
2021-06-05 21:13 ` Kyle Meyer [this message]
2021-06-05 21:13 ` [PATCH 04/18] lei: Add command and mode for displaying overview of search results Kyle Meyer
2021-06-05 21:13 ` [PATCH 05/18] lei query: Add piem-lei-show wrapper for displaying line's message Kyle Meyer
2021-06-05 21:13 ` [PATCH 06/18] lei: Add command for viewing a thread Kyle Meyer
2021-06-05 21:13 ` [PATCH 07/18] lei query: Fontify results Kyle Meyer
2021-06-05 21:13 ` [PATCH 08/18] piem-lei-query-thread: Position point on seed message Kyle Meyer
2021-06-05 21:13 ` [PATCH 09/18] piem-lei-query-thread: Drop repeated subjects Kyle Meyer
2021-06-05 21:13 ` [PATCH 10/18] piem-lei-query-thread: Deal with multiple "re:"s Kyle Meyer
2021-06-05 21:13 ` [PATCH 11/18] piem-lei-query-thread: Omit main part of subject if shared Kyle Meyer
2021-06-05 21:13 ` [PATCH 12/18] piem-lei-query-thread: Add bug#NNN special case when eliding subject Kyle Meyer
2021-06-05 21:13 ` [PATCH 13/18] lei query: Add next/previous line variants that update message buffer Kyle Meyer
2021-06-05 21:13 ` [PATCH 14/18] piem-lei-show: Record message ID Kyle Meyer
2021-06-05 21:13 ` [PATCH 15/18] lei query: Add commands for showing or scrolling message buffer Kyle Meyer
2021-06-05 21:14 ` [PATCH 16/18] lei: Configure bindings for query and show modes Kyle Meyer
2021-06-05 21:14 ` [PATCH 17/18] lei: Wire up piem.el hooks Kyle Meyer
2021-06-05 21:14 ` [PATCH 18/18] piem-lei-query-thread: Use piem-lei-get-mid to get message ID Kyle Meyer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://git.kyleam.com/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210605211402.20304-4-kyle@kyleam.com \
    --to=kyle@kyleam.com \
    --cc=piem@inbox.kyleam.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.kyleam.com/piem/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).