diff options
| author | Marc André Tanner <mat@brain-dump.org> | 2016-12-14 14:23:13 +0100 |
|---|---|---|
| committer | Marc André Tanner <mat@brain-dump.org> | 2016-12-14 14:44:49 +0100 |
| commit | 7fb525e5c3b29a1c23be6ec5c60a54edf702bfbc (patch) | |
| tree | 3d328fc3edbaa9f2f6bf91a07e9cd1d6294bcf36 /lua | |
| parent | 51a6a5c4a150715d0062408309f9704a0675190b (diff) | |
| download | vis-7fb525e5c3b29a1c23be6ec5c60a54edf702bfbc.tar.gz vis-7fb525e5c3b29a1c23be6ec5c60a54edf702bfbc.tar.xz | |
lua: allow per file type :commands being executed
Diffstat (limited to 'lua')
| -rw-r--r-- | lua/plugins/filetype.lua | 14 |
1 files changed, 11 insertions, 3 deletions
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 |
