aboutsummaryrefslogtreecommitdiff
path: root/runtime/indent
diff options
context:
space:
mode:
Diffstat (limited to 'runtime/indent')
-rw-r--r--runtime/indent/ada.vim22
-rw-r--r--runtime/indent/awk.vim6
-rw-r--r--runtime/indent/bst.vim4
-rw-r--r--runtime/indent/bzl.vim9
-rw-r--r--runtime/indent/cdl.vim18
-rw-r--r--runtime/indent/chaiscript.vim6
-rw-r--r--runtime/indent/clojure.vim8
-rw-r--r--runtime/indent/cmake.vim8
-rw-r--r--runtime/indent/cobol.vim24
-rw-r--r--runtime/indent/cucumber.vim4
-rw-r--r--runtime/indent/dylan.vim12
-rw-r--r--runtime/indent/erlang.vim32
-rw-r--r--runtime/indent/eruby.vim6
-rw-r--r--runtime/indent/falcon.vim16
-rw-r--r--runtime/indent/gitconfig.vim4
-rw-r--r--runtime/indent/gitolite.vim8
-rw-r--r--runtime/indent/go.vim22
-rw-r--r--runtime/indent/haml.vim4
-rw-r--r--runtime/indent/hamster.vim4
-rw-r--r--runtime/indent/hog.vim6
-rw-r--r--runtime/indent/html.vim57
-rw-r--r--runtime/indent/idlang.vim14
-rw-r--r--runtime/indent/ishd.vim8
-rw-r--r--runtime/indent/javascript.vim250
-rw-r--r--runtime/indent/json.vim6
-rw-r--r--runtime/indent/liquid.vim4
-rw-r--r--runtime/indent/logtalk.vim12
-rw-r--r--runtime/indent/lua.vim6
-rw-r--r--runtime/indent/matlab.vim8
-rw-r--r--runtime/indent/mma.vim2
-rw-r--r--runtime/indent/ocaml.vim12
-rw-r--r--runtime/indent/occam.vim6
-rw-r--r--runtime/indent/pascal.vim28
-rw-r--r--runtime/indent/perl.vim16
-rw-r--r--runtime/indent/perl6.vim10
-rw-r--r--runtime/indent/php.vim105
-rw-r--r--runtime/indent/postscr.vim6
-rw-r--r--runtime/indent/pov.vim6
-rw-r--r--runtime/indent/prolog.vim8
-rw-r--r--runtime/indent/r.vim28
-rw-r--r--runtime/indent/rhelp.vim2
-rw-r--r--runtime/indent/rpl.vim8
-rw-r--r--runtime/indent/ruby.vim6
-rw-r--r--runtime/indent/rust.vim213
-rw-r--r--runtime/indent/sass.vim4
-rw-r--r--runtime/indent/sdl.vim6
-rw-r--r--runtime/indent/sh.vim19
-rw-r--r--runtime/indent/sml.vim14
-rw-r--r--runtime/indent/sqlanywhere.vim24
-rw-r--r--runtime/indent/systemverilog.vim2
-rw-r--r--runtime/indent/teraterm.vim18
-rw-r--r--runtime/indent/tex.vim137
-rw-r--r--runtime/indent/tilde.vim4
-rw-r--r--runtime/indent/vb.vim10
-rw-r--r--runtime/indent/vhdl.vim36
-rw-r--r--runtime/indent/xml.vim4
-rw-r--r--runtime/indent/yaml.vim14
57 files changed, 773 insertions, 563 deletions
diff --git a/runtime/indent/ada.vim b/runtime/indent/ada.vim
index 575f326454..1ca7fbacbe 100644
--- a/runtime/indent/ada.vim
+++ b/runtime/indent/ada.vim
@@ -87,7 +87,7 @@ function s:MainBlockIndent (prev_indent, prev_lnum, blockstart, stop_at)
endwhile
endwhile
" Fallback - just move back one
- return a:prev_indent - &sw
+ return a:prev_indent - shiftwidth()
endfunction MainBlockIndent
" Section: s:EndBlockIndent {{{1
@@ -131,7 +131,7 @@ function s:EndBlockIndent( prev_indent, prev_lnum, blockstart, blockend )
endwhile
endwhile
" Fallback - just move back one
- return a:prev_indent - &sw
+ return a:prev_indent - shiftwidth()
endfunction EndBlockIndent
" Section: s:StatementIndent {{{1
@@ -213,15 +213,15 @@ function GetAdaIndent()
endif
" Move indent in
if ! false_match
- let ind = ind + &sw
+ let ind = ind + shiftwidth()
endif
elseif line =~ '^\s*\(case\|exception\)\>'
" Move indent in twice (next 'when' will move back)
- let ind = ind + 2 * &sw
+ let ind = ind + 2 * shiftwidth()
elseif line =~ '^\s*end\s*record\>'
- " Move indent back to tallying 'type' preceding the 'record'.
+ " Move indent back to tallying 'type' preceeding the 'record'.
" Allow indent to be equal to 'end record's.
- let ind = s:MainBlockIndent( ind+&sw, lnum, 'type\>', '' )
+ let ind = s:MainBlockIndent( ind+shiftwidth(), lnum, 'type\>', '' )
elseif line =~ '\(^\s*new\>.*\)\@<!)\s*[;,]\s*$'
" Revert to indent of line that started this parenthesis pair
exe lnum
@@ -235,10 +235,10 @@ function GetAdaIndent()
exe v:lnum
elseif line =~ '[.=(]\s*$'
" A statement continuation - move in one
- let ind = ind + &sw
+ let ind = ind + shiftwidth()
elseif line =~ '^\s*new\>'
" Multiple line generic instantiation ('package blah is\nnew thingy')
- let ind = s:StatementIndent( ind - &sw, lnum )
+ let ind = s:StatementIndent( ind - shiftwidth(), lnum )
elseif line =~ ';\s*$'
" Statement end (but not 'end' ) - try to find current statement-start indent
let ind = s:StatementIndent( ind, lnum )
@@ -256,17 +256,17 @@ function GetAdaIndent()
elseif continuation && line =~ '^\s*('
" Don't do this if we've already indented due to the previous line
if ind == initind
- let ind = ind + &sw
+ let ind = ind + shiftwidth()
endif
elseif line =~ '^\s*\(begin\|is\)\>'
let ind = s:MainBlockIndent( ind, lnum, '\(procedure\|function\|declare\|package\|task\)\>', 'begin\>' )
elseif line =~ '^\s*record\>'
- let ind = s:MainBlockIndent( ind, lnum, 'type\>\|for\>.*\<use\>', '' ) + &sw
+ let ind = s:MainBlockIndent( ind, lnum, 'type\>\|for\>.*\<use\>', '' ) + shiftwidth()
elseif line =~ '^\s*\(else\|elsif\)\>'
let ind = s:MainBlockIndent( ind, lnum, 'if\>', '' )
elseif line =~ '^\s*when\>'
" Align 'when' one /in/ from matching block start
- let ind = s:MainBlockIndent( ind, lnum, '\(case\|exception\)\>', '' ) + &sw
+ let ind = s:MainBlockIndent( ind, lnum, '\(case\|exception\)\>', '' ) + shiftwidth()
elseif line =~ '^\s*end\>\s*\<if\>'
" End of if statements
let ind = s:EndBlockIndent( ind, lnum, 'if\>', 'end\>\s*\<if\>' )
diff --git a/runtime/indent/awk.vim b/runtime/indent/awk.vim
index 6f6b70cc4e..aad73ee71f 100644
--- a/runtime/indent/awk.vim
+++ b/runtime/indent/awk.vim
@@ -60,7 +60,7 @@ function! GetAwkIndent()
" 'pattern { action }' (simple check match on /{/ increases the indent then)
if s:Get_brace_balance( prev_data, '{', '}' ) > 0
- return ind + &sw
+ return ind + shiftwidth()
endif
let brace_balance = s:Get_brace_balance( prev_data, '(', ')' )
@@ -99,7 +99,7 @@ function! GetAwkIndent()
return s:Safe_indent( ind, s:First_word_len(prev_data), getline(v:lnum))
else
" if/for/while without '{'
- return ind + &sw
+ return ind + shiftwidth()
endif
endif
endif
@@ -140,7 +140,7 @@ function! GetAwkIndent()
" Decrease indent if this line contains a '}'.
if getline(v:lnum) =~ '^\s*}'
- let ind = ind - &sw
+ let ind = ind - shiftwidth()
endif
return ind
diff --git a/runtime/indent/bst.vim b/runtime/indent/bst.vim
index be1f63e8e9..47e3058810 100644
--- a/runtime/indent/bst.vim
+++ b/runtime/indent/bst.vim
@@ -69,7 +69,7 @@ function! GetBstIndent(lnum) abort
endif
let fakeline = substitute(line,'^}','','').matchstr(cline,'^}')
let ind = indent(lnum)
- let ind = ind + &sw * s:count(line,'{')
- let ind = ind - &sw * s:count(fakeline,'}')
+ let ind = ind + shiftwidth() * s:count(line,'{')
+ let ind = ind - shiftwidth() * s:count(fakeline,'}')
return ind
endfunction
diff --git a/runtime/indent/bzl.vim b/runtime/indent/bzl.vim
index 24e5b870cd..6904bfdedb 100644
--- a/runtime/indent/bzl.vim
+++ b/runtime/indent/bzl.vim
@@ -1,7 +1,7 @@
" Vim indent file
" Language: Bazel (http://bazel.io)
" Maintainer: David Barnett (https://github.com/google/vim-ft-bzl)
-" Last Change: 2015 Aug 11
+" Last Change: 2017 Jun 13
if exists('b:did_indent')
finish
@@ -41,11 +41,8 @@ function GetBzlIndent(lnum) abort
if exists('g:pyindent_open_paren')
let l:pyindent_open_paren = g:pyindent_open_paren
endif
- " Vim 7.3.693 and later defines a shiftwidth() function to get the effective
- " shiftwidth value. Fall back to &shiftwidth if the function doesn't exist.
- let l:sw_expr = exists('*shiftwidth') ? 'shiftwidth()' : '&shiftwidth'
- let g:pyindent_nested_paren = l:sw_expr . ' * 2'
- let g:pyindent_open_paren = l:sw_expr . ' * 2'
+ let g:pyindent_nested_paren = 'shiftwidth() * 2'
+ let g:pyindent_open_paren = 'shiftwidth() * 2'
endif
let l:indent = -1
diff --git a/runtime/indent/cdl.vim b/runtime/indent/cdl.vim
index 5ec2a7b21a..5fae7b9046 100644
--- a/runtime/indent/cdl.vim
+++ b/runtime/indent/cdl.vim
@@ -47,7 +47,7 @@ fun! CdlGetIndent(lnum)
let thisline = getline(a:lnum)
if match(thisline, '^\s*\(\k\+\|\[[^]]*]\)\s*\(,\|;\s*$\)') >= 0
" it's an attributes line
- return &sw
+ return shiftwidth()
elseif match(thisline, '^\c\s*\([{}]\|\/[*/]\|dimension\|schedule\|group\|hierarchy\|class\)') >= 0
" it's a header or '{' or '}' or a comment
return 0
@@ -71,13 +71,13 @@ fun! CdlGetIndent(lnum)
let c = line[inicio-1]
" ')' and '=' don't change indent and are useless to set 'f'
if c == '{'
- return &sw
+ return shiftwidth()
elseif c != ')' && c != '='
let f = 1 " all but 'elseif' are followed by a formula
if c ==? 'n' || c ==? 'e' " 'then', 'else'
- let ind = ind + &sw
+ let ind = ind + shiftwidth()
elseif strpart(line, inicio-6, 6) ==? 'elseif' " elseif, set f to conditional
- let ind = ind + &sw
+ let ind = ind + shiftwidth()
let f = 0
end
end
@@ -98,16 +98,16 @@ fun! CdlGetIndent(lnum)
let ind = 0
let f = 1
elseif c == ')' || c== ';' || strpart(line, inicio-5, 5) ==? 'endif'
- let ind = ind - &sw
+ let ind = ind - shiftwidth()
elseif c == '(' || c ==? 'f' " '(' or 'if'
- let ind = ind + &sw
+ let ind = ind + shiftwidth()
else " c == '='
" if it is an asignment increase indent
if f == -1 " we don't know yet, find out
let f = CdlAsignment(lnum, strpart(line, 0, inicio))
end
if f == 1 " formula increase it
- let ind = ind + &sw
+ let ind = ind + shiftwidth()
end
end
endw
@@ -115,13 +115,13 @@ fun! CdlGetIndent(lnum)
" CURRENT LINE, if it starts with a closing element, decrease indent
" or if it starts with '=' (asignment), increase indent
if match(thisline, '^\c\s*\(else\|then\|endif\|[);]\)') >= 0
- let ind = ind - &sw
+ let ind = ind - shiftwidth()
elseif match(thisline, '^\s*=') >= 0
if f == -1 " we don't know yet if is an asignment, find out
let f = CdlAsignment(lnum, "")
end
if f == 1 " formula increase it
- let ind = ind + &sw
+ let ind = ind + shiftwidth()
end
end
diff --git a/runtime/indent/chaiscript.vim b/runtime/indent/chaiscript.vim
index 247e1a6e4c..445281cc46 100644
--- a/runtime/indent/chaiscript.vim
+++ b/runtime/indent/chaiscript.vim
@@ -31,19 +31,19 @@ function! GetChaiScriptIndent()
let flag = 0
let prevline = getline(lnum)
if prevline =~ '^.*{.*'
- let ind = ind + &shiftwidth
+ let ind = ind + shiftwidth()
let flag = 1
endif
" Subtract a 'shiftwidth' after lines containing a { followed by a }
" to keep it balanced
if flag == 1 && prevline =~ '.*{.*}.*'
- let ind = ind - &shiftwidth
+ let ind = ind - shiftwidth()
endif
" Subtract a 'shiftwidth' on lines ending with }
if getline(v:lnum) =~ '^\s*\%(}\)'
- let ind = ind - &shiftwidth
+ let ind = ind - shiftwidth()
endif
return ind
diff --git a/runtime/indent/clojure.vim b/runtime/indent/clojure.vim
index 7592b10d7d..7c4186e29b 100644
--- a/runtime/indent/clojure.vim
+++ b/runtime/indent/clojure.vim
@@ -261,7 +261,7 @@ if exists("*searchpairpos")
call cursor(paren)
if s:is_method_special_case(paren)
- return [paren[0], paren[1] + &shiftwidth - 1]
+ return [paren[0], paren[1] + shiftwidth() - 1]
endif
if s:is_reader_conditional_special_case(paren)
@@ -299,19 +299,19 @@ if exists("*searchpairpos")
let ww = s:strip_namespace_and_macro_chars(w)
if &lispwords =~# '\V\<' . ww . '\>'
- return [paren[0], paren[1] + &shiftwidth - 1]
+ return [paren[0], paren[1] + shiftwidth() - 1]
endif
if g:clojure_fuzzy_indent
\ && !s:match_one(g:clojure_fuzzy_indent_blacklist, ww)
\ && s:match_one(g:clojure_fuzzy_indent_patterns, ww)
- return [paren[0], paren[1] + &shiftwidth - 1]
+ return [paren[0], paren[1] + shiftwidth() - 1]
endif
call search('\v\_s', 'cW')
call search('\v\S', 'W')
if paren[0] < line(".")
- return [paren[0], paren[1] + (g:clojure_align_subforms ? 0 : &shiftwidth - 1)]
+ return [paren[0], paren[1] + (g:clojure_align_subforms ? 0 : shiftwidth() - 1)]
endif
call search('\v\S', 'bW')
diff --git a/runtime/indent/cmake.vim b/runtime/indent/cmake.vim
index 421afcb6d7..93a131b938 100644
--- a/runtime/indent/cmake.vim
+++ b/runtime/indent/cmake.vim
@@ -68,19 +68,19 @@ fun! CMakeGetIndent(lnum)
let ind = ind
else
if previous_line =~? cmake_indent_begin_regex
- let ind = ind + &sw
+ let ind = ind + shiftwidth()
endif
if previous_line =~? cmake_indent_open_regex
- let ind = ind + &sw
+ let ind = ind + shiftwidth()
endif
endif
" Subtract
if this_line =~? cmake_indent_end_regex
- let ind = ind - &sw
+ let ind = ind - shiftwidth()
endif
if previous_line =~? cmake_indent_close_regex
- let ind = ind - &sw
+ let ind = ind - shiftwidth()
endif
return ind
diff --git a/runtime/indent/cobol.vim b/runtime/indent/cobol.vim
index 8dce3cd014..c08444ac40 100644
--- a/runtime/indent/cobol.vim
+++ b/runtime/indent/cobol.vim
@@ -52,11 +52,11 @@ function! s:optionalblock(lnum,ind,blocks,clauses)
if getline(lastclause) =~? clauses && s:stripped(lastclause) !~? '^'.begin
let ind = indent(lastclause)
elseif lastclause > 0
- let ind = indent(lastclause) + &sw
- "let ind = ind + &sw
+ let ind = indent(lastclause) + shiftwidth()
+ "let ind = ind + shiftwidth()
endif
elseif line =~? clauses && cline !~? end
- let ind = ind + &sw
+ let ind = ind + shiftwidth()
endif
return ind
endfunction
@@ -98,8 +98,8 @@ function! GetCobolIndent(lnum) abort
let num = matchstr(line,'^\s*\zs\d\+\>')
if 0+cnum == num
return lindent
- elseif 0+cnum > num && default < lindent + &sw
- let default = lindent + &sw
+ elseif 0+cnum > num && default < lindent + shiftwidth()
+ let default = lindent + shiftwidth()
endif
elseif lindent < bshft && lindent >= ashft
break
@@ -135,13 +135,13 @@ function! GetCobolIndent(lnum) abort
if line =~? '^PERFORM\>'
let perfline = substitute(line, '\c^PERFORM\s*', "", "")
if perfline =~? '^\%(\k\+\s\+TIMES\)\=\s*$'
- let ind = ind + &sw
+ let ind = ind + shiftwidth()
elseif perfline =~? '^\%(WITH\s\+TEST\|VARYING\|UNTIL\)\>.*[^.]$'
- let ind = ind + &sw
+ let ind = ind + shiftwidth()
endif
endif
if line =~? '^\%(IF\|THEN\|ELSE\|READ\|EVALUATE\|SEARCH\|SELECT\)\>'
- let ind = ind + &sw
+ let ind = ind + shiftwidth()
endif
let ind = s:optionalblock(a:lnum,ind,'ADD\|COMPUTE\|DIVIDE\|MULTIPLY\|SUBTRACT','ON\s\+SIZE\s\+ERROR')
let ind = s:optionalblock(a:lnum,ind,'STRING\|UNSTRING\|ACCEPT\|DISPLAY\|CALL','ON\s\+OVERFLOW\|ON\s\+EXCEPTION')
@@ -157,10 +157,10 @@ function! GetCobolIndent(lnum) abort
"&& s:stripped(lastclause) !~? '^\%(SEARCH\|EVALUATE\|READ\)\>'
let ind = indent(lastclause)
elseif lastclause > 0
- let ind = indent(lastclause) + &sw
+ let ind = indent(lastclause) + shiftwidth()
endif
elseif line =~? '^WHEN\>'
- let ind = ind + &sw
+ let ind = ind + shiftwidth()
endif
"I'm not sure why I had this
"if line =~? '^ELSE\>-\@!' && line !~? '\.$'
@@ -168,7 +168,7 @@ function! GetCobolIndent(lnum) abort
"endif
if cline =~? '^\(END\)\>-\@!'
" On lines with just END, 'guess' a simple shift left
- let ind = ind - &sw
+ let ind = ind - shiftwidth()
elseif cline =~? '^\(END-IF\|THEN\|ELSE\)\>-\@!'
call cursor(a:lnum,indent(a:lnum))
let match = searchpair('\c-\@<!\<IF\>','\c-\@<!\%(THEN\|ELSE\)\>','\c-\@<!\<END-IF\>\zs','bnW',s:skip)
@@ -209,7 +209,7 @@ function! GetCobolIndent(lnum) abort
if match > 0
let ind = indent(match)
elseif cline =~? '^\(END-\(READ\|EVALUATE\|SEARCH\|PERFORM\)\)\>'
- let ind = ind - &sw
+ let ind = ind - shiftwidth()
endif
endif
return ind < bshft ? bshft : ind
diff --git a/runtime/indent/cucumber.vim b/runtime/indent/cucumber.vim
index 999b8d6a76..ad28a67a0d 100644
--- a/runtime/indent/cucumber.vim
+++ b/runtime/indent/cucumber.vim
@@ -1,7 +1,7 @@
" Vim indent file
" Language: Cucumber
" Maintainer: Tim Pope <vimNOSPAM@tpope.org>
-" Last Change: 2016 Aug 29
+" Last Change: 2017 Jun 13
if exists("b:did_indent")
finish
@@ -27,7 +27,7 @@ function! GetCucumberIndent()
let line = getline(prevnonblank(v:lnum-1))
let cline = getline(v:lnum)
let nline = getline(nextnonblank(v:lnum+1))
- let sw = exists('*shiftwidth') ? shiftwidth() : &sw
+ let sw = exists('*shiftwidth') ? shiftwidth() : shiftwidth()
let syn = s:syn(prevnonblank(v:lnum-1))
let csyn = s:syn(v:lnum)
let nsyn = s:syn(nextnonblank(v:lnum+1))
diff --git a/runtime/indent/dylan.vim b/runtime/indent/dylan.vim
index 0afcbeada7..6811ec4af5 100644
--- a/runtime/indent/dylan.vim
+++ b/runtime/indent/dylan.vim
@@ -1,7 +1,7 @@
" Vim indent file
" Language: Dylan
" Version: 0.01
-" Last Change: 2003 Feb 04
+" Last Change: 2017 Jun 13
" Maintainer: Brent A. Fulgham <bfulgham@debian.org>
" Only load this indent file when no other was loaded.
@@ -45,13 +45,13 @@ function DylanGetIndent()
" If previous line was a 'define', indent
if prevline =~? '\(^\s*\(begin\|block\|case\|define\|else\|elseif\|for\|finally\|if\|select\|unless\|while\)\|\s*\S*\s*=>$\)'
- let chg = &sw
+ let chg = shiftwidth()
" local methods indent the shift-width, plus 6 for the 'local'
elseif prevline =~? '^\s*local'
- let chg = &sw + 6
+ let chg = shiftwidth() + 6
" If previous line was a let with no closing semicolon, indent
elseif prevline =~? '^\s*let.*[^;]\s*$'
- let chg = &sw
+ let chg = shiftwidth()
" If previous line opened a parenthesis, and did not close it, indent
elseif prevline =~ '^.*(\s*[^)]*\((.*)\)*[^)]*$'
return = match( prevline, '(.*\((.*)\|[^)]\)*.*$') + 1
@@ -75,13 +75,13 @@ function DylanGetIndent()
" line doesn't start with an indentable command:
let curr_str = getline(curr_line)
if curr_str =~? '^\s*\(begin\|block\|case\|define\|else\|elseif\|for\|finally\|if\|select\|unless\|while\)'
- let chg = &sw
+ let chg = shiftwidth()
endif
endif
" If a line starts with end, un-indent (even if we just indented!)
if cline =~? '^\s*\(cleanup\|end\|else\|elseif\|exception\|finally\|otherwise\)'
- let chg = chg - &sw
+ let chg = chg - shiftwidth()
endif
return ind + chg
diff --git a/runtime/indent/erlang.vim b/runtime/indent/erlang.vim
index 7569fe9106..9228f18683 100644
--- a/runtime/indent/erlang.vim
+++ b/runtime/indent/erlang.vim
@@ -669,7 +669,7 @@ function! s:BeginningOfClauseFound(stack, token, stored_vcol)
call s:Pop(a:stack)
if empty(a:stack)
call s:Log(' Stack is ["when"], so LTI is in a guard -> return')
- return [1, a:stored_vcol + &sw + 2]
+ return [1, a:stored_vcol + shiftwidth() + 2]
else
return [1, s:UnexpectedToken(a:token, a:stack)]
endif
@@ -678,7 +678,7 @@ function! s:BeginningOfClauseFound(stack, token, stored_vcol)
call s:Pop(a:stack)
if empty(a:stack)
call s:Log(' Stack is ["->"], so LTI is in function body -> return')
- return [1, a:stored_vcol + &sw]
+ return [1, a:stored_vcol + shiftwidth()]
elseif a:stack[0] ==# ';'
call s:Pop(a:stack)
if empty(a:stack)
@@ -797,7 +797,7 @@ function! s:ErlangCalcIndent2(lnum, stack)
elseif token ==# 'begin'
let [ret, res] = s:BeginElementFound(stack, token, curr_vcol,
- \stored_vcol, 'end', &sw)
+ \stored_vcol, 'end', shiftwidth())
if ret | return res | endif
" case EXPR of BRANCHES end
@@ -848,11 +848,11 @@ function! s:ErlangCalcIndent2(lnum, stack)
elseif stack == ['->']
call s:Log(' LTI is in a branch after ' .
\'"of/receive/after/if/catch" -> return')
- return stored_vcol + &sw
+ return stored_vcol + shiftwidth()
elseif stack == ['when']
call s:Log(' LTI is in a guard after ' .
\'"of/receive/after/if/catch" -> return')
- return stored_vcol + &sw
+ return stored_vcol + shiftwidth()
else
return s:UnexpectedToken(token, stack)
endif
@@ -888,7 +888,7 @@ function! s:ErlangCalcIndent2(lnum, stack)
if empty(stack)
call s:Log(' LTI is in a condition; matching ' .
\'"case/if/try/receive" found')
- let stored_vcol = curr_vcol + &sw
+ let stored_vcol = curr_vcol + shiftwidth()
elseif stack[0] ==# 'align_to_begin_element'
call s:Pop(stack)
let stored_vcol = curr_vcol
@@ -897,23 +897,23 @@ function! s:ErlangCalcIndent2(lnum, stack)
\'"case/if/try/receive" found')
call s:Pop(stack)
call s:Pop(stack)
- let stored_vcol = curr_vcol + &sw
+ let stored_vcol = curr_vcol + shiftwidth()
elseif stack[0] ==# '->'
call s:Log(' LTI is in a branch; matching ' .
\'"case/if/try/receive" found')
call s:Pop(stack)
- let stored_vcol = curr_vcol + 2 * &sw
+ let stored_vcol = curr_vcol + 2 * shiftwidth()
elseif stack[0] ==# 'when'
call s:Log(' LTI is in a guard; matching ' .
\'"case/if/try/receive" found')
call s:Pop(stack)
- let stored_vcol = curr_vcol + 2 * &sw + 2
+ let stored_vcol = curr_vcol + 2 * shiftwidth() + 2
endif
endif
let [ret, res] = s:BeginElementFound(stack, token, curr_vcol,
- \stored_vcol, 'end', &sw)
+ \stored_vcol, 'end', shiftwidth())
if ret | return res | endif
elseif token ==# 'fun'
@@ -930,7 +930,7 @@ function! s:ErlangCalcIndent2(lnum, stack)
" stack = ['when'] => LTI is in a guard
if empty(stack)
call s:Log(' LTI is in a condition; matching "fun" found')
- let stored_vcol = curr_vcol + &sw
+ let stored_vcol = curr_vcol + shiftwidth()
elseif len(stack) > 1 && stack[0] ==# '->' && stack[1] ==# ';'
call s:Log(' LTI is in a condition; matching "fun" found')
call s:Pop(stack)
@@ -938,15 +938,15 @@ function! s:ErlangCalcIndent2(lnum, stack)
elseif stack[0] ==# '->'
call s:Log(' LTI is in a branch; matching "fun" found')
call s:Pop(stack)
- let stored_vcol = curr_vcol + 2 * &sw
+ let stored_vcol = curr_vcol + 2 * shiftwidth()
elseif stack[0] ==# 'when'
call s:Log(' LTI is in a guard; matching "fun" found')
call s:Pop(stack)
- let stored_vcol = curr_vcol + 2 * &sw + 2
+ let stored_vcol = curr_vcol + 2 * shiftwidth() + 2
endif
let [ret, res] = s:BeginElementFound(stack, token, curr_vcol,
- \stored_vcol, 'end', &sw)
+ \stored_vcol, 'end', shiftwidth())
if ret | return res | endif
else
" Pass: we have a function reference (e.g. "fun f/0")
@@ -1220,7 +1220,7 @@ function! s:ErlangCalcIndent2(lnum, stack)
" when A,
" LTI
let [ret, res] = s:BeginElementFoundIfEmpty(stack, token, curr_vcol,
- \stored_vcol, &sw)
+ \stored_vcol, shiftwidth())
if ret | return res | endif
else
" Example:
@@ -1252,7 +1252,7 @@ function! s:ErlangCalcIndent2(lnum, stack)
" If LTI is between an 'after' and the corresponding
" 'end', then let's return
let [ret, res] = s:BeginElementFoundIfEmpty(stack, token, curr_vcol,
- \stored_vcol, &sw)
+ \stored_vcol, shiftwidth())
if ret | return res | endif
endif
diff --git a/runtime/indent/eruby.vim b/runtime/indent/eruby.vim
index afabd4fe5b..5058325495 100644
--- a/runtime/indent/eruby.vim
+++ b/runtime/indent/eruby.vim
@@ -47,11 +47,7 @@ set cpo&vim
function! GetErubyIndent(...)
" The value of a single shift-width
- if exists('*shiftwidth')
- let sw = shiftwidth()
- else
- let sw = &sw
- endif
+ let sw = shiftwidth()
if a:0 && a:1 == '.'
let v:lnum = line('.')
diff --git a/runtime/indent/falcon.vim b/runtime/indent/falcon.vim
index 84b16d55f0..b34e7cfd47 100644
--- a/runtime/indent/falcon.vim
+++ b/runtime/indent/falcon.vim
@@ -339,7 +339,7 @@ function FalconGetIndent(...)
" 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)) + shiftwidth()
endif
" If it contained hanging closing brackets, find the rightmost one, find its
@@ -350,20 +350,20 @@ function FalconGetIndent(...)
if opening.pos != -1
if opening.type == '(' && searchpair('(', '', ')', 'bW', s:skip_expr) > 0
if col('.') + 1 == col('$')
- return ind + &sw
+ return ind + shiftwidth()
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 + shiftwidth()
endif
elseif closing.pos != -1
call cursor(lnum, closing.pos + 1)
normal! %
if s:Match(line('.'), s:falcon_indent_keywords)
- return indent('.') + &sw
+ return indent('.') + shiftwidth()
else
return indent('.')
endif
@@ -392,7 +392,7 @@ function FalconGetIndent(...)
let col = s:Match(lnum, s:falcon_indent_keywords)
if col > 0
call cursor(lnum, col)
- let ind = virtcol('.') - 1 + &sw
+ let ind = virtcol('.') - 1 + shiftwidth()
" 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
@@ -422,9 +422,9 @@ function FalconGetIndent(...)
" TODO: this does not take into account contrived things such as
" module Foo; class Bar; end
if s:Match(lnum, s:falcon_indent_keywords)
- let ind = msl_ind + &sw
+ let ind = msl_ind + shiftwidth()
if s:Match(lnum, s:end_end_regex)
- let ind = ind - &sw
+ let ind = ind - shiftwidth()
endif
return ind
endif
@@ -433,7 +433,7 @@ function FalconGetIndent(...)
" 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 + shiftwidth()
else
let ind = msl_ind
endif
diff --git a/runtime/indent/gitconfig.vim b/runtime/indent/gitconfig.vim
index 480c96d1b9..6a670ee271 100644
--- a/runtime/indent/gitconfig.vim
+++ b/runtime/indent/gitconfig.vim
@@ -1,7 +1,7 @@
" Vim indent file
" Language: git config file
" Maintainer: Tim Pope <vimNOSPAM@tpope.org>
-" Last Change: 2016 Aug 29
+" Last Change: 2017 Jun 13
if exists("b:did_indent")
finish
@@ -20,7 +20,7 @@ if exists("*GetGitconfigIndent")
endif
function! GetGitconfigIndent()
- let sw = exists('*shiftwidth') ? shiftwidth() : &sw
+ let sw = shiftwidth()
let line = getline(prevnonblank(v:lnum-1))
let cline = getline(v:lnum)
if line =~ '\\\@<!\%(\\\\\)*\\$'
diff --git a/runtime/indent/gitolite.vim b/runtime/indent/gitolite.vim
index 33b7c9f312..2d24b592d0 100644
--- a/runtime/indent/gitolite.vim
+++ b/runtime/indent/gitolite.vim
@@ -2,7 +2,7 @@
" Language: gitolite configuration
" URL: https://github.com/tmatilai/gitolite.vim
" Maintainer: Teemu Matilainen <teemu.matilainen@iki.fi>
-" Last Change: 2011-12-24
+" Last Change: 2017 Jun 13
if exists("b:did_indent")
finish
@@ -27,11 +27,11 @@ function! GetGitoliteIndent()
let cline = getline(v:lnum)
if cline =~ '^\s*\(C\|R\|RW\|RW+\|RWC\|RW+C\|RWD\|RW+D\|RWCD\|RW+CD\|-\)[ \t=]'
- return &sw
+ return shiftwidth()
elseif cline =~ '^\s*config\s'
- return &sw
+ return shiftwidth()
elseif pline =~ '^\s*repo\s' && cline =~ '^\s*\(#.*\)\?$'
- return &sw
+ return shiftwidth()
elseif cline =~ '^\s*#'
return indent(prevln)
elseif cline =~ '^\s*$'
diff --git a/runtime/indent/go.vim b/runtime/indent/go.vim
index 412ac871c4..bf9ff75e6c 100644
--- a/runtime/indent/go.vim
+++ b/runtime/indent/go.vim
@@ -1,7 +1,7 @@
" Vim indent file
" Language: Go
" Maintainer: David Barnett (https://github.com/google/vim-ft-go)
-" Last Change: 2014 Aug 16
+" Last Change: 2017 Jun 13
"
" TODO:
" - function invocations split across lines
@@ -23,18 +23,6 @@ if exists('*GoIndent')
finish
endif
-" The shiftwidth() function is relatively new.
-" Don't require it to exist.
-if exists('*shiftwidth')
- function s:sw() abort
- return shiftwidth()
- endfunction
-else
- function s:sw() abort
- return &shiftwidth
- endfunction
-endif
-
function! GoIndent(lnum)
let l:prevlnum = prevnonblank(a:lnum-1)
if l:prevlnum == 0
@@ -51,17 +39,17 @@ function! GoIndent(lnum)
if l:prevl =~ '[({]\s*$'
" previous line opened a block
- let l:ind += s:sw()
+ let l:ind += shiftwidth()
endif
if l:prevl =~# '^\s*\(case .*\|default\):$'
" previous line is part of a switch statement
- let l:ind += s:sw()
+ let l:ind += shiftwidth()
endif
" TODO: handle if the previous line is a label.
if l:thisl =~ '^\s*[)}]'
" this line closed a block
- let l:ind -= s:sw()
+ let l:ind -= shiftwidth()
endif
" Colons are tricky.
@@ -69,7 +57,7 @@ function! GoIndent(lnum)
" 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 l:thisl =~# '^\s*\(case .*\|default\):$'
- let l:ind -= s:sw()
+ let l:ind -= shiftwidth()
endif
return l:ind
diff --git a/runtime/indent/haml.vim b/runtime/indent/haml.vim
index c3935af9e9..e6416e6f53 100644
--- a/runtime/indent/haml.vim
+++ b/runtime/indent/haml.vim
@@ -1,7 +1,7 @@
" Vim indent file
" Language: Haml
" Maintainer: Tim Pope <vimNOSPAM@tpope.org>
-" Last Change: 2016 Aug 29
+" Last Change: 2017 Jun 13
if exists("b:did_indent")
finish
@@ -37,7 +37,7 @@ function! GetHamlIndent()
let line = substitute(line,'^\s\+','','')
let indent = indent(lnum)
let cindent = indent(v:lnum)
- let sw = exists('*shiftwidth') ? shiftwidth() : &sw
+ let sw = shiftwidth()
if cline =~# '\v^-\s*%(elsif|else|when)>'
let indent = cindent < indent ? cindent : indent - sw
endif
diff --git a/runtime/indent/hamster.vim b/runtime/indent/hamster.vim
index 93e7db486e..b27a173924 100644
--- a/runtime/indent/hamster.vim
+++ b/runtime/indent/hamster.vim
@@ -27,13 +27,13 @@ function HamGetIndent(lnum)
" Add a shiftwidth to statements following if, else, elseif,
" case, select, default, do, until, while, for, start
if prevline =~? '^\s*\<\(if\|else\%(if\)\?\|for\|repeat\|do\|while\|sub\)\>'
- let ind = ind + &sw
+ let ind = ind + shiftwidth()
endif
" Subtract a shiftwidth from else, elseif, end(if|while|for), until
let line = getline(v:lnum)
if line =~? '^\s*\(else\|elseif\|loop\|until\|end\%(if\|while\|for\|sub\)\)\>'
- let ind = ind - &sw
+ let ind = ind - shiftwidth()
endif
return ind
diff --git a/runtime/indent/hog.vim b/runtime/indent/hog.vim
index 02ac7d4d1b..ece587d46f 100644
--- a/runtime/indent/hog.vim
+++ b/runtime/indent/hog.vim
@@ -47,7 +47,7 @@ function GetHogIndent()
" Continuation of a line that wasn't indented
let prevline = getline(prevlnum)
if prevline =~ '^\k\+.*\\\s*$'
- return &sw
+ return shiftwidth()
endif
" Continuation of a line that was indented
@@ -58,13 +58,13 @@ function GetHogIndent()
" Indent the next line if previous line contained a start of a block
" definition ('{' or '(').
if prevline =~ '^\k\+[^#]*{}\@!\s*$' " TODO || prevline =~ '^\k\+[^#]*()\@!\s*$'
- return &sw
+ return shiftwidth()
endif
" Match inside of a block
if s:IsInBlock(v:lnum)
if prevline =~ "^\k\+.*$"
- return &sw
+ return shiftwidth()
else
return indent(prevlnum)
endif
diff --git a/runtime/indent/html.vim b/runtime/indent/html.vim
index 57ba53ecd4..37697841fd 100644
--- a/runtime/indent/html.vim
+++ b/runtime/indent/html.vim
@@ -2,7 +2,7 @@
" Header: "{{{
" Maintainer: Bram Moolenaar
" Original Author: Andy Wokula <anwoku@yahoo.de>
-" Last Change: 2017 Jan 17
+" Last Change: 2017 Jun 13
" Version: 1.0
" Description: HTML indent script with cached state for faster indenting on a
" range of lines.
@@ -51,15 +51,6 @@ if exists("*HtmlIndent") && !exists('g:force_reload_html')
finish
endif
-" shiftwidth() exists since patch 7.3.694
-if exists('*shiftwidth')
- let s:ShiftWidth = function('shiftwidth')
-else
- func! s:ShiftWidth()
- return &shiftwidth
- endfunc
-endif
-
" Allow for line continuation below.
let s:cpo_save = &cpo
set cpo-=C
@@ -123,7 +114,7 @@ func! HtmlIndent_CheckUserSettings()
let indone = {"zero": 0
\,"auto": "indent(prevnonblank(v:lnum-1))"
- \,"inc": "b:hi_indent.blocktagind + s:ShiftWidth()"}
+ \,"inc": "b:hi_indent.blocktagind + shiftwidth()"}
let script1 = ''
if exists("b:html_indent_script1")
@@ -358,7 +349,7 @@ func! s:CheckBlockTag(blocktag, ind)
endif
let b:hi_newstate.blocklnr = v:lnum
" save allover indent for the endtag
- let b:hi_newstate.blocktagind = b:hi_indent.baseindent + (s:nextrel + s:curind) * s:ShiftWidth()
+ let b:hi_newstate.blocktagind = b:hi_indent.baseindent + (s:nextrel + s:curind) * shiftwidth()
if a:ind == 3
return "SCRIPT" " all except this must be lowercase
" line is to be checked again for the type attribute
@@ -480,7 +471,7 @@ func! s:FreshState(lnum)
let state.blocklnr = stopline
" check preceding tags in the line:
call s:CountITags(tagline[: stopcol-2])
- let state.blocktagind = indent(stopline) + (s:curind + s:nextrel) * s:ShiftWidth()
+ let state.blocktagind = indent(stopline) + (s:curind + s:nextrel) * shiftwidth()
return state
elseif stopline == state.lnum
" handle special case: previous line (= state.lnum) contains a
@@ -490,7 +481,7 @@ func! s:FreshState(lnum)
if !swendtag
let [bline, bcol] = searchpos('<'.blocktag[1:].'\>', "bnW")
call s:CountITags(tolower(getline(bline)[: bcol-2]))
- let state.baseindent = indent(bline) + (s:curind + s:nextrel) * s:ShiftWidth()
+ let state.baseindent = indent(bline) + (s:curind + s:nextrel) * shiftwidth()
return state
endif
endif
@@ -511,7 +502,7 @@ func! s:FreshState(lnum)
if found == 2
let state.baseindent = b:hi_indent.baseindent
endif
- let state.blocktagind = indent(comlnum) + (s:curind + s:nextrel) * s:ShiftWidth()
+ let state.blocktagind = indent(comlnum) + (s:curind + s:nextrel) * shiftwidth()
return state
endif
@@ -530,7 +521,7 @@ func! s:FreshState(lnum)
let text = tolower(getline(comlnum)[: comcol-2])
endif
call s:CountITags(text)
- let state.baseindent = indent(comlnum) + (s:curind + s:nextrel) * s:ShiftWidth()
+ let state.baseindent = indent(comlnum) + (s:curind + s:nextrel) * shiftwidth()
" TODO check tags that follow "-->"
return state
endif
@@ -550,9 +541,9 @@ func! s:FreshState(lnum)
let text = getline(start_lnum)
let swendtag = match(text, '^\s*</') >= 0
call s:CountITags(text[: col('.') - 2])
- let state.baseindent += s:nextrel * s:ShiftWidth()
+ let state.baseindent += s:nextrel * shiftwidth()
if !swendtag
- let state.baseindent += s:curind * s:ShiftWidth()
+ let state.baseindent += s:curind * shiftwidth()
endif
endif
return state
@@ -565,9 +556,9 @@ func! s:FreshState(lnum)
let text = getline(state.lnum)
let swendtag = match(text, '^\s*</') >= 0
call s:CountITags(tolower(text))
- let state.baseindent = indent(state.lnum) + s:nextrel * s:ShiftWidth()
+ let state.baseindent = indent(state.lnum) + s:nextrel * shiftwidth()
if !swendtag
- let state.baseindent += s:curind * s:ShiftWidth()
+ let state.baseindent += s:curind * shiftwidth()
endif
return state
endfunc "}}}
@@ -646,7 +637,7 @@ func! s:CSSIndent()
" add indent after {
let brace_counts = HtmlIndent_CountBraces(prev_lnum)
- let extra = brace_counts.c_open * s:ShiftWidth()
+ let extra = brace_counts.c_open * shiftwidth()
let prev_text = getline(prev_lnum)
let below_end_brace = prev_text =~ '}\s*$'
@@ -663,7 +654,7 @@ func! s:CSSIndent()
" if the current line is not a comment or starts with @ (used by template
" systems) reduce indent if previous line is a continuation line
if !prev_hasfield && !prev_special
- let extra = -s:ShiftWidth()
+ let extra = -shiftwidth()
endif
else
let cur_hasfield = curtext =~ '^\s*[a-zA-Z0-9-]\+:'
@@ -671,14 +662,14 @@ func! s:CSSIndent()
if !cur_hasfield && (prev_hasfield || prev_unfinished)
" Continuation line has extra indent if the previous line was not a
" continuation line.
- let extra = s:ShiftWidth()
+ let extra = shiftwidth()
" Align with @if
if prev_text =~ '^\s*@if '
let extra = 4
endif
elseif cur_hasfield && !prev_hasfield && !prev_special
" less indent below a continuation line
- let extra = -s:ShiftWidth()
+ let extra = -shiftwidth()
endif
endif
endif
@@ -699,10 +690,10 @@ func! s:CSSIndent()
if special
" do not reduce indent below @{ ... }
if extra < 0
- let extra += s:ShiftWidth()
+ let extra += shiftwidth()
endif
else
- let extra -= (brace_counts.c_close - (prev_text =~ '^\s*}')) * s:ShiftWidth()
+ let extra -= (brace_counts.c_close - (prev_text =~ '^\s*}')) * shiftwidth()
endif
endif
@@ -710,10 +701,10 @@ func! s:CSSIndent()
if extra == 0
if brace_counts.p_open > brace_counts.p_close
" previous line has more ( than ): add a shiftwidth
- let extra = s:ShiftWidth()
+ let extra = shiftwidth()
elseif brace_counts.p_open < brace_counts.p_close
" previous line has more ) than (: subtract a shiftwidth
- let extra = -s:ShiftWidth()
+ let extra = -shiftwidth()
endif
endif
@@ -816,7 +807,7 @@ func! s:Alien5()
let idx = match(prevtext, '^\s*\zs<!--')
if idx >= 0
" just below comment start, add a shiftwidth
- return idx + s:ShiftWidth()
+ return idx + shiftwidth()
endif
" Some files add 4 spaces just below a TODO line. It's difficult to detect
@@ -837,7 +828,7 @@ func! s:Alien6()
return indent(lnum)
endif
endif
- return b:hi_indent.baseindent + s:ShiftWidth()
+ return b:hi_indent.baseindent + shiftwidth()
endfunc "}}}
" When the "lnum" line ends in ">" find the line containing the matching "<".
@@ -947,7 +938,7 @@ func! HtmlIndent()
endif
let curtext = tolower(getline(v:lnum))
- let indentunit = s:ShiftWidth()
+ let indentunit = shiftwidth()
let b:hi_newstate = {}
let b:hi_newstate.lnum = v:lnum
@@ -1030,9 +1021,9 @@ func! HtmlIndent()
if col('.') > 2
let swendtag = match(text, '^\s*</') >= 0
call s:CountITags(text[: col('.') - 2])
- let indent += s:nextrel * s:ShiftWidth()
+ let indent += s:nextrel * shiftwidth()
if !swendtag
- let indent += s:curind * s:ShiftWidth()
+ let indent += s:curind * shiftwidth()
endif
endif
else
diff --git a/runtime/indent/idlang.vim b/runtime/indent/idlang.vim
index b4c6ae6fea..7402e8688e 100644
--- a/runtime/indent/idlang.vim
+++ b/runtime/indent/idlang.vim
@@ -1,6 +1,6 @@
" IDL (Interactive Data Language) indent file.
" Language: IDL (ft=idlang)
-" Last change: 2012 May 18
+" Last change: 2017 Jun 13
" Maintainer: Aleksandar Jelenak <ajelenak AT yahoo.com>
" Only load this indent file when no other was loaded.
@@ -34,25 +34,25 @@ function GetIdlangIndent(lnum)
" Indenting of continued lines.
if getline(pnum) =~ '\$\s*\(;.*\)\=$'
if getline(pnum2) !~ '\$\s*\(;.*\)\=$'
- let curind = curind+&sw
+ let curind = curind+shiftwidth()
endif
else
if getline(pnum2) =~ '\$\s*\(;.*\)\=$'
- let curind = curind-&sw
+ let curind = curind-shiftwidth()
endif
endif
" Indenting blocks of statements.
if getline(v:lnum) =~? '^\s*\(endif\|endelse\|endwhile\|endfor\|endrep\)\>'
if getline(pnum) =~? 'begin\>'
- elseif indent(v:lnum) > curind-&sw
- let curind = curind-&sw
+ elseif indent(v:lnum) > curind-shiftwidth()
+ let curind = curind-shiftwidth()
else
return -1
endif
elseif getline(pnum) =~? 'begin\>'
- if indent(v:lnum) < curind+&sw
- let curind = curind+&sw
+ if indent(v:lnum) < curind+shiftwidth()
+ let curind = curind+shiftwidth()
else
return -1
endif
diff --git a/runtime/indent/ishd.vim b/runtime/indent/ishd.vim
index f55f7dc79c..531244b819 100644
--- a/runtime/indent/ishd.vim
+++ b/runtime/indent/ishd.vim
@@ -50,17 +50,17 @@ fun! GetIshdIndent(lnum)
" Add
if previous_line =~ '^\s*\<\(function\|begin\|switch\|case\|default\|if.\{-}then\|else\|elseif\|while\|repeat\)\>'
- let ind = ind + &sw
+ let ind = ind + shiftwidth()
endif
" Subtract
if this_line =~ '^\s*\<endswitch\>'
- let ind = ind - 2 * &sw
+ let ind = ind - 2 * shiftwidth()
elseif this_line =~ '^\s*\<\(begin\|end\|endif\|endwhile\|else\|elseif\|until\)\>'
- let ind = ind - &sw
+ let ind = ind - shiftwidth()
elseif this_line =~ '^\s*\<\(case\|default\)\>'
if previous_line !~ '^\s*\<switch\>'
- let ind = ind - &sw
+ let ind = ind - shiftwidth()
endif
endif
diff --git a/runtime/indent/javascript.vim b/runtime/indent/javascript.vim
index a6f1e1a8f8..3b3f3a104d 100644
--- a/runtime/indent/javascript.vim
+++ b/runtime/indent/javascript.vim
@@ -2,7 +2,7 @@
" Language: Javascript
" Maintainer: Chris Paul ( https://github.com/bounceme )
" URL: https://github.com/pangloss/vim-javascript
-" Last Change: December 31, 2016
+" Last Change: March 21, 2017
" Only load this indent file when no other was loaded.
if exists('b:did_indent')
@@ -14,6 +14,10 @@ let b:did_indent = 1
setlocal indentexpr=GetJavascriptIndent()
setlocal autoindent nolisp nosmartindent
setlocal indentkeys+=0],0)
+" Testable with something like:
+" vim -eNs "+filetype plugin indent on" "+syntax on" "+set ft=javascript" \
+" "+norm! gg=G" '+%print' '+:q!' testfile.js \
+" | diff -uBZ testfile.js -
let b:undo_indent = 'setlocal indentexpr< smartindent< autoindent< indentkeys<'
@@ -32,10 +36,14 @@ if exists('*shiftwidth')
endfunction
else
function s:sw()
- return &sw
+ return &l:shiftwidth == 0 ? &l:tabstop : &l:shiftwidth
endfunction
endif
+" Performance for forwards search(): start search at pos rather than masking
+" matches before pos.
+let s:z = has('patch-7.4.984') ? 'z' : ''
+
" searchpair() wrapper
if has('reltime')
function s:GetPair(start,end,flags,skip,time,...)
@@ -48,34 +56,41 @@ else
endif
" Regex of syntax group names that are or delimit string or are comments.
-let s:syng_strcom = 'string\|comment\|regex\|special\|doc\|template'
-let s:syng_str = 'string\|template'
+let s:syng_strcom = 'string\|comment\|regex\|special\|doc\|template\%(braces\)\@!'
+let s:syng_str = 'string\|template\|special'
let s:syng_com = 'comment\|doc'
" Expression used to check whether we should skip a match with searchpair().
let s:skip_expr = "synIDattr(synID(line('.'),col('.'),0),'name') =~? '".s:syng_strcom."'"
+function s:parse_cino(f) abort
+ return float2nr(eval(substitute(substitute(join(split(
+ \ matchstr(&cino,'.*'.a:f.'\zs[^,]*'), 's',1), '*'.s:W)
+ \ , '^-\=\zs\*','',''), '^-\=\zs\.','0.','')))
+endfunction
+
function s:skip_func()
- if !s:free || search('\m`\|\*\/','nW',s:looksyn)
- let s:free = !eval(s:skip_expr)
- let s:looksyn = s:free ? line('.') : s:looksyn
- return !s:free
+ if getline('.') =~ '\%<'.col('.').'c\/.\{-}\/\|\%>'.col('.').'c[''"]\|\\$'
+ return eval(s:skip_expr)
+ elseif s:checkIn || search('\m`\|\${\|\*\/','nW'.s:z,s:looksyn)
+ let s:checkIn = eval(s:skip_expr)
endif
let s:looksyn = line('.')
- return (search('\m\/','nbW',s:looksyn) || search('\m[''"]\|\\$','nW',s:looksyn)) && eval(s:skip_expr)
+ return s:checkIn
endfunction
function s:alternatePair(stop)
let pos = getpos('.')[1:2]
- while search('\m[][(){}]','bW',a:stop)
- if !s:skip_func()
- let idx = stridx('])}',s:looking_at())
- if idx + 1
- if !s:GetPair(['\[','(','{'][idx], '])}'[idx],'bW','s:skip_func()',2000,a:stop)
- break
- endif
- else
- return
+ let pat = '[][(){};]'
+ while search('\m'.pat,'bW',a:stop)
+ if s:skip_func() | continue | endif
+ let idx = stridx('])};',s:looking_at())
+ if idx is 3 | let pat = '[{}()]' | continue | endif
+ if idx + 1
+ if s:GetPair(['\[','(','{'][idx], '])}'[idx],'bW','s:skip_func()',2000,a:stop) <= 0
+ break
endif
+ else
+ return
endif
endwhile
call call('cursor',pos)
@@ -100,93 +115,91 @@ function s:token()
return s:looking_at() =~ '\k' ? expand('<cword>') : s:looking_at()
endfunction
-function s:b_token()
- if s:looking_at() =~ '\k'
- call search('\m\<','cbW')
- endif
- return search('\m\S','bW')
-endfunction
-
function s:previous_token()
- let l:n = line('.')
- while s:b_token()
- if (s:looking_at() == '/' || line('.') != l:n && search('\m\/\/','nbW',
- \ line('.'))) && s:syn_at(line('.'),col('.')) =~? s:syng_com
- call search('\m\_[^/]\zs\/[/*]','bW')
+ let l:pos = getpos('.')[1:2]
+ if search('\m\k\{1,}\zs\k\|\S','bW')
+ if (getline('.')[col('.')-2:col('.')-1] == '*/' || line('.') != l:pos[0] &&
+ \ getline('.') =~ '\%<'.col('.').'c\/\/') && s:syn_at(line('.'),col('.')) =~? s:syng_com
+ while search('\m\S\ze\_s*\/[/*]','bW')
+ if s:syn_at(line('.'),col('.')) !~? s:syng_com
+ return s:token()
+ endif
+ endwhile
else
return s:token()
endif
- endwhile
+ endif
+ call call('cursor',l:pos)
return ''
endfunction
-function s:others(p)
- return "((line2byte(line('.')) + col('.')) <= ".(line2byte(a:p[0]) + a:p[1]).") || ".s:skip_expr
-endfunction
-
-function s:tern_skip(p)
- return s:GetPair('{','}','nbW',s:others(a:p),200,a:p[0]) > 0
-endfunction
-
-function s:tern_col(p)
- return s:GetPair('?',':\@<!::\@!','nbW',s:others(a:p)
- \ .' || s:tern_skip('.string(a:p).')',200,a:p[0]) > 0
-endfunction
-
-function s:label_col()
- let pos = getpos('.')[1:2]
- let [s:looksyn,s:free] = pos
- call s:alternatePair(0)
- if s:save_pos('s:IsBlock')
- let poss = getpos('.')[1:2]
- return call('cursor',pos) || !s:tern_col(poss)
- elseif s:looking_at() == ':'
- return !s:tern_col([0,0])
+function s:expr_col()
+ if getline('.')[col('.')-2] == ':'
+ return 1
endif
+ let bal = 0
+ while search('\m[{}?:;]','bW')
+ if eval(s:skip_expr) | continue | endif
+ " switch (looking_at())
+ exe { '}': "if s:GetPair('{','}','bW',s:skip_expr,200) <= 0 | return | endif",
+ \ ';': "return",
+ \ '{': "return getpos('.')[1:2] != b:js_cache[1:] && !s:IsBlock()",
+ \ ':': "let bal -= getline('.')[max([col('.')-2,0]):col('.')] !~ '::'",
+ \ '?': "let bal += 1 | if bal > 0 | return 1 | endif" }[s:looking_at()]
+ endwhile
endfunction
" configurable regexes that define continuation lines, not including (, {, or [.
let s:opfirst = '^' . get(g:,'javascript_opfirst',
- \ '\%([<>=,?^%|*/&]\|\([-.:+]\)\1\@!\|!=\|in\%(stanceof\)\=\>\)')
+ \ '\C\%([<>=,?^%|*/&]\|\([-.:+]\)\1\@!\|!=\|in\%(stanceof\)\=\>\)')
let s:continuation = get(g:,'javascript_continuation',
- \ '\%([<=,.~!?/*^%|&:]\|+\@<!+\|-\@<!-\|=\@<!>\|\<\%(typeof\|delete\|void\|in\|instanceof\)\)') . '$'
+ \ '\C\%([-+<>=,.~!?/*^%|&:]\|\<\%(typeof\|new\|delete\|void\|in\|instanceof\|await\)\)') . '$'
function s:continues(ln,con)
- return !cursor(a:ln, match(' '.a:con,s:continuation)) &&
- \ eval((['s:syn_at(line("."),col(".")) !~? "regex"'] +
- \ repeat(['s:previous_token() != "."'],5) + [1])[
- \ index(split('/ typeof in instanceof void delete'),s:token())])
+ if !cursor(a:ln, match(' '.a:con,s:continuation))
+ let teol = s:looking_at()
+ if teol == '/'
+ return s:syn_at(line('.'),col('.')) !~? 'regex'
+ elseif teol =~ '[-+>]'
+ return getline('.')[col('.')-2] != tr(teol,'>','=')
+ elseif teol =~ '\l'
+ return s:previous_token() != '.'
+ elseif teol == ':'
+ return s:expr_col()
+ endif
+ return 1
+ endif
endfunction
" get the line of code stripped of comments and move cursor to the last
" non-comment char.
function s:Trim(ln)
let pline = substitute(getline(a:ln),'\s*$','','')
- let l:max = max([match(pline,'.*[^/]\zs\/[/*]'),0])
- while l:max && s:syn_at(a:ln, strlen(pline)) =~? s:syng_com
- let pline = substitute(strpart(pline, 0, l:max),'\s*$','','')
- let l:max = max([match(pline,'.*[^/]\zs\/[/*]'),0])
+ let l:max = max([strridx(pline,'//'), strridx(pline,'/*')])
+ while l:max != -1 && s:syn_at(a:ln, strlen(pline)) =~? s:syng_com
+ let pline = pline[: l:max]
+ let l:max = max([strridx(pline,'//'), strridx(pline,'/*')])
+ let pline = substitute(pline[:-2],'\s*$','','')
endwhile
- return cursor(a:ln,strlen(pline)) ? pline : pline
+ return pline is '' || cursor(a:ln,strlen(pline)) ? pline : pline
endfunction
" Find line above 'lnum' that isn't empty or in a comment
function s:PrevCodeLine(lnum)
- let l:n = prevnonblank(a:lnum)
+ let [l:pos, l:n] = [getpos('.')[1:2], prevnonblank(a:lnum)]
while l:n
if getline(l:n) =~ '^\s*\/[/*]'
- if (stridx(getline(l:n),'`') > 0 || getline(l:n-1)[-1:] == '\') &&
- \ s:syn_at(l:n,1) =~? s:syng_str
- return l:n
- endif
let l:n = prevnonblank(l:n-1)
- elseif s:syn_at(l:n,1) =~? s:syng_com
- let l:n = s:save_pos('eval',
- \ 'cursor('.l:n.',1) + search(''\m\/\*'',"bW")')
+ elseif stridx(getline(l:n), '*/') + 1 && s:syn_at(l:n,1) =~? s:syng_com
+ call cursor(l:n,1)
+ keepjumps norm! [*
+ let l:n = search('\m\S','nbW')
else
- return l:n
+ break
endif
endwhile
+ call call('cursor',l:pos)
+ return l:n
endfunction
" Check if line 'lnum' has a balanced amount of parentheses.
@@ -201,7 +214,9 @@ function s:Balanced(lnum)
return
endif
endif
- let pos = match(l:line, '[][(){}]', pos + 1)
+ let pos = match(l:line, (l:open ?
+ \ '['.escape(tr(l:line[pos],'({[]})',')}][{(').l:line[pos],']').']' :
+ \ '[][(){}]'), pos + 1)
endwhile
return !l:open
endfunction
@@ -210,20 +225,21 @@ function s:OneScope(lnum)
let pline = s:Trim(a:lnum)
let kw = 'else do'
if pline[-1:] == ')' && s:GetPair('(', ')', 'bW', s:skip_expr, 100) > 0
- call s:previous_token()
- let kw = 'for if let while with'
- if index(split('await each'),s:token()) + 1
+ if s:previous_token() =~# '^\%(await\|each\)$'
call s:previous_token()
let kw = 'for'
+ else
+ let kw = 'for if let while with'
endif
endif
return pline[-2:] == '=>' || index(split(kw),s:token()) + 1 &&
\ s:save_pos('s:previous_token') != '.'
endfunction
-" returns braceless levels started by 'i' and above lines * &sw. 'num' is the
-" lineNr which encloses the entire context, 'cont' if whether line 'i' + 1 is
-" a continued expression, which could have started in a braceless context
+" returns braceless levels started by 'i' and above lines * shiftwidth().
+" 'num' is the lineNr which encloses the entire context, 'cont' if whether
+" line 'i' + 1 is a continued expression, which could have started in a
+" braceless context
function s:iscontOne(i,num,cont)
let [l:i, l:num, bL] = [a:i, a:num + !a:num, 0]
let pind = a:num ? indent(l:num) + s:W : 0
@@ -246,18 +262,23 @@ function s:IsBlock()
if s:looking_at() == '{'
let l:n = line('.')
let char = s:previous_token()
- let syn = char =~ '[{>/]' ? s:syn_at(line('.'),col('.')-(char == '{')) : ''
- if syn =~? 'xml\|jsx'
+ if match(s:stack,'\cxml\|jsx') + 1 && s:syn_at(line('.'),col('.')-1) =~? 'xml\|jsx'
return char != '{'
elseif char =~ '\k'
- return index(split('return const let import export yield default delete var await void typeof throw case new in instanceof')
- \ ,char) < (line('.') != l:n) || s:previous_token() == '.'
+ if char ==# 'type'
+ return s:previous_token() !~# '^\%(im\|ex\)port$'
+ endif
+ return index(split('return const let import export extends yield default delete var await void typeof throw case new of in instanceof')
+ \ ,char) < (line('.') != l:n) || s:save_pos('s:previous_token') == '.'
elseif char == '>'
- return getline('.')[col('.')-2] == '=' || syn =~? '^jsflow'
+ return getline('.')[col('.')-2] == '=' || s:syn_at(line('.'),col('.')) =~? '^jsflow'
elseif char == ':'
- return getline('.')[col('.')-2] != ':' && s:label_col()
+ return !s:save_pos('s:expr_col')
+ elseif char == '/'
+ return s:syn_at(line('.'),col('.')) =~? 'regex'
endif
- return syn =~? 'regex' || char !~ '[-=~!<*+,/?^%|&([]'
+ return char !~ '[=~!<*,?^%|&([]' &&
+ \ (char !~ '[-+]' || l:n != line('.') && getline('.')[col('.')-2] == char)
endif
endfunction
@@ -266,7 +287,9 @@ function GetJavascriptIndent()
" Get the current line.
call cursor(v:lnum,1)
let l:line = getline('.')
- let syns = s:syn_at(v:lnum, 1)
+ " use synstack as it validates syn state and works in an empty line
+ let s:stack = map(synstack(v:lnum,1),"synIDattr(v:val,'name')")
+ let syns = get(s:stack,-1,'')
" start with strings,comments,etc.
if syns =~? s:syng_com
@@ -275,7 +298,7 @@ function GetJavascriptIndent()
elseif l:line !~ '^\s*\/[/*]'
return -1
endif
- elseif syns =~? s:syng_str && l:line !~ '^[''"]'
+ elseif syns =~? s:syng_str
if b:js_cache[0] == v:lnum - 1 && s:Balanced(v:lnum-1)
let b:js_cache[0] = v:lnum
endif
@@ -295,69 +318,60 @@ function GetJavascriptIndent()
endif
" the containing paren, bracket, or curly. Many hacks for performance
- let idx = strlen(l:line) ? stridx('])}',l:line[0]) : -1
+ let idx = index([']',')','}'],l:line[0])
if b:js_cache[0] >= l:lnum && b:js_cache[0] < v:lnum &&
\ (b:js_cache[0] > l:lnum || s:Balanced(l:lnum))
call call('cursor',b:js_cache[1:])
else
- let [s:looksyn, s:free, top] = [v:lnum - 1, 1, (!indent(l:lnum) &&
+ let [s:looksyn, s:checkIn, top] = [v:lnum - 1, 0, (!indent(l:lnum) &&
\ s:syn_at(l:lnum,1) !~? s:syng_str) * l:lnum]
if idx + 1
- call s:GetPair(['\[','(','{'][idx], '])}'[idx],'bW','s:skip_func()',2000,top)
- elseif indent(v:lnum) && syns =~? 'block'
+ call s:GetPair(['\[','(','{'][idx],'])}'[idx],'bW','s:skip_func()',2000,top)
+ elseif getline(v:lnum) !~ '^\S' && syns =~? 'block'
call s:GetPair('{','}','bW','s:skip_func()',2000,top)
else
call s:alternatePair(top)
endif
endif
- if idx + 1 || l:line[:1] == '|}'
- if idx == 2 && search('\m\S','bW',line('.')) && s:looking_at() == ')'
- call s:GetPair('(',')','bW',s:skip_expr,200)
- endif
- return indent('.')
- endif
-
let b:js_cache = [v:lnum] + (line('.') == v:lnum ? [0,0] : getpos('.')[1:2])
let num = b:js_cache[1]
let [s:W, isOp, bL, switch_offset] = [s:sw(),0,0,0]
if !num || s:IsBlock()
+ let ilnum = line('.')
let pline = s:save_pos('s:Trim',l:lnum)
if num && s:looking_at() == ')' && s:GetPair('(', ')', 'bW', s:skip_expr, 100) > 0
- let num = line('.')
- if s:previous_token() ==# 'switch' && s:previous_token() != '.'
- if &cino !~ ':' || !has('float')
+ let num = ilnum == num ? line('.') : num
+ if idx < 0 && s:previous_token() ==# 'switch' && s:previous_token() != '.'
+ if &cino !~ ':'
let switch_offset = s:W
else
- let cinc = matchlist(&cino,'.*:\(-\)\=\([0-9.]*\)\(s\)\=\C')
- let switch_offset = float2nr(str2float(cinc[1].(strlen(cinc[2]) ? cinc[2] : strlen(cinc[3])))
- \ * (strlen(cinc[3]) ? s:W : 1))
+ let switch_offset = max([-indent(num),s:parse_cino(':')])
endif
if pline[-1:] != '.' && l:line =~# '^\%(default\|case\)\>'
return indent(num) + switch_offset
endif
endif
endif
- if pline[-1:] !~ '[{;]'
- if pline =~# ':\@<!:$'
- call cursor(l:lnum,strlen(pline))
- let isOp = s:tern_col(b:js_cache[1:2])
- else
- let isOp = l:line =~# s:opfirst || s:continues(l:lnum,pline)
- endif
- let bL = s:iscontOne(l:lnum,num,isOp)
+ if idx < 0 && pline[-1:] !~ '[{;]'
+ let isOp = (l:line =~# s:opfirst || s:continues(l:lnum,pline)) * s:W
+ let bL = s:iscontOne(l:lnum,b:js_cache[1],isOp)
let bL -= (bL && l:line[0] == '{') * s:W
endif
+ elseif idx < 0 && getline(b:js_cache[1])[b:js_cache[2]-1] == '(' && &cino =~ '('
+ let pval = s:parse_cino('(')
+ return !pval ? (s:parse_cino('w') ? 0 : -(!!search('\m\S','W'.s:z,num))) + virtcol('.') :
+ \ max([indent('.') + pval + (s:GetPair('(',')','nbrmW',s:skip_expr,100,num) * s:W),0])
endif
" main return
- if isOp
- return (num ? indent(num) : -s:W) + (s:W * 2) + switch_offset + bL
+ if l:line =~ '^\%([])}]\||}\)'
+ return max([indent(num),0])
elseif num
- return indent(num) + s:W + switch_offset + bL
+ return indent(num) + s:W + switch_offset + bL + isOp
endif
- return bL
+ return bL + isOp
endfunction
let &cpo = s:cpo_save
diff --git a/runtime/indent/json.vim b/runtime/indent/json.vim
index 649f2b8aa5..b66a03d81b 100644
--- a/runtime/indent/json.vim
+++ b/runtime/indent/json.vim
@@ -1,7 +1,7 @@
" Vim indent file
" Language: JSON
" Mantainer: Eli Parra <eli@elzr.com> https://github.com/elzr/vim-json
-" Last Change: 2014 Aug 29
+" Last Change: 2017 Jun 13
" https://github.com/jakar/vim-json/commit/20b650e22aa750c4ab6a66aa646bdd95d7cd548a#diff-e81fc111b2052e306d126bd9989f7b7c
" Original Author: Rogerz Zhang <rogerz.zhang at gmail.com> http://github.com/rogerz/vim-json
" Acknowledgement: Based off of vim-javascript maintained by Darrick Wiebe
@@ -141,7 +141,7 @@ function GetJSONIndent()
" If the previous line ended with a block opening, add a level of indent.
" if s:Match(lnum, s:block_regex)
- " return indent(lnum) + &sw
+ " return indent(lnum) + shiftwidth()
" endif
" If the previous line contained an opening bracket, and we are still in it,
@@ -149,7 +149,7 @@ function GetJSONIndent()
if line =~ '[[({]'
let counts = s:LineHasOpeningBrackets(lnum)
if counts[0] == '1' || counts[1] == '1' || counts[2] == '1'
- return ind + &sw
+ return ind + shiftwidth()
else
call cursor(v:lnum, vcol)
end
diff --git a/runtime/indent/liquid.vim b/runtime/indent/liquid.vim
index f8e1c83079..7beb0388d1 100644
--- a/runtime/indent/liquid.vim
+++ b/runtime/indent/liquid.vim
@@ -1,7 +1,7 @@
" Vim indent file
" Language: Liquid
" Maintainer: Tim Pope <vimNOSPAM@tpope.org>
-" Last Change: 2016 Aug 29
+" Last Change: 2017 Jun 13
if exists('b:did_indent')
finish
@@ -54,7 +54,7 @@ function! GetLiquidIndent(...)
let line = substitute(line,'\C^\%(\s*{%\s*end\w*\s*%}\)\+','','')
let line .= matchstr(cline,'\C^\%(\s*{%\s*end\w*\s*%}\)\+')
let cline = substitute(cline,'\C^\%(\s*{%\s*end\w*\s*%}\)\+','','')
- let sw = exists('*shiftwidth') ? shiftwidth() : &sw
+ let sw = shiftwidth()
let ind += sw * s:count(line,'{%\s*\%(if\|elsif\|else\|unless\|ifchanged\|case\|when\|for\|empty\|tablerow\|capture\)\>')
let ind -= sw * s:count(line,'{%\s*end\%(if\|unless\|ifchanged\|case\|for\|tablerow\|capture\)\>')
let ind -= sw * s:count(cline,'{%\s*\%(elsif\|else\|when\|empty\)\>')
diff --git a/runtime/indent/logtalk.vim b/runtime/indent/logtalk.vim
index 99e6ec896b..5b69663e1d 100644
--- a/runtime/indent/logtalk.vim
+++ b/runtime/indent/logtalk.vim
@@ -38,24 +38,24 @@ function! GetLogtalkIndent()
endif
" Check for entity opening directive on previous line
if pline =~ '^\s*:-\s\(object\|protocol\|category\)\ze(.*,$'
- let ind = ind + &sw
+ let ind = ind + shiftwidth()
" Check for clause head on previous line
elseif pline =~ ':-\s*\(%.*\)\?$'
- let ind = ind + &sw
+ let ind = ind + shiftwidth()
" Check for entity closing directive on previous line
elseif pline =~ '^\s*:-\send_\(object\|protocol\|category\)\.\(%.*\)\?$'
- let ind = ind - &sw
+ let ind = ind - shiftwidth()
" Check for end of clause on previous line
elseif pline =~ '\.\s*\(%.*\)\?$'
- let ind = ind - &sw
+ let ind = ind - shiftwidth()
endif
" Check for opening conditional on previous line
if pline =~ '^\s*\([(;]\|->\)' && pline !~ '\.\s*\(%.*\)\?$' && pline !~ '^.*\([)][,]\s*\(%.*\)\?$\)'
- let ind = ind + &sw
+ let ind = ind + shiftwidth()
endif
" Check for closing an unclosed paren, or middle ; or ->
if line =~ '^\s*\([);]\|->\)'
- let ind = ind - &sw
+ let ind = ind - shiftwidth()
endif
return ind
endfunction
diff --git a/runtime/indent/lua.vim b/runtime/indent/lua.vim
index d1d2c0d600..604cd333c9 100644
--- a/runtime/indent/lua.vim
+++ b/runtime/indent/lua.vim
@@ -2,7 +2,7 @@
" Language: Lua script
" Maintainer: Marcus Aurelius Farias <marcus.cf 'at' bol.com.br>
" First Author: Max Ischenko <mfi 'at' ukr.net>
-" Last Change: 2016 Jan 10
+" Last Change: 2017 Jun 13
" Only load this indent file when no other was loaded.
if exists("b:did_indent")
@@ -48,7 +48,7 @@ function! GetLuaIndent()
" Add 'shiftwidth' if what we found previously is not in a comment and
" an "end" or "until" is not present on the same line.
if synIDattr(synID(prevlnum, midx + 1, 1), "name") != "luaComment" && prevline !~ '\<end\>\|\<until\>'
- let ind = ind + &shiftwidth
+ let ind = ind + shiftwidth()
endif
endif
@@ -56,7 +56,7 @@ function! GetLuaIndent()
" This is the part that requires 'indentkeys'.
let midx = match(getline(v:lnum), '^\s*\%(end\>\|else\>\|elseif\>\|until\>\|}\)')
if midx != -1 && synIDattr(synID(v:lnum, midx + 1, 1), "name") != "luaComment"
- let ind = ind - &shiftwidth
+ let ind = ind - shiftwidth()
endif
return ind
diff --git a/runtime/indent/matlab.vim b/runtime/indent/matlab.vim
index 7bccc7c0a7..6a31624389 100644
--- a/runtime/indent/matlab.vim
+++ b/runtime/indent/matlab.vim
@@ -44,9 +44,9 @@ function GetMatlabIndent(lnum)
" See if this line does not follow the line right after an openblock
if getline(plnum) =~ '^\s*\(for\|if\|else\|elseif\|case\|while\|switch\|try\|otherwise\|catch\)\>'
" See if the user has already dedented
- elseif indent(v:lnum) > curind - &sw
+ elseif indent(v:lnum) > curind - shiftwidth()
" If not, recommend one dedent
- let curind = curind - &sw
+ let curind = curind - shiftwidth()
else
" Otherwise, trust the user
return -1
@@ -56,9 +56,9 @@ function GetMatlabIndent(lnum)
" If the previous line opened a block
elseif getline(plnum) =~ '^\s*\(for\|if\|else\|elseif\|case\|while\|switch\|try\|otherwise\|catch\)\>'
" See if the user has already indented
- if indent(v:lnum) < curind + &sw
+ if indent(v:lnum) < curind + shiftwidth()
"If not, recommend indent
- let curind = curind + &sw
+ let curind = curind + shiftwidth()
else
" Otherwise, trust the user
return -1
diff --git a/runtime/indent/mma.vim b/runtime/indent/mma.vim
index 356b87618d..8298ad98cd 100644
--- a/runtime/indent/mma.vim
+++ b/runtime/indent/mma.vim
@@ -49,7 +49,7 @@ function GetMmaIndent()
" also, indent only if this line if this line isn't starting a new
" block... TODO - fix this with indentkeys?
if getline(v:lnum-1) =~ '\\\@<!\%(\[[^\]]*\|([^)]*\|{[^}]*\)$' && getline(v:lnum) !~ '\s\+[\[({]'
- let ind = ind+&sw
+ let ind = ind+shiftwidth()
endif
" if this line had unmatched closing block,
diff --git a/runtime/indent/ocaml.vim b/runtime/indent/ocaml.vim
index 3bd65c63f0..8fe9de3d61 100644
--- a/runtime/indent/ocaml.vim
+++ b/runtime/indent/ocaml.vim
@@ -4,7 +4,7 @@
" Mike Leary <leary@nwlink.com>
" Markus Mottl <markus.mottl@gmail.com>
" URL: http://www.ocaml.info/vim/indent/ocaml.vim
-" Last Change: 2013 Jun 29
+" Last Change: 2017 Jun 13
" 2005 Jun 25 - Fixed multiple bugs due to 'else\nreturn ind' working
" 2005 May 09 - Added an option to not indent OCaml-indents specially (MM)
" 2013 June - commented textwidth (Marc Weber)
@@ -101,7 +101,7 @@ function! GetOCamlIndent()
" Return double 'shiftwidth' after lines matching:
if lline =~ '^\s*|.*->\s*$'
- return ind + &sw + &sw
+ return ind + 2 * shiftwidth()
endif
let line = getline(v:lnum)
@@ -172,7 +172,7 @@ function! GetOCamlIndent()
" Indent if current line begins with 'and':
elseif line =~ '^\s*and\>'
if lline !~ '^\s*\(and\|let\|type\)\>\|\<end\s*$'
- return ind - &sw
+ return ind - shiftwidth()
endif
" Indent if current line begins with 'with':
@@ -199,14 +199,14 @@ function! GetOCamlIndent()
" or 'method':
elseif line =~ '^\s*\(constraint\|inherit\|initializer\|method\)\>'
if lline !~ s:obj
- return indent(search('\<\(object\|object\s*(.*)\)\s*$', 'bW')) + &sw
+ return indent(search('\<\(object\|object\s*(.*)\)\s*$', 'bW')) + shiftwidth()
endif
endif
" Add a 'shiftwidth' after lines ending with:
if lline =~ '\(:\|=\|->\|<-\|(\|\[\|{\|{<\|\[|\|\[<\|\<\(begin\|do\|else\|fun\|function\|functor\|if\|initializer\|object\|parser\|private\|sig\|struct\|then\|try\)\|\<object\s*(.*)\)\s*$'
- let ind = ind + &sw
+ let ind = ind + shiftwidth()
" Back to normal indent after lines ending with ';;':
elseif lline =~ ';;\s*$' && lline !~ '^\s*;;'
@@ -263,7 +263,7 @@ function! GetOCamlIndent()
" Subtract a 'shiftwidth' after lines matching 'match ... with parser':
if lline =~ '\<match\>.*\<with\>\s*\<parser\s*$'
- let ind = ind - &sw
+ let ind = ind - shiftwidth()
endif
return ind
diff --git a/runtime/indent/occam.vim b/runtime/indent/occam.vim
index bebb0528bb..4acd42e3c8 100644
--- a/runtime/indent/occam.vim
+++ b/runtime/indent/occam.vim
@@ -131,7 +131,7 @@ function GetOccamIndent()
if line =~ s:FirstLevelIndent || (line =~ s:FirstLevelNonColonEndIndent && line !~ s:ColonEnd)
\ || (line !~ s:ColonStart && (prevline =~ s:SecondLevelIndent
\ || (prevline =~ s:SecondLevelNonColonEndIndent && prevline !~ s:ColonEnd)))
- let curindent = curindent + &shiftwidth
+ let curindent = curindent + shiftwidth()
" Restore magic
if !save_magic|setlocal nomagic|endif
@@ -153,7 +153,7 @@ function GetOccamIndent()
while !found
- if indent(prevlinenum) == curindent - &shiftwidth
+ if indent(prevlinenum) == curindent - shiftwidth()
let found = 1
endif
@@ -171,7 +171,7 @@ function GetOccamIndent()
if prevlinenum > 0
if getline(prevlinenum) =~ s:SecondLevelIndent
- let curindent = curindent + &shiftwidth
+ let curindent = curindent + shiftwidth()
endif
endif
diff --git a/runtime/indent/pascal.vim b/runtime/indent/pascal.vim
index 6dd3030e9c..c7955d669b 100644
--- a/runtime/indent/pascal.vim
+++ b/runtime/indent/pascal.vim
@@ -2,7 +2,7 @@
" Language: Pascal
" Maintainer: Neil Carter <n.carter@swansea.ac.uk>
" Created: 2004 Jul 13
-" Last Change: 2011 Apr 01
+" Last Change: 2017 Jun 13
"
" This is version 2.0, a complete rewrite.
"
@@ -102,12 +102,12 @@ function! GetPascalIndent( line_num )
" If the PREVIOUS LINE ended in these items, always indent
if prev_codeline =~ '\<\(type\|const\|var\)$'
- return indnt + &shiftwidth
+ return indnt + shiftwidth()
endif
if prev_codeline =~ '\<repeat$'
if this_codeline !~ '^\s*until\>'
- return indnt + &shiftwidth
+ return indnt + shiftwidth()
else
return indnt
endif
@@ -115,7 +115,7 @@ function! GetPascalIndent( line_num )
if prev_codeline =~ '\<\(begin\|record\)$'
if this_codeline !~ '^\s*end\>'
- return indnt + &shiftwidth
+ return indnt + shiftwidth()
else
return indnt
endif
@@ -125,10 +125,10 @@ function! GetPascalIndent( line_num )
" followed by "begin"
if prev_codeline =~ '\<\(\|else\|then\|do\)$' || prev_codeline =~ ':$'
if this_codeline !~ '^\s*begin\>'
- return indnt + &shiftwidth
+ return indnt + shiftwidth()
else
" If it does start with "begin" then keep the same indent
- "return indnt + &shiftwidth
+ "return indnt + shiftwidth()
return indnt
endif
endif
@@ -137,7 +137,7 @@ function! GetPascalIndent( line_num )
" only the line before the current one. TODO: Get it working for
" parameter lists longer than two lines.
if prev_codeline =~ '([^)]\+$'
- return indnt + &shiftwidth
+ return indnt + shiftwidth()
endif
@@ -146,7 +146,7 @@ function! GetPascalIndent( line_num )
" Lines starting with "else", but not following line ending with
" "end".
if this_codeline =~ '^\s*else\>' && prev_codeline !~ '\<end$'
- return indnt - &shiftwidth
+ return indnt - shiftwidth()
endif
" Lines after a single-statement branch/loop.
@@ -160,16 +160,16 @@ function! GetPascalIndent( line_num )
" additional unindentation.
if this_codeline =~ '^\s*\(end;\|except\|finally\|\)$'
" Note that we don't return from here.
- return indnt - &shiftwidth - &shiftwidth
+ return indnt - 2 * shiftwidth()
endif
- return indnt - &shiftwidth
+ return indnt - shiftwidth()
endif
" Lines starting with "until" or "end". This rule must be overridden
" by the one for "end" after a single-statement branch/loop. In
" other words that rule should come before this one.
if this_codeline =~ '^\s*\(end\|until\)\>'
- return indnt - &shiftwidth
+ return indnt - shiftwidth()
endif
@@ -201,7 +201,7 @@ function! GetPascalIndent( line_num )
" If the PREVIOUS LINE ended in these items, always indent.
if prev_codeline =~ '^\s*\(unit\|uses\|try\|except\|finally\|private\|protected\|public\|published\)$'
- return indnt + &shiftwidth
+ return indnt + shiftwidth()
endif
" ???? Indent "procedure" and "functions" if they appear within an
@@ -212,11 +212,11 @@ function! GetPascalIndent( line_num )
" UNINDENT ONCE
if this_codeline =~ '^\s*\(except\|finally\)$'
- return indnt - &shiftwidth
+ return indnt - shiftwidth()
endif
if this_codeline =~ '^\s*\(private\|protected\|public\|published\)$'
- return indnt - &shiftwidth
+ return indnt - shiftwidth()
endif
diff --git a/runtime/indent/perl.vim b/runtime/indent/perl.vim
index fc4b6a30d3..cf256eae0a 100644
--- a/runtime/indent/perl.vim
+++ b/runtime/indent/perl.vim
@@ -3,7 +3,7 @@
" Maintainer: vim-perl <vim-perl@googlegroups.com>
" Homepage: http://github.com/vim-perl/vim-perl
" Bugs/requests: http://github.com/vim-perl/vim-perl/issues
-" Last Change: 2013-07-24
+" Last Change: 2017 Jun 13
" Suggestions and improvements by :
" Aaron J. Sherman (use syntax for hints)
@@ -138,9 +138,9 @@ function! GetPerlIndent()
\ || synid =~ '^perl\(Sub\|Block\|Package\)Fold'
let brace = strpart(line, bracepos, 1)
if brace == '(' || brace == '{' || brace == '['
- let ind = ind + &sw
+ let ind = ind + shiftwidth()
else
- let ind = ind - &sw
+ let ind = ind - shiftwidth()
endif
endif
let bracepos = match(line, braceclass, bracepos + 1)
@@ -152,25 +152,25 @@ function! GetPerlIndent()
\ || synid == "perlMatchStartEnd"
\ || synid == "perlBraces"
\ || synid =~ '^perl\(Sub\|Block\|Package\)Fold'
- let ind = ind - &sw
+ let ind = ind - shiftwidth()
endif
endif
else
if line =~ '[{[(]\s*\(#[^])}]*\)\=$'
- let ind = ind + &sw
+ let ind = ind + shiftwidth()
endif
if cline =~ '^\s*[])}]'
- let ind = ind - &sw
+ let ind = ind - shiftwidth()
endif
endif
" Indent lines that begin with 'or' or 'and'
if cline =~ '^\s*\(or\|and\)\>'
if line !~ '^\s*\(or\|and\)\>'
- let ind = ind + &sw
+ let ind = ind + shiftwidth()
endif
elseif line =~ '^\s*\(or\|and\)\>'
- let ind = ind - &sw
+ let ind = ind - shiftwidth()
endif
return ind
diff --git a/runtime/indent/perl6.vim b/runtime/indent/perl6.vim
index ff2a579f0a..8561c8c58c 100644
--- a/runtime/indent/perl6.vim
+++ b/runtime/indent/perl6.vim
@@ -3,7 +3,7 @@
" Maintainer: vim-perl <vim-perl@googlegroups.com>
" Homepage: http://github.com/vim-perl/vim-perl
" Bugs/requests: http://github.com/vim-perl/vim-perl/issues
-" Last Change: 2013-07-21
+" Last Change: 2017 Jun 13
" Contributors: Andy Lester <andy@petdance.com>
" Hinrik Örn Sigurðsson <hinrik.sig@gmail.com>
"
@@ -107,19 +107,19 @@ function! GetPerl6Indent()
endif
if line =~ '[<«\[{(]\s*\(#[^)}\]»>]*\)\=$'
- let ind = ind + &sw
+ let ind = ind + shiftwidth()
endif
if cline =~ '^\s*[)}\]»>]'
- let ind = ind - &sw
+ let ind = ind - shiftwidth()
endif
" Indent lines that begin with 'or' or 'and'
if cline =~ '^\s*\(or\|and\)\>'
if line !~ '^\s*\(or\|and\)\>'
- let ind = ind + &sw
+ let ind = ind + shiftwidth()
endif
elseif line =~ '^\s*\(or\|and\)\>'
- let ind = ind - &sw
+ let ind = ind - shiftwidth()
endif
return ind
diff --git a/runtime/indent/php.vim b/runtime/indent/php.vim
index 07ecd8f141..35dddaa270 100644
--- a/runtime/indent/php.vim
+++ b/runtime/indent/php.vim
@@ -3,8 +3,8 @@
" Author: John Wellesz <John.wellesz (AT) teaser (DOT) fr>
" URL: http://www.2072productions.com/vim/indent/php.vim
" Home: https://github.com/2072/PHP-Indenting-for-VIm
-" Last Change: 2015 September 8th
-" Version: 1.60
+" Last Change: 2017 Jun 13
+" Version: 1.62
"
"
" Type :help php-indent for available options
@@ -50,25 +50,15 @@ let b:did_indent = 1
let g:php_sync_method = 0
-if exists('*shiftwidth')
- function! s:sw()
- return shiftwidth()
- endfunction
-else
- function! s:sw()
- return &shiftwidth
- endfunction
-endif
-
if exists("PHP_default_indenting")
- let b:PHP_default_indenting = PHP_default_indenting * s:sw()
+ let b:PHP_default_indenting = PHP_default_indenting * shiftwidth()
else
let b:PHP_default_indenting = 0
endif
if exists("PHP_outdentSLComments")
- let b:PHP_outdentSLComments = PHP_outdentSLComments * s:sw()
+ let b:PHP_outdentSLComments = PHP_outdentSLComments * shiftwidth()
else
let b:PHP_outdentSLComments = 0
endif
@@ -141,11 +131,13 @@ let s:PHP_validVariable = '[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*'
let s:notPhpHereDoc = '\%(break\|return\|continue\|exit\|die\|else\)'
let s:blockstart = '\%(\%(\%(}\s*\)\=else\%(\s\+\)\=\)\=if\>\|\%(}\s*\)\?else\>\|do\>\|while\>\|switch\>\|case\>\|default\>\|for\%(each\)\=\>\|declare\>\|class\>\|trait\>\|use\>\|interface\>\|abstract\>\|final\>\|try\>\|\%(}\s*\)\=catch\>\|\%(}\s*\)\=finally\>\)'
let s:functionDecl = '\<function\>\%(\s\+'.s:PHP_validVariable.'\)\=\s*(.*'
-let s:endline= '\s*\%(//.*\|#.*\|/\*.*\*/\s*\)\=$'
+let s:endline = '\s*\%(//.*\|#.*\|/\*.*\*/\s*\)\=$'
+let s:unstated = '\%(^\s*'.s:blockstart.'.*)\|\%(//.*\)\@<!\<e'.'lse\>\)'.s:endline
-let s:terminated = '\%(\%(;\%(\s*\%(?>\|}\)\)\=\|<<<\s*[''"]\=\a\w*[''"]\=$\|^\s*}\|^\s*'.s:PHP_validVariable.':\)'.s:endline.'\)\|^[^''"`]*[''"`]$'
+let s:terminated = '\%(\%(;\%(\s*\%(?>\|}\)\)\=\|<<<\s*[''"]\=\a\w*[''"]\=$\|^\s*}\|^\s*'.s:PHP_validVariable.':\)'.s:endline.'\)'
let s:PHP_startindenttag = '<?\%(.*?>\)\@!\|<script[^>]*>\%(.*<\/script>\)\@!'
+let s:structureHead = '^\s*\%(' . s:blockstart . '\)\|'. s:functionDecl . s:endline . '\|\<new\s\+class\>'
@@ -214,10 +206,28 @@ function! GetLastRealCodeLNum(startline) " {{{
let lnum = lnum - 1
endwhile
elseif lastline =~ '^[^''"`]*[''"`][;,]'.s:endline
- let tofind=substitute( lastline, '^.*\([''"`]\)[;,].*$', '^[^\1]\\+[\1]$', '')
- while getline(lnum) !~? tofind && lnum > 1
- let lnum = lnum - 1
+
+ let tofind=substitute( lastline, '^.*\([''"`]\)[;,].*$', '^[^\1]\\+[\1]$\\|^[^\1]\\+[=([]\\s*[\1]', '')
+ let trylnum = lnum
+ while getline(trylnum) !~? tofind && trylnum > 1
+ let trylnum = trylnum - 1
endwhile
+
+ if trylnum == 1
+ break
+ else
+ if lastline =~ ';'.s:endline
+ while getline(trylnum) !~? s:terminated && getline(trylnum) !~? '{'.s:endline && trylnum > 1
+ let trylnum = prevnonblank(trylnum - 1)
+ endwhile
+
+
+ if trylnum == 1
+ break
+ end
+ end
+ let lnum = trylnum
+ end
else
break
endif
@@ -262,7 +272,7 @@ function! FindOpenBracket(lnum, blockStarter) " {{{
while line > 1
let linec = getline(line)
- if linec =~ s:terminated || linec =~ '^\s*\%(' . s:blockstart . '\)\|'. s:functionDecl . s:endline
+ if linec =~ s:terminated || linec =~ s:structureHead
break
endif
@@ -273,6 +283,20 @@ function! FindOpenBracket(lnum, blockStarter) " {{{
return line
endfun " }}}
+let s:blockChars = {'{':1, '[': 1, '(': 1, ')':-1, ']':-1, '}':-1}
+function! BalanceDirection (str)
+
+ let balance = 0
+
+ for c in split(a:str, '\zs')
+ if has_key(s:blockChars, c)
+ let balance += s:blockChars[c]
+ endif
+ endfor
+
+ return balance
+endfun
+
function! FindTheIfOfAnElse (lnum, StopAfterFirstPrevElse) " {{{
if getline(a:lnum) =~# '^\s*}\s*else\%(if\)\=\>'
@@ -323,7 +347,7 @@ function! FindTheSwitchIndent (lnum) " {{{
let test = GetLastRealCodeLNum(a:lnum - 1)
if test <= 1
- return indent(1) - s:sw() * b:PHP_vintage_case_default_indent
+ return indent(1) - shiftwidth() * b:PHP_vintage_case_default_indent
end
while getline(test) =~ '^\s*}' && test > 1
@@ -337,7 +361,7 @@ function! FindTheSwitchIndent (lnum) " {{{
if getline(test) =~# '^\s*switch\>'
return indent(test)
elseif getline(test) =~# s:defaultORcase
- return indent(test) - s:sw() * b:PHP_vintage_case_default_indent
+ return indent(test) - shiftwidth() * b:PHP_vintage_case_default_indent
else
return FindTheSwitchIndent(test)
endif
@@ -410,7 +434,7 @@ function! GetPhpIndent()
endif
if b:PHP_default_indenting
- let b:PHP_default_indenting = g:PHP_default_indenting * s:sw()
+ let b:PHP_default_indenting = g:PHP_default_indenting * shiftwidth()
endif
let cline = getline(v:lnum)
@@ -457,7 +481,7 @@ function! GetPhpIndent()
if synname!=""
if synname == "SpecStringEntrails"
- let b:InPHPcode = -1
+ let b:InPHPcode = -1 " thumb down
let b:InPHPcode_tofind = ""
elseif synname != "phpHereDoc" && synname != "phpHereDocDelimiter"
let b:InPHPcode = 1
@@ -540,7 +564,7 @@ function! GetPhpIndent()
let b:InPHPcode_and_script = 1
endif
- elseif last_line =~ '^[^''"`]\+[''"`]$'
+ elseif last_line =~ '^[^''"`]\+[''"`]$' " a string identifier with nothing after it and no other string identifier before
let b:InPHPcode = -1
let b:InPHPcode_tofind = substitute( last_line, '^.*\([''"`]\).*$', '^[^\1]*\1[;,]$', '')
elseif last_line =~? '<<<\s*[''"]\=\a\w*[''"]\=$'
@@ -660,25 +684,26 @@ function! GetPhpIndent()
let terminated = s:terminated
- let unstated = '\%(^\s*'.s:blockstart.'.*)\|\%(//.*\)\@<!\<e'.'lse\>\)'.endline
+ let unstated = s:unstated
+
if ind != b:PHP_default_indenting && cline =~# '^\s*else\%(if\)\=\>'
let b:PHP_CurrentIndentLevel = b:PHP_default_indenting
return indent(FindTheIfOfAnElse(v:lnum, 1))
elseif cline =~# s:defaultORcase
- return FindTheSwitchIndent(v:lnum) + s:sw() * b:PHP_vintage_case_default_indent
+ return FindTheSwitchIndent(v:lnum) + shiftwidth() * b:PHP_vintage_case_default_indent
elseif cline =~ '^\s*)\=\s*{'
let previous_line = last_line
let last_line_num = lnum
while last_line_num > 1
- if previous_line =~ terminated || previous_line =~ '^\s*\%(' . s:blockstart . '\)\|'. s:functionDecl . endline
+ if previous_line =~ terminated || previous_line =~ s:structureHead
let ind = indent(last_line_num)
if b:PHP_BracesAtCodeLevel
- let ind = ind + s:sw()
+ let ind = ind + shiftwidth()
endif
return ind
@@ -689,7 +714,7 @@ function! GetPhpIndent()
endwhile
elseif last_line =~# unstated && cline !~ '^\s*);\='.endline
- let ind = ind + s:sw()
+ let ind = ind + shiftwidth() " we indent one level further when the preceding line is not stated
return ind + addSpecial
elseif (ind != b:PHP_default_indenting || last_line =~ '^[)\]]' ) && last_line =~ terminated
@@ -699,7 +724,7 @@ function! GetPhpIndent()
let isSingleLineBlock = 0
while 1
- if ! isSingleLineBlock && previous_line =~ '^\s*}\|;\s*}'.endline
+ if ! isSingleLineBlock && previous_line =~ '^\s*}\|;\s*}'.endline " XXX
call cursor(last_line_num, 1)
if previous_line !~ '^}'
@@ -780,15 +805,15 @@ function! GetPhpIndent()
if !LastLineClosed
- if last_line =~# '[{(\[]'.endline || last_line =~? '\h\w*\s*(.*,$' && AntepenultimateLine !~ '[,(\[]'.endline
+ if last_line =~# '[{(\[]'.endline || last_line =~? '\h\w*\s*(.*,$' && AntepenultimateLine !~ '[,(\[]'.endline && BalanceDirection(last_line) > 0
let dontIndent = 0
- if last_line =~ '\S\+\s*{'.endline && last_line !~ '^\s*)\s*{'.endline && last_line !~ '^\s*\%(' . s:blockstart . '\)\|'. s:functionDecl . s:endline
+ if last_line =~ '\S\+\s*{'.endline && last_line !~ '^\s*[)\]]\+\s*{'.endline && last_line !~ s:structureHead
let dontIndent = 1
endif
if !dontIndent && (!b:PHP_BracesAtCodeLevel || last_line !~# '^\s*{')
- let ind = ind + s:sw()
+ let ind = ind + shiftwidth()
endif
if b:PHP_BracesAtCodeLevel || b:PHP_vintage_case_default_indent == 1
@@ -797,26 +822,26 @@ function! GetPhpIndent()
return ind + addSpecial
endif
- elseif last_line =~ '\S\+\s*),'.endline
+ elseif last_line =~ '\S\+\s*),'.endline && BalanceDirection(last_line) < 0
call cursor(lnum, 1)
- call search('),'.endline, 'W')
+ call search('),'.endline, 'W') " line never begins with ) so no need for 'c' flag
let openedparent = searchpair('(', '', ')', 'bW', 'Skippmatch()')
if openedparent != lnum
let ind = indent(openedparent)
endif
elseif last_line =~ '^\s*'.s:blockstart
- let ind = ind + s:sw()
+ let ind = ind + shiftwidth()
- elseif AntepenultimateLine =~ '{'.endline || AntepenultimateLine =~ terminated || AntepenultimateLine =~# s:defaultORcase
- let ind = ind + s:sw()
+ elseif AntepenultimateLine =~ '{'.endline && AntepenultimateLine !~? '^\s*use\>' || AntepenultimateLine =~ terminated || AntepenultimateLine =~# s:defaultORcase
+ let ind = ind + shiftwidth()
endif
endif
if cline =~ '^\s*[)\]];\='
- let ind = ind - s:sw()
+ let ind = ind - shiftwidth()
endif
let b:PHP_CurrentIndentLevel = ind
diff --git a/runtime/indent/postscr.vim b/runtime/indent/postscr.vim
index b0ff48e682..2592bcf62f 100644
--- a/runtime/indent/postscr.vim
+++ b/runtime/indent/postscr.vim
@@ -41,16 +41,16 @@ function! PostscrIndentGet(lnum)
" Indent for dicts, arrays, and saves with possible trailing comment
if pline =~ '\(begin\|<<\|g\=save\|{\|[\)\s*\(%.*\)\=$'
- let ind = ind + &sw
+ let ind = ind + shiftwidth()
endif
" Remove indent for popped dicts, and restores.
if pline =~ '\(end\|g\=restore\)\s*$'
- let ind = ind - &sw
+ let ind = ind - shiftwidth()
" Else handle immediate dedents of dicts, restores, and arrays.
elseif getline(a:lnum) =~ '\(end\|>>\|g\=restore\|}\|]\)'
- let ind = ind - &sw
+ let ind = ind - shiftwidth()
" Else handle DSC comments - always start of line.
elseif getline(a:lnum) =~ '^\s*%%'
diff --git a/runtime/indent/pov.vim b/runtime/indent/pov.vim
index 2b197635a1..e806756c8e 100644
--- a/runtime/indent/pov.vim
+++ b/runtime/indent/pov.vim
@@ -1,7 +1,7 @@
" Vim indent file
" Language: PoV-Ray Scene Description Language
" Maintainer: David Necas (Yeti) <yeti@physics.muni.cz>
-" Last Change: 2002-10-20
+" Last Change: 2017 Jun 13
" URI: http://trific.ath.cx/Ftp/vim/indent/pov.vim
" Only load this indent file when no other was loaded.
@@ -75,9 +75,9 @@ function GetPoVRayIndent()
" opening line.
let cur = s:MatchCount(v:lnum, '^\s*\%(#\s*\%(end\|else\)\>\|[]})]\)')
if cur > 0
- let final = plind + (chg - cur) * &sw
+ let final = plind + (chg - cur) * shiftwidth()
else
- let final = plind + chg * &sw
+ let final = plind + chg * shiftwidth()
endif
return final < 0 ? 0 : final
diff --git a/runtime/indent/prolog.vim b/runtime/indent/prolog.vim
index afe448e8f3..26a3bc3cd9 100644
--- a/runtime/indent/prolog.vim
+++ b/runtime/indent/prolog.vim
@@ -41,18 +41,18 @@ function! GetPrologIndent()
endif
" Check for clause head on previous line
if pline =~ ':-\s*\(%.*\)\?$'
- let ind = ind + &sw
+ let ind = ind + shiftwidth()
" Check for end of clause on previous line
elseif pline =~ '\.\s*\(%.*\)\?$'
- let ind = ind - &sw
+ let ind = ind - shiftwidth()
endif
" Check for opening conditional on previous line
if pline =~ '^\s*\([(;]\|->\)'
- let ind = ind + &sw
+ let ind = ind + shiftwidth()
endif
" Check for closing an unclosed paren, or middle ; or ->
if line =~ '^\s*\([);]\|->\)'
- let ind = ind - &sw
+ let ind = ind - shiftwidth()
endif
return ind
endfunction
diff --git a/runtime/indent/r.vim b/runtime/indent/r.vim
index 01f3812ed2..373b0e65df 100644
--- a/runtime/indent/r.vim
+++ b/runtime/indent/r.vim
@@ -274,7 +274,7 @@ function GetRIndent()
let nlnum = s:Get_prev_line(nlnum)
let nline = SanitizeRLine(getline(nlnum)) . nline
endwhile
- if nline =~ '^\s*function\s*(' && indent(nlnum) == &sw
+ if nline =~ '^\s*function\s*(' && indent(nlnum) == shiftwidth()
return 0
endif
endif
@@ -285,7 +285,7 @@ function GetRIndent()
" line is an incomplete command:
if line =~ '\<\(if\|while\|for\|function\)\s*()$' || line =~ '\<else$' || line =~ '<-$' || line =~ '->$'
- return indent(lnum) + &sw
+ return indent(lnum) + shiftwidth()
endif
" Deal with () and []
@@ -293,14 +293,14 @@ function GetRIndent()
let pb = s:Get_paren_balance(line, '(', ')')
if line =~ '^\s*{$' || line =~ '(\s*{' || (pb == 0 && (line =~ '{$' || line =~ '(\s*{$'))
- return indent(lnum) + &sw
+ return indent(lnum) + shiftwidth()
endif
let s:curtabstop = repeat(' ', &tabstop)
if g:r_indent_align_args == 1
if pb > 0 && line =~ '{$'
- return s:Get_last_paren_idx(line, '(', ')', pb) + &sw
+ return s:Get_last_paren_idx(line, '(', ')', pb) + shiftwidth()
endif
let bb = s:Get_paren_balance(line, '[', ']')
@@ -364,11 +364,11 @@ function GetRIndent()
if oline =~ g:r_indent_op_pattern && s:Get_paren_balance(line, "(", ")") == 0
return indent(lnum)
else
- return indent(lnum) + &sw
+ return indent(lnum) + shiftwidth()
endif
else
if oline =~ g:r_indent_op_pattern && s:Get_paren_balance(line, "(", ")") == 0
- return indent(lnum) - &sw
+ return indent(lnum) - shiftwidth()
endif
endif
endif
@@ -383,7 +383,7 @@ function GetRIndent()
let line = linepiece . line
endwhile
if line =~ '{$' && post_block == 0
- return indent(lnum) + &sw
+ return indent(lnum) + shiftwidth()
endif
" Now we can do some tests again
@@ -393,19 +393,19 @@ function GetRIndent()
if post_block == 0
let newl = SanitizeRLine(line)
if newl =~ '\<\(if\|while\|for\|function\)\s*()$' || newl =~ '\<else$' || newl =~ '<-$'
- return indent(lnum) + &sw
+ return indent(lnum) + shiftwidth()
endif
endif
endif
if cline =~ '^\s*else'
if line =~ '<-\s*if\s*()'
- return indent(lnum) + &sw
+ return indent(lnum) + shiftwidth()
else
if line =~ '\<if\s*()'
return indent(lnum)
else
- return indent(lnum) - &sw
+ return indent(lnum) - shiftwidth()
endif
endif
endif
@@ -474,12 +474,12 @@ function GetRIndent()
let ind = indent(lnum)
if g:r_indent_align_args == 0 && pb != 0
- let ind += pb * &sw
+ let ind += pb * shiftwidth()
return ind
endif
if g:r_indent_align_args == 0 && bb != 0
- let ind += bb * &sw
+ let ind += bb * shiftwidth()
return ind
endif
@@ -489,7 +489,7 @@ function GetRIndent()
let pind = 0
endif
- if ind == pind || (ind == (pind + &sw) && pline =~ '{$' && ppost_else == 0)
+ if ind == pind || (ind == (pind + shiftwidth()) && pline =~ '{$' && ppost_else == 0)
return ind
endif
@@ -509,7 +509,7 @@ function GetRIndent()
let pbb = s:Get_paren_balance(pline, '[', ']')
endwhile
let pind = indent(plnum)
- if ind == (pind + &sw) && pline =~ '{$'
+ if ind == (pind + shiftwidth()) && pline =~ '{$'
return ind
endif
endwhile
diff --git a/runtime/indent/rhelp.vim b/runtime/indent/rhelp.vim
index 9dc2031cb6..cf69ae3392 100644
--- a/runtime/indent/rhelp.vim
+++ b/runtime/indent/rhelp.vim
@@ -82,7 +82,7 @@ function GetRHelpIndent()
let closeb = strlen(line2) - strlen(line3)
let bb = openb - closeb
- let ind = indent(lnum) + (bb * &sw)
+ let ind = indent(lnum) + (bb * shiftwidth())
if line =~ '^\s*}\s*$'
let ind = indent(lnum)
diff --git a/runtime/indent/rpl.vim b/runtime/indent/rpl.vim
index 07bfd06590..fab258ed2b 100644
--- a/runtime/indent/rpl.vim
+++ b/runtime/indent/rpl.vim
@@ -1,7 +1,7 @@
" Vim indent file
" Language: RPL/2
" Version: 0.2
-" Last Change: 2005 Mar 28
+" Last Change: 2017 Jun 13
" Maintainer: BERTRAND Joël <rpl2@free.fr>
" Only load this indent file when no other was loaded.
@@ -32,16 +32,16 @@ function RplGetIndent(lnum)
if prevstat =~? '\<\(if\|iferr\|do\|while\)\>' && prevstat =~? '\<end\>'
elseif prevstat =~? '\(^\|\s\+\)<<\($\|\s\+\)' && prevstat =~? '\s\+>>\($\|\s\+\)'
elseif prevstat =~? '\<\(if\|iferr\|then\|else\|elseif\|select\|case\|do\|until\|while\|repeat\|for\|start\|default\)\>' || prevstat =~? '\(^\|\s\+\)<<\($\|\s\+\)'
- let ind = ind + &sw
+ let ind = ind + shiftwidth()
endif
" Subtract a shiftwidth from then, else, elseif, end, until, repeat, next,
" step
let line = getline(v:lnum)
if line =~? '^\s*\(then\|else\|elseif\|until\|repeat\|next\|step\|default\|end\)\>'
- let ind = ind - &sw
+ let ind = ind - shiftwidth()
elseif line =~? '^\s*>>\($\|\s\+\)'
- let ind = ind - &sw
+ let ind = ind - shiftwidth()
endif
return ind
diff --git a/runtime/indent/ruby.vim b/runtime/indent/ruby.vim
index a97f4828d6..d8733db305 100644
--- a/runtime/indent/ruby.vim
+++ b/runtime/indent/ruby.vim
@@ -404,11 +404,7 @@ function GetRubyIndent(...)
" ----------
" The value of a single shift-width
- if exists('*shiftwidth')
- let sw = shiftwidth()
- else
- let sw = &sw
- endif
+ let sw = shiftwidth()
" For the current line, use the first argument if given, else v:lnum
let clnum = a:0 ? a:1 : v:lnum
diff --git a/runtime/indent/rust.vim b/runtime/indent/rust.vim
new file mode 100644
index 0000000000..d30629b64e
--- /dev/null
+++ b/runtime/indent/rust.vim
@@ -0,0 +1,213 @@
+" Vim indent file
+" Language: Rust
+" Author: Chris Morgan <me@chrismorgan.info>
+" Last Change: 2017 Jun 13
+" For bugs, patches and license go to https://github.com/rust-lang/rust.vim
+
+" Only load this indent file when no other was loaded.
+if exists("b:did_indent")
+ finish
+endif
+let b:did_indent = 1
+
+setlocal cindent
+setlocal cinoptions=L0,(0,Ws,J1,j1
+setlocal cinkeys=0{,0},!^F,o,O,0[,0]
+" Don't think cinwords will actually do anything at all... never mind
+setlocal cinwords=for,if,else,while,loop,impl,mod,unsafe,trait,struct,enum,fn,extern
+
+" Some preliminary settings
+setlocal nolisp " Make sure lisp indenting doesn't supersede us
+setlocal autoindent " indentexpr isn't much help otherwise
+" Also do indentkeys, otherwise # gets shoved to column 0 :-/
+setlocal indentkeys=0{,0},!^F,o,O,0[,0]
+
+setlocal indentexpr=GetRustIndent(v:lnum)
+
+" Only define the function once.
+if exists("*GetRustIndent")
+ finish
+endif
+
+let s:save_cpo = &cpo
+set cpo&vim
+
+" Come here when loading the script the first time.
+
+function! s:get_line_trimmed(lnum)
+ " Get the line and remove a trailing comment.
+ " Use syntax highlighting attributes when possible.
+ " NOTE: this is not accurate; /* */ or a line continuation could trick it
+ let line = getline(a:lnum)
+ let line_len = strlen(line)
+ if has('syntax_items')
+ " If the last character in the line is a comment, do a binary search for
+ " the start of the comment. synID() is slow, a linear search would take
+ " too long on a long line.
+ if synIDattr(synID(a:lnum, line_len, 1), "name") =~ 'Comment\|Todo'
+ let min = 1
+ let max = line_len
+ while min < max
+ let col = (min + max) / 2
+ if synIDattr(synID(a:lnum, col, 1), "name") =~ 'Comment\|Todo'
+ let max = col
+ else
+ let min = col + 1
+ endif
+ endwhile
+ let line = strpart(line, 0, min - 1)
+ endif
+ return substitute(line, "\s*$", "", "")
+ else
+ " Sorry, this is not complete, nor fully correct (e.g. string "//").
+ " Such is life.
+ return substitute(line, "\s*//.*$", "", "")
+ endif
+endfunction
+
+function! s:is_string_comment(lnum, col)
+ if has('syntax_items')
+ for id in synstack(a:lnum, a:col)
+ let synname = synIDattr(id, "name")
+ if synname == "rustString" || synname =~ "^rustComment"
+ return 1
+ endif
+ endfor
+ else
+ " without syntax, let's not even try
+ return 0
+ endif
+endfunction
+
+function GetRustIndent(lnum)
+
+ " Starting assumption: cindent (called at the end) will do it right
+ " normally. We just want to fix up a few cases.
+
+ let line = getline(a:lnum)
+
+ if has('syntax_items')
+ let synname = synIDattr(synID(a:lnum, 1, 1), "name")
+ if synname == "rustString"
+ " If the start of the line is in a string, don't change the indent
+ return -1
+ elseif synname =~ '\(Comment\|Todo\)'
+ \ && line !~ '^\s*/\*' " not /* opening line
+ if synname =~ "CommentML" " multi-line
+ if line !~ '^\s*\*' && getline(a:lnum - 1) =~ '^\s*/\*'
+ " This is (hopefully) the line after a /*, and it has no
+ " leader, so the correct indentation is that of the
+ " previous line.
+ return GetRustIndent(a:lnum - 1)
+ endif
+ endif
+ " If it's in a comment, let cindent take care of it now. This is
+ " for cases like "/*" where the next line should start " * ", not
+ " "* " as the code below would otherwise cause for module scope
+ " Fun fact: " /*\n*\n*/" takes two calls to get right!
+ return cindent(a:lnum)
+ endif
+ endif
+
+ " cindent gets second and subsequent match patterns/struct members wrong,
+ " as it treats the comma as indicating an unfinished statement::
+ "
+ " match a {
+ " b => c,
+ " d => e,
+ " f => g,
+ " };
+
+ " Search backwards for the previous non-empty line.
+ let prevlinenum = prevnonblank(a:lnum - 1)
+ let prevline = s:get_line_trimmed(prevlinenum)
+ while prevlinenum > 1 && prevline !~ '[^[:blank:]]'
+ let prevlinenum = prevnonblank(prevlinenum - 1)
+ let prevline = s:get_line_trimmed(prevlinenum)
+ endwhile
+
+ " Handle where clauses nicely: subsequent values should line up nicely.
+ if prevline[len(prevline) - 1] == ","
+ \ && prevline =~# '^\s*where\s'
+ return indent(prevlinenum) + 6
+ endif
+
+ if prevline[len(prevline) - 1] == ","
+ \ && s:get_line_trimmed(a:lnum) !~ '^\s*[\[\]{}]'
+ \ && prevline !~ '^\s*fn\s'
+ \ && prevline !~ '([^()]\+,$'
+ \ && s:get_line_trimmed(a:lnum) !~ '^\s*\S\+\s*=>'
+ " Oh ho! The previous line ended in a comma! I bet cindent will try to
+ " take this too far... For now, let's normally use the previous line's
+ " indent.
+
+ " One case where this doesn't work out is where *this* line contains
+ " square or curly brackets; then we normally *do* want to be indenting
+ " further.
+ "
+ " Another case where we don't want to is one like a function
+ " definition with arguments spread over multiple lines:
+ "
+ " fn foo(baz: Baz,
+ " baz: Baz) // <-- cindent gets this right by itself
+ "
+ " Another case is similar to the previous, except calling a function
+ " instead of defining it, or any conditional expression that leaves
+ " an open paren:
+ "
+ " foo(baz,
+ " baz);
+ "
+ " if baz && (foo ||
+ " bar) {
+ "
+ " Another case is when the current line is a new match arm.
+ "
+ " There are probably other cases where we don't want to do this as
+ " well. Add them as needed.
+ return indent(prevlinenum)
+ endif
+
+ if !has("patch-7.4.355")
+ " cindent before 7.4.355 doesn't do the module scope well at all; e.g.::
+ "
+ " static FOO : &'static [bool] = [
+ " true,
+ " false,
+ " false,
+ " true,
+ " ];
+ "
+ " uh oh, next statement is indented further!
+
+ " Note that this does *not* apply the line continuation pattern properly;
+ " that's too hard to do correctly for my liking at present, so I'll just
+ " start with these two main cases (square brackets and not returning to
+ " column zero)
+
+ call cursor(a:lnum, 1)
+ if searchpair('{\|(', '', '}\|)', 'nbW',
+ \ 's:is_string_comment(line("."), col("."))') == 0
+ if searchpair('\[', '', '\]', 'nbW',
+ \ 's:is_string_comment(line("."), col("."))') == 0
+ " Global scope, should be zero
+ return 0
+ else
+ " At the module scope, inside square brackets only
+ "if getline(a:lnum)[0] == ']' || search('\[', '', '\]', 'nW') == a:lnum
+ if line =~ "^\\s*]"
+ " It's the closing line, dedent it
+ return 0
+ else
+ return shiftwidth()
+ endif
+ endif
+ endif
+ endif
+
+ " Fall back on cindent, which does it mostly right
+ return cindent(a:lnum)
+endfunction
+
+let &cpo = s:save_cpo
+unlet s:save_cpo
diff --git a/runtime/indent/sass.vim b/runtime/indent/sass.vim
index d87b371fdd..d6dbf3a8bb 100644
--- a/runtime/indent/sass.vim
+++ b/runtime/indent/sass.vim
@@ -1,7 +1,7 @@
" Vim indent file
" Language: Sass
" Maintainer: Tim Pope <vimNOSPAM@tpope.org>
-" Last Change: 2016 Aug 29
+" Last Change: 2017 Jun 13
if exists("b:did_indent")
finish
@@ -29,7 +29,7 @@ function! GetSassIndent()
let indent = indent(lnum)
let cindent = indent(v:lnum)
if line !~ s:property && line !~ s:extend && cline =~ s:property
- return indent + (exists('*shiftwidth') ? shiftwidth() : &sw)
+ return indent + shiftwidth()
else
return -1
endif
diff --git a/runtime/indent/sdl.vim b/runtime/indent/sdl.vim
index ba03f2d3f4..6ce30b6797 100644
--- a/runtime/indent/sdl.vim
+++ b/runtime/indent/sdl.vim
@@ -46,17 +46,17 @@ function! GetSDLIndent()
if (getline(lnum) =~? '^\s*\(start\|state\|system\|package\|connection\|channel\|alternative\|macro\|operator\|newtype\|select\|substructure\|decision\|generator\|refinement\|service\|method\|exceptionhandler\|asntype\|syntype\|value\|(.*):\|\(priority\s\+\)\=input\|provided\)'
\ || getline(lnum) =~? virtuality . '\(process\|procedure\|block\|object\)')
\ && getline(lnum) !~? 'end[[:alpha:]]\+;$'
- let ind = ind + &sw
+ let ind = ind + shiftwidth()
endif
" Subtract a 'shiftwidth' after states
if getline(lnum) =~? '^\s*\(stop\|return\>\|nextstate\)'
- let ind = ind - &sw
+ let ind = ind - shiftwidth()
endif
" Subtract a 'shiftwidth' on on end (uncompleted line)
if getline(v:lnum) =~? '^\s*end\>'
- let ind = ind - &sw
+ let ind = ind - shiftwidth()
endif
" Put each alternatives where the corresponding decision was
diff --git a/runtime/indent/sh.vim b/runtime/indent/sh.vim
index aca110f504..ae4f4b53c4 100644
--- a/runtime/indent/sh.vim
+++ b/runtime/indent/sh.vim
@@ -3,10 +3,12 @@
" Maintainer: Christian Brabandt <cb@256bit.org>
" Previous Maintainer: Peter Aronoff <telemachus@arpinum.org>
" Original Author: Nikolai Weibull <now@bitwi.se>
-" Latest Revision: 2016-06-27
+" Latest Revision: 2017-05-02
" License: Vim (see :h license)
" Repository: https://github.com/chrisbra/vim-sh-indent
" Changelog:
+" 20170502: - get rid of buffer-shiftwidth function
+" 20160912: - preserve indentation of here-doc blocks
" 20160627: - detect heredocs correctly
" 20160213: - detect function definition correctly
" 20160202: - use shiftwidth() function
@@ -33,15 +35,11 @@ endif
let s:cpo_save = &cpo
set cpo&vim
-function s:buffer_shiftwidth()
- return shiftwidth()
-endfunction
-
let s:sh_indent_defaults = {
- \ 'default': function('s:buffer_shiftwidth'),
- \ 'continuation-line': function('s:buffer_shiftwidth'),
- \ 'case-labels': function('s:buffer_shiftwidth'),
- \ 'case-statements': function('s:buffer_shiftwidth'),
+ \ 'default': function('shiftwidth'),
+ \ 'continuation-line': function('shiftwidth'),
+ \ 'case-labels': function('shiftwidth'),
+ \ 'case-statements': function('shiftwidth'),
\ 'case-breaks': 0 }
function! s:indent_value(option)
@@ -110,6 +108,9 @@ function! GetShIndent()
let ind -= s:indent_value('case-breaks')
elseif s:is_here_doc(line)
let ind = 0
+ " statements, executed within a here document. Keep the current indent
+ elseif match(map(synstack(v:lnum, 1), 'synIDattr(v:val, "name")'), '\c\mheredoc') > -1
+ return indent(v:lnum)
endif
return ind
diff --git a/runtime/indent/sml.vim b/runtime/indent/sml.vim
index fbbb15ed85..e760a8e350 100644
--- a/runtime/indent/sml.vim
+++ b/runtime/indent/sml.vim
@@ -115,9 +115,9 @@ function! GetSMLIndent()
" Return double 'shiftwidth' after lines matching:
if lline =~ '^\s*|.*=>\s*$'
- return ind + &sw + &sw
+ return ind + 2 *shiftwidth()
elseif lline =~ '^\s*val\>.*=\s*$'
- return ind + &sw
+ return ind + shiftwidth()
endif
let line = getline(v:lnum)
@@ -157,7 +157,7 @@ function! GetSMLIndent()
if lastModule == -1
return 0
else
- return lastModule + &sw
+ return lastModule + shiftwidth()
endif
" Indent lines starting with '|' from matching 'case', 'handle'
@@ -172,7 +172,7 @@ function! GetSMLIndent()
if switchLine =~ '\<case\>'
return col(".") + 2
elseif switchLine =~ '\<handle\>'
- return switchLineIndent + &sw
+ return switchLineIndent + shiftwidth()
elseif switchLine =~ '\<datatype\>'
call search('=')
return col(".") - 1
@@ -184,7 +184,7 @@ function! GetSMLIndent()
" Indent if last line ends with 'sig', 'struct', 'let', 'then', 'else',
" 'in'
elseif lline =~ '\<\(sig\|struct\|let\|in\|then\|else\)\s*$'
- let ind = ind + &sw
+ let ind = ind + shiftwidth()
" Indent if last line ends with 'of', align from 'case'
elseif lline =~ '\<\(of\)\s*$'
@@ -199,14 +199,14 @@ function! GetSMLIndent()
" Indent if last line starts with 'fun', 'case', 'fn'
elseif lline =~ '^\s*\(fun\|fn\|case\)\>'
- let ind = ind + &sw
+ let ind = ind + shiftwidth()
endif
" Don't indent 'let' if last line started with 'fun', 'fn'
if line =~ '^\s*let\>'
if lline =~ '^\s*\(fun\|fn\)'
- let ind = ind - &sw
+ let ind = ind - shiftwidth()
endif
endif
diff --git a/runtime/indent/sqlanywhere.vim b/runtime/indent/sqlanywhere.vim
index d11c54b5af..ba35d76715 100644
--- a/runtime/indent/sqlanywhere.vim
+++ b/runtime/indent/sqlanywhere.vim
@@ -1,7 +1,7 @@
" Vim indent file
" Language: SQL
" Maintainer: David Fishburn <dfishburn dot vim at gmail dot com>
-" Last Change: 2012 Dec 06
+" Last Change: 2017 Jun 13
" Version: 3.0
" Download: http://vim.sourceforge.net/script.php?script_id=495
@@ -147,7 +147,7 @@ function! s:CheckToIgnoreRightParan( prev_lnum, num_levels )
endwhile
" Fallback - just move back one
- " return a:prev_indent - &sw
+ " return a:prev_indent - shiftwidth()
return ignore_paran
endfunction
@@ -166,7 +166,7 @@ function! s:GetStmtStarterIndent( keyword, curr_lnum )
let lnum = a:curr_lnum
" Default - reduce indent by 1
- let ind = indent(a:curr_lnum) - &sw
+ let ind = indent(a:curr_lnum) - shiftwidth()
if a:keyword =~? 'end'
exec 'normal! ^'
@@ -230,7 +230,7 @@ function! s:ModuloIndent(ind)
let ind = a:ind
if ind > 0
- let modulo = ind % &shiftwidth
+ let modulo = ind % shiftwidth()
if modulo > 0
let ind = ind - modulo
@@ -291,7 +291,7 @@ function! GetSQLIndent()
" where END IF, END, should decrease the indent.
if prevline =~? s:SQLBlockStart
" Move indent in
- let ind = ind + &sw
+ let ind = ind + shiftwidth()
" echom 'prevl - SQLBlockStart - indent ' . ind . ' line: ' . prevline
elseif prevline =~ '[()]'
if prevline =~ '('
@@ -308,7 +308,7 @@ function! GetSQLIndent()
if num_unmatched_left > 0
" There is a open left paranethesis
" increase indent
- let ind = ind + ( &sw * num_unmatched_left )
+ let ind = ind + ( shiftwidth() * num_unmatched_left )
elseif num_unmatched_right > 0
" if it is an unbalanced paranethesis only unindent if
" it was part of a command (ie create table(..) )
@@ -323,7 +323,7 @@ function! GetSQLIndent()
endif
if (num_unmatched_right - ignore) > 0
- let ind = ind - ( &sw * (num_unmatched_right - ignore) )
+ let ind = ind - ( shiftwidth() * (num_unmatched_right - ignore) )
endif
endif
@@ -339,12 +339,12 @@ function! GetSQLIndent()
if line =~? '^\s*els'
" Any line when you type else will automatically back up one
" ident level (ie else, elseif, elsif)
- let ind = ind - &sw
+ let ind = ind - shiftwidth()
" echom 'curr - else - indent ' . ind
elseif line =~? '^\s*end\>'
let ind = s:GetStmtStarterIndent('end', v:lnum)
" General case for end
- " let ind = ind - &sw
+ " let ind = ind - shiftwidth()
" echom 'curr - end - indent ' . ind
elseif line =~? '^\s*when\>'
let ind = s:GetStmtStarterIndent('when', v:lnum)
@@ -352,7 +352,7 @@ function! GetSQLIndent()
" clause, do not change the indent level, since these
" statements do not have a corresponding END statement.
" if stmt_starter =~? 'case'
- " let ind = ind - &sw
+ " let ind = ind - shiftwidth()
" endif
" elseif line =~ '^\s*)\s*;\?\s*$'
" elseif line =~ '^\s*)'
@@ -371,14 +371,14 @@ function! GetSQLIndent()
" let num_unmatched_right = s:CountUnbalancedParan( line, ')' )
" if num_unmatched_right > 0
" elseif strpart( line, strlen(line)-1, 1 ) =~ ')'
- " let ind = ind - &sw
+ " let ind = ind - shiftwidth()
if line =~ '^\s*)'
" let ignore = ignore + 1
" echom 'curr - begins ) unbalanced ignore: ' . ignore
endif
if (num_unmatched_right - ignore) > 0
- let ind = ind - ( &sw * (num_unmatched_right - ignore) )
+ let ind = ind - ( shiftwidth() * (num_unmatched_right - ignore) )
endif
" endif
endif
diff --git a/runtime/indent/systemverilog.vim b/runtime/indent/systemverilog.vim
index b017535535..91fba4c3b6 100644
--- a/runtime/indent/systemverilog.vim
+++ b/runtime/indent/systemverilog.vim
@@ -29,7 +29,7 @@ function SystemVerilogIndent()
if exists('b:systemverilog_indent_width')
let offset = b:systemverilog_indent_width
else
- let offset = &sw
+ let offset = shiftwidth()
endif
if exists('b:systemverilog_indent_modules')
let indent_modules = offset
diff --git a/runtime/indent/teraterm.vim b/runtime/indent/teraterm.vim
index 8467cefcc0..370283c77f 100644
--- a/runtime/indent/teraterm.vim
+++ b/runtime/indent/teraterm.vim
@@ -3,7 +3,7 @@
" Based on Tera Term Version 4.92
" Maintainer: Ken Takata
" URL: https://github.com/k-takata/vim-teraterm
-" Last Change: 2016 Aug 17
+" Last Change: 2017 Jun 13
" Filenames: *.ttl
" License: VIM License
@@ -22,16 +22,6 @@ if exists("*GetTeraTermIndent")
finish
endif
-" The shiftwidth() function is relatively new.
-" Don't require it to exist.
-if exists('*shiftwidth')
- let s:sw = function('shiftwidth')
-else
- function s:sw() abort
- return &shiftwidth
- endfunction
-endif
-
function! GetTeraTermIndent(lnum)
let l:prevlnum = prevnonblank(a:lnum-1)
if l:prevlnum == 0
@@ -48,15 +38,15 @@ function! GetTeraTermIndent(lnum)
if l:prevl =~ '^\s*if\>.*\<then\>'
" previous line opened a block
- let l:ind += s:sw()
+ let l:ind += shiftwidth()
endif
if l:prevl =~ '^\s*\%(elseif\|else\|do\|until\|while\|for\)\>'
" previous line opened a block
- let l:ind += s:sw()
+ let l:ind += shiftwidth()
endif
if l:thisl =~ '^\s*\%(elseif\|else\|endif\|enduntil\|endwhile\|loop\|next\)\>'
" this line closed a block
- let l:ind -= s:sw()
+ let l:ind -= shiftwidth()
endif
return l:ind
diff --git a/runtime/indent/tex.vim b/runtime/indent/tex.vim
index 0150bb9623..1a4d8b1cb6 100644
--- a/runtime/indent/tex.vim
+++ b/runtime/indent/tex.vim
@@ -1,8 +1,8 @@
" Vim indent file
" Language: LaTeX
-" Maintainer: YiChao Zhou <broken.zhou AT gmail.com>
+" Maintainer: Yichao Zhou <broken.zhou AT gmail.com>
" Created: Sat, 16 Feb 2002 16:50:19 +0100
-" Version: 0.9.2
+" Version: 0.9.4
" Please email me if you found something I can do. Comments, bug report and
" feature request are welcome.
@@ -15,49 +15,53 @@
" 2005/06/15, Moshe Kaminsky <kaminsky AT math.huji.ac.il>
" (*) New variables:
" g:tex_items, g:tex_itemize_env, g:tex_noindent_env
-" 2011/3/6, by Zhou YiChao <broken.zhou AT gmail.com>
+" 2011/3/6, by Yichao Zhou <broken.zhou AT gmail.com>
" (*) Don't change indentation of lines starting with '%'
" I don't see any code with '%' and it doesn't work properly
" so I add some code.
" (*) New features: Add smartindent-like indent for "{}" and "[]".
" (*) New variables: g:tex_indent_brace
-" 2011/9/25, by Zhou Yichao <broken.zhou AT gmail.com>
+" 2011/9/25, by Yichao Zhou <broken.zhou AT gmail.com>
" (*) Bug fix: smartindent-like indent for "[]"
" (*) New features: Align with "&".
" (*) New variable: g:tex_indent_and.
-" 2011/10/23 by Zhou Yichao <broken.zhou AT gmail.com>
+" 2011/10/23 by Yichao Zhou <broken.zhou AT gmail.com>
" (*) Bug fix: improve the smartindent-like indent for "{}" and
" "[]".
-" 2012/02/27 by Zhou Yichao <broken.zhou AT gmail.com>
+" 2012/02/27 by Yichao Zhou <broken.zhou AT gmail.com>
" (*) Bug fix: support default folding marker.
" (*) Indent with "&" is not very handy. Make it not enable by
" default.
-" 2012/03/06 by Zhou Yichao <broken.zhou AT gmail.com>
+" 2012/03/06 by Yichao Zhou <broken.zhou AT gmail.com>
" (*) Modify "&" behavior and make it default again. Now "&"
" won't align when there are more then one "&" in the previous
" line.
" (*) Add indent "\left(" and "\right)"
" (*) Trust user when in "verbatim" and "lstlisting"
-" 2012/03/11 by Zhou Yichao <broken.zhou AT gmail.com>
+" 2012/03/11 by Yichao Zhou <broken.zhou AT gmail.com>
" (*) Modify "&" so that only indent when current line start with
" "&".
-" 2012/03/12 by Zhou Yichao <broken.zhou AT gmail.com>
+" 2012/03/12 by Yichao Zhou <broken.zhou AT gmail.com>
" (*) Modify indentkeys.
-" 2012/03/18 by Zhou Yichao <broken.zhou AT gmail.com>
+" 2012/03/18 by Yichao Zhou <broken.zhou AT gmail.com>
" (*) Add &cpo
-" 2013/05/02 by Zhou Yichao <broken.zhou AT gmail.com>
+" 2013/05/02 by Yichao Zhou <broken.zhou AT gmail.com>
" (*) Fix problem about GetTeXIndent checker. Thank Albert Netymk
" for reporting this.
-" 2014/06/23 by Zhou Yichao <broken.zhou AT gmail.com>
+" 2014/06/23 by Yichao Zhou <broken.zhou AT gmail.com>
" (*) Remove the feature g:tex_indent_and because it is buggy.
" (*) If there is not any obvious indentation hints, we do not
" alert our user's current indentation.
" (*) g:tex_indent_brace now only works if the open brace is the
" last character of that line.
-" 2014/08/03 by Zhou Yichao <broken.zhou AT gmail.com>
+" 2014/08/03 by Yichao Zhou <broken.zhou AT gmail.com>
" (*) Indent current line if last line has larger indentation
-" 2014/08/09 by Zhou Yichao <broken.zhou AT gmail.com>
-" (*) Add missing return value for s:GetEndIndentation(...)
+" 2016/11/08 by Yichao Zhou <broken.zhou AT gmail.com>
+" (*) Fix problems for \[ and \]. Thanks Bruno for reporting.
+" 2017/04/30 by Yichao Zhou <broken.zhou AT gmail.com>
+" (*) Fix a bug between g:tex_noindent_env and g:tex_indent_items
+" Now g:tex_noindent_env='document\|verbatim\|itemize' (Emacs
+" style) is supported. Thanks Miles Wheeler for reporting.
"
" }}}
@@ -81,44 +85,44 @@
" % Example 2
" \tikzexternalize[
" prefix=tikz]
-"
+"
" * g:tex_indent_items
"
" If this variable is set, item-environments are indented like Emacs does
" it, i.e., continuation lines are indented with a shiftwidth.
-"
+"
" NOTE: I've already set the variable below; delete the corresponding line
" if you don't like this behaviour.
"
" Per default, it is unset.
-"
+"
" set unset
" ----------------------------------------------------------------
-" \begin{itemize} \begin{itemize}
+" \begin{itemize} \begin{itemize}
" \item blablabla \item blablabla
-" bla bla bla bla bla bla
+" bla bla bla bla bla bla
" \item blablabla \item blablabla
-" bla bla bla bla bla bla
-" \end{itemize} \end{itemize}
+" bla bla bla bla bla bla
+" \end{itemize} \end{itemize}
"
"
" * g:tex_items
"
-" A list of tokens to be considered as commands for the beginning of an item
-" command. The tokens should be separated with '\|'. The initial '\' should
+" A list of tokens to be considered as commands for the beginning of an item
+" command. The tokens should be separated with '\|'. The initial '\' should
" be escaped. The default is '\\bibitem\|\\item'.
"
" * g:tex_itemize_env
-"
-" A list of environment names, separated with '\|', where the items (item
-" commands matching g:tex_items) may appear. The default is
+"
+" A list of environment names, separated with '\|', where the items (item
+" commands matching g:tex_items) may appear. The default is
" 'itemize\|description\|enumerate\|thebibliography'.
"
" * g:tex_noindent_env
"
-" A list of environment names. separated with '\|', where no indentation is
+" A list of environment names. separated with '\|', where no indentation is
" required. The default is 'document\|verbatim'.
-" }}}
+" }}}
" Only define the function once
if exists("b:did_indent")
@@ -146,7 +150,7 @@ if g:tex_indent_items
let g:tex_itemize_env = 'itemize\|description\|enumerate\|thebibliography'
endif
if !exists('g:tex_items')
- let g:tex_items = '\\bibitem\|\\item'
+ let g:tex_items = '\\bibitem\|\\item'
endif
else
let g:tex_items = ''
@@ -177,7 +181,7 @@ function! GetTeXIndent() " {{{
" At the start of the file use zero indent.
if lnum == 0
- return 0
+ return 0
endif
let line = substitute(getline(lnum), '\s*%.*', '','g') " last line
@@ -191,9 +195,9 @@ function! GetTeXIndent() " {{{
return indent(v:lnum)
end
endif
-
+
if lnum == 0
- return 0
+ return 0
endif
let ind = indent(lnum)
@@ -206,17 +210,19 @@ function! GetTeXIndent() " {{{
" Add a 'shiftwidth' after beginning of environments.
" Don't add it for \begin{document} and \begin{verbatim}
- ""if line =~ '^\s*\\begin{\(.*\)}' && line !~ 'verbatim'
+ " if line =~ '^\s*\\begin{\(.*\)}' && line !~ 'verbatim'
" LH modification : \begin does not always start a line
" ZYC modification : \end after \begin won't cause wrong indent anymore
- if line =~ '\\begin{.*}' && line !~ g:tex_noindent_env
- let ind = ind + &sw
- let stay = 0
+ if line =~ '\\begin{.*}'
+ if line !~ g:tex_noindent_env
+ let ind = ind + shiftwidth()
+ let stay = 0
+ endif
if g:tex_indent_items
" Add another sw for item-environments
if line =~ g:tex_itemize_env
- let ind = ind + &sw
+ let ind = ind + shiftwidth()
let stay = 0
endif
endif
@@ -235,39 +241,37 @@ function! GetTeXIndent() " {{{
if g:tex_indent_items
" Remove another sw for item-environments
if cline =~ g:tex_itemize_env
- let ind = ind - &sw
+ let ind = ind - shiftwidth()
let stay = 0
endif
endif
- let ind = ind - &sw
+ let ind = ind - shiftwidth()
let stay = 0
endif
if g:tex_indent_brace
- let char = line[strlen(line)-1]
- if char == '[' || char == '{'
- let ind += &sw
+ if line =~ '[[{]$'
+ let ind += shiftwidth()
let stay = 0
endif
- let cind = indent(v:lnum)
- let char = cline[cind]
- if (char == ']' || char == '}') &&
- \ s:CheckPairedIsLastCharacter(v:lnum, cind)
- let ind -= &sw
+ if cline =~ '^\s*\\\?[\]}]' && s:CheckPairedIsLastCharacter(v:lnum, indent(v:lnum))
+ let ind -= shiftwidth()
let stay = 0
endif
- for i in range(indent(lnum)+1, strlen(line)-1)
- let char = line[i]
- if char == ']' || char == '}'
- if s:CheckPairedIsLastCharacter(lnum, i)
- let ind -= &sw
- let stay = 0
+ if line !~ '^\s*\\\?[\]}]'
+ for i in range(indent(lnum)+1, strlen(line)-1)
+ let char = line[i]
+ if char == ']' || char == '}'
+ if s:CheckPairedIsLastCharacter(lnum, i)
+ let ind -= shiftwidth()
+ let stay = 0
+ endif
endif
- endif
- endfor
+ endfor
+ endif
endif
" Special treatment for 'item'
@@ -276,12 +280,12 @@ function! GetTeXIndent() " {{{
if g:tex_indent_items
" '\item' or '\bibitem' itself:
if cline =~ g:tex_items
- let ind = ind - &sw
+ let ind = ind - shiftwidth()
let stay = 0
endif
" lines following to '\item' are intented once again:
if line =~ g:tex_items
- let ind = ind + &sw
+ let ind = ind + shiftwidth()
let stay = 0
endif
endif
@@ -309,13 +313,13 @@ function! s:GetLastBeginIndentation(lnum) " {{{
let matchend -= 1
endif
if matchend == 0
- if line =~ g:tex_itemize_env
- return indent(lnum) + 2 * &sw
- endif
if line =~ g:tex_noindent_env
return indent(lnum)
endif
- return indent(lnum) + &sw
+ if line =~ g:tex_itemize_env
+ return indent(lnum) + 2 * shiftwidth()
+ endif
+ return indent(lnum) + shiftwidth()
endif
endfor
return -1
@@ -343,17 +347,20 @@ function! s:GetEndIndentation(lnum) " {{{
let min_indent = min([min_indent, indent(lnum)])
endif
endfor
- return min_indent - &sw
+ return min_indent - shiftwidth()
endfunction
" Most of the code is from matchparen.vim
function! s:CheckPairedIsLastCharacter(lnum, col) "{{{
- " Get the character under the cursor and check if it's in 'matchpairs'.
let c_lnum = a:lnum
let c_col = a:col+1
+ let line = getline(c_lnum)
+ if line[c_col-1] == '\'
+ let c_col = c_col + 1
+ endif
+ let c = line[c_col-1]
- let c = getline(c_lnum)[c_col-1]
let plist = split(&matchpairs, '.\zs[:,]')
let i = index(plist, c)
if i < 0
diff --git a/runtime/indent/tilde.vim b/runtime/indent/tilde.vim
index 5fdcfe0711..13082c8692 100644
--- a/runtime/indent/tilde.vim
+++ b/runtime/indent/tilde.vim
@@ -25,11 +25,11 @@ function GetTildeIndent(lnum)
endif
if getline(v:lnum) =~ '^\s*\~\(endif\|else\|elseif\|end\)\>'
- return indent(v:lnum) - &sw
+ return indent(v:lnum) - shiftwidth()
endif
if getline(plnum) =~ '^\s*\~\(if\|foreach\|foreach_row\|xml_loop\|file_loop\|file_write\|file_append\|imap_loopsections\|imap_index\|imap_list\|ldap_search\|post_loopall\|post_loop\|file_loop\|sql_loop_num\|sql_dbmsselect\|search\|sql_loop\|post\|for\|function_define\|silent\|while\|setvalbig\|mail_create\|systempipe\|mail_send\|dual\|elseif\|else\)\>'
- return indent(plnum) + &sw
+ return indent(plnum) + shiftwidth()
else
return -1
endif
diff --git a/runtime/indent/vb.vim b/runtime/indent/vb.vim
index 55a8ea302a..4d05345565 100644
--- a/runtime/indent/vb.vim
+++ b/runtime/indent/vb.vim
@@ -49,26 +49,26 @@ fun! VbGetIndent(lnum)
" Add
if previous_line =~? '^\s*\<\(begin\|\%(\%(private\|public\|friend\)\s\+\)\=\%(function\|sub\|property\)\|select\|case\|default\|if\|else\|elseif\|do\|for\|while\|enum\|with\)\>'
- let ind = ind + &sw
+ let ind = ind + shiftwidth()
endif
" Subtract
if this_line =~? '^\s*\<end\>\s\+\<select\>'
if previous_line !~? '^\s*\<select\>'
- let ind = ind - 2 * &sw
+ let ind = ind - 2 * shiftwidth()
else
" this case is for an empty 'select' -- 'end select'
" (w/o any case statements) like:
"
" select case readwrite
" end select
- let ind = ind - &sw
+ let ind = ind - shiftwidth()
endif
elseif this_line =~? '^\s*\<\(end\|else\|elseif\|until\|loop\|next\|wend\)\>'
- let ind = ind - &sw
+ let ind = ind - shiftwidth()
elseif this_line =~? '^\s*\<\(case\|default\)\>'
if previous_line !~? '^\s*\<select\>'
- let ind = ind - &sw
+ let ind = ind - shiftwidth()
endif
endif
diff --git a/runtime/indent/vhdl.vim b/runtime/indent/vhdl.vim
index 6982859670..7c3956035e 100644
--- a/runtime/indent/vhdl.vim
+++ b/runtime/indent/vhdl.vim
@@ -2,7 +2,7 @@
" Language: VHDL
" Maintainer: Gerald Lai <laigera+vim?gmail.com>
" Version: 1.60
-" Last Change: 2016 Feb 26
+" Last Change: 2017 Jun 13
" URL: http://www.vim.org/scripts/script.php?script_id=1450
" only load this indent file when no other was loaded
@@ -114,9 +114,9 @@ function GetVHDLindent()
return ind2 + m
else
if g:vhdl_indent_genportmap
- return ind2 + stridx(prevs_noi, '(') + &sw
+ return ind2 + stridx(prevs_noi, '(') + shiftwidth()
else
- return ind2 + &sw
+ return ind2 + shiftwidth()
endif
endif
endif
@@ -128,7 +128,7 @@ function GetVHDLindent()
if g:vhdl_indent_rhsassign
return ind2 + matchend(prevs_noi, '<=\s*\ze.')
else
- return ind2 + &sw
+ return ind2 + shiftwidth()
endif
endif
@@ -218,12 +218,12 @@ function GetVHDLindent()
let ps = getline(pn)
if (ps =~? s:NC.'\<begin\>')
- return indent(pn) - &sw
+ return indent(pn) - shiftwidth()
endif
endwhile
if (pn == 0)
- return ind - &sw
+ return ind - shiftwidth()
else
return indent(pn)
endif
@@ -237,7 +237,7 @@ function GetVHDLindent()
" keyword: "type"
let s3 = s:NC.s:NE.'\<type\>'
if curs !~? s3.'.*'.s:NC.'\<\%(record\|units\)\>.*'.s:ES && prevs =~? s3
- let ind = ind + &sw
+ let ind = ind + shiftwidth()
endif
return ind
endif
@@ -282,7 +282,7 @@ function GetVHDLindent()
" removed: "begin", "case", "elsif", "if", "loop", "record", "units", "while"
" where: anywhere in previous line
if prevs =~? s:NC.s:NE.'\<\%(block\|process\)\>'
- return ind + &sw
+ return ind + shiftwidth()
endif
" indent: +sw
@@ -290,7 +290,7 @@ function GetVHDLindent()
" removed: "component", "for", "when", "with"
" where: start of previous line
if prevs =~? '^\s*\%(architecture\|configuration\|entity\|package\)\>'
- return ind + &sw
+ return ind + shiftwidth()
endif
" indent: +sw
@@ -298,7 +298,7 @@ function GetVHDLindent()
" removed: "generate", "is", "=>"
" where: end of previous line
if prevs =~? s:NC.'\<select'.s:ES
- return ind + &sw
+ return ind + shiftwidth()
endif
" indent: +sw
@@ -310,7 +310,7 @@ function GetVHDLindent()
" where: end of previous line
" _note_: indent allowed to leave this filter
if prevs =~? s:NC.'\%(\<begin\>\|'.s:NE.'\<\%(loop\|record\|units\)\>\)' || prevs =~? '^\s*\%(component\|else\|for\)\>' || prevs =~? s:NC.'\%('.s:NE.'\<generate\|\<\%(is\|then\)\|=>\)'.s:ES
- let ind = ind + &sw
+ let ind = ind + shiftwidth()
endif
" ****************************************************************************************
@@ -322,7 +322,7 @@ function GetVHDLindent()
if prevs =~? s:NC.'\<is'.s:ES
return ind
elseif prevs !~? s4
- return ind - &sw
+ return ind - shiftwidth()
else
return ind2
endif
@@ -336,7 +336,7 @@ function GetVHDLindent()
if prevs =~? '^\s*\%(elsif\|'.s5.'\)'
return ind
else
- return ind - &sw
+ return ind - shiftwidth()
endif
endif
@@ -367,9 +367,9 @@ function GetVHDLindent()
"where: start of previous non-comment line
if m == 1
if ps =~? '^\s*end\s\+case\>'
- return indent(pn) - 2 * &sw
+ return indent(pn) - 2 * shiftwidth()
elseif ps =~? '^\s*when\>'
- return indent(pn) - &sw
+ return indent(pn) - shiftwidth()
elseif ps =~? '^\s*case\>'
return indent(pn)
endif
@@ -385,14 +385,14 @@ function GetVHDLindent()
let pn = prevnonblank(pn - 1)
let ps = getline(pn)
endwhile
- return ind - &sw
+ return ind - shiftwidth()
endif
" indent: -sw
" keyword: ")"
" where: start of current line
if curs =~ '^\s*)'
- return ind - &sw
+ return ind - shiftwidth()
endif
" indent: 0
@@ -407,7 +407,7 @@ function GetVHDLindent()
" where: start of current line
"if curs =~? '^\s*end\s\+\w\+\>'
if curs =~? '^\s*end\%(\s\|;'.s:ES.'\)'
- return ind - &sw
+ return ind - shiftwidth()
endif
" ****************************************************************************************
diff --git a/runtime/indent/xml.vim b/runtime/indent/xml.vim
index dbe5be5f25..87ffb329b5 100644
--- a/runtime/indent/xml.vim
+++ b/runtime/indent/xml.vim
@@ -1,6 +1,6 @@
" Language: xml
" Maintainer: Johannes Zellner <johannes@zellner.org>
-" Last Change: 2012 Jul 25
+" Last Change: 2017 Jun 13
" Notes: 1) does not indent pure non-xml code (e.g. embedded scripts)
" 2) will be confused by unbalanced tags in comments
" or CDATA sections.
@@ -67,7 +67,7 @@ endfun
fun! <SID>XmlIndentSum(lnum, style, add)
let line = getline(a:lnum)
if a:style == match(line, '^\s*</')
- return (&sw *
+ return (shiftwidth() *
\ (<SID>XmlIndentWithPattern(line, b:xml_indent_open)
\ - <SID>XmlIndentWithPattern(line, b:xml_indent_close)
\ - <SID>XmlIndentWithPattern(line, '.\{-}/>'))) + a:add
diff --git a/runtime/indent/yaml.vim b/runtime/indent/yaml.vim
index 3201462fbc..3eb16f845d 100644
--- a/runtime/indent/yaml.vim
+++ b/runtime/indent/yaml.vim
@@ -1,7 +1,7 @@
" Vim indent file
" Language: YAML
" Maintainer: Nikolai Pavlov <zyx.vim@gmail.com>
-" Last Change: 2015 Nov 01
+" Last Change: 2017 Jun 13
" Only load this indent file when no other was loaded.
if exists('b:did_indent')
@@ -24,14 +24,6 @@ if exists('*GetYAMLIndent')
finish
endif
-if exists('*shiftwidth')
- let s:shiftwidth = function('shiftwidth')
-else
- function s:shiftwidth()
- return &shiftwidth
- endfunction
-endif
-
function s:FindPrevLessIndentedLine(lnum, ...)
let prevlnum = prevnonblank(a:lnum-1)
let curindent = a:0 ? a:1 : indent(a:lnum)
@@ -119,7 +111,7 @@ function GetYAMLIndent(lnum)
"
" - |-
" Block scalar without indentation indicator
- return previndent+s:shiftwidth()
+ return previndent+shiftwidth()
elseif prevline =~# '\v[:-]\ [|>]%(\d+[+\-]?|[+\-]?\d+)%(\#.*|\s*)$'
" - |+2
" block scalar with indentation indicator
@@ -155,7 +147,7 @@ function GetYAMLIndent(lnum)
\ '\v)%(\s+|\s*%(\#.*)?$))*'
" Mapping with: value
" that is multiline scalar
- return previndent+s:shiftwidth()
+ return previndent+shiftwidth()
endif
return previndent
endfunction