Browse Source

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
Ihor Radchenko 2 years ago
parent
commit
00adad9357
1 changed files with 37 additions and 3 deletions
  1. 37 3
      lisp/org-src.el

+ 37 - 3
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.