Browse Source

Don't use an overlay for src blocks backgrounds

* org-faces.el (org-block-background): Delete.

* org.el (org-fontify-meta-lines-and-blocks-1): Don't use an
overlay for the block background.
(org-in-src-block-p): Check against the `src-block' text
property, not against an overlay.

The overlay was introduced here:
http://orgmode.org/cgit.cgi/org-mode.git/commit/?id=27d98d879
and fixed here
http://orgmode.org/cgit.cgi/org-mode.git/commit/?id=69811ff44

But (1) it makes fontification slowler, (2) it makes
`org-in-src-block-p' slower and it prevents correct ps-printing
of Org buffers.

If we want to use a different background color, we need another
solution than using overlays.
Bastien Guerry 5 years ago
parent
commit
f8b42e8
2 changed files with 2 additions and 15 deletions
  1. 0 3
      lisp/org-faces.el
  2. 2 12
      lisp/org.el

+ 0 - 3
lisp/org-faces.el

@@ -537,9 +537,6 @@ follows a #+DATE:, #+AUTHOR: or #+EMAIL: keyword."
   :group 'org-faces
   :version "22.1")
 
-(defface org-block-background '((t ()))
-  "Face used for the source block background.")
-
 (org-copy-face 'org-meta-line 'org-block-begin-line
   "Face used for the line delimiting the begin of source blocks.")
 

+ 2 - 12
lisp/org.el

@@ -5930,15 +5930,7 @@ by a #."
 	      (cond
 	       ((and lang (not (string= lang "")) org-src-fontify-natively)
 		(org-src-font-lock-fontify-block lang block-start block-end)
-		;; remove old background overlays
-		(mapc (lambda (ov)
-			(if (eq (overlay-get ov 'face) 'org-block-background)
-			    (delete-overlay ov)))
-		      (overlays-at (/ (+ beg1 block-end) 2)))
-		;; add a background overlay
-		(setq ovl (make-overlay beg1 block-end))
-                (overlay-put ovl 'face 'org-block-background)
-                (overlay-put ovl 'evaporate t)) ; make it go away when empty
+		(add-text-properties beg1 block-end '(src-block t)))
 	       (quoting
 		(add-text-properties beg1 (min (point-max) (1+ end1))
 				     '(face org-block))) ; end of source block
@@ -21828,9 +21820,7 @@ and end of string."
 When INSIDE is non-nil, don't consider we are within a src block
 when point is at #+BEGIN_SRC or #+END_SRC."
   (let ((case-fold-search t) ov)
-    (or (and (setq ov (overlays-at (point)))
-	     (memq 'org-block-background
-		   (overlay-properties (car ov))))
+    (or (and (eq (get-char-property (point) 'src-block) t))
 	(and (not inside)
 	     (save-match-data
 	       (save-excursion