]> granicus.if.org Git - vim/commitdiff
patch 8.2.3686: filetype detection often mixes up Forth and F# v8.2.3686
authorBram Moolenaar <Bram@vim.org>
Sat, 27 Nov 2021 17:22:07 +0000 (17:22 +0000)
committerBram Moolenaar <Bram@vim.org>
Sat, 27 Nov 2021 17:22:07 +0000 (17:22 +0000)
Problem:    Filetype detection often mixes up Forth and F#.
Solution:   Add a function to inspect the file contents. (Doug Kearns)

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

index 344889249bdb11e7c82fff766728ba876e6af268..0cbcb1bbb5c5ca7b62d64eaa642312c236fcf4b8 100644 (file)
@@ -219,6 +219,23 @@ func dist#ft#FTe()
   endif
 endfunc
 
+" Distinguish between Forth and F#.
+" Provided by Doug Kearns.
+func dist#ft#FTfs()
+  if exists("g:filetype_fs")
+    exe "setf " . g:filetype_fs
+  else
+    let line = getline(nextnonblank(1))
+    " comments and colon definitions
+    if line =~ '^\s*\.\=( ' || line =~ '^\s*\\G\= ' || line =~ '^\\$'
+         \ || line =~ '^\s*: \S'
+      setf forth
+    else
+      setf fs
+    endif
+  endif
+endfunc
+
 " Distinguish between HTML, XHTML and Django
 func dist#ft#FThtml()
   let n = 1
index 38622a426299af979ed39533c5987785038e0859..8cb2e118ad169003548b4e837d25006c936ddb7c 100644 (file)
@@ -139,18 +139,19 @@ can be used to overrule the filetype used for certain extensions:
 
        file name       variable ~
        *.asa           g:filetype_asa  |ft-aspvbs-syntax| |ft-aspperl-syntax|
-       *.asp           g:filetype_asp  |ft-aspvbs-syntax| |ft-aspperl-syntax|
        *.asm           g:asmsyntax     |ft-asm-syntax|
-       *.prg           g:filetype_prg
-       *.pl            g:filetype_pl
-       *.inc           g:filetype_inc
-       *.w             g:filetype_w    |ft-cweb-syntax|
+       *.asp           g:filetype_asp  |ft-aspvbs-syntax| |ft-aspperl-syntax|
+       *.fs            g:filetype_fs   |ft-forth-syntax|
        *.i             g:filetype_i    |ft-progress-syntax|
+       *.inc           g:filetype_inc
        *.m             g:filetype_m    |ft-mathematica-syntax|
        *.p             g:filetype_p    |ft-pascal-syntax|
+       *.pl            g:filetype_pl
        *.pp            g:filetype_pp   |ft-pascal-syntax|
+       *.prg           g:filetype_prg
        *.sh            g:bash_is_sh    |ft-sh-syntax|
        *.tex           g:tex_flavor    |ft-tex-plugin|
+       *.w             g:filetype_w    |ft-cweb-syntax|
 
                                                        *filetype-ignore*
 To avoid that certain files are being inspected, the g:ft_ignore_pat variable
@@ -538,6 +539,14 @@ Options:
 For further discussion of fortran_have_tabs and the method used for the
 detection of source format see |ft-fortran-syntax|.
 
+GPROF                                                  *ft-gprof-plugin*
+
+The gprof filetype plugin defines a mapping <C-]> to jump from a function
+entry in the gprof flat profile or from a function entry in the call graph
+to the details of that function in the call graph.
+
+The mapping can be disabled with: >
+       let g:no_gprof_maps = 1
 
 GIT COMMIT                                              *ft-gitcommit-plugin*
 
index 08d3f5f1116c3cc738a65ee7a1ed1f589232873c..3bc5cf4b0a1df6e61a299ff65a9ed29bcee14657 100644 (file)
@@ -1533,6 +1533,14 @@ gvim display.  Here, statements are colored LightYellow instead of Yellow, and
 conditionals are LightBlue for better distinction.
 
 
+FORTH                                          *forth.vim* *ft-forth-syntax*
+
+Files matching "*.fs" could be F# or Forth.  If the automatic detection
+doesn't work for you, or you don't edit F# at all, use this in your
+startup vimrc: >
+   :let filetype_fs = "forth"
+
+
 FORTRAN                                        *fortran.vim* *ft-fortran-syntax*
 
 Default highlighting and dialect ~
