To: vim_dev@googlegroups.com Subject: Patch 8.2.4064 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.2.4064 Problem: Foam files are not detected. Solution: Detect the foam filetype by the path and file contents. (Mohammed Elwardi Fadeli, closes #9501) Files: runtime/filetype.vim, runtime/autoload/dist/ft.vim, src/testdir/test_filetype.vim *** ../vim-8.2.4063/runtime/filetype.vim 2022-01-05 20:56:34.629480283 +0000 --- runtime/filetype.vim 2022-01-11 17:59:27.968435821 +0000 *************** *** 1214,1219 **** --- 1214,1222 ---- " 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 au BufNewFile,BufRead *.or setf openroad *** ../vim-8.2.4063/runtime/autoload/dist/ft.vim 2021-12-17 20:52:53.231772366 +0000 --- runtime/autoload/dist/ft.vim 2022-01-11 18:13:03.206394704 +0000 *************** *** 829,834 **** --- 829,851 ---- endfor 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' let &cpo = s:cpo_save unlet s:cpo_save *** ../vim-8.2.4063/src/testdir/test_filetype.vim 2022-01-07 20:07:40.379361718 +0000 --- src/testdir/test_filetype.vim 2022-01-11 17:59:27.968435821 +0000 *************** *** 1121,1124 **** --- 1121,1174 ---- filetype off 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-8.2.4063/src/version.c 2022-01-11 15:24:01.307663435 +0000 --- src/version.c 2022-01-11 18:13:35.938311914 +0000 *************** *** 752,753 **** --- 752,755 ---- { /* Add new patch number below this line */ + /**/ + 4064, /**/ -- Facepalm statement #5: "Petrol getting more expensive? Not for me, I'm always tanking for 20 dollars" /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// \\\ \\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///