aboutsummaryrefslogtreecommitdiffstats
path: root/vis-autocmd.lua
diff options
context:
space:
mode:
Diffstat (limited to 'vis-autocmd.lua')
-rw-r--r--vis-autocmd.lua38
1 files changed, 38 insertions, 0 deletions
diff --git a/vis-autocmd.lua b/vis-autocmd.lua
new file mode 100644
index 0000000..8b60501
--- /dev/null
+++ b/vis-autocmd.lua
@@ -0,0 +1,38 @@
+-- vis-autocmd
+-- (https://github.com/jocap/vis-autocmd)
+
+-- This plugin provides a declarative interface for setting vis
+-- options depending on filetype.
+--
+-- It expects a global variable called `settings` to be defined:
+--
+-- settings = {
+-- markdown = {"expandtab on", "tabwidth 4"}
+-- }
+--
+-- In this variable, filetypes are mapped to sets of settings that are
+-- to be executed when a window containing the specified filetype is
+-- opened.
+--
+-- If you want to do more than setting simple options, you can specify a function instead:
+--
+-- settings = {
+-- bash = function(win)
+-- -- do things for shell scripts
+-- end
+-- }
+--
+-- Be sure not to run commands that open another window with the same
+-- filetype, leading to an infinite loop.
+
+vis.events.subscribe(vis.events.WIN_OPEN, function(win)
+ local window_settings = settings[win.syntax]
+
+ if type(window_settings) == 'table' then
+ for _, setting in pairs(window_settings) do
+ vis:command(setting)
+ end
+ elseif type(window_settings) == 'function' then
+ window_settings(win)
+ end
+end)