annotate runtime/indent/matlab.vim @ 9309:178252c6850e v7.4.1937

commit https://github.com/vim/vim/commit/ab47c61f46f0797308217cd3c045472cb0ec3195 Author: Bram Moolenaar <Bram@vim.org> Date: Tue Jun 14 22:02:26 2016 +0200 patch 7.4.1937 Problem: No test for directory stack in quickfix. Solution: Add a test. (Yegappan Lakshmanan)
author Christian Brabandt <cb@256bit.org>
date Tue, 14 Jun 2016 22:15:08 +0200
parents 3fc0f57ecb91
children 63b0b7b79b25
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1 " Matlab indent file
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2 " Language: Matlab
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
3 " Maintainer: Christophe Poucet <christophe.poucet@pandora.be>
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4 " Last Change: 6 January, 2001
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6 " Only load this indent file when no other was loaded.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7 if exists("b:did_indent")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8 finish
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
10 let b:did_indent = 1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
11
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
12 " Some preliminary setting
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
13 setlocal indentkeys=!,o,O=end,=case,=else,=elseif,=otherwise,=catch
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
14
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
15
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
16 setlocal indentexpr=GetMatlabIndent(v:lnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
17
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
18 " Only define the function once.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
19 if exists("*GetMatlabIndent")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
20 finish
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
21 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
22
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
23 function GetMatlabIndent(lnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
24 " Give up if this line is explicitly joined.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
25 if getline(a:lnum - 1) =~ '\\$'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
26 return -1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
27 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
28
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
29 " Search backwards for the first non-empty line.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
30 let plnum = a:lnum - 1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
31 while plnum > 0 && getline(plnum) =~ '^\s*$'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
32 let plnum = plnum - 1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
33 endwhile
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
34
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
35 if plnum == 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
36 " This is the first non-empty line, use zero indent.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
37 return 0
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
38 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
39
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
40 let curind = indent(plnum)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
41
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
42 " If the current line is a stop-block statement...
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
43 if getline(v:lnum) =~ '^\s*\(end\|else\|elseif\|case\|otherwise\|catch\)\>'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
44 " See if this line does not follow the line right after an openblock
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
45 if getline(plnum) =~ '^\s*\(for\|if\|else\|elseif\|case\|while\|switch\|try\|otherwise\|catch\)\>'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
46 " See if the user has already dedented
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
47 elseif indent(v:lnum) > curind - &sw
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
48 " If not, recommend one dedent
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
49 let curind = curind - &sw
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
50 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
51 " Otherwise, trust the user
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
52 return -1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
53 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
54 " endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
55
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
56 " If the previous line opened a block
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
57 elseif getline(plnum) =~ '^\s*\(for\|if\|else\|elseif\|case\|while\|switch\|try\|otherwise\|catch\)\>'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
58 " See if the user has already indented
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
59 if indent(v:lnum) < curind + &sw
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
60 "If not, recommend indent
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
61 let curind = curind + &sw
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
62 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
63 " Otherwise, trust the user
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
64 return -1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
65 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
66 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
67
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
68
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
69
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
70 " If we got to here, it means that the user takes the standardversion, so we return it
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
71 return curind
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
72 endfunction
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
73
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
74 " vim:sw=2