summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Goaziou <mail@nicolasgoaziou.fr>2014-07-06 21:15:44 (GMT)
committer Nicolas Goaziou <mail@nicolasgoaziou.fr>2014-07-06 21:15:44 (GMT)
commit4235718d7901a243086288bdae32475b558ec1ce (patch)
tree001dd44fa29109553afd36cfb22fe04e12e822ae
parent0ce82e53a13c857e5548e8da8d59c2707fafab2e (diff)
downloadorg-mode-4235718d7901a243086288bdae32475b558ec1ce.zip
org-mode-4235718d7901a243086288bdae32475b558ec1ce.tar.gz
org-element: Small optimizations
* lisp/org-element.el (org-element-latex-fragment-parser): Avoid matching twice regexps in some cases. (org-element--object-lex): Avoid making a funcall if a line break isn't possible. This patch also removes the limit on the number of lines a latex fragment with a single dollar can span over.
-rw-r--r--lisp/org-element.el51
1 files changed, 26 insertions, 25 deletions
diff --git a/lisp/org-element.el b/lisp/org-element.el
index ff45c7b..f5208d4 100644
--- a/lisp/org-element.el
+++ b/lisp/org-element.el
@@ -2911,27 +2911,26 @@ Assume point is at the beginning of the LaTeX fragment."
(catch 'no-object
(save-excursion
(let* ((begin (point))
- (substring-match
- (or (catch 'exit
- (dolist (e (cdr org-latex-regexps))
- (let ((latex-regexp (nth 1 e)))
- (when (or (looking-at latex-regexp)
- (and (not (bobp))
- (save-excursion
- (backward-char)
- (looking-at latex-regexp))))
- (throw 'exit (nth 2 e))))))
- ;; Macro.
- (and (looking-at "\\\\[a-zA-Z]+\\*?\\(\\(\\[[^][\n{}]*\\]\\)\\|\\({[^{}\n]*}\\)\\)*")
- 0)
- ;; No fragment found.
- (throw 'no-object nil)))
- (value (org-match-string-no-properties substring-match))
- (post-blank (progn (goto-char (match-end substring-match))
- (skip-chars-forward " \t")))
+ (after-fragment
+ (if (eq (char-after) ?$)
+ (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)))
+ (case (char-after (1+ (point)))
+ (?\( (search-forward "\\)" nil t))
+ (?\[ (search-forward "\\]" nil t))
+ (otherwise
+ ;; Macro.
+ (and (looking-at "\\\\[a-zA-Z]+\\*?\\(\\(\\[[^][\n{}]*\\]\\)\\|\\({[^{}\n]*}\\)\\)*")
+ (match-end 0))))))
+ (post-blank (if (not after-fragment) (throw 'no-object nil)
+ (goto-char after-fragment)
+ (skip-chars-forward " \t")))
(end (point)))
(list 'latex-fragment
- (list :value value
+ (list :value (buffer-substring-no-properties begin after-fragment)
:begin begin
:end end
:post-blank post-blank))))))
@@ -4277,12 +4276,14 @@ to an appropriate container (e.g., a paragraph)."
(org-element-timestamp-parser))
(and (memq 'link restriction)
(org-element-link-parser)))))
- (?\\ (or (and (memq 'line-break restriction)
- (org-element-line-break-parser))
- (and (memq 'entity restriction)
- (org-element-entity-parser))
- (and (memq 'latex-fragment restriction)
- (org-element-latex-fragment-parser))))
+ (?\\
+ (if (eq (aref result 1) ?\\)
+ (and (memq 'line-break restriction)
+ (org-element-line-break-parser))
+ (or (and (memq 'entity restriction)
+ (org-element-entity-parser))
+ (and (memq 'latex-fragment restriction)
+ (org-element-latex-fragment-parser)))))
(?\[
(if (eq (aref result 1) ?\[)
(and (memq 'link restriction)