annotate runtime/indent/r.vim @ 6840:37828f7503c7

Updated runtime files.
author Bram Moolenaar <bram@vim.org>
date Fri, 19 Jun 2015 13:27:23 +0200
parents 8b86b69546a9
children da01d5da2cfa
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3082
3502a7f991fc Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1 " Vim indent file
3502a7f991fc Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2 " Language: R
3502a7f991fc Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3 " Author: Jakson Alves de Aquino <jalvesaq@gmail.com>
6840
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
4 " Last Change: Thu Mar 26, 2015 05:36PM
3082
3502a7f991fc Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5
3502a7f991fc Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6
3502a7f991fc Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
7 " Only load this indent file when no other was loaded.
4159
8b86b69546a9 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3153
diff changeset
8 if exists("b:did_indent")
6840
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
9 finish
3082
3502a7f991fc Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
10 endif
4159
8b86b69546a9 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3153
diff changeset
11 let b:did_indent = 1
3082
3502a7f991fc Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
12
3502a7f991fc Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
13 setlocal indentkeys=0{,0},:,!^F,o,O,e
3502a7f991fc Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
14 setlocal indentexpr=GetRIndent()
3502a7f991fc Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
15
3502a7f991fc Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
16 " Only define the function once.
3502a7f991fc Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
17 if exists("*GetRIndent")
6840
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
18 finish
3082
3502a7f991fc Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
19 endif
3502a7f991fc Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
20
3502a7f991fc Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
21 " Options to make the indentation more similar to Emacs/ESS:
3502a7f991fc Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
22 if !exists("g:r_indent_align_args")
6840
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
23 let g:r_indent_align_args = 1
3082
3502a7f991fc Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
24 endif
3502a7f991fc Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
25 if !exists("g:r_indent_ess_comments")
6840
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
26 let g:r_indent_ess_comments = 0
3082
3502a7f991fc Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
27 endif
3502a7f991fc Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
28 if !exists("g:r_indent_comment_column")
6840
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
29 let g:r_indent_comment_column = 40
3082
3502a7f991fc Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
30 endif
3502a7f991fc Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
31 if ! exists("g:r_indent_ess_compatible")
6840
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
32 let g:r_indent_ess_compatible = 0
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
33 endif
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
34 if ! exists("g:r_indent_op_pattern")
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
35 let g:r_indent_op_pattern = '\(+\|-\|\*\|/\|=\|\~\|%\)$'
3082
3502a7f991fc Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
36 endif
3502a7f991fc Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
37
3502a7f991fc Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
38 function s:RDelete_quotes(line)
6840
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
39 let i = 0
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
40 let j = 0
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
41 let line1 = ""
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
42 let llen = strlen(a:line)
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
43 while i < llen
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
44 if a:line[i] == '"'
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
45 let i += 1
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
46 let line1 = line1 . 's'
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
47 while !(a:line[i] == '"' && ((i > 1 && a:line[i-1] == '\' && a:line[i-2] == '\') || a:line[i-1] != '\')) && i < llen
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
48 let i += 1
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
49 endwhile
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
50 if a:line[i] == '"'
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
51 let i += 1
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
52 endif
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
53 else
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
54 if a:line[i] == "'"
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
55 let i += 1
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
56 let line1 = line1 . 's'
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
57 while !(a:line[i] == "'" && ((i > 1 && a:line[i-1] == '\' && a:line[i-2] == '\') || a:line[i-1] != '\')) && i < llen
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
58 let i += 1
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
59 endwhile
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
60 if a:line[i] == "'"
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
61 let i += 1
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
62 endif
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
63 else
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
64 if a:line[i] == "`"
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
65 let i += 1
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
66 let line1 = line1 . 's'
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
67 while a:line[i] != "`" && i < llen
3082
3502a7f991fc Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
68 let i += 1
6840
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
69 endwhile
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
70 if a:line[i] == "`"
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
71 let i += 1
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
72 endif
3082
3502a7f991fc Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
73 endif
6840
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
74 endif
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
75 endif
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
76 if i == llen
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
77 break
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
78 endif
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
79 let line1 = line1 . a:line[i]
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
80 let j += 1
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
81 let i += 1
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
82 endwhile
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
83 return line1
3082
3502a7f991fc Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
84 endfunction
3502a7f991fc Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
85
3502a7f991fc Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
86 " Convert foo(bar()) int foo()
3502a7f991fc Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
87 function s:RDelete_parens(line)
6840
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
88 if s:Get_paren_balance(a:line, "(", ")") != 0
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
89 return a:line
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
90 endif
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
91 let i = 0
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
92 let j = 0
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
93 let line1 = ""
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
94 let llen = strlen(a:line)
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
95 while i < llen
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
96 let line1 = line1 . a:line[i]
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
97 if a:line[i] == '('
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
98 let nop = 1
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
99 while nop > 0 && i < llen
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
100 let i += 1
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
101 if a:line[i] == ')'
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
102 let nop -= 1
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
103 else
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
104 if a:line[i] == '('
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
105 let nop += 1
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
106 endif
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
107 endif
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
108 endwhile
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
109 let line1 = line1 . a:line[i]
3082
3502a7f991fc Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
110 endif
6840
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
111 let i += 1
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
112 endwhile
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
113 return line1
3082
3502a7f991fc Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
114 endfunction
3502a7f991fc Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
115
3502a7f991fc Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
116 function! s:Get_paren_balance(line, o, c)
6840
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
117 let line2 = substitute(a:line, a:o, "", "g")
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
118 let openp = strlen(a:line) - strlen(line2)
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
119 let line3 = substitute(line2, a:c, "", "g")
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
120 let closep = strlen(line2) - strlen(line3)
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
121 return openp - closep
3082
3502a7f991fc Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
122 endfunction
3502a7f991fc Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
123
3502a7f991fc Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
124 function! s:Get_matching_brace(linenr, o, c, delbrace)
6840
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
125 let line = SanitizeRLine(getline(a:linenr))
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
126 if a:delbrace == 1
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
127 let line = substitute(line, '{$', "", "")
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
128 endif
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
129 let pb = s:Get_paren_balance(line, a:o, a:c)
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
130 let i = a:linenr
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
131 while pb != 0 && i > 1
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
132 let i -= 1
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
133 let pb += s:Get_paren_balance(SanitizeRLine(getline(i)), a:o, a:c)
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
134 endwhile
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
135 return i
3082
3502a7f991fc Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
136 endfunction
3502a7f991fc Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
137
3502a7f991fc Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
138 " This function is buggy because there 'if's without 'else'
3502a7f991fc Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
139 " It must be rewritten relying more on indentation
3502a7f991fc Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
140 function! s:Get_matching_if(linenr, delif)
6840
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
141 let line = SanitizeRLine(getline(a:linenr))
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
142 if a:delif
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
143 let line = substitute(line, "if", "", "g")
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
144 endif
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
145 let elsenr = 0
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
146 let i = a:linenr
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
147 let ifhere = 0
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
148 while i > 0
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
149 let line2 = substitute(line, '\<else\>', "xxx", "g")
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
150 let elsenr += strlen(line) - strlen(line2)
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
151 if line =~ '.*\s*if\s*()' || line =~ '.*\s*if\s*()'
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
152 let elsenr -= 1
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
153 if elsenr == 0
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
154 let ifhere = i
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
155 break
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
156 endif
3082
3502a7f991fc Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
157 endif
6840
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
158 let i -= 1
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
159 let line = SanitizeRLine(getline(i))
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
160 endwhile
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
161 if ifhere
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
162 return ifhere
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
163 else
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
164 return a:linenr
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
165 endif
3082
3502a7f991fc Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
166 endfunction
3502a7f991fc Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
167
3502a7f991fc Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
168 function! s:Get_last_paren_idx(line, o, c, pb)
6840
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
169 let blc = a:pb
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
170 let line = substitute(a:line, '\t', s:curtabstop, "g")
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
171 let theidx = -1
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
172 let llen = strlen(line)
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
173 let idx = 0
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
174 while idx < llen
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
175 if line[idx] == a:o
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
176 let blc -= 1
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
177 if blc == 0
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
178 let theidx = idx
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
179 endif
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
180 else
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
181 if line[idx] == a:c
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
182 let blc += 1
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
183 endif
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
184 endif
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
185 let idx += 1
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
186 endwhile
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
187 return theidx + 1
3082
3502a7f991fc Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
188 endfunction
3502a7f991fc Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
189
3502a7f991fc Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
190 " Get previous relevant line. Search back until getting a line that isn't
3502a7f991fc Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
191 " comment or blank
3502a7f991fc Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
192 function s:Get_prev_line(lineno)
6840
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
193 let lnum = a:lineno - 1
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
194 let data = getline( lnum )
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
195 while lnum > 0 && (data =~ '^\s*#' || data =~ '^\s*$')
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
196 let lnum = lnum - 1
3082
3502a7f991fc Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
197 let data = getline( lnum )
6840
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
198 endwhile
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
199 return lnum
3082
3502a7f991fc Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
200 endfunction
3502a7f991fc Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
201
3502a7f991fc Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
202 " This function is also used by r-plugin/common_global.vim
3502a7f991fc Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
203 " Delete from '#' to the end of the line, unless the '#' is inside a string.
3502a7f991fc Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
204 function SanitizeRLine(line)
6840
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
205 let newline = s:RDelete_quotes(a:line)
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
206 let newline = s:RDelete_parens(newline)
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
207 let newline = substitute(newline, '#.*', "", "")
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
208 let newline = substitute(newline, '\s*$', "", "")
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
209 if &filetype == "rhelp" && newline =~ '^\\method{.*}{.*}(.*'
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
210 let newline = substitute(newline, '^\\method{\(.*\)}{.*}', '\1', "")
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
211 endif
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
212 return newline
3082
3502a7f991fc Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
213 endfunction
3502a7f991fc Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
214
3502a7f991fc Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
215 function GetRIndent()
3502a7f991fc Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
216
6840
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
217 let clnum = line(".") " current line
3082
3502a7f991fc Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
218
6840
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
219 let cline = getline(clnum)
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
220 if cline =~ '^\s*#'
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
221 if g:r_indent_ess_comments == 1
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
222 if cline =~ '^\s*###'
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
223 return 0
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
224 endif
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
225 if cline !~ '^\s*##'
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
226 return g:r_indent_comment_column
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
227 endif
3082
3502a7f991fc Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
228 endif
6840
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
229 endif
3082
3502a7f991fc Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
230
6840
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
231 let cline = SanitizeRLine(cline)
3082
3502a7f991fc Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
232
6840
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
233 if cline =~ '^\s*}' || cline =~ '^\s*}\s*)$'
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
234 let indline = s:Get_matching_brace(clnum, '{', '}', 1)
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
235 if indline > 0 && indline != clnum
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
236 let iline = SanitizeRLine(getline(indline))
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
237 if s:Get_paren_balance(iline, "(", ")") == 0 || iline =~ '(\s*{$'
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
238 return indent(indline)
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
239 else
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
240 let indline = s:Get_matching_brace(indline, '(', ')', 1)
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
241 return indent(indline)
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
242 endif
3082
3502a7f991fc Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
243 endif
6840
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
244 endif
3082
3502a7f991fc Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
245
6840
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
246 " Find the first non blank line above the current line
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
247 let lnum = s:Get_prev_line(clnum)
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
248 " Hit the start of the file, use zero indent.
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
249 if lnum == 0
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
250 return 0
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
251 endif
3082
3502a7f991fc Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
252
6840
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
253 let line = SanitizeRLine(getline(lnum))
3082
3502a7f991fc Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
254
6840
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
255 if &filetype == "rhelp"
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
256 if cline =~ '^\\dontshow{' || cline =~ '^\\dontrun{' || cline =~ '^\\donttest{' || cline =~ '^\\testonly{'
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
257 return 0
3082
3502a7f991fc Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
258 endif
6840
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
259 if line =~ '^\\examples{' || line =~ '^\\usage{' || line =~ '^\\dontshow{' || line =~ '^\\dontrun{' || line =~ '^\\donttest{' || line =~ '^\\testonly{'
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
260 return 0
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
261 endif
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
262 endif
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
263
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
264 if &filetype == "rnoweb" && line =~ "^<<.*>>="
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
265 return 0
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
266 endif
3082
3502a7f991fc Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
267
6840
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
268 if cline =~ '^\s*{'
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
269 if g:r_indent_ess_compatible && line =~ ')$'
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
270 let nlnum = lnum
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
271 let nline = line
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
272 while s:Get_paren_balance(nline, '(', ')') < 0
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
273 let nlnum = s:Get_prev_line(nlnum)
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
274 let nline = SanitizeRLine(getline(nlnum)) . nline
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
275 endwhile
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
276 if nline =~ '^\s*function\s*(' && indent(nlnum) == &sw
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
277 return 0
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
278 endif
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
279 endif
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
280 if s:Get_paren_balance(line, "(", ")") == 0
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
281 return indent(lnum)
3082
3502a7f991fc Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
282 endif
6840
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
283 endif
3082
3502a7f991fc Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
284
6840
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
285 " line is an incomplete command:
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
286 if line =~ '\<\(if\|while\|for\|function\)\s*()$' || line =~ '\<else$' || line =~ '<-$'
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
287 return indent(lnum) + &sw
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
288 endif
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
289
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
290 " Deal with () and []
3082
3502a7f991fc Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
291
6840
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
292 let pb = s:Get_paren_balance(line, '(', ')')
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
293
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
294 if line =~ '^\s*{$' || line =~ '(\s*{' || (pb == 0 && (line =~ '{$' || line =~ '(\s*{$'))
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
295 return indent(lnum) + &sw
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
296 endif
3082
3502a7f991fc Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
297
6840
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
298 let s:curtabstop = repeat(' ', &tabstop)
3082
3502a7f991fc Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
299
6840
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
300 if g:r_indent_align_args == 1
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
301 if pb > 0 && line =~ '{$'
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
302 return s:Get_last_paren_idx(line, '(', ')', pb) + &sw
3082
3502a7f991fc Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
303 endif
3502a7f991fc Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
304
3502a7f991fc Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
305 let bb = s:Get_paren_balance(line, '[', ']')
3502a7f991fc Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
306
6840
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
307 if pb > 0
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
308 if &filetype == "rhelp"
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
309 let ind = s:Get_last_paren_idx(line, '(', ')', pb)
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
310 else
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
311 let ind = s:Get_last_paren_idx(getline(lnum), '(', ')', pb)
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
312 endif
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
313 return ind
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
314 endif
3082
3502a7f991fc Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
315
6840
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
316 if pb < 0 && line =~ '.*[,&|\-\*+<>]$'
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
317 let lnum = s:Get_prev_line(lnum)
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
318 while pb < 1 && lnum > 0
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
319 let line = SanitizeRLine(getline(lnum))
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
320 let line = substitute(line, '\t', s:curtabstop, "g")
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
321 let ind = strlen(line)
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
322 while ind > 0
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
323 if line[ind] == ')'
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
324 let pb -= 1
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
325 else
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
326 if line[ind] == '('
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
327 let pb += 1
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
328 endif
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
329 endif
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
330 if pb == 1
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
331 return ind + 1
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
332 endif
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
333 let ind -= 1
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
334 endwhile
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
335 let lnum -= 1
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
336 endwhile
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
337 return 0
3082
3502a7f991fc Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
338 endif
3502a7f991fc Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
339
6840
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
340 if bb > 0
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
341 let ind = s:Get_last_paren_idx(getline(lnum), '[', ']', bb)
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
342 return ind
3082
3502a7f991fc Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
343 endif
6840
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
344 endif
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
345
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
346 let post_block = 0
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
347 if line =~ '}$'
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
348 let lnum = s:Get_matching_brace(lnum, '{', '}', 0)
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
349 let line = SanitizeRLine(getline(lnum))
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
350 if lnum > 0 && line =~ '^\s*{'
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
351 let lnum = s:Get_prev_line(lnum)
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
352 let line = SanitizeRLine(getline(lnum))
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
353 endif
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
354 let pb = s:Get_paren_balance(line, '(', ')')
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
355 let post_block = 1
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
356 endif
3082
3502a7f991fc Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
357
6840
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
358 " Indent after operator pattern
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
359 let olnum = s:Get_prev_line(lnum)
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
360 let oline = getline(olnum)
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
361 if olnum > 0
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
362 if line =~ g:r_indent_op_pattern
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
363 if oline =~ g:r_indent_op_pattern
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
364 return indent(lnum)
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
365 else
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
366 return indent(lnum) + &sw
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
367 endif
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
368 else
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
369 if oline =~ g:r_indent_op_pattern
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
370 return indent(lnum) - &sw
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
371 endif
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
372 endif
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
373 endif
3082
3502a7f991fc Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
374
6840
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
375 let post_fun = 0
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
376 if pb < 0 && line !~ ')\s*[,&|\-\*+<>]$'
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
377 let post_fun = 1
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
378 while pb < 0 && lnum > 0
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
379 let lnum -= 1
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
380 let linepiece = SanitizeRLine(getline(lnum))
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
381 let pb += s:Get_paren_balance(linepiece, "(", ")")
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
382 let line = linepiece . line
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
383 endwhile
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
384 if line =~ '{$' && post_block == 0
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
385 return indent(lnum) + &sw
3082
3502a7f991fc Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
386 endif
3502a7f991fc Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
387
6840
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
388 " Now we can do some tests again
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
389 if cline =~ '^\s*{'
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
390 return indent(lnum)
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
391 endif
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
392 if post_block == 0
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
393 let newl = SanitizeRLine(line)
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
394 if newl =~ '\<\(if\|while\|for\|function\)\s*()$' || newl =~ '\<else$' || newl =~ '<-$'
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
395 return indent(lnum) + &sw
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
396 endif
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
397 endif
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
398 endif
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
399
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
400 if cline =~ '^\s*else'
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
401 if line =~ '<-\s*if\s*()'
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
402 return indent(lnum) + &sw
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
403 else
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
404 if line =~ '\<if\s*()'
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
405 return indent(lnum)
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
406 else
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
407 return indent(lnum) - &sw
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
408 endif
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
409 endif
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
410 endif
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
411
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
412 let bb = s:Get_paren_balance(line, '[', ']')
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
413 if bb < 0 && line =~ '.*]'
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
414 while bb < 0 && lnum > 0
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
415 let lnum -= 1
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
416 let linepiece = SanitizeRLine(getline(lnum))
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
417 let bb += s:Get_paren_balance(linepiece, "[", "]")
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
418 let line = linepiece . line
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
419 endwhile
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
420 let line = s:RDelete_parens(line)
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
421 endif
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
422
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
423 let plnum = s:Get_prev_line(lnum)
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
424 let ppost_else = 0
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
425 if plnum > 0
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
426 let pline = SanitizeRLine(getline(plnum))
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
427 let ppost_block = 0
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
428 if pline =~ '}$'
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
429 let ppost_block = 1
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
430 let plnum = s:Get_matching_brace(plnum, '{', '}', 0)
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
431 let pline = SanitizeRLine(getline(plnum))
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
432 if pline =~ '^\s*{$' && plnum > 0
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
433 let plnum = s:Get_prev_line(plnum)
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
434 let pline = SanitizeRLine(getline(plnum))
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
435 endif
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
436 endif
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
437
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
438 if pline =~ 'else$'
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
439 let ppost_else = 1
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
440 let plnum = s:Get_matching_if(plnum, 0)
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
441 let pline = SanitizeRLine(getline(plnum))
3082
3502a7f991fc Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
442 endif
3502a7f991fc Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
443
6840
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
444 if pline =~ '^\s*else\s*if\s*('
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
445 let pplnum = s:Get_prev_line(plnum)
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
446 let ppline = SanitizeRLine(getline(pplnum))
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
447 while ppline =~ '^\s*else\s*if\s*(' || ppline =~ '^\s*if\s*()\s*\S$'
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
448 let plnum = pplnum
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
449 let pline = ppline
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
450 let pplnum = s:Get_prev_line(plnum)
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
451 let ppline = SanitizeRLine(getline(pplnum))
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
452 endwhile
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
453 while ppline =~ '\<\(if\|while\|for\|function\)\s*()$' || ppline =~ '\<else$' || ppline =~ '<-$'
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
454 let plnum = pplnum
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
455 let pline = ppline
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
456 let pplnum = s:Get_prev_line(plnum)
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
457 let ppline = SanitizeRLine(getline(pplnum))
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
458 endwhile
3082
3502a7f991fc Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
459 endif
3502a7f991fc Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
460
6840
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
461 let ppb = s:Get_paren_balance(pline, '(', ')')
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
462 if ppb < 0 && (pline =~ ')\s*{$' || pline =~ ')$')
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
463 while ppb < 0 && plnum > 0
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
464 let plnum -= 1
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
465 let linepiece = SanitizeRLine(getline(plnum))
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
466 let ppb += s:Get_paren_balance(linepiece, "(", ")")
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
467 let pline = linepiece . pline
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
468 endwhile
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
469 let pline = s:RDelete_parens(pline)
3082
3502a7f991fc Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
470 endif
6840
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
471 endif
3082
3502a7f991fc Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
472
6840
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
473 let ind = indent(lnum)
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
474 let pind = indent(plnum)
3153
37ecb8ff4560 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3082
diff changeset
475
6840
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
476 if g:r_indent_align_args == 0 && pb != 0
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
477 let ind += pb * &sw
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
478 return ind
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
479 endif
3082
3502a7f991fc Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
480
6840
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
481 if g:r_indent_align_args == 0 && bb != 0
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
482 let ind += bb * &sw
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
483 return ind
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
484 endif
3153
37ecb8ff4560 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 3082
diff changeset
485
6840
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
486 if ind == pind || (ind == (pind + &sw) && pline =~ '{$' && ppost_else == 0)
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
487 return ind
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
488 endif
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
489
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
490 let pline = getline(plnum)
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
491 let pbb = s:Get_paren_balance(pline, '[', ']')
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
492
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
493 while pind < ind && plnum > 0 && ppb == 0 && pbb == 0
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
494 let ind = pind
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
495 let plnum = s:Get_prev_line(plnum)
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
496 let pline = getline(plnum)
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
497 let ppb = s:Get_paren_balance(pline, '(', ')')
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
498 let pbb = s:Get_paren_balance(pline, '[', ']')
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
499 while pline =~ '^\s*else'
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
500 let plnum = s:Get_matching_if(plnum, 1)
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
501 let pline = getline(plnum)
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
502 let ppb = s:Get_paren_balance(pline, '(', ')')
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
503 let pbb = s:Get_paren_balance(pline, '[', ']')
3082
3502a7f991fc Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
504 endwhile
6840
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
505 let pind = indent(plnum)
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
506 if ind == (pind + &sw) && pline =~ '{$'
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
507 return ind
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
508 endif
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
509 endwhile
3082
3502a7f991fc Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
510
6840
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
511 return ind
3082
3502a7f991fc Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
512
3502a7f991fc Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
513 endfunction
3502a7f991fc Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
514
6840
37828f7503c7 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 4159
diff changeset
515 " vim: sw=2