nvim-treesitter-textobjects
nvim-treesitter-textobjects copied to clipboard
Allow repeating swap operation
An attempt at #52; allows repeating swap with .
Is this stale?
@clason it does not seem to be possible to set operatorfunc to a Lua function. I would prefer to wait for this feature or a general way to make a Lua function repeatable (without
The best thing that I could get working was (see #343)
local function fn()
if opts.repeatable then
_G._nvim_treesitter_textobject_last_function = function()
require("nvim-treesitter.textobjects." .. submodule)[function_call](query)
end
vim.o.opfunc = "v:lua._nvim_treesitter_textobject_last_function"
vim.api.nvim_feedkeys("g@l", "n", false)
else
require("nvim-treesitter.textobjects." .. submodule)[function_call](query)
end
end
vim.keymap.set(
keymap_modes,
mapping,
fn,
{ buffer = bufnr, silent = true, remap = false, desc = mapping_description }
)
since opfunc seems to insist on a string
it does not seem to be possible to set operatorfunc to a Lua function.
That's right; this is tracked here: https://github.com/neovim/neovim/issues/18132 and here: https://github.com/neovim/neovim/issues/14157
Your workaround seems similar to https://github.com/neovim/neovim/issues/14157#issuecomment-1320787927
Superseded by #343