emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Imran Khan <imran@khan.ovh>
To: emacs-orgmode@gnu.org
Subject: [BUG] Writing table to a folded drawer unfolds it. [9.7.12 (release_9.7.12 @ /home/natrys/.emacs.d/elpa/org-mode/lisp/)]
Date: Tue, 15 Oct 2024 01:07:02 +0600	[thread overview]
Message-ID: <285d8923e769bbaadb990286c5b966f5@khan.ovh> (raw)

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

It seems to be specific to tables in my testing because writing anything
else doesn't cause the drawer to unfold like that.

For setup, given this simple org-mode file (test1.org):

```
* Headline
:DRAWER:
00000000
:END:

Content.
```

And a function that writes a table to current drawer at point:

```
(defun my-edit-drawer ()
  (let* ((element (org-element-at-point))
         (begin (org-element-property :contents-begin element))
         (end (org-element-property :contents-end element)))
    (delete-region begin end)
    (goto-char begin)
    
    (insert "| time |\n")
    (insert "|-+|\n")
    (insert "| " (format "%f" (time-to-seconds)) " |\n")

    ;; problem happens without this align call too
    ;; so this is just for good visual
    (org-table-align)))
```

If we edit the test1.org with elisp:

```
(with-current-buffer "test1.org"
  ;; reset visibility
  (org-show-all)

  ;; make sure all the drawers are folded at first
  (org-fold-hide-drawer-all)

  (goto-char (point-min))
  (search-forward ":DRAWER:")
  (beginning-of-line)

  ;; At the drawer now, let's write a table to it
  (when (org-at-drawer-p) (my-edit-drawer))

  ;; Once done with writing, really make sure drawer is folded again
  (org-fold-hide-drawer-all))
```

Not only had the originally folded drawer been unfolded, but that last
`org-fold-hide-drawer-all` call that should have folded it back again,
doesn't (but it works if I independently call it afterwards).

----

For some extra context, I arrived here because this causes really
annoying visual glitches in org-fc (a package for flashcards and spaced
repetition in org-mode). In org-fc, you can mark certain headlines as
questions for flashcard with answers below, then org-fc lets you review
those, and your performance data is stored in a table inside a drawer
under that question.

Let's say you have a top level headline, and then a few questions below
it (test2.org):

```
* Subject

** Question 1
:DRAWER:
0000
:END:

Content.

** Question 1
:DRAWER:
0000
:END:

Content.
```

I am simplifying this but when you are reviewing a question, org-fc lets
you see ancestor headlines (e.g. subject here) for extra context (but
none of the siblings) with: `(org-fold-show-set-visibility 'ancestors)`.

Let's say you just reviewed Question 1 (which wrote to table in its
drawer), and moved on to Question 2:

```
(with-current-buffer "test2.org"
  ;; reset visibility
  (org-show-all)

  ;; make sure all the drawers are folded
  (org-fold-hide-drawer-all)

  (goto-char (point-min))
  (search-forward ":DRAWER:")
  (beginning-of-line)

  ;; we review Question 1 and write to its drawer
  (when (org-at-drawer-p) (my-edit-drawer))

  ;; really make sure drawer is folded after writing
  (org-fold-hide-drawer-all)

  ;;; and now we want to review Question 2

  ;; but first fold everything
  (while (org-up-heading-safe))
  (org-fold-subtree t)

  ;; now only show Question 2 with ancestor context
  (search-forward "Question 2")
  (org-fold-show-set-visibility 'ancestors)
  (org-fold-show-subtree))
```

This should show Question 2, with only Subject headline above.

But this issue causes the table in Question 1's drawer somehow bleed
into the view:

```
* Top Level...
|              time |
|-------------------|
| 1728928902.770990 |
:END:...
** Question 2
:DRAWER:...

Content.
```

----

Anyway, I am using Emacs from master branch, and latest release of
org-mode (9.7.12). But I have checked that I can reproduce this with
`emacs -Q` which loads bundled org-mode (9.7.11) with no other custom
setting.

But I can't reproduce this on Emacs 29.4 with its bundled org-mode (9.6.15).
I am presuming this is an org-mode issue, rather than overlay rendering
problem or something else in Emacs itself, but I am not sure.

----

Emacs  : GNU Emacs 31.0.50 (build 1, x86_64-unknown-linux-gnu, cairo version 1.18.0) of 2024-10-14
Package: Org mode version 9.7.12 (release_9.7.12 @ /home/natyrs/.emacs.d/elpa/org-mode/lisp/)


             reply	other threads:[~2024-10-14 19:08 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-14 19:07 Imran Khan [this message]
2024-10-15 18:09 ` [BUG] Writing table to a folded drawer unfolds it. [9.7.12 (release_9.7.12 @ /home/natrys/.emacs.d/elpa/org-mode/lisp/)] Ihor Radchenko
2024-10-16 13:05   ` Imran Khan

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=285d8923e769bbaadb990286c5b966f5@khan.ovh \
    --to=imran@khan.ovh \
    --cc=emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).