vim-patch:8.2.4064: foam files are not detected (#17041)

* vim-patch:8.2.4064: foam files are not detected

Problem:    Foam files are not detected.
Solution:   Detect the foam filetype by the path and file contents. (Mohammed
            Elwardi Fadeli, closes vim/vim#9501)
2284f6cca3

* Port foam ft detection to filetype.lua

Co-authored-by: Gregory Anders <greg@gpanders.com>
This commit is contained in:
Christian Clason 2022-01-11 21:02:58 +01:00 committed by GitHub
parent 074b033e7e
commit 70fe3ce004
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 82 additions and 0 deletions

View File

@ -829,6 +829,23 @@ func dist#ft#Dep3patch()
endfor endfor
endfunc endfunc
" 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
func dist#ft#FTfoam()
let ffile = 0
let lnum = 1
while lnum <= 15
if getline(lnum) =~# '^FoamFile'
let ffile = 1
elseif ffile == 1 && getline(lnum) =~# '^\s*object'
setf foam
return
endif
let lnum = lnum + 1
endwhile
endfunc
" Restore 'cpoptions' " Restore 'cpoptions'
let &cpo = s:cpo_save let &cpo = s:cpo_save
unlet s:cpo_save unlet s:cpo_save

View File

@ -1210,6 +1210,9 @@ au BufNewFile,BufRead *.xom,*.xin setf omnimark
" OPAM " OPAM
au BufNewFile,BufRead opam,*.opam,*.opam.template setf opam au BufNewFile,BufRead opam,*.opam,*.opam.template setf opam
" OpenFOAM
au BufNewFile,BufRead [a-zA-Z0-9]*Dict\(.*\)\=,[a-zA-Z]*Properties\(.*\)\=,*Transport\(.*\),fvSchemes,fvSolution,fvConstrains,fvModels,*/constant/g,*/0\(\.orig\)\=/* call dist#ft#FTfoam()
" OpenROAD " OpenROAD
au BufNewFile,BufRead *.or setf openroad au BufNewFile,BufRead *.or setf openroad

View File

@ -860,6 +860,10 @@ local filename = {
["exim.conf"] = "exim", ["exim.conf"] = "exim",
exports = "exports", exports = "exports",
[".fetchmailrc"] = "fetchmail", [".fetchmailrc"] = "fetchmail",
fvSchemes = function() vim.fn["dist#ft#FTfoam"]() end,
fvSolution = function() vim.fn["dist#ft#FTfoam"]() end,
fvConstraints = function() vim.fn["dist#ft#FTfoam"]() end,
fvModels = function() vim.fn["dist#ft#FTfoam"]() end,
fstab = "fstab", fstab = "fstab",
mtab = "fstab", mtab = "fstab",
[".gdbinit"] = "gdb", [".gdbinit"] = "gdb",
@ -1334,6 +1338,14 @@ local pattern = {
["zlog.*"] = starsetf('zsh'), ["zlog.*"] = starsetf('zsh'),
["zsh.*"] = starsetf('zsh'), ["zsh.*"] = starsetf('zsh'),
["ae%d+%.txt"] = 'mail', ["ae%d+%.txt"] = 'mail',
["[a-zA-Z0-9]*Dict"] = function() vim.fn["dist#ft#FTfoam"]() end,
["[a-zA-Z0-9]*Dict%..*"] = function() vim.fn["dist#ft#FTfoam"]() end,
["[a-zA-Z]*Properties"] = function() vim.fn["dist#ft#FTfoam"]() end,
["[a-zA-Z]*Properties%..*"] = function() vim.fn["dist#ft#FTfoam"]() end,
[".*Transport%..*"] = function() vim.fn["dist#ft#FTfoam"]() end,
[".*/constant/g"] = function() vim.fn["dist#ft#FTfoam"]() end,
[".*/0/.*"] = function() vim.fn["dist#ft#FTfoam"]() end,
[".*/0%.orig/.*"] = function() vim.fn["dist#ft#FTfoam"]() end,
-- END PATTERN -- END PATTERN
} }
-- luacheck: pop -- luacheck: pop

View File

@ -1096,4 +1096,54 @@ func Test_git_file()
filetype off filetype off
endfunc endfunc
func Test_foam_file()
filetype on
call assert_true(mkdir('0', 'p'))
call assert_true(mkdir('0.orig', 'p'))
call writefile(['FoamFile {', ' object something;'], 'Xfile1Dict')
split Xfile1Dict
call assert_equal('foam', &filetype)
bwipe!
call writefile(['FoamFile {', ' object something;'], 'Xfile1Dict.something')
split Xfile1Dict.something
call assert_equal('foam', &filetype)
bwipe!
call writefile(['FoamFile {', ' object something;'], 'XfileProperties')
split XfileProperties
call assert_equal('foam', &filetype)
bwipe!
call writefile(['FoamFile {', ' object something;'], 'XfileProperties.something')
split XfileProperties.something
call assert_equal('foam', &filetype)
bwipe!
call writefile(['FoamFile {', ' object something;'], 'XfileProperties')
split XfileProperties
call assert_equal('foam', &filetype)
bwipe!
call writefile(['FoamFile {', ' object something;'], 'XfileProperties.something')
split XfileProperties.something
call assert_equal('foam', &filetype)
bwipe!
call writefile(['FoamFile {', ' object something;'], '0/Xfile')
split 0/Xfile
call assert_equal('foam', &filetype)
bwipe!
call writefile(['FoamFile {', ' object something;'], '0.orig/Xfile')
split 0.orig/Xfile
call assert_equal('foam', &filetype)
bwipe!
call delete('0', 'rf')
call delete('0.orig', 'rf')
filetype off
endfunc
" vim: shiftwidth=2 sts=2 expandtab " vim: shiftwidth=2 sts=2 expandtab