Subject: bug#65734: [BUG] kill-whole-line on folded subtrees [9.6.8 (release_9.6.8-3-g21171d @ /home/w/usr/emacs/0/29/0/lisp/org/)]

From: Eli Zaretskii <[email-masked]>
Date: Tue, 05 Sep 2023 14:54:26 +0300

> Cc: [email-masked], [email-masked]
> From: Ihor Radchenko <[email-masked]>
> Date: Tue, 05 Sep 2023 10:29:20 +0000
> 
> As I described in the above, Org needs more control over the behaviour of
> `kill-line'/`kill-whole-line' when the visible line contains multiple
> lines of hidden text - to protect accidental deletions.
> A hook, where Org can intervene with a yes/no prompt, would be useful.
> It would also make sense to group the two edits together via
> `combine-after-change-calls', although a more universal way to know that
> certain edits are a part of the same known command (even when called
> non-interactively) would be useful.

The command kills in two parts for a good reason, which is explained
in the comments to the code.  So making a single group will not work,
I think, at least not in all situations.  And relying on after-change
hooks to fix this use case sounds too obscure and fragile to me.

Moreover, I don't think this is specific to Org: any mode that folds
or hides portions of text might hit the same problem.

So we could decide that this command needs to become smarter when the
visual line includes invisible text.  That is, improve the command
without making any Org-specific changes anywhere.  Patches to that
effect are welcome.

> In addition, `org-kill-line' acts specially in certain scenarios:
> 
> For
> * Heading <point> text :tag1:tag2:
> 
> `org-kill-line' will keep and re-align ":tag1:tag2:":
> 
> * Heading <point>      :tag1:tag2:
> 
> It would be nice if we could express such behavior without overriding
> the `kill-line' command.

This could be handled by a suitable extension to end-of-visible-line.
For example, introduce a new text property which end-of-visible-line
would then handle the same as it currently handles invisible text.