aboutsummaryrefslogtreecommitdiffstats
path: root/init.lua
diff options
context:
space:
mode:
authorMatěj Cepl <mcepl@cepl.eu>2021-01-16 14:17:16 +0100
committerMatěj Cepl <mcepl@cepl.eu>2023-03-15 14:21:20 +0100
commit4cb2a07856318340405acec7ab2cd52d112f73b9 (patch)
tree1b59ff01e6514f60d11dc5f8d7d188f8338fbc9d /init.lua
parent9fcb1a7057f2e62117b8aa0e45e3a648834da7bc (diff)
downloadvis-filetype-settings-4cb2a07856318340405acec7ab2cd52d112f73b9.tar.gz
Make settings accessible from ~/.config/vis/visrc.lua.
Diffstat (limited to 'init.lua')
-rw-r--r--init.lua23
1 files changed, 15 insertions, 8 deletions
diff --git a/init.lua b/init.lua
index 9f2665a..0c74216 100644
--- a/init.lua
+++ b/init.lua
@@ -25,6 +25,10 @@
-- Be sure not to run commands that open another window with the same
-- filetype, leading to an infinite loop.
+local M = {}
+
+M.settings = {}
+
function execute(s, arg, arg2)
if type(s) == "table" then
for key, setting in pairs(s) do
@@ -44,8 +48,8 @@ end
-- Register events
vis.events.subscribe(vis.events.INPUT, function()
- if settings[vis.win.syntax] and settings[vis.win.syntax].INPUT then
- execute(settings[vis.win.syntax].INPUT, nil)
+ if M.settings[vis.win.syntax] and M.settings[vis.win.syntax].INPUT then
+ execute(M.settings[vis.win.syntax].INPUT, nil)
end
end)
@@ -60,8 +64,8 @@ for _, event in pairs(file_events) do
vis.events.subscribe(vis.events[event], function(file, path)
for win in vis:windows() do
if win.file == file then
- if settings[win.syntax] and settings[win.syntax][event] then
- execute(settings[win.syntax][event], file, path)
+ if M.settings[win.syntax] and M.settings[win.syntax][event] then
+ execute(M.settings[win.syntax][event], file, path)
end
end
end
@@ -85,12 +89,15 @@ local win_events = {
for _, event in pairs(win_events) do
vis.events.subscribe(vis.events[event], function(win)
- if settings[win.syntax] then
- if settings[win.syntax][event] then
- execute(settings[win.syntax][event], win)
+ if M.settings[win.syntax] == nil then return end
+ if M.settings[win.syntax] then
+ if M.settings[win.syntax][event] then
+ execute(M.settings[win.syntax][event], win)
elseif event == "WIN_OPEN" then -- default event
- execute(settings[win.syntax], win)
+ execute(M.settings[win.syntax], win)
end
end
end)
end
+
+return M