orgmode
orgmode copied to clipboard
Date ranges don't work in body of last headline
Describe the bug
Probably related to #303
Steps to reproduce
- Following org file, cursor is at pipe:
* a
<2022-05-27 Fri 14:00>--|
- Try to enter the second date with
<leader>oi.
- Observe error:
[orgmode] Failed to parse current headline. Make sure there are no errors in the document.
Expected behavior
date added
Emacs functionality
date added
Minimal init.lua
used default minimal_init.lua
Screenshots and recordings
No response
OS / Distro
ubuntu 20.04, alacritty
Neovim version/commit
master
Additional context
By the way, is it on purpose that when I do <leader>oi.
to add a date (anywhere, not just in this specific context), the date gets put before the cursor and not after it? It doesn't make so much sense to me that it gets put before the cursor. I can open a separate issue if you want.
I can reproduce this. Furthermore, if I add any line below the date range, even in the same heading, its starts working:
I agree with you @Maltimore that the cursor is confusing. It behaves like pasting with p
, when most of the time I would expect it to work like P
. As you can see in the gif, I have to add the space between the first and the second date. This space then gets pushed to the end of the line, when actually I never wanted it to begin with.
Btw: adding a new date in front or in between two dates works fine. It truly must be the end of the last line
I asked about this parsing error here: https://github.com/milisims/tree-sitter-org/issues/39 but apparently from the tree-sitter side this is the expected behavior. By the way @jgollenz I think (I'm not sure because it's difficult to see what exactly comes after the date in your gif) that what you experienced is not current anymore, i.e. adding another line below doesn't fix the behavior now.
Thanks for looking into this. I'm not really sure if it's about timestamps though, I think the culprit is the last line. I've noticed strange behavior on the last line of documents before.
Indeed, things seem to have changed. But now I don't get an error message when I try to add a second date, but it instead it changes the first date. Also: I noticed a crucial detail between what I'm doing in the gif and what you wrote in the issue. I have
* foo
<2023-02-11> |
but you tried
* foo
<2023-02-11>--|
Don't add the dashes, just one space after the timestamp. Still, the last line IS wonky. I'll look into it
There's an undocumented behavior of nvim-orgmode that is supposed to trigger in exactly your scenario (space after timestamp and cursor after that) where it automatically inserts a date range. I suggested in another issue that I think this (anyways undocumented) behavior is not necessary as it only adds two dashes. I'm on mobile right now, will update this comment later with more specific info.
I also tried looking deeper into it and I saw that when things go wrong, the function File:get_node_at_cursor(cursor)
in the file lua/orgmode/parser/file.lua
finds a wrong node, namely it goes to the document
node (is that the root node?).
Somewhat related to this, I also have a question regarding the code in this function, can't figure it out for the life of me: https://github.com/nvim-orgmode/orgmode/discussions/504
undocumented behavior
It's documented here, although hard to catch: When this command is used twice in succession, a time range is inserted
. But in emacs orgmode, inserting a timestamp results in:
* foo
<2023-02-02> |
It adds a space after the timestamp. The cursor is on that timestamp and you easily add another one to create a range. We don't do that atm. After inserting a timestamp, the cursor is on the closing angled bracket. To create a range you have to
- enter insert mode after the timestamp (
a
) - enter a space (
- exit to normal mode (
<ESC>
) - and finally execute the shortcut again (
<leader>oi.
)
Also, doing that will currently leave a trailing whitespace. But changing the current behavior to match the one in emacs will leave trailing whitespace after every inserted timestamp :/
This issue should be resolved for some time now.
There's an undocumented behavior of nvim-orgmode that is supposed to trigger in exactly your scenario (space after timestamp and cursor after that) where it automatically inserts a date range. I suggested in another issue that I think this (anyways undocumented) behavior is not necessary as it only adds two dashes. I'm on mobile right now, will update this comment later with more specific info.
For this, I did some changes how we append dates and explained it here https://github.com/nvim-orgmode/orgmode/pull/489#issuecomment-1974904753
Works perfectly, thank you!!