mirror of
https://github.com/neovim/neovim.git
synced 2025-09-06 03:18:16 +00:00
Merge pull request #35545 from zeertzjq/vim-9.1.1687
vim-patch:9.1.{1687,1693,1697,1713}: m4 ft detection updates
This commit is contained in:
@@ -734,13 +734,10 @@ local extension = {
|
|||||||
luau = 'luau',
|
luau = 'luau',
|
||||||
lrc = 'lyrics',
|
lrc = 'lyrics',
|
||||||
m = detect.m,
|
m = detect.m,
|
||||||
at = 'm4',
|
at = 'config',
|
||||||
mc = detect.mc,
|
mc = detect.mc,
|
||||||
quake = 'm3quake',
|
quake = 'm3quake',
|
||||||
m4 = function(path, _bufnr)
|
m4 = detect.m4,
|
||||||
local pathl = path:lower()
|
|
||||||
return not (pathl:find('html%.m4$') or pathl:find('fvwm2rc')) and 'm4' or nil
|
|
||||||
end,
|
|
||||||
eml = 'mail',
|
eml = 'mail',
|
||||||
mk = detect.make,
|
mk = detect.make,
|
||||||
mak = detect.make,
|
mak = detect.make,
|
||||||
@@ -2493,7 +2490,6 @@ local pattern = {
|
|||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
['^hg%-editor%-.*%.txt$'] = 'hgcommit',
|
['^hg%-editor%-.*%.txt$'] = 'hgcommit',
|
||||||
['%.html%.m4$'] = 'htmlm4',
|
|
||||||
['^JAM.*%.'] = starsetf('jam'),
|
['^JAM.*%.'] = starsetf('jam'),
|
||||||
['^Prl.*%.'] = starsetf('jam'),
|
['^Prl.*%.'] = starsetf('jam'),
|
||||||
['^${HOME}/.*/Code/User/.*%.json$'] = 'jsonc',
|
['^${HOME}/.*/Code/User/.*%.json$'] = 'jsonc',
|
||||||
|
@@ -688,10 +688,7 @@ function M.fvwm_v1(_, _)
|
|||||||
end
|
end
|
||||||
|
|
||||||
--- @type vim.filetype.mapfn
|
--- @type vim.filetype.mapfn
|
||||||
function M.fvwm_v2(path, _)
|
function M.fvwm_v2(_, _)
|
||||||
if fn.fnamemodify(path, ':e') == 'm4' then
|
|
||||||
return 'fvwm2m4'
|
|
||||||
end
|
|
||||||
return 'fvwm', function(bufnr)
|
return 'fvwm', function(bufnr)
|
||||||
vim.b[bufnr].fvwm_version = 2
|
vim.b[bufnr].fvwm_version = 2
|
||||||
end
|
end
|
||||||
@@ -1026,6 +1023,50 @@ function M.m(_, bufnr)
|
|||||||
end
|
end
|
||||||
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')
|
||||||
|
|
||||||
|
if fname:find('html%.m4$') then
|
||||||
|
return 'htmlm4'
|
||||||
|
end
|
||||||
|
|
||||||
|
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
|
||||||
|
then
|
||||||
|
return 'config'
|
||||||
|
end
|
||||||
|
|
||||||
|
-- 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
|
||||||
|
if line:find('^%s*A[CMSUT]_') then
|
||||||
|
return 'config'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Default to POSIX M4
|
||||||
|
return 'm4'
|
||||||
|
end
|
||||||
|
|
||||||
--- @param contents string[]
|
--- @param contents string[]
|
||||||
--- @return string?
|
--- @return string?
|
||||||
local function m4(contents)
|
local function m4(contents)
|
||||||
|
@@ -1,5 +1,10 @@
|
|||||||
" Test :setfiletype
|
" Test :setfiletype
|
||||||
|
|
||||||
|
" Make VIMRUNTIME and &rtp absolute.
|
||||||
|
" Otherwise, a :lcd inside a test would break the relative ../../runtime path.
|
||||||
|
let $VIMRUNTIME = fnamemodify($VIMRUNTIME, ':p')
|
||||||
|
let &rtp = join(map(split(&rtp, ','), 'fnamemodify(v:val, ":p")'), ',')
|
||||||
|
|
||||||
func Test_backup_strip()
|
func Test_backup_strip()
|
||||||
filetype on
|
filetype on
|
||||||
let fname = 'Xdetect.js~~~~~~~~~~~'
|
let fname = 'Xdetect.js~~~~~~~~~~~'
|
||||||
@@ -186,7 +191,7 @@ func s:GetFilenameChecks() abort
|
|||||||
\ 'coco': ['file.atg'],
|
\ 'coco': ['file.atg'],
|
||||||
\ 'conaryrecipe': ['file.recipe'],
|
\ 'conaryrecipe': ['file.recipe'],
|
||||||
\ 'conf': ['auto.master', 'file.conf', 'texdoc.cnf', '.x11vncrc', '.chktexrc', '.ripgreprc', 'ripgreprc', 'file.ctags'],
|
\ 'conf': ['auto.master', 'file.conf', 'texdoc.cnf', '.x11vncrc', '.chktexrc', '.ripgreprc', 'ripgreprc', 'file.ctags'],
|
||||||
\ 'config': ['configure.in', 'configure.ac', '/etc/hostname.file', 'any/etc/hostname.file'],
|
\ 'config': ['/etc/hostname.file', 'any/etc/hostname.file', 'configure.in', 'configure.ac', 'file.at', 'aclocal.m4'],
|
||||||
\ 'confini': ['pacman.conf', 'paru.conf', 'mpv.conf', 'any/.aws/config', 'any/.aws/credentials', 'file.nmconnection',
|
\ 'confini': ['pacman.conf', 'paru.conf', 'mpv.conf', 'any/.aws/config', 'any/.aws/credentials', 'file.nmconnection',
|
||||||
\ 'any/.gnuradio/grc.conf', 'any/gnuradio/config.conf', 'any/gnuradio/conf.d/modtool.conf'],
|
\ 'any/.gnuradio/grc.conf', 'any/gnuradio/config.conf', 'any/gnuradio/conf.d/modtool.conf'],
|
||||||
\ 'context': ['tex/context/any/file.tex', 'file.mkii', 'file.mkiv', 'file.mkvi', 'file.mkxl', 'file.mklx'],
|
\ 'context': ['tex/context/any/file.tex', 'file.mkii', 'file.mkiv', 'file.mkvi', 'file.mkxl', 'file.mklx'],
|
||||||
@@ -303,7 +308,8 @@ func s:GetFilenameChecks() abort
|
|||||||
\ 'fstab': ['fstab', 'mtab'],
|
\ 'fstab': ['fstab', 'mtab'],
|
||||||
\ 'func': ['file.fc'],
|
\ 'func': ['file.fc'],
|
||||||
\ 'fusion': ['file.fusion'],
|
\ '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'],
|
\ 'gdb': ['.gdbinit', 'gdbinit', '.cuda-gdbinit', 'cuda-gdbinit', 'file.gdb', '.config/gdbearlyinit', '.gdbearlyinit'],
|
||||||
\ 'gdmo': ['file.mo', 'file.gdmo'],
|
\ 'gdmo': ['file.mo', 'file.gdmo'],
|
||||||
\ 'gdresource': ['file.tscn', 'file.tres'],
|
\ 'gdresource': ['file.tscn', 'file.tres'],
|
||||||
@@ -463,7 +469,7 @@ func s:GetFilenameChecks() abort
|
|||||||
\ 'any/m17n-db/file.ali', 'any/m17n-db/file.cs', 'any/m17n-db/file.dir', 'any/m17n-db/FLT/file.flt', 'any/m17n-db/file.fst', 'any/m17n-db/LANGDATA/file.lnm', 'any/m17n-db/file.mic', 'any/m17n-db/MIM/file.mim', 'any/m17n-db/file.tbl'],
|
\ 'any/m17n-db/file.ali', 'any/m17n-db/file.cs', 'any/m17n-db/file.dir', 'any/m17n-db/FLT/file.flt', 'any/m17n-db/file.fst', 'any/m17n-db/LANGDATA/file.lnm', 'any/m17n-db/file.mic', 'any/m17n-db/MIM/file.mim', 'any/m17n-db/file.tbl'],
|
||||||
\ 'm3build': ['m3makefile', 'm3overrides'],
|
\ 'm3build': ['m3makefile', 'm3overrides'],
|
||||||
\ 'm3quake': ['file.quake', 'cm3.cfg'],
|
\ 'm3quake': ['file.quake', 'cm3.cfg'],
|
||||||
\ 'm4': ['file.at', '.m4_history'],
|
\ 'm4': ['.m4_history'],
|
||||||
\ 'mail': ['snd.123', '.letter', '.letter.123', '.followup', '.article', '.article.123', 'pico.123', 'mutt-xx-xxx', 'muttng-xx-xxx', 'ae123.txt', 'file.eml', 'reportbug-file'],
|
\ 'mail': ['snd.123', '.letter', '.letter.123', '.followup', '.article', '.article.123', 'pico.123', 'mutt-xx-xxx', 'muttng-xx-xxx', 'ae123.txt', 'file.eml', 'reportbug-file'],
|
||||||
\ 'mailaliases': ['/etc/mail/aliases', '/etc/aliases', 'any/etc/aliases', 'any/etc/mail/aliases'],
|
\ 'mailaliases': ['/etc/mail/aliases', '/etc/aliases', 'any/etc/aliases', 'any/etc/mail/aliases'],
|
||||||
\ 'mailcap': ['.mailcap', 'mailcap'],
|
\ 'mailcap': ['.mailcap', 'mailcap'],
|
||||||
@@ -1146,6 +1152,43 @@ endfunc
|
|||||||
" Keep sorted.
|
" Keep sorted.
|
||||||
"""""""""""""""""""""""""""""""""""""""""""""""""
|
"""""""""""""""""""""""""""""""""""""""""""""""""
|
||||||
|
|
||||||
|
" Since dist#ft#FTm4() looks around for configure.ac
|
||||||
|
" the test needs to isolate itself in a fresh temporary project tree,
|
||||||
|
" so that no configure.ac from another test (or from the repo root)
|
||||||
|
" accidentally influences detection.
|
||||||
|
func Test_autoconf_file()
|
||||||
|
filetype on
|
||||||
|
" Make a fresh sandbox far away from any configure.ac
|
||||||
|
let save_cwd = getcwd()
|
||||||
|
call mkdir('Xproj_autoconf/a/b', 'p')
|
||||||
|
execute 'lcd Xproj_autoconf/a/b'
|
||||||
|
|
||||||
|
try
|
||||||
|
call writefile(['AC_CHECK_HEADERS([stdio.h])'], 'foo.m4', 'D')
|
||||||
|
split foo.m4
|
||||||
|
call assert_equal('config', &filetype)
|
||||||
|
bwipe!
|
||||||
|
|
||||||
|
call writefile(['AS_IF([true], [:])'], 'bar.m4', 'D')
|
||||||
|
split bar.m4
|
||||||
|
call assert_equal('config', &filetype)
|
||||||
|
bwipe!
|
||||||
|
|
||||||
|
call writefile(['AC_INIT([foo],[1.0])'], 'configure.ac')
|
||||||
|
call mkdir('m4', 'p')
|
||||||
|
call writefile([], 'm4/empty.m4', 'D')
|
||||||
|
split m4/empty.m4
|
||||||
|
call assert_equal('config', &filetype)
|
||||||
|
bwipe!
|
||||||
|
finally
|
||||||
|
call delete('m4', 'rf')
|
||||||
|
call delete('configure.ac')
|
||||||
|
execute 'lcd' fnameescape(save_cwd)
|
||||||
|
call delete('Xproj_autoconf', 'rf')
|
||||||
|
filetype off
|
||||||
|
endtry
|
||||||
|
endfunc
|
||||||
|
|
||||||
func Test_bas_file()
|
func Test_bas_file()
|
||||||
filetype on
|
filetype on
|
||||||
|
|
||||||
@@ -1891,6 +1934,30 @@ func Test_m_file()
|
|||||||
filetype off
|
filetype off
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
|
" Since dist#ft#FTm4() looks around for configure.ac
|
||||||
|
" the test needs to isolate itself in a fresh temporary project tree,
|
||||||
|
" so that no configure.ac from another test (or from the repo root)
|
||||||
|
" accidentally influences detection.
|
||||||
|
func Test_m4_file()
|
||||||
|
filetype on
|
||||||
|
let save_cwd = getcwd()
|
||||||
|
|
||||||
|
" Make a fresh sandbox far away from any configure.ac
|
||||||
|
call mkdir('Xsandbox/level1/level2', 'p')
|
||||||
|
execute 'lcd Xsandbox/level1/level2'
|
||||||
|
|
||||||
|
try
|
||||||
|
call writefile(["define(`FOO', `bar')", "FOO"], 'plain.m4', 'D')
|
||||||
|
split plain.m4
|
||||||
|
call assert_equal('m4', &filetype)
|
||||||
|
bwipe!
|
||||||
|
finally
|
||||||
|
execute 'lcd' fnameescape(save_cwd)
|
||||||
|
call delete('Xsandbox', 'rf')
|
||||||
|
filetype off
|
||||||
|
endtry
|
||||||
|
endfunc
|
||||||
|
|
||||||
func Test_mod_file()
|
func Test_mod_file()
|
||||||
filetype on
|
filetype on
|
||||||
|
|
||||||
@@ -3047,4 +3114,23 @@ func Test_diff_format()
|
|||||||
filetype off
|
filetype off
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
|
func Test_m4_format()
|
||||||
|
filetype on
|
||||||
|
|
||||||
|
call mkdir('Xm4', 'D')
|
||||||
|
cd Xm4
|
||||||
|
call writefile([''], 'alocal.m4', 'D')
|
||||||
|
split alocal.m4
|
||||||
|
call assert_equal('m4', &filetype)
|
||||||
|
bwipe!
|
||||||
|
" an accompanying configure.ac in the current directory changes the filetype
|
||||||
|
call writefile([''], 'configure.ac')
|
||||||
|
split alocal.m4
|
||||||
|
call assert_equal('config', &filetype)
|
||||||
|
bwipe!
|
||||||
|
|
||||||
|
cd -
|
||||||
|
filetype off
|
||||||
|
endfunc
|
||||||
|
|
||||||
" vim: shiftwidth=2 sts=2 expandtab
|
" vim: shiftwidth=2 sts=2 expandtab
|
||||||
|
Reference in New Issue
Block a user