Skip to content

Commit 8b5901e

Browse files
committed
patch 9.0.0006: not all Visual Basic files are recognized
Problem: Not all Visual Basic files are recognized. Solution: Change detection of *.cls files. (Doug Kearns)
1 parent 0406741 commit 8b5901e

5 files changed

Lines changed: 90 additions & 22 deletions

File tree

runtime/autoload/dist/ft.vim

Lines changed: 42 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -72,22 +72,35 @@ export def FTbas()
7272

7373
# most frequent FreeBASIC-specific keywords in distro files
7474
var fb_keywords = '\c^\s*\%(extern\|var\|enum\|private\|scope\|union\|byref\|operator\|constructor\|delete\|namespace\|public\|property\|with\|destructor\|using\)\>\%(\s*[:=(]\)\@!'
75-
var fb_preproc = '\c^\s*\%(#\a\+\|option\s\+\%(byval\|dynamic\|escape\|\%(no\)\=gosub\|nokeyword\|private\|static\)\>\)'
75+
var fb_preproc = '\c^\s*\%(' ..
76+
# preprocessor
77+
'#\s*\a\+\|' ..
78+
# compiler option
79+
'option\s\+\%(byval\|dynamic\|escape\|\%(no\)\=gosub\|nokeyword\|private\|static\)\>\|' ..
80+
# metacommand
81+
'\%(''\|rem\)\s*\$lang\>\|' ..
82+
# default datatype
83+
'def\%(byte\|longint\|short\|ubyte\|uint\|ulongint\|ushort\)\>' ..
84+
'\)'
7685
var fb_comment = "^\\s*/'"
86+
7787
# OPTION EXPLICIT, without the leading underscore, is common to many dialects
7888
var qb64_preproc = '\c^\s*\%($\a\+\|option\s\+\%(_explicit\|_\=explicitarray\)\>\)'
7989

80-
var lines = getline(1, min([line("$"), 100]))
81-
82-
if match(lines, fb_preproc) > -1 || match(lines, fb_comment) > -1 || match(lines, fb_keywords) > -1
83-
setf freebasic
84-
elseif match(lines, qb64_preproc) > -1
85-
setf qb64
86-
elseif match(lines, ft_visual_basic_content) > -1
87-
setf vb
88-
else
89-
setf basic
90-
endif
90+
for lnum in range(1, min([line("$"), 100]))
91+
var line = getline(lnum)
92+
if line =~ ft_visual_basic_content
93+
setf vb
94+
return
95+
elseif line =~ fb_preproc || line =~ fb_comment || line =~ fb_keywords
96+
setf freebasic
97+
return
98+
elseif line =~ qb64_preproc
99+
setf qb64
100+
return
101+
endif
102+
endfor
103+
setf basic
91104
enddef
92105

93106
export def FTbtm()
@@ -126,6 +139,23 @@ export def FTcfg()
126139
endif
127140
enddef
128141

142+
export def FTcls()
143+
if exists("g:filetype_cls")
144+
exe "setf " .. g:filetype_cls
145+
return
146+
endif
147+
148+
if getline(1) =~ '^%'
149+
setf tex
150+
elseif getline(1)[0] == '#' && getline(1) =~ 'rexx'
151+
setf rexx
152+
elseif getline(1) == 'VERSION 1.0 CLASS'
153+
setf vb
154+
else
155+
setf st
156+
endif
157+
enddef
158+
129159
export def FTlpc()
130160
if exists("g:lpc_syntax_for_c")
131161
var lnum = 1

runtime/doc/filetype.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ variables can be used to overrule the filetype used for certain extensions:
143143
*.asp g:filetype_asp |ft-aspvbs-syntax| |ft-aspperl-syntax|
144144
*.bas g:filetype_bas |ft-basic-syntax|
145145
*.cfg g:filetype_cfg
146+
*.cls g:filetype_cls
146147
*.csh g:filetype_csh |ft-csh-syntax|
147148
*.dat g:filetype_dat
148149
*.frm g:filetype_frm |ft-form-syntax|

runtime/filetype.vim

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1798,16 +1798,11 @@ au BufNewFile,BufRead *.il,*.ils,*.cdf setf skill
17981798
au BufNewFile,BufRead .slrnrc setf slrnrc
17991799
au BufNewFile,BufRead *.score setf slrnsc
18001800

1801-
" Smalltalk (and TeX)
1801+
" Smalltalk
18021802
au BufNewFile,BufRead *.st setf st
1803-
au BufNewFile,BufRead *.cls
1804-
\ if getline(1) =~ '^%' |
1805-
\ setf tex |
1806-
\ elseif getline(1)[0] == '#' && getline(1) =~ 'rexx' |
1807-
\ setf rexx |
1808-
\ else |
1809-
\ setf st |
1810-
\ endif
1803+
1804+
" Smalltalk (and Rexx, TeX, and Visual Basic)
1805+
au BufNewFile,BufRead *.cls call dist#ft#FTcls()
18111806

18121807
" Smarty templates
18131808
au BufNewFile,BufRead *.tpl setf smarty

src/testdir/test_filetype.vim

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -837,7 +837,7 @@ func Test_bas_file()
837837

838838
" Visual Basic
839839

840-
call writefile(['Attribute VB_NAME = "Testing"'], 'Xfile.bas')
840+
call writefile(['Attribute VB_NAME = "Testing"', 'Enum Foo', 'End Enum'], 'Xfile.bas')
841841
split Xfile.bas
842842
call assert_equal('vb', &filetype)
843843
bwipe!
@@ -1719,5 +1719,45 @@ func Test_xpm_file()
17191719
filetype off
17201720
endfunc
17211721

1722+
func Test_cls_file()
1723+
filetype on
1724+
1725+
call writefile(['looks like Smalltalk'], 'Xfile.cls')
1726+
split Xfile.cls
1727+
call assert_equal('st', &filetype)
1728+
bwipe!
1729+
1730+
" Test dist#ft#FTcls()
1731+
1732+
let g:filetype_cls = 'vb'
1733+
split Xfile.cls
1734+
call assert_equal('vb', &filetype)
1735+
bwipe!
1736+
unlet g:filetype_cls
1737+
1738+
" TeX
1739+
1740+
call writefile(['%'], 'Xfile.cls')
1741+
split Xfile.cls
1742+
call assert_equal('tex', &filetype)
1743+
bwipe!
1744+
1745+
" Rexx
1746+
1747+
call writefile(['# rexx'], 'Xfile.cls')
1748+
split Xfile.cls
1749+
call assert_equal('rexx', &filetype)
1750+
bwipe!
1751+
1752+
" Visual Basic
1753+
1754+
call writefile(['VERSION 1.0 CLASS'], 'Xfile.cls')
1755+
split Xfile.cls
1756+
call assert_equal('vb', &filetype)
1757+
bwipe!
1758+
1759+
call delete('Xfile.cls')
1760+
filetype off
1761+
endfunc
17221762

17231763
" vim: shiftwidth=2 sts=2 expandtab

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -735,6 +735,8 @@ static char *(features[]) =
735735

736736
static int included_patches[] =
737737
{ /* Add new patch number below this line */
738+
/**/
739+
6,
738740
/**/
739741
5,
740742
/**/

0 commit comments

Comments
 (0)