You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi again! I'm trying to expose the keymaps table to the consumers of my plugin. Here's a simplified example:
localoptions= {
locallibmodal=require('libmodal')
localM= {}
localoptions= {
mode_keymaps= {
n=function() vim.notify('foo') end,
u=vim.cmd.undo, -- THIS DOESN'T CURRENTLY WORK
}
}
vim.keymap.set('n', 'M', function()
require('libmodal').mode.enter('Mode 1', mode_keymaps)
end)
functionM.setup(opts)
options=vim.tbl_deep_extend('force', options, optsor {})
end
The problem is the line u = vim.cmd.undo. Since libmodal passes the current mode as an agrument, that argument gets passed to vim.cmd.undo, causing the following error:
I could solve this by requiring my users to wrap each callback in a function like this:
u=function() vim.cmd.undo() end
But it feels like an ugly solution. I would prefer if I could abstract away libmodal. So I tried creating a function that iterates over all the mappings and wraps them with a function:
This solves the agove problem. However, I also want to use a mapping to switch mode with libmodal.mode.switch. That means that the Mode type argument passed to switches returned function gets lost.
Do you have any suggestions as to how I could solve this? Or is there any way for libmodal to determine whether it should or shouldn't pass an argument to the callback when calling it?
The text was updated successfully, but these errors were encountered:
--- Checks if `fn` is a callback, or a "mode callback" (meaning it uses `self`)--- @paramfnfunction--- @returnbooleanlocalfunctionis_mode_callback(fn)
localinfo=debug.getinfo(fn, 'Su')
returninfo.nparams==1-- takes one parameterandinfo.what=='Lua' -- is a lua functionandnotinfo.source:find'^@vim' -- is not a builtinend
Unfortunately, this kind of thing seems prevalent when it comes to callbacks. For example:
-- Template from `:h nvim_create_autocmd`vim.api.nvim_create_autocmd({"BufEnter", "BufWinEnter"}, {
pattern= {"*.c", "*.h"},
callback=vim.cmd.undo, -- ← this also doesn't work
})
I've merged #36 which adds libmodal.mode.map, a namespace including fn (the utility we discussed) and also switch (the utility implemented previously, just soft-moved to create emphasis that it can only be used as a mapping).
Hi again! I'm trying to expose the keymaps table to the consumers of my plugin. Here's a simplified example:
The problem is the line
u = vim.cmd.undo
. Since libmodal passes the current mode as an agrument, that argument gets passed tovim.cmd.undo
, causing the following error:I could solve this by requiring my users to wrap each callback in a
function
like this:But it feels like an ugly solution. I would prefer if I could abstract away libmodal. So I tried creating a function that iterates over all the mappings and wraps them with a function:
This solves the agove problem. However, I also want to use a mapping to switch mode with
libmodal.mode.switch
. That means that theMode
type argument passed toswitch
es returned function gets lost.Do you have any suggestions as to how I could solve this? Or is there any way for libmodal to determine whether it should or shouldn't pass an argument to the callback when calling it?
The text was updated successfully, but these errors were encountered: