aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--runtime/doc/filetype.txt1
-rw-r--r--runtime/lua/vim/filetype/detect.lua22
2 files changed, 19 insertions, 4 deletions
diff --git a/runtime/doc/filetype.txt b/runtime/doc/filetype.txt
index 96cd0f8ab0..6c2cddea54 100644
--- a/runtime/doc/filetype.txt
+++ b/runtime/doc/filetype.txt
@@ -167,6 +167,7 @@ variables can be used to overrule the filetype used for certain extensions:
`*.sh` g:bash_is_sh |ft-sh-syntax|
`*.tex` g:tex_flavor |ft-tex-plugin|
`*.typ` g:filetype_typ
+ `*.v` g:filetype_v
`*.w` g:filetype_w |ft-cweb-syntax|
For a few filetypes the global variable is used only when the filetype could
diff --git a/runtime/lua/vim/filetype/detect.lua b/runtime/lua/vim/filetype/detect.lua
index a1c5ac73b4..6a14c73c92 100644
--- a/runtime/lua/vim/filetype/detect.lua
+++ b/runtime/lua/vim/filetype/detect.lua
@@ -1530,12 +1530,26 @@ function M.v(_, bufnr)
-- Filetype was already detected
return
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
- if not line:find('^%s*/') then
- if findany(line, { ';%s*$', ';%s*/' }) then
- return 'verilog'
- elseif findany(line, { '%.%s*$', '%.%s*%(%*' }) then
+ if line:find('^%s*/%*') then
+ in_comment = 1
+ end
+ 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'
+ elseif findany(line, { ';%s*$', ';%s*/[/*]' }) then
+ return 'verilog'
end
end
end