From 79148813567909aae8bc733e585d7713f6069401 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 31 Aug 2023 07:44:33 +0800 Subject: vim-patch:9.0.1797: Vimball/Visual Basic filetype detection conflict (#24947) Problem: Vimball/Visual Basic filetype detection conflict Solution: runtime(vb): Improve Vimball and Visual Basic detection logic Only run Vimball Archiver's BufEnter autocommand on Vimball archives. Fixes vim/vim#2694. closes: vim/vim#12899 https://github.com/vim/vim/commit/f97f6bbf56408c0c97b4ddbe81fba858d7455b0d Co-authored-by: Doug Kearns --- runtime/lua/vim/filetype.lua | 12 ++++++++---- runtime/lua/vim/filetype/detect.lua | 31 +++++++++++++++++++++---------- 2 files changed, 29 insertions(+), 14 deletions(-) (limited to 'runtime') diff --git a/runtime/lua/vim/filetype.lua b/runtime/lua/vim/filetype.lua index 35a10b6bdc..0e8ecf1b07 100644 --- a/runtime/lua/vim/filetype.lua +++ b/runtime/lua/vim/filetype.lua @@ -351,6 +351,7 @@ local extension = { bat = 'dosbatch', wrap = 'dosini', ini = 'dosini', + vbp = 'dosini', dot = 'dot', gv = 'dot', drac = 'dracula', @@ -1025,13 +1026,18 @@ local extension = { url = 'urlshortcut', usd = 'usd', usda = 'usd', + v = detect.v, vsh = 'v', vv = 'v', + ctl = 'vb', + dob = 'vb', + dsm = 'vb', + dsr = 'vb', + pag = 'vb', sba = 'vb', vb = 'vb', - dsm = 'vb', - ctl = 'vb', vbs = 'vb', + vba = detect.vba, vdf = 'vdf', vdmpp = 'vdmpp', vpp = 'vdmpp', @@ -1041,7 +1047,6 @@ local extension = { vr = 'vera', vri = 'vera', vrh = 'vera', - v = detect.v, va = 'verilogams', vams = 'verilogams', vhdl = 'vhdl', @@ -1052,7 +1057,6 @@ local extension = { vbe = 'vhdl', tape = 'vhs', vim = 'vim', - vba = 'vim', mar = 'vmasm', cm = 'voscm', wrl = 'vrml', diff --git a/runtime/lua/vim/filetype/detect.lua b/runtime/lua/vim/filetype/detect.lua index af6d77ecbf..0609ac5513 100644 --- a/runtime/lua/vim/filetype/detect.lua +++ b/runtime/lua/vim/filetype/detect.lua @@ -77,7 +77,7 @@ function M.asm_syntax(_, bufnr) end local visual_basic_content = - { 'vb_name', 'begin vb%.form', 'begin vb%.mdiform', 'begin vb%.usercontrol' } + [[\c^\s*\%(Attribute\s\+VB_Name\|Begin\s\+\%(VB\.\|{\%(\x\+-\)\+\x\+}\)\)]] -- See frm() for Visual Basic form file detection --- @type vim.filetype.mapfn @@ -97,7 +97,7 @@ function M.bas(_, bufnr) local qb64_preproc = [[\c^\s*\%($\a\+\|option\s\+\%(_explicit\|_\=explicitarray\)\>\)]] for _, line in ipairs(getlines(bufnr, 1, 100)) do - if findany(line:lower(), visual_basic_content) then + if matchregex(line, visual_basic_content) then return 'vb' elseif line:find(fb_comment) @@ -193,12 +193,12 @@ function M.cls(_, bufnr) if vim.g.filetype_cls then return vim.g.filetype_cls end - local line = getline(bufnr, 1) - if line:find('^[%%\\]') then + local line1 = getline(bufnr, 1) + if line1:find('^[%%\\]') then return 'tex' - elseif line:find('^#') and line:lower():find('rexx') then + elseif line1:find('^#') and line1:lower():find('rexx') then return 'rexx' - elseif line == 'VERSION 1.0 CLASS' then + elseif line1 == 'VERSION 1.0 CLASS' then return 'vb' end return 'st' @@ -525,12 +525,15 @@ function M.frm(_, bufnr) if vim.g.filetype_frm then return vim.g.filetype_frm end - local lines = table.concat(getlines(bufnr, 1, 5)):lower() - if findany(lines, visual_basic_content) then + if getline(bufnr, 1) == 'VERSION 5.00' then return 'vb' - else - return 'form' end + for _, line in ipairs(getlines(bufnr, 1, 5)) do + if matchregex(line, visual_basic_content) then + return 'vb' + end + end + return 'form' end --- @type vim.filetype.mapfn @@ -1529,6 +1532,14 @@ function M.v(_, bufnr) return 'v' end +--- @type vim.filetype.mapfn +function M.vba(_, bufnr) + if getline(bufnr, 1):find('^["#] Vimball Archiver') then + return 'vim' + end + return 'vb' +end + -- WEB (*.web is also used for Winbatch: Guess, based on expecting "%" comment -- lines in a WEB file). --- @type vim.filetype.mapfn -- cgit