Browse Source

org-element: Avoid using a slow regexp

* lisp/org-element.el (org-element-latex-fragment-parser): Avoid using
  a slow regexp.
Nicolas Goaziou 3 years ago
parent
commit
baa2c5943a
1 changed files with 5 additions and 2 deletions
  1. 5 2
      lisp/org-element.el

+ 5 - 2
lisp/org-element.el

@@ -2916,8 +2916,11 @@ Assume point is at the beginning of the LaTeX fragment."
 		  (if (eq (char-after (1+ (point))) ?$)
 		      (search-forward "$$" nil t 2)
 		    (and (not (eq (char-before) ?$))
-			 (looking-at "\\$[^ \t\n,;.$]\\(?:[^$]*?[^ \t\n,.$]\\)?\\$\\([- \t.,?;:'\")]\\|$\\)")
-			 (match-beginning 1)))
+			 (search-forward "$" nil t 2)
+			 (not (memq (char-before (match-beginning 0))
+				    '(?\s ?\t ?\n ?, ?.)))
+			 (looking-at "\\([- \t.,?;:'\"]\\|$\\)")
+			 (point)))
 		(case (char-after (1+ (point)))
 		  (?\( (search-forward "\\)" nil t))
 		  (?\[ (search-forward "\\]" nil t))