From 2bf68df289de12510d472f362482e5bde253cb41 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Tue, 2 Jan 2024 19:06:43 +0800 Subject: 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 --- runtime/lua/vim/filetype/detect.lua | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) (limited to 'runtime/lua/vim') 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 -- cgit