Alright, so I have attached two patches adding test cases for the old vs new 
MATLAB indenting scripts respectively. I have also made updates to the new 
indent script itself. Edge-cases related to line continuations have been fixed 
and brackets are now indented correctly which increased complexity ten-fold. 
MATLAB smart indent compatibility should now, however, be up to 100% AFAICT.

I think the added test suite is a wonderful development. That said, I did 
stumble upon some issues when using it. Certain settings in my vimrc were 
interfering. Specifically, I do not use modelines and 'set sw=4' would only 
ever indent one level. Sourcing the indent file with a relative path and 
setting indent settings in the script would be preferable, in my opinion.

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.
diff --git a/runtime/indent/matlab.vim b/runtime/indent/matlab.vim
index 6a31624..f90ee62 100644
--- a/runtime/indent/matlab.vim
+++ b/runtime/indent/matlab.vim
@@ -1,74 +1,116 @@
-" Matlab indent file
-" Language:	Matlab
-" Maintainer:	Christophe Poucet <[email protected]>
-" Last Change:	6 January, 2001
-
-" Only load this indent file when no other was loaded.
-if exists("b:did_indent")
-  finish
-endif
+" Vim indent file
+" Language: MATLAB
+" Maintainer: Christophe Poucet <[email protected]>
+" Author: Axel Forsman <[email protected]>
+
+" Only load if no other indent file is 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
-
-
-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\|else\|elseif\|case\|otherwise\|catch\)\>'
-    " See if this line does not follow the line right after an openblock
-    if getline(plnum) =~ '^\s*\(for\|if\|else\|elseif\|case\|while\|switch\|try\|otherwise\|catch\)\>'
-    " See if the user has already dedented
-    elseif indent(v:lnum) > curind - shiftwidth()
-      " If not, recommend one dedent
-	let curind = curind - shiftwidth()
-    else
-      " Otherwise, trust the user
-      return -1
-    endif
-"  endif
-
-  " If the previous line opened a block
-  elseif getline(plnum) =~ '^\s*\(for\|if\|else\|elseif\|case\|while\|switch\|try\|otherwise\|catch\)\>'
-    " See if the user has already indented
-    if indent(v:lnum) < curind + shiftwidth()
-      "If not, recommend indent
-      let curind = curind + shiftwidth()
-    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
+setlocal indentexpr=GetMatlabIndent()
+setlocal indentkeys=!,o,O,e,0=end,0=elseif,0=case,0=otherwise,0=catch,0=function,0=elsei
+
+" The value of the Function indenting format in
+" MATLAB Editor/Debugger Language Preferences.
+" The possible values are 0 for Classic, 1 for Indent nested functions
+" and 2 for Indent all functions (default).
+let b:MATLAB_function_indent = get(g:, 'MATLAB_function_indent', 2)
+
+" Only define the function once
+if exists("*GetMatlabIndent") | finish | endif
+
+let s:end = '\<end\>\%([^(]*)\)\@!' " Array indexing heuristic
+let s:open_pat = 'for\|if\|parfor\|spmd\|switch\|try\|while\|classdef\|properties\|methods\|events\|enumeration'
+let s:dedent_pat = '\C^\s*\zs\<\%(end\|else\|elseif\|catch\|\(case\|otherwise\|function\)\)\>'
+let s:start_pat = '\C\<\%(function\|' . s:open_pat . '\)\>'
+let s:bracket_pair_pat = '\(\[\|{\)\|\(\]\|}\)'
+let s:zflag = has('patch-7.4.984') ? 'z' : ''
+
+" Returns whether a comment or string envelops the specified column.
+function! s:IsCommentOrString(lnum, col)
+	return synIDattr(synID(a:lnum, a:col, 1), "name") =~# 'matlabComment\|matlabMultilineComment\|matlabString'
+endfunction
+
+" Returns whether the specified line continues on the next line.
+function! s:IsLineContinuation(lnum)
+	let l = getline(a:lnum) | let c = -3
+	while 1
+		let c = match(l, '\.\{3}', c + 3)
+		if c == -1 | return 0
+		elseif !s:IsCommentOrString(a:lnum, c) | return 1 | endif
+	endwhile
+endfunction
+
+function! s:SubmatchCount(lnum, pattern, ...)
+	let endcol = a:0 >= 1 ? a:1 : 1 / 0 | let x = [0, 0, 0, 0]
+	call cursor(a:lnum, 1)
+	while 1
+		let [lnum, c, submatch] = searchpos(a:pattern, 'cpe' . s:zflag, a:lnum)
+		if !submatch || c >= endcol | break | endif
+		if !s:IsCommentOrString(lnum, c) | let x[submatch - 2] += 1 | endif
+		if cursor(0, c + 1) == -1 || col('.') == c | break | endif
+	endwhile
+	return x
 endfunction
 
