From 690718bd2a31f9293572aa7a583a31a0615d18c8 Mon Sep 17 00:00:00 2001 From: TEC Date: Tue, 13 Jul 2021 02:43:29 +0800 Subject: [PATCH] org-src: Implement native inline src fontification * lisp/org-src.el (org-fontify-inline-src-blocks, org-fontify-inline-src-blocks-1): Create a function to search the buffer up to a limit for inline src blocks. Light fontification is applied to matched inline src blocks. When `org-src-fontify-natively' is set, `org-src-font-lock-fontify-block' is applied to the content. * lisp/org.el (org-set-font-lock-defaults): Add `org-fontify-inline-src-blocks' to `org-font-lock-extra-keywords', which is locally bound inside `org-set-font-lock-defaults'. * lisp/org-faces.el: Introduce a new face `org-inline-src-block' which inherits from `org-block' by default. --- lisp/org-faces.el | 4 ++++ lisp/org-src.el | 44 ++++++++++++++++++++++++++++++++++++++++++++ lisp/org.el | 1 + 3 files changed, 49 insertions(+) diff --git a/lisp/org-faces.el b/lisp/org-faces.el index b151045a9..272762789 100644 --- a/lisp/org-faces.el +++ b/lisp/org-faces.el @@ -459,6 +459,10 @@ (defface org-block-end-line '((t (:inherit org-block-begin-line))) "Face used for the line delimiting the end of source blocks." :group 'org-faces) +(defface org-inline-src-block '((t (:inherit org-block))) + "Face used for inline source blocks as a whole." + :group 'org-faces) + (defface org-verbatim '((t (:inherit (fixed-pitch shadow)))) "Face for fixed-with text like code snippets." :group 'org-faces diff --git a/lisp/org-src.el b/lisp/org-src.el index 51dde602d..639a447e8 100644 --- a/lisp/org-src.el +++ b/lisp/org-src.el @@ -654,6 +654,50 @@ (defun org-src-font-lock-fontify-block (lang start end) '(font-lock-fontified t fontified t font-lock-multiline t)) (set-buffer-modified-p modified))))) +(defun org-fontify-inline-src-blocks (limit) + "Try to apply `org-fontify-inline-src-blocks-1'." + (condition-case nil + (org-fontify-inline-src-blocks-1 limit) + (error (message "Org mode fontification error in %S at %d" + (current-buffer) + (line-number-at-pos))))) + +(defun org-fontify-inline-src-blocks-1 (limit) + "Fontify inline src_LANG blocks, from `point' up to LIMIT." + (let ((case-fold-search t) + (initial-point (point))) + (while (re-search-forward "\\_