From 7fb525e5c3b29a1c23be6ec5c60a54edf702bfbc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Andr=C3=A9=20Tanner?= Date: Wed, 14 Dec 2016 14:23:13 +0100 Subject: lua: allow per file type :commands being executed --- lua/plugins/filetype.lua | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'lua') diff --git a/lua/plugins/filetype.lua b/lua/plugins/filetype.lua index 46da46c..51f5e1c 100644 --- a/lua/plugins/filetype.lua +++ b/lua/plugins/filetype.lua @@ -378,6 +378,14 @@ vis.ftdetect.filetypes = { } vis.events.subscribe(vis.events.WIN_OPEN, function(win) + + local set_filetype = function(syntax, filetype) + for _, cmd in pairs(filetype.cmd or {}) do + vis:command(cmd) + end + win.syntax = syntax + end + local name = win.file.name -- remove ignored suffixes from filename local sanitizedfn = name @@ -400,7 +408,7 @@ vis.events.subscribe(vis.events.WIN_OPEN, function(win) for lang, ft in pairs(vis.ftdetect.filetypes) do for _, pattern in pairs(ft.ext or {}) do if sanitizedfn:match(pattern) then - win.syntax = lang + set_filetype(lang, ft) return end end @@ -419,7 +427,7 @@ vis.events.subscribe(vis.events.WIN_OPEN, function(win) for lang, ft in pairs(vis.ftdetect.filetypes) do for _, ft_mime in pairs(ft.mime or {}) do if mime == ft_mime then - win.syntax = lang + set_filetype(lang, ft) return end end @@ -434,7 +442,7 @@ vis.events.subscribe(vis.events.WIN_OPEN, function(win) if data and #data > 0 then for lang, ft in pairs(vis.ftdetect.filetypes) do if type(ft.detect) == 'function' and ft.detect(file, data) then - win.syntax = lang + set_filetype(lang, ft) return end end -- cgit v1.2.3