diff options
Diffstat (limited to 'runtime/lua/vim')
-rw-r--r-- | runtime/lua/vim/filetype.lua | 4 | ||||
-rw-r--r-- | runtime/lua/vim/filetype/detect.lua | 18 |
2 files changed, 21 insertions, 1 deletions
diff --git a/runtime/lua/vim/filetype.lua b/runtime/lua/vim/filetype.lua index cbd9aa640b..4fafc4e2e2 100644 --- a/runtime/lua/vim/filetype.lua +++ b/runtime/lua/vim/filetype.lua @@ -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', diff --git a/runtime/lua/vim/filetype/detect.lua b/runtime/lua/vim/filetype/detect.lua index 94114ae7c3..74b01d569c 100644 --- a/runtime/lua/vim/filetype/detect.lua +++ b/runtime/lua/vim/filetype/detect.lua @@ -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) |