vim-patch:10b4f75d4c03 (#26846)

runtime(dist/ft): improve filetype detection for *.v (V/Verilog/Coq)

Patch provided by Dan Alt

closes: vim/vim#13793

10b4f75d4c

Co-authored-by: Christian Brabandt <cb@256bit.org>
This commit is contained in:
zeertzjq 2024-01-02 19:06:43 +08:00 committed by GitHub
parent e98bef259a
commit 2bf68df289
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 4 deletions

View File

@ -167,6 +167,7 @@ variables can be used to overrule the filetype used for certain extensions:
`*.sh` g:bash_is_sh |ft-sh-syntax| `*.sh` g:bash_is_sh |ft-sh-syntax|
`*.tex` g:tex_flavor |ft-tex-plugin| `*.tex` g:tex_flavor |ft-tex-plugin|
`*.typ` g:filetype_typ `*.typ` g:filetype_typ
`*.v` g:filetype_v
`*.w` g:filetype_w |ft-cweb-syntax| `*.w` g:filetype_w |ft-cweb-syntax|
For a few filetypes the global variable is used only when the filetype could For a few filetypes the global variable is used only when the filetype could

View File

@ -1530,12 +1530,26 @@ function M.v(_, bufnr)
-- Filetype was already detected -- Filetype was already detected
return return
end end
if vim.g.filetype_v then
return vim.g.filetype_v
end
local in_comment = 0
for _, line in ipairs(getlines(bufnr, 1, 200)) do for _, line in ipairs(getlines(bufnr, 1, 200)) do
if not line:find('^%s*/') then if line:find('^%s*/%*') then
if findany(line, { ';%s*$', ';%s*/' }) then in_comment = 1
return 'verilog' end
elseif findany(line, { '%.%s*$', '%.%s*%(%*' }) then if in_comment == 1 then
if line:find('%*/') then
in_comment = 0
end
elseif not line:find('^%s*//') then
if
line:find('%.%s*$') and not line:find('/[/*]')
or line:find('%(%*') and not line:find('/[/*].*%(%*')
then
return 'coq' return 'coq'
elseif findany(line, { ';%s*$', ';%s*/[/*]' }) then
return 'verilog'
end end
end end
end end