Skip to content

Commit e06e6a8

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 e06e6a8

File tree

1 file changed

+56
-4
lines changed

1 file changed

+56
-4
lines changed

evil-vars.el

Lines changed: 56 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1842,10 +1842,62 @@ Elements have the form (NAME . FUNCTION).")
18421842
:close-all ,(lambda ()
18431843
(with-no-warnings (hide-sublevels 1)))
18441844
:toggle outline-toggle-children
1845-
:open ,(lambda ()
1846-
(with-no-warnings
1847-
(show-entry)
1848-
(show-children)))
1845+
:open
1846+
,(lambda ()
1847+
(save-excursion
1848+
(let (func-invisible-p
1849+
func-back-to-heading
1850+
func-on-heading-p)
1851+
(cond
1852+
;; `outline-mode' and `outline-minor-mode'
1853+
((and (or (derived-mode-p 'outline-mode)
1854+
(bound-and-true-p outline-minor-mode))
1855+
(fboundp 'outline-invisible-p))
1856+
(setq func-on-heading-p #'outline-on-heading-p)
1857+
(setq func-back-to-heading #'outline-back-to-heading)
1858+
(setq func-invisible-p #'outline-invisible-p))
1859+
1860+
;; `org-mode'
1861+
((and (derived-mode-p 'org-mode)
1862+
(fboundp 'org-invisible-p))
1863+
(setq func-on-heading-p #'org-on-heading-p)
1864+
(setq func-back-to-heading #'org-back-to-heading)
1865+
(setq func-invisible-p #'org-invisible-p)))
1866+
1867+
(if (not (and func-back-to-heading
1868+
func-invisible-p
1869+
func-on-heading-p))
1870+
(with-no-warnings
1871+
(show-entry)
1872+
(show-children))
1873+
;; Repeatedly reveal children and body until the entry is no
1874+
;; longer folded
1875+
(condition-case nil
1876+
(let ((on-invisible-heading
1877+
(when (funcall func-on-heading-p t)
1878+
(funcall func-invisible-p (point)))))
1879+
;; Repeatedly reveal children and body until the
1880+
;; entry is no longer folded
1881+
(while (save-excursion
1882+
;; Folded?
1883+
(funcall func-back-to-heading)
1884+
(end-of-line)
1885+
(funcall func-invisible-p (point)))
1886+
(save-excursion
1887+
(funcall func-back-to-heading)
1888+
(with-no-warnings
1889+
(show-children)
1890+
(show-entry))))
1891+
1892+
;; If the header was previously hidden, hide the subtree to
1893+
;; collapse it. Otherwise, leave the fold open. This allows
1894+
;; the user to decide whether to expand the content under
1895+
;; the cursor.
1896+
(when on-invisible-heading
1897+
(outline-hide-subtree)))
1898+
;; Ignore the `outline-back-to-heading' error
1899+
(outline-before-first-heading
1900+
nil))))))
18491901
:open-rec show-subtree
18501902
:close hide-subtree)
18511903
((origami-mode)

0 commit comments

Comments
 (0)