Hi
I have slightly improved the vim 7.1 syntax/matlab.vim and indent/matlab.vim
in order to work with octave. At least autoindent works, and
syntax higlight is much better. except with % which is either a comment or
a format mark (i'm too dumb at regexp to fix this currently).
I have done this in the main vim files, maybe it should be done in ~/.vimrc
but i don't know (yet) how to.
On debian these files are:
/usr/share/vim/vim71/syntax/matlab.vim
/usr/share/vim/vim71/indent/matlab.vim
I tried to contact the vim maintainers for these files, but got no answer
yet.
http://groups.google.com/group/vim_dev/browse_thread/thread/a0bbe7ed9c67c13b
So i'm patiently waiting, and meanwhile i welcome any comment and improvements
on this.
my 2 cents.
Alain
" Matlab indent file
" Language: Matlab
" Maintainer: Christophe Poucet <christophe.pou...@pandora.be>
" Last Change: 6 January, 2001
"
" add some Octave stuff: 19 April 2009 <alain.baecker...@laposte.net>
" Only load this indent file when no other was loaded.
if exists("b:did_indent")
finish
endif
let b:did_indent = 1
" Some preliminary setting
setlocal
indentkeys=!,o,O=end,=case,=else,=elseif,=otherwise,=catch,=endfor,=endwhile,=until,=endfunction
setlocal indentexpr=GetMatlabIndent(v:lnum)
" Only define the function once.
if exists("*GetMatlabIndent")
finish
endif
function GetMatlabIndent(lnum)
" Give up if this line is explicitly joined.
if getline(a:lnum - 1) =~ '\\$'
return -1
endif
" Search backwards for the first non-empty line.
let plnum = a:lnum - 1
while plnum > 0 && getline(plnum) =~ '^\s*$'
let plnum = plnum - 1
endwhile
if plnum == 0
" This is the first non-empty line, use zero indent.
return 0
endif
let curind = indent(plnum)
" If the current line is a stop-block statement...
if getline(v:lnum) =~
'^\s*\(end\|endfor\|endwhile\|endif\|until\|endfunction\|else\|elseif\|case\|otherwise\|catch\)\>'
" See if this line does not follow the line right after an openblock
if getline(plnum) =~
'^\s*\(function\|for\|do\|while\|if\|else\|elseif\|case\|switch\|try\|otherwise\|catch\)\>'
" See if the user has already dedented
elseif indent(v:lnum) > curind - &sw
" If not, recommend one dedent
let curind = curind - &sw
else
" Otherwise, trust the user
return -1
endif
" endif
" If the previous line opened a block
elseif getline(plnum) =~
'^\s*\(function\|for\|do\|if\|else\|elseif\|case\|while\|switch\|try\|otherwise\|catch\)\>'
" See if the user has already indented
if indent(v:lnum) < curind + &sw
"If not, recommend indent
let curind = curind + &sw
else
" Otherwise, trust the user
return -1
endif
endif
" If we got to here, it means that the user takes the standardversion, so we
return it
return curind
endfunction
" vim:sw=2
" Vim syntax file
" Language: Matlab
" Maintainer: Preben 'Peppe' Guldberg <peppe-...@wielders.org>
" Original author: Mario Eusebio
" Last Change: 30 May 2003
"
" Add some Octave stuff : 19 April 2009 <alain.baecker...@laposte.net>
" For version 5.x: Clear all syntax items
" For version 6.x: Quit when a syntax file was already loaded
if version < 600
syntax clear
elseif exists("b:current_syntax")
finish
endif
syn keyword matlabStatement assert
syn keyword matlabError error warning
syn keyword matlabLabel case switch
syn keyword matlabConditional else elseif end if otherwise endif
syn keyword matlabRepeat do until for endfor while endwhile
break continue
syn keyword matlabTodo contained TODO FIXME
" If you do not want these operators lit, uncommment them and the "hi link"
below
syn match matlabArithmeticOperator "[-+]"
syn match matlabArithmeticOperator "\.\=[*/\\^]"
syn match matlabRelationalOperator "[=~]="
syn match matlabRelationalOperator "[<>]=\="
syn match matlabLogicalOperator "[&|~]"
syn match matlabLineContinuation "\.\{3}"
"syn match matlabIdentifier "\<\a\w*\>"
" String
syn region matlabString start=+'+ end=+'+ oneline
" If you don't like tabs
syn match matlabTab "\t"
" Standard numbers
syn match matlabNumber "\<\d\+[ij]\=\>"
syn match matlabNumber "[\t\ ][ij][\ \=]"
" floating point number, with dot, optional exponent
syn match matlabFloat
"\<\d\+\(\.\d*\)\=\([edED][-+]\=\d\+\)\=[ij]\=\>"
" floating point number, starting with a dot, optional exponent
syn match matlabFloat "\.\d\+\([edED][-+]\=\d\+\)\=[ij]\=\>"
" Transpose character and delimiters: Either use just [...] or (...) aswell
syn match matlabDelimiter "[][]"
"syn match matlabDelimiter "[][()]"
syn match matlabTransposeOperator "[])a-zA-Z0-9.]'"lc=1
syn match matlabSemicolon ";"
"syn match matlabComment "%.*$"
contains=matlabTodo,matlabTab
syn match matlabComment "#.*$" contains=matlabTodo,matlabTab
syn keyword matlabOperator zeros default margin round ones rand
syn keyword matlabOperator ceil floor size clear zeros eye mean
std cov
syn keyword matlabFunction eval function endfunction return
syn keyword matlabImplicit abs acos atan asin cos cosh exp log
prod sum
syn keyword matlabImplicit log10 log2 max min sign sin sqrt tan
reshape
" Help to prevent common mistakes
syn keyword matlabImplicit test
syn match matlabError "-\=\<\d\+\.\d\+\.[^*/\\^]"
syn match matlabError "-\=\<\d\+\.\d\+[eEdD][-+]\=\d\+\.\([^*/\\^]\)"
" Define the default highlighting.
" For version 5.7 and earlier: only when not done already
" For version 5.8 and later: only when an item doesn't have highlighting yet
if version >= 508 || !exists("did_matlab_syntax_inits")
if version < 508
let did_matlab_syntax_inits = 1
command -nargs=+ HiLink hi link <args>
else
command -nargs=+ HiLink hi def link <args>
endif
HiLink matlabTransposeOperator matlabOperator
HiLink matlabOperator Operator
HiLink matlabLineContinuation Special
HiLink matlabLabel Label
HiLink matlabConditional Conditional
HiLink matlabRepeat Repeat
HiLink matlabTodo Todo
HiLink matlabString String
HiLink matlabDelimiter Identifier
HiLink matlabTransposeOther Identifier
HiLink matlabNumber Number
HiLink matlabFloat Float
HiLink matlabFunction Function
HiLink matlabError Error
HiLink matlabImplicit matlabStatement
HiLink matlabStatement Statement
HiLink matlabSemicolon SpecialChar
HiLink matlabComment Comment
HiLink matlabArithmeticOperator matlabOperator
HiLink matlabRelationalOperator matlabOperator
HiLink matlabLogicalOperator matlabOperator
"optional highlighting
"HiLink matlabIdentifier Identifier
"HiLink matlabTab Error
delcommand HiLink
endif
let b:current_syntax = "matlab"
"EOF vim: ts=8 noet tw=100 sw=8 sts=0
------------------------------------------------------------------------------
Stay on top of everything new and different, both inside and
around Java (TM) technology - register by April 22, and save
$200 on the JavaOne (SM) conference, June 2-5, 2009, San Francisco.
300 plus technical and hands-on sessions. Register today.
Use priority code J9JMT32. http://p.sf.net/sfu/p
_______________________________________________
Octave-dev mailing list
Octave-dev@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/octave-dev