0
0
mirror of https://github.com/vim/vim.git synced 2025-07-04 23:07:33 -04:00

patch 9.0.1797: Vimball/Visual Basic filetype detection conflict

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 #2694.

closes: #12899

Signed-off-by: Christian Brabandt <cb@256bit.org>
Co-authored-by: Doug Kearns <dougkearns@gmail.com>
This commit is contained in:
Doug Kearns 2023-08-27 18:44:09 +02:00 committed by Christian Brabandt
parent 5c018bee0e
commit f97f6bbf56
No known key found for this signature in database
GPG Key ID: F3F92DA383FDDE09
5 changed files with 81 additions and 16 deletions

View File

@ -62,7 +62,7 @@ export def FTasmsyntax()
endif
enddef
var ft_visual_basic_content = '\cVB_Name\|Begin VB\.\(Form\|MDIForm\|UserControl\)'
var ft_visual_basic_content = '\c^\s*\%(Attribute\s\+VB_Name\|Begin\s\+\%(VB\.\|{\%(\x\+-\)\+\x\+}\)\)'
# See FTfrm() for Visual Basic form file detection
export def FTbas()
@ -146,11 +146,13 @@ export def FTcls()
return
endif
if getline(1) =~ '^\v%(\%|\\)'
var line1 = getline(1)
if line1 =~ '^\v%(\%|\\)'
setf tex
elseif getline(1)[0] == '#' && getline(1) =~ 'rexx'
elseif line1[0] == '#' && line1 =~ 'rexx'
setf rexx
elseif getline(1) == 'VERSION 1.0 CLASS'
elseif line1 == 'VERSION 1.0 CLASS'
setf vb
else
setf st
@ -324,6 +326,11 @@ export def FTfrm()
return
endif
if getline(1) == "VERSION 5.00"
setf vb
return
endif
var lines = getline(1, min([line("$"), 5]))
if match(lines, ft_visual_basic_content) > -1
@ -1197,5 +1204,13 @@ export def FTv()
setf v
enddef
export def FTvba()
if getline(1) =~ '^["#] Vimball Archiver'
setf vim
else
setf vb
endif
enddef
# Uncomment this line to check for compilation errors early
# defcompile

View File

@ -209,9 +209,6 @@ au BufNewFile,BufRead *.bi,*.bm call dist#ft#FTbas()
" Bass
au BufNewFile,BufRead *.bass setf bass
" Visual Basic Script (close to Visual Basic) or Visual Basic .NET
au BufNewFile,BufRead *.vb,*.vbs,*.dsm,*.ctl setf vb
" IBasic file (similar to QBasic)
au BufNewFile,BufRead *.iba,*.ibi setf ibasic
@ -2376,7 +2373,7 @@ au BufNewFile,BufRead *.tape setf vhs
au BufNewFile,BufRead *.hdl,*.vhd,*.vhdl,*.vbe,*.vst,*.vho setf vhdl
" Vim script
au BufNewFile,BufRead *.vim,*.vba,.exrc,_exrc setf vim
au BufNewFile,BufRead *.vim,.exrc,_exrc setf vim
" Viminfo file
au BufNewFile,BufRead .viminfo,_viminfo setf viminfo
@ -2389,10 +2386,31 @@ au BufRead,BufNewFile *.hw,*.module,*.pkg
\ setf virata |
\ endif
" Visual Basic (also uses *.bas) or FORM
" Visual Basic (see also *.bas *.cls)
" Visual Basic or FORM
au BufNewFile,BufRead *.frm call dist#ft#FTfrm()
" SaxBasic is close to Visual Basic
" Visual Basic
" user control, ActiveX document form, active designer, property page
au BufNewFile,BufRead *.ctl,*.dob,*.dsr,*.pag setf vb
" Visual Basic or Vimball Archiver
au BufNewFile,BufRead *.vba call dist#ft#FTvba()
" Visual Basic Project
au BufNewFile,BufRead *.vbp setf dosini
" VBScript (close to Visual Basic)
au BufNewFile,BufRead *.vbs setf vb
" Visual Basic .NET (close to Visual Basic)
au BufNewFile,BufRead *.vb setf vb
" Visual Studio Macro
au BufNewFile,BufRead *.dsm setf vb
" SaxBasic (close to Visual Basic)
au BufNewFile,BufRead *.sba setf vb
" Vgrindefs file

