org-element: Optimize parser only when cache is active
* lisp/org-element.el (org-element-at-point): Try opportunistic shortcut only when cache is active.
This commit is contained in:
parent
15246d1165
commit
5a2dabc21b
|
@ -5087,14 +5087,15 @@ first row."
|
||||||
(point)
|
(point)
|
||||||
(list (org-element-headline-parser (point-max) t))))))
|
(list (org-element-headline-parser (point-max) t))))))
|
||||||
(t
|
(t
|
||||||
;; Opportunistic shortcut. Instead of going back to headline
|
(catch 'loop
|
||||||
;; above (or beginning of buffer) and descending again, first
|
(when org-element-use-cache
|
||||||
;; try to find a known element above current position. Give up
|
;; Opportunistic shortcut. Instead of going back to
|
||||||
;; after 3 tries or when we hit a headline (or beginning of
|
;; headline above (or beginning of buffer) and descending
|
||||||
;; buffer).
|
;; again, first try to find a known element above current
|
||||||
|
;; position. Give up after 3 tries or when we hit
|
||||||
|
;; a headline (or beginning of buffer).
|
||||||
(beginning-of-line)
|
(beginning-of-line)
|
||||||
(skip-chars-backward " \r\t\n")
|
(skip-chars-backward " \r\t\n")
|
||||||
(catch 'loop
|
|
||||||
(dotimes (i 3)
|
(dotimes (i 3)
|
||||||
(unless (re-search-backward org-element-paragraph-separate nil t)
|
(unless (re-search-backward org-element-paragraph-separate nil t)
|
||||||
(throw 'loop (goto-char (point-min))))
|
(throw 'loop (goto-char (point-min))))
|
||||||
|
@ -5125,11 +5126,11 @@ first row."
|
||||||
(throw 'loop nil))
|
(throw 'loop nil))
|
||||||
(let ((cached (org-element-cache-get (point) 'element)))
|
(let ((cached (org-element-cache-get (point) 'element)))
|
||||||
;; Search successful: we know an element before point
|
;; Search successful: we know an element before point
|
||||||
;; which is not an headline. If it has a common ancestor
|
;; which is not an headline. If it has a common
|
||||||
;; with ORIGIN, set this ancestor as the current parent
|
;; ancestor with ORIGIN, set this ancestor as the
|
||||||
;; and the element as the one to check. Otherwise, move
|
;; current parent and the element as the one to check.
|
||||||
;; at top level and start parsing right after its broader
|
;; Otherwise, move at top level and start parsing right
|
||||||
;; ancestor.
|
;; after its broader ancestor.
|
||||||
(when cached
|
(when cached
|
||||||
(let ((cache-end (org-element-property :end cached)))
|
(let ((cache-end (org-element-property :end cached)))
|
||||||
(if (or (> cache-end origin)
|
(if (or (> cache-end origin)
|
||||||
|
@ -5146,7 +5147,7 @@ first row."
|
||||||
(setq element up
|
(setq element up
|
||||||
parent (org-element-property :parent up)
|
parent (org-element-property :parent up)
|
||||||
end (org-element-property :end up))))))
|
end (org-element-property :end up))))))
|
||||||
(throw 'loop nil))))
|
(throw 'loop nil)))))
|
||||||
;; Opportunistic search failed. Move back to beginning of
|
;; Opportunistic search failed. Move back to beginning of
|
||||||
;; section in current headline, if any, or to first non-empty
|
;; section in current headline, if any, or to first non-empty
|
||||||
;; line in buffer otherwise.
|
;; line in buffer otherwise.
|
||||||
|
|
Loading…
Reference in New Issue