orgmode
orgmode copied to clipboard
Cant open file by external link with `<leader>oo`
Describe the bug
Got error when trying to open files by <leader>oo
.../packer/start/orgmode.nvim/lua/orgmode/org/mappings.lua:869: attempt to index local 'item' (a nil value)
Steps to reproduce
- Enter external link to file
[[todo.org]]
- Try to open it with
<leader>oo
Expected behavior
Open file in new tab.
Emacs functionality
No response
Minimal init.lua
Standard
Screenshots and recordings
OS / Distro
ArtixLinux Kernel: 5.18.8-artix1-1
Neovim version/commit
v0.7.2
Additional context
No response
I think the issue is due to you not having any org headline at all in that file. When I change line 11 to * TODO [[todo.org]]
it works for me. I am unsure whether a file without any root headline is considered a valid org-file in emacs. @kristijanhusak?
@kristijanhusak I think this can be closed
I am unsure whether a file without any root headline is considered a valid org-file in emacs
@jgollenz did you check this? I think this should work even without headline, but I didn't check how emacs works.
Oh well, looks like Emacs has no trouble with that. A file just containing [[file:~/path/to/file.org]]
will open that file in a new buffer upon C-c C-o
.
Perhaps the buffer itself may be considered the "root heading", with depth -1.
I'm also hitting the same issue with any relative path link
Yes, this will happen for all links. It is because the logic will first check whether the cursor is on a date and that function tries to access the closest headline, which does not exist. Another interesting implication of that:
A link name that looks like a date will be interpreted as a date. I guess we should first check whether the cursor is inside a link.
After a bit of hacking, I believe that even with the date issue fixed and the heading present, it'll still look in the wrong place for relative paths. I think since it's ultimately calling edit xxxx
on the file path, relative links will open relative to the CWD instead of relative to the path of the file.
Do you know how Emacs behaves in such a case? Does it use the path relative to the filepath of the current buffer?
I pushed a fix for the reported issue. It should figure out the link even without the headline. Regarding the @zdcthomas , from what I tested, he is correct, Emacs opens things relative to the current file. I'll open up a separate issue for that.