Subject: bug#58928: 29.0.50; overlays in org-mode are disrupted after call `org-capture`

From: Matt Armstrong <[email-masked]>
Date: Tue, 01 Nov 2022 15:36:20 -0700

> Thanks for looking into this, Ihor!
>
> I don't know, but my guess is that the indirect buffer thing is
> already a good starting point for Stefan/Matt.

I can repro this with a test.org file containing one simple entry:

----------------------------------------------------------------------
* DONE test
My dog has fleas, a *lot* of fleas!
----------------------------------------------------------------------

As Eli Quian instructed, use Shift-TAB in test.org to get it like this:

----------------------------------------------------------------------
* DONE test...
----------------------------------------------------------------------

At that point there is one overlay:

----------------------------------------------------------------------
Buffer #<buffer test.org> has 1 overlays.

#<overlay from 12 to 49 in test.org>
(isearch-open-invisible
 #[128 "\300\301!\207"
       [org-show-context isearch]
       3 "\n\n(fn &rest _)"]
 invisible outline evaporate t)
----------------------------------------------------------------------

This covers from the newline just after "* DONE test" to end of buffer.

Now, "M-x org-capture" gets you a capture buffer and the test.org buffer
is already displaying the wrong thing:

----------------------------------------------------------------------
* DONE t...s!
----------------------------------------------------------------------

while CAPTURE-test.org is displaying this (the '|' is (point)):

----------------------------------------------------------------------
* |
----------------------------------------------------------------------

If I erase the "* " from CAPTURE-test.org then test.org displays this:

----------------------------------------------------------------------
* DONE tes...
----------------------------------------------------------------------

And if I "M-x widen" CAPTURE-test.org I see this:

----------------------------------------------------------------------

* DONE test
My dog has fleas, a *lot* of fleas!
----------------------------------------------------------------------

I cancel out and re-do the M-x org-capture, then type in a new org entry
in CAPTURE-test.org, which looks like:

----------------------------------------------------------------------
* My new org heading
----------------------------------------------------------------------

...and test.org looks like this:

----------------------------------------------------------------------
...s, a *lot* of fleas!
----------------------------------------------------------------------