View File

@ -28,10 +28,16 @@ com! -nargs=0 VimballList call vimball#Vimball(0)
com! -nargs=* -complete=dir RmVimball call vimball#SaveSettings()|call vimball#RmVimball(<f-args>)|call vimball#RestoreSettings()
augroup Vimball
au!
au BufEnter *.vba,*.vba.gz,*.vba.bz2,*.vba.zip,*.vba.xz setlocal bt=nofile fmr=[[[,]]] fdm=marker|if &ff != 'unix'|setlocal ma ff=unix noma|endif|if line('$') > 1|call vimball#ShowMesg(0,"Source this file to extract it! (:so %)")|endif
au BufEnter *.vba,*.vba.gz,*.vba.bz2,*.vba.zip,*.vba.xz
\ if getline(1) =~ '^" Vimball Archiver' |
\ setlocal bt=nofile fmr=[[[,]]] fdm=marker|if &ff != 'unix'|setlocal ma ff=unix noma|endif|if line('$') > 1|call vimball#ShowMesg(0, "Source this file to extract it! (:so %)")|endif |
\ endif
au SourceCmd *.vba.gz,*.vba.bz2,*.vba.zip,*.vba.xz let s:origfile=expand("%")|if expand("%")!=expand("<afile>") | exe "1sp" fnameescape(expand("<afile>"))|endif|call vimball#Decompress(expand("<amatch>"))|so %|if s:origfile!=expand("<afile>")|close|endif
au SourceCmd *.vba if expand("%")!=expand("<afile>") | exe "1sp" fnameescape(expand("<afile>"))|call vimball#Vimball(1)|close|else|call vimball#Vimball(1)|endif
au BufEnter *.vmb,*.vmb.gz,*.vmb.bz2,*.vmb.zip,*.vmb.xz setlocal bt=nofile fmr=[[[,]]] fdm=marker|if &ff != 'unix'|setlocal ma ff=unix noma|endif|if line('$') > 1|call vimball#ShowMesg(0,"Source this file to extract it! (:so %)")|endif
au BufEnter *.vmb,*.vmb.gz,*.vmb.bz2,*.vmb.zip,*.vmb.xz
\ if getline(1) =~ '^" Vimball Archiver' |
\ setlocal bt=nofile fmr=[[[,]]] fdm=marker|if &ff != 'unix'|setlocal ma ff=unix noma|endif|if line('$') > 1|call vimball#ShowMesg(0,"Source this file to extract it! (:so %)")|endif |
\ endif
au SourceCmd *.vmb.gz,*.vmb.bz2,*.vmb.zip,*.vmb.xz let s:origfile=expand("%")|if expand("%")!=expand("<afile>") | exe "1sp" fnameescape(expand("<afile>"))|endif|call vimball#Decompress(expand("<amatch>"))|so %|if s:origfile!=expand("<afile>")|close|endif
au SourceCmd *.vmb if expand("%")!=expand("<afile>") | exe "1sp" fnameescape(expand("<afile>"))|call vimball#Vimball(1)|close|else|call vimball#Vimball(1)|endif
augroup END
@ -41,3 +47,5 @@ augroup END
" vim: fdm=marker
let &cpo= s:keepcpo
unlet s:keepcpo
" vim: ts=4:

View File

