Merge pull request #33561 from zeertzjq/vim-9.1.1304

vim-patch:9.1.{1304,1327}: filetype: some man files are not recognized
This commit is contained in:
zeertzjq
2025-04-21 19:09:29 +08:00
committed by GitHub
3 changed files with 50 additions and 3 deletions

View File

@@ -835,6 +835,7 @@ local extension = {
nix = 'nix',
norg = 'norg',
nqc = 'nqc',
['0'] = detect.nroff,
['1'] = detect.nroff,
['2'] = detect.nroff,
['3'] = detect.nroff,
@@ -844,6 +845,23 @@ local extension = {
['7'] = detect.nroff,
['8'] = detect.nroff,
['9'] = detect.nroff,
['0p'] = detect.nroff,
['1p'] = detect.nroff,
['3p'] = detect.nroff,
['1x'] = detect.nroff,
['2x'] = detect.nroff,
['3x'] = detect.nroff,
['4x'] = detect.nroff,
['5x'] = detect.nroff,
['6x'] = detect.nroff,
['7x'] = detect.nroff,
['8x'] = detect.nroff,
['3am'] = detect.nroff,
['3perl'] = detect.nroff,
['3pm'] = detect.nroff,
['3posix'] = detect.nroff,
['3type'] = detect.nroff,
n = detect.nroff,
roff = 'nroff',
tmac = 'nroff',
man = 'nroff',

View File

@@ -1170,12 +1170,17 @@ function M.news(_, bufnr)
end
end
--- This function checks if one of the first five lines start with a dot. In
--- that case it is probably an nroff file.
--- This function checks if one of the first five lines start with a typical
--- nroff pattern in man files. In that case it is probably an nroff file.
--- @type vim.filetype.mapfn
function M.nroff(_, bufnr)
for _, line in ipairs(getlines(bufnr, 1, 5)) do
if line:find('^%.') then
if
matchregex(
line,
[[^\%([.']\s*\%(TH\|D[dt]\|S[Hh]\|d[es]1\?\|so\)\s\+\S\|[.'']\s*ig\>\|\%([.'']\s*\)\?\\"\)]]
)
then
return 'nroff'
end
end

View File

@@ -2918,6 +2918,30 @@ func Test_map_file()
filetype off
endfunc
func Test_nroff_file()
filetype on
call writefile(['.TH VIM 1 "YYYY Mth DD"'], 'Xfile.1', 'D')
split Xfile.1
call assert_equal('nroff', &filetype)
bwipe!
call writefile(['.Dd $Mdocdate$', '.Dt "DETECTION TEST" "7"', '.Os'], 'Xfile.7', 'D')
split Xfile.7
call assert_equal('nroff', &filetype)
bwipe!
call writefile(['''\" t'], 'Xfile.3p', 'D')
split Xfile.3p
call assert_equal('nroff', &filetype)
bwipe!
call writefile(['. /etc/profile'], 'Xfile.1', 'D')
split Xfile.1
call assert_notequal('nroff', &filetype)
bwipe!
endfunc
func Test_org_file()
filetype on