Skip to content

Commit 3f768fd

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 3f768fd

File tree

1 file changed

+64
-4
lines changed

1 file changed

+64
-4
lines changed

evil-vars.el

Lines changed: 64 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1842,10 +1842,70 @@ 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+
(let ((header-visible (save-excursion
1884+
(funcall func-back-to-heading t)
1885+
(not (funcall func-invisible-p
1886+
(point))))))
1887+
;; Repeatedly reveal children and body until the
1888+
;; entry is no longer folded
1889+
(while (save-excursion
1890+
;; Folded?
1891+
(funcall func-back-to-heading)
1892+
(end-of-line)
1893+
(funcall func-invisible-p (point)))
1894+
(save-excursion
1895+
(funcall func-back-to-heading)
1896+
(with-no-warnings
1897+
(show-children)
1898+
(show-entry))))
1899+
1900+
;; If the header was previously hidden, hide the subtree to
1901+
;; collapse it. Otherwise, leave the fold open. This allows
1902+
;; the user to decide whether to expand the content under
1903+
;; the cursor.
1904+
(unless header-visible
1905+
(outline-hide-subtree)))
1906+
;; Ignore the `outline-back-to-heading' error
1907+
(outline-before-first-heading
1908+
nil))))))
18491909
:open-rec show-subtree
18501910
:close hide-subtree)
18511911
((origami-mode)

0 commit comments

Comments
 (0)