patch 8.2.4172: filetype detection for BASIC is not optimal
Problem: Filetype detection for BASIC is not optimal. Solution: Improve BASIC filetype detection. (Doug Kearns)
This commit is contained in:
26
runtime/autoload/dist/ft.vim
vendored
26
runtime/autoload/dist/ft.vim
vendored
@ -67,13 +67,29 @@ func dist#ft#FTasmsyntax()
|
|||||||
endif
|
endif
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
" Check if one of the first five lines contains "VB_Name". In that case it is
|
func dist#ft#FTbas()
|
||||||
" probably a Visual Basic file. Otherwise it's assumed to be "alt" filetype.
|
if exists("g:filetype_bas")
|
||||||
func dist#ft#FTVB(alt)
|
exe "setf " . g:filetype_bas
|
||||||
if getline(1).getline(2).getline(3).getline(4).getline(5) =~? 'VB_Name\|Begin VB\.\(Form\|MDIForm\|UserControl\)'
|
return
|
||||||
|
endif
|
||||||
|
|
||||||
|
" most frequent FreeBASIC-specific keywords in distro files
|
||||||
|
let fb_keywords = '\c^\s*\%(extern\|var\|enum\|private\|scope\|union\|byref\|operator\|constructor\|delete\|namespace\|public\|property\|with\|destructor\|using\)\>\%(\s*[:=(]\)\@!'
|
||||||
|
let fb_preproc = '\c^\s*\%(#\a\+\|option\s\+\%(byval\|dynamic\|escape\|\%(no\)\=gosub\|nokeyword\|private\|static\)\>\)'
|
||||||
|
let fb_comment = "^\\s*/'"
|
||||||
|
" OPTION EXPLICIT, without the leading underscore, is common to many dialects
|
||||||
|
let qb64_preproc = '\c^\s*\%($\a\+\|option\s\+\%(_explicit\|_\=explicitarray\)\>\)'
|
||||||
|
|
||||||
|
let lines = getline(1, min([line("$"), 100]))
|
||||||
|
|
||||||
|
if match(lines, fb_preproc) > -1 || match(lines, fb_comment) > -1 || match(lines, fb_keywords) > -1
|
||||||
|
setf freebasic
|
||||||
|
elseif match(lines, qb64_preproc) > -1
|
||||||
|
setf qb64
|
||||||
|
elseif match(lines, '\cVB_Name\|Begin VB\.\(Form\|MDIForm\|UserControl\)') > -1
|
||||||
setf vb
|
setf vb
|
||||||
else
|
else
|
||||||
exe "setf " . a:alt
|
setf basic
|
||||||
endif
|
endif
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
|
|||||||
@ -193,7 +193,8 @@ au BufNewFile,BufRead *.awk,*.gawk setf awk
|
|||||||
au BufNewFile,BufRead *.mch,*.ref,*.imp setf b
|
au BufNewFile,BufRead *.mch,*.ref,*.imp setf b
|
||||||
|
|
||||||
" BASIC or Visual Basic
|
" BASIC or Visual Basic
|
||||||
au BufNewFile,BufRead *.bas call dist#ft#FTVB("basic")
|
au BufNewFile,BufRead *.bas call dist#ft#FTbas()
|
||||||
|
au BufNewFile,BufRead *.bi,*.bm call dist#ft#FTbas()
|
||||||
|
|
||||||
" Visual Basic Script (close to Visual Basic) or Visual Basic .NET
|
" Visual Basic Script (close to Visual Basic) or Visual Basic .NET
|
||||||
au BufNewFile,BufRead *.vb,*.vbs,*.dsm,*.ctl setf vb
|
au BufNewFile,BufRead *.vb,*.vbs,*.dsm,*.ctl setf vb
|
||||||
@ -202,7 +203,7 @@ au BufNewFile,BufRead *.vb,*.vbs,*.dsm,*.ctl setf vb
|
|||||||
au BufNewFile,BufRead *.iba,*.ibi setf ibasic
|
au BufNewFile,BufRead *.iba,*.ibi setf ibasic
|
||||||
|
|
||||||
" FreeBasic file (similar to QBasic)
|
" FreeBasic file (similar to QBasic)
|
||||||
au BufNewFile,BufRead *.fb,*.bi setf freebasic
|
au BufNewFile,BufRead *.fb setf freebasic
|
||||||
|
|
||||||
" Batch file for MSDOS.
|
" Batch file for MSDOS.
|
||||||
au BufNewFile,BufRead *.bat,*.sys setf dosbatch
|
au BufNewFile,BufRead *.bat,*.sys setf dosbatch
|
||||||
|
|||||||
@ -76,6 +76,7 @@ let s:filename_checks = {
|
|||||||
\ 'ave': ['file.ave'],
|
\ 'ave': ['file.ave'],
|
||||||
\ 'awk': ['file.awk', 'file.gawk'],
|
\ 'awk': ['file.awk', 'file.gawk'],
|
||||||
\ 'b': ['file.mch', 'file.ref', 'file.imp'],
|
\ 'b': ['file.mch', 'file.ref', 'file.imp'],
|
||||||
|
\ 'basic': ['file.bas', 'file.bi', 'file.bm'],
|
||||||
\ 'bzl': ['file.bazel', 'file.bzl', 'WORKSPACE'],
|
\ 'bzl': ['file.bazel', 'file.bzl', 'WORKSPACE'],
|
||||||
\ 'bc': ['file.bc'],
|
\ 'bc': ['file.bc'],
|
||||||
\ 'bdf': ['file.bdf'],
|
\ 'bdf': ['file.bdf'],
|
||||||
@ -186,7 +187,7 @@ let s:filename_checks = {
|
|||||||
\ 'fortran': ['file.f', 'file.for', 'file.fortran', 'file.fpp', 'file.ftn', 'file.f77', 'file.f90', 'file.f95', 'file.f03', 'file.f08'],
|
\ 'fortran': ['file.f', 'file.for', 'file.fortran', 'file.fpp', 'file.ftn', 'file.f77', 'file.f90', 'file.f95', 'file.f03', 'file.f08'],
|
||||||
\ 'fpcmake': ['file.fpc'],
|
\ 'fpcmake': ['file.fpc'],
|
||||||
\ 'framescript': ['file.fsl'],
|
\ 'framescript': ['file.fsl'],
|
||||||
\ 'freebasic': ['file.fb', 'file.bi'],
|
\ 'freebasic': ['file.fb'],
|
||||||
\ 'fsharp': ['file.fs', 'file.fsi', 'file.fsx'],
|
\ 'fsharp': ['file.fs', 'file.fsi', 'file.fsx'],
|
||||||
\ 'fstab': ['fstab', 'mtab'],
|
\ 'fstab': ['fstab', 'mtab'],
|
||||||
\ 'fvwm': ['/.fvwm/file', 'any/.fvwm/file'],
|
\ 'fvwm': ['/.fvwm/file', 'any/.fvwm/file'],
|
||||||
@ -1171,4 +1172,65 @@ func Test_foam_file()
|
|||||||
filetype off
|
filetype off
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
|
func Test_bas_file()
|
||||||
|
filetype on
|
||||||
|
|
||||||
|
call writefile(['looks like BASIC'], 'Xfile.bas')
|
||||||
|
split Xfile.bas
|
||||||
|
call assert_equal('basic', &filetype)
|
||||||
|
bwipe!
|
||||||
|
|
||||||
|
" Test dist#ft#FTbas()
|
||||||
|
|
||||||
|
let g:filetype_bas = 'freebasic'
|
||||||
|
split Xfile.bas
|
||||||
|
call assert_equal('freebasic', &filetype)
|
||||||
|
bwipe!
|
||||||
|
unlet g:filetype_bas
|
||||||
|
|
||||||
|
" FreeBASIC
|
||||||
|
|
||||||
|
call writefile(["/' FreeBASIC multiline comment '/"], 'Xfile.bas')
|
||||||
|
split Xfile.bas
|
||||||
|
call assert_equal('freebasic', &filetype)
|
||||||
|
bwipe!
|
||||||
|
|
||||||
|
call writefile(['#define TESTING'], 'Xfile.bas')
|
||||||
|
split Xfile.bas
|
||||||
|
call assert_equal('freebasic', &filetype)
|
||||||
|
bwipe!
|
||||||
|
|
||||||
|
call writefile(['option byval'], 'Xfile.bas')
|
||||||
|
split Xfile.bas
|
||||||
|
call assert_equal('freebasic', &filetype)
|
||||||
|
bwipe!
|
||||||
|
|
||||||
|
call writefile(['extern "C"'], 'Xfile.bas')
|
||||||
|
split Xfile.bas
|
||||||
|
call assert_equal('freebasic', &filetype)
|
||||||
|
bwipe!
|
||||||
|
|
||||||
|
" QB64
|
||||||
|
|
||||||
|
call writefile(['$LET TESTING = 1'], 'Xfile.bas')
|
||||||
|
split Xfile.bas
|
||||||
|
call assert_equal('qb64', &filetype)
|
||||||
|
bwipe!
|
||||||
|
|
||||||
|
call writefile(['OPTION _EXPLICIT'], 'Xfile.bas')
|
||||||
|
split Xfile.bas
|
||||||
|
call assert_equal('qb64', &filetype)
|
||||||
|
bwipe!
|
||||||
|
|
||||||
|
" Visual Basic
|
||||||
|
|
||||||
|
call writefile(['Attribute VB_NAME = "Testing"'], 'Xfile.bas')
|
||||||
|
split Xfile.bas
|
||||||
|
call assert_equal('vb', &filetype)
|
||||||
|
bwipe!
|
||||||
|
|
||||||
|
call delete('Xfile.bas')
|
||||||
|
filetype off
|
||||||
|
endfunc
|
||||||
|
|
||||||
" vim: shiftwidth=2 sts=2 expandtab
|
" vim: shiftwidth=2 sts=2 expandtab
|
||||||
|
|||||||
@ -750,6 +750,8 @@ static char *(features[]) =
|
|||||||
|
|
||||||
static int included_patches[] =
|
static int included_patches[] =
|
||||||
{ /* Add new patch number below this line */
|
{ /* Add new patch number below this line */
|
||||||
|
/**/
|
||||||
|
4172,
|
||||||
/**/
|
/**/
|
||||||
4171,
|
4171,
|
||||||
/**/
|
/**/
|
||||||
|
|||||||
Reference in New Issue
Block a user