luukvbaal / nnn.nvim

File manager for Neovim powered by nnn.
BSD 3-Clause "New" or "Revised" License
423 stars 9 forks source link

`replace_netrw` throws error when configured via Packer #26

Closed jose-elias-alvarez closed 2 years ago

jose-elias-alvarez commented 2 years ago

Thanks for the great plugin! I'm a big fan of nnn and am surprised to see how well it works as a file tree.

I'm having a small issue with the replace_netrw setting that I wasn't able to figure out by going through the code. This is the minimal config required to replicate the issue:

vim.cmd("packadd packer.nvim")

require("packer").startup(function()
    use({ "wbthomason/packer.nvim", opt = true })

    use({
        "luukvbaal/nnn.nvim",
        config = function()
            require("nnn").setup({ replace_netrw = "explorer" })
        end,
    })
end)

With this config, opening Neovim with nvim . immediately throws the following error:

Error detected while processing function <SNR>13_VimEnter[10]..<SNR>13_LocalBrowse:
line   32:
E117: Unknown function: netrw#LocalBrowseCheck

The explorer does open correctly, and opening subsequent directories (e.g. with :e .) once Neovim is open doesn't throw any errors.

The strange part is that moving the config outside of packer.startup makes everything work properly:

vim.cmd("packadd packer.nvim")

require("packer").startup(function()
    use({ "wbthomason/packer.nvim", opt = true })

    use("luukvbaal/nnn.nvim")
end)

require("nnn").setup({ replace_netrw = "explorer" })

With this config, nvim . opens the explorer without any errors.

It's also worth mentioning that I get this issue with the latest Neovim master (NVIM v0.6.0-dev+622-gfd6df7481) but not with 0.5.1, which works as expected with both configs. I have no idea what might have changed since 0.5.1 that affects this. It's not a dealbreaker for me, since I can achieve the same result with nvim -c NnnExplorer and everything works once Neovim is actually open, but I figured it might be worth reporting in case there's an easy fix that I'm unaware of.

luukvbaal commented 2 years ago

Didn't notice this because I set loaded_netrw to 1 in my init.lua, preventing netrw from loading at all.

This plugin also spoofs the netrw loaded values when replace_netrw is set in the setup function but it seems this is not always (on the latest nvim?) early enough to disable netrw.

The error should be avoided on the latest commit which clears the FileExplorer autocmd before the schedule() call, please confirm.

I would still suggest spoofing the netrw loaded variables to improve your startup time if you're gonna use replace_netrw though. I.e. set in your init.lua:

vim.g.loaded_netrw = 1
vim.g.loaded_netrwPlugin = 1
vim.g.loaded_netrwSettings = 1
vim.g.loaded_netrwFileHandlers = 1
jose-elias-alvarez commented 2 years ago

Awesome, thanks for the quick fix!

luukvbaal commented 2 years ago

Thanks for reporting and I'm glad you're enjoying the plugin!