diff options
author | Doug Kearns <dougkearns@gmail.com> | 2023-08-20 20:51:12 +0200 |
---|---|---|
committer | Christian Brabandt <cb@256bit.org> | 2023-08-20 20:53:47 +0200 |
commit | 19a3bc3addf9b4aa8150a01b11b4249c67d15d3b (patch) | |
tree | 9a6778b92527ccb378862faadb48ca8d033354de /runtime/autoload | |
parent | 6633611f4280f33934c2ab9b6a3e84c04f054ad3 (diff) |
patch 9.0.1773: cannot distinguish Forth and Fortran *.f filesv9.0.1773
Problem: cannot distinguish Forth and Fortran *.f files
Solution: Add Filetype detection Code
Also add *.4th as a Forth filetype
closes: #12251
Signed-off-by: Christian Brabandt <cb@256bit.org>
Co-authored-by: Doug Kearns <dougkearns@gmail.com>
Diffstat (limited to 'runtime/autoload')
-rw-r--r-- | runtime/autoload/dist/ft.vim | 45 |
1 files changed, 34 insertions, 11 deletions
diff --git a/runtime/autoload/dist/ft.vim b/runtime/autoload/dist/ft.vim index 9f53f68460..bc2125754a 100644 --- a/runtime/autoload/dist/ft.vim +++ b/runtime/autoload/dist/ft.vim @@ -287,6 +287,37 @@ export def FTe() endif enddef +def IsForth(): bool + var first_line = nextnonblank(1) + + # SwiftForth block comment (line is usually filled with '-' or '=') or + # OPTIONAL (sometimes precedes the header comment) + if getline(first_line) =~? '^\%({\%(\s\|$\)\|OPTIONAL\s\)' + return true + endif + + var n = first_line + while n < 100 && n <= line("$") + # Forth comments and colon definitions + if getline(n) =~ '^[:(\\] ' + return true + endif + n += 1 + endwhile + return false +enddef + +# Distinguish between Forth and Fortran +export def FTf() + if exists("g:filetype_f") + exe "setf " .. g:filetype_f + elseif IsForth() + setf forth + else + setf fortran + endif +enddef + export def FTfrm() if exists("g:filetype_frm") exe "setf " .. g:filetype_frm @@ -302,21 +333,13 @@ export def FTfrm() endif enddef -# Distinguish between Forth and F#. -# Provided by Doug Kearns. +# Distinguish between Forth and F# export def FTfs() if exists("g:filetype_fs") exe "setf " .. g:filetype_fs + elseif IsForth() + setf forth else - var n = 1 - while n < 100 && n <= line("$") - # Forth comments and colon definitions - if getline(n) =~ "^[:(\\\\] " - setf forth - return - endif - n += 1 - endwhile setf fsharp endif enddef |