]> granicus.if.org Git - vim/commitdiff
patch 8.2.4274: Basic and form filetype detection is incomplete v8.2.4274
authorDoug Kearns <dougkearns@gmail.com>
Mon, 31 Jan 2022 17:09:14 +0000 (17:09 +0000)
committerBram Moolenaar <Bram@vim.org>
Mon, 31 Jan 2022 17:09:14 +0000 (17:09 +0000)
Problem:    Basic and form filetype detection is incomplete.
Solution:   Add a separate function for .frm files. (Doug Kearns, closes #9675)

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

index f513a2ac8fb85a0d4e9082c853339b571b66d424..5d8734a625eb9c1a9f01143a2323c010e14c25d7 100644 (file)
@@ -67,7 +67,10 @@ func dist#ft#FTasmsyntax()
   endif
 endfunc
 
-func dist#ft#FTbas(alt = '')
+let s:ft_visual_basic_content = '\cVB_Name\|Begin VB\.\(Form\|MDIForm\|UserControl\)'
+
+" See FTfrm() for Visual Basic form file detection
+func dist#ft#FTbas()
   if exists("g:filetype_bas")
     exe "setf " . g:filetype_bas
     return
@@ -86,10 +89,8 @@ func dist#ft#FTbas(alt = '')
     setf freebasic
   elseif match(lines, qb64_preproc) > -1
     setf qb64
-  elseif match(lines, '\cVB_Name\|Begin VB\.\(Form\|MDIForm\|UserControl\)') > -1
+  elseif match(lines, s:ft_visual_basic_content) > -1
     setf vb
-  elseif a:alt != ''
-    exe 'setf ' .. a:alt
   else
     setf basic
   endif
@@ -237,6 +238,21 @@ func dist#ft#FTe()
   endif
 endfunc
 
+func dist#ft#FTfrm()
+  if exists("g:filetype_frm")
+    exe "setf " . g:filetype_frm
+    return
+  endif
+
+  let lines = getline(1, min([line("$"), 5]))
+
+  if match(lines, s:ft_visual_basic_content) > -1
+    setf vb
+  else
+    setf form
+  endif
+endfunc
+
 " Distinguish between Forth and F#.
 " Provided by Doug Kearns.
 func dist#ft#FTfs()
index 5d04f21c08487396aae220f47f27a2548d325c51..37126ad9550ba9e699c7a01cd5bf7f44620e24e5 100644 (file)
@@ -2051,7 +2051,7 @@ au BufRead,BufNewFile *.hw,*.module,*.pkg
        \ endif
 
 " Visual Basic (also uses *.bas) or FORM
-au BufNewFile,BufRead *.frm                    call dist#ft#FTbas('form')
+au BufNewFile,BufRead *.frm                    call dist#ft#FTfrm()
 
 " SaxBasic is close to Visual Basic
 au BufNewFile,BufRead *.sba                    setf vb
index 714d6f59cb303d7f5ea81c8c56c6e3d03de78a3d..6f4a42581460f1e7f73d800ea784adc44424e75d 100644 (file)
@@ -183,6 +183,7 @@ let s:filename_checks = {
     \ 'fgl': ['file.4gl', 'file.4gh', 'file.m4gl'],
     \ 'fish': ['file.fish'],
     \ 'focexec': ['file.fex', 'file.focexec'],
+    \ 'form': ['file.frm'],
     \ 'forth': ['file.ft', 'file.fth'],
     \ 'fortran': ['file.f', 'file.for', 'file.fortran', 'file.fpp', 'file.ftn', 'file.f77', 'file.f90', 'file.f95', 'file.f03', 'file.f08'],
     \ 'fpcmake': ['file.fpc'],
@@ -1278,4 +1279,31 @@ func Test_bas_file()
   filetype off
 endfunc
 
+func Test_frm_file()
+  filetype on
+
+  call writefile(['looks like FORM'], 'Xfile.frm')
+  split Xfile.frm
+  call assert_equal('form', &filetype)
+  bwipe!
+
+  " Test dist#ft#FTfrm()
+
+  let g:filetype_frm = 'form'
+  split Xfile.frm
+  call assert_equal('form', &filetype)
+  bwipe!
+  unlet g:filetype_frm
+
+  " Visual Basic
+
+  call writefile(['Begin VB.Form Form1'], 'Xfile.frm')
+  split Xfile.frm
+  call assert_equal('vb', &filetype)
+  bwipe!
+
+  call delete('Xfile.frm')
+  filetype off
+endfunc
+
 " vim: shiftwidth=2 sts=2 expandtab
index 4c9c59442b1e49b7e50ac920ccf5c1b2655979db..921f076727bf0dcceaaa08ab983ba38bc5c2d2ca 100644 (file)
@@ -746,6 +746,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    4274,
 /**/
     4273,
 /**/