diff options
Diffstat (limited to 'runtime')
-rw-r--r-- | runtime/doc/filetype.txt | 1 | ||||
-rw-r--r-- | runtime/doc/syntax.txt | 7 | ||||
-rw-r--r-- | runtime/lua/vim/filetype.lua | 5 | ||||
-rw-r--r-- | runtime/lua/vim/filetype/detect.lua | 40 |
4 files changed, 43 insertions, 10 deletions
diff --git a/runtime/doc/filetype.txt b/runtime/doc/filetype.txt index 9ebdc71eb2..cf60ecdb6b 100644 --- a/runtime/doc/filetype.txt +++ b/runtime/doc/filetype.txt @@ -144,6 +144,7 @@ variables can be used to overrule the filetype used for certain extensions: `*.cls` g:filetype_cls `*.csh` g:filetype_csh |ft-csh-syntax| `*.dat` g:filetype_dat + `*.f` g:filetype_f |ft-forth-syntax| `*.frm` g:filetype_frm |ft-form-syntax| `*.fs` g:filetype_fs |ft-forth-syntax| `*.i` g:filetype_i |ft-progress-syntax| diff --git a/runtime/doc/syntax.txt b/runtime/doc/syntax.txt index 498c55389a..59f8235ad2 100644 --- a/runtime/doc/syntax.txt +++ b/runtime/doc/syntax.txt @@ -1542,9 +1542,10 @@ example, FORM files, use this in your startup vimrc: > 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: > +Files matching "*.f" could be Fortran or Forth and those matching "*.fs" could +be F# or Forth. If the automatic detection doesn't work for you, or you don't +edit F# or Fortran at all, use this in your startup vimrc: > + :let filetype_f = "forth" :let filetype_fs = "forth" diff --git a/runtime/lua/vim/filetype.lua b/runtime/lua/vim/filetype.lua index ffb284cca7..c310eb3e42 100644 --- a/runtime/lua/vim/filetype.lua +++ b/runtime/lua/vim/filetype.lua @@ -398,6 +398,7 @@ local extension = { EXW = detect.euphoria, ex = detect.ex, exp = 'expect', + f = detect.f, factor = 'factor', fal = 'falcon', fan = 'fan', @@ -410,8 +411,9 @@ local extension = { fish = 'fish', focexec = 'focexec', fex = 'focexec', - fth = 'forth', ft = 'forth', + fth = 'forth', + ['4th'] = 'forth', FOR = 'fortran', f77 = 'fortran', f03 = 'fortran', @@ -427,7 +429,6 @@ local extension = { F77 = 'fortran', f95 = 'fortran', FPP = 'fortran', - f = 'fortran', F = 'fortran', F08 = 'fortran', f08 = 'fortran', diff --git a/runtime/lua/vim/filetype/detect.lua b/runtime/lua/vim/filetype/detect.lua index 59b50f2288..4a7a1cbefe 100644 --- a/runtime/lua/vim/filetype/detect.lua +++ b/runtime/lua/vim/filetype/detect.lua @@ -473,6 +473,38 @@ function M.ex(_, bufnr) end end +--- @param bufnr integer +--- @return boolean +local function is_forth(bufnr) + local first_line = nextnonblank(bufnr, 1) + + -- SwiftForth block comment (line is usually filled with '-' or '=') or + -- OPTIONAL (sometimes precedes the header comment) + if first_line and findany(first_line:lower(), { '^%{%s', '^%{$', '^optional%s' }) then + return true + end + + for _, line in ipairs(getlines(bufnr, 1, 100)) do + -- Forth comments and colon definitions + if line:find('^[:(\\] ') then + return true + end + end + return false +end + +-- Distinguish between Forth and Fortran +--- @type vim.filetype.mapfn +function M.f(_, bufnr) + if vim.g.filetype_f then + return vim.g.filetype_f + end + if is_forth(bufnr) then + return 'forth' + end + return 'fortran' +end + -- This function checks the first 15 lines for appearance of 'FoamFile' -- and then 'object' in a following line. -- In that case, it's probably an OpenFOAM file @@ -518,16 +550,14 @@ function M.fvwm_v2(path, _) end end --- Distinguish between Forth and F#. +-- Distinguish between Forth and F# --- @type vim.filetype.mapfn function M.fs(_, bufnr) if vim.g.filetype_fs then return vim.g.filetype_fs end - for _, line in ipairs(getlines(bufnr, 1, 100)) do - if line:find('^[:(\\] ') then - return 'forth' - end + if is_forth(bufnr) then + return 'forth' end return 'fsharp' end |