diff options
Diffstat (limited to 'indent')
| -rw-r--r-- | indent/puppet.vim | 16 | ||||
| -rw-r--r-- | indent/ruby.vim | 36 | 
2 files changed, 38 insertions, 14 deletions
| diff --git a/indent/puppet.vim b/indent/puppet.vim index 1067e9e0..ec714265 100644 --- a/indent/puppet.vim +++ b/indent/puppet.vim @@ -8,7 +8,7 @@ endif  " Last Change:  2009 Aug 19  " vim: set sw=4 sts=4: -if exists("b:did_indent") +if exists('b:did_indent')      finish  endif  let b:did_indent = 1 @@ -17,11 +17,11 @@ setlocal autoindent smartindent  setlocal indentexpr=GetPuppetIndent()  setlocal indentkeys+=0],0) -let b:undo_indent = " +let b:undo_indent = '      \ setlocal autoindent< smartindent< indentexpr< indentkeys< -    \" +    \' -if exists("*GetPuppetIndent") +if exists('*GetPuppetIndent')      finish  endif @@ -37,7 +37,7 @@ function! s:PartOfInclude(lnum)          if line !~ ',$'              break          endif -        if line =~ '^\s*include\s\+[^,]\+,$' && line !~ '[=>]>' +        if line =~# '^\s*include\s\+[^,]\+,$' && line !~ '[=>]>'              return 1          endif      endwhile @@ -84,7 +84,7 @@ function! GetPuppetIndent(...)      " the same indent here would be premature since for that particular case      " we want to instead get the indent level of the matching opening brace or      " parenthenses. -    if pline =~ '^\s*#' && line !~ '^\s*\(}\(,\|;\)\?$\|]:\|],\|}]\|];\?$\|)\)' +    if pline =~# '^\s*#' && line !~# '^\s*\(}\(,\|;\)\?$\|]:\|],\|}]\|];\?$\|)\)'          return ind      endif @@ -123,12 +123,12 @@ function! GetPuppetIndent(...)      endif      " Match } }, }; ] ]: ], ]; ) -    if line =~ '^\s*\(}\(,\|;\)\?$\|]:\|],\|}]\|];\?$\|)\)' +    if line =~# '^\s*\(}\(,\|;\)\?$\|]:\|],\|}]\|];\?$\|)\)'          let ind = indent(s:OpenBrace(v:lnum))      endif      " Don't actually shift over for } else { -    if line =~ '^\s*}\s*els\(e\|if\).*{\s*$' +    if line =~# '^\s*}\s*els\(e\|if\).*{\s*$'          let ind -= &sw      endif      " Don't indent resources that are one after another with a ->(ordering arrow) diff --git a/indent/ruby.vim b/indent/ruby.vim index afa72995..e4a295fd 100644 --- a/indent/ruby.vim +++ b/indent/ruby.vim @@ -93,6 +93,9 @@ let s:ruby_indent_keywords =        \ '\|\%([=,*/%+-]\|<<\|>>\|:\s\)\s*\zs' .        \    '\<\%(if\|for\|while\|until\|case\|unless\|begin\):\@!\>' +" Def without an end clause: def method_call(...) = <expression> +let s:ruby_endless_def = '\<def\s\+\k\+[!?]\=\%((.*)\|\s\)\s*=' +  " Regex used for words that, at the start of a line, remove a level of indent.  let s:ruby_deindent_keywords =        \ '^\s*\zs\<\%(ensure\|else\|rescue\|elsif\|when\|end\):\@!\>' @@ -112,10 +115,26 @@ let s:end_middle_regex = '\<\%(ensure\|else\|\%(\%(^\|;\)\s*\)\@<=\<rescue:\@!\>  " Regex that defines the end-match for the 'end' keyword.  let s:end_end_regex = '\%(^\|[^.:@$]\)\@<=\<end:\@!\>' -" Expression used for searchpair() call for finding match for 'end' keyword. -let s:end_skip_expr = s:skip_expr . -      \ ' || (expand("<cword>") == "do"' . -      \ ' && getline(".") =~ "^\\s*\\<\\(while\\|until\\|for\\):\\@!\\>")' +" Expression used for searchpair() call for finding a match for an 'end' keyword. +function! s:EndSkipExpr() +  if eval(s:skip_expr) +    return 1 +  elseif expand('<cword>') == 'do' +        \ && getline(".") =~ '^\s*\<\(while\|until\|for\):\@!\>' +    return 1 +  elseif getline('.') =~ s:ruby_endless_def +    return 1 +  elseif getline('.') =~ '\<def\s\+\k\+[!?]\=([^)]*$' +    " Then it's a `def method(` with a possible `) =` later +    call search('\<def\s\+\k\+\zs(', 'W', line('.')) +    normal! % +    return getline('.') =~ ')\s*=' +  else +    return 0 +  endif +endfunction + +let s:end_skip_expr = function('s:EndSkipExpr')  " Regex that defines continuation lines, not including (, {, or [.  let s:non_bracket_continuation_regex = @@ -575,6 +594,11 @@ function! s:AfterUnbalancedBracket(pline_info) abort        call cursor(info.plnum, closing.pos + 1)        normal! % +      if strpart(info.pline, closing.pos) =~ '^)\s*=' +        " special case: the closing `) =` of an endless def +        return indent(s:GetMSL(line('.'))) +      endif +        if s:Match(line('.'), s:ruby_indent_keywords)          return indent('.') + info.sw        else @@ -613,7 +637,7 @@ function! s:AfterIndentKeyword(pline_info) abort    let info = a:pline_info    let col = s:Match(info.plnum, s:ruby_indent_keywords) -  if col > 0 +  if col > 0 && s:Match(info.plnum, s:ruby_endless_def) <= 0      call cursor(info.plnum, col)      let ind = virtcol('.') - 1 + info.sw      " TODO: make this better (we need to count them) (or, if a searchpair @@ -660,7 +684,7 @@ function! s:IndentingKeywordInMSL(msl_info) abort    " TODO: this does not take into account contrived things such as    " module Foo; class Bar; end    let col = s:Match(info.plnum_msl, s:ruby_indent_keywords) -  if col > 0 +  if col > 0 && s:Match(info.plnum_msl, s:ruby_endless_def) <= 0      let ind = indent(info.plnum_msl) + info.sw      if s:Match(info.plnum_msl, s:end_end_regex)        let ind = ind - info.sw | 
