org: inline src fontification has been merged
This commit is contained in:
parent
2ff4da21fc
commit
2c7b0887bb
79
config.org
79
config.org
|
@ -6957,84 +6957,7 @@ If you have any idea what's going on or how to fix this /please/ get in touch.
|
|||
#+end_warning
|
||||
|
||||
#+begin_src emacs-lisp
|
||||
(defvar org-prettify-inline-results t
|
||||
"Whether to use (ab)use prettify-symbols-mode on {{{results(...)}}}.
|
||||
Either t or a cons cell of strings which are used as substitutions
|
||||
for the start and end of inline results, respectively.")
|
||||
|
||||
(defvar org-fontify-inline-src-blocks-max-length 200
|
||||
"Maximum content length of an inline src block that will be fontified.")
|
||||
|
||||
(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 "\\_<src_\\([^ \t\n[{]+\\)[{[]?" limit t) ; stolen from `org-element-inline-src-block-parser'
|
||||
(let ((beg (match-beginning 0))
|
||||
pt
|
||||
(lang-beg (match-beginning 1))
|
||||
(lang-end (match-end 1)))
|
||||
(remove-text-properties beg lang-end '(face nil))
|
||||
(font-lock-append-text-property lang-beg lang-end 'face 'org-meta-line)
|
||||
(font-lock-append-text-property beg lang-beg 'face 'shadow)
|
||||
(font-lock-append-text-property beg lang-end 'face 'org-block)
|
||||
(setq pt (goto-char lang-end))
|
||||
;; `org-element--parse-paired-brackets' doesn't take a limit, so to
|
||||
;; prevent it searching the entire rest of the buffer we temporarily
|
||||
;; narrow the active region.
|
||||
(save-restriction
|
||||
(narrow-to-region beg (min (point-max) limit (+ lang-end org-fontify-inline-src-blocks-max-length)))
|
||||
(when (ignore-errors (org-element--parse-paired-brackets ?\[))
|
||||
(remove-text-properties pt (point) '(face nil))
|
||||
(font-lock-append-text-property pt (point) 'face 'org-block)
|
||||
(setq pt (point)))
|
||||
(when (ignore-errors (org-element--parse-paired-brackets ?\{))
|
||||
(remove-text-properties pt (point) '(face nil))
|
||||
(font-lock-append-text-property pt (1+ pt) 'face '(org-block shadow))
|
||||
(unless (= (1+ pt) (1- (point)))
|
||||
(if org-src-fontify-natively
|
||||
(org-src-font-lock-fontify-block (buffer-substring-no-properties lang-beg lang-end) (1+ pt) (1- (point)))
|
||||
(font-lock-append-text-property (1+ pt) (1- (point)) 'face 'org-block)))
|
||||
(font-lock-append-text-property (1- (point)) (point) 'face '(org-block shadow))
|
||||
(setq pt (point))))
|
||||
(when (and org-prettify-inline-results (re-search-forward "\\= {{{results(" limit t))
|
||||
(font-lock-append-text-property pt (1+ pt) 'face 'org-block)
|
||||
(goto-char pt))))
|
||||
(when org-prettify-inline-results
|
||||
(goto-char initial-point)
|
||||
(org-fontify-inline-src-results limit))))
|
||||
|
||||
(defun org-fontify-inline-src-results (limit)
|
||||
(while (re-search-forward "{{{results(\\(.+?\\))}}}" limit t)
|
||||
(remove-list-of-text-properties (match-beginning 0) (point)
|
||||
'(composition
|
||||
prettify-symbols-start
|
||||
prettify-symbols-end))
|
||||
(font-lock-append-text-property (match-beginning 0) (match-end 0) 'face 'org-block)
|
||||
(let ((start (match-beginning 0)) (end (match-beginning 1)))
|
||||
(with-silent-modifications
|
||||
(compose-region start end (if (eq org-prettify-inline-results t) "⟨" (car org-prettify-inline-results)))
|
||||
(add-text-properties start end `(prettify-symbols-start ,start prettify-symbols-end ,end))))
|
||||
(let ((start (match-end 1)) (end (point)))
|
||||
(with-silent-modifications
|
||||
(compose-region start end (if (eq org-prettify-inline-results t) "⟩" (cdr org-prettify-inline-results)))
|
||||
(add-text-properties start end `(prettify-symbols-start ,start prettify-symbols-end ,end))))))
|
||||
|
||||
(defun org-fontify-inline-src-blocks-enable ()
|
||||
"Add inline src fontification to font-lock in Org.
|
||||
Must be run as part of `org-font-lock-set-keywords-hook'."
|
||||
(setq org-font-lock-extra-keywords
|
||||
(append org-font-lock-extra-keywords '((org-fontify-inline-src-blocks)))))
|
||||
|
||||
(add-hook 'org-font-lock-set-keywords-hook #'org-fontify-inline-src-blocks-enable)
|
||||
(setq org-inline-src-prettify-results '("⟨" . "⟩"))
|
||||
#+end_src
|
||||
|
||||
Doom theme's extra fontification is more problematic than helpful.
|
||||
|
|
Loading…
Reference in New Issue