vis

a vi-like editor based on Plan 9's structural regular expressions

git clone https://9o.is/git/vis.git

commit f46b67c227063d6eef2f5fe01c77c7e2cdecd329
parent 6a98d533cb6df172d8719d25022e02cf0eae4d73
Author: Marc André Tanner <mat@brain-dump.org>
Date:   Wed, 14 Dec 2016 14:23:13 +0100

lua: allow per file type :commands being executed

Diffstat:
Mlua/plugins/filetype.lua | 14+++++++++++---
1 file changed, 11 insertions(+), 3 deletions(-)

diff --git 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