Imran Khan <im...@khan.ovh> writes:

> ... Writing table to a folded drawer unfolds it
> ...
>     (insert "| " (format "%f" (time-to-seconds)) " |\n")

This is expected.
In the middle of the editing, you are breaking the drawer structure,
transiently having something like

:DRAWER:
...
| :END:

So, Org mode unfolds the drawer to avoid having a fold that cannot be
unfolded by normal means.

> Also any attempt to fold the drawer immediately afterwards (in same
> elisp thread of execution) does nothing.

This one is a bit tricky.
The above unfolding does not happen immediately after the edit - we
cannot reliably do it from inside after-change-functions.  So, the
unfolding of drawers is delayed until `post-command-hook' is evaluated.

Since your attempt to fold the drawer happens _before_
`post-command-hook', your folding is effectively undone shortly after.

To work around the problem, you can use
`org-fold-core-ignore-fragility-checks' macro around your code modifying
the drawer contents; as long as you know that you are not actually
breaking the drawer structure.

P.S. The above is all quite tricky and should be eventually simplified
by using track-changes.el library (will be a part of Emacs 30). But not
yet, and not until we drop Emacs 29 support.

Wontfix.
Canceled.

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>

Reply via email to