summaryrefslogtreecommitdiff
path: root/.config/vis/visrc.lua
blob: 9641dd6ae01c2c87b033390803af09e742f46683 (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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
require('vis')

require('plugins/vis-backspace')
require('plugins/vis-ctags')
require('plugins/vis-cursors')
require('plugins/vis-editorconfig')
require('plugins/vis-quickfix')

for _, ext in ipairs({ "%.jsx$", "%.ts", "%.tsx$" }) do
	table.insert(vis.ftdetect.filetypes.javascript.ext, ext)
end

vis.ftdetect.filetypes.hare = {
	ext = { "%.ha$" },
}

shebangs = {
	awk = { "awk" },
	bash = { "bash", "sh" },
	execline = { "execlineb" },
	perl = { "perl" },
	python = { "python", "python3" },
}

vis.events.subscribe(vis.events.WIN_OPEN, function(win)
	local shebang = vis.win.file.lines[1]
	local cmd = shebang:match("^#!%g*/([^/%s]+)")
	if cmd == "env" then
		cmd = shebang:match("^#!%g*/env (%g+)")
	end
	for syntax, cmds in pairs(shebangs) do
		for _, c in ipairs(cmds) do
			if c == cmd then
				vis:command("set syntax " .. syntax)
				return
			end
		end
	end
end)

vis.events.subscribe(vis.events.INIT, function()
	vis:command('set escdelay 25')
	vis:command('set autoindent')
	vis:command('set theme flexoki')
end)

vis.events.subscribe(vis.events.WIN_OPEN, function(win)
	vis:command('set relativenumbers')
end)

function automake_handler()
	vis:command('make')
end

vis:option_register('automake', 'bool', function(value, toggle)
	if toggle then
		vis.events.subscribe(vis.events.FILE_SAVE_POST, automake_handler)
	else
		vis.events.unsubscribe(vis.events.FILE_SAVE_POST, automake_handler)
	end
end, 'Run :make automatically after saving')