summaryrefslogtreecommitdiffstats
path: root/indent
diff options
context:
space:
mode:
Diffstat (limited to 'indent')
-rw-r--r--indent/go.vim80
-rw-r--r--indent/html.vim2
-rw-r--r--indent/ruby.vim15
-rw-r--r--indent/tex.vim4
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, '\|') . '\)}'