summaryrefslogtreecommitdiff
path: root/lua/conftool.lua
blob: f0b0098a3a4d690ebf0cebdfa8c3eedddf2ddcb4 (plain)
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
41
42
--
-- Configuration tools
--

local conftool = {}

-- a viml-like set function
function conftool.set(...)
	for _,a in ipairs{...} do
		if type(a) == "string" then
			vim.opt[a] = true;
		elseif type(a) == "table" then
			local val = false
			if #a == 2 then val = a[2]
			elseif #a == 1 then val = true end
			vim.opt[ a[1] ] = val
		end
	end
end

function conftool.augroup(name, ...)
	vim.cmd('augroup ' .. name)
	vim.cmd('autocmd!')
	for _, autocmd in ipairs{...} do
		vim.cmd('autocmd ' .. table.concat(autocmd, ' '))
	end
	vim.cmd('augroup END')
end

function conftool.map(mode, keyseq, argcmd, argopts)
	local opts = {noremap = true}
	if argopts then opts = vim.tbl_extend('force', defopts, opts) end
	vim.api.nvim_set_keymap(mode, keyseq, argcmd, opts)
end

function conftool.defcmd(cmd, repl, attr, redef)
	if not redef then redef = '' end
	if not attr then attr = '' end
	vim.cmd('command' .. redef .. ' ' .. cmd  .. ' ' .. attr .. ' ' .. repl)
end

return conftool