Skip to content

Commit a15fcd2

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 a15fcd2

File tree

1 file changed

+37
-3
lines changed

1 file changed

+37
-3
lines changed

evil-vars.el

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1843,9 +1843,43 @@ 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+
(func-back-to-heading
1858+
(cond
1859+
((and (derived-mode-p 'org-mode)
1860+
(fboundp 'org-back-to-heading))
1861+
#'org-back-to-heading)
1862+
((and (derived-mode-p 'outline-mode)
1863+
(fboundp 'outline-back-to-heading))
1864+
#'outline-invisible-p)
1865+
(t
1866+
#'beginning-of-visual-line))))
1867+
;; Repeatedly reveal children and body until the entry
1868+
;; is no longer folded
1869+
(while (save-excursion
1870+
(funcall func-back-to-heading)
1871+
(end-of-line)
1872+
(funcall func-invisible-p (point)))
1873+
(save-excursion
1874+
(funcall func-back-to-heading)
1875+
(with-no-warnings
1876+
(show-children)
1877+
(show-entry))))
1878+
1879+
;; Final pass to guarantee the heading under the cursor
1880+
;; and its body are visible
1881+
(with-no-warnings
1882+
(show-entry)))))
18491883
:open-rec show-subtree
18501884
:close hide-subtree)
18511885
((origami-mode)

0 commit comments

Comments
 (0)