@ -205,7 +205,7 @@ def s:GetFilenameChecks(): dict<list<string>>
dnsmasq: ['/etc/dnsmasq.conf', '/etc/dnsmasq.d/file', 'any/etc/dnsmasq.conf', 'any/etc/dnsmasq.d/file'],
dockerfile: ['Containerfile', 'Dockerfile', 'dockerfile', 'file.Dockerfile', 'file.dockerfile', 'Dockerfile.debian', 'Containerfile.something'],
dosbatch: ['file.bat'],
dosini: ['/etc/yum.conf', 'file.ini', 'npmrc', '.npmrc', 'php.ini', 'php.ini-5', 'php.ini-file', '/etc/yum.repos.d/file', 'any/etc/yum.conf', 'any/etc/yum.repos.d/file', 'file.wrap'],
dosini: ['/etc/yum.conf', 'file.ini', 'npmrc', '.npmrc', 'php.ini', 'php.ini-5', 'php.ini-file', '/etc/yum.repos.d/file', 'any/etc/yum.conf', 'any/etc/yum.repos.d/file', 'file.wrap', 'file.vbp'],
dot: ['file.dot', 'file.gv'],
dracula: ['file.drac', 'file.drc', 'filelvs', 'filelpe', 'drac.file', 'lpe', 'lvs', 'some-lpe', 'some-lvs'],
dtd: ['file.dtd'],
@ -759,7 +759,7 @@ def s:GetFilenameChecks(): dict<list<string>>
usw2kagtlog: ['usw2kagt.log', 'USW2KAGT.LOG', 'usw2kagt.file.log', 'USW2KAGT.FILE.LOG', 'file.usw2kagt.log', 'FILE.USW2KAGT.LOG'],
v: ['file.vsh', 'file.vv'],
vala: ['file.vala'],
vb: ['file.sba', 'file.vb', 'file.vbs', 'file.dsm', 'file.ctl'],
vb: ['file.sba', 'file.vb', 'file.vbs', 'file.dsm', 'file.ctl', 'file.dob', 'file.dsr'],
vdf: ['file.vdf'],
vdmpp: ['file.vpp', 'file.vdmpp'],
vdmrt: ['file.vdmrt'],
@ -769,7 +769,7 @@ def s:GetFilenameChecks(): dict<list<string>>
vgrindefs: ['vgrindefs'],
vhdl: ['file.hdl', 'file.vhd', 'file.vhdl', 'file.vbe', 'file.vst', 'file.vhdl_123', 'file.vho', 'some.vhdl_1', 'some.vhdl_1-file'],
vhs: ['file.tape'],
vim: ['file.vim', 'file.vba', '.exrc', '_exrc', 'some-vimrc', 'some-vimrc-file', 'vimrc', 'vimrc-file'],
vim: ['file.vim', '.exrc', '_exrc', 'some-vimrc', 'some-vimrc-file', 'vimrc', 'vimrc-file'],
viminfo: ['.viminfo', '_viminfo'],
vmasm: ['file.mar'],
voscm: ['file.cm'],
@ -1379,7 +1379,7 @@ func Test_frm_file()
" Visual Basic
call writefile(['Begin VB.Form Form1'], 'Xfile.frm')
call writefile(['VERSION 5.00', 'Begin VB.Form Form1'], 'Xfile.frm')
split Xfile.frm
call assert_equal('vb', &filetype)
bwipe!
@ -2288,4 +2288,26 @@ func Test_typ_file()
filetype off
endfunc
func Test_vba_file()
filetype on
" Test dist#ft#FTvba()
" Visual Basic
call writefile(['looks like Visual Basic'], 'Xfile.vba', 'D')
split Xfile.vba
call assert_equal('vb', &filetype)
bwipe!
" Vimball Archiver (ft=vim)
call writefile(['" Vimball Archiver by Charles E. Campbell, Ph.D.', 'UseVimball', 'finish'], 'Xfile.vba', 'D')
split Xfile.vba
call assert_equal('vim', &filetype)
bwipe!
filetype off
endfunc
" vim: shiftwidth=2 sts=2 expandtab

View File

@ -699,6 +699,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
1797,
/**/
1796,
/**/