Patch 8.2.4172

1 view
Skip to first unread message

Bram Moolenaar

unread,
Jan 21, 2022, 9:55:50 AMJan 21
to vim...@googlegroups.com

Patch 8.2.4172
Problem: Filetype detection for BASIC is not optimal.
Solution: Improve BASIC filetype detection. (Doug Kearns)
Files: runtime/autoload/dist/ft.vim, runtime/filetype.vim,
src/testdir/test_filetype.vim


*** ../vim-8.2.4171/runtime/autoload/dist/ft.vim 2022-01-11 18:14:17.934205651 +0000
--- runtime/autoload/dist/ft.vim 2022-01-21 14:50:11.943200742 +0000
***************
*** 67,79 ****
endif
endfunc

! " Check if one of the first five lines contains "VB_Name". In that case it is
! " probably a Visual Basic file. Otherwise it's assumed to be "alt" filetype.
! func dist#ft#FTVB(alt)
! if getline(1).getline(2).getline(3).getline(4).getline(5) =~? 'VB_Name\|Begin VB\.\(Form\|MDIForm\|UserControl\)'
setf vb
else
! exe "setf " . a:alt
endif
endfunc

--- 67,95 ----
endif
endfunc

! func dist#ft#FTbas()
! if exists("g:filetype_bas")
! exe "setf " . g:filetype_bas
! 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
else
! setf basic
endif
endfunc

*** ../vim-8.2.4171/runtime/filetype.vim 2022-01-13 14:49:06.698083235 +0000
--- runtime/filetype.vim 2022-01-21 14:50:11.943200742 +0000
***************
*** 193,199 ****
au BufNewFile,BufRead *.mch,*.ref,*.imp setf b

" BASIC or Visual Basic
! au BufNewFile,BufRead *.bas call dist#ft#FTVB("basic")

" Visual Basic Script (close to Visual Basic) or Visual Basic .NET
au BufNewFile,BufRead *.vb,*.vbs,*.dsm,*.ctl setf vb
--- 193,200 ----
au BufNewFile,BufRead *.mch,*.ref,*.imp setf b

" BASIC or Visual 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
au BufNewFile,BufRead *.vb,*.vbs,*.dsm,*.ctl setf vb
***************
*** 202,208 ****
au BufNewFile,BufRead *.iba,*.ibi setf ibasic

" FreeBasic file (similar to QBasic)
! au BufNewFile,BufRead *.fb,*.bi setf freebasic

" Batch file for MSDOS.
au BufNewFile,BufRead *.bat,*.sys setf dosbatch
--- 203,209 ----
au BufNewFile,BufRead *.iba,*.ibi setf ibasic

" FreeBasic file (similar to QBasic)
! au BufNewFile,BufRead *.fb setf freebasic

" Batch file for MSDOS.
au BufNewFile,BufRead *.bat,*.sys setf dosbatch
*** ../vim-8.2.4171/src/testdir/test_filetype.vim 2022-01-15 12:27:03.540876108 +0000
--- src/testdir/test_filetype.vim 2022-01-21 14:50:11.943200742 +0000
***************
*** 76,81 ****
--- 76,82 ----
\ 'ave': ['file.ave'],
\ 'awk': ['file.awk', 'file.gawk'],
\ 'b': ['file.mch', 'file.ref', 'file.imp'],
+ \ 'basic': ['file.bas', 'file.bi', 'file.bm'],
\ 'bzl': ['file.bazel', 'file.bzl', 'WORKSPACE'],
\ 'bc': ['file.bc'],
\ 'bdf': ['file.bdf'],
***************
*** 186,192 ****
\ 'fortran': ['file.f', 'file.for', 'file.fortran', 'file.fpp', 'file.ftn', 'file.f77', 'file.f90', 'file.f95', 'file.f03', 'file.f08'],
\ 'fpcmake': ['file.fpc'],
\ 'framescript': ['file.fsl'],
! \ 'freebasic': ['file.fb', 'file.bi'],
\ 'fsharp': ['file.fs', 'file.fsi', 'file.fsx'],
\ 'fstab': ['fstab', 'mtab'],
\ 'fvwm': ['/.fvwm/file', 'any/.fvwm/file'],
--- 187,193 ----
\ 'fortran': ['file.f', 'file.for', 'file.fortran', 'file.fpp', 'file.ftn', 'file.f77', 'file.f90', 'file.f95', 'file.f03', 'file.f08'],
\ 'fpcmake': ['file.fpc'],
\ 'framescript': ['file.fsl'],
! \ 'freebasic': ['file.fb'],
\ 'fsharp': ['file.fs', 'file.fsi', 'file.fsx'],
\ 'fstab': ['fstab', 'mtab'],
\ 'fvwm': ['/.fvwm/file', 'any/.fvwm/file'],
***************
*** 1171,1174 ****
--- 1172,1236 ----
filetype off
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-8.2.4171/src/version.c 2022-01-21 13:29:52.483888785 +0000
--- src/version.c 2022-01-21 14:51:47.981293475 +0000
***************
*** 752,753 ****
--- 752,755 ----
{ /* Add new patch number below this line */
+ /**/
+ 4172,
/**/

--
Why isn't there mouse-flavored cat food?

/// Bram Moolenaar -- Br...@Moolenaar.net -- http://www.Moolenaar.net \\\
/// \\\
\\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///
Reply all
Reply to author
Forward
0 new messages