aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorzeertzjq <zeertzjq@outlook.com>2024-01-02 19:06:43 +0800
committerGitHub <noreply@github.com>2024-01-02 19:06:43 +0800
commit2bf68df289de12510d472f362482e5bde253cb41 (patch)
tree98224e3f267b124b59331accc929db95971395e0
parente98bef259abf876b90ba1f7885a36b94490e38a6 (diff)
downloadrneovim-2bf68df289de12510d472f362482e5bde253cb41.tar.gz
rneovim-2bf68df289de12510d472f362482e5bde253cb41.tar.bz2
rneovim-2bf68df289de12510d472f362482e5bde253cb41.zip
vim-patch:10b4f75d4c03 (#26846)
runtime(dist/ft): improve filetype detection for *.v (V/Verilog/Coq) Patch provided by Dan Alt closes: vim/vim#13793 https://github.com/vim/vim/commit/10b4f75d4c03c1cd4f579be5fdc812ba41b72fef Co-authored-by: Christian Brabandt <cb@256bit.org>
-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