diff options
Diffstat (limited to 'indent/ruby.vim')
-rw-r--r-- | indent/ruby.vim | 42 |
1 files changed, 32 insertions, 10 deletions
diff --git a/indent/ruby.vim b/indent/ruby.vim index 3617a925..78d10d7a 100644 --- a/indent/ruby.vim +++ b/indent/ruby.vim @@ -69,7 +69,7 @@ let s:skip_expr = let s:ruby_indent_keywords = \ '^\s*\zs\<\%(module\|class\|if\|for' . \ '\|while\|until\|else\|elsif\|case\|when\|unless\|begin\|ensure\|rescue' . - \ '\|\%(public\|protected\|private\)\=\s*def\):\@!\>' . + \ '\|\%(\K\k*[!?]\?\)\=\s*def\):\@!\>' . \ '\|\%([=,*/%+-]\|<<\|>>\|:\s\)\s*\zs' . \ '\<\%(if\|for\|while\|until\|case\|unless\|begin\):\@!\>' @@ -83,7 +83,7 @@ let s:ruby_deindent_keywords = let s:end_start_regex = \ '\C\%(^\s*\|[=,*/%+\-|;{]\|<<\|>>\|:\s\)\s*\zs' . \ '\<\%(module\|class\|if\|for\|while\|until\|case\|unless\|begin' . - \ '\|\%(public\|protected\|private\)\=\s*def\):\@!\>' . + \ '\|\%(\K\k*[!?]\?\)\=\s*def\):\@!\>' . \ '\|\%(^\|[^.:@$]\)\@<=\<do:\@!\>' " Regex that defines the middle-match for the 'end' keyword. @@ -195,8 +195,29 @@ function! GetRubyIndent(...) abort " 2.3. Work on the previous line. {{{2 " ------------------------------- + + " Special case: we don't need the real s:PrevNonBlankNonString for an empty + " line inside a string. And that call can be quite expensive in that + " particular situation. let indent_callback_names = [ \ 's:EmptyInsideString', + \ ] + + for callback_name in indent_callback_names +" Decho "Running: ".callback_name + let indent = call(function(callback_name), [indent_info]) + + if indent >= 0 +" Decho "Match: ".callback_name." indent=".indent." info=".string(indent_info) + return indent + endif + endfor + + " Previous line number + let indent_info.plnum = s:PrevNonBlankNonString(indent_info.clnum - 1) + let indent_info.pline = getline(indent_info.plnum) + + let indent_callback_names = [ \ 's:StartOfFile', \ 's:AfterAccessModifier', \ 's:ContinuedLine', @@ -208,10 +229,6 @@ function! GetRubyIndent(...) abort \ 's:AfterIndentKeyword', \ ] - " Previous line number - let indent_info.plnum = s:PrevNonBlankNonString(indent_info.clnum - 1) - let indent_info.pline = getline(indent_info.plnum) - for callback_name in indent_callback_names " Decho "Running: ".callback_name let indent = call(function(callback_name), [indent_info]) @@ -389,12 +406,17 @@ function! s:LeadingOperator(cline_info) abort endfunction function! s:EmptyInsideString(pline_info) abort - " If the line is empty and inside a string (plnum would not be the real - " prevnonblank in that case), use the previous line's indent + " If the line is empty and inside a string (the previous line is a string, + " too), use the previous line's indent let info = a:pline_info - if info.cline =~ '^\s*$' && info.plnum != prevnonblank(info.clnum - 1) - return indent(prevnonblank(info.clnum)) + let plnum = prevnonblank(info.clnum - 1) + let pline = getline(plnum) + + if info.cline =~ '^\s*$' + \ && s:IsInStringOrComment(plnum, 1) + \ && s:IsInStringOrComment(plnum, strlen(pline)) + return indent(plnum) endif return -1 endfunction |