index dcef709eda20447667c37729c3243c5487a92fd0..fd3998b299281342a5e01049609e1cc68d8944e4 100644 (file)
@@ -632,7 +632,10 @@ au BufNewFile,BufRead auto.master          setf conf
 au BufNewFile,BufRead *.mas,*.master           setf master
 
 " Forth
-au BufNewFile,BufRead *.fs,*.ft,*.fth          setf forth
+au BufNewFile,BufRead *.ft,*.fth               setf forth
+
+" F# or Forth
+au BufNewFile,BufRead *.fs                     call dist#ft#FTfs()
 
 " Reva Forth
 au BufNewFile,BufRead *.frt                    setf reva
index 0ff8e4908859853ebf56bd01209e3272e0165cb8..3790b1c10ff46d4e6faa55407fe4292e5af68d65 100644 (file)
@@ -198,6 +198,10 @@ if s:line1 =~# "^#!"
   elseif s:name =~# 'fish\>'
     set ft=fish
 
+    " Gforth
+  elseif s:name =~# 'gforth\>'
+    set ft=forth
+
   endif
   unlet s:name
 
index ebf6eb0d447fc525b1489e500a23a8dd13efd8b9..3b875bbb9d34cbe9fdaa0db8ae1639bc4f12f92c 100644 (file)
@@ -182,11 +182,12 @@ let s:filename_checks = {
     \ 'fgl': ['file.4gl', 'file.4gh', 'file.m4gl'],
     \ 'fish': ['file.fish'],
     \ 'focexec': ['file.fex', 'file.focexec'],
-    \ 'forth': ['file.fs', 'file.ft', 'file.fth'],
+    \ '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'],
     \ 'framescript': ['file.fsl'],
     \ 'freebasic': ['file.fb', 'file.bi'],
+    \ 'fs': ['file.fs'],
     \ 'fstab': ['fstab', 'mtab'],
     \ 'fvwm': ['/.fvwm/file', 'any/.fvwm/file'],
     \ 'gdb': ['.gdbinit', 'gdbinit'],
@@ -664,6 +665,7 @@ let s:script_checks = {
       \ 'fennel': [['#!/path/fennel']],
       \ 'routeros': [['#!/path/rsc']],
       \ 'fish': [['#!/path/fish']],
+      \ 'forth': [['#!/path/gforth']],
       \ }
 
 " Various forms of "env" optional arguments.
@@ -970,4 +972,57 @@ func Test_xpm_file()
   filetype off
 endfunc
 
+func Test_fs_file()
+  filetype on
+
+  call writefile(['looks like F#'], 'Xfile.fs')
+  split Xfile.fs
+  call assert_equal('fs', &filetype)
+  bwipe!
+
+  let g:filetype_fs = 'forth'
+  split Xfile.fs
+  call assert_equal('forth', &filetype)
+  bwipe!
+  unlet g:filetype_fs
+
+  " Test dist#ft#FTfs()
+
+  " Forth (Gforth)
+
+  call writefile(['( Forth inline comment )'], 'Xfile.fs')
+  split Xfile.fs
+  call assert_equal('forth', &filetype)
+  bwipe!
+
+  call writefile(['.( Forth displayed inline comment )'], 'Xfile.fs')
+  split Xfile.fs
+  call assert_equal('forth', &filetype)
+  bwipe!
+
+  call writefile(['\ Forth line comment'], 'Xfile.fs')
+  split Xfile.fs
+  call assert_equal('forth', &filetype)
+  bwipe!
+
+  " empty line comment - no space required
+  call writefile(['\'], 'Xfile.fs')
+  split Xfile.fs
+  call assert_equal('forth', &filetype)
+  bwipe!
+
+  call writefile(['\G Forth documentation comment '], 'Xfile.fs')
+  split Xfile.fs
+  call assert_equal('forth', &filetype)
+  bwipe!
+
+  call writefile([': squared ( n -- n^2 )', 'dup * ;'], 'Xfile.fs')
+  split Xfile.fs
+  call assert_equal('forth', &filetype)
+  bwipe!
+
+  call delete('Xfile.fs')
+  filetype off
+endfunc
+
 " vim: shiftwidth=2 sts=2 expandtab
index 5483fe61ead9e275f9744fa1a4c80f75dfc3515a..9456737844d1284cba2529a837d81b86bbc6444d 100644 (file)
@@ -757,6 +757,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    3686,
 /**/
     3685,
 /**/