mirror of
https://github.com/neovim/neovim.git
synced 2026-04-25 00:35:36 +00:00
vim-patch:9.1.1327: filetype: nroff detection can be improved
Problem: filetype: nroff detection can be improved
Solution: improve nroff detection (Eisuke Kawashima)
- explicitly check roff comments and macros typically found in manpages
- do not try to detect alphabetically-sectioned files, except for n, as
nroff
- l: > 'l' happens to be a section for historical reasons
<https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=391977>
- n: e.g. /usr/share/man/mann/Tcl.n.gz
- o: unsure (perhaps fedora-specific)
- p: unsure (perhaps fedora-specific)
closes: vim/vim#17160
2cb42efc18
Co-authored-by: Eisuke Kawashima <e-kwsm@users.noreply.github.com>
This commit is contained in:
@@ -696,7 +696,7 @@ local extension = {
|
|||||||
lex = 'lex',
|
lex = 'lex',
|
||||||
lxx = 'lex',
|
lxx = 'lex',
|
||||||
['l++'] = 'lex',
|
['l++'] = 'lex',
|
||||||
l = detect_seq('lex', detect.nroff),
|
l = 'lex',
|
||||||
lhs = 'lhaskell',
|
lhs = 'lhaskell',
|
||||||
lidr = 'lidris2',
|
lidr = 'lidris2',
|
||||||
ly = 'lilypond',
|
ly = 'lilypond',
|
||||||
@@ -862,7 +862,6 @@ local extension = {
|
|||||||
['3posix'] = detect.nroff,
|
['3posix'] = detect.nroff,
|
||||||
['3type'] = detect.nroff,
|
['3type'] = detect.nroff,
|
||||||
n = detect.nroff,
|
n = detect.nroff,
|
||||||
o = detect.nroff,
|
|
||||||
roff = 'nroff',
|
roff = 'nroff',
|
||||||
tmac = 'nroff',
|
tmac = 'nroff',
|
||||||
man = 'nroff',
|
man = 'nroff',
|
||||||
@@ -1409,7 +1408,7 @@ local extension = {
|
|||||||
pp = detect.pp,
|
pp = detect.pp,
|
||||||
i = detect.i,
|
i = detect.i,
|
||||||
w = detect.progress_cweb,
|
w = detect.progress_cweb,
|
||||||
p = detect_seq(detect.nroff, detect.progress_pascal),
|
p = detect.progress_pascal,
|
||||||
pro = detect_seq(detect.proto, 'idlang'),
|
pro = detect_seq(detect.proto, 'idlang'),
|
||||||
patch = detect.patch,
|
patch = detect.patch,
|
||||||
r = detect.r,
|
r = detect.r,
|
||||||
|
|||||||
@@ -1170,12 +1170,17 @@ function M.news(_, bufnr)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
--- This function checks if one of the first five lines start with a dot. In
|
--- This function checks if one of the first five lines start with a typical
|
||||||
--- that case it is probably an nroff file.
|
--- nroff pattern in man files. In that case it is probably an nroff file.
|
||||||
--- @type vim.filetype.mapfn
|
--- @type vim.filetype.mapfn
|
||||||
function M.nroff(_, bufnr)
|
function M.nroff(_, bufnr)
|
||||||
for _, line in ipairs(getlines(bufnr, 1, 5)) do
|
for _, line in ipairs(getlines(bufnr, 1, 5)) do
|
||||||
if line:find('^%.%S%S?') then
|
if
|
||||||
|
matchregex(
|
||||||
|
line,
|
||||||
|
[[^\%([.']\s*\%(TH\|D[dt]\|S[Hh]\|d[es]1\?\|so\)\s\+\S\|[.'']\s*ig\>\|\%([.'']\s*\)\?\\"\)]]
|
||||||
|
)
|
||||||
|
then
|
||||||
return 'nroff'
|
return 'nroff'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -2921,11 +2921,21 @@ endfunc
|
|||||||
func Test_nroff_file()
|
func Test_nroff_file()
|
||||||
filetype on
|
filetype on
|
||||||
|
|
||||||
call writefile(['.TH vim 1 "YYYY Mth DD"'], 'Xfile.1', 'D')
|
call writefile(['.TH VIM 1 "YYYY Mth DD"'], 'Xfile.1', 'D')
|
||||||
split Xfile.1
|
split Xfile.1
|
||||||
call assert_equal('nroff', &filetype)
|
call assert_equal('nroff', &filetype)
|
||||||
bwipe!
|
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')
|
call writefile(['. /etc/profile'], 'Xfile.1', 'D')
|
||||||
split Xfile.1
|
split Xfile.1
|
||||||
call assert_notequal('nroff', &filetype)
|
call assert_notequal('nroff', &filetype)
|
||||||
|
|||||||
Reference in New Issue
Block a user