summaryrefslogtreecommitdiff
path: root/.config/nvim/lua/mango/lib.lua
blob: 5ff57af8f78bfae949ada37cd8401ad1a60ba949 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
local M = {}

function M.set_tab_width(tw, localp)
	local opt = localp and vim.opt_local or vim.opt

	opt.tabstop = tw
	opt.softtabstop = tw
	opt.shiftwidth = tw
end

function M.remap(modes, from, to, opts)
	local ct = {}

	modes:gsub('.', function(c)
		table.insert(ct, c)
	end)

	vim.keymap.set(ct, from, to, opts or {
		noremap = true,
		silent = true,
	})
end

function M.save_regs(regs, callback)
	local rs = {}
	for r in regs:gmatch('.') do
		rs[r] = {
			s = vim.fn.getreg(r),
			t = vim.fn.getregtype(r),
		}
	end

	callback()

	for k, v in pairs(rs) do
		vim.fn.setreg(k, v.s, v.t)
	end
end

return M