vim-patch:9.0.1478: filetypes for *.v files not detected properly (#23282)

* vim-patch:9.0.1478: filetypes for *.v files not detected properly

Problem:    Filetypes for *.v files not detected properly.
Solution:   Use the file contents to detect the filetype. (Turiiya,
            closes vim/vim#12281)

80406c2618

Co-authored-by: Turiiya <34311583+tobealive@users.noreply.github.com>
Co-authored-by: Jonas Strittmatter <40792180+smjonas@users.noreply.github.com>
This commit is contained in:
Christian Clason
2023-04-23 14:15:52 +02:00
committed by GitHub
parent bf0ac4f241
commit f17bb4f411
3 changed files with 42 additions and 2 deletions

View File

@@ -1091,7 +1091,9 @@ local extension = {
vr = 'vera',
vri = 'vera',
vrh = 'vera',
v = 'verilog',
v = function(path, bufnr)
return require('vim.filetype.detect').v(bufnr)
end,
va = 'verilogams',
vams = 'verilogams',
vhdl = 'vhdl',

View File

@@ -1322,6 +1322,24 @@ function M.txt(bufnr)
end
end
-- Determine if a .v file is Verilog, V, or Coq
function M.v(bufnr)
if vim.fn.did_filetype() ~= 0 then
-- Filetype was already detected
return
end
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
return 'coq'
end
end
end
return 'v'
end
-- WEB (*.web is also used for Winbatch: Guess, based on expecting "%" comment
-- lines in a WEB file).
function M.web(bufnr)