-" vim:sw=2
+function! s:GetOpenCloseCount(lnum, pattern, ...)
+	let counts = call('s:SubmatchCount', [a:lnum, a:pattern] + a:000)
+	return counts[0] - counts[1]
+endfunction
+
+" The value of b:changedtick during last call
+let b:MATLAB_lasttick = -1
+" The last indented line
+let b:MATLAB_lastline = -1
+" Whether the line above was a line continuation
+let b:MATLAB_waslc = 0
+let b:MATLAB_bracketlevel = 0
+
+function! GetMatlabIndent()
+	let prevlnum = prevnonblank(v:lnum - 1)
+
+	if b:MATLAB_lasttick != b:changedtick || b:MATLAB_lastline != prevlnum
+		" Recalculate bracket count (only have to check same block minus one line)
+		let b:MATLAB_bracketlevel = 0
+		let previndent = indent(prevlnum) | let l = prevlnum
+		while 1
+			let l = prevnonblank(l - 1) | let indent = indent(l)
+			if l <= 0 || previndent < indent | break | endif
+			let b:MATLAB_bracketlevel += s:GetOpenCloseCount(l, s:bracket_pair_pat)
+			if previndent != indent | break | endif
+		endwhile
+
+		let b:MATLAB_waslc = s:IsLineContinuation(prevlnum - 1)
+	endif
+	" If line above was blank it can impossibly have been a LC
+	let above_lc = b:MATLAB_lasttick == b:changedtick && prevlnum != v:lnum - 1 && b:MATLAB_lastline == prevlnum ? 0 : s:IsLineContinuation(v:lnum - 1)
+
+	let pair_pat = '\C\<\(' . s:open_pat . '\|'
+				\ . (b:MATLAB_function_indent == 1 ? '^\@<!' : '')
+				\ . (b:MATLAB_function_indent >= 1 ? 'function\|' : '')
+				\ . '\|\%(^\s*\)\@<=\%(else\|elseif\|case\|otherwise\|catch\)\)\>'
+				\ . '\|\S\s*\zs\(' . s:end . '\)' " End at start-of-line handled above
+	let [open, close, b_open, b_close] = prevlnum ? s:SubmatchCount(prevlnum,
+				\ pair_pat . '\|' . s:bracket_pair_pat) : [0, 0, 0, 0]
+	let curbracketlevel = b:MATLAB_bracketlevel + b_open - b_close
+
+	call cursor(v:lnum, 1)
+	let submatch = search(s:dedent_pat, 'cp' . s:zflag, v:lnum)
+	if submatch && !s:IsCommentOrString(v:lnum, col('.'))
+		" Align end, et cetera with start of block
+		let [lnum, col] = searchpairpos(s:start_pat, '',  '\C' . s:end, 'bW', 's:IsCommentOrString(line("."), col("."))')
+		let result = lnum ? indent(lnum) + shiftwidth() * (s:GetOpenCloseCount(lnum, pair_pat, col) + submatch == 2) : 0
+	else
+		" Count how many blocks the previous line opens/closes
+		" Line continuations/brackets indent once per statement
+		let result = indent(prevlnum) + shiftwidth() * (open - close
+					\ + (b:MATLAB_bracketlevel ? -!curbracketlevel : !!curbracketlevel)
+					\ + (curbracketlevel <= 0) * (above_lc - b:MATLAB_waslc))
+	endif
+
+	let b:MATLAB_waslc = above_lc
+	let b:MATLAB_bracketlevel = curbracketlevel
+	let b:MATLAB_lasttick = b:changedtick
+	let b:MATLAB_lastline = v:lnum
+	return result
+endfunction
diff --git a/runtime/indent/testdir/matlab.in b/runtime/indent/testdir/matlab.in
index 1a2bc83..5bba1a5 100644
--- a/runtime/indent/testdir/matlab.in
+++ b/runtime/indent/testdir/matlab.in
@@ -15,3 +15,66 @@ catch exception
 statements
 end
 % END_INDENT
