-
-
Notifications
You must be signed in to change notification settings - Fork 623
draft PR to discuss migration strategies for keymaps / on_attach #1464
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
I went backwards with The real questions:
1 is simpler than I thought
Updating 2 has many possible solutions; one isGenerate Not sure how this would actually be done, as we need to somehow convert a function reference to an API call as a string. Perhaps storing the callback as a string and using something like A more pragmatic solution might be to just denormalise e.g. {
key = "<C-e>",
callbackFn = Api.node.open.replace_tree_buffer,
callbackString = "Api.node.open.replace_tree_buffer",
desc = "edit the file in place, effectively replacing the tree explorer",
}, Needs more thought. |
a simpler on_attach c82d1b0
local function on_attach(bufnr)
local opts = { buffer = bufnr, noremap = true, silent = true, nowait = true, }
vim.keymap.set('n', '<CR>', Api.node.open.edit , opts)
vim.keymap.set('n', 'z', Api.node.open.edit , opts)
vim.keymap.set('n', 'Z', Api.tree.expand_all , opts)
vim.keymap.set('n', 'o', Api.node.open.edit , opts)
vim.keymap.set('n', '<2-LeftMouse>', Api.node.open.edit , opts)
... We can go further... |
on_attach passed mode and opts 92a0ad9 local function on_attach(bufnr, mode, opts)
vim.keymap.set(mode, '<CR>', Api.node.open.edit , opts)
vim.keymap.set(mode, 'o', Api.node.open.edit , opts)
vim.keymap.set(mode, '<2-LeftMouse>', Api.node.open.edit , opts)
vim.keymap.set(mode, '<C-e>', Api.node.open.replace_tree_buffer , opts)
vim.keymap.set(mode, 'z', Api.node.open.edit , opts)
... There is no need for the user to set mode or opts. They can do so if they have some reason to.
|
I would very much like to do this under the hood as much as possible. It wouldn't be hard i believe to convert all the existing mappings table into vim.keymap.set in the attach module. This way we could just migrate all the users config in one go. There is also the help menu that needs refactoring. Because actions are not named anymore, and user mappings will not be registered in our table. |
Also does the jit compiler offers introspection on the lua code ? maybe this could help us generate the code executed in the on_attach call. |
|
That works and would be more consistent. We could put the actions in DEFAULT_KEYMAPS, along with some introspectable string for the callback. |
That will resolve many problems. We could map the Api function back to the table with the description. |
CF #1476 for automatic migration |
i've tried the keymap introspection but i don't think it will work :/ for _, v in pairs(vim.api.nvim_buf_get_keymap(require"nvim-tree.view".get_bufnr(), "")) do
if v.callback then
local info = debug.getinfo(v.callback)
local line, source = info.linedefined, string.sub(info.source, 2)
local file = vim.fn.readfile(source, '', line)
local l = file[line]
print(l)
end
end results in
which are callbacks from |
Of course. It was worth a try... |
See #1579 |
No description provided.