org-element-cache-map never returns when the buffer is narrowed to a
subtree that contains a plain list followed by a non-list line, and
the next top-level heading has a subheading.
Minimal file (test.org):
* A
- item
text
* B
** C
Steps (emacs -Q):
emacs -Q --batch --eval "(progn (require 'org)
(find-file \"test.org\")
(org-narrow-to-subtree)
(org-element-cache-map #'ignore :granularity 'element)
(message \"done\"))"
Expected: "done" at once. Actual: never returns (CPU-bound until C-g).
Variations, all with emacs -Q:
- Not narrowed: returns at once.
- Narrowed, with :narrow t: returns at once.
- Narrowed, org-element-map over (org-element-parse-buffer 'element):
returns at once.
- Without the "- item" line, without the "text" line, or without
"** C": returns at once. The line after the item can also be a
LaTeX environment, a fixed-width line or a #+begin_quote block.
A profile of the real case shows the time in org-element-cache-map ->
org-element-at-point, with org-element--parse-to,
org-element--cache-sync and org-element--cache-active-p underneath.
User-visible effect: with the new org-latex-preview (main), previewing
LaTeX in a narrowed subtree hangs Emacs when the subtree has a list
followed by a LaTeX environment, e.g.
* A
- The index is defined as:
\begin{equation}
x = 1
\end{equation}
* B
** C
Narrow to * A and run C-u C-u C-c C-x C-l. The hang is in
org-latex-preview--get-numbered-environments, which calls
org-element-cache-map over the accessible region. Presentation
packages that narrow to each slide (e.g. org-slideboard) hit this on
any slide like that.
Seen with:
- Org 9.8.7 (built into Emacs 32.0.50)
- Org main f38ac21c2 (2026-10-18)