orgmode icon indicating copy to clipboard operation
orgmode copied to clipboard

Cant open file by external link with `<leader>oo`

Open VolkovIlia opened this issue 2 years ago • 1 comments

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

  1. Enter external link to file [[todo.org]]
  2. 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

image

OS / Distro

ArtixLinux Kernel: 5.18.8-artix1-1

Neovim version/commit

v0.7.2

Additional context

No response

VolkovIlia avatar Jul 15 '22 13:07 VolkovIlia

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?

jgollenz avatar Jul 15 '22 16:07 jgollenz

@kristijanhusak I think this can be closed

jgollenz avatar Aug 15 '22 15:08 jgollenz

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.

kristijanhusak avatar Aug 15 '22 15:08 kristijanhusak

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.

jgollenz avatar Aug 15 '22 15:08 jgollenz

Perhaps the buffer itself may be considered the "root heading", with depth -1.

jgollenz avatar Aug 15 '22 15:08 jgollenz

I'm also hitting the same issue with any relative path link

zdcthomas avatar Sep 05 '22 05:09 zdcthomas

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:

link_priorities

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.

jgollenz avatar Sep 05 '22 10:09 jgollenz

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.

zdcthomas avatar Sep 05 '22 15:09 zdcthomas

Do you know how Emacs behaves in such a case? Does it use the path relative to the filepath of the current buffer?

jgollenz avatar Sep 05 '22 17:09 jgollenz

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.

kristijanhusak avatar Sep 05 '22 19:09 kristijanhusak