neovim

Neovim text editor
git clone https://git.dasho.dev/neovim.git
Log | Files | Refs | README

commit 8051092414a2403685916cdf5c442d146ab2c117
parent 1437144740925fc8e594d21172b54d2b00acd035
Author: zeertzjq <zeertzjq@outlook.com>
Date:   Mon, 21 Apr 2025 19:09:29 +0800

Merge pull request #33561 from zeertzjq/vim-9.1.1304

vim-patch:9.1.{1304,1327}: filetype: some man files are not recognized
Diffstat:
Mruntime/lua/vim/filetype.lua | 18++++++++++++++++++
Mruntime/lua/vim/filetype/detect.lua | 11++++++++---
Mtest/old/testdir/test_filetype.vim | 24++++++++++++++++++++++++
3 files changed, 50 insertions(+), 3 deletions(-)

diff --git a/runtime/lua/vim/filetype.lua b/runtime/lua/vim/filetype.lua @@ -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', diff --git a/runtime/lua/vim/filetype/detect.lua b/runtime/lua/vim/filetype/detect.lua @@ -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 diff --git a/test/old/testdir/test_filetype.vim b/test/old/testdir/test_filetype.vim @@ -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