]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.0.0006: not all Visual Basic files are recognized v9.0.0006
authorBram Moolenaar <Bram@vim.org>
Wed, 29 Jun 2022 13:39:12 +0000 (14:39 +0100)
committerBram Moolenaar <Bram@vim.org>
Wed, 29 Jun 2022 13:39:12 +0000 (14:39 +0100)
Problem:    Not all Visual Basic files are recognized.
Solution:   Change detection of *.cls files. (Doug Kearns)

runtime/autoload/dist/ft.vim
runtime/doc/filetype.txt
runtime/filetype.vim
src/testdir/test_filetype.vim
src/version.c

index 01cde4631e291d3561b1da90555f916b34376f28..5f48f4b10d4ecf1ce2c75b2fa4c313674085ebc1 100644 (file)
@@ -72,22 +72,35 @@ export def FTbas()
 
   # most frequent FreeBASIC-specific keywords in distro files
   var fb_keywords = '\c^\s*\%(extern\|var\|enum\|private\|scope\|union\|byref\|operator\|constructor\|delete\|namespace\|public\|property\|with\|destructor\|using\)\>\%(\s*[:=(]\)\@!'
-  var fb_preproc  = '\c^\s*\%(#\a\+\|option\s\+\%(byval\|dynamic\|escape\|\%(no\)\=gosub\|nokeyword\|private\|static\)\>\)'
+  var fb_preproc  = '\c^\s*\%(' ..
+                      # preprocessor
+                      '#\s*\a\+\|' ..
+                      # compiler option
+                      'option\s\+\%(byval\|dynamic\|escape\|\%(no\)\=gosub\|nokeyword\|private\|static\)\>\|' ..
+                      # metacommand
+                      '\%(''\|rem\)\s*\$lang\>\|' ..
+                      # default datatype
+                      'def\%(byte\|longint\|short\|ubyte\|uint\|ulongint\|ushort\)\>' ..
+                    '\)'
   var fb_comment  = "^\\s*/'"
+
   # OPTION EXPLICIT, without the leading underscore, is common to many dialects
   var qb64_preproc = '\c^\s*\%($\a\+\|option\s\+\%(_explicit\|_\=explicitarray\)\>\)'
 
-  var 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, ft_visual_basic_content) > -1
-    setf vb
-  else
-    setf basic
-  endif
+  for lnum in range(1, min([line("$"), 100]))
+    var line = getline(lnum)
+    if line =~ ft_visual_basic_content
+      setf vb
+      return
+    elseif line =~ fb_preproc || line =~ fb_comment || line =~ fb_keywords
+      setf freebasic
+      return
+    elseif line =~ qb64_preproc
+      setf qb64
+      return
+    endif
+  endfor
+  setf basic
 enddef
 
 export def FTbtm()
@@ -126,6 +139,23 @@ export def FTcfg()
   endif
 enddef
 
+export def FTcls()
+  if exists("g:filetype_cls")
+    exe "setf " .. g:filetype_cls
+    return
+  endif
+
+  if getline(1) =~ '^%'
+    setf tex
+  elseif getline(1)[0] == '#' && getline(1) =~ 'rexx'
+    setf rexx
+  elseif getline(1) == 'VERSION 1.0 CLASS'
+    setf vb
+  else
+    setf st
+  endif
+enddef
+
 export def FTlpc()
   if exists("g:lpc_syntax_for_c")
     var lnum = 1
index 06eff2da1abc94c63ad81769bbc4a76ab105c402..282a7966cb651b1c29aac2ad60238327ee6f4d29 100644 (file)
@@ -143,6 +143,7 @@ variables can be used to overrule the filetype used for certain extensions:
        *.asp           g:filetype_asp  |ft-aspvbs-syntax| |ft-aspperl-syntax|
        *.bas           g:filetype_bas  |ft-basic-syntax|
        *.cfg           g:filetype_cfg
+       *.cls           g:filetype_cls
        *.csh           g:filetype_csh  |ft-csh-syntax|
        *.dat           g:filetype_dat
        *.frm           g:filetype_frm  |ft-form-syntax|
index 6280d32e53d9a0d454c44251715994bd5e448c12..1648e82ab77a9266ea20e8b7bfd8c47140c80b6f 100644 (file)
@@ -1798,16 +1798,11 @@ au BufNewFile,BufRead *.il,*.ils,*.cdf          setf skill
 au BufNewFile,BufRead .slrnrc                  setf slrnrc
 au BufNewFile,BufRead *.score                  setf slrnsc
 
-" Smalltalk (and TeX)
+" Smalltalk
 au BufNewFile,BufRead *.st                     setf st
-au BufNewFile,BufRead *.cls
-       \ if getline(1) =~ '^%' |
-       \  setf tex |
-       \ elseif getline(1)[0] == '#' && getline(1) =~ 'rexx' |
-       \  setf rexx |
-       \ else |
-       \  setf st |
-       \ endif
+
+" Smalltalk (and Rexx, TeX, and Visual Basic)
+au BufNewFile,BufRead *.cls                     call dist#ft#FTcls()
 
 " Smarty templates
 au BufNewFile,BufRead *.tpl                    setf smarty
index 545e33f7befbd6e045c15ee39b0595e57e641dc4..d8ddeff25081787f8d08904f3f0b41cf3867595b 100644 (file)
@@ -837,7 +837,7 @@ func Test_bas_file()
 
   " Visual Basic
 
-  call writefile(['Attribute VB_NAME = "Testing"'], 'Xfile.bas')
+  call writefile(['Attribute VB_NAME = "Testing"', 'Enum Foo', 'End Enum'], 'Xfile.bas')
   split Xfile.bas
   call assert_equal('vb', &filetype)
   bwipe!
@@ -1719,5 +1719,45 @@ func Test_xpm_file()
   filetype off
 endfunc
 
+func Test_cls_file()
+  filetype on
+
+  call writefile(['looks like Smalltalk'], 'Xfile.cls')
+  split Xfile.cls
+  call assert_equal('st', &filetype)
+  bwipe!
+
+  " Test dist#ft#FTcls()
+
+  let g:filetype_cls = 'vb'
+  split Xfile.cls
+  call assert_equal('vb', &filetype)
+  bwipe!
+  unlet g:filetype_cls
+
+  " TeX
+
+  call writefile(['%'], 'Xfile.cls')
+  split Xfile.cls
+  call assert_equal('tex', &filetype)
+  bwipe!
+
+  " Rexx
+
+  call writefile(['# rexx'], 'Xfile.cls')
+  split Xfile.cls
+  call assert_equal('rexx', &filetype)
+  bwipe!
+
+  " Visual Basic
+
+  call writefile(['VERSION 1.0 CLASS'], 'Xfile.cls')
+  split Xfile.cls
+  call assert_equal('vb', &filetype)
+  bwipe!
+
+  call delete('Xfile.cls')
+  filetype off
+endfunc
 
 " vim: shiftwidth=2 sts=2 expandtab
index 0e6758f7428c8c012ced9d66b3e2b450bc74cbc4..98227fa445c4594d6642a0ba86174bd5e00a3792 100644 (file)
@@ -735,6 +735,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    6,
 /**/
     5,
 /**/