diff options
author | ZyX <kp-pav@yandex.ru> | 2017-12-03 16:49:30 +0300 |
---|---|---|
committer | ZyX <kp-pav@yandex.ru> | 2017-12-03 16:49:30 +0300 |
commit | c49e22d3964d6c7ae1c24e8ad01b5fec4ca40b57 (patch) | |
tree | b7e59c416d1435725c65f8952b6e55c70544d97e /runtime/indent | |
parent | 62108c3b0be46936c83f6d4c98b44ceb5e6f77fd (diff) | |
parent | 27a577586eace687c47e7398845178208cae524a (diff) | |
download | rneovim-c49e22d3964d6c7ae1c24e8ad01b5fec4ca40b57.tar.gz rneovim-c49e22d3964d6c7ae1c24e8ad01b5fec4ca40b57.tar.bz2 rneovim-c49e22d3964d6c7ae1c24e8ad01b5fec4ca40b57.zip |
Merge branch 'master' into s-dash-stdin
Diffstat (limited to 'runtime/indent')
87 files changed, 2601 insertions, 979 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/automake.vim b/runtime/indent/automake.vim index 5fbc222bc7..7e38f92ebf 100644 --- a/runtime/indent/automake.vim +++ b/runtime/indent/automake.vim @@ -1,7 +1,7 @@ " Vim indent file -" Language: automake -" Maintainer: Nikolai Weibull <now@bitwi.se> -" Latest Revision: 2006-04-19 +" Language: automake +" Previous Maintainer: Nikolai Weibull <now@bitwi.se> +" Latest Revision: 2006-04-19 if exists("b:did_indent") finish 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 db2b9052b2..5fae7b9046 100644 --- a/runtime/indent/cdl.vim +++ b/runtime/indent/cdl.vim @@ -16,7 +16,7 @@ if exists("*CdlGetIndent") "finish endif -" find out if an "...=..." expresion its an asignment (or a conditional) +" find out if an "...=..." expresion is an assignment (or a conditional) " it scans 'line' first, and then the previos lines fun! CdlAsignment(lnum, line) let f = -1 @@ -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..845bdd7655 100644 --- a/runtime/indent/cmake.vim +++ b/runtime/indent/cmake.vim @@ -1,14 +1,12 @@ " Vim indent file -" Program: CMake - Cross-Platform Makefile Generator -" Module: $RCSfile: cmake-indent.vim,v $ " Language: CMake (ft=cmake) " Author: Andy Cedilnik <andy.cedilnik@kitware.com> -" Maintainer: Karthik Krishnan <karthik.krishnan@kitware.com> -" Last Change: $Date: 2008-01-16 16:53:53 $ -" Version: $Revision: 1.9 $ +" Maintainer: Dimitri Merejkowsky <d.merej@gmail.com> +" Former Maintainer: Karthik Krishnan <karthik.krishnan@kitware.com> +" Last Change: 2017 Sep 24 " " Licence: The CMake license applies to this file. See -" http://www.cmake.org/HTML/Copyright.html +" https://cmake.org/licensing " This implies that distribution with Vim is allowed if exists("b:did_indent") @@ -68,19 +66,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/config.vim b/runtime/indent/config.vim index 7eb1657572..074f467bee 100644 --- a/runtime/indent/config.vim +++ b/runtime/indent/config.vim @@ -1,8 +1,8 @@ " Vim indent file -" Language: Autoconf configure.{ac,in} file -" Maintainer: Nikolai Weibull <now@bitwi.se> -" Latest Revision: 2006-12-20 -" TODO: how about nested [()]'s in one line +" Language: Autoconf configure.{ac,in} file +" Previous Maintainer: Nikolai Weibull <now@bitwi.se> +" Latest Revision: 2006-12-20 +" TODO: how about nested [()]'s in one line " what's wrong with '\\\@!'? " Only load this indent file when no other was loaded. diff --git a/runtime/indent/context.vim b/runtime/indent/context.vim new file mode 100644 index 0000000000..652479f7e2 --- /dev/null +++ b/runtime/indent/context.vim @@ -0,0 +1,36 @@ +" ConTeXt indent file +" Language: ConTeXt typesetting engine +" Maintainer: Nicola Vitacolonna <nvitacolonna@gmail.com> +" Last Change: 2016 Oct 15 + +if exists("b:did_indent") + finish +endif + +if !get(b:, 'context_metapost', get(g:, 'context_metapost', 1)) + finish +endif + +" Load MetaPost indentation script +runtime! indent/mp.vim + +let s:keepcpo= &cpo +set cpo&vim + +setlocal indentexpr=GetConTeXtIndent() + +let b:undo_indent = "setl indentexpr<" + +function! GetConTeXtIndent() + " Use MetaPost rules inside MetaPost graphic environments + if len(synstack(v:lnum, 1)) > 0 && + \ synIDattr(synstack(v:lnum, 1)[0], "name") ==# 'contextMPGraphic' + return GetMetaPostIndent() + endif + return -1 +endfunc + +let &cpo = s:keepcpo +unlet s:keepcpo + +" vim:sw=2 diff --git a/runtime/indent/css.vim b/runtime/indent/css.vim index f0a272eff9..4d15b8d2dc 100644 --- a/runtime/indent/css.vim +++ b/runtime/indent/css.vim @@ -2,6 +2,7 @@ " Language: CSS " Maintainer: Nikolai Weibull <now@bitwi.se> " Latest Revision: 2012-05-30 +" Use of shiftwidth() added by Oleg Zubchenko. if exists("b:did_indent") finish @@ -75,8 +76,8 @@ function GetCSSIndent() return 0 endif - return indent(pnum) + s:count_braces(pnum, 1) * &sw - \ - s:count_braces(v:lnum, 0) * &sw + return indent(pnum) + s:count_braces(pnum, 1) * shiftwidth() + \ - s:count_braces(v:lnum, 0) * shiftwidth() endfunction let &cpo = s:keepcpo diff --git a/runtime/indent/cucumber.vim b/runtime/indent/cucumber.vim index 965c7786ed..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: 2013 May 30 +" Last Change: 2017 Jun 13 if exists("b:did_indent") finish @@ -27,6 +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() : shiftwidth() let syn = s:syn(prevnonblank(v:lnum-1)) let csyn = s:syn(v:lnum) let nsyn = s:syn(nextnonblank(v:lnum+1)) @@ -35,38 +36,38 @@ function! GetCucumberIndent() return 0 elseif csyn ==# 'cucumberExamples' || cline =~# '^\s*\%(Examples\|Scenarios\):' " examples heading - return 2 * &sw + return 2 * sw elseif csyn =~# '^cucumber\%(Background\|Scenario\|ScenarioOutline\)$' || cline =~# '^\s*\%(Background\|Scenario\|Scenario Outline\):' " background, scenario or outline heading - return &sw + return sw elseif syn ==# 'cucumberFeature' || line =~# '^\s*Feature:' " line after feature heading - return &sw + return sw elseif syn ==# 'cucumberExamples' || line =~# '^\s*\%(Examples\|Scenarios\):' " line after examples heading - return 3 * &sw + return 3 * sw elseif syn =~# '^cucumber\%(Background\|Scenario\|ScenarioOutline\)$' || line =~# '^\s*\%(Background\|Scenario\|Scenario Outline\):' " line after background, scenario or outline heading - return 2 * &sw + return 2 * sw elseif cline =~# '^\s*[@#]' && (nsyn == 'cucumberFeature' || nline =~# '^\s*Feature:' || indent(prevnonblank(v:lnum-1)) <= 0) " tag or comment before a feature heading return 0 elseif cline =~# '^\s*@' " other tags - return &sw + return sw elseif cline =~# '^\s*[#|]' && line =~# '^\s*|' " mid-table " preserve indent return indent(prevnonblank(v:lnum-1)) elseif cline =~# '^\s*|' && line =~# '^\s*[^|]' " first line of a table, relative indent - return indent(prevnonblank(v:lnum-1)) + &sw + return indent(prevnonblank(v:lnum-1)) + sw elseif cline =~# '^\s*[^|]' && line =~# '^\s*|' " line after a table, relative unindent - return indent(prevnonblank(v:lnum-1)) - &sw + return indent(prevnonblank(v:lnum-1)) - sw elseif cline =~# '^\s*#' && getline(v:lnum-1) =~ '^\s*$' && (nsyn =~# '^cucumber\%(Background\|Scenario\|ScenarioOutline\)$' || nline =~# '^\s*\%(Background\|Scenario\|Scenario Outline\):') " comments on scenarios - return &sw + return sw endif return indent(prevnonblank(v:lnum-1)) endfunction diff --git a/runtime/indent/dictconf.vim b/runtime/indent/dictconf.vim index adbc1a5242..2e15c76146 100644 --- a/runtime/indent/dictconf.vim +++ b/runtime/indent/dictconf.vim @@ -1,7 +1,7 @@ " Vim indent file -" Language: dict(1) configuration file -" Maintainer: Nikolai Weibull <now@bitwi.se> -" Latest Revision: 2006-12-20 +" Language: dict(1) configuration file +" Previous Maintainer: Nikolai Weibull <now@bitwi.se> +" Latest Revision: 2006-12-20 if exists("b:did_indent") finish diff --git a/runtime/indent/dictdconf.vim b/runtime/indent/dictdconf.vim index 9427342c7e..5c4fbdafb5 100644 --- a/runtime/indent/dictdconf.vim +++ b/runtime/indent/dictdconf.vim @@ -1,7 +1,7 @@ " Vim indent file -" Language: dictd(8) configuration file -" Maintainer: Nikolai Weibull <now@bitwi.se> -" Latest Revision: 2006-12-20 +" Language: dictd(8) configuration file +" Previous Maintainer: Nikolai Weibull <now@bitwi.se> +" Latest Revision: 2006-12-20 if exists("b:did_indent") finish diff --git a/runtime/indent/docbk.vim b/runtime/indent/docbk.vim index 3fde2a13b6..d8661ffbe9 100644 --- a/runtime/indent/docbk.vim +++ b/runtime/indent/docbk.vim @@ -1,7 +1,7 @@ " Vim indent file -" Language: DocBook Documentation Format -" Maintainer: Nikolai Weibull <now@bitwi.se> -" Latest Revision: 2006-04-19 +" Language: DocBook Documentation Format +" Previous Maintainer: Nikolai Weibull <now@bitwi.se> +" Latest Revision: 2006-04-19 if exists("b:did_indent") finish diff --git a/runtime/indent/dtd.vim b/runtime/indent/dtd.vim index 88c0c5129e..5633362367 100644 --- a/runtime/indent/dtd.vim +++ b/runtime/indent/dtd.vim @@ -1,7 +1,7 @@ " Vim indent file -" Language: DTD (Document Type Definition for XML) -" Maintainer: Nikolai Weibull <now@bitwi.se> -" Latest Revision: 2011-07-08 +" Language: DTD (Document Type Definition for XML) +" Previous Maintainer: Nikolai Weibull <now@bitwi.se> +" Latest Revision: 2011-07-08 let s:cpo_save = &cpo set cpo&vim @@ -84,7 +84,7 @@ function GetDTDIndent() let [declaration, end] = s:lex1(line, col) if declaration == "" - return indent + &sw + return indent + shiftwidth() elseif declaration == '--' " We’re looking at a comment. Now, simply determine if the comment is " terminated or not. If it isn’t, let Vim take care of that using @@ -100,7 +100,7 @@ function GetDTDIndent() " Check for element name. If none exists, indent one level. let [name, end] = s:lex(line, end) if name == "" - return indent + &sw + return indent + shiftwidth() endif " Check for token following element name. This can be a specification of @@ -113,7 +113,7 @@ function GetDTDIndent() let n += 1 endwhile if token == "" - return indent + &sw + return indent + shiftwidth() endif " Next comes the content model. If the token we’ve found isn’t a @@ -148,7 +148,7 @@ function GetDTDIndent() return indent endif " TODO: Should use s:lex here on getline(v:lnum) and check for >. - return getline(v:lnum) =~ '^\s*>' || count(values(seen), 0) == 0 ? indent : (indent + &sw) + return getline(v:lnum) =~ '^\s*>' || count(values(seen), 0) == 0 ? indent : (indent + shiftwidth()) endif " If we’ve seen an addition or exception already and this is of the same @@ -167,7 +167,7 @@ function GetDTDIndent() " Check for element name. If none exists, indent one level. let [name, end] = s:lex(line, end) if name == "" - return indent + &sw + return indent + shiftwidth() endif " Check for any number of attributes. @@ -180,7 +180,7 @@ function GetDTDIndent() let [name, end] = s:lex(line, end) if name == "" " TODO: Should use s:lex here on getline(v:lnum) and check for >. - return getline(v:lnum) =~ '^\s*>' ? indent : (indent + &sw) + return getline(v:lnum) =~ '^\s*>' ? indent : (indent + shiftwidth()) elseif name == ">" return indent endif @@ -194,14 +194,14 @@ function GetDTDIndent() " (CDATA|NMTOKEN|NMTOKENS|ID|IDREF|IDREFS|ENTITY|ENTITIES)? let [value, end] = s:lex(line, end, '^\%((\|[^[:space:]]\+\)') if value == "" - return indent + &sw * 2 + return indent + shiftwidth() * 2 elseif value == 'NOTATION' " If this is a enumerated value based on notations, read another token " for the actual value. If it doesn’t exist, indent three levels. " TODO: If validating according to above, value must be equal to '('. let [value, end] = s:lex(line, end, '^\%((\|[^[:space:]]\+\)') if value == "" - return indent + &sw * 3 + return indent + shiftwidth() * 3 endif endif @@ -216,13 +216,13 @@ function GetDTDIndent() " two levels. let [default, end] = s:lex(line, end, '^\%("\_[^"]*"\|#\(REQUIRED\|IMPLIED\|FIXED\)\)') if default == "" - return indent + &sw * 2 + return indent + shiftwidth() * 2 elseif default == '#FIXED' " We need to look for the fixed value. If non exists, indent three " levels. let [default, end] = s:lex(line, end, '^"\_[^"]*"') if default == "" - return indent + &sw * 3 + return indent + shiftwidth() * 3 endif endif endwhile @@ -233,11 +233,11 @@ function GetDTDIndent() " again, if none exists, indent one level. let [name, end] = s:lex(line, end) if name == "" - return indent + &sw + return indent + shiftwidth() elseif name == '%' let [name, end] = s:lex(line, end) if name == "" - return indent + &sw + return indent + shiftwidth() endif endif @@ -256,27 +256,27 @@ function GetDTDIndent() " we’re now done with this entity. let [value, end] = s:lex(line, end) if value == "" - return indent + &sw + return indent + shiftwidth() elseif value == 'SYSTEM' || value == 'PUBLIC' let [quoted_string, end] = s:lex(line, end, '\%("[^"]\+"\|''[^'']\+''\)') if quoted_string == "" - return indent + &sw * 2 + return indent + shiftwidth() * 2 endif if value == 'PUBLIC' let [quoted_string, end] = s:lex(line, end, '\%("[^"]\+"\|''[^'']\+''\)') if quoted_string == "" - return indent + &sw * 2 + return indent + shiftwidth() * 2 endif endif let [ndata, end] = s:lex(line, end) if ndata == "" - return indent + &sw + return indent + shiftwidth() endif let [name, end] = s:lex(line, end) - return name == "" ? (indent + &sw * 2) : indent + return name == "" ? (indent + shiftwidth() * 2) : indent else return indent endif @@ -284,24 +284,24 @@ function GetDTDIndent() " Check for notation name. If none exists, indent one level. let [name, end] = s:lex(line, end) if name == "" - return indent + &sw + return indent + shiftwidth() endif " Now check for the external ID. If none exists, indent one level. let [id, end] = s:lex(line, end) if id == "" - return indent + &sw + return indent + shiftwidth() elseif id == 'SYSTEM' || id == 'PUBLIC' let [quoted_string, end] = s:lex(line, end, '\%("[^"]\+"\|''[^'']\+''\)') if quoted_string == "" - return indent + &sw * 2 + return indent + shiftwidth() * 2 endif if id == 'PUBLIC' let [quoted_string, end] = s:lex(line, end, '\%("[^"]\+"\|''[^'']\+''\|>\)') if quoted_string == "" " TODO: Should use s:lex here on getline(v:lnum) and check for >. - return getline(v:lnum) =~ '^\s*>' ? indent : (indent + &sw * 2) + return getline(v:lnum) =~ '^\s*>' ? indent : (indent + shiftwidth() * 2) elseif quoted_string == '>' return indent endif 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/eiffel.vim b/runtime/indent/eiffel.vim index 87e82e833d..d7667a8346 100644 --- a/runtime/indent/eiffel.vim +++ b/runtime/indent/eiffel.vim @@ -2,9 +2,10 @@ " Language: Eiffel " Maintainer: Jocelyn Fiat <jfiat@eiffel.com> " Previous-Maintainer: David Clarke <gadicath@dishevelled.net> +" Contributions from: Takuya Fujiwara " Contributions from: Thilo Six -" $Date: 2004/12/09 21:33:52 $ -" $Revision: 1.3 $ +" $Date: 2017/03/08 06:00:00 $ +" $Revision: 1.4 $ " URL: https://github.com/eiffelhub/vim-eiffel " Only load this indent file when no other was loaded. @@ -28,7 +29,7 @@ let b:undo_indent = "setl smartindent< indentkeys< indentexpr< autoindent< comme " Define some stuff " keywords grouped by indenting let s:trust_user_indent = '\(+\)\(\s*\(--\).*\)\=$' -let s:relative_indent = '^\s*\(deferred\|class\|feature\|creation\|inherit\|loop\|from\|until\|if\|else\|elseif\|ensure\|require\|check\|do\|local\|invariant\|variant\|rename\|redefine\|do\|export\)\>' +let s:relative_indent = '^\s*\(deferred\|class\|feature\|creation\|inherit\|loop\|from\|across\|until\|if\|else\|elseif\|ensure\|require\|check\|do\|local\|invariant\|variant\|rename\|redefine\|do\|export\)\>' let s:outdent = '^\s*\(else\|invariant\|variant\|do\|require\|until\|loop\|local\)\>' let s:no_indent = '^\s*\(class\|feature\|creation\|inherit\)\>' let s:single_dent = '^[^-]\+[[:alnum:]]\+ is\(\s*\(--\).*\)\=$' @@ -63,23 +64,23 @@ function GetEiffelIndent() " Add a 'shiftwidth' after lines that start with an indent word let ind = indent(lnum) if getline(lnum) =~ s:relative_indent - let ind = ind + &sw + let ind = ind + shiftwidth() endif " Indent to single indent if getline(v:lnum) =~ s:single_dent && getline(v:lnum) !~ s:relative_indent \ && getline(v:lnum) !~ '\s*\<\(and\|or\|implies\)\>' - let ind = &sw + let ind = shiftwidth() endif " Indent to double indent if getline(v:lnum) =~ s:inheritance_dent - let ind = 2 * &sw + let ind = 2 * shiftwidth() endif " Indent line after the first line of the function definition if getline(lnum) =~ s:single_dent - let ind = ind + &sw + let ind = ind + shiftwidth() endif " The following should always be at the start of a line, no indenting @@ -91,17 +92,17 @@ function GetEiffelIndent() " or first thing after the 'do' if getline(v:lnum) =~ s:outdent && getline(v:lnum - 1) !~ s:single_dent \ && getline(v:lnum - 1) !~ '^\s*do\>' - let ind = ind - &sw + let ind = ind - shiftwidth() endif " Subtract a shiftwidth for end statements if getline(v:lnum) =~ '^\s*end\>' - let ind = ind - &sw + let ind = ind - shiftwidth() endif " set indent of zero end statements that are at an indent of 3, this should " only ever be the class's end. - if getline(v:lnum) =~ '^\s*end\>' && ind == &sw + if getline(v:lnum) =~ '^\s*end\>' && ind == shiftwidth() let ind = 0 endif 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 80cab7000e..5058325495 100644 --- a/runtime/indent/eruby.vim +++ b/runtime/indent/eruby.vim @@ -19,6 +19,9 @@ else endif unlet! b:did_indent +" Force HTML indent to not keep state. +let b:html_indent_usestate = 0 + if &l:indentexpr == '' if &l:cindent let &l:indentexpr = 'cindent(v:lnum)' @@ -38,7 +41,14 @@ if exists("*GetErubyIndent") finish endif +" this file uses line continuations +let s:cpo_sav = &cpo +set cpo&vim + function! GetErubyIndent(...) + " The value of a single shift-width + let sw = shiftwidth() + if a:0 && a:1 == '.' let v:lnum = line('.') elseif a:0 && a:1 =~ '^\d' @@ -52,31 +62,44 @@ function! GetErubyIndent(...) let ind = GetRubyIndent(v:lnum) else exe "let ind = ".b:eruby_subtype_indentexpr + + " Workaround for Andy Wokula's HTML indent. This should be removed after + " some time, since the newest version is fixed in a different way. + if b:eruby_subtype_indentexpr =~# '^HtmlIndent(' + \ && exists('b:indent') + \ && type(b:indent) == type({}) + \ && has_key(b:indent, 'lnum') + " Force HTML indent to not keep state + let b:indent.lnum = -1 + endif endif let lnum = prevnonblank(v:lnum-1) let line = getline(lnum) let cline = getline(v:lnum) if cline =~# '^\s*<%[-=]\=\s*\%(}\|end\|else\|\%(ensure\|rescue\|elsif\|when\).\{-\}\)\s*\%([-=]\=%>\|$\)' - let ind = ind - &sw + let ind = ind - sw endif if line =~# '\S\s*<%[-=]\=\s*\%(}\|end\).\{-\}\s*\%([-=]\=%>\|$\)' - let ind = ind - &sw + let ind = ind - sw endif if line =~# '\%({\|\<do\)\%(\s*|[^|]*|\)\=\s*[-=]\=%>' - let ind = ind + &sw + let ind = ind + sw elseif line =~# '<%[-=]\=\s*\%(module\|class\|def\|if\|for\|while\|until\|else\|elsif\|case\|when\|unless\|begin\|ensure\|rescue\)\>.*%>' - let ind = ind + &sw + let ind = ind + sw endif if line =~# '^\s*<%[=#-]\=\s*$' && cline !~# '^\s*end\>' - let ind = ind + &sw + let ind = ind + sw endif - if line !~# '^\s*<%' && line =~# '%>\s*$' - let ind = ind - &sw + if line !~# '^\s*<%' && line =~# '%>\s*$' && line !~# '^\s*end\>' + let ind = ind - sw endif if cline =~# '^\s*[-=]\=%>\s*$' - let ind = ind - &sw + let ind = ind - sw endif return ind endfunction +let &cpo = s:cpo_sav +unlet! s:cpo_sav + " vim:set sw=2 sts=2 ts=8 noet: diff --git a/runtime/indent/eterm.vim b/runtime/indent/eterm.vim index f25f5f4dad..8ee342fcfa 100644 --- a/runtime/indent/eterm.vim +++ b/runtime/indent/eterm.vim @@ -1,7 +1,7 @@ " Vim indent file -" Language: Eterm configuration file -" Maintainer: Nikolai Weibull <now@bitwi.se> -" Latest Revision: 2006-12-20 +" Language: Eterm configuration file +" Previous Maintainer: Nikolai Weibull <now@bitwi.se> +" Latest Revision: 2006-12-20 if exists("b:did_indent") finish @@ -25,11 +25,11 @@ function GetEtermIndent() let ind = indent(lnum) if getline(lnum) =~ '^\s*begin\>' - let ind = ind + &sw + let ind = ind + shiftwidth() endif if getline(v:lnum) =~ '^\s*end\>' - let ind = ind - &sw + let ind = ind - shiftwidth() endif return ind 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/fortran.vim b/runtime/indent/fortran.vim index e19a19fb1f..2ba69e86df 100644 --- a/runtime/indent/fortran.vim +++ b/runtime/indent/fortran.vim @@ -1,11 +1,12 @@ " Vim indent file " Language: Fortran 2008 (and older: Fortran 2003, 95, 90, and 77) -" Version: 0.44 -" Last Change: 2016 Jan. 26 +" Version: 47 +" Last Change: 2016 Oct. 29 " Maintainer: Ajit J. Thakkar <ajit@unb.ca>; <http://www2.unb.ca/~ajit/> " Usage: For instructions, do :help fortran-indent from Vim " Credits: -" Useful suggestions were made by: Albert Oliver Serra and Takuya Fujiwara. +" Useful suggestions were made, in chronological order, by: +" Albert Oliver Serra, Takuya Fujiwara and Philipp Edelmann. " Only load this indent file when no other was loaded. if exists("b:did_indent") @@ -99,9 +100,9 @@ function FortranGetIndent(lnum) endif endif - "Add a shiftwidth to statements following if, else, else if, case, + "Add a shiftwidth to statements following if, else, else if, case, class, "where, else where, forall, type, interface and associate statements - if prevstat =~? '^\s*\(case\|else\|else\s*if\|else\s*where\)\>' + if prevstat =~? '^\s*\(case\|class\|else\|else\s*if\|else\s*where\)\>' \ ||prevstat=~? '^\s*\(type\|interface\|associate\|enum\)\>' \ ||prevstat=~?'^\s*\(\d\+\s\)\=\s*\(\a\w*\s*:\)\=\s*\(forall\|where\|block\)\>' \ ||prevstat=~? '^\s*\(\d\+\s\)\=\s*\(\a\w*\s*:\)\=\s*if\>' @@ -121,7 +122,8 @@ function FortranGetIndent(lnum) let prefix='\(\(pure\|impure\|elemental\|recursive\)\s\+\)\{,2}' let type='\(\(integer\|real\|double\s\+precision\|complex\|logical' \.'\|character\|type\|class\)\s*\S*\s\+\)\=' - if prevstat =~? '^\s*\(module\|contains\|program\)\>' + if prevstat =~? '^\s*\(contains\|submodule\|program\)\>' + \ ||prevstat =~? '^\s*'.'module\>\(\s*\procedure\)\@!' \ ||prevstat =~? '^\s*'.prefix.'subroutine\>' \ ||prevstat =~? '^\s*'.prefix.type.'function\>' \ ||prevstat =~? '^\s*'.type.prefix.'function\>' @@ -129,16 +131,16 @@ function FortranGetIndent(lnum) endif if getline(v:lnum) =~? '^\s*contains\>' \ ||getline(v:lnum)=~? '^\s*end\s*' - \ .'\(function\|subroutine\|module\|program\)\>' + \ .'\(function\|subroutine\|module\|submodule\|program\)\>' let ind = ind - shiftwidth() endif endif - "Subtract a shiftwidth from else, else if, elsewhere, case, end if, + "Subtract a shiftwidth from else, else if, elsewhere, case, class, end if, " end where, end select, end forall, end interface, end associate, - " end enum, and end type statements + " end enum, end type, end block and end type statements if getline(v:lnum) =~? '^\s*\(\d\+\s\)\=\s*' - \. '\(else\|else\s*if\|else\s*where\|case\|' + \. '\(else\|else\s*if\|else\s*where\|case\|class\|' \. 'end\s*\(if\|where\|select\|interface\|' \. 'type\|forall\|associate\|enum\|block\)\)\>' let ind = ind - shiftwidth() @@ -152,9 +154,6 @@ function FortranGetIndent(lnum) if prevstat =~ '&\s*$' && prev2stat !~ '&\s*$' let ind = ind + shiftwidth() endif - if prevstat =~ '&\s*$' && prevstat =~ '\<else\s*if\>' - let ind = ind - shiftwidth() - endif "Line after last continuation line if prevstat !~ '&\s*$' && prev2stat =~ '&\s*$' && prevstat !~? '\<then\>' let ind = ind - shiftwidth() diff --git a/runtime/indent/framescript.vim b/runtime/indent/framescript.vim index 49ff92a81d..f9a274eab6 100644 --- a/runtime/indent/framescript.vim +++ b/runtime/indent/framescript.vim @@ -1,7 +1,7 @@ " Vim indent file -" Language: FrameScript -" Maintainer: Nikolai Weibull <now@bitwi.se> -" Latest Revision: 2008-07-19 +" Language: FrameScript +" Previous Maintainer: Nikolai Weibull <now@bitwi.se> +" Latest Revision: 2008-07-19 if exists("b:did_indent") finish @@ -30,11 +30,11 @@ function GetFrameScriptIndent() let ind = indent(lnum) if getline(lnum) =~? '^\s*\%(If\|Loop\|Sub\)' - let ind = ind + &sw + let ind = ind + shiftwidth() endif if getline(v:lnum) =~? '^\s*\%(Else\|End\%(If\|Loop\|Sub\)\)' - let ind = ind - &sw + let ind = ind - shiftwidth() endif return ind diff --git a/runtime/indent/gitconfig.vim b/runtime/indent/gitconfig.vim index 7d5d44b779..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: 2013 May 30 +" Last Change: 2017 Jun 13 if exists("b:did_indent") finish @@ -20,17 +20,18 @@ if exists("*GetGitconfigIndent") endif function! GetGitconfigIndent() + let sw = shiftwidth() let line = getline(prevnonblank(v:lnum-1)) let cline = getline(v:lnum) if line =~ '\\\@<!\%(\\\\\)*\\$' " odd number of slashes, in a line continuation - return 2 * &sw + return 2 * sw elseif cline =~ '^\s*\[' return 0 elseif cline =~ '^\s*\a' - return &sw + return sw elseif cline == '' && line =~ '^\[' - return &sw + return sw else return -1 endif diff --git a/runtime/indent/gitolite.vim b/runtime/indent/gitolite.vim index 33b7c9f312..b36f30a494 100644 --- a/runtime/indent/gitolite.vim +++ b/runtime/indent/gitolite.vim @@ -1,8 +1,10 @@ " Vim indent file " Language: gitolite configuration -" URL: https://github.com/tmatilai/gitolite.vim -" Maintainer: Teemu Matilainen <teemu.matilainen@iki.fi> -" Last Change: 2011-12-24 +" URL: https://github.com/sitaramc/gitolite/blob/master/contrib/vim/indent/gitolite.vim +" (https://raw.githubusercontent.com/sitaramc/gitolite/master/contrib/vim/indent/gitolite.vim) +" Maintainer: Sitaram Chamarty <sitaramc@gmail.com> +" (former Maintainer: Teemu Matilainen <teemu.matilainen@iki.fi>) +" Last Change: 2017 Oct 05 if exists("b:did_indent") finish @@ -27,11 +29,13 @@ 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 cline =~ '^\s*option\s' + 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 c47a8a59c7..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: 2013 May 30 +" Last Change: 2017 Jun 13 if exists("b:did_indent") finish @@ -37,10 +37,11 @@ function! GetHamlIndent() let line = substitute(line,'^\s\+','','') let indent = indent(lnum) let cindent = indent(v:lnum) + let sw = shiftwidth() if cline =~# '\v^-\s*%(elsif|else|when)>' - let indent = cindent < indent ? cindent : indent - &sw + let indent = cindent < indent ? cindent : indent - sw endif - let increase = indent + &sw + let increase = indent + sw if indent == indent(lnum) let indent = cindent <= indent ? -1 : increase 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 828bc3120b..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: 2016 Mar 30 +" Last Change: 2017 Jun 13 " Version: 1.0 " Description: HTML indent script with cached state for faster indenting on a " range of lines. @@ -25,27 +25,22 @@ if exists("b:did_indent") "{{{ finish endif + +" Load the Javascript indent script first, it defines GetJavascriptIndent(). +" Undo the rest. +" Load base python indent. +if !exists('*GetJavascriptIndent') + runtime! indent/javascript.vim +endif let b:did_indent = 1 setlocal indentexpr=HtmlIndent() setlocal indentkeys=o,O,<Return>,<>>,{,},!^F -" "j1" is included to make cindent() work better with Javascript. -setlocal cino=j1 -" "J1" should be included, but it doen't work properly before 7.4.355. -if has("patch-7.4.355") - setlocal cino+=J1 -endif -" Before patch 7.4.355 indenting after "(function() {" does not work well, add -" )2 to limit paren search. -if !has("patch-7.4.355") - setlocal cino+=)2 -endif - " Needed for % to work when finding start/end of a tag. setlocal matchpairs+=<:> -let b:undo_indent = "setlocal inde< indk< cino<" +let b:undo_indent = "setlocal inde< indk<" " b:hi_indent keeps state to speed up indenting consecutive lines. let b:hi_indent = {"lnum": -1} @@ -56,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 @@ -128,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") @@ -363,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 @@ -485,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 @@ -495,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 @@ -516,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 @@ -535,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 @@ -555,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 @@ -570,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 "}}} @@ -596,7 +582,7 @@ func! s:Alien3() return eval(b:hi_js1indent) endif if b:hi_indent.scripttype == "javascript" - return cindent(v:lnum) + return GetJavascriptIndent() else return -1 endif @@ -651,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*$' @@ -668,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-]\+:' @@ -676,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 @@ -704,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 @@ -715,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 @@ -749,7 +735,7 @@ func! s:CssPrevNonComment(lnum, stopline) while 1 let ccol = match(getline(lnum), '\*/') if ccol < 0 - " No comment end thus its something else. + " No comment end thus it's something else. return lnum endif call cursor(lnum, ccol + 1) @@ -821,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 @@ -842,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 "<". @@ -952,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 @@ -1035,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/java.vim b/runtime/indent/java.vim index e0aec0faef..49f8010d21 100644 --- a/runtime/indent/java.vim +++ b/runtime/indent/java.vim @@ -1,12 +1,14 @@ " Vim indent file " Language: Java " Previous Maintainer: Toby Allsopp <toby.allsopp@peace.com> -" Current Maintainer: Hong Xu <xuhdev@gmail.com> -" Last Change: 2012 May 18 -" Version: 1.0 +" Current Maintainer: Hong Xu <hong@topbug.net> +" Homepage: http://www.vim.org/scripts/script.php?script_id=3899 +" https://github.com/xuhdev/indent-java.vim +" Last Change: 2016 Mar 7 +" Version: 1.1 " License: Same as Vim. -" Copyright (c) 2012 Hong Xu -" Before 2012, this file is maintained by Toby Allsopp. +" Copyright (c) 2012-2016 Hong Xu +" Before 2012, this file was maintained by Toby Allsopp. " Only load this indent file when no other was loaded. if exists("b:did_indent") @@ -29,6 +31,7 @@ let b:undo_indent = "set cin< cino< indentkeys< indentexpr<" if exists("*GetJavaIndent") finish endif + let s:keepcpo= &cpo set cpo&vim @@ -70,7 +73,7 @@ function GetJavaIndent() " If the previous line starts with '@', we should have the same indent as " the previous one - if getline(lnum) =~ '^\s*@\S\+\s*$' + if getline(lnum) =~ '^\s*@.*$' return indent(lnum) endif @@ -85,9 +88,9 @@ function GetJavaIndent() " Try to align "throws" lines for methods and "extends" and "implements" for " classes. - if getline(v:lnum) =~ '^\s*\(extends\|implements\)\>' - \ && getline(lnum) !~ '^\s*\(extends\|implements\)\>' - let theIndent = theIndent + &sw + if getline(v:lnum) =~ '^\s*\(throws\|extends\|implements\)\>' + \ && getline(lnum) !~ '^\s*\(throws\|extends\|implements\)\>' + let theIndent = theIndent + shiftwidth() endif " correct for continuation lines of "throws", "implements" and "extends" @@ -96,27 +99,27 @@ function GetJavaIndent() if strlen(cont_kw) > 0 let amount = strlen(cont_kw) + 1 if getline(lnum) !~ ',\s*$' - let theIndent = theIndent - (amount + &sw) + let theIndent = theIndent - (amount + shiftwidth()) if theIndent < 0 let theIndent = 0 endif elseif prev == lnum let theIndent = theIndent + amount if cont_kw ==# 'throws' - let theIndent = theIndent + &sw + let theIndent = theIndent + shiftwidth() endif endif elseif getline(prev) =~ '^\s*\(throws\|implements\|extends\)\>' \ && (getline(prev) =~ '{\s*$' \ || getline(v:lnum) =~ '^\s*{\s*$') - let theIndent = theIndent - &sw + let theIndent = theIndent - shiftwidth() endif " When the line starts with a }, try aligning it with the matching {, " skipping over "throws", "extends" and "implements" clauses. if getline(v:lnum) =~ '^\s*}\s*\(//.*\|/\*.*\)\=$' call cursor(v:lnum, 1) - silent normal % + silent normal! % let lnum = line('.') if lnum < v:lnum while lnum > 1 diff --git a/runtime/indent/javascript.vim b/runtime/indent/javascript.vim index 3507e305ed..2861716287 100644 --- a/runtime/indent/javascript.vim +++ b/runtime/indent/javascript.vim @@ -1,8 +1,8 @@ " Vim indent file " Language: Javascript -" Maintainer: vim-javascript community +" Maintainer: Chris Paul ( https://github.com/bounceme ) " URL: https://github.com/pangloss/vim-javascript -" Last Change: August 12, 2016 +" Last Change: September 18, 2017 " Only load this indent file when no other was loaded. if exists('b:did_indent') @@ -10,13 +10,27 @@ if exists('b:did_indent') endif let b:did_indent = 1 +" indent correctly if inside <script> +" vim/vim@690afe1 for the switch from cindent +let b:html_indent_script1 = 'inc' + " Now, set up our indentation expression and keys that trigger it. setlocal indentexpr=GetJavascriptIndent() -setlocal nolisp -setlocal indentkeys=0{,0},0),0],:,!^F,o,O,e -setlocal cinoptions+=j1,J1 +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<' -let b:undo_indent = 'setlocal indentexpr< indentkeys< cinoptions<' +" Regex of syntax group names that are or delimit string or are comments. +let b:syng_strcom = get(b:,'syng_strcom','string\|comment\|regex\|special\|doc\|template\%(braces\)\@!') +let b:syng_str = get(b:,'syng_str','string\|template\|special') +" template strings may want to be excluded when editing graphql: +" au! Filetype javascript let b:syng_str = '^\%(.*template\)\@!.*string\|special' +" au! Filetype javascript let b:syng_strcom = '^\%(.*template\)\@!.*string\|comment\|regex\|special\|doc' " Only define the function once. if exists('*GetJavascriptIndent') @@ -33,160 +47,403 @@ if exists('*shiftwidth') endfunction else function s:sw() - return &sw + return &l:shiftwidth ? &l:shiftwidth : &l:tabstop endfunction endif -let s:line_pre = '^\s*\%(\/\*.\{-}\*\/\s*\)*' -let s:expr_case = s:line_pre . '\%(\%(case\>.\+\)\|default\)\s*:' -" Regex of syntax group names that are or delimit string or are comments. -let s:syng_strcom = '\%(s\%(tring\|pecial\)\|comment\|regex\|doc\|template\)' - -" Regex of syntax group names that are strings or documentation. -let s:syng_comment = '\%(comment\|doc\)' +" Performance for forwards search(): start search at pos rather than masking +" matches before pos. +let s:z = has('patch-7.4.984') ? 'z' : '' " Expression used to check whether we should skip a match with searchpair(). -let s:skip_expr = "line('.') < (prevnonblank(v:lnum) - 2000) ? dummy : synIDattr(synID(line('.'),col('.'),0),'name') =~? '".s:syng_strcom."'" +let s:skip_expr = "s:SynAt(line('.'),col('.')) =~? b:syng_strcom" +let s:in_comm = s:skip_expr[:-14] . "'comment\\|doc'" -function s:lookForParens(start,end,flags,time) - if has('reltime') - return searchpair(a:start,'',a:end,a:flags,s:skip_expr,0,a:time) - else - return searchpair(a:start,'',a:end,a:flags,0,0) +let s:rel = has('reltime') +" searchpair() wrapper +if s:rel + function s:GetPair(start,end,flags,skip) + return searchpair('\m'.a:start,'','\m'.a:end,a:flags,a:skip,s:l1,a:skip ==# 's:SkipFunc()' ? 2000 : 200) + endfunction +else + function s:GetPair(start,end,flags,skip) + return searchpair('\m'.a:start,'','\m'.a:end,a:flags,a:skip,s:l1) + endfunction +endif + +function s:SynAt(l,c) + let byte = line2byte(a:l) + a:c - 1 + let pos = index(s:synid_cache[0], byte) + if pos == -1 + let s:synid_cache[:] += [[byte], [synIDattr(synID(a:l, a:c, 0), 'name')]] endif + return s:synid_cache[1][pos] endfunction -let s:line_term = '\%(\s*\%(\/\*.\{-}\*\/\s*\)\=\)\@>$' +function s:ParseCino(f) + let [divider, n, cstr] = [0] + matchlist(&cino, + \ '\%(.*,\)\=\%(\%d'.char2nr(a:f).'\(-\)\=\([.s0-9]*\)\)\=')[1:2] + for c in split(cstr,'\zs') + if c == '.' && !divider + let divider = 1 + elseif c ==# 's' + if n !~ '\d' + return n . s:sw() + 0 + endif + let n = str2nr(n) * s:sw() + break + else + let [n, divider] .= [c, 0] + endif + endfor + return str2nr(n) / max([str2nr(divider),1]) +endfunction -" configurable regexes that define continuation lines, not including (, {, or [. -if !exists('g:javascript_opfirst') - let g:javascript_opfirst = '\%([<>,:?^%]\|\([-/.+]\)\%(\1\|\*\|\/\)\@!\|\*\/\@!\|=>\@!\||\|&\|in\%(stanceof\)\=\>\)' -endif -let g:javascript_opfirst = s:line_pre . g:javascript_opfirst +" Optimized {skip} expr, only callable from the search loop which +" GetJavascriptIndent does to find the containing [[{(] (side-effects) +function s:SkipFunc() + if s:top_col == 1 + throw 'out of bounds' + endif + let s:top_col = 0 + if s:check_in + if eval(s:skip_expr) + return 1 + endif + let s:check_in = 0 + elseif getline('.') =~ '\%<'.col('.').'c\/.\{-}\/\|\%>'.col('.').'c[''"]\|\\$' + if eval(s:skip_expr) + let s:looksyn = a:firstline + return 1 + endif + elseif search('\m`\|\${\|\*\/','nW'.s:z,s:looksyn) && eval(s:skip_expr) + let s:check_in = 1 + return 1 + endif + let [s:looksyn, s:top_col] = getpos('.')[1:2] +endfunction -if !exists('g:javascript_continuation') - let g:javascript_continuation = '\%([<*,.?:^%]\|+\@<!+\|-\@<!-\|=\@<!>\|\*\@<!\/\|=\||\|&\|\<in\%(stanceof\)\=\)' -endif -let g:javascript_continuation .= s:line_term +function s:AlternatePair() + let [pat, l:for] = ['[][(){};]', 2] + while s:SearchLoop(pat,'bW','s:SkipFunc()') + if s:LookingAt() == ';' + if !l:for + if s:GetPair('{','}','bW','s:SkipFunc()') + return + endif + break + else + let [pat, l:for] = ['[{}();]', l:for - 1] + endif + else + let idx = stridx('])}',s:LookingAt()) + if idx == -1 + return + elseif !s:GetPair(['\[','(','{'][idx],'])}'[idx],'bW','s:SkipFunc()') + break + endif + endif + endwhile + throw 'out of bounds' +endfunction -function s:Onescope(lnum,text,add) - return a:text =~# '\%(\<else\|\<do\|=>' . (a:add ? '\|\<try\|\<finally' : '' ) . '\)' . s:line_term || - \ ((a:add && a:text =~ s:line_pre . '$' && search('\%' . s:PrevCodeLine(a:lnum - 1) . 'l.)' . s:line_term)) || - \ cursor(a:lnum, match(a:text, ')' . s:line_term)) > -1) && - \ s:lookForParens('(', ')', 'cbW', 100) > 0 && search((a:add ? - \ '\%(function\*\|[[:lower:][:upper:]_$][[:digit:][:lower:][:upper:]_$]*\)' : - \ '\<\%(for\%(\s\+each\)\=\|if\|let\|w\%(hile\|ith\)\)') . '\_s*\%#\C','bW') && - \ (a:add || (expand('<cword>') ==# 'while' ? !s:lookForParens('\<do\>\C', '\<while\>\C','bW',100) : 1)) +function s:Nat(int) + return a:int * (a:int > 0) endfunction -" Auxiliary Functions {{{2 +function s:LookingAt() + return getline('.')[col('.')-1] +endfunction + +function s:Token() + return s:LookingAt() =~ '\k' ? expand('<cword>') : s:LookingAt() +endfunction -" strip line of comment -function s:StripLine(c) - return a:c !~# s:expr_case ? substitute(a:c, '\%(:\@<!\/\/.*\)$', '','') : a:c +function s:PreviousToken() + let l:col = col('.') + if search('\m\k\{1,}\|\S','ebW') + if search('\m\*\%#\/\|\/\/\%<'.a:firstline.'l','nbW',line('.')) && eval(s:in_comm) + if s:SearchLoop('\S\ze\_s*\/[/*]','bW',s:in_comm) + return s:Token() + endif + call cursor(a:firstline, l:col) + else + return s:Token() + endif + endif + return '' endfunction -" Find line above 'lnum' that isn't empty, in a comment, or in a string. -function s:PrevCodeLine(lnum) - let l:lnum = prevnonblank(a:lnum) - while l:lnum > 0 - if synIDattr(synID(l:lnum,matchend(getline(l:lnum), '^\s*[^''"]'),0),'name') !~? s:syng_strcom +function s:Pure(f,...) + return eval("[call(a:f,a:000),cursor(a:firstline,".col('.').")][0]") +endfunction + +function s:SearchLoop(pat,flags,expr) + return s:GetPair(a:pat,'\_$.',a:flags,a:expr) +endfunction + +function s:ExprCol() + let bal = 0 + while s:SearchLoop('[{}?]\|\_[^:]\zs::\@!','bW',s:skip_expr) + if s:LookingAt() == ':' + let bal -= 1 + elseif s:LookingAt() == '?' + let bal += 1 + if bal == 1 + break + endif + elseif s:LookingAt() == '{' + let bal = !s:IsBlock() + break + elseif !s:GetPair('{','}','bW',s:skip_expr) break endif - let l:lnum = prevnonblank(l:lnum - 1) endwhile - return l:lnum + return s:Nat(bal) +endfunction + +" configurable regexes that define continuation lines, not including (, {, or [. +let s:opfirst = '^' . get(g:,'javascript_opfirst', + \ '\C\%([<>=,.?^%|/&]\|\([-:+]\)\1\@!\|\*\+\|!=\|in\%(stanceof\)\=\>\)') +let s:continuation = get(g:,'javascript_continuation', + \ '\C\%([<=,.~!?/*^%|&:]\|+\@<!+\|-\@<!-\|=\@<!>\|\<\%(typeof\|new\|delete\|void\|in\|instanceof\|await\)\)') . '$' + +function s:Continues(ln,con) + let tok = matchstr(a:con[-15:],s:continuation) + if tok =~ '[a-z:]' + call cursor(a:ln, len(a:con)) + return tok == ':' ? s:ExprCol() : s:PreviousToken() != '.' + elseif tok !~ '[/>]' + return tok isnot '' + endif + return s:SynAt(a:ln, len(a:con)) !~? (tok == '>' ? 'jsflow\|^html' : 'regex') endfunction " Check if line 'lnum' has a balanced amount of parentheses. function s:Balanced(lnum) - let open_0 = 0 - let open_2 = 0 - let open_4 = 0 - let l:line = getline(a:lnum) - let pos = match(l:line, '[][(){}]', 0) + let [l:open, l:line] = [0, getline(a:lnum)] + let pos = match(l:line, '[][(){}]') while pos != -1 - if synIDattr(synID(a:lnum,pos + 1,0),'name') !~? s:syng_strcom - let idx = stridx('(){}[]', l:line[pos]) - if idx % 2 == 0 - let open_{idx} = open_{idx} + 1 - else - let open_{idx - 1} = open_{idx - 1} - 1 + if s:SynAt(a:lnum,pos + 1) !~? b:syng_strcom + let l:open += match(' ' . l:line[pos],'[[({]') + if l:open < 0 + return endif endif - let pos = match(l:line, '[][(){}]', pos + 1) + let pos = match(l:line, !l:open ? '[][(){}]' : '()' =~ l:line[pos] ? + \ '[()]' : '{}' =~ l:line[pos] ? '[{}]' : '[][]', pos + 1) endwhile - return (!open_4 + !open_2 + !open_0) - 2 + return !l:open endfunction -" }}} -function GetJavascriptIndent() - if !exists('b:js_cache') - let b:js_cache = [0,0,0] +function s:OneScope() + if s:LookingAt() == ')' && s:GetPair('(', ')', 'bW', s:skip_expr) + let tok = s:PreviousToken() + return (count(split('for if let while with'),tok) || + \ tok =~# '^await$\|^each$' && s:PreviousToken() ==# 'for') && + \ s:Pure('s:PreviousToken') != '.' && !(tok == 'while' && s:DoWhile()) + elseif s:Token() =~# '^else$\|^do$' + return s:Pure('s:PreviousToken') != '.' + endif + return strpart(getline('.'),col('.')-2,2) == '=>' +endfunction + +function s:DoWhile() + let cpos = searchpos('\m\<','cbW') + if s:SearchLoop('\C[{}]\|\<\%(do\|while\)\>','bW',s:skip_expr) + if s:{s:LookingAt() == '}' && s:GetPair('{','}','bW',s:skip_expr) ? + \ 'Previous' : ''}Token() ==# 'do' && s:IsBlock() + return 1 + endif + call call('cursor',cpos) endif - " Get the current line. +endfunction + +" returns total offset from braceless contexts. 'num' is the lineNr which +" encloses the entire context, 'cont' if whether a:firstline is a continued +" expression, which could have started in a braceless context +function s:IsContOne(num,cont) + let [l:num, b_l] = [a:num + !a:num, 0] + let pind = a:num ? indent(a:num) + s:sw() : 0 + let ind = indent('.') + !a:cont + while line('.') > l:num && ind > pind || line('.') == l:num + if indent('.') < ind && s:OneScope() + let b_l += 1 + elseif !a:cont || b_l || ind < indent(a:firstline) + break + else + call cursor(0,1) + endif + let ind = min([ind, indent('.')]) + if s:PreviousToken() is '' + break + endif + endwhile + return b_l +endfunction + +function s:Class() + return (s:Token() ==# 'class' || s:PreviousToken() =~# '^class$\|^extends$') && + \ s:PreviousToken() != '.' +endfunction + +function s:IsSwitch() + return s:PreviousToken() !~ '[.*]' && + \ (!s:GetPair('{','}','cbW',s:skip_expr) || s:IsBlock() && !s:Class()) +endfunction + +" https://github.com/sweet-js/sweet.js/wiki/design#give-lookbehind-to-the-reader +function s:IsBlock() + let tok = s:PreviousToken() + if join(s:stack) =~? 'xml\|jsx' && s:SynAt(line('.'),col('.')-1) =~? 'xml\|jsx' + return tok != '{' + elseif tok =~ '\k' + if tok ==# 'type' + return s:Pure('eval',"s:PreviousToken() !~# '^\\%(im\\|ex\\)port$' || s:PreviousToken() == '.'") + elseif tok ==# 'of' + return s:Pure('eval',"!s:GetPair('[[({]','[])}]','bW',s:skip_expr) || s:LookingAt() != '(' ||" + \ ."s:{s:PreviousToken() ==# 'await' ? 'Previous' : ''}Token() !=# 'for' || s:PreviousToken() == '.'") + endif + return index(split('return const let import export extends yield default delete var await void typeof throw case new in instanceof') + \ ,tok) < (line('.') != a:firstline) || s:Pure('s:PreviousToken') == '.' + elseif tok == '>' + return getline('.')[col('.')-2] == '=' || s:SynAt(line('.'),col('.')) =~? 'jsflow\|^html' + elseif tok == '*' + return s:Pure('s:PreviousToken') == ':' + elseif tok == ':' + return s:Pure('eval',"s:PreviousToken() =~ '^\\K\\k*$' && !s:ExprCol()") + elseif tok == '/' + return s:SynAt(line('.'),col('.')) =~? 'regex' + elseif tok !~ '[=~!<,.?^%|&([]' + return tok !~ '[-+]' || line('.') != a:firstline && getline('.')[col('.')-2] == tok + endif +endfunction + +function GetJavascriptIndent() + let b:js_cache = get(b:,'js_cache',[0,0,0]) + let s:synid_cache = [[],[]] let l:line = getline(v:lnum) - let syns = synIDattr(synID(v:lnum, 1, 0), 'name') + " 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')") - " start with strings,comments,etc.{{{2 - if (l:line !~ '^[''"`]' && syns =~? 'string\|template') || - \ (l:line !~ '^\s*[/*]' && syns =~? s:syng_comment) + " start with strings,comments,etc. + if s:stack[-1] =~? 'comment\|doc' + if l:line =~ '^\s*\*' + return cindent(v:lnum) + elseif l:line !~ '^\s*\/[/*]' + return -1 + endif + elseif s:stack[-1] =~? b:syng_str + if b:js_cache[0] == v:lnum - 1 && s:Balanced(v:lnum-1) + let b:js_cache[0] = v:lnum + endif return -1 endif - if l:line !~ '^\%(\/\*\|\s*\/\/\)' && syns =~? s:syng_comment - return cindent(v:lnum) - endif - let l:lnum = s:PrevCodeLine(v:lnum - 1) - if l:lnum == 0 - return 0 + + let s:l1 = max([0,prevnonblank(v:lnum) - (s:rel ? 2000 : 1000), + \ get(get(b:,'hi_indent',{}),'blocklnr')]) + call cursor(v:lnum,1) + if s:PreviousToken() is '' + return endif + let [l:lnum, pline] = [line('.'), getline('.')[:col('.')-1]] - if (l:line =~# s:expr_case) - let cpo_switch = &cpo - set cpo+=% - let ind = cindent(v:lnum) - let &cpo = cpo_switch - return ind + let l:line = substitute(l:line,'^\s*','','') + let l:line_raw = l:line + if l:line[:1] == '/*' + let l:line = substitute(l:line,'^\%(\/\*.\{-}\*\/\s*\)*','','') + endif + if l:line =~ '^\/[/*]' + let l:line = '' endif - "}}} - " the containing paren, bracket, curly. Memoize, last lineNr either has the - " same scope or starts a new one, unless if it closed a scope. + " the containing paren, bracket, or curly. Many hacks for performance call cursor(v:lnum,1) - if b:js_cache[0] >= l:lnum && b:js_cache[0] <= v:lnum && b:js_cache[0] && - \ (b:js_cache[0] > l:lnum || s:Balanced(l:lnum) > 0) - let num = b:js_cache[1] - elseif syns != '' && l:line[0] =~ '\s' - let pattern = syns =~? 'block' ? ['{','}'] : syns =~? 'jsparen' ? ['(',')'] : - \ syns =~? 'jsbracket'? ['\[','\]'] : ['[({[]','[])}]'] - let num = s:lookForParens(pattern[0],pattern[1],'bW',2000) + 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 num = s:lookForParens('[({[]','[])}]','bW',2000) + let [s:looksyn, s:top_col, s:check_in, s:l1] = [v:lnum - 1,0,0, + \ max([s:l1, &smc ? search('\m^.\{'.&smc.',}','nbW',s:l1 + 1) + 1 : 0])] + try + if idx != -1 + call s:GetPair(['\[','(','{'][idx],'])}'[idx],'bW','s:SkipFunc()') + elseif getline(v:lnum) !~ '^\S' && s:stack[-1] =~? 'block\|^jsobject$' + call s:GetPair('{','}','bW','s:SkipFunc()') + else + call s:AlternatePair() + endif + catch /^\Cout of bounds$/ + call cursor(v:lnum,1) + endtry + let b:js_cache[1:] = line('.') == v:lnum ? [0,0] : getpos('.')[1:2] endif - let b:js_cache = [v:lnum,num,line('.') == v:lnum ? b:js_cache[2] : col('.')] - if l:line =~ s:line_pre . '[])}]' - return indent(num) - endif + let [b:js_cache[0], num] = [v:lnum, b:js_cache[1]] - let pline = s:StripLine(getline(l:lnum)) - let inb = num == 0 ? 1 : (s:Onescope(num, s:StripLine(strpart(getline(num),0,b:js_cache[2] - 1)),1) || - \ (l:line !~ s:line_pre . ',' && pline !~ ',' . s:line_term)) && num < l:lnum - let switch_offset = (!inb || num == 0) || expand("<cword>") !=# 'switch' ? 0 : &cino !~ ':' || !has('float') ? s:sw() : - \ float2nr(str2float(matchstr(&cino,'.*:\zs[-0-9.]*')) * (&cino =~# '.*:[^,]*s' ? s:sw() : 1)) - - " most significant, find the indent amount - if (inb && (l:line =~# g:javascript_opfirst || - \ (pline =~# g:javascript_continuation && pline !~# s:expr_case && (pline !~ ':' . s:line_term || l:line !~# - \ s:line_pre . '\%(d\%(o\|ebugger\)\|else\|f\%(or\|inally\)\|if\|let\|switch\|t\%(hrow\|ry\)\|w\%(hile\|ith\)\)\>')))) || - \ (num < l:lnum && s:Onescope(l:lnum,pline,0) && l:line !~ s:line_pre . '{') - return (num > 0 ? indent(num) : -s:sw()) + (s:sw() * 2) + switch_offset - elseif num > 0 - return indent(num) + s:sw() + switch_offset + let [num_ind, is_op, b_l, l:switch_offset] = [s:Nat(indent(num)),0,0,0] + if !num || s:LookingAt() == '{' && s:IsBlock() + let ilnum = line('.') + if num && s:LookingAt() == ')' && s:GetPair('(',')','bW',s:skip_expr) + if ilnum == num + let [num, num_ind] = [line('.'), indent('.')] + endif + if idx == -1 && s:PreviousToken() ==# 'switch' && s:IsSwitch() + let l:switch_offset = &cino !~ ':' ? s:sw() : s:ParseCino(':') + if pline[-1:] != '.' && l:line =~# '^\%(default\|case\)\>' + return s:Nat(num_ind + l:switch_offset) + elseif &cino =~ '=' + let l:case_offset = s:ParseCino('=') + endif + endif + endif + if idx == -1 && pline[-1:] !~ '[{;]' + let sol = matchstr(l:line,s:opfirst) + if sol is '' || sol == '/' && s:SynAt(v:lnum, + \ 1 + len(getline(v:lnum)) - len(l:line)) =~? 'regex' + if s:Continues(l:lnum,pline) + let is_op = s:sw() + endif + elseif num && sol =~# '^\%(in\%(stanceof\)\=\|\*\)$' + call call('cursor',b:js_cache[1:]) + if s:PreviousToken() =~ '\k' && s:Class() + return num_ind + s:sw() + endif + let is_op = s:sw() + else + let is_op = s:sw() + endif + call cursor(l:lnum, len(pline)) + let b_l = s:Nat(s:IsContOne(b:js_cache[1],is_op) - (!is_op && l:line =~ '^{')) * s:sw() + endif + elseif idx.s:LookingAt().&cino =~ '^-1(.*(' && (search('\m\S','nbW',num) || s:ParseCino('U')) + let pval = s:ParseCino('(') + if !pval + let [Wval, vcol] = [s:ParseCino('W'), virtcol('.')] + if search('\m\S','W',num) + return s:ParseCino('w') ? vcol : virtcol('.')-1 + endif + return Wval ? s:Nat(num_ind + Wval) : vcol + endif + return s:Nat(num_ind + pval + searchpair('\m(','','\m)','nbrmW',s:skip_expr,num) * s:sw()) endif + " main return + if l:line =~ '^[])}]\|^|}' + if l:line_raw[0] == ')' && getline(num)[b:js_cache[2]-1] == '(' + if s:ParseCino('M') + return indent(l:lnum) + elseif &cino =~# 'm' && !s:ParseCino('m') + return virtcol('.') - 1 + endif + endif + return num_ind + elseif num + return s:Nat(num_ind + get(l:,'case_offset',s:sw()) + l:switch_offset + b_l + is_op) + endif + return b_l + is_op endfunction - let &cpo = s:cpo_save unlet 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/ld.vim b/runtime/indent/ld.vim index eccf42b2b4..a72a3a9548 100644 --- a/runtime/indent/ld.vim +++ b/runtime/indent/ld.vim @@ -1,7 +1,7 @@ " Vim indent file -" Language: ld(1) script -" Maintainer: Nikolai Weibull <now@bitwi.se> -" Latest Revision: 2006-12-20 +" Language: ld(1) script +" Previous Maintainer: Nikolai Weibull <now@bitwi.se> +" Latest Revision: 2006-12-20 if exists("b:did_indent") finish @@ -65,7 +65,7 @@ function GetLDIndent() if line =~ '^\s*\*' return cindent(v:lnum) elseif line =~ '^\s*}' - return indent(v:lnum) - &sw + return indent(v:lnum) - shiftwidth() endif let pnum = s:prevnonblanknoncomment(v:lnum - 1) @@ -73,11 +73,11 @@ function GetLDIndent() return 0 endif - let ind = indent(pnum) + s:count_braces(pnum, 1) * &sw + let ind = indent(pnum) + s:count_braces(pnum, 1) * shiftwidth() let pline = getline(pnum) if pline =~ '}\s*$' - let ind -= (s:count_braces(pnum, 0) - (pline =~ '^\s*}' ? 1 : 0)) * &sw + let ind -= (s:count_braces(pnum, 0) - (pline =~ '^\s*}' ? 1 : 0)) * shiftwidth() endif return ind diff --git a/runtime/indent/liquid.vim b/runtime/indent/liquid.vim index 01e7223696..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: 2013 May 30 +" Last Change: 2017 Jun 13 if exists('b:did_indent') finish @@ -54,9 +54,10 @@ 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 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\)\>') - let ind -= &sw * s:count(cline,'{%\s*end\w*$') + 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\)\>') + let ind -= sw * s:count(cline,'{%\s*end\w*$') return ind endfunction 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/make.vim b/runtime/indent/make.vim index 8412fbb4d1..66a8a40173 100644 --- a/runtime/indent/make.vim +++ b/runtime/indent/make.vim @@ -1,7 +1,7 @@ " Vim indent file -" Language: Makefile -" Maintainer: Nikolai Weibull <now@bitwi.se> -" Latest Revision: 2007-05-07 +" Language: Makefile +" Previous Maintainer: Nikolai Weibull <now@bitwi.se> +" Latest Revision: 2007-05-07 if exists("b:did_indent") finish @@ -48,14 +48,14 @@ function GetMakeIndent() if prev_prev_line =~ s:continuation_rx return indent(prev_lnum) elseif prev_line =~ s:rule_rx - return &sw + return shiftwidth() elseif prev_line =~ s:assignment_rx call cursor(prev_lnum, 1) if search(s:assignment_rx, 'W') != 0 return virtcol('.') - 1 else " TODO: ? - return &sw + return shiftwidth() endif else " TODO: OK, this might be a continued shell command, so perhaps indent @@ -66,7 +66,7 @@ function GetMakeIndent() " return indent(prev_lnum) + 2 " endif "endif - return indent(prev_lnum) + &sw + return indent(prev_lnum) + shiftwidth() endif elseif prev_prev_line =~ s:continuation_rx let folded_line = s:remove_continuation(prev_prev_line) . ' ' . s:remove_continuation(prev_line) @@ -102,13 +102,13 @@ function GetMakeIndent() return &ts endif elseif prev_line =~ s:conditional_directive_rx - return &sw + return shiftwidth() else let line = getline(v:lnum) if line =~ s:just_inserted_rule_rx return 0 elseif line =~ s:end_conditional_directive_rx - return v:lnum - 1 == 0 ? 0 : indent(v:lnum - 1) - &sw + return v:lnum - 1 == 0 ? 0 : indent(v:lnum - 1) - shiftwidth() else return v:lnum - 1 == 0 ? 0 : indent(v:lnum - 1) endif 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/mf.vim b/runtime/indent/mf.vim new file mode 100644 index 0000000000..88737f4e9f --- /dev/null +++ b/runtime/indent/mf.vim @@ -0,0 +1,6 @@ +" METAFONT indent file +" Language: METAFONT +" Maintainer: Nicola Vitacolonna <nvitacolonna@gmail.com> +" Last Change: 2016 Oct 1 + +runtime! indent/mp.vim 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/mp.vim b/runtime/indent/mp.vim index a118eb8b60..86fa2539c1 100644 --- a/runtime/indent/mp.vim +++ b/runtime/indent/mp.vim @@ -1,56 +1,19 @@ " MetaPost indent file -" Language: MetaPost -" Maintainer: Eugene Minkovskii <emin@mccme.ru> -" Last Change: 2012 May 18 -" Version: 0.1 -" ========================================================================== - -" Identation Rules: {{{1 -" First of all, MetaPost language don't expect any identation rules. -" This screept need for you only if you (not MetaPost) need to do -" exactly code. If you don't need to use indentation, see -" :help filetype-indent-off -" -" Note: Every rules of identation in MetaPost or TeX languages (and in some -" other of course) is very subjective. I can release only my vision of this -" promlem. -" -" .......................................................................... -" Example of correct (by me) identation {{{2 -" shiftwidth=4 -" ========================================================================== -" for i=0 upto 99: -" z[i] = (0,1u) rotated (i*360/100); -" endfor -" draw z0 -- z10 -- z20 -" withpen ... % <- 2sw because breaked line -" withcolor ...; % <- same as previous -" draw z0 for i=1 upto 99: -" -- z[i] % <- 1sw from left end of 'for' satement -" endfor withpen ... % <- 0sw from left end of 'for' satement -" withcolor ...; % <- 2sw because breaked line -" draw if One: % <- This is internal if (like 'for' above) -" one -" elsif Other: -" other -" fi withpen ...; -" if one: % <- This is external if -" draw one; -" elseif other: -" draw other; -" fi -" draw z0; draw z1; -" }}} -" }}} +" Language: MetaPost +" Maintainer: Nicola Vitacolonna <nvitacolonna@gmail.com> +" Former Maintainers: Eugene Minkovskii <emin@mccme.ru> +" Last Change: 2016 Oct 2, 4:13pm +" Version: 0.2 -" Only load this indent file when no other was loaded. if exists("b:did_indent") finish endif let b:did_indent = 1 setlocal indentexpr=GetMetaPostIndent() -setlocal indentkeys+=;,<:>,=if,=for,=def,=end,=else,=fi +setlocal indentkeys+==end,=else,=fi,=fill,0),0] + +let b:undo_indent = "setl indentkeys< indentexpr<" " Only define the function once. if exists("*GetMetaPostIndent") @@ -59,151 +22,337 @@ endif let s:keepcpo= &cpo set cpo&vim -" Auxiliary Definitions: {{{1 -function! MetaNextNonblankNoncomment(pos) - " Like nextnonblank() but ignore comment lines - let tmp = nextnonblank(a:pos) - while tmp && getline(tmp) =~ '^\s*%' - let tmp = nextnonblank(tmp+1) +function GetMetaPostIndent() + let ignorecase_save = &ignorecase + try + let &ignorecase = 0 + return GetMetaPostIndentIntern() + finally + let &ignorecase = ignorecase_save + endtry +endfunc + +" Regexps {{{ +" Note: the next three variables are made global so that a user may add +" further keywords. +" +" Example: +" +" Put these in ~/.vim/after/indent/mp.vim +" +" let g:mp_open_tag .= '\|\<begintest\>' +" let g:mp_close_tag .= '\|\<endtest\>' + +" Expressions starting indented blocks +let g:mp_open_tag = '' + \ . '\<if\>' + \ . '\|\<else\%[if]\>' + \ . '\|\<for\%(\|ever\|suffixes\)\>' + \ . '\|\<begingroup\>' + \ . '\|\<\%(\|var\|primary\|secondary\|tertiary\)def\>' + \ . '\|^\s*\<begin\%(fig\|graph\|glyph\|char\|logochar\)\>' + \ . '\|[([{]' + +" Expressions ending indented blocks +let g:mp_close_tag = '' + \ . '\<fi\>' + \ . '\|\<else\%[if]\>' + \ . '\|\<end\%(\|for\|group\|def\|fig\|char\|glyph\|graph\)\>' + \ . '\|[)\]}]' + +" Statements that may span multiple lines and are ended by a semicolon. To +" keep this list short, statements that are unlikely to be very long or are +" not very common (e.g., keywords like `interim` or `showtoken`) are not +" included. +" +" The regex for assignments and equations (the last branch) is tricky, because +" it must not match things like `for i :=`, `if a=b`, `def...=`, etc... It is +" not perfect, but it works reasonably well. +let g:mp_statement = '' + \ . '\<\%(\|un\|cut\)draw\>' + \ . '\|\<\%(\|un\)fill\%[draw]\>' + \ . '\|\<draw\%(dbl\)\=arrow\>' + \ . '\|\<clip\>' + \ . '\|\<addto\>' + \ . '\|\<save\>' + \ . '\|\<setbounds\>' + \ . '\|\<message\>' + \ . '\|\<errmessage\>' + \ . '\|\<errhelp\>' + \ . '\|\<fontmapline\>' + \ . '\|\<pickup\>' + \ . '\|\<show\>' + \ . '\|\<special\>' + \ . '\|\<write\>' + \ . '\|\%(^\|;\)\%([^;=]*\%('.g:mp_open_tag.'\)\)\@!.\{-}:\==' + +" A line ends with zero or more spaces, possibly followed by a comment. +let s:eol = '\s*\%($\|%\)' +" }}} + +" Auxiliary functions {{{ +" Returns 1 if (0-based) position immediately preceding `pos` in `line` is +" inside a string or a comment; returns 0 otherwise. + +" This is the function that is called more often when indenting, so it is +" critical that it is efficient. The method we use is significantly faster +" than using syntax attributes, and more general (it does not require +" syntax_items). It is also faster than using a single regex matching an even +" number of quotes. It helps that MetaPost strings cannot span more than one +" line and cannot contain escaped quotes. +function! s:CommentOrString(line, pos) + let in_string = 0 + let q = stridx(a:line, '"') + let c = stridx(a:line, '%') + while q >= 0 && q < a:pos + if c >= 0 && c < q + if in_string " Find next percent symbol + let c = stridx(a:line, '%', q + 1) + else " Inside comment + return 1 + endif + endif + let in_string = 1 - in_string + let q = stridx(a:line, '"', q + 1) " Find next quote endwhile - return tmp + return in_string || (c >= 0 && c <= a:pos) endfunction -function! MetaPrevNonblankNoncomment(pos) - " Like prevnonblank() but ignore comment lines - let tmp = prevnonblank(a:pos) - while tmp && getline(tmp) =~ '^\s*%' - let tmp = prevnonblank(tmp-1) +" Find the first non-comment non-blank line before the current line. +function! s:PrevNonBlankNonComment(lnum) + let l:lnum = prevnonblank(a:lnum - 1) + while getline(l:lnum) =~# '^\s*%' + let l:lnum = prevnonblank(l:lnum - 1) endwhile - return tmp + return l:lnum endfunction -function! MetaSearchNoncomment(pattern, ...) - " Like search() but ignore commented areas - if a:0 - let flags = a:1 - elseif &wrapscan - let flags = "w" - else - let flags = "W" - endif - let cl = line(".") - let cc = col(".") - let tmp = search(a:pattern, flags) - while tmp && synIDattr(synID(line("."), col("."), 1), "name") =~ - \ 'm[fp]\(Comment\|TeXinsert\|String\)' - let tmp = search(a:pattern, flags) +" Returns true if the last tag appearing in the line is an open tag; returns +" false otherwise. +function! s:LastTagIsOpen(line) + let o = s:LastValidMatchEnd(a:line, g:mp_open_tag, 0) + if o == - 1 | return v:false | endif + return s:LastValidMatchEnd(a:line, g:mp_close_tag, o) < 0 +endfunction + +" A simple, efficient and quite effective heuristics is used to test whether +" a line should cause the next line to be indented: count the "opening tags" +" (if, for, def, ...) in the line, count the "closing tags" (endif, endfor, +" ...) in the line, and compute the difference. We call the result the +" "weight" of the line. If the weight is positive, then the next line should +" most likely be indented. Note that `else` and `elseif` are both opening and +" closing tags, so they "cancel out" in almost all cases, the only exception +" being a leading `else[if]`, which is counted as an opening tag, but not as +" a closing tag (so that, for instance, a line containing a single `else:` +" will have weight equal to one, not zero). We do not treat a trailing +" `else[if]` in any special way, because lines ending with an open tag are +" dealt with separately before this function is called (see +" GetMetaPostIndentIntern()). +" +" Example: +" +" forsuffixes $=a,b: if x.$ = y.$ : draw else: fill fi +" % This line will be indented because |{forsuffixes,if,else}| > |{else,fi}| (3 > 2) +" endfor + +function! s:Weight(line) + let [o, i] = [0, s:ValidMatchEnd(a:line, g:mp_open_tag, 0)] + while i > 0 + let o += 1 + let i = s:ValidMatchEnd(a:line, g:mp_open_tag, i) + endwhile + let [c, i] = [0, matchend(a:line, '^\s*\<else\%[if]\>')] " Skip a leading else[if] + let i = s:ValidMatchEnd(a:line, g:mp_close_tag, i) + while i > 0 + let c += 1 + let i = s:ValidMatchEnd(a:line, g:mp_close_tag, i) + endwhile + return o - c +endfunction + +" Similar to matchend(), but skips strings and comments. +" line: a String +function! s:ValidMatchEnd(line, pat, start) + let i = matchend(a:line, a:pat, a:start) + while i > 0 && s:CommentOrString(a:line, i) + let i = matchend(a:line, a:pat, i) + endwhile + return i +endfunction + +" Like s:ValidMatchEnd(), but returns the end position of the last (i.e., +" rightmost) match. +function! s:LastValidMatchEnd(line, pat, start) + let last_found = -1 + let i = matchend(a:line, a:pat, a:start) + while i > 0 + if !s:CommentOrString(a:line, i) + let last_found = i + endif + let i = matchend(a:line, a:pat, i) endwhile - if !tmp - call cursor(cl,cc) + return last_found +endfunction + +function! s:DecreaseIndentOnClosingTag(curr_indent) + let cur_text = getline(v:lnum) + if cur_text =~# '^\s*\%('.g:mp_close_tag.'\)' + return max([a:curr_indent - shiftwidth(), 0]) endif - return tmp + return a:curr_indent endfunction " }}} -function! GetMetaPostIndent() - " not indent in comment ??? - if synIDattr(synID(line("."), col("."), 1), "name") =~ - \ 'm[fp]\(Comment\|TeXinsert\|String\)' +" Main function {{{ +" +" Note: Every rule of indentation in MetaPost is very subjective. We might get +" creative, but things get murky very soon (there are too many corner cases). +" So, we provide a means for the user to decide what to do when this script +" doesn't get it. We use a simple idea: use '%>', '%<' and '%=' to explicitly +" control indentation. The '<' and '>' symbols may be repeated many times +" (e.g., '%>>' will cause the next line to be indented twice). +" +" By using '%>...', '%<...' and '%=', the indentation the user wants is +" preserved by commands like gg=G, even if it does not follow the rules of +" this script. +" +" Example: +" +" def foo = +" makepen( +" subpath(T-n,t) of r %> +" shifted .5down %> +" --subpath(t,T) of r shifted .5up -- cycle %<<< +" ) +" withcolor black +" enddef +" +" The default indentation of the previous example would be: +" +" def foo = +" makepen( +" subpath(T-n,t) of r +" shifted .5down +" --subpath(t,T) of r shifted .5up -- cycle +" ) +" withcolor black +" enddef +" +" Personally, I prefer the latter, but anyway... +function! GetMetaPostIndentIntern() + " Do not touch indentation inside verbatimtex/btex.. etex blocks. + if synIDattr(synID(v:lnum, 1, 1), "name") =~# '^mpTeXinsert$\|^tex\|^Delimiter' return -1 endif - " Some RegExps: {{{1 - " end_of_item: all of end by ';' - " + all of end by :endfor, :enddef, :endfig, :endgroup, :fi - " + all of start by :beginfig(num), :begingroup - " + all of start by :for, :if, :else, :elseif and end by ':' - " + all of start by :def, :vardef and end by '=' - let end_of_item = '\(' . - \ ';\|' . - \ '\<\(end\(for\|def\|fig\|group\)\|fi\)\>\|' . - \ '\<begin\(group\>\|fig\s*(\s*\d\+\s*)\)\|' . - \ '\<\(for\|if\|else\(if\)\=\)\>.\+:\|' . - \ '\<\(var\)\=def\>.\+=' . '\)' - " }}} - " Save: current position {{{1 - let cl = line (".") - let cc = col (".") - let cs = getline(".") - " if it is :beginfig or :endfig use zero indent - if cs =~ '^\s*\(begin\|end\)fig\>' - return 0 - endif - " }}} - " Initialise: ind variable {{{1 - " search previous item not in current line - let p_semicol_l = MetaSearchNoncomment(end_of_item,"bW") - while p_semicol_l == cl - let p_semicol_l = MetaSearchNoncomment(end_of_item,"bW") - endwhile - " if this is first item in program use zero indent - if !p_semicol_l + + " This is the reference line relative to which the current line is indented + " (but see below). + let lnum = s:PrevNonBlankNonComment(v:lnum) + + " At the start of the file use zero indent. + if lnum == 0 return 0 endif - " if this is multiline item, remember first indent - if MetaNextNonblankNoncomment(p_semicol_l+1) < cl - let ind = indent(MetaNextNonblankNoncomment(p_semicol_l+1)) - " else --- search pre-previous item for search first line in previous item - else - " search pre-previous item not in current line - let pp_semicol_l = MetaSearchNoncomment(end_of_item,"bW") - while pp_semicol_l == p_semicol_l - let pp_semicol_l = MetaSearchNoncomment(end_of_item,"bW") - endwhile - " if we find pre-previous item, remember indent of previous item - " else --- remember zero - if pp_semicol_l - let ind = indent(MetaNextNonblankNoncomment(line(".")+1)) - else - let ind = 0 + + let prev_text = getline(lnum) + + " User-defined overrides take precedence over anything else. + " See above for an example. + let j = match(prev_text, '%[<>=]') + if j > 0 + let i = strlen(matchstr(prev_text, '%>\+', j)) - 1 + if i > 0 + return indent(lnum) + i * shiftwidth() + endif + + let i = strlen(matchstr(prev_text, '%<\+', j)) - 1 + if i > 0 + return max([indent(lnum) - i * shiftwidth(), 0]) + endif + + if match(prev_text, '%=', j) + return indent(lnum) endif endif - " }}} - " Increase Indent: {{{1 - " if it is an internal/external :for or :if statements {{{2 - let pnn_s = getline(MetaPrevNonblankNoncomment(cl-1)) - if pnn_s =~ '\<\(for\|if\)\>.\+:\s*\($\|%\)' - let ind = match(pnn_s, '\<\(for\|if\)\>.\+:\s*\($\|%\)') + &sw - " }}} - " if it is a :def, :vardef, :beginfig, :begingroup, :else, :elseif {{{2 - elseif pnn_s =~ '^\s*\(' . - \ '\(var\)\=def\|' . - \ 'begin\(group\|fig\s*(\s*\d\+\s*)\)\|' . - \ 'else\(if\)\=' . '\)\>' - let ind = ind + &sw - " }}} - " if it is a broken line {{{2 - elseif pnn_s !~ end_of_item.'\s*\($\|%\)' - let ind = ind + (2 * &sw) + + " If the reference line ends with an open tag, indent. + " + " Example: + " + " if c: + " 0 + " else: + " 1 + " fi if c2: % Note that this line has weight equal to zero. + " ... % This line will be indented + if s:LastTagIsOpen(prev_text) + return s:DecreaseIndentOnClosingTag(indent(lnum) + shiftwidth()) endif - " }}} - " }}} - " Decrease Indent: {{{1 - " if this is :endfor or :enddef statements {{{2 - " this is correct because :def cannot be inside :for - if cs =~ '\<end\(for\|def\)\=\>' - call MetaSearchNoncomment('\<for\>.\+:\s*\($\|%\)' . '\|' . - \ '^\s*\(var\)\=def\>',"bW") - if col(".") > 1 - let ind = col(".") - 1 + + " Lines with a positive weight are unbalanced and should likely be indented. + " + " Example: + " + " def f = enddef for i = 1 upto 5: if x[i] > 0: 1 else: 2 fi + " ... % This line will be indented (because of the unterminated `for`) + if s:Weight(prev_text) > 0 + return s:DecreaseIndentOnClosingTag(indent(lnum) + shiftwidth()) + endif + + " Unterminated statements cause indentation to kick in. + " + " Example: + " + " draw unitsquare + " withcolor black; % This line is indented because of `draw`. + " x := a + b + c + " + d + e; % This line is indented because of `:=`. + " + let i = s:LastValidMatchEnd(prev_text, g:mp_statement, 0) + if i >= 0 " Does the line contain a statement? + if s:ValidMatchEnd(prev_text, ';', i) < 0 " Is the statement unterminated? + return indent(lnum) + shiftwidth() else - let ind = indent(".") + return s:DecreaseIndentOnClosingTag(indent(lnum)) endif - " }}} - " if this is :fi, :else, :elseif statements {{{2 - elseif cs =~ '\<\(else\(if\)\=\|fi\)\>' - call MetaSearchNoncomment('\<if\>.\+:\s*\($\|%\)',"bW") - let ind = col(".") - 1 - " }}} - " if this is :endgroup statement {{{2 - elseif cs =~ '^\s*endgroup\>' - let ind = ind - &sw endif - " }}} - " }}} - return ind + " Deal with the special case of a statement spanning multiple lines. If the + " current reference line L ends with a semicolon, search backwards for + " another semicolon or a statement keyword. If the latter is found first, + " its line is used as the reference line for indenting the current line + " instead of L. + " + " Example: + " + " if cond: + " draw if a: z0 else: z1 fi + " shifted S + " scaled T; % L + " + " for i = 1 upto 3: % <-- Current line: this gets the same indent as `draw ...` + " + " NOTE: we get here only if L does not contain a statement (among those + " listed in g:mp_statement). + if s:ValidMatchEnd(prev_text, ';'.s:eol, 0) >= 0 " L ends with a semicolon + let stm_lnum = s:PrevNonBlankNonComment(lnum) + while stm_lnum > 0 + let prev_text = getline(stm_lnum) + let sc_pos = s:LastValidMatchEnd(prev_text, ';', 0) + let stm_pos = s:ValidMatchEnd(prev_text, g:mp_statement, sc_pos) + if stm_pos > sc_pos + let lnum = stm_lnum + break + elseif sc_pos > stm_pos + break + endif + let stm_lnum = s:PrevNonBlankNonComment(stm_lnum) + endwhile + endif + + return s:DecreaseIndentOnClosingTag(indent(lnum)) endfunction -" +" }}} let &cpo = s:keepcpo unlet s:keepcpo 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..094d1d37ea 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-01-04 " Suggestions and improvements by : " Aaron J. Sherman (use syntax for hints) @@ -48,11 +48,6 @@ function! GetPerlIndent() return 0 endif - " Don't reindent comments on first column - if cline =~ '^#.' - return 0 - endif - " Get current syntax item at the line's first char let csynid = '' if b:indent_use_syntax @@ -134,13 +129,14 @@ function! GetPerlIndent() \ || synid == "perlMatchStartEnd" \ || synid == "perlHereDoc" \ || synid == "perlBraces" + \ || synid == "perlStatementIndirObj" \ || synid =~ "^perlFiledescStatement" \ || 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) @@ -151,26 +147,27 @@ function! GetPerlIndent() if synid == "" \ || synid == "perlMatchStartEnd" \ || synid == "perlBraces" + \ || synid == "perlStatementIndirObj" \ || 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/readline.vim b/runtime/indent/readline.vim index 6ac2185bdc..e202ddfd89 100644 --- a/runtime/indent/readline.vim +++ b/runtime/indent/readline.vim @@ -1,7 +1,7 @@ " Vim indent file -" Language: readline configuration file -" Maintainer: Nikolai Weibull <now@bitwi.se> -" Latest Revision: 2006-12-20 +" Language: readline configuration file +" Previous Maintainer: Nikolai Weibull <now@bitwi.se> +" Latest Revision: 2006-12-20 if exists("b:did_indent") finish @@ -25,11 +25,11 @@ function GetReadlineIndent() let ind = indent(lnum) if getline(lnum) =~ '^\s*$\(if\|else\)\>' - let ind = ind + &sw + let ind = ind + shiftwidth() endif if getline(v:lnum) =~ '^\s*$\(else\|endif\)\>' - let ind = ind - &sw + let ind = ind - shiftwidth() endif return ind 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/rnoweb.vim b/runtime/indent/rnoweb.vim index 29fa5bc78f..8c11e85cb3 100644 --- a/runtime/indent/rnoweb.vim +++ b/runtime/indent/rnoweb.vim @@ -2,7 +2,7 @@ " Language: Rnoweb " Author: Jakson Alves de Aquino <jalvesaq@gmail.com> " Homepage: https://github.com/jalvesaq/R-Vim-runtime -" Last Change: Tue Apr 07, 2015 04:38PM +" Last Change: Fri Apr 15, 2016 10:58PM " Only load this indent file when no other was loaded. @@ -10,7 +10,17 @@ if exists("b:did_indent") finish endif runtime indent/tex.vim -let s:TeXIndent = function(substitute(&indentexpr, "()", "", "")) + +function! s:NoTeXIndent() + return indent(line(".")) +endfunction + +if &indentexpr == "" || &indentexpr == "GetRnowebIndent()" + let s:TeXIndent = function("s:NoTeXIndent") +else + let s:TeXIndent = function(substitute(&indentexpr, "()", "", "")) +endif + unlet b:did_indent runtime indent/r.vim let s:RIndent = function(substitute(&indentexpr, "()", "", "")) 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/rst.vim b/runtime/indent/rst.vim index 80d3308fd8..c1ef8c9957 100644 --- a/runtime/indent/rst.vim +++ b/runtime/indent/rst.vim @@ -1,7 +1,7 @@ " Vim indent file -" Language: reStructuredText Documentation Format -" Maintainer: Nikolai Weibull <now@bitwi.se> -" Latest Revision: 2011-08-03 +" Language: reStructuredText Documentation Format +" Previous Maintainer: Nikolai Weibull <now@bitwi.se> +" Latest Revision: 2011-08-03 if exists("b:did_indent") finish diff --git a/runtime/indent/ruby.vim b/runtime/indent/ruby.vim index 095b3a43c6..d8733db305 100644 --- a/runtime/indent/ruby.vim +++ b/runtime/indent/ruby.vim @@ -13,12 +13,23 @@ if exists("b:did_indent") endif let b:did_indent = 1 +if !exists('g:ruby_indent_access_modifier_style') + " Possible values: "normal", "indent", "outdent" + let g:ruby_indent_access_modifier_style = 'normal' +endif + +if !exists('g:ruby_indent_block_style') + " Possible values: "expression", "do" + let g:ruby_indent_block_style = 'expression' +endif + setlocal nosmartindent " Now, set up our indentation expression and keys that trigger it. setlocal indentexpr=GetRubyIndent(v:lnum) -setlocal indentkeys=0{,0},0),0],!^F,o,O,e +setlocal indentkeys=0{,0},0),0],!^F,o,O,e,:,. setlocal indentkeys+==end,=else,=elsif,=when,=ensure,=rescue,==begin,==end +setlocal indentkeys+==private,=protected,=public " Only define the function once. if exists("*GetRubyIndent") @@ -34,7 +45,7 @@ set cpo&vim " Regex of syntax group names that are or delimit strings/symbols or are comments. let s:syng_strcom = '\<ruby\%(Regexp\|RegexpDelimiter\|RegexpEscape' . \ '\|Symbol\|String\|StringDelimiter\|StringEscape\|ASCIICode' . - \ '\|Interpolation\|NoInterpolation\|Comment\|Documentation\)\>' + \ '\|Interpolation\|InterpolationDelimiter\|NoInterpolation\|Comment\|Documentation\)\>' " Regex of syntax group names that are strings. let s:syng_string = @@ -49,9 +60,10 @@ let s:skip_expr = \ "synIDattr(synID(line('.'),col('.'),1),'name') =~ '".s:syng_strcom."'" " Regex used for words that, at the start of a line, add a level of indent. -let s:ruby_indent_keywords = '^\s*\zs\<\%(module\|class\|def\|if\|for' . - \ '\|while\|until\|else\|elsif\|case\|when\|unless\|begin\|ensure' . - \ '\|rescue\):\@!\>' . +let s:ruby_indent_keywords = + \ '^\s*\zs\<\%(module\|class\|if\|for' . + \ '\|while\|until\|else\|elsif\|case\|when\|unless\|begin\|ensure\|rescue' . + \ '\|\%(public\|protected\|private\)\=\s*def\):\@!\>' . \ '\|\%([=,*/%+-]\|<<\|>>\|:\s\)\s*\zs' . \ '\<\%(if\|for\|while\|until\|case\|unless\|begin\):\@!\>' @@ -64,7 +76,8 @@ let s:ruby_deindent_keywords = " TODO: the do here should be restricted somewhat (only at end of line)? let s:end_start_regex = \ '\C\%(^\s*\|[=,*/%+\-|;{]\|<<\|>>\|:\s\)\s*\zs' . - \ '\<\%(module\|class\|def\|if\|for\|while\|until\|case\|unless\|begin\):\@!\>' . + \ '\<\%(module\|class\|if\|for\|while\|until\|case\|unless\|begin' . + \ '\|\%(public\|protected\|private\)\=\s*def\):\@!\>' . \ '\|\%(^\|[^.:@$]\)\@<=\<do:\@!\>' " Regex that defines the middle-match for the 'end' keyword. @@ -79,19 +92,39 @@ let s:end_skip_expr = s:skip_expr . \ ' && getline(".") =~ "^\\s*\\<\\(while\\|until\\|for\\):\\@!\\>")' " Regex that defines continuation lines, not including (, {, or [. -let s:non_bracket_continuation_regex = '\%([\\.,:*/%+]\|\<and\|\<or\|\%(<%\)\@<![=-]\|\W[|&?]\|||\|&&\)\s*\%(#.*\)\=$' +let s:non_bracket_continuation_regex = + \ '\%([\\.,:*/%+]\|\<and\|\<or\|\%(<%\)\@<![=-]\|:\@<![^[:alnum:]:][|&?]\|||\|&&\)\s*\%(#.*\)\=$' " Regex that defines continuation lines. -" TODO: this needs to deal with if ...: and so on let s:continuation_regex = - \ '\%(%\@<![({[\\.,:*/%+]\|\<and\|\<or\|\%(<%\)\@<![=-]\|\W[|&?]\|||\|&&\)\s*\%(#.*\)\=$' + \ '\%(%\@<![({[\\.,:*/%+]\|\<and\|\<or\|\%(<%\)\@<![=-]\|:\@<![^[:alnum:]:][|&?]\|||\|&&\)\s*\%(#.*\)\=$' + +" Regex that defines continuable keywords +let s:continuable_regex = + \ '\C\%(^\s*\|[=,*/%+\-|;{]\|<<\|>>\|:\s\)\s*\zs' . + \ '\<\%(if\|for\|while\|until\|unless\):\@!\>' " Regex that defines bracket continuations let s:bracket_continuation_regex = '%\@<!\%([({[]\)\s*\%(#.*\)\=$' +" Regex that defines dot continuations +let s:dot_continuation_regex = '%\@<!\.\s*\%(#.*\)\=$' + +" Regex that defines backslash continuations +let s:backslash_continuation_regex = '%\@<!\\\s*$' + +" Regex that defines end of bracket continuation followed by another continuation +let s:bracket_switch_continuation_regex = '^\([^(]\+\zs).\+\)\+'.s:continuation_regex + " Regex that defines the first part of a splat pattern let s:splat_regex = '[[,(]\s*\*\s*\%(#.*\)\=$' +" Regex that describes all indent access modifiers +let s:access_modifier_regex = '\C^\s*\%(public\|protected\|private\)\s*\%(#.*\)\=$' + +" Regex that describes the indent access modifiers (excludes public) +let s:indent_access_modifier_regex = '\C^\s*\%(protected\|private\)\s*\%(#.*\)\=$' + " Regex that defines blocks. " " Note that there's a slight problem with this regex and s:continuation_regex. @@ -102,10 +135,13 @@ let s:splat_regex = '[[,(]\s*\*\s*\%(#.*\)\=$' " The reason is that the pipe matches a hanging "|" operator. " let s:block_regex = - \ '\%(\<do:\@!\>\|%\@<!{\)\s*\%(|\s*(*\s*\%([*@&]\=\h\w*,\=\s*\)\%(,\s*(*\s*[*@&]\=\h\w*\s*)*\s*\)*|\)\=\s*\%(#.*\)\=$' + \ '\%(\<do:\@!\>\|%\@<!{\)\s*\%(|[^|]*|\)\=\s*\%(#.*\)\=$' let s:block_continuation_regex = '^\s*[^])}\t ].*'.s:block_regex +" Regex that describes a leading operator (only a method call's dot for now) +let s:leading_operator_regex = '^\s*[.]' + " 2. Auxiliary Functions {{{1 " ====================== @@ -165,7 +201,21 @@ function s:GetMSL(lnum) " Otherwise, terminate search as we have found our MSL already. let line = getline(lnum) - if s:Match(lnum, s:splat_regex) + if !s:Match(msl, s:backslash_continuation_regex) && + \ s:Match(lnum, s:backslash_continuation_regex) + " If the current line doesn't end in a backslash, but the previous one + " does, look for that line's msl + " + " Example: + " foo = "bar" \ + " "baz" + " + let msl = lnum + elseif s:Match(msl, s:leading_operator_regex) + " If the current line starts with a leading operator, keep its indent + " and keep looking for an MSL. + let msl = lnum + elseif s:Match(lnum, s:splat_regex) " If the above line looks like the "*" of a splat, use the current one's " indentation. " @@ -175,7 +225,7 @@ function s:GetMSL(lnum) " something " return msl - elseif s:Match(line, s:non_bracket_continuation_regex) && + elseif s:Match(lnum, s:non_bracket_continuation_regex) && \ s:Match(msl, s:non_bracket_continuation_regex) " If the current line is a non-bracket continuation and so is the " previous one, keep its indent and continue looking for an MSL. @@ -186,6 +236,18 @@ function s:GetMSL(lnum) " three " let msl = lnum + elseif s:Match(lnum, s:dot_continuation_regex) && + \ (s:Match(msl, s:bracket_continuation_regex) || s:Match(msl, s:block_continuation_regex)) + " If the current line is a bracket continuation or a block-starter, but + " the previous is a dot, keep going to see if the previous line is the + " start of another continuation. + " + " Example: + " parent. + " method_call { + " three + " + let msl = lnum elseif s:Match(lnum, s:non_bracket_continuation_regex) && \ (s:Match(msl, s:bracket_continuation_regex) || s:Match(msl, s:block_continuation_regex)) " If the current line is a bracket continuation or a block-starter, but @@ -299,18 +361,39 @@ function s:ExtraBrackets(lnum) endfunction function s:Match(lnum, regex) - let col = match(getline(a:lnum), '\C'.a:regex) + 1 - return col > 0 && !s:IsInStringOrComment(a:lnum, col) ? col : 0 + let line = getline(a:lnum) + let offset = match(line, '\C'.a:regex) + let col = offset + 1 + + while offset > -1 && s:IsInStringOrComment(a:lnum, col) + let offset = match(line, '\C'.a:regex, offset + 1) + let col = offset + 1 + endwhile + + if offset > -1 + return col + else + return 0 + endif endfunction -function s:MatchLast(lnum, regex) - let line = getline(a:lnum) - let col = match(line, '.*\zs' . a:regex) - while col != -1 && s:IsInStringOrComment(a:lnum, col) - let line = strpart(line, 0, col) - let col = match(line, '.*' . a:regex) +" Locates the containing class/module's definition line, ignoring nested classes +" along the way. +" +function! s:FindContainingClass() + let saved_position = getpos('.') + + while searchpair(s:end_start_regex, s:end_middle_regex, s:end_end_regex, 'bW', + \ s:end_skip_expr) > 0 + if expand('<cword>') =~# '\<class\|module\>' + let found_lnum = line('.') + call setpos('.', saved_position) + return found_lnum + endif endwhile - return col + 1 + + call setpos('.', saved_position) + return 0 endfunction " 3. GetRubyIndent Function {{{1 @@ -320,6 +403,9 @@ function GetRubyIndent(...) " 3.1. Setup {{{2 " ---------- + " The value of a single shift-width + let sw = shiftwidth() + " For the current line, use the first argument if given, else v:lnum let clnum = a:0 ? a:1 : v:lnum @@ -333,6 +419,24 @@ function GetRubyIndent(...) let line = getline(clnum) let ind = -1 + " If this line is an access modifier keyword, align according to the closest + " class declaration. + if g:ruby_indent_access_modifier_style == 'indent' + if s:Match(clnum, s:access_modifier_regex) + let class_line = s:FindContainingClass() + if class_line > 0 + return indent(class_line) + sw + endif + endif + elseif g:ruby_indent_access_modifier_style == 'outdent' + if s:Match(clnum, s:access_modifier_regex) + let class_line = s:FindContainingClass() + if class_line > 0 + return indent(class_line) + endif + endif + endif + " If we got a closing bracket on an empty line, find its match and indent " according to it. For parentheses we indent to its column - 1, for the " others we indent to the containing line's MSL's level. Return -1 if fail. @@ -343,7 +447,9 @@ function GetRubyIndent(...) if searchpair(escape(bs[0], '\['), '', bs[1], 'bW', s:skip_expr) > 0 if line[col-1]==')' && col('.') != col('$') - 1 let ind = virtcol('.') - 1 - else + elseif g:ruby_indent_block_style == 'do' + let ind = indent(line('.')) + else " g:ruby_indent_block_style == 'expression' let ind = indent(s:GetMSL(line('.'))) endif endif @@ -366,10 +472,17 @@ function GetRubyIndent(...) if strpart(line, 0, col('.') - 1) =~ '=\s*$' && \ strpart(line, col('.') - 1, 2) !~ 'do' + " assignment to case/begin/etc, on the same line, hanging indent let ind = virtcol('.') - 1 + elseif g:ruby_indent_block_style == 'do' + " align to line of the "do", not to the MSL + let ind = indent(line('.')) elseif getline(msl) =~ '=\s*\(#.*\)\=$' + " in the case of assignment to the MSL, align to the starting line, + " not to the MSL let ind = indent(line('.')) else + " align to the MSL let ind = indent(msl) endif endif @@ -389,6 +502,11 @@ function GetRubyIndent(...) return 0 endif + " If the current line starts with a leading operator, add a level of indent. + if s:Match(clnum, s:leading_operator_regex) + return indent(s:GetMSL(clnum)) + sw + endif + " 3.3. Work on the previous line. {{{2 " ------------------------------- @@ -409,14 +527,50 @@ function GetRubyIndent(...) let line = getline(lnum) let ind = indent(lnum) + if g:ruby_indent_access_modifier_style == 'indent' + " If the previous line was a private/protected keyword, add a + " level of indent. + if s:Match(lnum, s:indent_access_modifier_regex) + return indent(lnum) + sw + endif + elseif g:ruby_indent_access_modifier_style == 'outdent' + " If the previous line was a private/protected/public keyword, add + " a level of indent, since the keyword has been out-dented. + if s:Match(lnum, s:access_modifier_regex) + return indent(lnum) + sw + endif + endif + + if s:Match(lnum, s:continuable_regex) && s:Match(lnum, s:continuation_regex) + return indent(s:GetMSL(lnum)) + sw + sw + endif + " If the previous line ended with a block opening, add a level of indent. if s:Match(lnum, s:block_regex) - return indent(s:GetMSL(lnum)) + &sw + let msl = s:GetMSL(lnum) + + if g:ruby_indent_block_style == 'do' + " don't align to the msl, align to the "do" + let ind = indent(lnum) + sw + elseif getline(msl) =~ '=\s*\(#.*\)\=$' + " in the case of assignment to the msl, align to the starting line, + " not to the msl + let ind = indent(lnum) + sw + else + let ind = indent(msl) + sw + endif + return ind + endif + + " If the previous line started with a leading operator, use its MSL's level + " of indent + if s:Match(lnum, s:leading_operator_regex) + return indent(s:GetMSL(lnum)) endif " If the previous line ended with the "*" of a splat, add a level of indent if line =~ s:splat_regex - return indent(lnum) + &sw + return indent(lnum) + sw endif " If the previous line contained unclosed opening brackets and we are still @@ -431,22 +585,22 @@ function GetRubyIndent(...) if opening.pos != -1 if opening.type == '(' && searchpair('(', '', ')', 'bW', s:skip_expr) > 0 if col('.') + 1 == col('$') - return ind + &sw + return ind + sw else return virtcol('.') endif else let nonspace = matchend(line, '\S', opening.pos + 1) - 1 - return nonspace > 0 ? nonspace : ind + &sw + return nonspace > 0 ? nonspace : ind + sw endif elseif closing.pos != -1 call cursor(lnum, closing.pos + 1) normal! % if s:Match(line('.'), s:ruby_indent_keywords) - return indent('.') + &sw + return indent('.') + sw else - return indent('.') + return indent(s:GetMSL(line('.'))) endif else call cursor(clnum, vcol) @@ -473,7 +627,7 @@ function GetRubyIndent(...) let col = s:Match(lnum, s:ruby_indent_keywords) if col > 0 call cursor(lnum, col) - let ind = virtcol('.') - 1 + &sw + let ind = virtcol('.') - 1 + sw " TODO: make this better (we need to count them) (or, if a searchpair " fails, we know that something is lacking an end and thus we indent a " level @@ -490,10 +644,14 @@ function GetRubyIndent(...) let p_lnum = lnum let lnum = s:GetMSL(lnum) - " If the previous line wasn't a MSL and is continuation return its indent. - " TODO: the || s:IsInString() thing worries me a bit. + " If the previous line wasn't a MSL. if p_lnum != lnum - if s:Match(p_lnum, s:non_bracket_continuation_regex) || s:IsInString(p_lnum,strlen(line)) + " If previous line ends bracket and begins non-bracket continuation decrease indent by 1. + if s:Match(p_lnum, s:bracket_switch_continuation_regex) + return ind - 1 + " If previous line is a continuation return its indent. + " TODO: the || s:IsInString() thing worries me a bit. + elseif s:Match(p_lnum, s:non_bracket_continuation_regex) || s:IsInString(p_lnum,strlen(line)) return ind endif endif @@ -506,9 +664,9 @@ function GetRubyIndent(...) " TODO: this does not take into account contrived things such as " module Foo; class Bar; end if s:Match(lnum, s:ruby_indent_keywords) - let ind = msl_ind + &sw + let ind = msl_ind + sw if s:Match(lnum, s:end_end_regex) - let ind = ind - &sw + let ind = ind - sw endif return ind endif @@ -517,7 +675,7 @@ function GetRubyIndent(...) " closing bracket, indent one extra level. if s:Match(lnum, s:non_bracket_continuation_regex) && !s:Match(lnum, '^\s*\([\])}]\|end\)') if lnum == p_lnum - let ind = msl_ind + &sw + let ind = msl_ind + sw else let ind = msl_ind endif 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/sas.vim b/runtime/indent/sas.vim new file mode 100644 index 0000000000..d591b2796e --- /dev/null +++ b/runtime/indent/sas.vim @@ -0,0 +1,138 @@ +" Vim indent file +" Language: SAS +" Maintainer: Zhen-Huan Hu <wildkeny@gmail.com> +" Version: 3.0.1 +" Last Change: Mar 13, 2017 + +if exists("b:did_indent") + finish +endif +let b:did_indent = 1 + +setlocal indentexpr=GetSASIndent() +setlocal indentkeys+=;,=~data,=~proc,=~macro + +if exists("*GetSASIndent") + finish +endif + +let s:cpo_save = &cpo +set cpo&vim + +" Regex that captures the start of a data/proc section +let s:section_str = '\v%(^|;)\s*%(data|proc)>' +" Regex that captures the end of a run-processing section +let s:section_run = '\v%(^|;)\s*run\s*;' +" Regex that captures the end of a data/proc section +let s:section_end = '\v%(^|;)\s*%(quit|enddata)\s*;' + +" Regex that captures the start of a control block (anything inside a section) +let s:block_str = '\v<%(do>%([^;]+<%(to|over)>[^;]+)=|%(define|layout|method|select)>[^;]+|begingraph)\s*;' +" Regex that captures the end of a control block (anything inside a section) +let s:block_end = '\v<%(end|endlayout|endgraph)\s*;' + +" Regex that captures the start of a macro +let s:macro_str = '\v%(^|;)\s*\%macro>' +" Regex that captures the end of a macro +let s:macro_end = '\v%(^|;)\s*\%mend\s*;' + +" Regex that defines the end of the program +let s:program_end = '\v%(^|;)\s*endsas\s*;' + +" List of procs supporting run-processing +let s:run_processing_procs = [ + \ 'catalog', 'chart', 'datasets', 'document', 'ds2', 'plot', 'sql', + \ 'gareabar', 'gbarline', 'gchart', 'gkpi', 'gmap', 'gplot', 'gradar', 'greplay', 'gslide', 'gtile', + \ 'anova', 'arima', 'catmod', 'factex', 'glm', 'model', 'optex', 'plan', 'reg', + \ 'iml', + \ ] + +" Find the line number of previous keyword defined by the regex +function! s:PrevMatch(lnum, regex) + let prev_lnum = prevnonblank(a:lnum - 1) + while prev_lnum > 0 + let prev_line = getline(prev_lnum) + if prev_line =~ a:regex + break + else + let prev_lnum = prevnonblank(prev_lnum - 1) + endif + endwhile + return prev_lnum +endfunction + +" Main function +function! GetSASIndent() + let prev_lnum = prevnonblank(v:lnum - 1) + if prev_lnum ==# 0 + " Leave the indentation of the first line unchanged + return indent(1) + else + let prev_line = getline(prev_lnum) + " Previous non-blank line contains the start of a macro/section/block + " while not the end of a macro/section/block (at the same line) + if (prev_line =~ s:section_str && prev_line !~ s:section_run && prev_line !~ s:section_end) || + \ (prev_line =~ s:block_str && prev_line !~ s:block_end) || + \ (prev_line =~ s:macro_str && prev_line !~ s:macro_end) + let ind = indent(prev_lnum) + &sts + elseif prev_line =~ s:section_run && prev_line !~ s:section_end + let prev_section_str_lnum = s:PrevMatch(v:lnum, s:section_str) + let prev_section_end_lnum = max([ + \ s:PrevMatch(v:lnum, s:section_end), + \ s:PrevMatch(v:lnum, s:macro_end ), + \ s:PrevMatch(v:lnum, s:program_end)]) + " Check if the section supports run-processing + if prev_section_end_lnum < prev_section_str_lnum && + \ getline(prev_section_str_lnum) =~ '\v%(^|;)\s*proc\s+%(' . + \ join(s:run_processing_procs, '|') . ')>' + let ind = indent(prev_lnum) + &sts + else + let ind = indent(prev_lnum) + endif + else + let ind = indent(prev_lnum) + endif + endif + " Re-adjustments based on the inputs of the current line + let curr_line = getline(v:lnum) + if curr_line =~ s:program_end + " End of the program + " Same indentation as the first non-blank line + return indent(nextnonblank(1)) + elseif curr_line =~ s:macro_end + " Current line is the end of a macro + " Match the indentation of the start of the macro + return indent(s:PrevMatch(v:lnum, s:macro_str)) + elseif curr_line =~ s:block_end && curr_line !~ s:block_str + " Re-adjust if current line is the end of a block + " while not the beginning of a block (at the same line) + " Returning the indent of previous block start directly + " would not work due to nesting + let ind = ind - &sts + elseif curr_line =~ s:section_str || curr_line =~ s:section_run || curr_line =~ s:section_end + " Re-adjust if current line is the start/end of a section + " since the end of a section could be inexplicit + let prev_section_str_lnum = s:PrevMatch(v:lnum, s:section_str) + " Check if the previous section supports run-processing + if getline(prev_section_str_lnum) =~ '\v%(^|;)\s*proc\s+%(' . + \ join(s:run_processing_procs, '|') . ')>' + let prev_section_end_lnum = max([ + \ s:PrevMatch(v:lnum, s:section_end), + \ s:PrevMatch(v:lnum, s:macro_end ), + \ s:PrevMatch(v:lnum, s:program_end)]) + else + let prev_section_end_lnum = max([ + \ s:PrevMatch(v:lnum, s:section_end), + \ s:PrevMatch(v:lnum, s:section_run), + \ s:PrevMatch(v:lnum, s:macro_end ), + \ s:PrevMatch(v:lnum, s:program_end)]) + endif + if prev_section_end_lnum < prev_section_str_lnum + let ind = ind - &sts + endif + endif + return ind +endfunction + +let &cpo = s:cpo_save +unlet s:cpo_save diff --git a/runtime/indent/sass.vim b/runtime/indent/sass.vim index b6e2e66e8a..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: 2013 May 30 +" Last Change: 2017 Jun 13 if exists("b:did_indent") finish @@ -29,9 +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 + &sw - "elseif line =~ s:property && cline !~ s:property - "return indent - &sw + return indent + shiftwidth() else return -1 endif diff --git a/runtime/indent/scala.vim b/runtime/indent/scala.vim new file mode 100644 index 0000000000..6fd8ca9d81 --- /dev/null +++ b/runtime/indent/scala.vim @@ -0,0 +1,609 @@ +" Vim indent file +" Language: Scala (http://scala-lang.org/) +" Original Author: Stefan Matthias Aust +" Modifications By: Derek Wyatt +" URL: https://github.com/derekwyatt/vim-scala +" Last Change: 2016 Aug 26 + +if exists("b:did_indent") + finish +endif +let b:did_indent = 1 + +setlocal autoindent +setlocal indentexpr=GetScalaIndent() +setlocal indentkeys=0{,0},0),!^F,<>>,o,O,e,=case,<CR> + +if exists("*GetScalaIndent") + finish +endif +let s:keepcpo= &cpo +set cpo&vim + +let s:defMatcher = '\%(\%(private\|protected\)\%(\[[^\]]*\]\)\?\s\+\|abstract\s\+\|override\s\+\)*\<def\>' +let s:funcNameMatcher = '\w\+' +let s:typeSpecMatcher = '\%(\s*\[\_[^\]]*\]\)' +let s:defArgMatcher = '\%((\_.\{-})\)' +let s:returnTypeMatcher = '\%(:\s*\w\+' . s:typeSpecMatcher . '\?\)' +let g:fullDefMatcher = '^\s*' . s:defMatcher . '\s\+' . s:funcNameMatcher . '\s*' . s:typeSpecMatcher . '\?\s*' . s:defArgMatcher . '\?\s*' . s:returnTypeMatcher . '\?\s*[={]' + +function! scala#ConditionalConfirm(msg) + if 0 + call confirm(a:msg) + endif +endfunction + +function! scala#GetLine(lnum) + let line = substitute(getline(a:lnum), '//.*$', '', '') + let line = substitute(line, '"\(.\|\\"\)\{-}"', '""', 'g') + return line +endfunction + +function! scala#CountBrackets(line, openBracket, closedBracket) + let line = substitute(a:line, '"\(.\|\\"\)\{-}"', '', 'g') + let open = substitute(line, '[^' . a:openBracket . ']', '', 'g') + let close = substitute(line, '[^' . a:closedBracket . ']', '', 'g') + return strlen(open) - strlen(close) +endfunction + +function! scala#CountParens(line) + return scala#CountBrackets(a:line, '(', ')') +endfunction + +function! scala#CountCurlies(line) + return scala#CountBrackets(a:line, '{', '}') +endfunction + +function! scala#LineEndsInIncomplete(line) + if a:line =~ '[.,]\s*$' + return 1 + else + return 0 + endif +endfunction + +function! scala#LineIsAClosingXML(line) + if a:line =~ '^\s*</\w' + return 1 + else + return 0 + endif +endfunction + +function! scala#LineCompletesXML(lnum, line) + let savedpos = getpos('.') + call setpos('.', [savedpos[0], a:lnum, 0, savedpos[3]]) + let tag = substitute(a:line, '^.*</\([^>]*\)>.*$', '\1', '') + let [lineNum, colnum] = searchpairpos('<' . tag . '>', '', '</' . tag . '>', 'Wbn') + call setpos('.', savedpos) + let pline = scala#GetLine(prevnonblank(lineNum - 1)) + if pline =~ '=\s*$' + return 1 + else + return 0 + endif +endfunction + +function! scala#IsParentCase() + let savedpos = getpos('.') + call setpos('.', [savedpos[0], savedpos[1], 0, savedpos[3]]) + let [l, c] = searchpos('^\s*\%(' . s:defMatcher . '\|\%(\<case\>\)\)', 'bnW') + let retvalue = -1 + if l != 0 && search('\%' . l . 'l\s*\<case\>', 'bnW') + let retvalue = l + endif + call setpos('.', savedpos) + return retvalue +endfunction + +function! scala#CurlyMatcher() + let matchline = scala#GetLineThatMatchesBracket('{', '}') + if scala#CountParens(scala#GetLine(matchline)) < 0 + let savedpos = getpos('.') + call setpos('.', [savedpos[0], matchline, 9999, savedpos[3]]) + call searchpos('{', 'Wbc') + call searchpos(')', 'Wb') + let [lnum, colnum] = searchpairpos('(', '', ')', 'Wbn') + call setpos('.', savedpos) + let line = scala#GetLine(lnum) + if line =~ '^\s*' . s:defMatcher + return lnum + else + return matchline + endif + else + return matchline + endif +endfunction + +function! scala#GetLineAndColumnThatMatchesCurly() + return scala#GetLineAndColumnThatMatchesBracket('{', '}') +endfunction + +function! scala#GetLineAndColumnThatMatchesParen() + return scala#GetLineAndColumnThatMatchesBracket('(', ')') +endfunction + +function! scala#GetLineAndColumnThatMatchesBracket(openBracket, closedBracket) + let savedpos = getpos('.') + let curline = scala#GetLine(line('.')) + if curline =~ a:closedBracket . '.*' . a:openBracket . '.*' . a:closedBracket + call setpos('.', [savedpos[0], savedpos[1], 0, savedpos[3]]) + call searchpos(a:closedBracket . '\ze[^' . a:closedBracket . a:openBracket . ']*' . a:openBracket, 'W') + else + call setpos('.', [savedpos[0], savedpos[1], 9999, savedpos[3]]) + call searchpos(a:closedBracket, 'Wbc') + endif + let [lnum, colnum] = searchpairpos(a:openBracket, '', a:closedBracket, 'Wbn') + call setpos('.', savedpos) + return [lnum, colnum] +endfunction + +function! scala#GetLineThatMatchesCurly() + return scala#GetLineThatMatchesBracket('{', '}') +endfunction + +function! scala#GetLineThatMatchesParen() + return scala#GetLineThatMatchesBracket('(', ')') +endfunction + +function! scala#GetLineThatMatchesBracket(openBracket, closedBracket) + let [lnum, colnum] = scala#GetLineAndColumnThatMatchesBracket(a:openBracket, a:closedBracket) + return lnum +endfunction + +function! scala#NumberOfBraceGroups(line) + let line = substitute(a:line, '[^()]', '', 'g') + if strlen(line) == 0 + return 0 + endif + let line = substitute(line, '^)*', '', 'g') + if strlen(line) == 0 + return 0 + endif + let line = substitute(line, '^(', '', 'g') + if strlen(line) == 0 + return 0 + endif + let c = 1 + let counter = 0 + let groupCount = 0 + while counter < strlen(line) + let char = strpart(line, counter, 1) + if char == '(' + let c = c + 1 + elseif char == ')' + let c = c - 1 + endif + if c == 0 + let groupCount = groupCount + 1 + endif + let counter = counter + 1 + endwhile + return groupCount +endfunction + +function! scala#MatchesIncompleteDefValr(line) + if a:line =~ '^\s*\%(' . s:defMatcher . '\|\<va[lr]\>\).*[=({]\s*$' + return 1 + else + return 0 + endif +endfunction + +function! scala#LineIsCompleteIf(line) + if scala#CountBrackets(a:line, '{', '}') == 0 && + \ scala#CountBrackets(a:line, '(', ')') == 0 && + \ a:line =~ '^\s*\<if\>\s*([^)]*)\s*\S.*$' + return 1 + else + return 0 + endif +endfunction + +function! scala#LineCompletesIfElse(lnum, line) + if a:line =~ '^\s*\%(\<if\>\|\%(}\s*\)\?\<else\>\)' + return 0 + endif + let result = search('^\%(\s*\<if\>\s*(.*).*\n\|\s*\<if\>\s*(.*)\s*\n.*\n\)\%(\s*\<else\>\s*\<if\>\s*(.*)\s*\n.*\n\)*\%(\s*\<else\>\s*\n\|\s*\<else\>[^{]*\n\)\?\%' . a:lnum . 'l', 'Wbn') + if result != 0 && scala#GetLine(prevnonblank(a:lnum - 1)) !~ '{\s*$' + return result + endif + return 0 +endfunction + +function! scala#GetPrevCodeLine(lnum) + " This needs to skip comment lines + return prevnonblank(a:lnum - 1) +endfunction + +function! scala#InvertBracketType(openBracket, closedBracket) + if a:openBracket == '(' + return [ '{', '}' ] + else + return [ '(', ')' ] + endif +endfunction + +function! scala#Testhelper(lnum, line, openBracket, closedBracket, iteration) + let bracketCount = scala#CountBrackets(a:line, a:openBracket, a:closedBracket) + " There are more '}' braces than '{' on this line so it may be completing the function definition + if bracketCount < 0 + let [matchedLNum, matchedColNum] = scala#GetLineAndColumnThatMatchesBracket(a:openBracket, a:closedBracket) + if matchedLNum == a:lnum + return -1 + endif + let matchedLine = scala#GetLine(matchedLNum) + if ! scala#MatchesIncompleteDefValr(matchedLine) + let bracketLine = substitute(substitute(matchedLine, '\%' . matchedColNum . 'c.*$', '', ''), '[^{}()]', '', 'g') + if bracketLine =~ '}$' + return scala#Testhelper(matchedLNum, matchedLine, '{', '}', a:iteration + 1) + elseif bracketLine =~ ')$' + return scala#Testhelper(matchedLNum, matchedLine, '(', ')', a:iteration + 1) + else + let prevCodeLNum = scala#GetPrevCodeLine(matchedLNum) + if scala#MatchesIncompleteDefValr(scala#GetLine(prevCodeLNum)) + return prevCodeLNum + else + return -1 + endif + endif + else + " return indent value instead + return matchedLNum + endif + " There's an equal number of '{' and '}' on this line so it may be a single line function definition + elseif bracketCount == 0 + if a:iteration == 0 + let otherBracketType = scala#InvertBracketType(a:openBracket, a:closedBracket) + return scala#Testhelper(a:lnum, a:line, otherBracketType[0], otherBracketType[1], a:iteration + 1) + else + let prevCodeLNum = scala#GetPrevCodeLine(a:lnum) + let prevCodeLine = scala#GetLine(prevCodeLNum) + if scala#MatchesIncompleteDefValr(prevCodeLine) && prevCodeLine !~ '{\s*$' + return prevCodeLNum + else + let possibleIfElse = scala#LineCompletesIfElse(a:lnum, a:line) + if possibleIfElse != 0 + let defValrLine = prevnonblank(possibleIfElse - 1) + let possibleDefValr = scala#GetLine(defValrLine) + if scala#MatchesIncompleteDefValr(possibleDefValr) && possibleDefValr =~ '^.*=\s*$' + return possibleDefValr + else + return -1 + endif + else + return -1 + endif + endif + endif + else + return -1 + endif +endfunction + +function! scala#Test(lnum, line, openBracket, closedBracket) + return scala#Testhelper(a:lnum, a:line, a:openBracket, a:closedBracket, 0) +endfunction + +function! scala#LineCompletesDefValr(lnum, line) + let bracketCount = scala#CountBrackets(a:line, '{', '}') + if bracketCount < 0 + let matchedBracket = scala#GetLineThatMatchesBracket('{', '}') + if ! scala#MatchesIncompleteDefValr(scala#GetLine(matchedBracket)) + let possibleDefValr = scala#GetLine(prevnonblank(matchedBracket - 1)) + if matchedBracket != -1 && scala#MatchesIncompleteDefValr(possibleDefValr) + return 1 + else + return 0 + endif + else + return 0 + endif + elseif bracketCount == 0 + let bracketCount = scala#CountBrackets(a:line, '(', ')') + if bracketCount < 0 + let matchedBracket = scala#GetLineThatMatchesBracket('(', ')') + if ! scala#MatchesIncompleteDefValr(scala#GetLine(matchedBracket)) + let possibleDefValr = scala#GetLine(prevnonblank(matchedBracket - 1)) + if matchedBracket != -1 && scala#MatchesIncompleteDefValr(possibleDefValr) + return 1 + else + return 0 + endif + else + return 0 + endif + elseif bracketCount == 0 + let possibleDefValr = scala#GetLine(prevnonblank(a:lnum - 1)) + if scala#MatchesIncompleteDefValr(possibleDefValr) && possibleDefValr =~ '^.*=\s*$' + return 1 + else + let possibleIfElse = scala#LineCompletesIfElse(a:lnum, a:line) + if possibleIfElse != 0 + let possibleDefValr = scala#GetLine(prevnonblank(possibleIfElse - 1)) + if scala#MatchesIncompleteDefValr(possibleDefValr) && possibleDefValr =~ '^.*=\s*$' + return 2 + else + return 0 + endif + else + return 0 + endif + endif + else + return 0 + endif + endif +endfunction + +function! scala#SpecificLineCompletesBrackets(lnum, openBracket, closedBracket) + let savedpos = getpos('.') + call setpos('.', [savedpos[0], a:lnum, 9999, savedpos[3]]) + let retv = scala#LineCompletesBrackets(a:openBracket, a:closedBracket) + call setpos('.', savedpos) + + return retv +endfunction + +function! scala#LineCompletesBrackets(openBracket, closedBracket) + let savedpos = getpos('.') + let offline = 0 + while offline == 0 + let [lnum, colnum] = searchpos(a:closedBracket, 'Wb') + let [lnumA, colnumA] = searchpairpos(a:openBracket, '', a:closedBracket, 'Wbn') + if lnum != lnumA + let [lnumB, colnumB] = searchpairpos(a:openBracket, '', a:closedBracket, 'Wbnr') + let offline = 1 + endif + endwhile + call setpos('.', savedpos) + if lnumA == lnumB && colnumA == colnumB + return lnumA + else + return -1 + endif +endfunction + +function! GetScalaIndent() + " Find a non-blank line above the current line. + let prevlnum = prevnonblank(v:lnum - 1) + + " Hit the start of the file, use zero indent. + if prevlnum == 0 + return 0 + endif + + let ind = indent(prevlnum) + let originalIndentValue = ind + let prevline = scala#GetLine(prevlnum) + let curlnum = v:lnum + let curline = scala#GetLine(curlnum) + if get(g:, 'scala_scaladoc_indent', 0) + let star_indent = 2 + else + let star_indent = 1 + end + + if prevline =~ '^\s*/\*\*' + if prevline =~ '\*/\s*$' + return ind + else + return ind + star_indent + endif + endif + + if curline =~ '^\s*\*' + return cindent(curlnum) + endif + + " If this line starts with a { then make it indent the same as the previous line + if curline =~ '^\s*{' + call scala#ConditionalConfirm("1") + " Unless, of course, the previous one is a { as well + if prevline !~ '^\s*{' + call scala#ConditionalConfirm("2") + return indent(prevlnum) + endif + endif + + " '.' continuations + if curline =~ '^\s*\.' + if prevline =~ '^\s*\.' + return ind + else + return ind + shiftwidth() + endif + endif + + " Indent html literals + if prevline !~ '/>\s*$' && prevline =~ '^\s*<[a-zA-Z][^>]*>\s*$' + call scala#ConditionalConfirm("3") + return ind + shiftwidth() + endif + + " assumes curly braces around try-block + if curline =~ '^\s*}\s*\<catch\>' + return ind - shiftwidth() + elseif curline =~ '^\s*\<catch\>' + return ind + endif + + " Add a shiftwidth()' after lines that start a block + " If 'if', 'for' or 'while' end with ), this is a one-line block + " If 'val', 'var', 'def' end with =, this is a one-line block + if (prevline =~ '^\s*\<\%(\%(}\?\s*else\s\+\)\?if\|for\|while\)\>.*[)=]\s*$' && scala#NumberOfBraceGroups(prevline) <= 1) + \ || prevline =~ '^\s*' . s:defMatcher . '.*=\s*$' + \ || prevline =~ '^\s*\<va[lr]\>.*[=]\s*$' + \ || prevline =~ '^\s*\%(}\s*\)\?\<else\>\s*$' + \ || prevline =~ '=\s*$' + call scala#ConditionalConfirm("4") + let ind = ind + shiftwidth() + elseif prevline =~ '^\s*\<\%(}\?\s*else\s\+\)\?if\>' && curline =~ '^\s*}\?\s*\<else\>' + return ind + endif + + let lineCompletedBrackets = 0 + let bracketCount = scala#CountBrackets(prevline, '{', '}') + if bracketCount > 0 || prevline =~ '.*{\s*$' + call scala#ConditionalConfirm("5b") + let ind = ind + shiftwidth() + elseif bracketCount < 0 + call scala#ConditionalConfirm("6b") + " if the closing brace actually completes the braces entirely, then we + " have to indent to line that started the whole thing + let completeLine = scala#LineCompletesBrackets('{', '}') + if completeLine != -1 + call scala#ConditionalConfirm("8b") + let prevCompleteLine = scala#GetLine(prevnonblank(completeLine - 1)) + " However, what actually started this part looks like it was a function + " definition, so we need to indent to that line instead. This is + " actually pretty weak at the moment. + if prevCompleteLine =~ '=\s*$' + call scala#ConditionalConfirm("9b") + let ind = indent(prevnonblank(completeLine - 1)) + else + call scala#ConditionalConfirm("10b") + let ind = indent(completeLine) + endif + else + let lineCompletedBrackets = 1 + endif + endif + + if ind == originalIndentValue + let bracketCount = scala#CountBrackets(prevline, '(', ')') + if bracketCount > 0 || prevline =~ '.*(\s*$' + call scala#ConditionalConfirm("5a") + let ind = ind + shiftwidth() + elseif bracketCount < 0 + call scala#ConditionalConfirm("6a") + " if the closing brace actually completes the braces entirely, then we + " have to indent to line that started the whole thing + let completeLine = scala#LineCompletesBrackets('(', ')') + if completeLine != -1 && prevline !~ '^.*{\s*$' + call scala#ConditionalConfirm("8a") + let prevCompleteLine = scala#GetLine(prevnonblank(completeLine - 1)) + " However, what actually started this part looks like it was a function + " definition, so we need to indent to that line instead. This is + " actually pretty weak at the moment. + if prevCompleteLine =~ '=\s*$' + call scala#ConditionalConfirm("9a") + let ind = indent(prevnonblank(completeLine - 1)) + else + call scala#ConditionalConfirm("10a") + let ind = indent(completeLine) + endif + else + " This is the only part that's different from from the '{', '}' one below + " Yup... some refactoring is necessary at some point. + let ind = ind + (bracketCount * shiftwidth()) + let lineCompletedBrackets = 1 + endif + endif + endif + + if curline =~ '^\s*}\?\s*\<else\>\%(\s\+\<if\>\s*(.*)\)\?\s*{\?\s*$' && + \ ! scala#LineIsCompleteIf(prevline) && + \ prevline !~ '^.*}\s*$' + let ind = ind - shiftwidth() + endif + + " Subtract a shiftwidth()' on '}' or html + let curCurlyCount = scala#CountCurlies(curline) + if curCurlyCount < 0 + call scala#ConditionalConfirm("14a") + let matchline = scala#CurlyMatcher() + return indent(matchline) + elseif curline =~ '^\s*</[a-zA-Z][^>]*>' + call scala#ConditionalConfirm("14c") + return ind - shiftwidth() + endif + + let prevParenCount = scala#CountParens(prevline) + if prevline =~ '^\s*\<for\>.*$' && prevParenCount > 0 + call scala#ConditionalConfirm("15") + let ind = indent(prevlnum) + 5 + endif + + let prevCurlyCount = scala#CountCurlies(prevline) + if prevCurlyCount == 0 && prevline =~ '^.*\%(=>\|⇒\)\s*$' && prevline !~ '^\s*this\s*:.*\%(=>\|⇒\)\s*$' && curline !~ '^\s*\<case\>' + call scala#ConditionalConfirm("16") + let ind = ind + shiftwidth() + endif + + if ind == originalIndentValue && curline =~ '^\s*\<case\>' + call scala#ConditionalConfirm("17") + let parentCase = scala#IsParentCase() + if parentCase != -1 + call scala#ConditionalConfirm("17a") + return indent(parentCase) + endif + endif + + if prevline =~ '^\s*\*/' + \ || prevline =~ '*/\s*$' + call scala#ConditionalConfirm("18") + let ind = ind - star_indent + endif + + if scala#LineEndsInIncomplete(prevline) + call scala#ConditionalConfirm("19") + return ind + endif + + if scala#LineIsAClosingXML(prevline) + if scala#LineCompletesXML(prevlnum, prevline) + call scala#ConditionalConfirm("20a") + return ind - shiftwidth() + else + call scala#ConditionalConfirm("20b") + return ind + endif + endif + + if ind == originalIndentValue + "let indentMultiplier = scala#LineCompletesDefValr(prevlnum, prevline) + "if indentMultiplier != 0 + " call scala#ConditionalConfirm("19a") + " let ind = ind - (indentMultiplier * shiftwidth()) + let defValrLine = scala#Test(prevlnum, prevline, '{', '}') + if defValrLine != -1 + call scala#ConditionalConfirm("21a") + let ind = indent(defValrLine) + elseif lineCompletedBrackets == 0 + call scala#ConditionalConfirm("21b") + if scala#GetLine(prevnonblank(prevlnum - 1)) =~ '^.*\<else\>\s*\%(//.*\)\?$' + call scala#ConditionalConfirm("21c") + let ind = ind - shiftwidth() + elseif scala#LineCompletesIfElse(prevlnum, prevline) + call scala#ConditionalConfirm("21d") + let ind = ind - shiftwidth() + elseif scala#CountParens(curline) < 0 && curline =~ '^\s*)' && scala#GetLine(scala#GetLineThatMatchesBracket('(', ')')) =~ '.*(\s*$' + " Handles situations that look like this: + " + " val a = func( + " 10 + " ) + " + " or + " + " val a = func( + " 10 + " ).somethingHere() + call scala#ConditionalConfirm("21e") + let ind = ind - shiftwidth() + endif + endif + endif + + call scala#ConditionalConfirm("returning " . ind) + + return ind +endfunction + +let &cpo = s:keepcpo +unlet s:keepcpo + +" vim:set sw=2 sts=2 ts=8 et: +" vim600:fdm=marker fdl=1 fdc=0: 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..fd9a6a9c92 100644 --- a/runtime/indent/sh.vim +++ b/runtime/indent/sh.vim @@ -3,10 +3,13 @@ " 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-08-08 " License: Vim (see :h license) " Repository: https://github.com/chrisbra/vim-sh-indent " Changelog: +" 20170808: - better indent of line continuation +" 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 +36,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,13 +109,17 @@ 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 endfunction function! s:is_continuation_line(line) - return a:line =~ '\%(\%(^\|[^\\]\)\\\|&&\|||\)$' + return a:line =~ '\%(\%(^\|[^\\]\)\\\|&&\|||\||\)' . + \ '\s*\({\s*\)\=\(#.*\)\=$' endfunction function! s:find_continued_lnum(lnum) 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/tcl.vim b/runtime/indent/tcl.vim index a92f57d67d..e9d61e4366 100644 --- a/runtime/indent/tcl.vim +++ b/runtime/indent/tcl.vim @@ -56,7 +56,7 @@ function GetTclIndent() if line =~ '^\s*\*' return cindent(v:lnum) elseif line =~ '^\s*}' - return indent(v:lnum) - &sw + return indent(v:lnum) - shiftwidth() endif let pnum = s:prevnonblanknoncomment(v:lnum - 1) @@ -64,11 +64,11 @@ function GetTclIndent() return 0 endif - let ind = indent(pnum) + s:count_braces(pnum, 1) * &sw + let ind = indent(pnum) + s:count_braces(pnum, 1) * shiftwidth() let pline = getline(pnum) if pline =~ '}\s*$' - let ind -= (s:count_braces(pnum, 0) - (pline =~ '^\s*}' ? 1 : 0)) * &sw + let ind -= (s:count_braces(pnum, 0) - (pline =~ '^\s*}' ? 1 : 0)) * shiftwidth() endif return ind diff --git a/runtime/indent/tcsh.vim b/runtime/indent/tcsh.vim index 59a9d56f44..ed08e6c6e2 100644 --- a/runtime/indent/tcsh.vim +++ b/runtime/indent/tcsh.vim @@ -32,17 +32,17 @@ function TcshGetIndent() let ind = indent(lnum) let line = getline(lnum) if line =~ '\v^\s*%(while|foreach)>|^\s*%(case\s.*:|default:|else)\s*$|%(<then|\\)$' - let ind = ind + &sw + let ind = ind + shiftwidth() endif if line =~ '\v^\s*breaksw>' - let ind = ind - &sw + let ind = ind - shiftwidth() endif " Subtract indent if current line has on end, endif, case commands let line = getline(v:lnum) if line =~ '\v^\s*%(else|end|endif)\s*$' - let ind = ind - &sw + let ind = ind - shiftwidth() endif return ind diff --git a/runtime/indent/teraterm.vim b/runtime/indent/teraterm.vim index ba24257b02..370283c77f 100644 --- a/runtime/indent/teraterm.vim +++ b/runtime/indent/teraterm.vim @@ -1,9 +1,9 @@ " Vim indent file " Language: Tera Term Language (TTL) -" Based on Tera Term Version 4.86 +" Based on Tera Term Version 4.92 " Maintainer: Ken Takata " URL: https://github.com/k-takata/vim-teraterm -" Last Change: 2015 Jun 4 +" Last Change: 2017 Jun 13 " Filenames: *.ttl " License: VIM License @@ -22,18 +22,6 @@ if exists("*GetTeraTermIndent") 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! GetTeraTermIndent(lnum) let l:prevlnum = prevnonblank(a:lnum-1) if l:prevlnum == 0 @@ -48,17 +36,17 @@ function! GetTeraTermIndent(lnum) let l:ind = l:previ - if l:prevl =~ '^\s*if\>.*\<then\s*$' + 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/tf.vim b/runtime/indent/tf.vim index 17597734b8..a980538506 100644 --- a/runtime/indent/tf.vim +++ b/runtime/indent/tf.vim @@ -1,8 +1,8 @@ " Vim indent file " Language: tf (TinyFugue) " Maintainer: Christian J. Robinson <heptite@gmail.com> -" URL: http://christianrobinson.name/vim/indent/tf.vim -" Last Change: 2002 May 29 +" URL: http://www.vim.org/scripts/script.php?script_id=174 +" Last Change: 2017 Feb 25 " Only load this indent file when no other was loaded. if exists("b:did_indent") @@ -38,14 +38,14 @@ function GetTFIndent() endif if line =~ '\(/def.*\\\|/for.*\(%;\s*\)\@\<!\\\)$' - let ind = ind + &sw + let ind = ind + shiftwidth() elseif line =~ '\(/if\|/else\|/then\)' if line !~ '/endif' - let ind = ind + &sw + let ind = ind + shiftwidth() endif elseif line =~ '/while' if line !~ '/done' - let ind = ind + &sw + let ind = ind + shiftwidth() endif endif @@ -53,11 +53,11 @@ function GetTFIndent() if line =~ '\(/else\|/endif\|/then\)' if line !~ '/if' - let ind = ind - &sw + let ind = ind - shiftwidth() endif elseif line =~ '/done' if line !~ '/while' - let ind = ind - &sw + let ind = ind - shiftwidth() endif endif 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/treetop.vim b/runtime/indent/treetop.vim index a2af78b8c2..2c6eecf5c4 100644 --- a/runtime/indent/treetop.vim +++ b/runtime/indent/treetop.vim @@ -1,7 +1,7 @@ " Vim indent file -" Language: Treetop -" Maintainer: Nikolai Weibull <now@bitwi.se> -" Latest Revision: 2011-03-14 +" Language: Treetop +" Previous Maintainer: Nikolai Weibull <now@bitwi.se> +" Latest Revision: 2011-03-14 if exists("b:did_indent") finish @@ -26,12 +26,12 @@ function GetTreetopIndent() let line = getline(pnum) if line =~ '^\s*\%(grammar\|module\|rule\)\>' - let ind += &sw + let ind += shiftwidth() endif let line = getline(v:lnum) if line =~ '^\s*end\>' - let ind -= &sw + let ind -= shiftwidth() end retur ind 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/verilog.vim b/runtime/indent/verilog.vim index ecca462636..ab3d0ba3e0 100644 --- a/runtime/indent/verilog.vim +++ b/runtime/indent/verilog.vim @@ -1,10 +1,12 @@ " Language: Verilog HDL -" Maintainer: Chih-Tsun Huang <cthuang@larc.ee.nthu.edu.tw> -" Last Change: 2011 Dec 10 by Thilo Six -" URL: http://larc.ee.nthu.edu.tw/~cthuang/vim/indent/verilog.vim +" Maintainer: Chih-Tsun Huang <cthuang@cs.nthu.edu.tw> +" Last Change: 2017 Aug 25 by Chih-Tsun Huang +" URL: http://www.cs.nthu.edu.tw/~cthuang/vim/indent/verilog.vim " " Credits: " Suggestions for improvement, bug reports by +" Takuya Fujiwara <tyru.exe@gmail.com> +" Thilo Six <debian@Xk2c.de> " Leo Butlero <lbutler@brocade.com> " " Buffer Variables: @@ -23,7 +25,8 @@ let b:did_indent = 1 setlocal indentexpr=GetVerilogIndent() setlocal indentkeys=!^F,o,O,0),=begin,=end,=join,=endcase setlocal indentkeys+==endmodule,=endfunction,=endtask,=endspecify -setlocal indentkeys+==`else,=`endif +setlocal indentkeys+==endconfig,=endgenerate,=endprimitive,=endtable +setlocal indentkeys+==`else,=`elsif,=`endif " Only define the function once. if exists("*GetVerilogIndent") @@ -38,7 +41,7 @@ function GetVerilogIndent() if exists('b:verilog_indent_width') let offset = b:verilog_indent_width else - let offset = &sw + let offset = shiftwidth() endif if exists('b:verilog_indent_modules') let indent_modules = offset @@ -82,7 +85,9 @@ function GetVerilogIndent() endif " Indent after if/else/for/case/always/initial/specify/fork blocks - elseif last_line =~ '`\@<!\<\(if\|else\)\>' || + " Note: We exclude '`if' or '`else' and consider 'end else' + " 'end if' is redundant here + elseif last_line =~ '^\s*\(end\)\=\s*`\@<!\<\(if\|else\)\>' || \ last_line =~ '^\s*\<\(for\|case\%[[zx]]\)\>' || \ last_line =~ '^\s*\<\(always\|initial\)\>' || \ last_line =~ '^\s*\<\(specify\|fork\)\>' @@ -91,8 +96,8 @@ function GetVerilogIndent() let ind = ind + offset if vverb | echo vverb_str "Indent after a block statement." | endif endif - " Indent after function/task blocks - elseif last_line =~ '^\s*\<\(function\|task\)\>' + " Indent after function/task/config/generate/primitive/table blocks + elseif last_line =~ '^\s*\<\(function\|task\|config\|generate\|primitive\|table\)\>' if last_line !~ '\<end\>\s*' . vlog_comment . '*$' || \ last_line =~ '\(//\|/\*\).*\(;\|\<end\>\)\s*' . vlog_comment . '*$' let ind = ind + offset @@ -159,11 +164,11 @@ function GetVerilogIndent() let ind = ind - offset if vverb | echo vverb_str "De-indent after a close statement." | endif - " `ifdef and `else - elseif last_line =~ '^\s*`\<\(ifdef\|else\)\>' + " `ifdef or `ifndef or `elsif or `else + elseif last_line =~ '^\s*`\<\(ifn\?def\|elsif\|else\)\>' let ind = ind + offset if vverb - echo vverb_str "Indent after a `ifdef or `else statement." + echo vverb_str "Indent after a `ifdef or `ifndef or `elsif or `else statement." endif endif @@ -173,7 +178,8 @@ function GetVerilogIndent() " De-indent on the end of the block " join/end/endcase/endfunction/endtask/endspecify if curr_line =~ '^\s*\<\(join\|end\|endcase\)\>' || - \ curr_line =~ '^\s*\<\(endfunction\|endtask\|endspecify\)\>' + \ curr_line =~ '^\s*\<\(endfunction\|endtask\|endspecify\)\>' || + \ curr_line =~ '^\s*\<\(endconfig\|endgenerate\|endprimitive\|endtable\)\>' let ind = ind - offset if vverb | echo vverb_str "De-indent the end of a block." | endif elseif curr_line =~ '^\s*\<endmodule\>' @@ -184,7 +190,7 @@ function GetVerilogIndent() " De-indent on a stand-alone 'begin' elseif curr_line =~ '^\s*\<begin\>' - if last_line !~ '^\s*\<\(function\|task\|specify\|module\)\>' && + if last_line !~ '^\s*\<\(function\|task\|specify\|module\|config\|generate\|primitive\|table\)\>' && \ last_line !~ '^\s*\()*\s*;\|)\+\)\s*' . vlog_comment . '*$' && \ ( last_line =~ \ '\<\(`\@<!if\|`\@<!else\|for\|case\%[[zx]]\|always\|initial\)\>' || @@ -206,10 +212,10 @@ function GetVerilogIndent() echo vverb_str "De-indent the end of a multiple statement." endif - " De-indent `else and `endif - elseif curr_line =~ '^\s*`\<\(else\|endif\)\>' + " De-indent `elsif or `else or `endif + elseif curr_line =~ '^\s*`\<\(elsif\|else\|endif\)\>' let ind = ind - offset - if vverb | echo vverb_str "De-indent `else and `endif statement." | endif + if vverb | echo vverb_str "De-indent `elsif or `else or `endif statement." | endif endif diff --git a/runtime/indent/vhdl.vim b/runtime/indent/vhdl.vim index 6982859670..ad318066f4 100644 --- a/runtime/indent/vhdl.vim +++ b/runtime/indent/vhdl.vim @@ -1,8 +1,8 @@ " VHDL indent ('93 syntax) " Language: VHDL " Maintainer: Gerald Lai <laigera+vim?gmail.com> -" Version: 1.60 -" Last Change: 2016 Feb 26 +" Version: 1.62 +" Last Change: 2017 Oct 17 " 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,16 +407,17 @@ 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 " **************************************************************************************** " indent: maintain indent of previous opening statement - " keywords: without "procedure", "generic", "map", "port" + ":" but not ":=" + eventually ;$ + " keywords: without "procedure", "generic", "map", "port" + ":" but not ":=" + "in", "out", "inout", "buffer", "linkage", variable & ":=" " where: start of current line - if curs =~? '^\s*\%(\<\%(procedure\|generic\|map\|port\)\>.*\)\@<!\w\+\s*\w*\s*:[^=].*;.*$' + if curs =~? '^\s*\%(\<\%(procedure\|generic\|map\|port\)\>.*\)\@<!\w\+\s*\w*\s*:[^=]\@=\s*\%(\%(in\|out\|inout\|buffer\|linkage\)\>\|\w\+\s\+:=\)' return ind2 endif + " **************************************************************************************** " indent: maintain indent of previous opening statement, corner case which " does not end in ;, but is part of a mapping @@ -424,10 +425,10 @@ function GetVHDLindent() " prevline without "procedure", "generic", "map", "port" + ":" but not ":=" + eventually ;$ " where: start of current line if curs =~? '^\s*\%(\<\%(procedure\|generic\|map\|port\)\>.*\)\@<!\w\+\s*\w*\s*:[^=].*[^;].*$' - if prevs =~? '^\s*\%(\<\%(procedure\|generic\|map\|port\)\>.*\)\@<!\w\+\s*\w*\s*:[^=].*;.*$' - return ind2 - endif - endif + if prevs =~? '^\s*\%(\<\%(procedure\|generic\|map\|port\)\>.*\)\@<!\w\+\s*\w*\s*:[^=].*;.*$' + return ind2 + endif + endif " return leftover filtered indent return ind diff --git a/runtime/indent/xf86conf.vim b/runtime/indent/xf86conf.vim index 4174a24224..5a8bc0fec1 100644 --- a/runtime/indent/xf86conf.vim +++ b/runtime/indent/xf86conf.vim @@ -1,7 +1,7 @@ " Vim indent file -" Language: XFree86 Configuration File -" Maintainer: Nikolai Weibull <now@bitwi.se> -" Latest Revision: 2006-12-20 +" Language: XFree86 Configuration File +" Previous Maintainer: Nikolai Weibull <now@bitwi.se> +" Latest Revision: 2006-12-20 if exists("b:did_indent") finish @@ -26,11 +26,11 @@ function GetXF86ConfIndent() let ind = indent(lnum) if getline(lnum) =~? '^\s*\(Sub\)\=Section\>' - let ind = ind + &sw + let ind = ind + shiftwidth() endif if getline(v:lnum) =~? '^\s*End\(Sub\)\=Section\>' - let ind = ind - &sw + let ind = ind - shiftwidth() endif return ind diff --git a/runtime/indent/xinetd.vim b/runtime/indent/xinetd.vim index c8127237e8..977ee3d33b 100644 --- a/runtime/indent/xinetd.vim +++ b/runtime/indent/xinetd.vim @@ -1,7 +1,7 @@ " Vim indent file -" Language: xinetd.conf(5) configuration file -" Maintainer: Nikolai Weibull <now@bitwi.se> -" Latest Revision: 2006-12-20 +" Language: xinetd.conf(5) configuration file +" Previous Maintainer: Nikolai Weibull <now@bitwi.se> +" Latest Revision: 2006-12-20 if exists("b:did_indent") finish @@ -47,8 +47,8 @@ function GetXinetdIndent() return 0 endif - return indent(pnum) + s:count_braces(pnum, 1) * &sw - \ - s:count_braces(v:lnum, 0) * &sw + return indent(pnum) + s:count_braces(pnum, 1) * shiftwidth() + \ - s:count_braces(v:lnum, 0) * shiftwidth() endfunction let &cpo = s:keepcpo 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/yacc.vim b/runtime/indent/yacc.vim index 2ab7d7b38c..01ad4fc56d 100644 --- a/runtime/indent/yacc.vim +++ b/runtime/indent/yacc.vim @@ -1,7 +1,7 @@ " Vim indent file -" Language: YACC input file -" Maintainer: Nikolai Weibull <now@bitwi.se> -" Latest Revision: 2006-12-20 +" Language: YACC input file +" Previous Maintainer: Nikolai Weibull <now@bitwi.se> +" Latest Revision: 2006-12-20 " Only load this indent file when no other was loaded. if exists("b:did_indent") diff --git a/runtime/indent/yaml.vim b/runtime/indent/yaml.vim index aa4906ce0a..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,20 +24,12 @@ 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) while prevlnum \&& indent(prevlnum) >= curindent - \&& getline(prevlnum) !~# '^\s*#' + \&& getline(prevlnum) =~# '^\s*#' let prevlnum = prevnonblank(prevlnum-1) endwhile return prevlnum @@ -51,11 +43,33 @@ function s:FindPrevLEIndentedLineMatchingRegex(lnum, regex) return plilnum endfunction -let s:mapkeyregex='\v^\s*%(\''%([^'']|'''')*\'''. - \ '|\"%([^"\\]|\\.)*\"'. - \ '|%(%(\:\ )@!.)*)\:%(\ |$)' +let s:mapkeyregex='\v^\s*\#@!\S@=%(\''%([^'']|\''\'')*\'''. + \ '|\"%([^"\\]|\\.)*\"'. + \ '|%(%(\:\ )@!.)*)\:%(\ |$)' let s:liststartregex='\v^\s*%(\-%(\ |$))' +let s:c_ns_anchor_char = '\v%([\n\r\uFEFF \t,[\]{}]@!\p)' +let s:c_ns_anchor_name = s:c_ns_anchor_char.'+' +let s:c_ns_anchor_property = '\v\&'.s:c_ns_anchor_name + +let s:ns_word_char = '\v[[:alnum:]_\-]' +let s:ns_tag_char = '\v%(%\x\x|'.s:ns_word_char.'|[#/;?:@&=+$.~*''()])' +let s:c_named_tag_handle = '\v\!'.s:ns_word_char.'+\!' +let s:c_secondary_tag_handle = '\v\!\!' +let s:c_primary_tag_handle = '\v\!' +let s:c_tag_handle = '\v%('.s:c_named_tag_handle. + \ '|'.s:c_secondary_tag_handle. + \ '|'.s:c_primary_tag_handle.')' +let s:c_ns_shorthand_tag = '\v'.s:c_tag_handle . s:ns_tag_char.'+' +let s:c_non_specific_tag = '\v\!' +let s:ns_uri_char = '\v%(%\x\x|'.s:ns_word_char.'\v|[#/;?:@&=+$,.!~*''()[\]])' +let s:c_verbatim_tag = '\v\!\<'.s:ns_uri_char.'+\>' +let s:c_ns_tag_property = '\v'.s:c_verbatim_tag. + \ '\v|'.s:c_ns_shorthand_tag. + \ '\v|'.s:c_non_specific_tag + +let s:block_scalar_header = '\v[|>]%([+-]?[1-9]|[1-9]?[+-])?' + function GetYAMLIndent(lnum) if a:lnum == 1 || !prevnonblank(a:lnum-1) return 0 @@ -97,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 @@ -127,10 +141,13 @@ function GetYAMLIndent(lnum) " - List with " multiline scalar return previndent+2 - elseif prevline =~# s:mapkeyregex + elseif prevline =~# s:mapkeyregex . '\v\s*%(%('.s:c_ns_tag_property. + \ '\v|'.s:c_ns_anchor_property. + \ '\v|'.s:block_scalar_header. + \ '\v)%(\s+|\s*%(\#.*)?$))*' " Mapping with: value " that is multiline scalar - return previndent+s:shiftwidth() + return previndent+shiftwidth() endif return previndent endfunction |