From 75a1e1a848b49c52a17cdcf85d4a2a3c98ddc62a Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 30 May 2026 11:29:42 +0800 Subject: [PATCH] vim-patch:9.2.0557: filetype: Kawasaki Robots files are not recognized Problem: filetype: Kawasaki Robots files are not recognized Solution: Detect *.pg as kawasaki_as filetype, add filetype detection for *.as as atlas or kawasaki_as filetype (KnoP-01). In Kawasaki robots (https://kawasakirobotics.com/products-robots/) AS language *.pg is the extention for a program file and *.as is for a complete backup. closes: vim/vim#20370 https://github.com/vim/vim/commit/dec3d6c7da637de5717c27d24a2f7ca50f7180a3 Co-authored-by: KnoP-01 --- runtime/doc/filetype.txt | 1 + runtime/lua/vim/filetype.lua | 3 ++- runtime/lua/vim/filetype/detect.lua | 14 ++++++++++++++ test/old/testdir/test_filetype.vim | 16 ++++++++++++++++ 4 files changed, 33 insertions(+), 1 deletion(-) 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