Skip to content

Commit deba5eb

Browse files
committed
patch 8.2.3399: Octave files are not recognized
Problem: Octave files are not recognized. Solution: Detect Octave files. (Doug Kearns)
1 parent af631f6 commit deba5eb

File tree

5 files changed

+116
-5
lines changed

5 files changed

+116
-5
lines changed

runtime/autoload/dist/ft.vim

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,13 @@ func dist#ft#ProtoCheck(default)
264264
endfunc
265265

266266
func dist#ft#FTm()
267+
if exists("g:filetype_m")
268+
exe "setf " . g:filetype_m
269+
return
270+
endif
271+
272+
let octave_block_terminators = '\<end\%(_try_catch\|classdef\|enumeration\|events\|for\|function\|if\|methods\|parfor\|properties\|switch\|while\)\>'
273+
267274
let n = 1
268275
let saw_comment = 0 " Whether we've seen a multiline comment leader.
269276
while n < 100
@@ -278,6 +285,13 @@ func dist#ft#FTm()
278285
setf objc
279286
return
280287
endif
288+
if line =~ '^\s*\%(#\|%!\|[#%]{\=\s*$\)' ||
289+
\ line =~ '^\s*unwind_protect\>' ||
290+
\ line =~ '\%(^\|;\)\s*' .. octave_block_terminators
291+
setf octave
292+
return
293+
endif
294+
" TODO: could be Matlab or Octave
281295
if line =~ '^\s*%'
282296
setf matlab
283297
return
@@ -298,11 +312,8 @@ func dist#ft#FTm()
298312
" or Murphi based on the comment leader. Assume the former as it is more
299313
" common.
300314
setf objc
301-
elseif exists("g:filetype_m")
302-
" Use user specified default filetype for .m
303-
exe "setf " . g:filetype_m
304315
else
305-
" Default is matlab
316+
" Default is Matlab
306317
setf matlab
307318
endif
308319
endfunc

runtime/doc/filetype.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ can be used to overrule the filetype used for certain extensions:
146146
*.inc g:filetype_inc
147147
*.w g:filetype_w |ft-cweb-syntax|
148148
*.i g:filetype_i |ft-progress-syntax|
149+
*.m g:filetype_m |ft-mathematica-syntax|
149150
*.p g:filetype_p |ft-pascal-syntax|
150151
*.pp g:filetype_pp |ft-pascal-syntax|
151152
*.sh g:bash_is_sh |ft-sh-syntax|

runtime/filetype.vim

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1029,7 +1029,7 @@ au BufNewFile,BufRead *.markdown,*.mdown,*.mkd,*.mkdn,*.mdwn,*.md setf markdown
10291029
" Mason
10301030
au BufNewFile,BufRead *.mason,*.mhtml,*.comp setf mason
10311031

1032-
" Mathematica, Matlab, Murphi or Objective C
1032+
" Mathematica, Matlab, Murphi, Objective C or Octave
10331033
au BufNewFile,BufRead *.m call dist#ft#FTm()
10341034

10351035
" Mathematica notebook
@@ -1175,6 +1175,9 @@ au BufNewFile,BufRead *.ml,*.mli,*.mll,*.mly,.ocamlinit,*.mlt,*.mlp,*.mlip,*.mli
11751175
" Occam
11761176
au BufNewFile,BufRead *.occ setf occam
11771177

1178+
" Octave
1179+
au BufNewFile,BufRead octave.conf,.octaverc,octaverc setf octave
1180+
11781181
" Omnimark
11791182
au BufNewFile,BufRead *.xom,*.xin setf omnimark
11801183

