diff options
| author | Marc André Tanner <mat@brain-dump.org> | 2016-09-29 19:48:32 +0200 |
|---|---|---|
| committer | Marc André Tanner <mat@brain-dump.org> | 2016-09-29 19:48:32 +0200 |
| commit | 642bd558b10880ad7b2e7429f405eab3c2234def (patch) | |
| tree | 66e4b3952d4e2a09d521bcde037ede792a3eb05d /vis.lua | |
| parent | fc05dec81e70dd9b3d0ed75772455999f35e0d33 (diff) | |
| download | vis-642bd558b10880ad7b2e7429f405eab3c2234def.tar.gz vis-642bd558b10880ad7b2e7429f405eab3c2234def.tar.xz | |
Cosmetic changes to file detection code
Diffstat (limited to 'vis.lua')
| -rw-r--r-- | vis.lua | 12 |
1 files changed, 7 insertions, 5 deletions
@@ -192,8 +192,8 @@ vis.ftdetect.filetypes = { -- array of filetype detecting functions (win, filename, shebang, app) -> string vis.ftdetect.customdetectors = { - function(win) - if win.file:content(0, 5) == '<?xml' then + function(file, data) + if data:sub(1, 5) == '<?xml' then return 'xml' end end, @@ -218,11 +218,13 @@ vis.filetype_detect = function(win) until not changed end + local data = win.file:content(0, 256); + -- find out via shebang which application would run our file local shebang local app - if win.file:content(0, 2) == '#!' then - shebang = win.file:content(0, 256):gsub('^#!%s*', ''):gsub('\n.*$', '') + if data:sub(1, 2) == '#!' then + shebang = data:gsub('^#!%s*', ''):gsub('\n.*$', '') app = shebang:gsub('^/usr/bin/env%s*', ''):gsub('%s.*$', ''):gsub('^.*/', '') if #app == 0 then app = nil @@ -231,7 +233,7 @@ vis.filetype_detect = function(win) -- call custom detectors if any for _, func in pairs(vis.ftdetect.customdetectors) do - local fres = func(win, sanitizedfn, shebang, app) + local fres = func(win.file, data, sanitizedfn, shebang, app) if fres ~= nil then win.syntax = fres return |
