Skip to content

Commit 1afd9ea

Browse files
committed
Org: Improve inline src font-lock
Now handles multiple instances of inline src blocks per line, and doesn't skip over inline src blocks in an over-eager search for {{{results}}} but instead uses a second pass to match results. `org-prettify-inline-results' has also been updated to handle a cons cell specifying replacement strings to use instead of the default.
1 parent 028ff67 commit 1afd9ea

File tree

1 file changed

+25
-17
lines changed

1 file changed

+25
-17
lines changed

config.org

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5942,7 +5942,9 @@ If you have any idea what's going on or how to fix this /please/ get in touch.
59425942

59435943
#+begin_src emacs-lisp
59445944
(defvar org-prettify-inline-results t
5945-
"Whether to use (ab)use prettify-symbols-mode on {{{results(...)}}}.")
5945+
"Whether to use (ab)use prettify-symbols-mode on {{{results(...)}}}.
5946+
Either t or a cons cell of strings which are used as substitutions
5947+
for the start and end of inline results, respectively.")
59465948

59475949
(defvar org-fontify-inline-src-blocks-max-length 200
59485950
"Maximum content length of an inline src block that will be fontified.")
@@ -5957,8 +5959,9 @@ If you have any idea what's going on or how to fix this /please/ get in touch.
59575959

59585960
(defun org-fontify-inline-src-blocks-1 (limit)
59595961
"Fontify inline src_LANG blocks, from `point' up to LIMIT."
5960-
(let ((case-fold-search t))
5961-
(when (re-search-forward "\\_<src_\\([^ \t\n[{]+\\)[{[]?" limit t) ; stolen from `org-element-inline-src-block-parser'
5962+
(let ((case-fold-search t)
5963+
(initial-point (point)))
5964+
(while (re-search-forward "\\_<src_\\([^ \t\n[{]+\\)[{[]?" limit t) ; stolen from `org-element-inline-src-block-parser'
59625965
(let ((beg (match-beginning 0))
59635966
pt
59645967
(lang-beg (match-beginning 1))
@@ -5989,20 +5992,25 @@ If you have any idea what's going on or how to fix this /please/ get in touch.
59895992
(when (and org-prettify-inline-results (re-search-forward "\\= {{{results(" limit t))
59905993
(font-lock-append-text-property pt (1+ pt) 'face 'org-block)
59915994
(goto-char pt))))
5992-
(when (and org-prettify-inline-results (re-search-forward "{{{results(\\(.+?\\))}}}" limit t))
5993-
(remove-list-of-text-properties (match-beginning 0) (point)
5994-
'(composition
5995-
prettify-symbols-start
5996-
prettify-symbols-end))
5997-
(font-lock-append-text-property (match-beginning 0) (match-end 0) 'face 'org-block)
5998-
(let ((start (match-beginning 0)) (end (match-beginning 1)))
5999-
(with-silent-modifications
6000-
(compose-region start end "⟨")
6001-
(add-text-properties start end `(prettify-symbols-start ,start prettify-symbols-end ,end))))
6002-
(let ((start (match-end 1)) (end (point)))
6003-
(with-silent-modifications
6004-
(compose-region start end "⟩")
6005-
(add-text-properties start end `(prettify-symbols-start ,start prettify-symbols-end ,end)))))))
5995+
(when org-prettify-inline-results
5996+
(goto-char initial-point)
5997+
(org-fontify-inline-src-results limit))))
5998+
5999+
(defun org-fontify-inline-src-results (limit)
6000+
(while (re-search-forward "{{{results(\\(.+?\\))}}}" limit t)
6001+
(remove-list-of-text-properties (match-beginning 0) (point)
6002+
'(composition
6003+
prettify-symbols-start
6004+
prettify-symbols-end))
6005+
(font-lock-append-text-property (match-beginning 0) (match-end 0) 'face 'org-block)
6006+
(let ((start (match-beginning 0)) (end (match-beginning 1)))
6007+
(with-silent-modifications
6008+
(compose-region start end (if (eq org-prettify-inline-results t) "⟨" (car org-prettify-inline-results)))
6009+
(add-text-properties start end `(prettify-symbols-start ,start prettify-symbols-end ,end))))
6010+
(let ((start (match-end 1)) (end (point)))
6011+
(with-silent-modifications
6012+
(compose-region start end (if (eq org-prettify-inline-results t) "⟩" (cdr org-prettify-inline-results)))
6013+
(add-text-properties start end `(prettify-symbols-start ,start prettify-symbols-end ,end))))))
60066014

60076015
(defun org-fontify-inline-src-blocks-enable ()
60086016
"Add inline src fontification to font-lock in Org.

0 commit comments

Comments
 (0)