From 00adad9357b9123a7b11ecf12c148a5196debcb7 Mon Sep 17 00:00:00 2001 From: Ihor Radchenko Date: Sun, 7 Aug 2022 18:33:11 +0800 Subject: [PATCH] org-src: Fix invisible text in src block fontification * lisp/org-src.el (org-src-font-lock-fontify-block): If fontified text has `invisible' text property, avoid interfering with Org folding making the invisibility of lower priority compared to folding. Fixes https://orgmode.org/list/87zgghrsd2.fsf@gmail.com --- lisp/org-src.el | 40 +++++++++++++++++++++++++++++++++++++--- 1 file changed, 37 insertions(+), 3 deletions(-) diff --git a/lisp/org-src.el b/lisp/org-src.el index 0249af60b..e0cded9ed 100644 --- a/lisp/org-src.el +++ b/lisp/org-src.el @@ -651,9 +651,43 @@ as `org-src-fontify-natively' is non-nil." (dolist (prop (append '(font-lock-face face) font-lock-extra-managed-props)) (let ((new-prop (get-text-property pos prop))) (when new-prop - (put-text-property - (+ start (1- pos)) (1- (+ start next)) prop new-prop - org-buffer)))) + (if (not (eq prop 'invisible)) + (put-text-property + (+ start (1- pos)) (1- (+ start next)) prop new-prop + org-buffer) + ;; Special case. `invisible' text property may + ;; clash with Org folding. Do not assign + ;; `invisible' text property directly. Use + ;; property alias instead. + (let ((invisibility-spec + (or + ;; ATOM spec. + (and (memq new-prop buffer-invisibility-spec) + new-prop) + ;; (ATOM . ELLIPSIS) spec. + (assq new-prop buffer-invisibility-spec)))) + (with-current-buffer org-buffer + ;; Add new property alias. + (unless (memq 'org-src-invisible + (cdr (assq 'invisible char-property-alias-alist))) + (setq-local + char-property-alias-alist + (cons (cons 'invisible + (nconc (cdr (assq 'invisible char-property-alias-alist)) + '(org-src-invisible))) + (remove (assq 'invisible char-property-alias-alist) + char-property-alias-alist)))) + ;; Carry over the invisibility spec, unless + ;; already present. Note that there might + ;; be conflicting invisibility specs from + ;; different major modes. We cannot do much + ;; about this then. + (when invisibility-spec + (add-to-invisibility-spec invisibility-spec)) + (put-text-property + (+ start (1- pos)) (1- (+ start next)) + 'org-src-invisible new-prop + org-buffer))))))) (setq pos next))) (set-buffer-modified-p nil)) ;; Add Org faces.