mirror of
https://github.com/neovim/neovim.git
synced 2026-04-20 22:35:33 +00:00
vim-patch:9.0.1773: cannot distinguish Forth and Fortran *.f files (#24841)
Problem: cannot distinguish Forth and Fortran *.f files
Solution: Add Filetype detection Code
Also add *.4th as a Forth filetype
closes: vim/vim#12251
19a3bc3add
Don't remove filetype files from Vim patches:
- filetype.vim, script.vim, ft.vim usually contain useful changes
- script.vim and ft.vim don't even have their paths spelled correctly
Co-authored-by: Doug Kearns <dougkearns@gmail.com>
This commit is contained in:
@@ -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',
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user