Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Date ranges don't work in body of last headline #307

Closed
Maltimore opened this issue May 27, 2022 · 8 comments
Closed

Date ranges don't work in body of last headline #307

Maltimore opened this issue May 27, 2022 · 8 comments
Labels
bug Something isn't working

Comments

@Maltimore
Copy link
Contributor

Describe the bug

Probably related to #303

Steps to reproduce

  1. Following org file, cursor is at pipe:
* a
  <2022-05-27 Fri 14:00>--|
  1. Try to enter the second date with <leader>oi.
  2. 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.

@Maltimore Maltimore added the bug Something isn't working label May 27, 2022
@jgollenz
Copy link
Contributor

jgollenz commented Aug 15, 2022

I can reproduce this. Furthermore, if I add any line below the date range, even in the same heading, its starts working:

date-range

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

@Maltimore
Copy link
Contributor Author

I asked about this parsing error here: milisims/tree-sitter-org#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.

@jgollenz
Copy link
Contributor

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

@Maltimore
Copy link
Contributor Author

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.

@Maltimore
Copy link
Contributor Author

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: #504

@jgollenz
Copy link
Contributor

jgollenz commented Feb 20, 2023

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

  1. enter insert mode after the timestamp (a)
  2. enter a space ( )
  3. exit to normal mode (<ESC>)
  4. 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 :/

@kristijanhusak
Copy link
Member

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 #489 (comment)

@Maltimore
Copy link
Contributor Author

Works perfectly, thank you!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants