Skip to content

Commit 128745f

Browse files
committed
Fixes #1986: evil-open-fold fails to open folds in deeply nested outline/org headers
This commit fixes an issue in evil-mode where, in outline-mode or org-mode, attempting to open a folded section (zo) fails when the cursor is inside a deeply nested header. Previously, the fold would either not expand or expand incorrectly, leaving the nested content hidden and making navigation and editing of deeply nested structures difficult.
1 parent 334a636 commit 128745f

File tree

1 file changed

+27
-3
lines changed

1 file changed

+27
-3
lines changed

evil-vars.el

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1843,9 +1843,33 @@ Elements have the form (NAME . FUNCTION).")
18431843
(with-no-warnings (hide-sublevels 1)))
18441844
:toggle outline-toggle-children
18451845
:open ,(lambda ()
1846-
(with-no-warnings
1847-
(show-entry)
1848-
(show-children)))
1846+
(save-excursion
1847+
(let ((func-invisible-p
1848+
(cond
1849+
((and (derived-mode-p 'org-mode)
1850+
(fboundp 'org-invisible-p))
1851+
#'org-invisible-p)
1852+
((and (derived-mode-p 'outline-mode)
1853+
(fboundp 'outline-invisible-p))
1854+
#'outline-invisible-p)
1855+
(t
1856+
#'invisible-p))))
1857+
;; Ensure the current heading and body are fully
1858+
;; visible. Repeatedly reveal children and body until
1859+
;; the entry is no longer folded.
1860+
(while (save-excursion
1861+
(end-of-line)
1862+
(funcall func-invisible-p (point)))
1863+
(save-excursion
1864+
(outline-back-to-heading)
1865+
(with-no-warnings
1866+
(show-children)
1867+
(show-entry))))
1868+
1869+
;; Final pass to guarantee the heading under the cursor
1870+
;; is visible
1871+
(with-no-warnings
1872+
(show-entry)))))
18491873
:open-rec show-subtree
18501874
:close hide-subtree)
18511875
((origami-mode)

0 commit comments

Comments
 (0)