aboutsummaryrefslogtreecommitdiff
path: root/runtime/lua/vim
diff options
context:
space:
mode:
authorJonas Strittmatter <40792180+smjonas@users.noreply.github.com>2022-05-22 20:16:04 +0200
committerGitHub <noreply@github.com>2022-05-22 12:16:04 -0600
commit52623ce9353bac2b4a82c0197c5a08202e74b156 (patch)
tree836dcd62eb1a33745fe1787339320ce7cd60a6f8 /runtime/lua/vim
parent8c2fd65bb165582b7d02195309a3ce3697e27d8f (diff)
downloadrneovim-52623ce9353bac2b4a82c0197c5a08202e74b156.tar.gz
rneovim-52623ce9353bac2b4a82c0197c5a08202e74b156.tar.bz2
rneovim-52623ce9353bac2b4a82c0197c5a08202e74b156.zip
refactor(runtime): convert the remaining dist#ft functions to lua (#18623)
Diffstat (limited to 'runtime/lua/vim')
-rw-r--r--runtime/lua/vim/filetype.lua343
-rw-r--r--runtime/lua/vim/filetype/detect.lua530
2 files changed, 494 insertions, 379 deletions
diff --git a/runtime/lua/vim/filetype.lua b/runtime/lua/vim/filetype.lua
index 8321e0b11e..c9e81b53d7 100644
--- a/runtime/lua/vim/filetype.lua
+++ b/runtime/lua/vim/filetype.lua
@@ -786,8 +786,8 @@ local extension = {
zut = 'zimbutempl',
zsh = 'zsh',
vala = 'vala',
- E = function()
- vim.fn['dist#ft#FTe']()
+ E = function(path, bufnr)
+ return require('vim.filetype.detect').e(bufnr)
end,
EU = function(path, bufnr)
return require('vim.filetype.detect').euphoria(bufnr)
@@ -804,26 +804,26 @@ local extension = {
EXW = function(path, bufnr)
return require('vim.filetype.detect').euphoria(bufnr)
end,
- PL = function()
- vim.fn['dist#ft#FTpl']()
+ PL = function(path, bufnr)
+ return require('vim.filetype.detect').pl(bufnr)
end,
R = function(path, bufnr)
- require('vim.filetype.detect').r(bufnr)
+ return require('vim.filetype.detect').r(bufnr)
end,
asm = function(path, bufnr)
- require('vim.filetype.detect').asm(bufnr)
+ return require('vim.filetype.detect').asm(bufnr)
end,
bas = function(path, bufnr)
- require('vim.filetype.detect').bas(bufnr)
+ return require('vim.filetype.detect').bas(bufnr)
end,
- bi = function()
- vim.fn['dist#ft#FTbas']()
+ bi = function(path, bufnr)
+ return require('vim.filetype.detect').bas(bufnr)
end,
- bm = function()
- vim.fn['dist#ft#FTbas']()
+ bm = function(path, bufnr)
+ return require('vim.filetype.detect').bas(bufnr)
end,
- bash = function()
- vim.fn['dist#ft#SetFileTypeSH']('bash')
+ bash = function(path, bufnr)
+ return require('vim.filetype.detect').sh(path, bufnr, 'bash')
end,
btm = function(path, bufnr)
return require('vim.filetype.detect').btm(bufnr)
@@ -834,104 +834,104 @@ local extension = {
ch = function(path, bufnr)
return require('vim.filetype.detect').change(bufnr)
end,
- com = function()
- vim.fn['dist#ft#BindzoneCheck']('dcl')
+ com = function(path, bufnr)
+ return require('vim.filetype.detect').bindzone(bufnr, 'dcl')
end,
- cpt = function()
- vim.fn['dist#ft#FThtml']()
+ cpt = function(path, bufnr)
+ return require('vim.filetype.detect').html(bufnr)
end,
- csh = function()
- vim.fn['dist#ft#CSH']()
+ csh = function(path, bufnr)
+ return require('vim.filetype.detect').csh(path, bufnr)
end,
d = function(path, bufnr)
return require('vim.filetype.detect').dtrace(bufnr)
end,
- db = function()
- vim.fn['dist#ft#BindzoneCheck']('')
+ db = function(path, bufnr)
+ return require('vim.filetype.detect').bindzone(bufnr, '')
end,
- dtml = function()
- vim.fn['dist#ft#FThtml']()
+ dtml = function(path, bufnr)
+ return require('vim.filetype.detect').html(bufnr)
end,
- e = function()
- vim.fn['dist#ft#FTe']()
+ e = function(path, bufnr)
+ return require('vim.filetype.detect').e(bufnr)
end,
- ebuild = function()
- vim.fn['dist#ft#SetFileTypeSH']('bash')
+ ebuild = function(path, bufnr)
+ return require('vim.filetype.detect').sh(path, bufnr, 'bash')
end,
- eclass = function()
- vim.fn['dist#ft#SetFileTypeSH']('bash')
+ eclass = function(path, bufnr)
+ return require('vim.filetype.detect').sh(path, bufnr, 'bash')
end,
ent = function(path, bufnr)
- require('vim.filetype.detect').ent(bufnr)
+ return require('vim.filetype.detect').ent(bufnr)
end,
- env = function()
- vim.fn['dist#ft#SetFileTypeSH'](vim.fn.getline(1))
+ env = function(path, bufnr)
+ return require('vim.filetype.detect').sh(path, bufnr, getline(bufnr, 1))
end,
eu = function(path, bufnr)
- require('vim.filetype.detect').euphoria(bufnr)
+ return require('vim.filetype.detect').euphoria(bufnr)
end,
ew = function(path, bufnr)
- require('vim.filetype.detect').euphoria(bufnr)
+ return require('vim.filetype.detect').euphoria(bufnr)
end,
ex = function(path, bufnr)
- require('vim.filetype.detect').ex(bufnr)
+ return require('vim.filetype.detect').ex(bufnr)
end,
exu = function(path, bufnr)
- require('vim.filetype.detect').euphoria(bufnr)
+ return require('vim.filetype.detect').euphoria(bufnr)
end,
exw = function(path, bufnr)
- require('vim.filetype.detect').euphoria(bufnr)
+ return require('vim.filetype.detect').euphoria(bufnr)
end,
frm = function(path, bufnr)
- require('vim.filetype.detect').frm(bufnr)
+ return require('vim.filetype.detect').frm(bufnr)
end,
fs = function(path, bufnr)
- vim.fn['dist#ft#FTfs']()
+ return require('vim.filetype.detect').fs(bufnr)
end,
h = function(path, bufnr)
- require('vim.filetype.detect').header(bufnr)
+ return require('vim.filetype.detect').header(bufnr)
end,
- htm = function()
- vim.fn['dist#ft#FThtml']()
+ htm = function(path, bufnr)
+ return require('vim.filetype.detect').html(bufnr)
end,
- html = function()
- vim.fn['dist#ft#FThtml']()
+ html = function(path, bufnr)
+ return require('vim.filetype.detect').html(bufnr)
end,
i = function(path, bufnr)
- require('vim.filetype.detect').progress_asm(bufnr)
+ return require('vim.filetype.detect').progress_asm(bufnr)
end,
idl = function(path, bufnr)
- require('vim.filetype.detect').idl(bufnr)
+ return require('vim.filetype.detect').idl(bufnr)
end,
- inc = function()
- vim.fn['dist#ft#FTinc']()
+ inc = function(path, bufnr)
+ return require('vim.filetype.detect').inc(bufnr)
end,
inp = function(path, bufnr)
- require('vim.filetype.detect').inp(bufnr)
+ return require('vim.filetype.detect').inp(bufnr)
end,
- ksh = function()
- vim.fn['dist#ft#SetFileTypeSH']('ksh')
+ ksh = function(path, bufnr)
+ return require('vim.filetype.detect').sh(path, bufnr, 'ksh')
end,
lst = function(path, bufnr)
- require('vim.filetype.detect').asm(bufnr)
+ return require('vim.filetype.detect').asm(bufnr)
end,
m = function(path, bufnr)
- require('vim.filetype.detect').m(bufnr)
+ return require('vim.filetype.detect').m(bufnr)
end,
mac = function(path, bufnr)
- require('vim.filetype.detect').asm(bufnr)
+ return require('vim.filetype.detect').asm(bufnr)
end,
mc = function(path, bufnr)
- require('vim.filetype.detect').mc(bufnr)
+ return require('vim.filetype.detect').mc(bufnr)
end,
mm = function(path, bufnr)
- require('vim.filetype.detect').mm(bufnr)
+ return require('vim.filetype.detect').mm(bufnr)
end,
mms = function(path, bufnr)
- require('vim.filetype.detect').mms(bufnr)
+ return require('vim.filetype.detect').mms(bufnr)
end,
p = function(path, bufnr)
- require('vim.filetype.detect').progress_pascal(bufnr)
+ return require('vim.filetype.detect').progress_pascal(bufnr)
end,
patch = function(path, bufnr)
local firstline = getline(bufnr, 1)
@@ -941,65 +941,65 @@ local extension = {
return 'diff'
end
end,
- pl = function()
- vim.fn['dist#ft#FTpl']()
+ pl = function(path, bufnr)
+ return require('vim.filetype.detect').pl(bufnr)
end,
- pp = function()
- vim.fn['dist#ft#FTpp']()
+ pp = function(path, bufnr)
+ return require('vim.filetype.detect').pp(bufnr)
end,
- pro = function()
- vim.fn['dist#ft#ProtoCheck']('idlang')
+ pro = function(path, bufnr)
+ return require('vim.filetype.detect').proto(bufnr, 'idlang')
end,
- pt = function()
- vim.fn['dist#ft#FThtml']()
+ pt = function(path, bufnr)
+ return require('vim.filetype.detect').html('idlang')
end,
r = function(path, bufnr)
- require('vim.filetype.detect').r(bufnr)
+ return require('vim.filetype.detect').r(bufnr)
end,
rdf = function(path, bufnr)
- require('vim.filetype.detect').redif(bufnr)
+ return require('vim.filetype.detect').redif(bufnr)
end,
rules = function(path, bufnr)
- require('vim.filetype.detect').rules(path, bufnr)
+ return require('vim.filetype.detect').rules(path, bufnr)
end,
sc = function(path, bufnr)
- require('vim.filetype.detect').sc(bufnr)
+ return require('vim.filetype.detect').sc(bufnr)
end,
scd = function(path, bufnr)
- require('vim.filetype.detect').scd(bufnr)
+ return require('vim.filetype.detect').scd(bufnr)
end,
- sh = function()
- vim.fn['dist#ft#SetFileTypeSH'](vim.fn.getline(1))
+ sh = function(path, bufnr)
+ return require('vim.filetype.detect').sh(path, bufnr, getline(bufnr, 1))
end,
- shtml = function()
- vim.fn['dist#ft#FThtml']()
+ shtml = function(path, bufnr)
+ return require('vim.filetype.detect').html(bufnr)
end,
sql = function(path, bufnr)
- require('vim.filetype.detect').sql(bufnr)
+ return require('vim.filetype.detect').sql(bufnr)
end,
- stm = function()
- vim.fn['dist#ft#FThtml']()
+ stm = function(path, bufnr)
+ return require('vim.filetype.detect').html(bufnr)
end,
- tcsh = function()
- vim.fn['dist#ft#SetFileTypeShell']('tcsh')
+ tcsh = function(path, bufnr)
+ return require('vim.filetype.detect').shell(path, bufnr, 'tcsh')
end,
- tex = function()
- vim.fn['dist#ft#FTtex']()
+ tex = function(path, bufnr)
+ return require('vim.filetype.detect').tex(path, bufnr)
end,
tf = function(path, bufnr)
- require('vim.filetype.detect').tf(bufnr)
+ return require('vim.filetype.detect').tf(bufnr)
end,
w = function(path, bufnr)
- require('vim.filetype.detect').progress_cweb(bufnr)
+ return require('vim.filetype.detect').progress_cweb(bufnr)
end,
xml = function(path, bufnr)
- require('vim.filetype.detect').xml(bufnr)
+ return require('vim.filetype.detect').xml(bufnr)
end,
y = function(path, bufnr)
- require('vim.filetype.detect').y(bufnr)
+ return require('vim.filetype.detect').y(bufnr)
end,
zsql = function(path, bufnr)
- require('vim.filetype.detect').sql(bufnr)
+ return require('vim.filetype.detect').sql(bufnr)
end,
txt = function(path, bufnr)
--helpfiles match *.txt, but should have a modeline as last line
@@ -1075,16 +1075,16 @@ local filename = {
exports = 'exports',
['.fetchmailrc'] = 'fetchmail',
fvSchemes = function(path, bufnr)
- require('vim.filetype.detect').foam(bufnr)
+ return require('vim.filetype.detect').foam(bufnr)
end,
fvSolution = function(path, bufnr)
- require('vim.filetype.detect').foam(bufnr)
+ return require('vim.filetype.detect').foam(bufnr)
end,
fvConstraints = function(path, bufnr)
- require('vim.filetype.detect').foam(bufnr)
+ return require('vim.filetype.detect').foam(bufnr)
end,
fvModels = function(path, bufnr)
- require('vim.filetype.detect').foam(bufnr)
+ return require('vim.filetype.detect').foam(bufnr)
end,
fstab = 'fstab',
mtab = 'fstab',
@@ -1300,63 +1300,63 @@ local filename = {
['.zcompdump'] = 'zsh',
['.zshenv'] = 'zsh',
['.zfbfmarks'] = 'zsh',
- ['.alias'] = function()
- vim.fn['dist#ft#CSH']()
+ ['.alias'] = function(path, bufnr)
+ return require('vim.filetype.detect').csh(path, bufnr)
end,
- ['.bashrc'] = function()
- vim.fn['dist#ft#SetFileTypeSH']('bash')
+ ['.bashrc'] = function(path, bufnr)
+ return require('vim.filetype.detect').sh(path, bufnr, 'bash')
end,
- ['.cshrc'] = function()
- vim.fn['dist#ft#CSH']()
+ ['.cshrc'] = function(path, bufnr)
+ return require('vim.filetype.detect').csh(path, bufnr)
end,
- ['.env'] = function()
- vim.fn['dist#ft#SetFileTypeSH'](vim.fn.getline(1))
+ ['.env'] = function(path, bufnr)
+ return require('vim.filetype.detect').sh(path, bufnr, getline(bufnr, 1))
end,
- ['.kshrc'] = function()
- vim.fn['dist#ft#SetFileTypeSH']('ksh')
+ ['.kshrc'] = function(path, bufnr)
+ return require('vim.filetype.detect').sh(path, bufnr, 'ksh')
end,
- ['.login'] = function()
- vim.fn['dist#ft#CSH']()
+ ['.login'] = function(path, bufnr)
+ return require('vim.filetype.detect').csh(path, bufnr)
end,
- ['.profile'] = function()
- vim.fn['dist#ft#SetFileTypeSH'](vim.fn.getline(1))
+ ['.profile'] = function(path, bufnr)
+ return require('vim.filetype.detect').sh(path, bufnr, getline(bufnr, 1))
end,
- ['.tcshrc'] = function()
- vim.fn['dist#ft#SetFileTypeShell']('tcsh')
+ ['.tcshrc'] = function(path, bufnr)
+ return require('vim.filetype.detect').shell(path, bufnr, 'tcsh')
end,
- ['/etc/profile'] = function()
- vim.fn['dist#ft#SetFileTypeSH'](vim.fn.getline(1))
+ ['/etc/profile'] = function(path, bufnr)
+ return require('vim.filetype.detect').sh(path, bufnr, getline(bufnr, 1))
end,
- APKBUILD = function()
- vim.fn['dist#ft#SetFileTypeSH']('bash')
+ APKBUILD = function(path, bufnr)
+ return require('vim.filetype.detect').sh(path, bufnr, 'bash')
end,
- PKGBUILD = function()
- vim.fn['dist#ft#SetFileTypeSH']('bash')
+ PKGBUILD = function(path, bufnr)
+ return require('vim.filetype.detect').sh(path, bufnr, 'bash')
end,
- ['bash.bashrc'] = function()
- vim.fn['dist#ft#SetFileTypeSH']('bash')
+ ['bash.bashrc'] = function(path, bufnr)
+ return require('vim.filetype.detect').sh(path, bufnr, 'bash')
end,
- bashrc = function()
- vim.fn['dist#ft#SetFileTypeSH']('bash')
+ bashrc = function(path, bufnr)
+ return require('vim.filetype.detect').sh(path, bufnr, 'bash')
end,
crontab = starsetf('crontab'),
- ['csh.cshrc'] = function()
- vim.fn['dist#ft#CSH']()
+ ['csh.cshrc'] = function(path, bufnr)
+ return require('vim.filetype.detect').csh(path, bufnr)
end,
- ['csh.login'] = function()
- vim.fn['dist#ft#CSH']()
+ ['csh.login'] = function(path, bufnr)
+ return require('vim.filetype.detect').csh(path, bufnr)
end,
- ['csh.logout'] = function()
- vim.fn['dist#ft#CSH']()
+ ['csh.logout'] = function(path, bufnr)
+ return require('vim.filetype.detect').csh(path, bufnr)
end,
- ['indent.pro'] = function()
- vim.fn['dist#ft#ProtoCheck']('indent')
+ ['indent.pro'] = function(path, bufnr)
+ return require('vim.filetype.detect').proto(bufnr, 'indent')
end,
- ['tcsh.login'] = function()
- vim.fn['dist#ft#SetFileTypeShell']('tcsh')
+ ['tcsh.login'] = function(path, bufnr)
+ return require('vim.filetype.detect').shell(path, bufnr, 'tcsh')
end,
- ['tcsh.tcshrc'] = function()
- vim.fn['dist#ft#SetFileTypeShell']('tcsh')
+ ['tcsh.tcshrc'] = function(path, bufnr)
+ return require('vim.filetype.detect').shell(path, bufnr, 'tcsh')
end,
-- END FILENAME
}
@@ -1528,44 +1528,44 @@ local pattern = {
['.*/etc/xdg/menus/.*%.menu'] = 'xml',
['.*Xmodmap'] = 'xmodmap',
['.*/etc/zprofile'] = 'zsh',
- ['%.bash[_-]aliases'] = function()
- vim.fn['dist#ft#SetFileTypeSH']('bash')
+ ['%.bash[_-]aliases'] = function(path, bufnr)
+ return require('vim.filetype.detect').sh(path, bufnr, 'bash')
end,
- ['%.bash[_-]logout'] = function()
- vim.fn['dist#ft#SetFileTypeSH']('bash')
+ ['%.bash[_-]logout'] = function(path, bufnr)
+ return require('vim.filetype.detect').sh(path, bufnr, 'bash')
end,
- ['%.bash[_-]profile'] = function()
- vim.fn['dist#ft#SetFileTypeSH']('bash')
+ ['%.bash[_-]profile'] = function(path, bufnr)
+ return require('vim.filetype.detect').sh(path, bufnr, 'bash')
end,
- ['%.cshrc.*'] = function()
- vim.fn['dist#ft#CSH']()
+ ['%.cshrc.*'] = function(path, bufnr)
+ return require('vim.filetype.detect').csh(path, bufnr)
end,
['%.gtkrc.*'] = starsetf('gtkrc'),
- ['%.kshrc.*'] = function()
- vim.fn['dist#ft#SetFileTypeSH']('ksh')
+ ['%.kshrc.*'] = function(path, bufnr)
+ return require('vim.filetype.detect').sh(path, bufnr, 'ksh')
end,
- ['%.login.*'] = function()
- vim.fn['dist#ft#CSH']()
+ ['%.login.*'] = function(path, bufnr)
+ return require('vim.filetype.detect').csh(path, bufnr)
end,
['%.neomuttrc.*'] = starsetf('neomuttrc'),
- ['%.profile.*'] = function()
- vim.fn['dist#ft#SetFileTypeSH'](vim.fn.getline(1))
+ ['%.profile.*'] = function(path, bufnr)
+ return require('vim.filetype.detect').sh(path, bufnr, getline(bufnr, 1))
end,
['%.reminders.*'] = starsetf('remind'),
- ['%.tcshrc.*'] = function()
- vim.fn['dist#ft#SetFileTypeShell']('tcsh')
+ ['%.tcshrc.*'] = function(path, bufnr)
+ return require('vim.filetype.detect').shell(path, bufnr, 'tcsh')
end,
['%.zcompdump.*'] = starsetf('zsh'),
['%.zlog.*'] = starsetf('zsh'),
['%.zsh.*'] = starsetf('zsh'),
['.*%.[1-9]'] = function(path, bufnr)
- require('vim.filetype.detect').nroff(bufnr)
+ return require('vim.filetype.detect').nroff(bufnr)
end,
['.*%.[aA]'] = function(path, bufnr)
- require('vim.filetype.detect').asm(bufnr)
+ return require('vim.filetype.detect').asm(bufnr)
end,
['.*%.[sS]'] = function(path, bufnr)
- require('vim.filetype.detect').asm(bufnr)
+ return require('vim.filetype.detect').asm(bufnr)
end,
['.*%.properties_.._.._.*'] = starsetf('jproperties'),
['.*%.vhdl_[0-9].*'] = starsetf('vhdl'),
@@ -1576,7 +1576,7 @@ local pattern = {
['.*/app%-defaults/.*'] = starsetf('xdefaults'),
['.*/bind/db%..*'] = starsetf('bindzone'),
['.*/debian/patches/.*'] = function(path, bufnr)
- require('vim.filetype.detect').dep3patch(path, bufnr)
+ return require('vim.filetype.detect').dep3patch(path, bufnr)
end,
['.*/etc/Muttrc%.d/.*'] = starsetf('muttrc'),
['.*/etc/apache2/.*%.conf.*'] = starsetf('apache'),
@@ -1592,8 +1592,8 @@ local pattern = {
['.*/etc/logcheck/.*%.d.*/.*'] = starsetf('logcheck'),
['.*/etc/modprobe%..*'] = starsetf('modconf'),
['.*/etc/pam%.d/.*'] = starsetf('pamconf'),
- ['.*/etc/profile'] = function()
- vim.fn['dist#ft#SetFileTypeSH'](vim.fn.getline(1))
+ ['.*/etc/profile'] = function(path, bufnr)
+ return require('vim.filetype.detect').sh(path, bufnr, getline(bufnr, 1))
end,
['.*/etc/proftpd/.*%.conf.*'] = starsetf('apachestyle'),
['.*/etc/proftpd/conf%..*/.*'] = starsetf('apachestyle'),
@@ -1621,8 +1621,8 @@ local pattern = {
['access%.conf.*'] = starsetf('apache'),
['apache%.conf.*'] = starsetf('apache'),
['apache2%.conf.*'] = starsetf('apache'),
- ['bash%-fc[-%.]'] = function()
- vim.fn['dist#ft#SetFileTypeSH']('bash')
+ ['bash%-fc[-%.]'] = function(path, bufnr)
+ return require('vim.filetype.detect').sh(path, bufnr, 'bash')
end,
['cabal%.project%..*'] = starsetf('cabalproject'),
['crontab%..*'] = starsetf('crontab'),
@@ -1650,28 +1650,28 @@ local pattern = {
['neomutt' .. string.rep('[%w_-]', 6)] = 'mail',
['/tmp/SLRN[0-9A-Z.]+'] = 'mail',
['[a-zA-Z0-9].*Dict'] = function(path, bufnr)
- require('vim.filetype.detect').foam(bufnr)
+ return require('vim.filetype.detect').foam(bufnr)
end,
['[a-zA-Z0-9].*Dict%..*'] = function(path, bufnr)
- require('vim.filetype.detect').foam(bufnr)
+ return require('vim.filetype.detect').foam(bufnr)
end,
['[a-zA-Z].*Properties'] = function(path, bufnr)
- require('vim.filetype.detect').foam(bufnr)
+ return require('vim.filetype.detect').foam(bufnr)
end,
['[a-zA-Z].*Properties%..*'] = function(path, bufnr)
- require('vim.filetype.detect').foam(bufnr)
+ return require('vim.filetype.detect').foam(bufnr)
end,
['.*Transport%..*'] = function(path, bufnr)
- require('vim.filetype.detect').foam(bufnr)
+ return require('vim.filetype.detect').foam(bufnr)
end,
['.*/constant/g'] = function(path, bufnr)
- require('vim.filetype.detect').foam(bufnr)
+ return require('vim.filetype.detect').foam(bufnr)
end,
['.*/0/.*'] = function(path, bufnr)
- require('vim.filetype.detect').foam(bufnr)
+ return require('vim.filetype.detect').foam(bufnr)
end,
['.*/0%.orig/.*'] = function(path, bufnr)
- require('vim.filetype.detect').foam(bufnr)
+ return require('vim.filetype.detect').foam(bufnr)
end,
['.*/etc/sensors%.d/[^.].*'] = starsetf('sensors'),
['.*%.git/.*'] = function(path, bufnr)
@@ -1680,24 +1680,29 @@ local pattern = {
return 'git'
end
end,
- ['.*%.[Cc][Ff][Gg]'] = function(path, bufnr)
- require('vim.filetype.detect').cfg(bufnr)
- end,
+ ['.*%.[Cc][Ff][Gg]'] = {
+ function(path, bufnr)
+ 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)
- require('vim.filetype.detect').dat(bufnr)
+ return require('vim.filetype.detect').dat(bufnr)
end,
['.*%.[Mm][Oo][Dd]'] = function(path, bufnr)
- require('vim.filetype.detect').mod(path, bufnr)
+ return require('vim.filetype.detect').mod(path, bufnr)
end,
['.*%.[Ss][Rr][Cc]'] = function(path, bufnr)
- require('vim.filetype.detect').src(bufnr)
+ return require('vim.filetype.detect').src(bufnr)
end,
['.*%.[Ss][Uu][Bb]'] = 'krl',
['.*%.[Pp][Rr][Gg]'] = function(path, bufnr)
- require('vim.filetype.detect').prg(bufnr)
+ return require('vim.filetype.detect').prg(bufnr)
end,
['.*%.[Ss][Yy][Ss]'] = function(path, bufnr)
- require('vim.filetype.detect').sys(bufnr)
+ return require('vim.filetype.detect').sys(bufnr)
end,
-- Neovim only
['.*/queries/.*%.scm'] = 'query', -- tree-sitter queries
diff --git a/runtime/lua/vim/filetype/detect.lua b/runtime/lua/vim/filetype/detect.lua
index da59625353..1721923c18 100644
--- a/runtime/lua/vim/filetype/detect.lua
+++ b/runtime/lua/vim/filetype/detect.lua
@@ -27,6 +27,9 @@ end
---@private
local function findany(s, patterns)
+ if s == nil then
+ return false
+ end
for _, v in ipairs(patterns) do
if s:find(v) then
return true
@@ -82,7 +85,7 @@ function M.asm(bufnr)
vim.b[bufnr].asmsyntax = 'asm'
end
end
- vim.bo[bufnr].filetype = vim.fn.fnameescape(vim.b[bufnr].asmsyntax)
+ return vim.fn.fnameescape(vim.b[bufnr].asmsyntax)
end
-- 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
function M.bas(bufnr)
if vim.g.filetype_bas then
- vim.bo[bufnr].filetype = vim.g.filetype_bas
- return
+ return vim.g.filetype_bas
end
-- 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
if line:find(fb_comment) or matchregex(line, fb_preproc) or matchregex(line, fb_keywords) then
- vim.bo[bufnr].filetype = 'freebasic'
- return
+ return 'freebasic'
elseif matchregex(line, qb64_preproc) then
- vim.bo[bufnr].filetype = 'qb64'
- return
+ return 'qb64'
elseif findany(line:lower(), visual_basic_content) then
- vim.bo[bufnr].filetype = 'vb'
- return
+ return 'vb'
end
end
- vim.bo[bufnr].filetype = 'basic'
+ return 'basic'
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)
if vim.g.dosbatch_syntax_for_btm and vim.g.dosbatch_syntax_for_btm ~= 0 then
- vim.bo[bufnr].filetype = 'dosbatch'
+ return 'dosbatch'
else
- vim.bo[bufnr].filetype = 'btm'
+ return 'btm'
end
end
@@ -157,11 +163,11 @@ end
function M.cfg(bufnr)
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
- vim.bo[bufnr].filetype = 'rapid'
+ return 'rapid'
else
- vim.bo[bufnr].filetype = 'cfg'
+ return 'cfg'
end
end
@@ -173,38 +179,44 @@ end
function M.change(bufnr)
local first_line = getlines(bufnr, 1)
if findany(first_line, { '^#', '^!' }) then
- vim.bo[bufnr].filetype = 'ch'
- return
+ return 'ch'
end
for _, line in ipairs(getlines(bufnr, 1, 10)) do
if line:find('^@') then
- vim.bo[bufnr].filetype = 'change'
- return
+ return 'change'
end
if line:find('MODULE') then
- vim.bo[bufnr].filetype = 'chill'
- return
+ return 'chill'
elseif findany(line:lower(), { 'main%s*%(', '#%s*include', '//' }) then
- vim.bo[bufnr].filetype = 'ch'
- return
+ return 'ch'
end
end
- vim.bo[bufnr].filetype = 'chill'
+ return 'chill'
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
--- TODO: this one fails for some reason, so I omitted it. #18219 should be merged first.
function M.dat(bufnr)
- -- if vim.g.filetype_dat then
- -- vim.bo[bufnr].filetype = vim.g.filetype_dat
- -- return
- -- end
- -- local line = nextnonblank(bufnr, 1):lower()
- -- if findany(line, { "^%s*&%w+", "^%s*defdat" }) then
- -- vim.bo[bufnr].filetype = "krl"
- -- end
+ if vim.g.filetype_dat then
+ return vim.g.filetype_dat
+ end
+ local line = nextnonblank(bufnr, 1)
+ if matchregex(line, [[\c\v^\s*%(\&\w+|defdat>)]]) then
+ return 'krl'
+ end
end
-- This function is called for all files under */debian/patches/*, make sure not
@@ -231,8 +243,7 @@ function M.dep3patch(path, bufnr)
'^Applied%-Upstream:',
})
then
- vim.bo[bufnr].filetype = 'dep3patch'
- return
+ return 'dep3patch'
elseif line:find('^%-%-%-') then
-- End of headers found. stop processing
return
@@ -249,25 +260,24 @@ function M.dtrace(bufnr)
for _, line in ipairs(getlines(bufnr, 1, 100)) do
if matchregex(line, [[\c^module\>\|^import\>]]) then
-- D files often start with a module and/or import statement.
- vim.bo[bufnr].filetype = 'd'
- return
+ return 'd'
elseif findany(line, { '^#!%S+dtrace', '#pragma%s+D%s+option', ':%S-:%S-:' }) then
- vim.bo[bufnr].filetype = 'dtrace'
- return
+ return 'dtrace'
end
end
- vim.bo[bufnr].filetype = 'd'
+ return 'd'
end
-function M.e(path, bufnr)
+function M.e(bufnr)
if vim.g.filetype_euphoria then
- vim.bo[bufnr].filetype = vim.g.filetype_euphoria
- return
+ return vim.g.filetype_euphoria
end
- -- TODO: WIP
- -- for _, line in ipairs(getlines(bufnr, 1, 100)) do
- -- if line:find("^$")
- -- end
+ for _, line in ipairs(getlines(bufnr, 1, 100)) do
+ if findany(line, { "^%s*<'%s*$", "^%s*'>%s*$" }) then
+ return 'specman'
+ end
+ end
+ return 'eiffel'
end
-- This function checks for valid cl syntax in the first five lines.
@@ -276,36 +286,34 @@ end
function M.ent(bufnr)
for _, line in ipairs(getlines(bufnr, 1, 5)) do
if line:find('^%s*[#{]') then
- vim.bo[bufnr].filetype = 'cl'
- return
+ return 'cl'
elseif not line:find('^%s*$') then
-- Not a blank line, not a comment, and not a block start,
-- so doesn't look like valid cl code.
break
end
end
- vim.bo[bufnr].filetype = 'dtd'
+ return 'dtd'
end
function M.euphoria(bufnr)
if vim.g.filetype_euphoria then
- vim.bo[bufnr].filetype = vim.g.filetype_euphoria
+ return vim.g.filetype_euphoria
else
- vim.bo[bufnr].filetype = 'euphoria3'
+ return 'euphoria3'
end
end
function M.ex(bufnr)
if vim.g.filetype_euphoria then
- vim.bo[bufnr].filetype = vim.g.filetype_euphoria
+ return vim.g.filetype_euphoria
else
for _, line in ipairs(getlines(bufnr, 1, 100)) do
if matchregex(line, [[\c^--\|^ifdef\>\|^include\>]]) then
- vim.bo[bufnr].filetype = 'euphoria3'
- return
+ return 'euphoria3'
end
end
- vim.bo[bufnr].filetype = 'elixir'
+ return 'elixir'
end
end
@@ -318,93 +326,110 @@ function M.foam(bufnr)
if line:find('^FoamFile') then
foam_file = true
elseif foam_file and line:find('^%s*object') then
- vim.bo[bufnr].filetype = 'foam'
- return
+ return 'foam'
end
end
end
function M.frm(bufnr)
if vim.g.filetype_frm then
- vim.bo[bufnr].filetype = vim.g.filetype_frm
- return
+ return vim.g.filetype_frm
end
local lines = table.concat(getlines(bufnr, 1, 5)):lower()
if findany(lines, visual_basic_content) then
- vim.bo[bufnr].filetype = 'vb'
+ return 'vb'
else
- vim.bo[bufnr].filetype = 'form'
+ return 'form'
end
end
-- Distinguish between Forth and F#.
function M.fs(bufnr)
- -- TODO: WIP
- -- if vim.g.filetype_fs then
- -- vim.bo[bufnr].filetype = vim.g.filetype_fs
- -- return
- -- end
- -- local line = nextnonblank(bufnr, 1)
- -- if findany(line, { '^%s*.?%( ', '^%s*\\G? ', '^\\$', '^%s*: %S' }) then
- -- vim.bo[bufnr].filetype = 'forth'
- -- else
- -- vim.bo[bufnr].filetype = 'fsharp'
- -- end
+ if vim.g.filetype_fs then
+ return vim.g.filetype_fs
+ end
+ local line = nextnonblank(bufnr, 1)
+ if findany(line, { '^%s*%.?%( ', '^%s*\\G? ', '^\\$', '^%s*: %S' }) then
+ return 'forth'
+ else
+ return 'fsharp'
+ end
end
function M.header(bufnr)
for _, line in ipairs(getlines(bufnr, 1, 200)) do
if findany(line:lower(), { '^@interface', '^@end', '^@class' }) then
if vim.g.c_syntax_for_h then
- vim.bo[bufnr].filetype = 'objc'
+ return 'objc'
else
- vim.bo[bufnr].filetype = 'objcpp'
+ return 'objcpp'
end
- return
end
end
if vim.g.c_syntax_for_h then
- vim.bo[bufnr].filetype = 'c'
+ return 'c'
elseif vim.g.ch_syntax_for_h then
- vim.bo[bufnr].filetype = 'ch'
+ return 'ch'
else
- vim.bo[bufnr].filetype = 'cpp'
+ return 'cpp'
end
end
function M.html(bufnr)
for _, line in ipairs(getlines(bufnr, 1, 10)) do
if matchregex(line, [[\<DTD\s\+XHTML\s]]) then
- vim.bo[bufnr].filetype = 'xhtml'
- return
+ return 'xhtml'
elseif matchregex(line, [[\c{%\s*\(extends\|block\|load\)\>\|{#\s\+]]) then
- vim.bo[bufnr].filetype = 'htmldjango'
- return
+ return 'htmldjango'
end
end
- vim.bo[bufnr].filetype = 'html'
+ return 'html'
end
function M.idl(bufnr)
for _, line in ipairs(getlines(bufnr, 1, 50)) do
if findany(line:lower(), { '^%s*import%s+"unknwn"%.idl', '^%s*import%s+"objidl"%.idl' }) then
- vim.bo[bufnr].filetype = 'msidl'
- return
+ return 'msidl'
end
end
- vim.bo[bufnr].filetype = 'idl'
+ return 'idl'
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)
if getlines(bufnr, 1):find('^%*') then
- vim.bo[bufnr].filetype = 'abaqus'
+ return 'abaqus'
else
for _, line in ipairs(getlines(bufnr, 1, 500)) do
if line:lower():find('^header surface data') then
- vim.bo[bufnr].filetype = 'trasys'
- return
+ return 'trasys'
end
end
end
@@ -426,18 +451,16 @@ function M.lpc(bufnr)
'^mixed',
})
then
- vim.bo[bufnr].filetype = 'lpc'
- return
+ return 'lpc'
end
end
end
- vim.bo[bufnr].filetype = 'c'
+ return 'c'
end
function M.m(bufnr)
if vim.g.filetype_m then
- vim.bo[bufnr].filetype = vim.g.filetype_m
- return
+ return vim.g.filetype_m
end
-- Excluding end(for|function|if|switch|while) common to Murphi
@@ -455,25 +478,20 @@ function M.m(bufnr)
saw_comment = true
end
if line:find('^%s*//') or matchregex(line, [[\c^\s*@import\>]]) or matchregex(line, objc_preprocessor) then
- vim.bo[bufnr].filetype = 'objc'
- return
+ return 'objc'
end
if
findany(line, { '^%s*#', '^%s*%%!' })
or matchregex(line, [[\c^\s*unwind_protect\>]])
or matchregex(line, [[\c\%(^\|;\)\s*]] .. octave_block_terminators)
then
- vim.bo[bufnr].filetype = 'octave'
- return
+ return 'octave'
elseif line:find('^%s*%%') then
- vim.bo[bufnr].filetype = 'matlab'
- return
+ return 'matlab'
elseif line:find('^%s*%(%*') then
- vim.bo[bufnr].filetype = 'mma'
- return
+ return 'mma'
elseif matchregex(line, [[\c^\s*\(\(type\|var\)\>\|--\)]]) then
- vim.bo[bufnr].filetype = 'murphi'
- return
+ return 'murphi'
end
end
@@ -481,10 +499,10 @@ function M.m(bufnr)
-- 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
-- common.
- vim.bo[bufnr].filetype = 'objc'
+ return 'objc'
else
-- Default is Matlab
- vim.bo[bufnr].filetype = 'matlab'
+ return 'mat