refactor(runtime): convert the remaining dist#ft functions to lua (#18623)

This commit is contained in:
Jonas Strittmatter 2022-05-22 20:16:04 +02:00 committed by GitHub
parent 8c2fd65bb1
commit 52623ce935
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 494 additions and 379 deletions

View File

@ -786,8 +786,8 @@ local extension = {
zut = 'zimbutempl', zut = 'zimbutempl',
zsh = 'zsh', zsh = 'zsh',
vala = 'vala', vala = 'vala',
E = function() E = function(path, bufnr)
vim.fn['dist#ft#FTe']() return require('vim.filetype.detect').e(bufnr)
end, end,
EU = function(path, bufnr) EU = function(path, bufnr)
return require('vim.filetype.detect').euphoria(bufnr) return require('vim.filetype.detect').euphoria(bufnr)
@ -804,26 +804,26 @@ local extension = {
EXW = function(path, bufnr) EXW = function(path, bufnr)
return require('vim.filetype.detect').euphoria(bufnr) return require('vim.filetype.detect').euphoria(bufnr)
end, end,
PL = function() PL = function(path, bufnr)
vim.fn['dist#ft#FTpl']() return require('vim.filetype.detect').pl(bufnr)
end, end,
R = function(path, bufnr) R = function(path, bufnr)
require('vim.filetype.detect').r(bufnr) return require('vim.filetype.detect').r(bufnr)
end, end,
asm = function(path, bufnr) asm = function(path, bufnr)
require('vim.filetype.detect').asm(bufnr) return require('vim.filetype.detect').asm(bufnr)
end, end,
bas = function(path, bufnr) bas = function(path, bufnr)
require('vim.filetype.detect').bas(bufnr) return require('vim.filetype.detect').bas(bufnr)
end, end,
bi = function() bi = function(path, bufnr)
vim.fn['dist#ft#FTbas']() return require('vim.filetype.detect').bas(bufnr)
end, end,
bm = function() bm = function(path, bufnr)
vim.fn['dist#ft#FTbas']() return require('vim.filetype.detect').bas(bufnr)
end, end,
bash = function() bash = function(path, bufnr)
vim.fn['dist#ft#SetFileTypeSH']('bash') return require('vim.filetype.detect').sh(path, bufnr, 'bash')
end, end,
btm = function(path, bufnr) btm = function(path, bufnr)
return require('vim.filetype.detect').btm(bufnr) return require('vim.filetype.detect').btm(bufnr)
@ -834,104 +834,104 @@ local extension = {
ch = function(path, bufnr) ch = function(path, bufnr)
return require('vim.filetype.detect').change(bufnr) return require('vim.filetype.detect').change(bufnr)
end, end,
com = function() com = function(path, bufnr)
vim.fn['dist#ft#BindzoneCheck']('dcl') return require('vim.filetype.detect').bindzone(bufnr, 'dcl')
end, end,
cpt = function() cpt = function(path, bufnr)
vim.fn['dist#ft#FThtml']() return require('vim.filetype.detect').html(bufnr)
end, end,
csh = function() csh = function(path, bufnr)
vim.fn['dist#ft#CSH']() return require('vim.filetype.detect').csh(path, bufnr)
end, end,
d = function(path, bufnr) d = function(path, bufnr)
return require('vim.filetype.detect').dtrace(bufnr) return require('vim.filetype.detect').dtrace(bufnr)
end, end,
db = function() db = function(path, bufnr)
vim.fn['dist#ft#BindzoneCheck']('') return require('vim.filetype.detect').bindzone(bufnr, '')
end, end,
dtml = function() dtml = function(path, bufnr)
vim.fn['dist#ft#FThtml']() return require('vim.filetype.detect').html(bufnr)
end, end,
e = function() e = function(path, bufnr)
vim.fn['dist#ft#FTe']() return require('vim.filetype.detect').e(bufnr)
end, end,
ebuild = function() ebuild = function(path, bufnr)
vim.fn['dist#ft#SetFileTypeSH']('bash') return require('vim.filetype.detect').sh(path, bufnr, 'bash')
end, end,
eclass = function() eclass = function(path, bufnr)
vim.fn['dist#ft#SetFileTypeSH']('bash') return require('vim.filetype.detect').sh(path, bufnr, 'bash')
end, end,
ent = function(path, bufnr) ent = function(path, bufnr)
require('vim.filetype.detect').ent(bufnr) return require('vim.filetype.detect').ent(bufnr)
end, end,
env = function() env = function(path, bufnr)
vim.fn['dist#ft#SetFileTypeSH'](vim.fn.getline(1)) return require('vim.filetype.detect').sh(path, bufnr, getline(bufnr, 1))
end, end,
eu = function(path, bufnr) eu = function(path, bufnr)
require('vim.filetype.detect').euphoria(bufnr) return require('vim.filetype.detect').euphoria(bufnr)
end, end,
ew = function(path, bufnr) ew = function(path, bufnr)
require('vim.filetype.detect').euphoria(bufnr) return require('vim.filetype.detect').euphoria(bufnr)
end, end,
ex = function(path, bufnr) ex = function(path, bufnr)
require('vim.filetype.detect').ex(bufnr) return require('vim.filetype.detect').ex(bufnr)
end, end,
exu = function(path, bufnr) exu = function(path, bufnr)
require('vim.filetype.detect').euphoria(bufnr) return require('vim.filetype.detect').euphoria(bufnr)
end, end,
exw = function(path, bufnr) exw = function(path, bufnr)
require('vim.filetype.detect').euphoria(bufnr) return require('vim.filetype.detect').euphoria(bufnr)
end, end,
frm = function(path, bufnr) frm = function(path, bufnr)
require('vim.filetype.detect').frm(bufnr) return require('vim.filetype.detect').frm(bufnr)
end, end,
fs = function(path, bufnr) fs = function(path, bufnr)
vim.fn['dist#ft#FTfs']() return require('vim.filetype.detect').fs(bufnr)
end, end,
h = function(path, bufnr) h = function(path, bufnr)
require('vim.filetype.detect').header(bufnr) return require('vim.filetype.detect').header(bufnr)
end, end,
htm = function() htm = function(path, bufnr)
vim.fn['dist#ft#FThtml']() return require('vim.filetype.detect').html(bufnr)
end, end,
html = function() html = function(path, bufnr)
vim.fn['dist#ft#FThtml']() return require('vim.filetype.detect').html(bufnr)
end, end,
i = function(path, bufnr) i = function(path, bufnr)
require('vim.filetype.detect').progress_asm(bufnr) return require('vim.filetype.detect').progress_asm(bufnr)
end, end,
idl = function(path, bufnr) idl = function(path, bufnr)
require('vim.filetype.detect').idl(bufnr) return require('vim.filetype.detect').idl(bufnr)
end, end,
inc = function() inc = function(path, bufnr)
vim.fn['dist#ft#FTinc']() return require('vim.filetype.detect').inc(bufnr)
end, end,
inp = function(path, bufnr) inp = function(path, bufnr)
require('vim.filetype.detect').inp(bufnr) return require('vim.filetype.detect').inp(bufnr)
end, end,
ksh = function() ksh = function(path, bufnr)
vim.fn['dist#ft#SetFileTypeSH']('ksh') return require('vim.filetype.detect').sh(path, bufnr, 'ksh')
end, end,
lst = function(path, bufnr) lst = function(path, bufnr)
require('vim.filetype.detect').asm(bufnr) return require('vim.filetype.detect').asm(bufnr)
end, end,
m = function(path, bufnr) m = function(path, bufnr)
require('vim.filetype.detect').m(bufnr) return require('vim.filetype.detect').m(bufnr)
end, end,
mac = function(path, bufnr) mac = function(path, bufnr)
require('vim.filetype.detect').asm(bufnr) return require('vim.filetype.detect').asm(bufnr)
end, end,
mc = function(path, bufnr) mc = function(path, bufnr)
require('vim.filetype.detect').mc(bufnr) return require('vim.filetype.detect').mc(bufnr)
end, end,
mm = function(path, bufnr) mm = function(path, bufnr)
require('vim.filetype.detect').mm(bufnr) return require('vim.filetype.detect').mm(bufnr)
end, end,
mms = function(path, bufnr) mms = function(path, bufnr)
require('vim.filetype.detect').mms(bufnr) return require('vim.filetype.detect').mms(bufnr)
end, end,
p = function(path, bufnr) p = function(path, bufnr)
require('vim.filetype.detect').progress_pascal(bufnr) return require('vim.filetype.detect').progress_pascal(bufnr)
end, end,
patch = function(path, bufnr) patch = function(path, bufnr)
local firstline = getline(bufnr, 1) local firstline = getline(bufnr, 1)
@ -941,65 +941,65 @@ local extension = {
return 'diff' return 'diff'
end end
end, end,
pl = function() pl = function(path, bufnr)
vim.fn['dist#ft#FTpl']() return require('vim.filetype.detect').pl(bufnr)
end, end,
pp = function() pp = function(path, bufnr)
vim.fn['dist#ft#FTpp']() return require('vim.filetype.detect').pp(bufnr)
end, end,
pro = function() pro = function(path, bufnr)
vim.fn['dist#ft#ProtoCheck']('idlang') return require('vim.filetype.detect').proto(bufnr, 'idlang')
end, end,
pt = function() pt = function(path, bufnr)
vim.fn['dist#ft#FThtml']() return require('vim.filetype.detect').html('idlang')
end, end,
r = function(path, bufnr) r = function(path, bufnr)
require('vim.filetype.detect').r(bufnr) return require('vim.filetype.detect').r(bufnr)
end, end,
rdf = function(path, bufnr) rdf = function(path, bufnr)
require('vim.filetype.detect').redif(bufnr) return require('vim.filetype.detect').redif(bufnr)
end, end,
rules = function(path, bufnr) rules = function(path, bufnr)
require('vim.filetype.detect').rules(path, bufnr) return require('vim.filetype.detect').rules(path, bufnr)
end, end,
sc = function(path, bufnr) sc = function(path, bufnr)
require('vim.filetype.detect').sc(bufnr) return require('vim.filetype.detect').sc(bufnr)
end, end,
scd = function(path, bufnr) scd = function(path, bufnr)
require('vim.filetype.detect').scd(bufnr) return require('vim.filetype.detect').scd(bufnr)
end, end,
sh = function() sh = function(path, bufnr)
vim.fn['dist#ft#SetFileTypeSH'](vim.fn.getline(1)) return require('vim.filetype.detect').sh(path, bufnr, getline(bufnr, 1))
end, end,
shtml = function() shtml = function(path, bufnr)
vim.fn['dist#ft#FThtml']() return require('vim.filetype.detect').html(bufnr)
end, end,
sql = function(path, bufnr) sql = function(path, bufnr)
require('vim.filetype.detect').sql(bufnr) return require('vim.filetype.detect').sql(bufnr)
end, end,
stm = function() stm = function(path, bufnr)
vim.fn['dist#ft#FThtml']() return require('vim.filetype.detect').html(bufnr)
end, end,
tcsh = function() tcsh = function(path, bufnr)
vim.fn['dist#ft#SetFileTypeShell']('tcsh') return require('vim.filetype.detect').shell(path, bufnr, 'tcsh')
end, end,
tex = function() tex = function(path, bufnr)
vim.fn['dist#ft#FTtex']() return require('vim.filetype.detect').tex(path, bufnr)
end, end,
tf = function(path, bufnr) tf = function(path, bufnr)
require('vim.filetype.detect').tf(bufnr) return require('vim.filetype.detect').tf(bufnr)
end, end,
w = function(path, bufnr) w = function(path, bufnr)
require('vim.filetype.detect').progress_cweb(bufnr) return require('vim.filetype.detect').progress_cweb(bufnr)
end, end,
xml = function(path, bufnr) xml = function(path, bufnr)
require('vim.filetype.detect').xml(bufnr) return require('vim.filetype.detect').xml(bufnr)
end, end,
y = function(path, bufnr) y = function(path, bufnr)
require('vim.filetype.detect').y(bufnr) return require('vim.filetype.detect').y(bufnr)
end, end,
zsql = function(path, bufnr) zsql = function(path, bufnr)
require('vim.filetype.detect').sql(bufnr) return require('vim.filetype.detect').sql(bufnr)
end, end,
txt = function(path, bufnr) txt = function(path, bufnr)
--helpfiles match *.txt, but should have a modeline as last line --helpfiles match *.txt, but should have a modeline as last line
@ -1075,16 +1075,16 @@ local filename = {
exports = 'exports', exports = 'exports',
['.fetchmailrc'] = 'fetchmail', ['.fetchmailrc'] = 'fetchmail',
fvSchemes = function(path, bufnr) fvSchemes = function(path, bufnr)
require('vim.filetype.detect').foam(bufnr) return require('vim.filetype.detect').foam(bufnr)
end, end,
fvSolution = function(path, bufnr) fvSolution = function(path, bufnr)
require('vim.filetype.detect').foam(bufnr) return require('vim.filetype.detect').foam(bufnr)
end, end,
fvConstraints = function(path, bufnr) fvConstraints = function(path, bufnr)
require('vim.filetype.detect').foam(bufnr) return require('vim.filetype.detect').foam(bufnr)
end, end,
fvModels = function(path, bufnr) fvModels = function(path, bufnr)
require('vim.filetype.detect').foam(bufnr) return require('vim.filetype.detect').foam(bufnr)
end, end,
fstab = 'fstab', fstab = 'fstab',
mtab = 'fstab', mtab = 'fstab',
@ -1300,63 +1300,63 @@ local filename = {
['.zcompdump'] = 'zsh', ['.zcompdump'] = 'zsh',
['.zshenv'] = 'zsh', ['.zshenv'] = 'zsh',
['.zfbfmarks'] = 'zsh', ['.zfbfmarks'] = 'zsh',
['.alias'] = function() ['.alias'] = function(path, bufnr)
vim.fn['dist#ft#CSH']() return require('vim.filetype.detect').csh(path, bufnr)
end, end,
['.bashrc'] = function() ['.bashrc'] = function(path, bufnr)
vim.fn['dist#ft#SetFileTypeSH']('bash') return require('vim.filetype.detect').sh(path, bufnr, 'bash')
end, end,
['.cshrc'] = function() ['.cshrc'] = function(path, bufnr)
vim.fn['dist#ft#CSH']() return require('vim.filetype.detect').csh(path, bufnr)
end, end,
['.env'] = function() ['.env'] = function(path, bufnr)
vim.fn['dist#ft#SetFileTypeSH'](vim.fn.getline(1)) return require('vim.filetype.detect').sh(path, bufnr, getline(bufnr, 1))
end, end,
['.kshrc'] = function() ['.kshrc'] = function(path, bufnr)
vim.fn['dist#ft#SetFileTypeSH']('ksh') return require('vim.filetype.detect').sh(path, bufnr, 'ksh')
end, end,
['.login'] = function() ['.login'] = function(path, bufnr)
vim.fn['dist#ft#CSH']() return require('vim.filetype.detect').csh(path, bufnr)
end, end,
['.profile'] = function() ['.profile'] = function(path, bufnr)
vim.fn['dist#ft#SetFileTypeSH'](vim.fn.getline(1)) return require('vim.filetype.detect').sh(path, bufnr, getline(bufnr, 1))
end, end,
['.tcshrc'] = function() ['.tcshrc'] = function(path, bufnr)
vim.fn['dist#ft#SetFileTypeShell']('tcsh') return require('vim.filetype.detect').shell(path, bufnr, 'tcsh')
end, end,
['/etc/profile'] = function() ['/etc/profile'] = function(path, bufnr)
vim.fn['dist#ft#SetFileTypeSH'](vim.fn.getline(1)) return require('vim.filetype.detect').sh(path, bufnr, getline(bufnr, 1))
end, end,
APKBUILD = function() APKBUILD = function(path, bufnr)
vim.fn['dist#ft#SetFileTypeSH']('bash') return require('vim.filetype.detect').sh(path, bufnr, 'bash')
end, end,
PKGBUILD = function() PKGBUILD = function(path, bufnr)
vim.fn['dist#ft#SetFileTypeSH']('bash') return require('vim.filetype.detect').sh(path, bufnr, 'bash')
end, end,
['bash.bashrc'] = function() ['bash.bashrc'] = function(path, bufnr)
vim.fn['dist#ft#SetFileTypeSH']('bash') return require('vim.filetype.detect').sh(path, bufnr, 'bash')
end, end,
bashrc = function() bashrc = function(path, bufnr)
vim.fn['dist#ft#SetFileTypeSH']('bash') return require('vim.filetype.detect').sh(path, bufnr, 'bash')
end, end,
crontab = starsetf('crontab'), crontab = starsetf('crontab'),
['csh.cshrc'] = function() ['csh.cshrc'] = function(path, bufnr)
vim.fn['dist#ft#CSH']() return require('vim.filetype.detect').csh(path, bufnr)
end, end,
['csh.login'] = function() ['csh.login'] = function(path, bufnr)
vim.fn['dist#ft#CSH']() return require('vim.filetype.detect').csh(path, bufnr)
end, end,
['csh.logout'] = function() ['csh.logout'] = function(path, bufnr)
vim.fn['dist#ft#CSH']() return require('vim.filetype.detect').csh(path, bufnr)
end, end,
['indent.pro'] = function() ['indent.pro'] = function(path, bufnr)
vim.fn['dist#ft#ProtoCheck']('indent') return require('vim.filetype.detect').proto(bufnr, 'indent')
end, end,
['tcsh.login'] = function() ['tcsh.login'] = function(path, bufnr)
vim.fn['dist#ft#SetFileTypeShell']('tcsh') return require('vim.filetype.detect').shell(path, bufnr, 'tcsh')
end, end,
['tcsh.tcshrc'] = function() ['tcsh.tcshrc'] = function(path, bufnr)
vim.fn['dist#ft#SetFileTypeShell']('tcsh') return require('vim.filetype.detect').shell(path, bufnr, 'tcsh')
end, end,
-- END FILENAME -- END FILENAME
} }
@ -1528,44 +1528,44 @@ local pattern = {
['.*/etc/xdg/menus/.*%.menu'] = 'xml', ['.*/etc/xdg/menus/.*%.menu'] = 'xml',
['.*Xmodmap'] = 'xmodmap', ['.*Xmodmap'] = 'xmodmap',
['.*/etc/zprofile'] = 'zsh', ['.*/etc/zprofile'] = 'zsh',
['%.bash[_-]aliases'] = function() ['%.bash[_-]aliases'] = function(path, bufnr)
vim.fn['dist#ft#SetFileTypeSH']('bash') return require('vim.filetype.detect').sh(path, bufnr, 'bash')
end, end,
['%.bash[_-]logout'] = function() ['%.bash[_-]logout'] = function(path, bufnr)
vim.fn['dist#ft#SetFileTypeSH']('bash') return require('vim.filetype.detect').sh(path, bufnr, 'bash')
end, end,
['%.bash[_-]profile'] = function() ['%.bash[_-]profile'] = function(path, bufnr)
vim.fn['dist#ft#SetFileTypeSH']('bash') return require('vim.filetype.detect').sh(path, bufnr, 'bash')
end, end,
['%.cshrc.*'] = function() ['%.cshrc.*'] = function(path, bufnr)
vim.fn['dist#ft#CSH']() return require('vim.filetype.detect').csh(path, bufnr)
end, end,
['%.gtkrc.*'] = starsetf('gtkrc'), ['%.gtkrc.*'] = starsetf('gtkrc'),
['%.kshrc.*'] = function() ['%.kshrc.*'] = function(path, bufnr)
vim.fn['dist#ft#SetFileTypeSH']('ksh') return require('vim.filetype.detect').sh(path, bufnr, 'ksh')
end, end,
['%.login.*'] = function() ['%.login.*'] = function(path, bufnr)
vim.fn['dist#ft#CSH']() return require('vim.filetype.detect').csh(path, bufnr)
end, end,
['%.neomuttrc.*'] = starsetf('neomuttrc'), ['%.neomuttrc.*'] = starsetf('neomuttrc'),
['%.profile.*'] = function() ['%.profile.*'] = function(path, bufnr)
vim.fn['dist#ft#SetFileTypeSH'](vim.fn.getline(1)) return require('vim.filetype.detect').sh(path, bufnr, getline(bufnr, 1))
end, end,
['%.reminders.*'] = starsetf('remind'), ['%.reminders.*'] = starsetf('remind'),
['%.tcshrc.*'] = function() ['%.tcshrc.*'] = function(path, bufnr)
vim.fn['dist#ft#SetFileTypeShell']('tcsh') return require('vim.filetype.detect').shell(path, bufnr, 'tcsh')
end, end,
['%.zcompdump.*'] = starsetf('zsh'), ['%.zcompdump.*'] = starsetf('zsh'),
['%.zlog.*'] = starsetf('zsh'), ['%.zlog.*'] = starsetf('zsh'),
['%.zsh.*'] = starsetf('zsh'), ['%.zsh.*'] = starsetf('zsh'),
['.*%.[1-9]'] = function(path, bufnr) ['.*%.[1-9]'] = function(path, bufnr)
require('vim.filetype.detect').nroff(bufnr) return require('vim.filetype.detect').nroff(bufnr)
end, end,
['.*%.[aA]'] = function(path, bufnr) ['.*%.[aA]'] = function(path, bufnr)
require('vim.filetype.detect').asm(bufnr) return require('vim.filetype.detect').asm(bufnr)
end, end,
['.*%.[sS]'] = function(path, bufnr) ['.*%.[sS]'] = function(path, bufnr)
require('vim.filetype.detect').asm(bufnr) return require('vim.filetype.detect').asm(bufnr)
end, end,
['.*%.properties_.._.._.*'] = starsetf('jproperties'), ['.*%.properties_.._.._.*'] = starsetf('jproperties'),
['.*%.vhdl_[0-9].*'] = starsetf('vhdl'), ['.*%.vhdl_[0-9].*'] = starsetf('vhdl'),
@ -1576,7 +1576,7 @@ local pattern = {
['.*/app%-defaults/.*'] = starsetf('xdefaults'), ['.*/app%-defaults/.*'] = starsetf('xdefaults'),
['.*/bind/db%..*'] = starsetf('bindzone'), ['.*/bind/db%..*'] = starsetf('bindzone'),
['.*/debian/patches/.*'] = function(path, bufnr) ['.*/debian/patches/.*'] = function(path, bufnr)
require('vim.filetype.detect').dep3patch(path, bufnr) return require('vim.filetype.detect').dep3patch(path, bufnr)
end, end,
['.*/etc/Muttrc%.d/.*'] = starsetf('muttrc'), ['.*/etc/Muttrc%.d/.*'] = starsetf('muttrc'),
['.*/etc/apache2/.*%.conf.*'] = starsetf('apache'), ['.*/etc/apache2/.*%.conf.*'] = starsetf('apache'),
@ -1592,8 +1592,8 @@ local pattern = {
['.*/etc/logcheck/.*%.d.*/.*'] = starsetf('logcheck'), ['.*/etc/logcheck/.*%.d.*/.*'] = starsetf('logcheck'),
['.*/etc/modprobe%..*'] = starsetf('modconf'), ['.*/etc/modprobe%..*'] = starsetf('modconf'),
['.*/etc/pam%.d/.*'] = starsetf('pamconf'), ['.*/etc/pam%.d/.*'] = starsetf('pamconf'),
['.*/etc/profile'] = function() ['.*/etc/profile'] = function(path, bufnr)
vim.fn['dist#ft#SetFileTypeSH'](vim.fn.getline(1)) return require('vim.filetype.detect').sh(path, bufnr, getline(bufnr, 1))
end, end,
['.*/etc/proftpd/.*%.conf.*'] = starsetf('apachestyle'), ['.*/etc/proftpd/.*%.conf.*'] = starsetf('apachestyle'),
['.*/etc/proftpd/conf%..*/.*'] = starsetf('apachestyle'), ['.*/etc/proftpd/conf%..*/.*'] = starsetf('apachestyle'),
@ -1621,8 +1621,8 @@ local pattern = {
['access%.conf.*'] = starsetf('apache'), ['access%.conf.*'] = starsetf('apache'),
['apache%.conf.*'] = starsetf('apache'), ['apache%.conf.*'] = starsetf('apache'),
['apache2%.conf.*'] = starsetf('apache'), ['apache2%.conf.*'] = starsetf('apache'),
['bash%-fc[-%.]'] = function() ['bash%-fc[-%.]'] = function(path, bufnr)
vim.fn['dist#ft#SetFileTypeSH']('bash') return require('vim.filetype.detect').sh(path, bufnr, 'bash')
end, end,
['cabal%.project%..*'] = starsetf('cabalproject'), ['cabal%.project%..*'] = starsetf('cabalproject'),
['crontab%..*'] = starsetf('crontab'), ['crontab%..*'] = starsetf('crontab'),
@ -1650,28 +1650,28 @@ local pattern = {
['neomutt' .. string.rep('[%w_-]', 6)] = 'mail', ['neomutt' .. string.rep('[%w_-]', 6)] = 'mail',
['/tmp/SLRN[0-9A-Z.]+'] = 'mail', ['/tmp/SLRN[0-9A-Z.]+'] = 'mail',
['[a-zA-Z0-9].*Dict'] = function(path, bufnr) ['[a-zA-Z0-9].*Dict'] = function(path, bufnr)
require('vim.filetype.detect').foam(bufnr) return require('vim.filetype.detect').foam(bufnr)
end, end,
['[a-zA-Z0-9].*Dict%..*'] = function(path, bufnr) ['[a-zA-Z0-9].*Dict%..*'] = function(path, bufnr)
require('vim.filetype.detect').foam(bufnr) return require('vim.filetype.detect').foam(bufnr)
end, end,
['[a-zA-Z].*Properties'] = function(path, bufnr) ['[a-zA-Z].*Properties'] = function(path, bufnr)
require('vim.filetype.detect').foam(bufnr) return require('vim.filetype.detect').foam(bufnr)
end, end,
['[a-zA-Z].*Properties%..*'] = function(path, bufnr) ['[a-zA-Z].*Properties%..*'] = function(path, bufnr)
require('vim.filetype.detect').foam(bufnr) return require('vim.filetype.detect').foam(bufnr)
end, end,
['.*Transport%..*'] = function(path, bufnr) ['.*Transport%..*'] = function(path, bufnr)
require('vim.filetype.detect').foam(bufnr) return require('vim.filetype.detect').foam(bufnr)
end, end,
['.*/constant/g'] = function(path, bufnr) ['.*/constant/g'] = function(path, bufnr)
require('vim.filetype.detect').foam(bufnr) return require('vim.filetype.detect').foam(bufnr)
end, end,
['.*/0/.*'] = function(path, bufnr) ['.*/0/.*'] = function(path, bufnr)
require('vim.filetype.detect').foam(bufnr) return require('vim.filetype.detect').foam(bufnr)
end, end,
['.*/0%.orig/.*'] = function(path, bufnr) ['.*/0%.orig/.*'] = function(path, bufnr)
require('vim.filetype.detect').foam(bufnr) return require('vim.filetype.detect').foam(bufnr)
end, end,
['.*/etc/sensors%.d/[^.].*'] = starsetf('sensors'), ['.*/etc/sensors%.d/[^.].*'] = starsetf('sensors'),
['.*%.git/.*'] = function(path, bufnr) ['.*%.git/.*'] = function(path, bufnr)
@ -1680,24 +1680,29 @@ local pattern = {
return 'git' return 'git'
end end
end, end,
['.*%.[Cc][Ff][Gg]'] = function(path, bufnr) ['.*%.[Cc][Ff][Gg]'] = {
require('vim.filetype.detect').cfg(bufnr) function(path, bufnr)
end, return require('vim.filetype.detect').cfg(bufnr)
end,
-- Decrease the priority to avoid conflicts with more specific patterns
-- such as '.*/etc/a2ps/.*%.cfg', '.*enlightenment/.*%.cfg', etc.
{ priority = -1 },
},
['.*%.[Dd][Aa][Tt]'] = function(path, bufnr) ['.*%.[Dd][Aa][Tt]'] = function(path, bufnr)
require('vim.filetype.detect').dat(bufnr) return require('vim.filetype.detect').dat(bufnr)
end, end,
['.*%.[Mm][Oo][Dd]'] = function(path, bufnr) ['.*%.[Mm][Oo][Dd]'] = function(path, bufnr)
require('vim.filetype.detect').mod(path, bufnr) return require('vim.filetype.detect').mod(path, bufnr)
end, end,
['.*%.[Ss][Rr][Cc]'] = function(path, bufnr) ['.*%.[Ss][Rr][Cc]'] = function(path, bufnr)
require('vim.filetype.detect').src(bufnr) return require('vim.filetype.detect').src(bufnr)
end, end,
['.*%.[Ss][Uu][Bb]'] = 'krl', ['.*%.[Ss][Uu][Bb]'] = 'krl',
['.*%.[Pp][Rr][Gg]'] = function(path, bufnr) ['.*%.[Pp][Rr][Gg]'] = function(path, bufnr)
require('vim.filetype.detect').prg(bufnr) return require('vim.filetype.detect').prg(bufnr)
end, end,
['.*%.[Ss][Yy][Ss]'] = function(path, bufnr) ['.*%.[Ss][Yy][Ss]'] = function(path, bufnr)
require('vim.filetype.detect').sys(bufnr) return require('vim.filetype.detect').sys(bufnr)
end, end,
-- Neovim only -- Neovim only
['.*/queries/.*%.scm'] = 'query', -- tree-sitter queries ['.*/queries/.*%.scm'] = 'query', -- tree-sitter queries

View File

@ -27,6 +27,9 @@ end
---@private ---@private
local function findany(s, patterns) local function findany(s, patterns)
if s == nil then
return false
end
for _, v in ipairs(patterns) do for _, v in ipairs(patterns) do
if s:find(v) then if s:find(v) then
return true return true
@ -82,7 +85,7 @@ function M.asm(bufnr)
vim.b[bufnr].asmsyntax = 'asm' vim.b[bufnr].asmsyntax = 'asm'
end end
end end
vim.bo[bufnr].filetype = vim.fn.fnameescape(vim.b[bufnr].asmsyntax) return vim.fn.fnameescape(vim.b[bufnr].asmsyntax)
end end
-- Checks the first 5 lines for a asmsyntax=foo override. -- Checks the first 5 lines for a asmsyntax=foo override.
@ -102,8 +105,7 @@ local visual_basic_content = { 'vb_name', 'begin vb%.form', 'begin vb%.mdiform',
-- See frm() for Visual Basic form file detection -- See frm() for Visual Basic form file detection
function M.bas(bufnr) function M.bas(bufnr)
if vim.g.filetype_bas then if vim.g.filetype_bas then
vim.bo[bufnr].filetype = vim.g.filetype_bas return vim.g.filetype_bas
return
end end
-- Most frequent FreeBASIC-specific keywords in distro files -- Most frequent FreeBASIC-specific keywords in distro files
@ -118,26 +120,30 @@ function M.bas(bufnr)
for _, line in ipairs(getlines(bufnr, 1, 100)) do for _, line in ipairs(getlines(bufnr, 1, 100)) do
if line:find(fb_comment) or matchregex(line, fb_preproc) or matchregex(line, fb_keywords) then if line:find(fb_comment) or matchregex(line, fb_preproc) or matchregex(line, fb_keywords) then
vim.bo[bufnr].filetype = 'freebasic' return 'freebasic'
return
elseif matchregex(line, qb64_preproc) then elseif matchregex(line, qb64_preproc) then
vim.bo[bufnr].filetype = 'qb64' return 'qb64'
return
elseif findany(line:lower(), visual_basic_content) then elseif findany(line:lower(), visual_basic_content) then
vim.bo[bufnr].filetype = 'vb' return 'vb'
return
end end
end end
vim.bo[bufnr].filetype = 'basic' return 'basic'
end end
function M.bindzone(bufnr, default_ft) end function M.bindzone(bufnr, default)
local lines = table.concat(getlines(bufnr, 1, 4))
if findany(lines, { '^; <<>> DiG [0-9%.]+.* <<>>', '%$ORIGIN', '%$TTL', 'IN%s+SOA' }) then
return 'bindzone'
else
return default
end
end
function M.btm(bufnr) function M.btm(bufnr)
if vim.g.dosbatch_syntax_for_btm and vim.g.dosbatch_syntax_for_btm ~= 0 then if vim.g.dosbatch_syntax_for_btm and vim.g.dosbatch_syntax_for_btm ~= 0 then
vim.bo[bufnr].filetype = 'dosbatch' return 'dosbatch'
else else
vim.bo[bufnr].filetype = 'btm' return 'btm'
end end
end end
@ -157,11 +163,11 @@ end
function M.cfg(bufnr) function M.cfg(bufnr)
if vim.g.filetype_cfg then if vim.g.filetype_cfg then
vim.bo[bufnr].filetype = vim.g.filetype_cfg return vim.g.filetype_cfg
elseif is_rapid(bufnr, 'cfg') then elseif is_rapid(bufnr, 'cfg') then
vim.bo[bufnr].filetype = 'rapid' return 'rapid'
else else
vim.bo[bufnr].filetype = 'cfg' return 'cfg'
end end
end end
@ -173,38 +179,44 @@ end
function M.change(bufnr) function M.change(bufnr)
local first_line = getlines(bufnr, 1) local first_line = getlines(bufnr, 1)
if findany(first_line, { '^#', '^!' }) then if findany(first_line, { '^#', '^!' }) then
vim.bo[bufnr].filetype = 'ch' return 'ch'
return
end end
for _, line in ipairs(getlines(bufnr, 1, 10)) do for _, line in ipairs(getlines(bufnr, 1, 10)) do
if line:find('^@') then if line:find('^@') then
vim.bo[bufnr].filetype = 'change' return 'change'
return
end end
if line:find('MODULE') then if line:find('MODULE') then
vim.bo[bufnr].filetype = 'chill' return 'chill'
return
elseif findany(line:lower(), { 'main%s*%(', '#%s*include', '//' }) then elseif findany(line:lower(), { 'main%s*%(', '#%s*include', '//' }) then
vim.bo[bufnr].filetype = 'ch' return 'ch'
return
end end
end end
vim.bo[bufnr].filetype = 'chill' return 'chill'
end end
function M.csh(path, bufnr) end function M.csh(path, bufnr)
if vim.fn.did_filetype() then
-- Filetype was already detected
return
end
if vim.g.filetype_csh then
return M.shell(path, bufnr, vim.g.filetype_csh)
elseif string.find(vim.o.shell, 'tcsh') then
return M.shell(path, bufnr, 'tcsh')
else
return M.shell(path, bufnr, 'csh')
end
end
-- Determine if a *.dat file is Kuka Robot Language -- Determine if a *.dat file is Kuka Robot Language
-- TODO: this one fails for some reason, so I omitted it. #18219 should be merged first.
function M.dat(bufnr) function M.dat(bufnr)
-- if vim.g.filetype_dat then if vim.g.filetype_dat then
-- vim.bo[bufnr].filetype = vim.g.filetype_dat return vim.g.filetype_dat
-- return end
-- end local line = nextnonblank(bufnr, 1)
-- local line = nextnonblank(bufnr, 1):lower() if matchregex(line, [[\c\v^\s*%(\&\w+|defdat>)]]) then
-- if findany(line, { "^%s*&%w+", "^%s*defdat" }) then return 'krl'
-- vim.bo[bufnr].filetype = "krl" end
-- end
end end
-- This function is called for all files under */debian/patches/*, make sure not -- This function is called for all files under */debian/patches/*, make sure not
@ -231,8 +243,7 @@ function M.dep3patch(path, bufnr)
'^Applied%-Upstream:', '^Applied%-Upstream:',
}) })
then then
vim.bo[bufnr].filetype = 'dep3patch' return 'dep3patch'
return
elseif line:find('^%-%-%-') then elseif line:find('^%-%-%-') then
-- End of headers found. stop processing -- End of headers found. stop processing
return return
@ -249,25 +260,24 @@ function M.dtrace(bufnr)
for _, line in ipairs(getlines(bufnr, 1, 100)) do for _, line in ipairs(getlines(bufnr, 1, 100)) do
if matchregex(line, [[\c^module\>\|^import\>]]) then if matchregex(line, [[\c^module\>\|^import\>]]) then
-- D files often start with a module and/or import statement. -- D files often start with a module and/or import statement.
vim.bo[bufnr].filetype = 'd' return 'd'
return
elseif findany(line, { '^#!%S+dtrace', '#pragma%s+D%s+option', ':%S-:%S-:' }) then elseif findany(line, { '^#!%S+dtrace', '#pragma%s+D%s+option', ':%S-:%S-:' }) then
vim.bo[bufnr].filetype = 'dtrace' return 'dtrace'
return
end end
end end
vim.bo[bufnr].filetype = 'd' return 'd'
end end
function M.e(path, bufnr) function M.e(bufnr)
if vim.g.filetype_euphoria then if vim.g.filetype_euphoria then
vim.bo[bufnr].filetype = vim.g.filetype_euphoria return vim.g.filetype_euphoria
return
end end
-- TODO: WIP for _, line in ipairs(getlines(bufnr, 1, 100)) do
-- for _, line in ipairs(getlines(bufnr, 1, 100)) do if findany(line, { "^%s*<'%s*$", "^%s*'>%s*$" }) then
-- if line:find("^$") return 'specman'
-- end end
end
return 'eiffel'
end end
-- This function checks for valid cl syntax in the first five lines. -- This function checks for valid cl syntax in the first five lines.
@ -276,36 +286,34 @@ end
function M.ent(bufnr) function M.ent(bufnr)
for _, line in ipairs(getlines(bufnr, 1, 5)) do for _, line in ipairs(getlines(bufnr, 1, 5)) do
if line:find('^%s*[#{]') then if line:find('^%s*[#{]') then
vim.bo[bufnr].filetype = 'cl' return 'cl'
return
elseif not line:find('^%s*$') then elseif not line:find('^%s*$') then
-- Not a blank line, not a comment, and not a block start, -- Not a blank line, not a comment, and not a block start,
-- so doesn't look like valid cl code. -- so doesn't look like valid cl code.
break break
end end
end end
vim.bo[bufnr].filetype = 'dtd' return 'dtd'
end end
function M.euphoria(bufnr) function M.euphoria(bufnr)
if vim.g.filetype_euphoria then if vim.g.filetype_euphoria then
vim.bo[bufnr].filetype = vim.g.filetype_euphoria return vim.g.filetype_euphoria
else else
vim.bo[bufnr].filetype = 'euphoria3' return 'euphoria3'
end end
end end
function M.ex(bufnr) function M.ex(bufnr)
if vim.g.filetype_euphoria then if vim.g.filetype_euphoria then
vim.bo[bufnr].filetype = vim.g.filetype_euphoria return vim.g.filetype_euphoria
else else
for _, line in ipairs(getlines(bufnr, 1, 100)) do for _, line in ipairs(getlines(bufnr, 1, 100)) do
if matchregex(line, [[\c^--\|^ifdef\>\|^include\>]]) then if matchregex(line, [[\c^--\|^ifdef\>\|^include\>]]) then
vim.bo[bufnr].filetype = 'euphoria3' return 'euphoria3'
return
end end
end end
vim.bo[bufnr].filetype = 'elixir' return 'elixir'
end end
end end
@ -318,93 +326,110 @@ function M.foam(bufnr)
if line:find('^FoamFile') then if line:find('^FoamFile') then
foam_file = true foam_file = true
elseif foam_file and line:find('^%s*object') then elseif foam_file and line:find('^%s*object') then
vim.bo[bufnr].filetype = 'foam' return 'foam'
return
end end
end end
end end
function M.frm(bufnr) function M.frm(bufnr)
if vim.g.filetype_frm then if vim.g.filetype_frm then
vim.bo[bufnr].filetype = vim.g.filetype_frm return vim.g.filetype_frm
return
end end
local lines = table.concat(getlines(bufnr, 1, 5)):lower() local lines = table.concat(getlines(bufnr, 1, 5)):lower()
if findany(lines, visual_basic_content) then if findany(lines, visual_basic_content) then
vim.bo[bufnr].filetype = 'vb' return 'vb'
else else
vim.bo[bufnr].filetype = 'form' return 'form'
end end
end end
-- Distinguish between Forth and F#. -- Distinguish between Forth and F#.
function M.fs(bufnr) function M.fs(bufnr)
-- TODO: WIP if vim.g.filetype_fs then
-- if vim.g.filetype_fs then return vim.g.filetype_fs
-- vim.bo[bufnr].filetype = vim.g.filetype_fs end
-- return local line = nextnonblank(bufnr, 1)
-- end if findany(line, { '^%s*%.?%( ', '^%s*\\G? ', '^\\$', '^%s*: %S' }) then
-- local line = nextnonblank(bufnr, 1) return 'forth'
-- if findany(line, { '^%s*.?%( ', '^%s*\\G? ', '^\\$', '^%s*: %S' }) then else
-- vim.bo[bufnr].filetype = 'forth' return 'fsharp'
-- else end
-- vim.bo[bufnr].filetype = 'fsharp'
-- end
end end
function M.header(bufnr) function M.header(bufnr)
for _, line in ipairs(getlines(bufnr, 1, 200)) do for _, line in ipairs(getlines(bufnr, 1, 200)) do
if findany(line:lower(), { '^@interface', '^@end', '^@class' }) then if findany(line:lower(), { '^@interface', '^@end', '^@class' }) then
if vim.g.c_syntax_for_h then if vim.g.c_syntax_for_h then
vim.bo[bufnr].filetype = 'objc' return 'objc'
else else
vim.bo[bufnr].filetype = 'objcpp' return 'objcpp'
end end
return
end end
end end
if vim.g.c_syntax_for_h then if vim.g.c_syntax_for_h then
vim.bo[bufnr].filetype = 'c' return 'c'
elseif vim.g.ch_syntax_for_h then elseif vim.g.ch_syntax_for_h then
vim.bo[bufnr].filetype = 'ch' return 'ch'
else else
vim.bo[bufnr].filetype = 'cpp' return 'cpp'
end end
end end
function M.html(bufnr) function M.html(bufnr)
for _, line in ipairs(getlines(bufnr, 1, 10)) do for _, line in ipairs(getlines(bufnr, 1, 10)) do
if matchregex(line, [[\<DTD\s\+XHTML\s]]) then if matchregex(line, [[\<DTD\s\+XHTML\s]]) then
vim.bo[bufnr].filetype = 'xhtml' return 'xhtml'
return
elseif matchregex(line, [[\c{%\s*\(extends\|block\|load\)\>\|{#\s\+]]) then elseif matchregex(line, [[\c{%\s*\(extends\|block\|load\)\>\|{#\s\+]]) then
vim.bo[bufnr].filetype = 'htmldjango' return 'htmldjango'
return
end end
end end
vim.bo[bufnr].filetype = 'html' return 'html'
end end
function M.idl(bufnr) function M.idl(bufnr)
for _, line in ipairs(getlines(bufnr, 1, 50)) do for _, line in ipairs(getlines(bufnr, 1, 50)) do
if findany(line:lower(), { '^%s*import%s+"unknwn"%.idl', '^%s*import%s+"objidl"%.idl' }) then if findany(line:lower(), { '^%s*import%s+"unknwn"%.idl', '^%s*import%s+"objidl"%.idl' }) then
vim.bo[bufnr].filetype = 'msidl' return 'msidl'
return
end end
end end
vim.bo[bufnr].filetype = 'idl' return 'idl'
end end
function M.inc(path, bufnr) end local pascal_comments = { '^%s*{', '^%s*%(%*', '^%s*//' }
local pascal_keywords = [[\c^\s*\%(program\|unit\|library\|uses\|begin\|procedure\|function\|const\|type\|var\)\>]]
function M.inc(bufnr)
if vim.g.filetype_inc then
return vim.g.filetype_inc
end
local lines = table.concat(getlines(bufnr, 1, 3))
if lines:lower():find('perlscript') then
return 'aspperl'
elseif lines:find('<%%') then
return 'aspvbs'
elseif lines:find('<%?') then
return 'php'
-- Pascal supports // comments but they're vary rarely used for file
-- headers so assume POV-Ray
elseif findany(lines, { '^%s{', '^%s%(%*' }) or matchregex(lines, pascal_keywords) then
return 'pascal'
else
M.asm_syntax(bufnr)
if vim.b[bufnr].asm_syntax then
return vim.fn.fnameescape(vim.b[bufnr].asm_syntax)
else
return 'pov'
end
end
end
function M.inp(bufnr) function M.inp(bufnr)
if getlines(bufnr, 1):find('^%*') then if getlines(bufnr, 1):find('^%*') then
vim.bo[bufnr].filetype = 'abaqus' return 'abaqus'
else else
for _, line in ipairs(getlines(bufnr, 1, 500)) do for _, line in ipairs(getlines(bufnr, 1, 500)) do
if line:lower():find('^header surface data') then if line:lower():find('^header surface data') then
vim.bo[bufnr].filetype = 'trasys' return 'trasys'
return
end end
end end
end end
@ -426,18 +451,16 @@ function M.lpc(bufnr)
'^mixed', '^mixed',
}) })
then then
vim.bo[bufnr].filetype = 'lpc' return 'lpc'
return
end end
end end
end end
vim.bo[bufnr].filetype = 'c' return 'c'
end end
function M.m(bufnr) function M.m(bufnr)
if vim.g.filetype_m then if vim.g.filetype_m then
vim.bo[bufnr].filetype = vim.g.filetype_m return vim.g.filetype_m
return
end end
-- Excluding end(for|function|if|switch|while) common to Murphi -- Excluding end(for|function|if|switch|while) common to Murphi
@ -455,25 +478,20 @@ function M.m(bufnr)
saw_comment = true saw_comment = true
end end
if line:find('^%s*//') or matchregex(line, [[\c^\s*@import\>]]) or matchregex(line, objc_preprocessor) then if line:find('^%s*//') or matchregex(line, [[\c^\s*@import\>]]) or matchregex(line, objc_preprocessor) then
vim.bo[bufnr].filetype = 'objc' return 'objc'
return
end end
if if
findany(line, { '^%s*#', '^%s*%%!' }) findany(line, { '^%s*#', '^%s*%%!' })
or matchregex(line, [[\c^\s*unwind_protect\>]]) or matchregex(line, [[\c^\s*unwind_protect\>]])
or matchregex(line, [[\c\%(^\|;\)\s*]] .. octave_block_terminators) or matchregex(line, [[\c\%(^\|;\)\s*]] .. octave_block_terminators)
then then
vim.bo[bufnr].filetype = 'octave' return 'octave'
return
elseif line:find('^%s*%%') then elseif line:find('^%s*%%') then
vim.bo[bufnr].filetype = 'matlab' return 'matlab'
return
elseif line:find('^%s*%(%*') then elseif line:find('^%s*%(%*') then
vim.bo[bufnr].filetype = 'mma' return 'mma'
return
elseif matchregex(line, [[\c^\s*\(\(type\|var\)\>\|--\)]]) then elseif matchregex(line, [[\c^\s*\(\(type\|var\)\>\|--\)]]) then
vim.bo[bufnr].filetype = 'murphi' return 'murphi'
return
end end
end end
@ -481,10 +499,10 @@ function M.m(bufnr)
-- We didn't see anything definitive, but this looks like either Objective C -- We didn't see anything definitive, but this looks like either Objective C
-- or Murphi based on the comment leader. Assume the former as it is more -- or Murphi based on the comment leader. Assume the former as it is more
-- common. -- common.
vim.bo[bufnr].filetype = 'objc' return 'objc'
else else
-- Default is Matlab -- Default is Matlab
vim.bo[bufnr].filetype = 'matlab' return 'matlab'
end end
end end
@ -494,38 +512,33 @@ function M.mc(bufnr)
for _, line in ipairs(getlines(bufnr, 1, 20)) do for _, line in ipairs(getlines(bufnr, 1, 20)) do
if findany(line:lower(), { '^%s*#', '^%s*dnl' }) then if findany(line:lower(), { '^%s*#', '^%s*dnl' }) then
-- Sendmail .mc file -- Sendmail .mc file
vim.bo[bufnr].filetype = 'm4' return 'm4'
return
elseif line:find('^%s*;') then elseif line:find('^%s*;') then
vim.bo[bufnr].filetype = 'msmessages' return 'msmessages'
return
end end
end end
-- Default: Sendmail .mc file -- Default: Sendmail .mc file
vim.bo[bufnr].filetype = 'm4' return 'm4'
end end
function M.mm(bufnr) function M.mm(bufnr)
for _, line in ipairs(getlines(bufnr, 1, 20)) do for _, line in ipairs(getlines(bufnr, 1, 20)) do
if matchregex(line, [[\c^\s*\(#\s*\(include\|import\)\>\|@import\>\|/\*\)]]) then if matchregex(line, [[\c^\s*\(#\s*\(include\|import\)\>\|@import\>\|/\*\)]]) then
vim.bo[bufnr].filetype = 'objcpp' return 'objcpp'
return
end end
end end
vim.bo[bufnr].filetype = 'nroff' return 'nroff'
end end
function M.mms(bufnr) function M.mms(bufnr)
for _, line in ipairs(getlines(bufnr, 1, 20)) do for _, line in ipairs(getlines(bufnr, 1, 20)) do
if findany(line, { '^%s*%%', '^%s*//', '^%*' }) then if findany(line, { '^%s*%%', '^%s*//', '^%*' }) then
vim.bo[bufnr].filetype = 'mmix' return 'mmix'
return
elseif line:find('^%s*#') then elseif line:find('^%s*#') then
vim.bo[bufnr].filetype = 'make' return 'make'
return
end end
end end
vim.bo[bufnr].filetype = 'mmix' return 'mmix'
end end
-- Returns true if file content looks like LambdaProlog -- Returns true if file content looks like LambdaProlog
@ -544,18 +557,18 @@ end
-- Determine if *.mod is ABB RAPID, LambdaProlog, Modula-2, Modsim III or go.mod -- Determine if *.mod is ABB RAPID, LambdaProlog, Modula-2, Modsim III or go.mod
function M.mod(path, bufnr) function M.mod(path, bufnr)
if vim.g.filetype_mod then if vim.g.filetype_mod then
vim.bo[bufnr].filetype = vim.g.filetype_mod return vim.g.filetype_mod
elseif is_lprolog(bufnr) then elseif is_lprolog(bufnr) then
vim.bo[bufnr].filetype = 'lprolog' return 'lprolog'
elseif matchregex(nextnonblank(bufnr, 1), [[\%(\<MODULE\s\+\w\+\s*;\|^\s*(\*\)]]) then elseif matchregex(nextnonblank(bufnr, 1), [[\%(\<MODULE\s\+\w\+\s*;\|^\s*(\*\)]]) then
vim.bo[bufnr].filetype = 'modula2' return 'modula2'
elseif is_rapid(bufnr) then elseif is_rapid(bufnr) then
vim.bo[bufnr].filetype = 'rapid' return 'rapid'
elseif matchregex(path, [[\c\<go\.mod$]]) then elseif matchregex(path, [[\c\<go\.mod$]]) then
vim.bo[bufnr].filetype = 'gomod' return 'gomod'
else else
-- Nothing recognized, assume modsim3 -- Nothing recognized, assume modsim3
vim.bo[bufnr].filetype = 'modsim3' return 'modsim3'
end end
end end
@ -564,7 +577,6 @@ end
function M.nroff(bufnr) function M.nroff(bufnr)
for _, line in ipairs(getlines(bufnr, 1, 5)) do for _, line in ipairs(getlines(bufnr, 1, 5)) do
if line:find('^%.') then if line:find('^%.') then
vim.bo[bufnr].filetype = 'nroff'
return true return true
end end
end end
@ -578,51 +590,58 @@ end
function M.perl(path, bufnr) function M.perl(path, bufnr)
local dirname = vim.fn.expand(path, '%:p:h:t') local dirname = vim.fn.expand(path, '%:p:h:t')
if vim.fn.expand(dirname, '%:e') == 't' and (dirname == 't' or dirname == 'xt') then if vim.fn.expand(dirname, '%:e') == 't' and (dirname == 't' or dirname == 'xt') then
vim.bo[bufnr].filetype = 'perl'
return true return true
end end
local first_line = getlines(bufnr, 1) local first_line = getlines(bufnr, 1)
if first_line:find('^#') and first_line:lower():find('perl') then if first_line:find('^#') and first_line:lower():find('perl') then
vim.bo[bufnr].filetype = 'perl'
return true return true
end end
for _, line in ipairs(getlines(bufnr, 1, 30)) do for _, line in ipairs(getlines(bufnr, 1, 30)) do
if matchregex(line, [[\c^use\s\s*\k]]) then if matchregex(line, [[\c^use\s\s*\k]]) then
vim.bo[bufnr].filetype = 'perl'
return true return true
end end
end end
return false return false
end end
function M.pl(path, bufnr) end function M.pl(bufnr)
if vim.g.filetype_pl then
local pascal_comments = { '^%s*{', '^%s*%(*', '^%s*//' } return vim.g.filetype_pl
local pascal_keywords = [[\c^\s*\%(program\|unit\|library\|uses\|begin\|procedure\|function\|const\|type\|var\)\>]] end
-- Recognize Prolog by specific text in the first non-empty line;
-- require a blank after the '%' because Perl uses "%list" and "%translate"
local line = nextnonblank(bufnr, 1)
if
line and line:find(':%-')
or matchregex(line, [[\c\<prolog\>]])
or findany(line, { '^%s*%%+%s', '^%s*%%+$', '^%s*/%*' })
then
return 'prolog'
else
return 'perl'
end
end
function M.pp(bufnr) function M.pp(bufnr)
-- TODO: WIP if vim.g.filetype_pp then
return vim.g.filetype_pp
-- if vim.g.filetype_pp then end
-- vim.bo[bufnr].filetype = vim.g.filetype_pp local line = nextnonblank(bufnr, 1)
-- return if findany(line, pascal_comments) or matchregex(line, pascal_keywords) then
-- end return 'pascal'
-- local first_line = nextnonblank(bufnr, 1):lower() else
-- if findany(first_line, { pascal_comments, pascal_keywords }) then return 'puppet'
-- vim.bo[bufnr].filetype = "pascal" end
-- else
-- vim.bo[bufnr].filetype = "puppet"
-- end
end end
function M.prg(bufnr) function M.prg(bufnr)
if vim.g.filetype_prg then if vim.g.filetype_prg then
vim.bo[bufnr].filetype = vim.g.filetype_prg return vim.g.filetype_prg
elseif is_rapid(bufnr) then elseif is_rapid(bufnr) then
vim.bo[bufnr].filetype = 'rapid' return 'rapid'
else else
-- Nothing recognized, assume Clipper -- Nothing recognized, assume Clipper
vim.bo[bufnr].filetype = 'clipper' return 'clipper'
end end
end end
@ -630,8 +649,7 @@ end
-- If not found, assume Progress. -- If not found, assume Progress.
function M.progress_asm(bufnr) function M.progress_asm(bufnr)
if vim.g.filetype_i then if vim.g.filetype_i then
vim.bo[bufnr].filetype = vim.g.filetype_i return vim.g.filetype_i
return
end end
for _, line in ipairs(getlines(bufnr, 1, 10)) do for _, line in ipairs(getlines(bufnr, 1, 10)) do
@ -643,17 +661,17 @@ function M.progress_asm(bufnr)
break break
end end
end end
vim.bo[bufnr].filetype = 'progress' return 'progress'
end end
function M.progress_cweb(bufnr) function M.progress_cweb(bufnr)
if vim.g.filetype_w then if vim.g.filetype_w then
vim.bo[bufnr].filetype = vim.g.filetype_w return vim.g.filetype_w
else else
if getlines(bufnr, 1):lower():find('^&analyze') or getlines(bufnr, 3):lower():find('^&global%-define') then if getlines(bufnr, 1):lower():find('^&analyze') or getlines(bufnr, 3):lower():find('^&global%-define') then
vim.bo[bufnr].filetype = 'progress' return 'progress'
else else
vim.bo[bufnr].filetype = 'cweb' return 'cweb'
end end
end end
end end
@ -663,58 +681,65 @@ end
-- If not found, assume Progress. -- If not found, assume Progress.
function M.progress_pascal(bufnr) function M.progress_pascal(bufnr)
if vim.g.filetype_p then if vim.g.filetype_p then
vim.bo[bufnr].filetype = vim.g.filetype_p return vim.g.filetype_p
return
end end
for _, line in ipairs(getlines(bufnr, 1, 10)) do for _, line in ipairs(getlines(bufnr, 1, 10)) do
if findany(line, pascal_comments) or matchregex(line, pascal_keywords) then if findany(line, pascal_comments) or matchregex(line, pascal_keywords) then
vim.bo[bufnr].filetype = 'pascal' return 'pascal'
return
elseif not line:find('^%s*$') or line:find('^/%*') then elseif not line:find('^%s*$') or line:find('^/%*') then
-- Not an empty line: Doesn't look like valid Pascal code. -- Not an empty line: Doesn't look like valid Pascal code.
-- Or it looks like a Progress /* comment -- Or it looks like a Progress /* comment
break break
end end
end end
vim.bo[bufnr].filetype = 'progress' return 'progress'
end end
function M.proto(path, bufnr) end -- Distinguish between "default" and Cproto prototype file.
function M.proto(bufnr, default)
-- Cproto files have a comment in the first line and a function prototype in
-- the second line, it always ends in ";". Indent files may also have
-- comments, thus we can't match comments to see the difference.
-- IDL files can have a single ';' in the second line, require at least one
-- character before the ';'.
if getlines(bufnr, 2):find('.;$') then
return 'cpp'
else
return default
end
end
function M.r(bufnr) function M.r(bufnr)
local lines = getlines(bufnr, 1, 50) local lines = getlines(bufnr, 1, 50)
-- Rebol is easy to recognize, check for that first -- Rebol is easy to recognize, check for that first
if matchregex(table.concat(lines), [[\c\<rebol\>]]) then if matchregex(table.concat(lines), [[\c\<rebol\>]]) then
vim.bo[bufnr].filetype = 'rebol' return 'rebol'
return
end end
for _, line in ipairs(lines) do for _, line in ipairs(lines) do
-- R has # comments -- R has # comments
if line:find('^%s*#') then if line:find('^%s*#') then
vim.bo[bufnr].filetype = 'r' return 'r'
return
end end
-- Rexx has /* comments */ -- Rexx has /* comments */
if line:find('^%s*/%*') then if line:find('^%s*/%*') then
vim.bo[bufnr].filetype = 'rexx' return 'rexx'
return
end end
end end
-- Nothing recognized, use user default or assume R -- Nothing recognized, use user default or assume R
if vim.g.filetype_r then if vim.g.filetype_r then
vim.bo[bufnr].filetype = vim.g.filetype_r return vim.g.filetype_r
else else
-- Rexx used to be the default, but R appears to be much more popular. -- Rexx used to be the default, but R appears to be much more popular.
vim.bo[bufnr].filetype = 'r' return 'r'
end end
end end
function M.redif(bufnr) function M.redif(bufnr)
for _, line in ipairs(getlines(bufnr, 1, 5)) do for _, line in ipairs(getlines(bufnr, 1, 5)) do
if line:lower():find('^template%-type:') then if line:lower():find('^template%-type:') then
vim.bo[bufnr].filetype = 'redif' return 'redif'
end end
end end
end end
@ -732,28 +757,26 @@ function M.rules(path, bufnr)
'/lib/udev/rules%.d/.*%.rules$', '/lib/udev/rules%.d/.*%.rules$',
}) })
then then
vim.bo[bufnr].filetype = 'udevrules' return 'udevrules'
elseif path:find('^/etc/ufw/') then elseif path:find('^/etc/ufw/') then
-- Better than hog -- Better than hog
vim.bo[bufnr].filetype = 'conf' return 'conf'
elseif findany(path, { '^/etc/polkit%-1/rules%.d', '/usr/share/polkit%-1/rules%.d' }) then elseif findany(path, { '^/etc/polkit%-1/rules%.d', '/usr/share/polkit%-1/rules%.d' }) then
vim.bo[bufnr].filetype = 'javascript' return 'javascript'
else else
local ok, config_lines = pcall(vim.fn.readfile, '/etc/udev/udev.conf') local ok, config_lines = pcall(vim.fn.readfile, '/etc/udev/udev.conf')
if not ok then if not ok then
vim.bo[bufnr].filetype = 'hog' return 'hog'
return
end end
local dir = vim.fn.expand(path, ':h') local dir = vim.fn.expand(path, ':h')
for _, line in ipairs(config_lines) do for _, line in ipairs(config_lines) do
local match = line:match(udev_rules_pattern) local match = line:match(udev_rules_pattern)
local udev_rules = line:gsub(udev_rules_pattern, match, 1) local udev_rules = line:gsub(udev_rules_pattern, match, 1)
if dir == udev_rules then if dir == udev_rules then
vim.bo[bufnr].filetype = 'udevrules' return 'udevrules'
return
end end
end end
vim.bo[bufnr].filetype = 'hog' return 'hog'
end end
end end
@ -767,11 +790,10 @@ function M.sc(bufnr)
{ '[A-Za-z0-9]*%s:%s[A-Za-z0-9]', 'var%s<', 'classvar%s<', '%^this.*', '|%w*|', '%+%s%w*%s{', '%*ar%s' } { '[A-Za-z0-9]*%s:%s[A-Za-z0-9]', 'var%s<', 'classvar%s<', '%^this.*', '|%w*|', '%+%s%w*%s{', '%*ar%s' }
) )
then then
vim.bo[bufnr].filetype = 'supercollider' return 'supercollider'
return
end end
end end
vim.bo[bufnr].filetype = 'scala' return 'scala'
end end
-- This function checks the first line of file extension "scd" to resolve -- This function checks the first line of file extension "scd" to resolve
@ -781,47 +803,140 @@ function M.scd(bufnr)
local opt = [[%s+"[^"]*"]] local opt = [[%s+"[^"]*"]]
local line = getlines(bufnr, 1) local line = getlines(bufnr, 1)
if findany(line, { first .. '$', first .. opt .. '$', first .. opt .. opt .. '$' }) then if findany(line, { first .. '$', first .. opt .. '$', first .. opt .. opt .. '$' }) then
vim.bo[bufnr].filetype = 'scdoc' return 'scdoc'
else else
vim.bo[bufnr].filetype = 'supercollider' return 'supercollider'
end end
end end
function M.sh(path, bufnr) end -- Also called from filetype.lua
function M.sh(path, bufnr, name)
if vim.fn.did_filetype() or path:find(vim.g.ft_ignore_pat) then
-- Filetype was already detected or detection should be skipped
return
end
function M.shell(path, bufnr) end if matchregex(name, [[\<csh\>]]) then
-- Some .sh scripts contain #!/bin/csh.
return M.shell(path, bufnr, 'csh')
-- Some .sh scripts contain #!/bin/tcsh.
elseif matchregex(name, [[\<tcsh\>]]) then
return M.shell(path, bufnr, 'tcsh')
-- Some .sh scripts contain #!/bin/zsh.
elseif matchregex(name, [[\<zsh\>]]) then
return M.shell(path, bufnr, 'zsh')
elseif matchregex(name, [[\<ksh\>]]) then
vim.b[bufnr].is_kornshell = 1
vim.b[bufnr].is_bash = nil
vim.b[bufnr].is_sh = nil
elseif vim.g.bash_is_sh or matchregex(name, [[\<bash\>]]) or matchregex(name, [[\<bash2\>]]) then
vim.b[bufnr].is_bash = 1
vim.b[bufnr].is_kornshell = nil
vim.b[bufnr].is_sh = nil
elseif matchregex(name, [[\<sh\>]]) then
vim.b[bufnr].is_sh = 1
vim.b[bufnr].is_kornshell = nil
vim.b[bufnr].is_bash = nil
end
return M.shell(path, bufnr, 'sh')
end
-- For shell-like file types, check for an "exec" command hidden in a comment, as used for Tcl.
-- Also called from scripts.vim, thus can't be local to this script. [TODO]
function M.shell(path, bufnr, name)
if vim.fn.did_filetype() or matchregex(path, vim.g.ft_ignore_pat) then
-- Filetype was already detected or detection should be skipped
return
end
local prev_line = ''
for _, line in ipairs(getlines(bufnr, 2, -1)) do
line = line:lower()
if line:find('%s*exec%s') and not prev_line:find('^%s*#.*\\$') then
-- Found an "exec" line after a comment with continuation
local n = line:gsub('%s*exec%s+([^ ]*/)?', '', 1)
if matchregex(n, [[\c\<tclsh\|\<wish]]) then
return 'tcl'
end
end
prev_line = line
end
return name
end
function M.sql(bufnr) function M.sql(bufnr)
if vim.g.filetype_sql then if vim.g.filetype_sql then
vim.bo[bufnr].filetype = vim.g.filetype_sql return vim.g.filetype_sql
else else
vim.bo[bufnr].filetype = 'sql' return 'sql'
end end
end end
-- Determine if a *.src file is Kuka Robot Language -- Determine if a *.src file is Kuka Robot Language
function M.src(bufnr) function M.src(bufnr)
if vim.g.filetype_src then if vim.g.filetype_src then
vim.bo[bufnr].filetype = vim.g.filetype_src return vim.g.filetype_src
return
end end
local line = nextnonblank(bufnr, 1) local line = nextnonblank(bufnr, 1)
if matchregex(line, [[\c\v^\s*%(\&\w+|%(global\s+)?def%(fct)?>)]]) then if matchregex(line, [[\c\v^\s*%(\&\w+|%(global\s+)?def%(fct)?>)]]) then
vim.bo[bufnr].filetype = 'krl' return 'krl'
end end
end end
function M.sys(bufnr) function M.sys(bufnr)
if vim.g.filetype_sys then if vim.g.filetype_sys then
vim.bo[bufnr].filetype = vim.g.filetype_sys return vim.g.filetype_sys
elseif is_rapid(bufnr) then elseif is_rapid(bufnr) then
vim.bo[bufnr].filetype = 'rapid' return 'rapid'
else else
vim.bo[bufnr].filetype = 'bat' return 'bat'
end end
end end
function M.tex(path, bufnr) end -- Choose context, plaintex, or tex (LaTeX) based on these rules:
-- 1. Check the first line of the file for "%&<format>".
-- 2. Check the first 1000 non-comment lines for LaTeX or ConTeXt keywords.
-- 3. Default to "plain" or to g:tex_flavor, can be set in user's vimrc.
function M.tex(path, bufnr)
local format = getlines(bufnr, 1):find('^%%&%s*(%a+)')
if format then
format = format:lower():gsub('pdf', '', 1)
if format == 'tex' then
return 'tex'
elseif format == 'plaintex' then
return 'plaintex'
end
elseif path:lower():find('tex/context/.*/.*%.tex') then
return 'context'
else
local lpat = [[documentclass\>\|usepackage\>\|begin{\|newcommand\>\|renewcommand\>]]
local cpat =
[[start\a\+\|setup\a\+\|usemodule\|enablemode\|enableregime\|setvariables\|useencoding\|usesymbols\|stelle\a\+\|verwende\a\+\|stel\a\+\|gebruik\a\+\|usa\a\+\|imposta\a\+\|regle\a\+\|utilisemodule\>]]
for i, l in ipairs(getlines(bufnr, 1, 1000)) do
-- Find first non-comment line
if not l:find('^%s*%%%S') then
-- Check the next thousand lines for a LaTeX or ConTeXt keyword.
for _, line in ipairs(getlines(bufnr, i + 1, i + 1000)) do
local lpat_match, cpat_match = matchregex(line, [[\c^\s*\\\%(]] .. lpat .. [[\)\|^\s*\\\(]] .. cpat .. [[\)]])
if lpat_match then
return 'tex'
elseif cpat_match then
return 'context'
end
end
end
end
-- TODO: add AMSTeX, RevTex, others?
if not vim.g.tex_flavor or vim.g.tex_flavor == 'plain' then
return 'plaintex'
elseif vim.g.tex_flavor == 'context' then
return 'context'
else
-- Probably LaTeX
return 'tex'
end
end
end
-- Determine if a *.tf file is TF mud client or terraform -- Determine if a *.tf file is TF mud client or terraform
function M.tf(bufnr) function M.tf(bufnr)
@ -829,11 +944,10 @@ function M.tf(bufnr)
-- Assume terraform file on a non-empty line (not whitespace-only) -- Assume terraform file on a non-empty line (not whitespace-only)
-- and when the first non-whitespace character is not a ; or / -- and when the first non-whitespace character is not a ; or /
if not line:find('^%s*$') and not line:find('^%s*[;/]') then if not line:find('^%s*$') and not line:find('^%s*[;/]') then
vim.bo[bufnr].filetype = 'terraform' return 'terraform'
return
end end
end end
vim.bo[bufnr].filetype = 'tf' return 'tf'
end end
function M.xml(bufnr) function M.xml(bufnr)
@ -844,29 +958,25 @@ function M.xml(bufnr)
if is_docbook4 or is_docbook5 then if is_docbook4 or is_docbook5 then
vim.b[bufnr].docbk_type = 'xml' vim.b[bufnr].docbk_type = 'xml'
vim.b[bufnr].docbk_ver = is_docbook4 and 4 or 5 vim.b[bufnr].docbk_ver = is_docbook4 and 4 or 5
vim.bo[bufnr].filetype = 'docbk' return 'docbk'
return
end end
if line:find([[xmlns:xbl="http://www.mozilla.org/xbl"]]) then if line:find([[xmlns:xbl="http://www.mozilla.org/xbl"]]) then
vim.bo[bufnr].filetype = 'xbl' return 'xbl'
return
end end
end end
vim.bo[bufnr].filetype = 'xml' return 'xml'
end end
function M.y(bufnr) function M.y(bufnr)
for _, line in ipairs(getlines(bufnr, 1, 100)) do for _, line in ipairs(getlines(bufnr, 1, 100)) do
if line:find('^%s*%%') then if line:find('^%s*%%') then
vim.bo[bufnr].filetype = 'yacc' return 'yacc'
return
end end
if matchregex(line, [[\c^\s*\(#\|class\>\)]]) and not line:lower():find('^%s*#%s*include') then if matchregex(line, [[\c^\s*\(#\|class\>\)]]) and not line:lower():find('^%s*#%s*include') then
vim.bo[bufnr].filetype = 'racc' return 'racc'
return
end end
end end
vim.bo[bufnr].filetype = 'yacc' return 'yacc'
end end
-- luacheck: pop -- luacheck: pop