From 563281f8bed02e8ec12e48696ebdd98e61ccfbac Mon Sep 17 00:00:00 2001 From: TEC Date: Wed, 31 Mar 2021 22:30:40 +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 | 73 +++++++++++++++++++++++++++++++++++++++++++++++++ lisp/org.el | 21 +++++++++++++- 2 files changed, 93 insertions(+), 1 deletion(-) diff --git a/lisp/org-src.el b/lisp/org-src.el index 20acee4e6..9119372d7 100644 --- a/lisp/org-src.el +++ b/lisp/org-src.el @@ -624,6 +624,79 @@ (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 "\\_