annotate runtime/indent/r.vim @ 32294:b2e8663e6dcc

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