src/testdir/test_filetype.vim

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,7 @@ let s:filename_checks = {
295295
\ 'lss': ['file.lss'],
296296
\ 'lua': ['file.lua', 'file.rockspec', 'file.nse'],
297297
\ 'lynx': ['lynx.cfg'],
298+
\ 'matlab': ['file.m'],
298299
\ 'm3build': ['m3makefile', 'm3overrides'],
299300
\ 'm3quake': ['file.quake', 'cm3.cfg'],
300301
\ 'm4': ['file.at'],
@@ -351,6 +352,7 @@ let s:filename_checks = {
351352
\ 'obj': ['file.obj'],
352353
\ 'ocaml': ['file.ml', 'file.mli', 'file.mll', 'file.mly', '.ocamlinit', 'file.mlt', 'file.mlp', 'file.mlip', 'file.mli.cppo', 'file.ml.cppo'],
353354
\ 'occam': ['file.occ'],
355+
\ 'octave': ['octaverc', '.octaverc', 'octave.conf'],
354356
\ 'omnimark': ['file.xom', 'file.xin'],
355357
\ 'opam': ['opam', 'file.opam', 'file.opam.template'],
356358
\ 'openroad': ['file.or'],
@@ -851,4 +853,96 @@ func Test_dsl_file()
851853
filetype off
852854
endfunc
853855

856+
func Test_m_file()
857+
filetype on
858+
859+
call writefile(['looks like Matlab'], 'Xfile.m')
860+
split Xfile.m
861+
call assert_equal('matlab', &filetype)
862+
bwipe!
863+
864+
let g:filetype_m = 'octave'
865+
split Xfile.m
866+
call assert_equal('octave', &filetype)
867+
bwipe!
868+
unlet g:filetype_m
869+
870+
" Test dist#ft#FTm()
871+
872+
" Objective-C
873+
874+
call writefile(['// Objective-C line comment'], 'Xfile.m')
875+
split Xfile.m
876+
call assert_equal('objc', &filetype)
877+
bwipe!
878+
879+
call writefile(['/* Objective-C block comment */'], 'Xfile.m')
880+
split Xfile.m
881+
call assert_equal('objc', &filetype)
882+
bwipe!
883+
884+
call writefile(['#import "test.m"'], 'Xfile.m')
885+
split Xfile.m
886+
call assert_equal('objc', &filetype)
887+
bwipe!
888+
889+
" Octave
890+
891+
call writefile(['# Octave line comment'], 'Xfile.m')
892+
split Xfile.m
893+
call assert_equal('octave', &filetype)
894+
bwipe!
895+
896+
call writefile(['#{', 'Octave block comment', '#}'], 'Xfile.m')
897+
split Xfile.m
898+
call assert_equal('octave', &filetype)
899+
bwipe!
900+
901+
call writefile(['%{', 'Octave block comment', '%}'], 'Xfile.m')
902+
split Xfile.m
903+
call assert_equal('octave', &filetype)
904+
bwipe!
905+
906+
call writefile(['%!test "Octave test"'], 'Xfile.m')
907+
split Xfile.m
908+
call assert_equal('octave', &filetype)
909+
bwipe!
910+
911+
call writefile(['unwind_protect'], 'Xfile.m')
912+
split Xfile.m
913+
call assert_equal('octave', &filetype)
914+
bwipe!
915+
916+
call writefile(['function test(); 42; endfunction'], 'Xfile.m')
917+
split Xfile.m
918+
call assert_equal('octave', &filetype)
919+
bwipe!
920+
921+
" Mathematica
922+
923+
call writefile(['(* Mathematica comment'], 'Xfile.m')
924+
split Xfile.m
925+
call assert_equal('mma', &filetype)
926+
bwipe!
927+
928+
" Murphi
929+
930+
call writefile(['-- Murphi comment'], 'Xfile.m')
931+
split Xfile.m
932+
call assert_equal('murphi', &filetype)
933+
bwipe!
934+
935+
call writefile(['/* Murphi block comment */', 'Type'], 'Xfile.m')
936+
split Xfile.m
937+
call assert_equal('murphi', &filetype)
938+
bwipe!
939+
940+
call writefile(['Type'], 'Xfile.m')
941+
split Xfile.m
942+
call assert_equal('murphi', &filetype)
943+
bwipe!
944+
945+
call delete('Xfile.m')
946+
filetype off
947+
endfunc
854948
" vim: shiftwidth=2 sts=2 expandtab

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -755,6 +755,8 @@ static char *(features[]) =
755755

756756
static int included_patches[] =
757757
{ /* Add new patch number below this line */
758+
/**/
759+
3399,
758760
/**/
759761
3398,
760762
/**/

0 commit comments

Comments
 (0)