Skip to content

Commit 0ec3d0e

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 0ec3d0e

File tree

1 file changed

+56
-3
lines changed

1 file changed

+56
-3
lines changed

evil-vars.el

Lines changed: 56 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1843,9 +1843,62 @@ 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+
1853+
((and (or (derived-mode-p 'outline-mode)
1854+
(derived-mode-p 'outline-minor-mode))
1855+
(fboundp 'outline-invisible-p))
1856+
'outline-invisible-p)
1857+
1858+
(t
1859+
'invisible-p)))
1860+
(initial-point (point))
1861+
(visual-point nil)
1862+
(visual-init-point nil))
1863+
;; Unfolding loop
1864+
(while (and
1865+
;; Folded?
1866+
(save-excursion
1867+
(end-of-line)
1868+
(funcall func-invisible-p (point)))
1869+
;; When the real point differs from the visual
1870+
;; point, it indicates that the cursor is still
1871+
;; located within a hidden header. This prevents
1872+
;; infinite loops if the unfolding stops
1873+
;; changing the cursor position.
1874+
(or
1875+
(not visual-init-point)
1876+
(not visual-point)
1877+
(/= visual-init-point visual-point)))
1878+
1879+
(save-excursion
1880+
(outline-back-to-heading)
1881+
(beginning-of-line)
1882+
(setq visual-point (point))
1883+
(with-no-warnings
1884+
(show-children))
1885+
1886+
;; Go back to point
1887+
(goto-char initial-point)
1888+
(outline-back-to-heading)
1889+
(beginning-of-line)
1890+
(setq visual-init-point (point))))
1891+
1892+
;; Previous version of `outline-show-entry'
1893+
(save-excursion
1894+
(outline-back-to-heading t)
1895+
(outline-flag-region (1- (point))
1896+
(progn
1897+
(outline-next-preface)
1898+
(if (= 1 (- (point-max) (point)))
1899+
(point-max)
1900+
(point)))
1901+
nil)))))
18491902
:open-rec show-subtree
18501903
:close hide-subtree)
18511904
((origami-mode)

0 commit comments

Comments
 (0)