To: vim_dev@googlegroups.com Subject: Patch 8.2.3399 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.2.3399 Problem: Octave files are not recognized. Solution: Detect Octave files. (Doug Kearns) Files: runtime/autoload/dist/ft.vim, runtime/doc/filetype.txt, runtime/filetype.vim, src/testdir/test_filetype.vim *** ../vim-8.2.3398/runtime/autoload/dist/ft.vim 2021-06-26 12:02:51.484571740 +0200 --- runtime/autoload/dist/ft.vim 2021-09-03 19:16:03.959875245 +0200 *************** *** 264,269 **** --- 264,276 ---- endfunc func dist#ft#FTm() + if exists("g:filetype_m") + exe "setf " . g:filetype_m + return + endif + + let octave_block_terminators = '\' + let n = 1 let saw_comment = 0 " Whether we've seen a multiline comment leader. while n < 100 *************** *** 278,283 **** --- 285,297 ---- setf objc return endif + if line =~ '^\s*\%(#\|%!\|[#%]{\=\s*$\)' || + \ line =~ '^\s*unwind_protect\>' || + \ line =~ '\%(^\|;\)\s*' .. octave_block_terminators + setf octave + return + endif + " TODO: could be Matlab or Octave if line =~ '^\s*%' setf matlab return *************** *** 298,308 **** " or Murphi based on the comment leader. Assume the former as it is more " common. setf objc - elseif exists("g:filetype_m") - " Use user specified default filetype for .m - exe "setf " . g:filetype_m else ! " Default is matlab setf matlab endif endfunc --- 312,319 ---- " or Murphi based on the comment leader. Assume the former as it is more " common. setf objc else ! " Default is Matlab setf matlab endif endfunc *** ../vim-8.2.3398/runtime/doc/filetype.txt 2021-01-31 17:02:06.250490190 +0100 --- runtime/doc/filetype.txt 2021-09-03 19:16:03.963875234 +0200 *************** *** 146,151 **** --- 146,152 ---- *.inc g:filetype_inc *.w g:filetype_w |ft-cweb-syntax| *.i g:filetype_i |ft-progress-syntax| + *.m g:filetype_m |ft-mathematica-syntax| *.p g:filetype_p |ft-pascal-syntax| *.pp g:filetype_pp |ft-pascal-syntax| *.sh g:bash_is_sh |ft-sh-syntax| *** ../vim-8.2.3398/runtime/filetype.vim 2021-08-25 17:10:35.479921268 +0200 --- runtime/filetype.vim 2021-09-03 19:16:03.963875234 +0200 *************** *** 1029,1035 **** " Mason au BufNewFile,BufRead *.mason,*.mhtml,*.comp setf mason ! " Mathematica, Matlab, Murphi or Objective C au BufNewFile,BufRead *.m call dist#ft#FTm() " Mathematica notebook --- 1029,1035 ---- " Mason au BufNewFile,BufRead *.mason,*.mhtml,*.comp setf mason ! " Mathematica, Matlab, Murphi, Objective C or Octave au BufNewFile,BufRead *.m call dist#ft#FTm() " Mathematica notebook *************** *** 1175,1180 **** --- 1175,1183 ---- " Occam au BufNewFile,BufRead *.occ setf occam + " Octave + au BufNewFile,BufRead octave.conf,.octaverc,octaverc setf octave + " Omnimark au BufNewFile,BufRead *.xom,*.xin setf omnimark *** ../vim-8.2.3398/src/testdir/test_filetype.vim 2021-08-25 17:10:35.479921268 +0200 --- src/testdir/test_filetype.vim 2021-09-03 19:16:03.967875224 +0200 *************** *** 295,300 **** --- 295,301 ---- \ 'lss': ['file.lss'], \ 'lua': ['file.lua', 'file.rockspec', 'file.nse'], \ 'lynx': ['lynx.cfg'], + \ 'matlab': ['file.m'], \ 'm3build': ['m3makefile', 'm3overrides'], \ 'm3quake': ['file.quake', 'cm3.cfg'], \ 'm4': ['file.at'], *************** *** 351,356 **** --- 352,358 ---- \ 'obj': ['file.obj'], \ 'ocaml': ['file.ml', 'file.mli', 'file.mll', 'file.mly', '.ocamlinit', 'file.mlt', 'file.mlp', 'file.mlip', 'file.mli.cppo', 'file.ml.cppo'], \ 'occam': ['file.occ'], + \ 'octave': ['octaverc', '.octaverc', 'octave.conf'], \ 'omnimark': ['file.xom', 'file.xin'], \ 'opam': ['opam', 'file.opam', 'file.opam.template'], \ 'openroad': ['file.or'], *************** *** 851,854 **** --- 853,948 ---- filetype off endfunc + func Test_m_file() + filetype on + + call writefile(['looks like Matlab'], 'Xfile.m') + split Xfile.m + call assert_equal('matlab', &filetype) + bwipe! + + let g:filetype_m = 'octave' + split Xfile.m + call assert_equal('octave', &filetype) + bwipe! + unlet g:filetype_m + + " Test dist#ft#FTm() + + " Objective-C + + call writefile(['// Objective-C line comment'], 'Xfile.m') + split Xfile.m + call assert_equal('objc', &filetype) + bwipe! + + call writefile(['/* Objective-C block comment */'], 'Xfile.m') + split Xfile.m + call assert_equal('objc', &filetype) + bwipe! + + call writefile(['#import "test.m"'], 'Xfile.m') + split Xfile.m + call assert_equal('objc', &filetype) + bwipe! + + " Octave + + call writefile(['# Octave line comment'], 'Xfile.m') + split Xfile.m + call assert_equal('octave', &filetype) + bwipe! + + call writefile(['#{', 'Octave block comment', '#}'], 'Xfile.m') + split Xfile.m + call assert_equal('octave', &filetype) + bwipe! + + call writefile(['%{', 'Octave block comment', '%}'], 'Xfile.m') + split Xfile.m + call assert_equal('octave', &filetype) + bwipe! + + call writefile(['%!test "Octave test"'], 'Xfile.m') + split Xfile.m + call assert_equal('octave', &filetype) + bwipe! + + call writefile(['unwind_protect'], 'Xfile.m') + split Xfile.m + call assert_equal('octave', &filetype) + bwipe! + + call writefile(['function test(); 42; endfunction'], 'Xfile.m') + split Xfile.m + call assert_equal('octave', &filetype) + bwipe! + + " Mathematica + + call writefile(['(* Mathematica comment'], 'Xfile.m') + split Xfile.m + call assert_equal('mma', &filetype) + bwipe! + + " Murphi + + call writefile(['-- Murphi comment'], 'Xfile.m') + split Xfile.m + call assert_equal('murphi', &filetype) + bwipe! + + call writefile(['/* Murphi block comment */', 'Type'], 'Xfile.m') + split Xfile.m + call assert_equal('murphi', &filetype) + bwipe! + + call writefile(['Type'], 'Xfile.m') + split Xfile.m + call assert_equal('murphi', &filetype) + bwipe! + + call delete('Xfile.m') + filetype off + endfunc " vim: shiftwidth=2 sts=2 expandtab *** ../vim-8.2.3398/src/version.c 2021-09-03 16:50:11.967606130 +0200 --- src/version.c 2021-09-03 19:18:19.555520145 +0200 *************** *** 757,758 **** --- 757,760 ---- { /* Add new patch number below this line */ + /**/ + 3399, /**/ -- Engineers will go without food and hygiene for days to solve a problem. (Other times just because they forgot.) (Scott Adams - The Dilbert principle) /// 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 ///