ghostbuster91 / nvim-next

Apache License 2.0
30 stars 6 forks source link

make_repeatable_pair line throws Error E5108 #17

Closed seb-mueller closed 9 months ago

seb-mueller commented 10 months ago

I tried to get this plugin to work, but are getting an error when sourcing my vimrc: It works fine up to this stage, since map ; rightfully maps to nvim-next

lua << EOF
local nvim_next_builtins = require("nvim-next.builtins")
 require("nvim-next").setup({
     default_mappings = {
         repeat_style = "original",
     },
     items = {
         nvim_next_builtins.f,
         nvim_next_builtins.t
     }
 })
local next = require("nvim-next").setup()
local next_integrations = require("nvim-next.integrations")
EOF

However when adding the line before EOF

vim.keymap.set("n", "f", next.make_repeatable_pair(functions.F, functions.f))

it throws:

E5108: Error executing lua [string ":lua"]:13: attempt to index global 'functions' (a nil value)                                                                                                                                                                                                                         
stack traceback:                                                                                                                                                                                                                                                                                                         
        [string ":lua"]:13: in main chunk 

However it seems those lines are working

local nqf = next_integrations.quickfix()
vim.keymap.set("n", "[d", nqf.cprevious, { desc = "previous quickfix list item" })
vim.keymap.set("n", "]d", nqf.cnext, { desc = "next quickfix list item" })

None of the mapping (; or ,) do the desired though (i.e. repeating), probably because of this issue.

ghostbuster91 commented 10 months ago

The following line

vim.keymap.set("n", "f", next.make_repeatable_pair(functions.F, functions.f))

doesn't work because there is no functions variable. (my bad, I will correct the readme) Having said that, this line is redundant (again, I should make it more clear in the readme) provided that you have:

    items = {
         nvim_next_builtins.f,
         nvim_next_builtins.t
     }

which does exactly that during the setup.

The offensive line is only needed if someone would like to setup mapping on their own (e.g. to something else than f/t).

ghostbuster91 commented 10 months ago

I created #18 to address this issue, let me know if it clarifies enough.

seb-mueller commented 10 months ago

Thanks for the clarification and provided code. I suppose I'll just remove the lines in questions, however for the sake of testing, I've tried you suggested, but get a new error:

E5108: Error executing lua vim/keymap.lua:0: opts: expected table, got function                                                                                                                                                                                                       
stack traceback:                                                                                                                                                                                                                                                                      
        [C]: in function 'error'                                                                                                                                                                                                                                                      
        vim/shared.lua: in function 'validate'                                                                                                                                                                                                                                        
        vim/keymap.lua: in function 'set'                                                                                                                                                                                                                                             
        [string ":lua"]:17: in main chunk

Again, the same line is the culprit. This is my vim entry:

lua << EOF
local nvim_next_builtins = require("nvim-next.builtins")
require("nvim-next").setup({
   default_mappings = {
       repeat_style = "original",
   },
   items = {
     nvim_next_builtins.f,
     nvim_next_builtins.t
   }
})
local next_integrations = require("nvim-next.integrations")
local nqf = next_integrations.quickfix()
local next = require("nvim-next").setup()
vim.keymap.set("n", "[d", nqf.cprevious, { desc = "previous quickfix list item" })
vim.keymap.set("n", "]d", nqf.cnext, { desc = "next quickfix list item" })
local functions = require("nvim-next.builtins.functions")
vim.keymap.set("n", "f", next.make_repeatable_pair(functions.F, functions.f))
EOF
ghostbuster91 commented 10 months ago

sorry I was writing this from the top of my head and didn't have time to test it. I forgot that the next.make_repeatable_pair function returns pair of functions (prev and next). I updated the readme accordingly.

Thanks for catching that mistake :+1: