annotate runtime/indent/r.vim @ 4861:e79a20f07daa v7.3.1177

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