From c6e0bf2b4753608467bf9d545f62cc1d79bda80f Mon Sep 17 00:00:00 2001 From: Phil Estival Date: Wed, 8 Jun 2022 08:24:00 +0200 Subject: [PATCH 1/2] (cosmetic) distinct faces in block declaration when is language set --- lisp/org-faces.el | 12 ++++++++++++ lisp/org.el | 21 ++++++++++++++++----- 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/lisp/org-faces.el b/lisp/org-faces.el index d96898372..96e190a17 100644 --- a/lisp/org-faces.el +++ b/lisp/org-faces.el @@ -455,6 +455,18 @@ verse and quote blocks are fontified using the `org-verse' and "Face used for the line delimiting the end of source blocks." :group 'org-faces) +(defface org-block-begin-src '((t (:inherit org-block-begin-line))) + "Face used for the begin_term of source blocks." + :group 'org-faces) + +(defface org-block-lang '((t (:inherit org-block-begin-line))) + "Face used for the language of source blocks." + :group 'org-faces) + +(defface org-block-switches '((t (:inherit org-block-begin-line))) + "Face used for the switches and headers arguments of source blocks." + :group 'org-faces) + (defface org-verbatim '((t (:inherit shadow))) "Face for fixed-with text like code snippets." :group 'org-faces diff --git a/lisp/org.el b/lisp/org.el index 1fc4251a3..c7de64b81 100644 --- a/lisp/org.el +++ b/lisp/org.el @@ -4964,7 +4964,7 @@ The following commands are available: (set-face-foreground 'org-hide foreground))) ;; Set face extension as requested. (org--set-faces-extend '(org-block-begin-line org-block-end-line) - org-fontify-whole-block-delimiter-line) + org-fontify-whole-block-delimiter-line) (org--set-faces-extend org-level-faces org-fontify-whole-heading-line)) ;; Update `customize-package-emacs-version-alist' @@ -5291,6 +5291,8 @@ by a #." ;; after the end of block content. (block-start (match-end 0)) (block-end nil) + (lang-begin (match-beginning 7)) + (lang-end (match-end 7)) (lang (match-string 7)) ; The language, if it is a source block. (bol-after-beginline (line-beginning-position 2)) (dc1 (downcase (match-string 2))) @@ -5346,10 +5348,19 @@ by a #." ((string= block-type "verse") (add-face-text-property bol-after-beginline beg-of-endline 'org-verse t))) - ;; Fontify the #+begin and #+end lines of the blocks - (add-text-properties - beg (if whole-blockline bol-after-beginline end-of-beginline) - '(face org-block-begin-line)) + ;; Fontify the #+begin and #+end lines of the blocks + (if (string= lang "") + (add-text-properties + beg (if whole-blockline bol-after-beginline end-of-beginline) + '(face org-block-begin-line)) + ;; when language is set, fontify separately + ;; begin_[src], language and switches + (and (add-text-properties beg lang-begin + '(face org-block-begin-src)) + (add-text-properties lang-begin lang-end + '(face org-block-lang)) + (add-text-properties lang-end bol-after-beginline + '(face org-block-switches)))) (unless (eq (char-after beg-of-endline) ?*) (add-text-properties beg-of-endline -- 2.31.GIT