From 53d2851e248c4f4e4076878a999cbf647b401578 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'. (org-inline-src-fontify-max-length): Create a variable to limit the maximum length of an inline-src block fontified, to protect from lag spikes (e.g. when typing out src_lang{ and half of the buffer is fontified). --- lisp/org-src.el | 46 ++++++++++++++++++++++++++++++++++++++++++++++ lisp/org.el | 18 ++++++++++++++++++ 2 files changed, 64 insertions(+) diff --git a/lisp/org-src.el b/lisp/org-src.el index 51dde602d..c3a6a40bc 100644 --- a/lisp/org-src.el +++ b/lisp/org-src.el @@ -654,6 +654,52 @@ (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 + (progn + (org-fontify-inline-src-blocks-1 limit) + (org-fontify-inline-src-results 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))) + (when (re-search-forward "\\_