Skip to content

Commit b2d9692

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 b2d9692

File tree

1 file changed

+53
-4
lines changed

1 file changed

+53
-4
lines changed

evil-vars.el

Lines changed: 53 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1842,10 +1842,59 @@ 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 (;; Invisible
1849+
(func-invisible-p
1850+
(cond
1851+
;; `org-mode'
1852+
((and (derived-mode-p 'org-mode)
1853+
(fboundp 'org-invisible-p))
1854+
#'org-invisible-p)
1855+
1856+
;; `outline-mode' and `outline-minor-mode'
1857+
((and (or (derived-mode-p 'outline-mode)
1858+
(bound-and-true-p outline-minor-mode))
1859+
(fboundp 'outline-invisible-p))
1860+
#'outline-invisible-p)))
1861+
1862+
;; Back to heading
1863+
(func-back-to-heading
1864+
(cond
1865+
;; `org-mode'
1866+
((and (derived-mode-p 'org-mode)
1867+
(fboundp 'org-back-to-heading))
1868+
#'org-back-to-heading)
1869+
1870+
;; `outline-mode' and `outline-minor-mode'
1871+
((and (or (derived-mode-p 'outline-mode)
1872+
(bound-and-true-p outline-minor-mode))
1873+
(fboundp 'outline-back-to-heading))
1874+
#'outline-back-to-heading))))
1875+
(if (not (and func-back-to-heading
1876+
func-invisible-p))
1877+
(with-no-warnings
1878+
(show-entry)
1879+
(show-children))
1880+
;; Repeatedly reveal children and body until the entry is no
1881+
;; longer folded
1882+
(condition-case nil
1883+
;; Repeatedly reveal children and body until the entry is no
1884+
;; longer folded
1885+
(while (save-excursion
1886+
;; Folded?
1887+
(funcall func-back-to-heading)
1888+
(end-of-line)
1889+
(funcall func-invisible-p (point)))
1890+
(save-excursion
1891+
(funcall func-back-to-heading)
1892+
(with-no-warnings
1893+
(show-children)
1894+
(show-entry))))
1895+
;; Ignore the `outline-back-to-heading' error
1896+
(outline-before-first-heading
1897+
nil))))))
18491898
:open-rec show-subtree
18501899
:close hide-subtree)
18511900
((origami-mode)

0 commit comments

Comments
 (0)