Changeset 7179
- Timestamp:
- 01/26/11 09:21:15 (14 years ago)
- Location:
- issm/trunk/externalpackages/vim/addons/vim
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
issm/trunk/externalpackages/vim/addons/vim/indent/matlab.vim
r4230 r7179 2 2 " Language: Matlab 3 3 " Maintainer: Fabrice Guy <fabrice.guy at gmail dot com> 4 " Last Change: 200 8 Oct 154 " Last Change: 2009 Nov 23 - Added support for if/end block on the same line 5 5 6 6 " Only load this indent file when no other was loaded. … … 9 9 endif 10 10 let b:did_indent = 1 11 let s: onlySubfunctionExists= 011 let s:functionWithoutEndStatement = 0 12 12 13 13 setlocal indentexpr=GetMatlabIndent() … … 63 63 let curind = indent(plnum) 64 64 if s:IsMatlabContinuationLine(v:lnum - 1) 65 let curind = curind + &s ofttabstop65 let curind = curind + &sw 66 66 endif 67 67 " Add a 'shiftwidth' after classdef, properties, switch, methods, events, 68 " function, if, while, for, otherwise, case, t ic, try, catch, else, elseif69 if getline(plnum) =~ '^\s*\(classdef\|properties\|switch\|methods\|events\|function\|if\|while\|for\|otherwise\|case\|t ic\|try\|catch\|else\|elseif\)\>'70 let curind = curind + &s ofttabstop68 " function, if, while, for, otherwise, case, try, catch, else, elseif 69 if getline(plnum) =~ '^\s*\(classdef\|properties\|switch\|methods\|events\|function\|if\|while\|for\|otherwise\|case\|try\|catch\|else\|elseif\)\>' 70 let curind = curind + &sw 71 71 " In Matlab we have different kind of functions 72 72 " - the main function (the function with the same name than the filename) … … 74 74 " - the functions defined in methods (for classes) 75 75 " - subfunctions 76 " For the moment the main function (located line 1) doesn't produce any indentation in the 77 " code (default behavior in the Matlab editor) and the other kind of 78 " functions indent the code 76 " Principles for the indentation : 77 " - all the function keywords are indented (corresponding to the 78 " 'indent all functions' in the Matlab Editor) 79 " - if we have only subfonctions (ie if the main function doesn't have 80 " any mayching end), then each function is dedented 79 81 if getline(plnum) =~ '^\s*\function\>' 80 " If it is the main function 81 if plnum == 1 82 let pplnum = plnum - 1 83 while pplnum > 1 && (getline(pplnum) =~ '^\s*%') 84 let pplnum = pplnum - 1 85 endwhile 86 " If it is the main function, determine if function has a matching end 87 " or not 88 if pplnum <= 1 82 89 " look for a matching end : 83 " - if we find a matching end everything is fine 84 " - if not, then all other functions are subfunctions 90 " - if we find a matching end everything is fine : end of functions 91 " will be dedented when 'end' is reached 92 " - if not, then all other functions are subfunctions : 'function' 93 " keyword has to be dedended 94 let old_lnum = v:lnum 95 let motion = plnum . "gg" 96 execute "normal" . motion 85 97 normal % 86 98 if getline(line('.')) =~ '^\s*end' 87 let s: onlySubfunctionExists= 099 let s:functionWithoutEndStatement = 0 88 100 else 89 let s: onlySubfunctionExists= 1101 let s:functionWithoutEndStatement = 1 90 102 endif 91 103 normal % 92 let curind = curind - &softtabstop 93 else 94 " it is a subfunction without matching end : dedent 95 if s:onlySubfunctionExists 96 let curind = curind - &softtabstop 97 endif 104 let motion = old_lnum . "gg" 105 execute "normal" . motion 98 106 endif 107 endif 108 " if the for-end block (or while-end) is on the same line : dedent 109 if getline(plnum) =~ '\<end[,;]*\s*\(%.*\)\?$' 110 let curind = curind - &sw 99 111 endif 100 112 endif 101 113 102 " Subtract a 'shiftwidth' on a else, elseif, end, catch, otherwise, case, 103 " toc 104 if getline(v:lnum) =~ '^\s*\(else\|elseif\|end\|catch\|otherwise\|case\|toc\)\>' 105 let curind = curind - &softtabstop 114 " Subtract a 'shiftwidth' on a else, elseif, end, catch, otherwise, case 115 if getline(v:lnum) =~ '^\s*\(else\|elseif\|end\|catch\|otherwise\|case\)\>' 116 let curind = curind - &sw 106 117 endif 107 118 " No indentation in a subfunction 108 if getline(v:lnum) =~ '^\s*\function\>' && s: onlySubfunctionExists109 let curind = curind - &s ofttabstop119 if getline(v:lnum) =~ '^\s*\function\>' && s:functionWithoutEndStatement 120 let curind = curind - &sw 110 121 endif 111 112 122 " First case after a switch : indent 113 123 if getline(v:lnum) =~ '^\s*case' … … 116 126 endwhile 117 127 if getline(plnum) =~ '^\s*switch' 118 let curind = indent(plnum) + &s ofttabstop128 let curind = indent(plnum) + &sw 119 129 endif 120 130 endif … … 125 135 if getline(v:lnum) =~ '^\s*end' 126 136 normal % 127 if getline(line('.')) =~ "switch"128 let curind = curind - &s ofttabstop137 if getline(line('.')) =~ '^\s*switch' 138 let curind = curind - &sw 129 139 endif 130 140 normal % -
issm/trunk/externalpackages/vim/addons/vim/syntax/matlab.vim
r4230 r7179 5 5 " Last Change: 2008 Oct 16 : added try/catch/rethrow and class statements 6 6 " 2008 Oct 28 : added highlighting for most of Matlab functions 7 " 2009 Nov 23 : added 'todo' keyword in the matlabTodo keywords 8 " (for doxygen support) 7 9 8 10 " For version 5.x: Clear all syntax items … … 15 17 16 18 syn keyword matlabStatement return function 17 syn keyword matlabConditional switch case else elseif end if otherwise for while18 syn keyword matlabRepeat do break continue19 syn keyword matlabConditional switch case else elseif end if otherwise break continue 20 syn keyword matlabRepeat do for while 19 21 syn keyword matlabStorageClass classdef methods properties events persistent global 20 22 syn keyword matlabExceptions try catch rethrow throw … … 54 56 55 57 syn match matlabComment "%.*$" contains=matlabTodo,matlabTab 56 syn region matlabBlockComment start=+%{+ end=+%}+ 58 syn region matlabBlockComment start=+%{+ end=+%}+ contains=matlabBlockComment 57 59 58 60 … … 306 308 307 309 308 syn match matlabError "-\=\<\d\+\.\d\+\.[^*/\\^]"309 syn match matlabError "-\=\<\d\+\.\d\+[eEdD][-+]\=\d\+\.\([^*/\\^]\)"310 311 310 " Define the default highlighting. 312 311 " For version 5.7 and earlier: only when not done already … … 332 331 HiLink matlabFloat Float 333 332 HiLink matlabConstant Constant 334 HiLink matlabError Error335 333 HiLink matlabImplicit matlabStatement 336 334 HiLink matlabStatement Statement
Note:
See TracChangeset
for help on using the changeset viewer.