diff options
author | Adam Stankiewicz <sheerun@sher.pl> | 2015-03-08 21:32:50 -0700 |
---|---|---|
committer | Adam Stankiewicz <sheerun@sher.pl> | 2015-03-08 21:32:50 -0700 |
commit | 23913e0598d23ec5948b71ea78c549b39cecf764 (patch) | |
tree | f21bd3dd20a7fe0e46bed7dd11329a204fe4cc3f /indent | |
parent | 1c2123117537fb4bccf87fcf39abc05eaf950ec2 (diff) | |
download | vim-polyglot-1.12.1.tar.gz vim-polyglot-1.12.1.zip |
Updatev1.12.1
Diffstat (limited to 'indent')
-rw-r--r-- | indent/go.vim | 80 | ||||
-rw-r--r-- | indent/html.vim | 2 | ||||
-rw-r--r-- | indent/ruby.vim | 15 | ||||
-rw-r--r-- | indent/tex.vim | 4 |
4 files changed, 64 insertions, 37 deletions
diff --git a/indent/go.vim b/indent/go.vim index 660aa506..a3fa2b7a 100644 --- a/indent/go.vim +++ b/indent/go.vim @@ -9,7 +9,7 @@ " - general line splits (line ends in an operator) if exists("b:did_indent") - finish + finish endif let b:did_indent = 1 @@ -21,46 +21,58 @@ setlocal indentexpr=GoIndent(v:lnum) setlocal indentkeys+=<:>,0=},0=) if exists("*GoIndent") - finish + finish +endif + +" use shiftwidth function only if it's available +if exists('*shiftwidth') + func s:sw() + return shiftwidth() + endfunc +else + func s:sw() + return &sw + endfunc endif function! GoIndent(lnum) - let prevlnum = prevnonblank(a:lnum-1) - if prevlnum == 0 - " top of file - return 0 - endif + let prevlnum = prevnonblank(a:lnum-1) + if prevlnum == 0 + " top of file + return 0 + endif - " grab the previous and current line, stripping comments. - let prevl = substitute(getline(prevlnum), '//.*$', '', '') - let thisl = substitute(getline(a:lnum), '//.*$', '', '') - let previ = indent(prevlnum) + " grab the previous and current line, stripping comments. + let prevl = substitute(getline(prevlnum), '//.*$', '', '') + let thisl = substitute(getline(a:lnum), '//.*$', '', '') + let previ = indent(prevlnum) - let ind = previ - let s:shiftwidth = shiftwidth() + let ind = previ - if prevl =~ '[({]\s*$' - " previous line opened a block - let ind += s:shiftwidth - endif - if prevl =~# '^\s*\(case .*\|default\):$' - " previous line is part of a switch statement - let ind += s:shiftwidth - endif - " TODO: handle if the previous line is a label. + if prevl =~ '[({]\s*$' + " previous line opened a block + let ind += s:sw() + endif + if prevl =~# '^\s*\(case .*\|default\):$' + " previous line is part of a switch statement + let ind += s:sw() + endif + " TODO: handle if the previous line is a label. - if thisl =~ '^\s*[)}]' - " this line closed a block - let ind -= s:shiftwidth - endif + if thisl =~ '^\s*[)}]' + " this line closed a block + let ind -= s:sw() + endif - " Colons are tricky. - " We want to outdent if it's part of a switch ("case foo:" or "default:"). - " We ignore trying to deal with jump labels because (a) they're rare, and - " (b) they're hard to disambiguate from a composite literal key. - if thisl =~# '^\s*\(case .*\|default\):$' - let ind -= s:shiftwidth - endif + " Colons are tricky. + " We want to outdent if it's part of a switch ("case foo:" or "default:"). + " We ignore trying to deal with jump labels because (a) they're rare, and + " (b) they're hard to disambiguate from a composite literal key. + if thisl =~# '^\s*\(case .*\|default\):$' + let ind -= s:sw() + endif - return ind + return ind endfunction + +" vim:ts=4:sw=4:et diff --git a/indent/html.vim b/indent/html.vim index c8fe18e0..94baa871 100644 --- a/indent/html.vim +++ b/indent/html.vim @@ -128,8 +128,10 @@ call add(s:tags, 'nav') call add(s:tags, 'output') call add(s:tags, 'progress') call add(s:tags, 'picture') +call add(s:tags, 'rb') call add(s:tags, 'rp') call add(s:tags, 'rt') +call add(s:tags, 'rtc') call add(s:tags, 'ruby') call add(s:tags, 'section') call add(s:tags, 'source') diff --git a/indent/ruby.vim b/indent/ruby.vim index 1acde808..f0dde6fa 100644 --- a/indent/ruby.vim +++ b/indent/ruby.vim @@ -440,10 +440,14 @@ function GetRubyIndent(...) if strpart(line, 0, col('.') - 1) =~ '=\s*$' && \ strpart(line, col('.') - 1, 2) !~ 'do' + " assignment to case/begin/etc, on the same line, hanging indent let ind = virtcol('.') - 1 elseif getline(msl) =~ '=\s*\(#.*\)\=$' + " in the case of assignment to the msl, align to the starting line, + " not to the msl let ind = indent(line('.')) else + " align to the msl let ind = indent(msl) endif endif @@ -508,7 +512,16 @@ function GetRubyIndent(...) " If the previous line ended with a block opening, add a level of indent. if s:Match(lnum, s:block_regex) - return indent(s:GetMSL(lnum)) + sw + let msl = s:GetMSL(lnum) + + if getline(msl) =~ '=\s*\(#.*\)\=$' + " in the case of assignment to the msl, align to the starting line, + " not to the msl + let ind = indent(lnum) + sw + else + let ind = indent(msl) + sw + endif + return ind endif " If the previous line started with a leading operator, use its MSL's level diff --git a/indent/tex.vim b/indent/tex.vim index 93f70ece..e7653d03 100644 --- a/indent/tex.vim +++ b/indent/tex.vim @@ -17,8 +17,8 @@ let s:list_envs = ['itemize', 'enumerate', 'description'] " indent on \left( and on \(, but not on ( " indent on \left[ and on \[, but not on [ " indent on \left\{ and on {, but not on \{ -let s:open_pat = '\\\@<!\%(\\begin\|\\left\|\\(\|\\\[\|{\)' -let s:close_pat = '\\\@<!\%(\\end\|\\right\|\\)\|\\\]\|}\)' +let s:open_pat = '\\\@<!\%(\\begin\|\\left\a\@!\|\\(\|\\\[\|{\)' +let s:close_pat = '\\\@<!\%(\\end\|\\right\a\@!\|\\)\|\\\]\|}\)' let s:list_open_pat = '\\\@<!\\begin{\%(' . join(s:list_envs, '\|') . '\)}' let s:list_close_pat = '\\\@<!\\end{\%(' . join(s:list_envs, '\|') . '\)}' |