nvim-orgmode / orgmode

Orgmode clone written in Lua for Neovim 0.9+.

Home Page:https://nvim-orgmode.github.io/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Orgmode as filetype plugin throws error

seflue opened this issue · comments

Describe the bug

When I load orgmode as ftplugin when opening org-files, I get the following error:

Error detected while processing BufReadPost Autocommands for "*":
Error executing lua callback: ...im---neovim/nvim-linux64/share/nvim/runtime/filetype.lua:24: Error executing lua: ...im---neovim/nvim-linux64/share/nvim/runtime/filetype.lua:25: BufReadPost Autocommands for "*"..FileType Autocommands for "org"..FileType Autocommands for "org": Vim(append):Error executing lua 
callback: ...bflu/.local/share/nvim/lazy/orgmode/lua/orgmode/init.lua:53: EISDIR: illegal operation on a directory
stack traceback:
        [C]: in function 'load_sync'
        ...bflu/.local/share/nvim/lazy/orgmode/lua/orgmode/init.lua:53: in function 'init'
        ...bflu/.local/share/nvim/lazy/orgmode/lua/orgmode/init.lua:77: in function 'reload'
        ...bflu/.local/share/nvim/lazy/orgmode/lua/orgmode/init.lua:94: in function <...bflu/.local/share/nvim/lazy/orgmode/lua/orgmode/init.lua:93>
        [C]: in function 'nvim_exec_autocmds'
        ...hare/nvim/lazy/lazy.nvim/lua/lazy/core/handler/event.lua:157: in function <...hare/nvim/lazy/lazy.nvim/lua/lazy/core/handler/event.lua:156>
        [C]: in function 'xpcall'
        .../.local/share/nvim/lazy/lazy.nvim/lua/lazy/core/util.lua:113: in function 'try'
        ...hare/nvim/lazy/lazy.nvim/lua/lazy/core/handler/event.lua:156: in function 'trigger'
        ...hare/nvim/lazy/lazy.nvim/lua/lazy/core/handler/event.lua:87: in function <...hare/nvim/lazy/lazy.nvim/lua/lazy/core/handler/event.lua:72>
        [C]: in function 'nvim_cmd'
        ...im---neovim/nvim-linux64/share/nvim/runtime/filetype.lua:25: in function <...im---neovim/nvim-linux64/share/nvim/runtime/filetype.lua:24>
        [C]: in function 'nvim_buf_call'
        ...im---neovim/nvim-linux64/share/nvim/runtime/filetype.lua:24: in function <...im---neovim/nvim-linux64/share/nvim/runtime/filetype.lua:10>
stack traceback:
        [C]: in function 'nvim_cmd'
        ...im---neovim/nvim-linux64/share/nvim/runtime/filetype.lua:25: in function <...im---neovim/nvim-linux64/share/nvim/runtime/filetype.lua:24>
        [C]: in function 'nvim_buf_call'
        ...im---neovim/nvim-linux64/share/nvim/runtime/filetype.lua:24: in function <...im---neovim/nvim-linux64/share/nvim/runtime/filetype.lua:10>
stack traceback:
        [C]: in function 'nvim_buf_call'
        ...im---neovim/nvim-linux64/share/nvim/runtime/filetype.lua:24: in function <...im---neovim/nvim-linux64/share/nvim/runtime/filetype.lua:10>

There were a lot of changes in the last weeks. After poking around a little bit in the code, I have the feeling, that the behavior how agenda files are read in, has changed and I might have a folder in my agenda files, which the function tries to treat as a file.

In this case I would expect a bit more robust behavior and at least give a hint, which file/folder is causing the error.

Currently I don't have the time to do a deeper investigation. If you, @kristijanhusak have an idea, I would be thankful, but if not, I will come back to this issue as soon as I have enough time to find out, what the cause actually is.

Steps to reproduce

  • Upgrade orgmode to latest version
  • remove treesitter dependencies from orgmode config
  • add ft = "org", to orgmode config (Lazy module)
  • open existing org file with nvim

Expected behavior

Load my orgfile without complaining.

Emacs functionality

No response

Minimal init.lua

local M = {
  "nvim-orgmode/orgmode",
  ft = "org",
  event = "VeryLazy", -- using VeryLazy leads to issues with session managers
}

Screenshots and recordings

No response

OS / Distro

Ubuntu 22.04

Neovim version/commit

v0.9.5

Additional context

No response

Does the issue happen when you do not use ft = 'org'?

It does look like there is some file that is treated as a directory, but that should not happen because I use glob function to find all the files. I also have directories in my orgfiles and lazy load my org plugin without any issues.

If this does not happen without ft = 'org', I'll need more info in the setup part. The minimal init you provided does not have anything.

Without ft='org' the plugin just doesn't load for the orgfile, until I type :set filetype=org which produces the very same error.

It doesn't work for any orgfile? Even if you open one that is outside of your agenda files? Here are few steps how you can debug it:

  1. Remove org_agenda_files and try opening some specific file, check if it works
  2. Do the thing you did in your last comment, but before that do :set debug=msg. This should print more errors.

When I edit an org-file outside of the agenda files, I get the error message on writing the file. If I change my agenda file folder to an empty one, the error message is gone - but the plugin only loads, if I set the filetype to "org".

So the ft option is not the source of the error but some unexpected file/folder in my agenda folders. I have also non-org files in my agenda folders but I used the pattern somefolder/**/*.org in the past to configure my agenda files. Because of the error I changed that to somefolder/**/* (according to the documentation) but this didn't remove the error.

Setting org as extension in glob is not necessary since I filter out only valid ones anyway. https://github.com/nvim-orgmode/orgmode/blob/master/lua/orgmode/files/init.lua#L353-L356

You can do it if you have a lot of files just to speed up the glob.

I'm not sure which non-org files you have. I have images and those are not causing any issues.

Also, do you get these errors on 0.3.1 version (with nvim-treesitter dependency)? If not, I'd appreciate it if you could bisect and see where the issue happens. I'll introduce a better error message once I figure out what the issue is and how to reproduce it.

Thanks for the hints. I will try to find the cause as soon as I have some more time and give you an update.

Found the cause: A directory with somename.org somehow sneaked into my agenda folders. It would be great, if you can catch this case somehow, because it could happen very easily, that someone creates a folder named something.org by purpose or by mistake.

Thanks, I'll look into it.

I pushed a fix. It will not warn you, it will just ignore everything that is not a file. That should fix the issue.