Subject: Re: bug#79286: outline-mode: attempting to open folded sections does not work as expected inside a deeply nested header

From: Rahguzar <[email-masked]>
Date: Thu, 21 Aug 2025 23:34:27 +0500

Hi James,

James Cherti <[email-masked]> writes:

> When using outline-mode or outline-minor-mode, attempting to
> open folded sections (outline-show-entry) does not work as
> expected when the cursor is positioned inside a deeply
> nested header.
>
> Steps to Reproduce:
> -------------------
> 1. Open an outline-mode buffer with multiple
>     nested headers, for example:
>
> Level 1
> ** Level 2
> *** Level 3
> **** Level 4: A
> Some content here
> Some content here
> Some content here
> Some content here
> **** Level 4: B
> Some content here
> Some content here
> Some content here
> Some content here
> **** Level 4: C
> Some content here
> Some content here< PUT THE CURSOR HERE
> Some content here
> Some content here
> **** Level 4: D
> Some content here
> Some content here
> Some content here
> Some content here
> Some content here
> **** Level 4: E
> Some content here
> Some content here
> Some content here
>
> 2. Put the cursor before `< PUT THE CURSOR HERE`
>
> 3. Collapse all folds with: (hide-sublevels 1)
>
> 6. Show entry: (outline-show-entry)
>
> The folds fail to expand fully in nested hierarchies, leaving all 
> content hidden except for `level 4: C`.
>
> Screenshot: 
> https://github.com/user-attachments/assets/2ea6c3bd-0284-40a7-90e5-1619bdf3acc5
>
> Expected Behavior:
> ------------------
> The expected behavior is that only the heading at point (and
> its associated content) should be expanded, while all
> ancestor headings remain collapsed. (Similar to other editors.)
>
> Actual Behavior:
> ----------------
> Only the heading at point expands, while other headings
> remain invisible, which is confusing. In some cases, these
> hidden headings cannot be revealed until the parent heading
> is first collapsed and then expanded again.

I have encountered this with isearch and was able to fix this
with in my init file.

```emacs-lisp
  (defun +outline-reveal (pos)
    (let ((heading-pos nil))
      (while (not (eq heading-pos (progn (outline-back-to-heading) (point))))
        (setq heading-pos (point))
        (outline-show-children)
        (goto-char pos))
      (outline-show-entry)
      (goto-char pos)))

  (defun +outline-invsible-open (&optional _)
    (when (and outline-minor-mode
               (outline-invisible-p))
      (+outline-reveal (point))))

  (setq outline-isearch-open-invisible-function #'+outline-invsible-open)
```
With an interactive spec the function +outline-reveal can be used as an
alternative to outline-show-entry without this problem but I can't
imagine a scenario where that might be needed.

> Environment:
> ------------
> * Emacs version: 30.2 and master branch 
> (ade6608e2587452c8ea565ce3057879379ebd0b5)
>
> --
> James Cherti
> GitHub: https://github.com/jamescherti
> Website: https://www.jamescherti.com/

Rahguzar