Skip to content
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

Dot repeatable #68

Open
tummetott opened this issue Feb 9, 2023 · 5 comments · May be fixed by #69
Open

Dot repeatable #68

tummetott opened this issue Feb 9, 2023 · 5 comments · May be fixed by #69

Comments

@tummetott
Copy link

tummetott commented Feb 9, 2023

It would be nice if commands like :ISwapNodeWithLeft could be made dot repeatable.

@tummetott tummetott changed the title Cursor follows swap + dot repeatable Dot repeatable Feb 9, 2023
@tummetott
Copy link
Author

tummetott commented Feb 9, 2023

I managed to get dot repetition as following:

I created a file called wrapper.lua in my runtimepath

local M = {}

M.swap_left = function()
    require('iswap').iswap_node_with('left')
end

M.swap_right = function()
    require('iswap').iswap_node_with('right')
end

return M

Then i created keymaps in my plugin config:

vim.keymap.set(
    'n',
    '[s',
    function ()
        vim.go.operatorfunc = "v:lua.require'wrapper'.swap_left"
        return 'g@l'
    end,
    { desc = 'Swap with left node', expr = true }
)

vim.keymap.set(
    'n',
    ']s',
    function ()
        vim.go.operatorfunc = "v:lua.require'wrapper'.swap_right"
        return 'g@l'
    end,
    { desc = 'Swap with right node', expr = true }
)

The wrapper functions are needed since operatorfunc takes a function pointer and therefore, no arguments are allowed.

@mizlan maybe you can add the following functions for convenience?

require('iswap').iswap_with_left()
require('iswap').iswap_with_right()
require('iswap').iswap_node_with_left()
require('iswap').iswap_node_with_right()

Then users could define keymaps directly and does not have to define wrapers themself

@qleveque
Copy link

qleveque commented Apr 6, 2024

Thank you for studying this issue @tummetott, I can finally repeat this operation.
Any news on the status of this PR ?

@tummetott
Copy link
Author

Oh I totally forgot about this tbh. I'm quite busy atm but I'll look into this as soon as I have a little more time. Should not be hard to implement

@qleveque
Copy link

qleveque commented Apr 6, 2024

Actually it looks like you already implemented it, thank you for your work
@mizlan It would be really nice to merge this PR, would that be possible?

@tummetott
Copy link
Author

No I didn't. @mizlan expressed his wish to include all the boilerplate code into the plugin. The PR I suggested needs some polishing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants