mirror of
https://git.savannah.gnu.org/git/emacs/org-mode.git
synced 2024-09-29 20:37:51 +00:00
org-babel-tangle-collect-blocks: Use cache
* lisp/ob-tangle.el (org-babel-tangle-collect-blocks): Use element cache to find the containing headline instead of regexp search. Direct regexp search sometimes causes quadratic scaling. See https://lists.gnu.org/r/emacs-orgmode/2022-01/msg00484.html
This commit is contained in:
parent
70970dff8d
commit
2ae8d6c1cf
|
@ -37,6 +37,9 @@
|
||||||
(declare-function org-babel-update-block-body "ob-core" (new-body))
|
(declare-function org-babel-update-block-body "ob-core" (new-body))
|
||||||
(declare-function org-back-to-heading "org" (&optional invisible-ok))
|
(declare-function org-back-to-heading "org" (&optional invisible-ok))
|
||||||
(declare-function org-before-first-heading-p "org" ())
|
(declare-function org-before-first-heading-p "org" ())
|
||||||
|
(declare-function org-element--cache-active-p "org-element" ())
|
||||||
|
(declare-function org-element-lineage "org-element" (datum &optional types with-self))
|
||||||
|
(declare-function org-element-property "org-element" (property element))
|
||||||
(declare-function org-element-at-point "org-element" (&optional pom cached-only))
|
(declare-function org-element-at-point "org-element" (&optional pom cached-only))
|
||||||
(declare-function org-element-type "org-element" (element))
|
(declare-function org-element-type "org-element" (element))
|
||||||
(declare-function org-heading-components "org" ())
|
(declare-function org-heading-components "org" ())
|
||||||
|
@ -425,8 +428,10 @@ code blocks by target file."
|
||||||
(let ((counter 0) last-heading-pos blocks)
|
(let ((counter 0) last-heading-pos blocks)
|
||||||
(org-babel-map-src-blocks (buffer-file-name)
|
(org-babel-map-src-blocks (buffer-file-name)
|
||||||
(let ((current-heading-pos
|
(let ((current-heading-pos
|
||||||
(org-with-wide-buffer
|
(if (org-element--cache-active-p)
|
||||||
(org-with-limited-levels (outline-previous-heading)))))
|
(or (org-element-property :begin (org-element-lineage (org-element-at-point) '(headline) t)) 1)
|
||||||
|
(org-with-wide-buffer
|
||||||
|
(org-with-limited-levels (outline-previous-heading))))))
|
||||||
(if (eq last-heading-pos current-heading-pos) (cl-incf counter)
|
(if (eq last-heading-pos current-heading-pos) (cl-incf counter)
|
||||||
(setq counter 1)
|
(setq counter 1)
|
||||||
(setq last-heading-pos current-heading-pos)))
|
(setq last-heading-pos current-heading-pos)))
|
||||||
|
|
Loading…
Reference in a new issue