summaryrefslogtreecommitdiffstats
path: root/indent
diff options
context:
space:
mode:
Diffstat (limited to 'indent')
-rw-r--r--indent/elixir.vim10
-rw-r--r--indent/eruby.vim21
-rw-r--r--indent/html.vim2
-rw-r--r--indent/javascript.vim56
-rw-r--r--indent/ruby.vim35
5 files changed, 101 insertions, 23 deletions
diff --git a/indent/elixir.vim b/indent/elixir.vim
index 3563f44a..92b98460 100644
--- a/indent/elixir.vim
+++ b/indent/elixir.vim
@@ -12,7 +12,6 @@ setlocal nosmartindent
setlocal indentexpr=GetElixirIndent()
setlocal indentkeys+=0=end,0=else,0=match,0=elsif,0=catch,0=after,0=rescue
-setlocal indentkeys+==->
if exists("*GetElixirIndent")
finish
@@ -69,9 +68,16 @@ function! GetElixirIndent()
endif
" if line starts with pipeline
+ " and last line contains pipeline(s)
+ " align them
+ if last_line =~ '|>.*$' &&
+ \ current_line =~ s:pipeline
+ let ind = float2nr(match(last_line, '|>') / &sw) * &sw
+
+ " if line starts with pipeline
" and last line is an attribution
" indents pipeline in same level as attribution
- if current_line =~ s:pipeline &&
+ elseif current_line =~ s:pipeline &&
\ last_line =~ '^[^=]\+=.\+$'
let b:old_ind = ind
let ind = float2nr(matchend(last_line, '=\s*[^ ]') / &sw) * &sw
diff --git a/indent/eruby.vim b/indent/eruby.vim
index 5f323857..5028fe06 100644
--- a/indent/eruby.vim
+++ b/indent/eruby.vim
@@ -42,6 +42,13 @@ if exists("*GetErubyIndent")
endif
function! GetErubyIndent(...)
+ " The value of a single shift-width
+ if exists('*shiftwidth')
+ let sw = shiftwidth()
+ else
+ let sw = &sw
+ endif
+
if a:0 && a:1 == '.'
let v:lnum = line('.')
elseif a:0 && a:1 =~ '^\d'
@@ -70,24 +77,24 @@ function! GetErubyIndent(...)
let line = getline(lnum)
let cline = getline(v:lnum)
if cline =~# '^\s*<%[-=]\=\s*\%(}\|end\|else\|\%(ensure\|rescue\|elsif\|when\).\{-\}\)\s*\%([-=]\=%>\|$\)'
- let ind = ind - &sw
+ let ind = ind - sw
endif
if line =~# '\S\s*<%[-=]\=\s*\%(}\|end\).\{-\}\s*\%([-=]\=%>\|$\)'
- let ind = ind - &sw
+ let ind = ind - sw
endif
if line =~# '\%({\|\<do\)\%(\s*|[^|]*|\)\=\s*[-=]\=%>'
- let ind = ind + &sw
+ let ind = ind + sw
elseif line =~# '<%[-=]\=\s*\%(module\|class\|def\|if\|for\|while\|until\|else\|elsif\|case\|when\|unless\|begin\|ensure\|rescue\)\>.*%>'
- let ind = ind + &sw
+ let ind = ind + sw
endif
if line =~# '^\s*<%[=#-]\=\s*$' && cline !~# '^\s*end\>'
- let ind = ind + &sw
+ let ind = ind + sw
endif
if line !~# '^\s*<%' && line =~# '%>\s*$'
- let ind = ind - &sw
+ let ind = ind - sw
endif
if cline =~# '^\s*[-=]\=%>\s*$'
- let ind = ind - &sw
+ let ind = ind - sw
endif
return ind
endfunction
diff --git a/indent/html.vim b/indent/html.vim
index 769f6318..c8fe18e0 100644
--- a/indent/html.vim
+++ b/indent/html.vim
@@ -127,10 +127,12 @@ call add(s:tags, 'meter')
call add(s:tags, 'nav')
call add(s:tags, 'output')
call add(s:tags, 'progress')
+call add(s:tags, 'picture')
call add(s:tags, 'rp')
call add(s:tags, 'rt')
call add(s:tags, 'ruby')
call add(s:tags, 'section')
+call add(s:tags, 'source')
call add(s:tags, 'summary')
call add(s:tags, 'time')
call add(s:tags, 'video')
diff --git a/indent/javascript.vim b/indent/javascript.vim
index 29fba2ba..5cde88d1 100644
--- a/indent/javascript.vim
+++ b/indent/javascript.vim
@@ -15,6 +15,7 @@ setlocal nosmartindent
" Now, set up our indentation expression and keys that trigger it.
setlocal indentexpr=GetJavascriptIndent()
+setlocal formatexpr=Fixedgq(v:lnum,v:count)
setlocal indentkeys=0{,0},0),0],0\,,!^F,o,O,e
" Only define the function once.
@@ -437,3 +438,58 @@ endfunction
let &cpo = s:cpo_save
unlet s:cpo_save
+
+function! Fixedgq(lnum, count)
+ let l:tw = &tw ? &tw : 80;
+
+ let l:count = a:count
+
+ if mode() == 'i' " gq was not pressed, but tw was set
+ return 1
+ endif
+
+ if len(getline(a:lnum)) < l:tw && l:count == 1 " No need for gq
+ return 1
+ endif
+
+ " Put all the lines on one line and do normal spliting after that
+ if l:count > 1
+ while l:count > 1
+ let l:count -= 1
+ normal J
+ endwhile
+ endif
+
+ let l:winview = winsaveview()
+
+ call cursor(a:lnum, l:tw + 1)
+ let orig_breakpoint = searchpairpos(' ', '', '\.', 'bcW', '', a:lnum)
+ call cursor(a:lnum, l:tw + 1)
+ let breakpoint = searchpairpos(' ', '', '\.', 'bcW', s:skip_expr, a:lnum)
+
+ " No need for special treatment, normal gq handles edgecases better
+ if breakpoint[1] == orig_breakpoint[1]
+ call winrestview(l:winview)
+ return 1
+ endif
+
+ " Try breaking after string
+ if breakpoint[1] <= indent(a:lnum)
+ call cursor(a:lnum, l:tw + 1)
+ let breakpoint = searchpairpos('\.', '', ' ', 'cW', s:skip_expr, a:lnum)
+ endif
+
+
+ if breakpoint[1] != 0
+ call feedkeys("r\<CR>")
+ else
+ let l:count = l:count - 1
+ endif
+
+ " run gq on new lines
+ if l:count == 1
+ call feedkeys("gqq")
+ endif
+
+ return 0
+endfunction
diff --git a/indent/ruby.vim b/indent/ruby.vim
index f2059982..1acde808 100644
--- a/indent/ruby.vim
+++ b/indent/ruby.vim
@@ -369,6 +369,13 @@ function GetRubyIndent(...)
" 3.1. Setup {{{2
" ----------
+ " The value of a single shift-width
+ if exists('*shiftwidth')
+ let sw = shiftwidth()
+ else
+ let sw = &sw
+ endif
+
" For the current line, use the first argument if given, else v:lnum
let clnum = a:0 ? a:1 : v:lnum
@@ -388,7 +395,7 @@ function GetRubyIndent(...)
if s:Match(clnum, s:access_modifier_regex)
let class_line = s:FindContainingClass()
if class_line > 0
- return indent(class_line) + &sw
+ return indent(class_line) + sw
endif
endif
elseif g:ruby_indent_access_modifier_style == 'outdent'
@@ -458,7 +465,7 @@ function GetRubyIndent(...)
" If the current line starts with a leading operator, add a level of indent.
if s:Match(clnum, s:leading_operator_regex)
- return indent(s:GetMSL(clnum)) + &sw
+ return indent(s:GetMSL(clnum)) + sw
endif
" 3.3. Work on the previous line. {{{2
@@ -485,23 +492,23 @@ function GetRubyIndent(...)
" If the previous line was a private/protected keyword, add a
" level of indent.
if s:Match(lnum, s:indent_access_modifier_regex)
- return indent(lnum) + &sw
+ return indent(lnum) + sw
endif
elseif g:ruby_indent_access_modifier_style == 'outdent'
" If the previous line was a private/protected/public keyword, add
" a level of indent, since the keyword has been out-dented.
if s:Match(lnum, s:access_modifier_regex)
- return indent(lnum) + &sw
+ return indent(lnum) + sw
endif
endif
if s:Match(lnum, s:continuable_regex) && s:Match(lnum, s:continuation_regex)
- return indent(s:GetMSL(lnum)) + &sw + &sw
+ return indent(s:GetMSL(lnum)) + sw + sw
endif
" 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
+ return indent(s:GetMSL(lnum)) + sw
endif
" If the previous line started with a leading operator, use its MSL's level
@@ -512,7 +519,7 @@ function GetRubyIndent(...)
" If the previous line ended with the "*" of a splat, add a level of indent
if line =~ s:splat_regex
- return indent(lnum) + &sw
+ return indent(lnum) + sw
endif
" If the previous line contained unclosed opening brackets and we are still
@@ -527,20 +534,20 @@ function GetRubyIndent(...)
if opening.pos != -1
if opening.type == '(' && searchpair('(', '', ')', 'bW', s:skip_expr) > 0
if col('.') + 1 == col('$')
- return ind + &sw
+ return ind + sw
else
return virtcol('.')
endif
else
let nonspace = matchend(line, '\S', opening.pos + 1) - 1
- return nonspace > 0 ? nonspace : ind + &sw
+ return nonspace > 0 ? nonspace : ind + sw
endif
elseif closing.pos != -1
call cursor(lnum, closing.pos + 1)
normal! %
if s:Match(line('.'), s:ruby_indent_keywords)
- return indent('.') + &sw
+ return indent('.') + sw
else
return indent('.')
endif
@@ -569,7 +576,7 @@ function GetRubyIndent(...)
let col = s:Match(lnum, s:ruby_indent_keywords)
if col > 0
call cursor(lnum, col)
- let ind = virtcol('.') - 1 + &sw
+ let ind = virtcol('.') - 1 + sw
" TODO: make this better (we need to count them) (or, if a searchpair
" fails, we know that something is lacking an end and thus we indent a
" level
@@ -606,9 +613,9 @@ function GetRubyIndent(...)
" TODO: this does not take into account contrived things such as
" module Foo; class Bar; end
if s:Match(lnum, s:ruby_indent_keywords)
- let ind = msl_ind + &sw
+ let ind = msl_ind + sw
if s:Match(lnum, s:end_end_regex)
- let ind = ind - &sw
+ let ind = ind - sw
endif
return ind
endif
@@ -617,7 +624,7 @@ function GetRubyIndent(...)
" closing bracket, indent one extra level.
if s:Match(lnum, s:non_bracket_continuation_regex) && !s:Match(lnum, '^\s*\([\])}]\|end\)')
if lnum == p_lnum
- let ind = msl_ind + &sw
+ let ind = msl_ind + sw
else
let ind = msl_ind
endif