nvim-orgmode / orgmode

Orgmode clone written in Lua for Neovim 0.9+.
https://nvim-orgmode.github.io/
MIT License
3.06k stars 137 forks source link

if a link url is file only, open_at_point() action will continue its execution to the end with self:_goto_headline(headline), which will cause an error message #807

Closed CaeChao closed 1 month ago

CaeChao commented 1 month ago

Describe the bug

image Error message: attempt to index field 'file' (a nil value) I think it is caused by the line 919 in lua/orgmode/org/mappings.lua: image which the line vim.cmd([[normal! zv]]) should be executed with a return, so that the function won't continue its execution to line 957 self:_goto_headline(headline) when the link is is_file_only

Steps to reproduce

create a file only link and open it at point

Expected behavior

should not popup error message

Emacs functionality

No response

Minimal init.lua


require('lazy').setup({
  {
    'nvim-orgmode/orgmode',
    event = 'VeryLazy',
    ft = { 'org' },
    config = function()
      require('orgmode').setup()
    end,
  },
}, {
  root = lazy_root,
  lockfile = nvim_root .. '/lazy.json',
  install = {
    missing = false,
  },
})

Screenshots and recordings

No response

OS / Distro

Linux

Neovim version/commit

v0.10.0

Additional context

No response

kristijanhusak commented 1 month ago

Can you try using this branch and see if it works?

https://github.com/nvim-orgmode/orgmode/pull/803

CaeChao commented 1 month ago

image The Error message is replaced with a warning message in feat/new-links

kristijanhusak commented 1 month ago

Please provide exact steps how to reproduce. I'm not able to reproduce it. I tried these formats and none of them error/warning:

* Headline
Non existing file:
[[file:./test_file.org]]
[[./test_file.org]]

Existing file:
[[file:./todos.org]]
[[./todos.org]]
CaeChao commented 1 month ago

Steps to Reproduce:

test.org:

[[./test_file.org][Test file]]

image test_file.org:


* Headline

** Head 2

image

CaeChao commented 1 month ago

After I added a return before the vim.cmd at line 919 lua/orgmode/org/mappings.lua in master branch

if link.url:is_file_only() then
    local file_path = link.url:get_file()
    local cmd = file_path and string.format('edit %s', fs.get_real_path(file_path)) or ''
    vim.cmd(cmd)
    return vim.cmd([[normal! zv]]) -- line 919
  end

none of error/warning appear again

kristijanhusak commented 1 month ago

Since https://github.com/nvim-orgmode/orgmode/pull/803 will be merged fairly soon, I fixed the issue there.

kristijanhusak commented 1 month ago

PR https://github.com/nvim-orgmode/orgmode/pull/803 is merged, so I'm considering this issue solved. If you run into anything let me know.