+
+% START_INDENT
+if true, ...
+if true
+disp hello
+end
+end
+% END_INDENT
+
+% START_INDENT
+switch a
+case expr
+if true, foo; end
+disp hello
+otherwise
+disp bar
+end
+% END_INDENT
+
+% START_INDENT
+if true
+A(1:end - 1)
+disp foo
+end
+% END_INDENT
+
+% START_INDENT
+A = [{
+}
+] ...
+disp foo
+disp bar
+% END_INDENT
+
+% START_INDENT
+% INDENT_EXE let b:MATLAB_function_indent = 0
+function foo
+disp foo
+function nested
+disp bar
+end
+end
+% END_INDENT
+
+% START_INDENT
+% INDENT_EXE let b:MATLAB_function_indent = 1
+function foo
+disp foo
+function nested
+disp bar
+end
+end
+% END_INDENT
+
+% START_INDENT
+% INDENT_EXE let b:MATLAB_function_indent = 2
+function foo
+disp foo
+function nested
+disp bar
+end
+end
+% END_INDENT
diff --git a/runtime/indent/testdir/matlab.ok b/runtime/indent/testdir/matlab.ok
index 88e1d86..87b9084 100644
--- a/runtime/indent/testdir/matlab.ok
+++ b/runtime/indent/testdir/matlab.ok
@@ -15,3 +15,66 @@ catch exception
     statements
 end
 % END_INDENT
+
+% START_INDENT
+if true, ...
+        if true
+        disp hello
+        end
+end
+% END_INDENT
+
+% START_INDENT
+switch a
+    case expr
+        if true, foo; end
+        disp hello
+    otherwise
+        disp bar
+end
+% END_INDENT
+
+% START_INDENT
+if true
+    A(1:end - 1)
+    disp foo
+end
+% END_INDENT
+
+% START_INDENT
+A = [{
+    }
+    ] ...
+    disp foo
+disp bar
+% END_INDENT
+
+% START_INDENT
+% INDENT_EXE let b:MATLAB_function_indent = 0
+function foo
+disp foo
+    function nested
+    disp bar
+    end
+end
+% END_INDENT
+
+% START_INDENT
+% INDENT_EXE let b:MATLAB_function_indent = 1
+function foo
+disp foo
+    function nested
+        disp bar
+    end
+end
+% END_INDENT
+
+% START_INDENT
+% INDENT_EXE let b:MATLAB_function_indent = 2
+function foo
+    disp foo
+    function nested
+        disp bar
+    end
+end
+% END_INDENT
diff --git a/runtime/indent/testdir/matlab.in b/runtime/indent/testdir/matlab.in
new file mode 100644
index 0000000..1a2bc83
--- /dev/null
+++ b/runtime/indent/testdir/matlab.in
@@ -0,0 +1,17 @@
+% vim: set ft=matlab sw=4 :
+
+% START_INDENT
+if true
+disp foo
+elseif false
+disp bar
+end
+% END_INDENT
+
+% START_INDENT
+try
+statements
+catch exception
+statements
+end
+% END_INDENT
diff --git a/runtime/indent/testdir/matlab.ok b/runtime/indent/testdir/matlab.ok
new file mode 100644
index 0000000..88e1d86
--- /dev/null
+++ b/runtime/indent/testdir/matlab.ok
@@ -0,0 +1,17 @@
+% vim: set ft=matlab sw=4 :
+
+% START_INDENT
+if true
+    disp foo
+elseif false
+    disp bar
+end
+% END_INDENT
+
+% START_INDENT
+try
+    statements
+catch exception
+    statements
+end
+% END_INDENT

Raspunde prin e-mail lui