diff --git a/runtime/lua/vim/filetype/detect.lua b/runtime/lua/vim/filetype/detect.lua index a8ef5c0c47..25b10351a1 100644 --- a/runtime/lua/vim/filetype/detect.lua +++ b/runtime/lua/vim/filetype/detect.lua @@ -688,10 +688,7 @@ function M.fvwm_v1(_, _) end --- @type vim.filetype.mapfn -function M.fvwm_v2(path, _) - if fn.fnamemodify(path, ':e') == 'm4' then - return 'fvwm2m4' - end +function M.fvwm_v2(_, _) return 'fvwm', function(bufnr) vim.b[bufnr].fvwm_version = 2 end @@ -1026,22 +1023,30 @@ function M.m(_, bufnr) end end +--- For files ending in *.m4, distinguish: +--- – *.html.m4 files +--- - *fvwm2rc*.m4 files +--- – files in the Autoconf M4 dialect +--- – files in POSIX M4 --- @type vim.filetype.mapfn function M.m4(path, bufnr) local fname = fn.fnamemodify(path, ':t') path = fn.fnamemodify(path, ':p:h') - -- Case 0: canonical Autoconf file - if fname == 'aclocal.m4' then - return 'config' - end - - -- Case 1: html.m4 if fname:find('html%.m4$') then return 'htmlm4' end - -- Case 2: repo heuristic (nearby configure.ac) + if fname:find('fvwm2rc') then + return 'fvwm2m4' + end + + -- Canonical Autoconf file + if fname == 'aclocal.m4' then + return 'config' + end + + -- Repo heuristic for Autoconf M4 (nearby configure.ac) if fn.filereadable(path .. '/../configure.ac') ~= 0 or fn.filereadable(path .. '/configure.ac') ~= 0 @@ -1049,7 +1054,7 @@ function M.m4(path, bufnr) return 'config' end - -- Case 3: content heuristic (scan first ~200 lines) + -- Content heuristic for Autoconf M4 (scan first ~200 lines) -- Signals: -- - Autoconf macro prefixes: AC_/AM_/AS_/AU_/AT_ for _, line in ipairs(getlines(bufnr, 1, 200)) do @@ -1058,7 +1063,7 @@ function M.m4(path, bufnr) end end - -- Case 4: default to POSIX M4 + -- Default to POSIX M4 return 'm4' end diff --git a/test/old/testdir/test_filetype.vim b/test/old/testdir/test_filetype.vim index 5f09e5822d..9ec9d73a3c 100644 --- a/test/old/testdir/test_filetype.vim +++ b/test/old/testdir/test_filetype.vim @@ -308,7 +308,8 @@ func s:GetFilenameChecks() abort \ 'fstab': ['fstab', 'mtab'], \ 'func': ['file.fc'], \ 'fusion': ['file.fusion'], - \ 'fvwm': ['/.fvwm/file', 'any/.fvwm/file'], + \ 'fvwm': ['/.fvwm/file', 'any/.fvwm/file', '.fvwmrc', 'foo.fvwmrc', 'fvwmrc.foo', '.fvwm2rc', 'foo.fvwm2rc', 'fvwm2rc.foo', 'foo.fvwm95.hook', 'fvwm95.foo.hook'], + \ 'fvwm2m4': ['.fvwm2rc.m4', 'foo.fvwm2rc.m4', 'fvwm2rc.foo.m4'], \ 'gdb': ['.gdbinit', 'gdbinit', '.cuda-gdbinit', 'cuda-gdbinit', 'file.gdb', '.config/gdbearlyinit', '.gdbearlyinit'], \ 'gdmo': ['file.mo', 'file.gdmo'], \ 'gdresource': ['file.tscn', 'file.tres'],