From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp2 ([2001:41d0:2:aacc::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms12 with LMTPS id /ihwDDfpu2BgdgAAsNZ9tg (envelope-from ); Sat, 05 Jun 2021 21:14:31 +0000 Received: from out2.migadu.com ([2001:41d0:2:aacc::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp2 with LMTPS id 0GclDDPpu2AeWgAAB5/wlQ (envelope-from ); Sat, 05 Jun 2021 21:14:27 +0000 X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kyleam.com; s=key1; t=1622927665; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=m0QG7sWs12n18HCPIuCcA+ivgWk0eDiexrkFedGnwXw=; b=wvb2k/T9nlxA84sneT+iQ8O4VLcxVHCcR2Ydk02wWW7Twng2+0wL4lRkNnDiAeZjrU4jEg O/LmknUUfoOCgMoXOq3hPYKt891x7qovgBMS18ruyyTNRmL1UWy3AYhu5zem/Cy3N8QY9n HZzc2DVCfoJhRurv50OtyuzRByDXCRehGMyhFiBEAeKXFPupNNXQiEyKz2zPA/hjMWn1JC uohcPEfbF4o9eqitSpuVpjgy1i+BE4uBy2uHolraLklg86/V/VfCR/hlAlQDm32YBBpdx+ FSq+wq6tV1C8qWh99g1lw7KG/qfL3jS0KcYIhYWlzmelaczoRe4jgD6kPzZ7Gg== From: Kyle Meyer 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 Message-Id: <20210605211402.20304-4-kyle@kyleam.com> In-Reply-To: <20210605211402.20304-1-kyle@kyleam.com> References: <20210605211402.20304-1-kyle@kyleam.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT X-Migadu-Auth-User: kyle@kyleam.com X-TUID: b4q5ZC1/CL47 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 ;;;; 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