From 81c56a48ebe516890691420243efe966f3c50eef Mon Sep 17 00:00:00 2001 From: TEC Date: Mon, 3 May 2021 11:16:17 +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' to the content. (org-fontify-inline-src-results): Search for {{{results(...)}}} constructs. Then when `org-inline-src-prettify-results` is non-nil, mimic prettify-symbols and use `compose-region' to substitute visually simpler elements for the wrapping around the value. * 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'. (org-inline-src-fontify-max-length, org-inline-src-prettify-results): Create variables for use in the new inline src/result fontification methods in org-src.el. --- lisp/org-src.el | 79 +++++++++++++++++++++++++++++++++++++++++++++++++ lisp/org.el | 21 ++++++++++++- 2 files changed, 99 insertions(+), 1 deletion(-) diff --git a/lisp/org-src.el b/lisp/org-src.el index a694e5595..1d09f03a8 100644 --- a/lisp/org-src.el +++ b/lisp/org-src.el @@ -623,6 +623,85 @@ (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 "\\_