diff --git a/runtime/doc/filetype.txt b/runtime/doc/filetype.txt index ca40c76ce4..67bf41da73 100644 --- a/runtime/doc/filetype.txt +++ b/runtime/doc/filetype.txt @@ -137,6 +137,7 @@ variables can be used to overrule the filetype used for certain extensions: file name variable ~ `*.app` g:filetype_app + `*.as` g:filetype_as `*.asa` g:filetype_asa |ft-aspperl-syntax| |ft-aspvbs-syntax| `*.asm` g:asmsyntax |ft-asm-syntax| diff --git a/runtime/lua/vim/filetype.lua b/runtime/lua/vim/filetype.lua index af27e53fec..bb4b4d22df 100644 --- a/runtime/lua/vim/filetype.lua +++ b/runtime/lua/vim/filetype.lua @@ -275,7 +275,7 @@ local extension = { astro = 'astro', asy = 'asy', atl = 'atlas', - as = 'atlas', + as = detect.as, zed = 'authzed', ahk = 'autohotkey', au3 = 'autoit', @@ -730,6 +730,7 @@ local extension = { JUST = 'just', kl = 'karel', KL = 'karel', + pg = 'kawasaki_as', kdl = 'kdl', kerml = 'kerml', kv = 'kivy', diff --git a/runtime/lua/vim/filetype/detect.lua b/runtime/lua/vim/filetype/detect.lua index 49739dba4f..f5bdd46084 100644 --- a/runtime/lua/vim/filetype/detect.lua +++ b/runtime/lua/vim/filetype/detect.lua @@ -63,6 +63,20 @@ function M.app(path, bufnr) end end +-- This function checks for Kawasaki robots AS file or atlas file type. +--- @type vim.filetype.mapfn +function M.as(_, bufnr) + if vim.g.filetype_as then + return vim.g.filetype_as + end + for _, line in ipairs(getlines(bufnr, 1, 30)) do + if line:find('^%.NETCONF') then + return 'kawasaki_as' + end + end + return 'atlas' +end + --- @param bufnr integer --- @return boolean local function is_objectscript_routime(bufnr) diff --git a/test/old/testdir/test_filetype.vim b/test/old/testdir/test_filetype.vim index eb9e38c917..d8a1de5297 100644 --- a/test/old/testdir/test_filetype.vim +++ b/test/old/testdir/test_filetype.vim @@ -433,6 +433,7 @@ func s:GetFilenameChecks() abort \ 'julia': ['file.jl'], \ 'just': ['justfile', 'Justfile', '.justfile', 'config.just'], \ 'karel': ['file.kl', 'file.KL'], + \ 'kawasaki_as': ['file.pg'], \ 'kconfig': ['Kconfig', 'Kconfig.debug', 'Kconfig.file', 'Config.in', 'Config.in.host'], \ 'kdl': ['file.kdl'], \ 'kerml': ['file.kerml'], @@ -3526,4 +3527,19 @@ func Test_cucumber_code_injection() filetype plugin off endfunc +func Test_as_file() + filetype on + + call writefile([], 'Xfile.as', 'D') + split Xfile.as + call assert_equal('atlas', &filetype) + bwipe! + call writefile(['', '.NETCONF'], 'Xfile.as', 'D') + split Xfile.as + call assert_equal('kawasaki_as', &filetype) + bwipe! + + filetype off +endfunc + " vim: shiftwidth=2 sts=2 expandtab