Compare commits

...

2 commits

Author SHA1 Message Date
Bruno BELANYI e7082b885d home: vim: git: use 'partial'
All checks were successful
ci/woodpecker/push/check Pipeline was successful
2024-07-12 20:38:40 +01:00
Bruno BELANYI 65d036f473 home: vim: lua: utils: add 'partial'
Love me some functional goodness.

This was taken from [1].

[1]: https://reddit.com/r/lua/comments/fh2go5
2024-07-12 20:34:51 +01:00
2 changed files with 29 additions and 12 deletions

View file

@ -48,4 +48,22 @@ M.list_lsp_clients = function(bufnr)
return names
end
--- partially apply a function with given arguments
M.partial = function(f, ...)
local a = { ... }
local a_len = select("#", ...)
return function(...)
local tmp = { ... }
local tmp_len = select("#", ...)
-- Merge arg lists
for i = 1, tmp_len do
a[a_len + i] = tmp[i]
end
return f(unpack(a, 1, a_len + tmp_len))
end
end
return M

View file

@ -1,4 +1,5 @@
local gitsigns = require("gitsigns")
local utils = require("ambroisie.utils")
local wk = require("which-key")
--- Transform `f` into a function which acts on the current visual selection
@ -11,16 +12,14 @@ local function make_visual(f)
end
local function nav_hunk(dir)
return function()
if vim.wo.diff then
local map = {
prev = "[c",
next = "]c",
}
vim.cmd.normal({ map[dir], bang = true })
else
gitsigns.nav_hunk(dir)
end
if vim.wo.diff then
local map = {
prev = "[c",
next = "]c",
}
vim.cmd.normal({ map[dir], bang = true })
else
gitsigns.nav_hunk(dir)
end
end
@ -33,8 +32,8 @@ gitsigns.setup({
local keys = {
-- Navigation
["[c"] = { nav_hunk("prev"), "Previous hunk/diff" },
["]c"] = { nav_hunk("next"), "Next hunk/diff" },
["[c"] = { utils.partial(nav_hunk, "prev"), "Previous hunk/diff" },
["]c"] = { utils.partial(nav_hunk, "next"), "Next hunk/diff" },
-- Commands
["<leader>g"] = {