Mercurial > vim
annotate runtime/indent/ruby.vim @ 10722:7598ce51bf2a v8.0.0251
patch 8.0.0251: not easy to select Python 2 or 3
commit https://github.com/vim/vim/commit/f42dd3c3901ea0ba38e67a616aea9953cae81b8d
Author: Bram Moolenaar <Bram@vim.org>
Date: Sat Jan 28 16:06:38 2017 +0100
patch 8.0.0251: not easy to select Python 2 or 3
Problem: It is not so easy to write a script that works with both Python 2
and Python 3, even when the Python code works with both.
Solution: Add 'pyxversion', :pyx, etc. (Marc Weber, Ken Takata)
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Sat, 28 Jan 2017 16:15:04 +0100 |
parents | 57b2b8268d3a |
children | 63b0b7b79b25 |
rev | line source |
---|---|
7 | 1 " Vim indent file |
843 | 2 " Language: Ruby |
3 " Maintainer: Nikolai Weibull <now at bitwi.se> | |
4869 | 4 " URL: https://github.com/vim-ruby/vim-ruby |
843 | 5 " Release Coordinator: Doug Kearns <dougkearns@gmail.com> |
530 | 6 |
7 " 0. Initialization {{{1 | |
8 " ================= | |
7 | 9 |
10 " Only load this indent file when no other was loaded. | |
11 if exists("b:did_indent") | |
12 finish | |
13 endif | |
14 let b:did_indent = 1 | |
15 | |
10048
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
16 if !exists('g:ruby_indent_access_modifier_style') |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
17 " Possible values: "normal", "indent", "outdent" |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
18 let g:ruby_indent_access_modifier_style = 'normal' |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
19 endif |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
20 |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
21 if !exists('g:ruby_indent_block_style') |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
22 " Possible values: "expression", "do" |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
23 let g:ruby_indent_block_style = 'expression' |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
24 endif |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
25 |
843 | 26 setlocal nosmartindent |
27 | |
530 | 28 " Now, set up our indentation expression and keys that trigger it. |
4869 | 29 setlocal indentexpr=GetRubyIndent(v:lnum) |
10048
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
30 setlocal indentkeys=0{,0},0),0],!^F,o,O,e,:,. |
4869 | 31 setlocal indentkeys+==end,=else,=elsif,=when,=ensure,=rescue,==begin,==end |
10048
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
32 setlocal indentkeys+==private,=protected,=public |
7 | 33 |
34 " Only define the function once. | |
35 if exists("*GetRubyIndent") | |
36 finish | |
37 endif | |
38 | |
530 | 39 let s:cpo_save = &cpo |
40 set cpo&vim | |
41 | |
42 " 1. Variables {{{1 | |
43 " ============ | |
44 | |
4869 | 45 " Regex of syntax group names that are or delimit strings/symbols or are comments. |
46 let s:syng_strcom = '\<ruby\%(Regexp\|RegexpDelimiter\|RegexpEscape' . | |
47 \ '\|Symbol\|String\|StringDelimiter\|StringEscape\|ASCIICode' . | |
10048
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
48 \ '\|Interpolation\|InterpolationDelimiter\|NoInterpolation\|Comment\|Documentation\)\>' |
530 | 49 |
50 " Regex of syntax group names that are strings. | |
51 let s:syng_string = | |
1668 | 52 \ '\<ruby\%(String\|Interpolation\|NoInterpolation\|StringEscape\)\>' |
530 | 53 |
54 " Regex of syntax group names that are strings or documentation. | |
55 let s:syng_stringdoc = | |
4869 | 56 \'\<ruby\%(String\|Interpolation\|NoInterpolation\|StringEscape\|Documentation\)\>' |
530 | 57 |
58 " Expression used to check whether we should skip a match with searchpair(). | |
59 let s:skip_expr = | |
1668 | 60 \ "synIDattr(synID(line('.'),col('.'),1),'name') =~ '".s:syng_strcom."'" |
530 | 61 |
62 " Regex used for words that, at the start of a line, add a level of indent. | |
10048
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
63 let s:ruby_indent_keywords = |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
64 \ '^\s*\zs\<\%(module\|class\|if\|for' . |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
65 \ '\|while\|until\|else\|elsif\|case\|when\|unless\|begin\|ensure\|rescue' . |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
66 \ '\|\%(public\|protected\|private\)\=\s*def\):\@!\>' . |
4869 | 67 \ '\|\%([=,*/%+-]\|<<\|>>\|:\s\)\s*\zs' . |
68 \ '\<\%(if\|for\|while\|until\|case\|unless\|begin\):\@!\>' | |
530 | 69 |
70 " Regex used for words that, at the start of a line, remove a level of indent. | |
71 let s:ruby_deindent_keywords = | |
4869 | 72 \ '^\s*\zs\<\%(ensure\|else\|rescue\|elsif\|when\|end\):\@!\>' |
530 | 73 |
74 " Regex that defines the start-match for the 'end' keyword. | |
75 "let s:end_start_regex = '\%(^\|[^.]\)\<\%(module\|class\|def\|if\|for\|while\|until\|case\|unless\|begin\|do\)\>' | |
76 " TODO: the do here should be restricted somewhat (only at end of line)? | |
4869 | 77 let s:end_start_regex = |
78 \ '\C\%(^\s*\|[=,*/%+\-|;{]\|<<\|>>\|:\s\)\s*\zs' . | |
10048
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
79 \ '\<\%(module\|class\|if\|for\|while\|until\|case\|unless\|begin' . |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
80 \ '\|\%(public\|protected\|private\)\=\s*def\):\@!\>' . |
4869 | 81 \ '\|\%(^\|[^.:@$]\)\@<=\<do:\@!\>' |
530 | 82 |
83 " Regex that defines the middle-match for the 'end' keyword. | |
4869 | 84 let s:end_middle_regex = '\<\%(ensure\|else\|\%(\%(^\|;\)\s*\)\@<=\<rescue:\@!\>\|when\|elsif\):\@!\>' |
530 | 85 |
86 " Regex that defines the end-match for the 'end' keyword. | |
4869 | 87 let s:end_end_regex = '\%(^\|[^.:@$]\)\@<=\<end:\@!\>' |
530 | 88 |
89 " Expression used for searchpair() call for finding match for 'end' keyword. | |
90 let s:end_skip_expr = s:skip_expr . | |
91 \ ' || (expand("<cword>") == "do"' . | |
4869 | 92 \ ' && getline(".") =~ "^\\s*\\<\\(while\\|until\\|for\\):\\@!\\>")' |
530 | 93 |
94 " Regex that defines continuation lines, not including (, {, or [. | |
10272
57b2b8268d3a
commit https://github.com/vim/vim/commit/4575876dc865d4160f20d61bd822fbe7cafbec41
Christian Brabandt <cb@256bit.org>
parents:
10048
diff
changeset
|
95 let s:non_bracket_continuation_regex = |
57b2b8268d3a
commit https://github.com/vim/vim/commit/4575876dc865d4160f20d61bd822fbe7cafbec41
Christian Brabandt <cb@256bit.org>
parents:
10048
diff
changeset
|
96 \ '\%([\\.,:*/%+]\|\<and\|\<or\|\%(<%\)\@<![=-]\|:\@<![^[:alnum:]:][|&?]\|||\|&&\)\s*\%(#.*\)\=$' |
530 | 97 |
98 " Regex that defines continuation lines. | |
4869 | 99 let s:continuation_regex = |
10272
57b2b8268d3a
commit https://github.com/vim/vim/commit/4575876dc865d4160f20d61bd822fbe7cafbec41
Christian Brabandt <cb@256bit.org>
parents:
10048
diff
changeset
|
100 \ '\%(%\@<![({[\\.,:*/%+]\|\<and\|\<or\|\%(<%\)\@<![=-]\|:\@<![^[:alnum:]:][|&?]\|||\|&&\)\s*\%(#.*\)\=$' |
4869 | 101 |
10048
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
102 " Regex that defines continuable keywords |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
103 let s:continuable_regex = |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
104 \ '\C\%(^\s*\|[=,*/%+\-|;{]\|<<\|>>\|:\s\)\s*\zs' . |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
105 \ '\<\%(if\|for\|while\|until\|unless\):\@!\>' |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
106 |
4869 | 107 " Regex that defines bracket continuations |
108 let s:bracket_continuation_regex = '%\@<!\%([({[]\)\s*\%(#.*\)\=$' | |
109 | |
10048
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
110 " Regex that defines dot continuations |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
111 let s:dot_continuation_regex = '%\@<!\.\s*\%(#.*\)\=$' |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
112 |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
113 " Regex that defines backslash continuations |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
114 let s:backslash_continuation_regex = '%\@<!\\\s*$' |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
115 |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
116 " Regex that defines end of bracket continuation followed by another continuation |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
117 let s:bracket_switch_continuation_regex = '^\([^(]\+\zs).\+\)\+'.s:continuation_regex |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
118 |
4869 | 119 " Regex that defines the first part of a splat pattern |
120 let s:splat_regex = '[[,(]\s*\*\s*\%(#.*\)\=$' | |
530 | 121 |
10048
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
122 " Regex that describes all indent access modifiers |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
123 let s:access_modifier_regex = '\C^\s*\%(public\|protected\|private\)\s*\%(#.*\)\=$' |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
124 |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
125 " Regex that describes the indent access modifiers (excludes public) |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
126 let s:indent_access_modifier_regex = '\C^\s*\%(protected\|private\)\s*\%(#.*\)\=$' |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
127 |
530 | 128 " Regex that defines blocks. |
4869 | 129 " |
130 " Note that there's a slight problem with this regex and s:continuation_regex. | |
131 " Code like this will be matched by both: | |
132 " | |
133 " method_call do |(a, b)| | |
134 " | |
135 " The reason is that the pipe matches a hanging "|" operator. | |
136 " | |
530 | 137 let s:block_regex = |
10048
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
138 \ '\%(\<do:\@!\>\|%\@<!{\)\s*\%(|[^|]*|\)\=\s*\%(#.*\)\=$' |
4869 | 139 |
140 let s:block_continuation_regex = '^\s*[^])}\t ].*'.s:block_regex | |
530 | 141 |
10048
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
142 " Regex that describes a leading operator (only a method call's dot for now) |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
143 let s:leading_operator_regex = '^\s*[.]' |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
144 |
530 | 145 " 2. Auxiliary Functions {{{1 |
146 " ====================== | |
147 | |
148 " Check if the character at lnum:col is inside a string, comment, or is ascii. | |
149 function s:IsInStringOrComment(lnum, col) | |
1668 | 150 return synIDattr(synID(a:lnum, a:col, 1), 'name') =~ s:syng_strcom |
530 | 151 endfunction |
152 | |
153 " Check if the character at lnum:col is inside a string. | |
154 function s:IsInString(lnum, col) | |
1668 | 155 return synIDattr(synID(a:lnum, a:col, 1), 'name') =~ s:syng_string |
530 | 156 endfunction |
157 | |
158 " Check if the character at lnum:col is inside a string or documentation. | |
159 function s:IsInStringOrDocumentation(lnum, col) | |
1668 | 160 return synIDattr(synID(a:lnum, a:col, 1), 'name') =~ s:syng_stringdoc |
530 | 161 endfunction |
162 | |
4869 | 163 " Check if the character at lnum:col is inside a string delimiter |
164 function s:IsInStringDelimiter(lnum, col) | |
165 return synIDattr(synID(a:lnum, a:col, 1), 'name') == 'rubyStringDelimiter' | |
166 endfunction | |
167 | |
530 | 168 " Find line above 'lnum' that isn't empty, in a comment, or in a string. |
169 function s:PrevNonBlankNonString(lnum) | |
170 let in_block = 0 | |
171 let lnum = prevnonblank(a:lnum) | |
172 while lnum > 0 | |
173 " Go in and out of blocks comments as necessary. | |
174 " If the line isn't empty (with opt. comment) or in a string, end search. | |
175 let line = getline(lnum) | |
4869 | 176 if line =~ '^=begin' |
530 | 177 if in_block |
4869 | 178 let in_block = 0 |
530 | 179 else |
4869 | 180 break |
530 | 181 endif |
4869 | 182 elseif !in_block && line =~ '^=end' |
530 | 183 let in_block = 1 |
184 elseif !in_block && line !~ '^\s*#.*$' && !(s:IsInStringOrComment(lnum, 1) | |
4869 | 185 \ && s:IsInStringOrComment(lnum, strlen(line))) |
530 | 186 break |
187 endif | |
188 let lnum = prevnonblank(lnum - 1) | |
189 endwhile | |
190 return lnum | |
191 endfunction | |
192 | |
193 " Find line above 'lnum' that started the continuation 'lnum' may be part of. | |
194 function s:GetMSL(lnum) | |
195 " Start on the line we're at and use its indent. | |
196 let msl = a:lnum | |
4869 | 197 let msl_body = getline(msl) |
530 | 198 let lnum = s:PrevNonBlankNonString(a:lnum - 1) |
199 while lnum > 0 | |
200 " If we have a continuation line, or we're in a string, use line as MSL. | |
201 " Otherwise, terminate search as we have found our MSL already. | |
202 let line = getline(lnum) | |
4869 | 203 |
10048
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
204 if !s:Match(msl, s:backslash_continuation_regex) && |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
205 \ s:Match(lnum, s:backslash_continuation_regex) |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
206 " If the current line doesn't end in a backslash, but the previous one |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
207 " does, look for that line's msl |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
208 " |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
209 " Example: |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
210 " foo = "bar" \ |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
211 " "baz" |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
212 " |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
213 let msl = lnum |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
214 elseif s:Match(msl, s:leading_operator_regex) |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
215 " If the current line starts with a leading operator, keep its indent |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
216 " and keep looking for an MSL. |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
217 let msl = lnum |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
218 elseif s:Match(lnum, s:splat_regex) |
4869 | 219 " If the above line looks like the "*" of a splat, use the current one's |
220 " indentation. | |
221 " | |
222 " Example: | |
223 " Hash[* | |
224 " method_call do | |
225 " something | |
226 " | |
227 return msl | |
10048
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
228 elseif s:Match(lnum, s:non_bracket_continuation_regex) && |
4869 | 229 \ s:Match(msl, s:non_bracket_continuation_regex) |
230 " If the current line is a non-bracket continuation and so is the | |
231 " previous one, keep its indent and continue looking for an MSL. | |
232 " | |
233 " Example: | |
234 " method_call one, | |
235 " two, | |
236 " three | |
237 " | |
530 | 238 let msl = lnum |
10048
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
239 elseif s:Match(lnum, s:dot_continuation_regex) && |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
240 \ (s:Match(msl, s:bracket_continuation_regex) || s:Match(msl, s:block_continuation_regex)) |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
241 " If the current line is a bracket continuation or a block-starter, but |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
242 " the previous is a dot, keep going to see if the previous line is the |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
243 " start of another continuation. |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
244 " |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
245 " Example: |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
246 " parent. |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
247 " method_call { |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
248 " three |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
249 " |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
250 let msl = lnum |
4869 | 251 elseif s:Match(lnum, s:non_bracket_continuation_regex) && |
252 \ (s:Match(msl, s:bracket_continuation_regex) || s:Match(msl, s:block_continuation_regex)) | |
253 " If the current line is a bracket continuation or a block-starter, but | |
254 " the previous is a non-bracket one, respect the previous' indentation, | |
255 " and stop here. | |
256 " | |
257 " Example: | |
258 " method_call one, | |
259 " two { | |
260 " three | |
261 " | |
262 return lnum | |
263 elseif s:Match(lnum, s:bracket_continuation_regex) && | |
264 \ (s:Match(msl, s:bracket_continuation_regex) || s:Match(msl, s:block_continuation_regex)) | |
265 " If both lines are bracket continuations (the current may also be a | |
266 " block-starter), use the current one's and stop here | |
267 " | |
268 " Example: | |
269 " method_call( | |
270 " other_method_call( | |
271 " foo | |
272 return msl | |
273 elseif s:Match(lnum, s:block_regex) && | |
274 \ !s:Match(msl, s:continuation_regex) && | |
275 \ !s:Match(msl, s:block_continuation_regex) | |
276 " If the previous line is a block-starter and the current one is | |
277 " mostly ordinary, use the current one as the MSL. | |
278 " | |
279 " Example: | |
280 " method_call do | |
281 " something | |
282 " something_else | |
283 return msl | |
530 | 284 else |
4869 | 285 let col = match(line, s:continuation_regex) + 1 |
286 if (col > 0 && !s:IsInStringOrComment(lnum, col)) | |
287 \ || s:IsInString(lnum, strlen(line)) | |
288 let msl = lnum | |
289 else | |
290 break | |
291 endif | |
530 | 292 endif |
4869 | 293 |
294 let msl_body = getline(msl) | |
530 | 295 let lnum = s:PrevNonBlankNonString(lnum - 1) |
296 endwhile | |
297 return msl | |
298 endfunction | |
299 | |
300 " Check if line 'lnum' has more opening brackets than closing ones. | |
4869 | 301 function s:ExtraBrackets(lnum) |
302 let opening = {'parentheses': [], 'braces': [], 'brackets': []} | |
303 let closing = {'parentheses': [], 'braces': [], 'brackets': []} | |
304 | |
530 | 305 let line = getline(a:lnum) |
4869 | 306 let pos = match(line, '[][(){}]', 0) |
307 | |
308 " Save any encountered opening brackets, and remove them once a matching | |
309 " closing one has been found. If a closing bracket shows up that doesn't | |
310 " close anything, save it for later. | |
530 | 311 while pos != -1 |
312 if !s:IsInStringOrComment(a:lnum, pos + 1) | |
4869 | 313 if line[pos] == '(' |
314 call add(opening.parentheses, {'type': '(', 'pos': pos}) | |
315 elseif line[pos] == ')' | |
316 if empty(opening.parentheses) | |
317 call add(closing.parentheses, {'type': ')', 'pos': pos}) | |
318 else | |
319 let opening.parentheses = opening.parentheses[0:-2] | |
320 endif | |
321 elseif line[pos] == '{' | |
322 call add(opening.braces, {'type': '{', 'pos': pos}) | |
323 elseif line[pos] == '}' | |
324 if empty(opening.braces) | |
325 call add(closing.braces, {'type': '}', 'pos': pos}) | |
326 else | |
327 let opening.braces = opening.braces[0:-2] | |
328 endif | |
329 elseif line[pos] == '[' | |
330 call add(opening.brackets, {'type': '[', 'pos': pos}) | |
331 elseif line[pos] == ']' | |
332 if empty(opening.brackets) | |
333 call add(closing.brackets, {'type': ']', 'pos': pos}) | |
334 else | |
335 let opening.brackets = opening.brackets[0:-2] | |
336 endif | |
530 | 337 endif |
338 endif | |
4869 | 339 |
530 | 340 let pos = match(line, '[][(){}]', pos + 1) |
341 endwhile | |
4869 | 342 |
343 " Find the rightmost brackets, since they're the ones that are important in | |
344 " both opening and closing cases | |
345 let rightmost_opening = {'type': '(', 'pos': -1} | |
346 let rightmost_closing = {'type': ')', 'pos': -1} | |
347 | |
348 for opening in opening.parentheses + opening.braces + opening.brackets | |
349 if opening.pos > rightmost_opening.pos | |
350 let rightmost_opening = opening | |
351 endif | |
352 endfor | |
353 | |
354 for closing in closing.parentheses + closing.braces + closing.brackets | |
355 if closing.pos > rightmost_closing.pos | |
356 let rightmost_closing = closing | |
357 endif | |
358 endfor | |
359 | |
360 return [rightmost_opening, rightmost_closing] | |
530 | 361 endfunction |
362 | |
363 function s:Match(lnum, regex) | |
10048
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
364 let line = getline(a:lnum) |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
365 let offset = match(line, '\C'.a:regex) |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
366 let col = offset + 1 |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
367 |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
368 while offset > -1 && s:IsInStringOrComment(a:lnum, col) |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
369 let offset = match(line, '\C'.a:regex, offset + 1) |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
370 let col = offset + 1 |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
371 endwhile |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
372 |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
373 if offset > -1 |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
374 return col |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
375 else |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
376 return 0 |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
377 endif |
530 | 378 endfunction |
379 | |
10048
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
380 " Locates the containing class/module's definition line, ignoring nested classes |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
381 " along the way. |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
382 " |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
383 function! s:FindContainingClass() |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
384 let saved_position = getpos('.') |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
385 |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
386 while searchpair(s:end_start_regex, s:end_middle_regex, s:end_end_regex, 'bW', |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
387 \ s:end_skip_expr) > 0 |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
388 if expand('<cword>') =~# '\<class\|module\>' |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
389 let found_lnum = line('.') |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
390 call setpos('.', saved_position) |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
391 return found_lnum |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
392 endif |
10272
57b2b8268d3a
commit https://github.com/vim/vim/commit/4575876dc865d4160f20d61bd822fbe7cafbec41
Christian Brabandt <cb@256bit.org>
parents:
10048
diff
changeset
|
393 endwhile |
10048
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
394 |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
395 call setpos('.', saved_position) |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
396 return 0 |
530 | 397 endfunction |
398 | |
399 " 3. GetRubyIndent Function {{{1 | |
400 " ========================= | |
401 | |
4869 | 402 function GetRubyIndent(...) |
530 | 403 " 3.1. Setup {{{2 |
404 " ---------- | |
405 | |
10048
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
406 " The value of a single shift-width |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
407 if exists('*shiftwidth') |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
408 let sw = shiftwidth() |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
409 else |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
410 let sw = &sw |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
411 endif |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
412 |
4869 | 413 " For the current line, use the first argument if given, else v:lnum |
414 let clnum = a:0 ? a:1 : v:lnum | |
415 | |
416 " Set up variables for restoring position in file. Could use clnum here. | |
530 | 417 let vcol = col('.') |
418 | |
419 " 3.2. Work on the current line {{{2 | |
420 " ----------------------------- | |
421 | |
422 " Get the current line. | |
4869 | 423 let line = getline(clnum) |
530 | 424 let ind = -1 |
425 | |
10048
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
426 " If this line is an access modifier keyword, align according to the closest |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
427 " class declaration. |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
428 if g:ruby_indent_access_modifier_style == 'indent' |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
429 if s:Match(clnum, s:access_modifier_regex) |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
430 let class_line = s:FindContainingClass() |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
431 if class_line > 0 |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
432 return indent(class_line) + sw |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
433 endif |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
434 endif |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
435 elseif g:ruby_indent_access_modifier_style == 'outdent' |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
436 if s:Match(clnum, s:access_modifier_regex) |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
437 let class_line = s:FindContainingClass() |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
438 if class_line > 0 |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
439 return indent(class_line) |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
440 endif |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
441 endif |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
442 endif |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
443 |
530 | 444 " If we got a closing bracket on an empty line, find its match and indent |
445 " according to it. For parentheses we indent to its column - 1, for the | |
446 " others we indent to the containing line's MSL's level. Return -1 if fail. | |
447 let col = matchend(line, '^\s*[]})]') | |
4869 | 448 if col > 0 && !s:IsInStringOrComment(clnum, col) |
449 call cursor(clnum, col) | |
530 | 450 let bs = strpart('(){}[]', stridx(')}]', line[col - 1]) * 2, 2) |
451 if searchpair(escape(bs[0], '\['), '', bs[1], 'bW', s:skip_expr) > 0 | |
1121 | 452 if line[col-1]==')' && col('.') != col('$') - 1 |
4869 | 453 let ind = virtcol('.') - 1 |
10048
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
454 elseif g:ruby_indent_block_style == 'do' |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
455 let ind = indent(line('.')) |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
456 else " g:ruby_indent_block_style == 'expression' |
4869 | 457 let ind = indent(s:GetMSL(line('.'))) |
1121 | 458 endif |
530 | 459 endif |
460 return ind | |
461 endif | |
462 | |
463 " If we have a =begin or =end set indent to first column. | |
464 if match(line, '^\s*\%(=begin\|=end\)$') != -1 | |
465 return 0 | |
466 endif | |
467 | |
468 " If we have a deindenting keyword, find its match and indent to its level. | |
469 " TODO: this is messy | |
4869 | 470 if s:Match(clnum, s:ruby_deindent_keywords) |
471 call cursor(clnum, 1) | |
530 | 472 if searchpair(s:end_start_regex, s:end_middle_regex, s:end_end_regex, 'bW', |
4869 | 473 \ s:end_skip_expr) > 0 |
474 let msl = s:GetMSL(line('.')) | |
475 let line = getline(line('.')) | |
476 | |
532 | 477 if strpart(line, 0, col('.') - 1) =~ '=\s*$' && |
4869 | 478 \ strpart(line, col('.') - 1, 2) !~ 'do' |
10048
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
479 " assignment to case/begin/etc, on the same line, hanging indent |
4869 | 480 let ind = virtcol('.') - 1 |
10048
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
481 elseif g:ruby_indent_block_style == 'do' |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
482 " align to line of the "do", not to the MSL |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
483 let ind = indent(line('.')) |
4869 | 484 elseif getline(msl) =~ '=\s*\(#.*\)\=$' |
10048
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
485 " in the case of assignment to the MSL, align to the starting line, |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
486 " not to the MSL |
4869 | 487 let ind = indent(line('.')) |
530 | 488 else |
10048
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
489 " align to the MSL |
4869 | 490 let ind = indent(msl) |
530 | 491 endif |
492 endif | |
493 return ind | |
494 endif | |
495 | |
496 " If we are in a multi-line string or line-comment, don't do anything to it. | |
4869 | 497 if s:IsInStringOrDocumentation(clnum, matchend(line, '^\s*') + 1) |
530 | 498 return indent('.') |
499 endif | |
500 | |
4869 | 501 " If we are at the closing delimiter of a "<<" heredoc-style string, set the |
502 " indent to 0. | |
503 if line =~ '^\k\+\s*$' | |
504 \ && s:IsInStringDelimiter(clnum, 1) | |
505 \ && search('\V<<'.line, 'nbW') > 0 | |
506 return 0 | |
507 endif | |
508 | |
10048
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
509 " If the current line starts with a leading operator, add a level of indent. |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
510 if s:Match(clnum, s:leading_operator_regex) |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
511 return indent(s:GetMSL(clnum)) + sw |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
512 endif |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
513 |
530 | 514 " 3.3. Work on the previous line. {{{2 |
515 " ------------------------------- | |
516 | |
517 " Find a non-blank, non-multi-line string line above the current line. | |
4869 | 518 let lnum = s:PrevNonBlankNonString(clnum - 1) |
7 | 519 |
1668 | 520 " If the line is empty and inside a string, use the previous line. |
4869 | 521 if line =~ '^\s*$' && lnum != prevnonblank(clnum - 1) |
522 return indent(prevnonblank(clnum)) | |
1668 | 523 endif |
524 | |
7 | 525 " At the start of the file use zero indent. |
526 if lnum == 0 | |
527 return 0 | |
528 endif | |
529 | |
4869 | 530 " Set up variables for the previous line. |
530 | 531 let line = getline(lnum) |
532 let ind = indent(lnum) | |
533 | |
10048
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
534 if g:ruby_indent_access_modifier_style == 'indent' |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
535 " If the previous line was a private/protected keyword, add a |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
536 " level of indent. |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
537 if s:Match(lnum, s:indent_access_modifier_regex) |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
538 return indent(lnum) + sw |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
539 endif |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
540 elseif g:ruby_indent_access_modifier_style == 'outdent' |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
541 " If the previous line was a private/protected/public keyword, add |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
542 " a level of indent, since the keyword has been out-dented. |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
543 if s:Match(lnum, s:access_modifier_regex) |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
544 return indent(lnum) + sw |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
545 endif |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
546 endif |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
547 |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
548 if s:Match(lnum, s:continuable_regex) && s:Match(lnum, s:continuation_regex) |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
549 return indent(s:GetMSL(lnum)) + sw + sw |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
550 endif |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
551 |
530 | 552 " If the previous line ended with a block opening, add a level of indent. |
553 if s:Match(lnum, s:block_regex) | |
10048
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
554 let msl = s:GetMSL(lnum) |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
555 |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
556 if g:ruby_indent_block_style == 'do' |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
557 " don't align to the msl, align to the "do" |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
558 let ind = indent(lnum) + sw |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
559 elseif getline(msl) =~ '=\s*\(#.*\)\=$' |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
560 " in the case of assignment to the msl, align to the starting line, |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
561 " not to the msl |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
562 let ind = indent(lnum) + sw |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
563 else |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
564 let ind = indent(msl) + sw |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
565 endif |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
566 return ind |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
567 endif |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
568 |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
569 " If the previous line started with a leading operator, use its MSL's level |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
570 " of indent |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
571 if s:Match(lnum, s:leading_operator_regex) |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
572 return indent(s:GetMSL(lnum)) |
530 | 573 endif |
574 | |
4869 | 575 " If the previous line ended with the "*" of a splat, add a level of indent |
576 if line =~ s:splat_regex | |
10048
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
577 return indent(lnum) + sw |
4869 | 578 endif |
579 | |
580 " If the previous line contained unclosed opening brackets and we are still | |
581 " in them, find the rightmost one and add indent depending on the bracket | |
582 " type. | |
583 " | |
584 " If it contained hanging closing brackets, find the rightmost one, find its | |
585 " match and indent according to that. | |
586 if line =~ '[[({]' || line =~ '[])}]\s*\%(#.*\)\=$' | |
587 let [opening, closing] = s:ExtraBrackets(lnum) | |
588 | |
589 if opening.pos != -1 | |
590 if opening.type == '(' && searchpair('(', '', ')', 'bW', s:skip_expr) > 0 | |
591 if col('.') + 1 == col('$') | |
10048
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
592 return ind + sw |
4869 | 593 else |
594 return virtcol('.') | |
595 endif | |
1121 | 596 else |
4869 | 597 let nonspace = matchend(line, '\S', opening.pos + 1) - 1 |
10048
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
598 return nonspace > 0 ? nonspace : ind + sw |
1121 | 599 endif |
4869 | 600 elseif closing.pos != -1 |
601 call cursor(lnum, closing.pos + 1) | |
602 normal! % | |
603 | |
604 if s:Match(line('.'), s:ruby_indent_keywords) | |
10048
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
605 return indent('.') + sw |
4869 | 606 else |
10048
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
607 return indent(s:GetMSL(line('.'))) |
4869 | 608 endif |
530 | 609 else |
4869 | 610 call cursor(clnum, vcol) |
530 | 611 end |
7 | 612 endif |
613 | |
530 | 614 " If the previous line ended with an "end", match that "end"s beginning's |
615 " indent. | |
1212 | 616 let col = s:Match(lnum, '\%(^\|[^.:@$]\)\<end\>\s*\%(#.*\)\=$') |
530 | 617 if col > 0 |
618 call cursor(lnum, col) | |
619 if searchpair(s:end_start_regex, '', s:end_end_regex, 'bW', | |
4869 | 620 \ s:end_skip_expr) > 0 |
530 | 621 let n = line('.') |
622 let ind = indent('.') | |
623 let msl = s:GetMSL(n) | |
624 if msl != n | |
4869 | 625 let ind = indent(msl) |
530 | 626 end |
627 return ind | |
628 endif | |
629 end | |
630 | |
631 let col = s:Match(lnum, s:ruby_indent_keywords) | |
632 if col > 0 | |
633 call cursor(lnum, col) | |
10048
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
634 let ind = virtcol('.') - 1 + sw |
530 | 635 " TODO: make this better (we need to count them) (or, if a searchpair |
636 " fails, we know that something is lacking an end and thus we indent a | |
637 " level | |
638 if s:Match(lnum, s:end_end_regex) | |
639 let ind = indent('.') | |
640 endif | |
641 return ind | |
7 | 642 endif |
643 | |
530 | 644 " 3.4. Work on the MSL line. {{{2 |
645 " -------------------------- | |
646 | |
647 " Set up variables to use and search for MSL to the previous line. | |
648 let p_lnum = lnum | |
649 let lnum = s:GetMSL(lnum) | |
650 | |
10048
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
651 " If the previous line wasn't a MSL. |
530 | 652 if p_lnum != lnum |
10048
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
653 " If previous line ends bracket and begins non-bracket continuation decrease indent by 1. |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
654 if s:Match(p_lnum, s:bracket_switch_continuation_regex) |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
655 return ind - 1 |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
656 " If previous line is a continuation return its indent. |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
657 " TODO: the || s:IsInString() thing worries me a bit. |
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
658 elseif s:Match(p_lnum, s:non_bracket_continuation_regex) || s:IsInString(p_lnum,strlen(line)) |
530 | 659 return ind |
660 endif | |
7 | 661 endif |
662 | |
530 | 663 " Set up more variables, now that we know we wasn't continuation bound. |
664 let line = getline(lnum) | |
665 let msl_ind = indent(lnum) | |
666 | |
667 " If the MSL line had an indenting keyword in it, add a level of indent. | |
668 " TODO: this does not take into account contrived things such as | |
669 " module Foo; class Bar; end | |
670 if s:Match(lnum, s:ruby_indent_keywords) | |
10048
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
671 let ind = msl_ind + sw |
530 | 672 if s:Match(lnum, s:end_end_regex) |
10048
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
673 let ind = ind - sw |
530 | 674 endif |
675 return ind | |
7 | 676 endif |
677 | |
4869 | 678 " If the previous line ended with [*+/.,-=], but wasn't a block ending or a |
679 " closing bracket, indent one extra level. | |
680 if s:Match(lnum, s:non_bracket_continuation_regex) && !s:Match(lnum, '^\s*\([\])}]\|end\)') | |
530 | 681 if lnum == p_lnum |
10048
43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Christian Brabandt <cb@256bit.org>
parents:
4869
diff
changeset
|
682 let ind = msl_ind + sw |
530 | 683 else |
684 let ind = msl_ind | |
685 endif | |
4869 | 686 return ind |
530 | 687 endif |
688 | |
689 " }}}2 | |
690 | |
7 | 691 return ind |
692 endfunction | |
693 | |
530 | 694 " }}}1 |
695 | |
696 let &cpo = s:cpo_save | |
697 unlet s:cpo_save | |
1121 | 698 |
4869 | 699 " vim:set sw=2 sts=2 ts=8 et: |