Skip to content

Commit 00adad9

Browse files
committed
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
1 parent a303a79 commit 00adad9

File tree

1 file changed

+37
-3
lines changed

1 file changed

+37
-3
lines changed

lisp/org-src.el

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -651,9 +651,43 @@ as `org-src-fontify-natively' is non-nil."
651651
(dolist (prop (append '(font-lock-face face) font-lock-extra-managed-props))
652652
(let ((new-prop (get-text-property pos prop)))
653653
(when new-prop
654-
(put-text-property
655-
(+ start (1- pos)) (1- (+ start next)) prop new-prop
656-
org-buffer))))
654+
(if (not (eq prop 'invisible))
655+
(put-text-property
656+
(+ start (1- pos)) (1- (+ start next)) prop new-prop
657+
org-buffer)
658+
;; Special case. `invisible' text property may
659+
;; clash with Org folding. Do not assign
660+
;; `invisible' text property directly. Use
661+
;; property alias instead.
662+
(let ((invisibility-spec
663+
(or
664+
;; ATOM spec.
665+
(and (memq new-prop buffer-invisibility-spec)
666+
new-prop)
667+
;; (ATOM . ELLIPSIS) spec.
668+
(assq new-prop buffer-invisibility-spec))))
669+
(with-current-buffer org-buffer
670+
;; Add new property alias.
671+
(unless (memq 'org-src-invisible
672+
(cdr (assq 'invisible char-property-alias-alist)))
673+
(setq-local
674+
char-property-alias-alist
675+
(cons (cons 'invisible
676+
(nconc (cdr (assq 'invisible char-property-alias-alist))
677+
'(org-src-invisible)))
678+
(remove (assq 'invisible char-property-alias-alist)
679+
char-property-alias-alist))))
680+
;; Carry over the invisibility spec, unless
681+
;; already present. Note that there might
682+
;; be conflicting invisibility specs from
683+
;; different major modes. We cannot do much
684+
;; about this then.
685+
(when invisibility-spec
686+
(add-to-invisibility-spec invisibility-spec))
687+
(put-text-property
688+
(+ start (1- pos)) (1- (+ start next))
689+
'org-src-invisible new-prop
690+
org-buffer)))))))
657691
(setq pos next)))
658692
(set-buffer-modified-p nil))
659693
;; Add Org faces.

0 commit comments

Comments
 (0)