Просмотр исходного кода

LaTeX snippets: Avoid Overlap

It is possible that the regular expressions for LaTeX snippets match
at nested locations.  For example, Nick Dokos submitted this:

,----
| #+LaTeX_HEADER: \usepackage{amsmath}
|
| * foo
|
| \[
| \begin{matrix}
| 1&d\\
| d&d\\
| \end{matrix}
| \]
|
`----

where the snippet regexps match at \[ ... \] and also at
\\begin{matrix}.

This would lead to two nested overlays being placed.  With this
commit, only the outer one will remain.
Carsten Dominik 15 лет назад
Родитель
Сommit
5834ad01b6
2 измененных файлов с 13 добавлено и 1 удалено
  1. 2 0
      lisp/ChangeLog
  2. 11 1
      lisp/org.el

+ 2 - 0
lisp/ChangeLog

@@ -1,5 +1,7 @@
 2009-08-11  Carsten Dominik  <carsten.dominik@gmail.com>
 
+	* org.el (org-format-latex): Avoid nested overlays.
+
 	* org-latex.el (org-export-latex-listings-langs): Add a few more
 	languages.
 

+ 11 - 1
lisp/org.el

@@ -13902,7 +13902,11 @@ The images can be removed again with \\[org-ctrl-c-ctrl-c]."
 	(while (re-search-forward re nil t)
 	  (when (and (or (not at) (equal (cdr at) (match-beginning n)))
 		     (not (get-text-property (match-beginning n)
-					     'org-protected)))
+					     'org-protected))
+		     (or (not overlays)
+			 (not (eq (get-char-property (match-beginning n)
+						     'org-overlay-type)
+				  'org-latex-overlay))))
 	    (setq txt (match-string n)
 		  beg (match-beginning n) end (match-end n)
 		  cnt (1+ cnt)
@@ -13926,7 +13930,13 @@ The images can be removed again with \\[org-ctrl-c-ctrl-c]."
 	     txt movefile opt forbuffer)
 	    (if overlays
 		(progn
+		  (mapc (lambda (o)
+			  (if (eq (org-overlay-get o 'org-overlay-type)
+				  'org-latex-overlay)
+			      (org-delete-overlay o)))
+			(org-overlays-in beg end))
 		  (setq ov (org-make-overlay beg end))
+		  (org-overlay-put ov 'org-overlay-type 'org-latex-overlay)
 		  (if (featurep 'xemacs)
 		      (progn
 			(org-overlay-put ov 'invisible t)