orgmode icon indicating copy to clipboard operation
orgmode copied to clipboard

Adding TODO headliner after current headline puts new TODO after blank newlines

Open kofm opened this issue 2 years ago • 10 comments

Describe the bug

First of all, thanks for all the work you're putting in this project. I could not live without it anymore.

When i try to add a new TODO e.g. with <leader>oit, the new todo is added after the empty new lines that follow that TODO instead of right before its content. I think that blank lines are treated as actual content of the previous TODO, even if they're completely empty (no whitespace in)

Steps to reproduce

  1. Go to a TODO that is followed by one or two blank lines
  2. Press oit

Expected behavior

The new TODO should be right after TODO and its content, ignoring whitespace (which can be used as separator between headlines)

Emacs functionality

No response

Minimal init.lua

I'm using

org_blank_before_new_entry = {
    heading = false,
    plain_list_item = false,
  }

Screenshots and recordings

No response

OS / Distro

Arch Linux

Neovim version/commit

0.6.1

Additional context

No response

kofm avatar Mar 07 '22 09:03 kofm

To be honest, that's the behavior I would expect. If there are newlines after a TODO item, they should belong to that TODO. What else should they belong to? Probably not the following headline?

Maltimore avatar Mar 08 '22 07:03 Maltimore

I usually use them as visual separation between headlines like it's shown in the README's screenshots https://user-images.githubusercontent.com/1782860/123550227-e8605800-d76c-11eb-96f6-c0a677d562d4.gif

How do you accomplish that? Do you manually reapply space each time you insert a new TODO item?

kofm avatar Mar 08 '22 07:03 kofm

Ah I see what you're trying to do! Personally I don't use blanks for visual separation so I haven't ecountered the issue before. I would maintain that the blanks under a headline belong to that headline, and to achieve what you want should be phrased differently, something like "how to insert a headline such that there's a blank both to the headlines above and below it". I'm curious how emacs org-mode does this, if I find some time I'll research that.

Maltimore avatar Mar 08 '22 08:03 Maltimore

@kofm why do you have heading set to false in in org_blank_before_entry? Try setting it to true, I think that will enable the behavior you want

jgollenz avatar Mar 08 '22 15:03 jgollenz

Thanks guys for your responses. I just installed and tested using emacs-org and I can reproduce the behaviour I'm expecting. I don't want to automatically insert a blankline before a new entry but I want the empty newlines following a TODO to not be considered as part of it. Example:

ATM if i have this situation:

* Heading 1
** TODO Foo | <-- cursor here
   Lorem ipsum

* Heading 2

if I press (default mapping) <leader>oit, i get this:

* Heading 1
** TODO Foo
   Lorem ipsum

** TODO Bar
* Heading 2

if instead i press <leader>oiT, i get this:

* Heading 1
** TODO Foo
** TODO Bar
   Lorem ipsum

* Heading 2

which disrupts any note-clock-etc. under the TODOs

Using vanilla emacs-org, in the same first scenario using S-M-RET (org-insert-todo-heading), gives me:

* Heading 1
** TODO Foo
   Lorem ipsum
** TODO Bar

* Heading 2

Which is what I would expect. (Reference: https://orgmode.org/manual/TODO-Basics.html#TODO-Basics)

I think the point here is that IF the line does not contain any whitespace it should be ignored and not considered as part of the previous TODO. Hope this helps

kofm avatar Mar 11 '22 14:03 kofm

Interesting. Prompted by your comment I just tried it in emacs as well and could reproduce. It's great that we can always cross-check behavior with emacs and just copy it.

Maltimore avatar Mar 11 '22 15:03 Maltimore

@kristijanhusak I think that the idea of @kofm to have the blank lines above a headline be part of that headline, and not the headline above it, would make the most sense. I guess this would have to be changed in the tree-sitter org grammar (@milisims), and then this issue would be automatically solved.

It's quite unintuitive at first. But as far as I can see, blank lines between headings are used mostly/only for visual separation. So making this change would have more advantages: if one does something with a headline (refiling it, moving it), it's practical if the separator whitespace gets moved to the new location as well.

Maltimore avatar May 11 '22 13:05 Maltimore

It's quite unintuitive at first

I'm not really interested in that change, for this reason. And I'm not really convinced by the utility of it, because can easily construct realistic examples where it would be counterintuitive to associate the empty line above a headline, like

* hl1
a

** hl2
** hl3

Moving / archiving hl2 doesn't make any sense to me to move with the newline, and creating a new headline above the hl2 section would create it immediately below the paragraph, rather than immediately above the headline.

milisims avatar May 11 '22 17:05 milisims

I agree with @milisims . Also, Emacs Org considers empty lines in a same way (not above the headline).

kristijanhusak avatar May 11 '22 17:05 kristijanhusak

@Maltimore can you confirm that empty lines above a headline are considered part of the headline tree in Emacs? I.e. what happens if you archive / refile such a headline? Do the empty lines get moved as well? I'm not sure whether this is what you meant in your last comment @kristijanhusak.

jgollenz avatar Aug 07 '22 19:08 jgollenz