ziontee113 / syntax-tree-surfer

A plugin for Neovim that helps you surf through your document and move elements around using the nvim-treesitter API.
MIT License
472 stars 10 forks source link

fix: avoid global variable use #23

Closed litoj closed 9 months ago

litoj commented 9 months ago

fixes #22

this is an implementation with the least changes required, however, if you don't mind, I personally prefer to make all the original functions accessible directly, like this:

-- Swap in Normal Mode
vim.api.nvim_create_user_command("STSSwapUpNormal", function()
    M.move("n", true)
end, {})
-- Normal Swap Dot Repeat{{{
M.STSSwapUpNormal_Dot = function()
    vim.cmd("STSSwapUpNormal")
end
-- Swap The Master Node relative to the cursor with it's siblings, Dot Repeatable
vim.keymap.set("n", "vU", function()
    vim.opt.opfunc = "v:lua.require'syntax-tree-surfer'.STSSwapUpNormal_Dot"
    return "g@l"
end, { silent = true, expr = true })

↓↓↓

M.mk_repeatable = function(fname)
    return function()
        vim.go.opfunc = "v:lua.require'syntax-tree-surfer'." .. fname
        vim.cmd("normal! g@l")
    end
end

-- Swap in Normal Mode
M.STSSwapUpNormal = function()
    M.move("n", true)
end
vim.api.nvim_create_user_command("STSSwapUpNormal", M.STSSwapUpNormal, {})
-- Swap The Master Node relative to the cursor with it's siblings, Dot Repeatable
vim.keymap.set("n", "vU", require("syntax-tree-surfer").mk_repeatable("STSSwapUpNormal"), { silent = true })

So if you consider this a possibility, I can make those changes too

I simplified the approach taken by gitsigns

ziontee113 commented 9 months ago

Hi @JosefLitos , thank you for offering to help with the plugin.

I've been slacking on maintaining this project for a while. Nowadays I don't even want to write Lua anymore and choose to write Neovim plugins in Python instead :sweat_smile:

This was my first project ever and I didn't have a lot of experience back then, hence the messy spaghetti code.

if you don't mind, I personally prefer to make all the original functions accessible directly

If the end user doesn't have to change their config at all, then please go for it :+1:

Again, thank you for offering to help :heart:

litoj commented 9 months ago

Hi, unfortunately the config change is inevitable either way since the functions for dot repeat were presented in the readme to be copied, not as references to functions already present in the module itself (passable by reference).

ziontee113 commented 9 months ago

Sorry @JosefLitos , due to the changes affect users directly, I don't think I can merge this. This will break existing users config.

litoj commented 9 months ago

I know