diff options
author | Bram Moolenaar <Bram@vim.org> | 2018-12-09 20:43:55 +0100 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2018-12-09 20:43:55 +0100 |
commit | d47d52232bf21036c5c89081458be7eaf2630d24 (patch) | |
tree | 5b7031e52717248256f1d4d4307f241bce046184 /runtime/indent | |
parent | 37402ed53475166cd988edbea1269fa4e9918dc4 (diff) | |
download | vim-git-d47d52232bf21036c5c89081458be7eaf2630d24.tar.gz |
Update runtime files.
Diffstat (limited to 'runtime/indent')
-rw-r--r-- | runtime/indent/cs.vim | 74 | ||||
-rw-r--r-- | runtime/indent/html.vim | 17 | ||||
-rw-r--r-- | runtime/indent/tcl.vim | 50 | ||||
-rw-r--r-- | runtime/indent/testdir/html.in | 26 | ||||
-rw-r--r-- | runtime/indent/testdir/html.ok | 26 | ||||
-rw-r--r-- | runtime/indent/testdir/tcl.in | 19 | ||||
-rw-r--r-- | runtime/indent/testdir/tcl.ok | 19 | ||||
-rw-r--r-- | runtime/indent/testdir/xml.in | 32 | ||||
-rw-r--r-- | runtime/indent/testdir/xml.ok | 32 |
9 files changed, 267 insertions, 28 deletions
diff --git a/runtime/indent/cs.vim b/runtime/indent/cs.vim index 4a040b6fe..76c12efec 100644 --- a/runtime/indent/cs.vim +++ b/runtime/indent/cs.vim @@ -1,15 +1,73 @@ " Vim indent file -" Language: C# -" Maintainer: Johannes Zellner <johannes@zellner.org> -" Last Change: Fri, 15 Mar 2002 07:53:54 CET +" Language: C# +" Maintainer: Nick Jensen <nickspoon@gmail.com> +" Former Maintainers: Aquila Deus +" Johannes Zellner <johannes@zellner.org> +" Last Change: 2018-11-21 +" Filenames: *.cs +" License: Vim (see :h license) +" Repository: https://github.com/nickspoons/vim-cs +" " Only load this indent file when no other was loaded. -if exists("b:did_indent") - finish +if exists('b:did_indent') + finish endif let b:did_indent = 1 -" C# is like indenting C -setlocal cindent +let s:save_cpo = &cpoptions +set cpoptions&vim -let b:undo_indent = "setl cin<" + +setlocal indentexpr=GetCSIndent(v:lnum) + +function! s:IsCompilerDirective(line) + return a:line =~? '^\s*#' +endf + +function! s:IsAttributeLine(line) + return a:line =~? '^\s*\[[A-Za-z]' && a:line =~? '\]$' +endf + +function! s:FindPreviousNonCompilerDirectiveLine(start_lnum) + for delta in range(0, a:start_lnum) + let lnum = a:start_lnum - delta + let line = getline(lnum) + let is_directive = s:IsCompilerDirective(line) + if !is_directive + return lnum + endif + endfor + return 0 +endf + +function! GetCSIndent(lnum) abort + " Hit the start of the file, use zero indent. + if a:lnum == 0 + return 0 + endif + + let this_line = getline(a:lnum) + + " Compiler directives use zero indent if so configured. + let is_first_col_macro = s:IsCompilerDirective(this_line) && stridx(&l:cinkeys, '0#') >= 0 + if is_first_col_macro + return cindent(a:lnum) + endif + + let lnum = s:FindPreviousNonCompilerDirectiveLine(a:lnum - 1) + let previous_code_line = getline(lnum) + if s:IsAttributeLine(previous_code_line) + let ind = indent(lnum) + return ind + else + return cindent(a:lnum) + endif +endfunction + +let b:undo_indent = 'setlocal indentexpr<' + +let &cpoptions = s:save_cpo +unlet s:save_cpo + +" vim:et:sw=2:sts=2 diff --git a/runtime/indent/html.vim b/runtime/indent/html.vim index bece6614b..1a8177050 100644 --- a/runtime/indent/html.vim +++ b/runtime/indent/html.vim @@ -216,8 +216,9 @@ endfunc "}}} " Add known tag pairs. " Self-closing tags and tags that are sometimes {{{ " self-closing (e.g., <p>) are not here (when encountering </p> we can find -" the matching <p>, but not the other way around). Known self-closing tags: -" 'p', 'img', 'source'. +" the matching <p>, but not the other way around). +" Known self-closing tags: " 'p', 'img', 'source', 'area', 'keygen', 'track', +" 'wbr'. " Old HTML tags: call s:AddITags(s:indent_tags, [ \ 'a', 'abbr', 'acronym', 'address', 'b', 'bdo', 'big', @@ -232,11 +233,11 @@ call s:AddITags(s:indent_tags, [ " New HTML5 elements: call s:AddITags(s:indent_tags, [ - \ 'area', 'article', 'aside', 'audio', 'bdi', 'canvas', - \ 'command', 'data', 'datalist', 'details', 'embed', 'figcaption', - \ 'figure', 'footer', 'header', 'keygen', 'main', 'mark', 'meter', - \ 'nav', 'output', 'picture', 'progress', 'rp', 'rt', 'ruby', 'section', - \ 'summary', 'svg', 'time', 'track', 'video', 'wbr']) + \ 'article', 'aside', 'audio', 'bdi', 'canvas', 'command', 'data', + \ 'datalist', 'details', 'dialog', 'embed', 'figcaption', 'figure', + \ 'footer', 'header', 'hgroup', 'main', 'mark', 'meter', 'nav', 'output', + \ 'picture', 'progress', 'rp', 'rt', 'ruby', 'section', 'summary', + \ 'svg', 'time', 'video']) " Tags added for web components: call s:AddITags(s:indent_tags, [ @@ -934,7 +935,7 @@ func! s:InsideTag(foundHtmlString) let idx = match(text, '<' . s:tagname . '\s\+\zs\w') endif if idx == -1 - " after just <tag indent one level more + " after just "<tag" indent one level more let idx = match(text, '<' . s:tagname . '$') if idx >= 0 call cursor(lnum, idx) diff --git a/runtime/indent/tcl.vim b/runtime/indent/tcl.vim index e9d61e436..d77081841 100644 --- a/runtime/indent/tcl.vim +++ b/runtime/indent/tcl.vim @@ -1,7 +1,8 @@ " Vim indent file -" Language: Tcl -" Maintainer: Nikolai Weibull <now@bitwi.se> -" Latest Revision: 2006-12-20 +" Language: Tcl +" Previous Maintainer: Nikolai Weibull <now@bitwi.se> +" Latest Update: Chris Heithoff <chrisheithoff@gmail.com> +" Latest Revision: 2018-12-05 if exists("b:did_indent") finish @@ -28,6 +29,15 @@ function s:prevnonblanknoncomment(lnum) return lnum endfunction +function s:ends_with_backslash(lnum) + let line = getline(a:lnum) + if line =~ '\\\s*$' + return 1 + else + return 0 + endif +endfunction + function s:count_braces(lnum, count_open) let n_open = 0 let n_close = 0 @@ -53,23 +63,39 @@ endfunction function GetTclIndent() let line = getline(v:lnum) - if line =~ '^\s*\*' - return cindent(v:lnum) - elseif line =~ '^\s*}' - return indent(v:lnum) - shiftwidth() - endif + " Get the line number of the previous non-blank or non-comment line. let pnum = s:prevnonblanknoncomment(v:lnum - 1) if pnum == 0 return 0 endif - let ind = indent(pnum) + s:count_braces(pnum, 1) * shiftwidth() + " ..and the previous line before the previous line. + let pnum2 = s:prevnonblanknoncomment(pnum-1) - let pline = getline(pnum) - if pline =~ '}\s*$' - let ind -= (s:count_braces(pnum, 0) - (pline =~ '^\s*}' ? 1 : 0)) * shiftwidth() + " Default indentation is to preserve the previous indentation. + let ind = indent(pnum) + + " ...but if previous line introduces an open brace, then increase current line's indentation + if s:count_braces(pnum, 1) > 0 + let ind += shiftwidth() + else + " Look for backslash line continuation on the previous two lines. + let slash1 = s:ends_with_backslash(pnum) + let slash2 = s:ends_with_backslash(pnum2) + if slash1 && !slash2 + " If the previous line begins a line continuation. + let ind += shiftwidth() + elseif !slash1 && slash2 + " If two lines ago was the end of a line continuation group of lines. + let ind -= shiftwidth() + endif endif + " If the current line begins with a closed brace, then decrease the indentation by one. + if line =~ '^\s*}' + let ind -= shiftwidth() + endif + return ind endfunction diff --git a/runtime/indent/testdir/html.in b/runtime/indent/testdir/html.in new file mode 100644 index 000000000..9c776d61c --- /dev/null +++ b/runtime/indent/testdir/html.in @@ -0,0 +1,26 @@ +" vim: set ft=html sw=4 : + + +" START_INDENT +<div> +<div> +text +</div> +</div> + +<div +class="foo bar"> +text +</div> + +<div class="foo bar" +data="something"> +text +</div> + +<div class="foo +bar"> +text +</div> + +" END_INDENT diff --git a/runtime/indent/testdir/html.ok b/runtime/indent/testdir/html.ok new file mode 100644 index 000000000..524d57bb6 --- /dev/null +++ b/runtime/indent/testdir/html.ok @@ -0,0 +1,26 @@ +" vim: set ft=html sw=4 : + + +" START_INDENT +<div> + <div> + text + </div> +</div> + +<div + class="foo bar"> + text +</div> + +<div class="foo bar" + data="something"> + text +</div> + +<div class="foo + bar"> + text +</div> + +" END_INDENT diff --git a/runtime/indent/testdir/tcl.in b/runtime/indent/testdir/tcl.in new file mode 100644 index 000000000..3ef4ebc0a --- /dev/null +++ b/runtime/indent/testdir/tcl.in @@ -0,0 +1,19 @@ +# vim: set filetype=tcl shiftwidth=4 tabstop=4: + +# START_INDENT +proc abc {} { +set a 5 +if {[some_cmd]==1} { +foreach i [list {1 2 3}] { +# Does this comment affect anything? +puts $i +} +} +} + +command_with_a_long_time -arg1 "First" \ +-arg2 "Second" \ +-arg3 "Third" + +puts "Move indent back after line continuation is complete" +# END_INDENT
\ No newline at end of file diff --git a/runtime/indent/testdir/tcl.ok b/runtime/indent/testdir/tcl.ok new file mode 100644 index 000000000..0fb52e782 --- /dev/null +++ b/runtime/indent/testdir/tcl.ok @@ -0,0 +1,19 @@ +# vim: set filetype=tcl shiftwidth=4 tabstop=4: + +# START_INDENT +proc abc {} { + set a 5 + if {[some_cmd]==1} { + foreach i [list {1 2 3}] { + # Does this comment affect anything? + puts $i + } + } +} + +command_with_a_long_time -arg1 "First" \ + -arg2 "Second" \ + -arg3 "Third" + +puts "Move indent back after line continuation is complete" +# END_INDENT diff --git a/runtime/indent/testdir/xml.in b/runtime/indent/testdir/xml.in new file mode 100644 index 000000000..d184681c8 --- /dev/null +++ b/runtime/indent/testdir/xml.in @@ -0,0 +1,32 @@ +<!-- vim: set ft=xml ts=2 sw=0 sts=-1 et : --> +<!-- START_INDENT --> +<?xml version="1.0" encoding="utf-8"?> +<tag0> + <tag1> +<!-- comment --> +<tag2> + <tag3/> +</tag2> +<!-- text comment --> + +<!-- +text comment +--> +</tag1> +<!-- +text comment +end coment --> +</tag0> +<!-- END_INDENT --> + +<!-- START_INDENT --> +<?xml version="1.0" encoding="utf-8"?> +<tag0> + <tag1> +<!-- comment --> +<tag2> + <tag3/> +</tag2> +</tag1> +</tag0> +<!-- END_INDENT --> diff --git a/runtime/indent/testdir/xml.ok b/runtime/indent/testdir/xml.ok new file mode 100644 index 000000000..a8e2c92a1 --- /dev/null +++ b/runtime/indent/testdir/xml.ok @@ -0,0 +1,32 @@ +<!-- vim: set ft=xml ts=2 sw=0 sts=-1 et : --> +<!-- START_INDENT --> +<?xml version="1.0" encoding="utf-8"?> +<tag0> + <tag1> + <!-- comment --> + <tag2> + <tag3/> + </tag2> + <!-- text comment --> + + <!-- + text comment + --> + </tag1> + <!-- + text comment + end coment --> +</tag0> +<!-- END_INDENT --> + +<!-- START_INDENT --> +<?xml version="1.0" encoding="utf-8"?> +<tag0> + <tag1> + <!-- comment --> + <tag2> + <tag3/> + </tag2> + </tag1> +</tag0> +<!-- END_INDENT --> |