diff options
author | Bram Moolenaar <Bram@vim.org> | 2020-06-07 21:07:18 +0200 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2020-06-07 21:07:18 +0200 |
commit | acc224064033e5cea21ef7f1eefb356ca06ff11d (patch) | |
tree | bb447a8591e335b0bec96a43a7c8fa5774d741df /runtime/indent | |
parent | df44a27b53586fccfc6a3aedc89061fdd9a515ff (diff) |
Update runtime files
Diffstat (limited to 'runtime/indent')
-rw-r--r-- | runtime/indent/elm.vim | 114 | ||||
-rw-r--r-- | runtime/indent/sqlanywhere.vim | 80 | ||||
-rw-r--r-- | runtime/indent/testdir/yaml.in | 5 | ||||
-rw-r--r-- | runtime/indent/testdir/yaml.ok | 5 | ||||
-rw-r--r-- | runtime/indent/yaml.vim | 11 |
5 files changed, 173 insertions, 42 deletions
diff --git a/runtime/indent/elm.vim b/runtime/indent/elm.vim new file mode 100644 index 0000000000..232c347c66 --- /dev/null +++ b/runtime/indent/elm.vim @@ -0,0 +1,114 @@ +" Elm indent plugin file +" Language: Elm +" Maintainer: Andreas Scharf <as@99n.de> +" Original Author: Joseph Hager <ajhager@gmail.com> +" Copyright: Joseph Hager <ajhager@gmail.com> +" License: BSD3 +" Latest Revision: 2020-05-29 + +" Only load this indent file when no other was loaded. +if exists('b:did_indent') + finish +endif +let b:did_indent = 1 + +" Local defaults +setlocal expandtab +setlocal indentexpr=GetElmIndent() +setlocal indentkeys+=0=else,0=if,0=of,0=import,0=then,0=type,0\|,0},0\],0),=-},0=in +setlocal nolisp +setlocal nosmartindent + +" Only define the function once. +if exists('*GetElmIndent') + finish +endif + +" Indent pairs +function! s:FindPair(pstart, pmid, pend) + "call search(a:pend, 'bW') + return indent(searchpair(a:pstart, a:pmid, a:pend, 'bWn', 'synIDattr(synID(line("."), col("."), 0), "name") =~? "string\\|comment"')) +endfunction + +function! GetElmIndent() + let l:lnum = v:lnum - 1 + + " Ident 0 if the first line of the file: + if l:lnum == 0 + return 0 + endif + + let l:ind = indent(l:lnum) + let l:lline = getline(l:lnum) + let l:line = getline(v:lnum) + + " Indent if current line begins with '}': + if l:line =~? '^\s*}' + return s:FindPair('{', '', '}') + + " Indent if current line begins with 'else': + elseif l:line =~# '^\s*else\>' + if l:lline !~# '^\s*\(if\|then\)\>' + return s:FindPair('\<if\>', '', '\<else\>') + endif + + " Indent if current line begins with 'then': + elseif l:line =~# '^\s*then\>' + if l:lline !~# '^\s*\(if\|else\)\>' + return s:FindPair('\<if\>', '', '\<then\>') + endif + + " HACK: Indent lines in case with nearest case clause: + elseif l:line =~# '->' && l:line !~# ':' && l:line !~# '\\' + return indent(search('^\s*case', 'bWn')) + &shiftwidth + + " HACK: Don't change the indentation if the last line is a comment. + elseif l:lline =~# '^\s*--' + return l:ind + + " Align the end of block comments with the start + elseif l:line =~# '^\s*-}' + return indent(search('{-', 'bWn')) + + " Indent double shift after let with an empty rhs + elseif l:lline =~# '\<let\>.*\s=$' + return l:ind + 4 + &shiftwidth + + " Align 'in' with the parent let. + elseif l:line =~# '^\s*in\>' + return indent(search('^\s*let', 'bWn')) + + " Align bindings with the parent let. + elseif l:lline =~# '\<let\>' + return l:ind + 4 + + " Align bindings with the parent in. + elseif l:lline =~# '^\s*in\>' + return l:ind + + endif + + " Add a 'shiftwidth' after lines ending with: + if l:lline =~# '\(|\|=\|->\|<-\|(\|\[\|{\|\<\(of\|else\|if\|then\)\)\s*$' + let l:ind = l:ind + &shiftwidth + + " Add a 'shiftwidth' after lines starting with type ending with '=': + elseif l:lline =~# '^\s*type' && l:line =~# '^\s*=' + let l:ind = l:ind + &shiftwidth + + " Back to normal indent after comments: + elseif l:lline =~# '-}\s*$' + call search('-}', 'bW') + let l:ind = indent(searchpair('{-', '', '-}', 'bWn', 'synIDattr(synID(line("."), col("."), 0), "name") =~? "string"')) + + " Ident some operators if there aren't any starting the last line. + elseif l:line =~# '^\s*\(!\|&\|(\|`\|+\||\|{\|[\|,\)=' && l:lline !~# '^\s*\(!\|&\|(\|`\|+\||\|{\|[\|,\)=' && l:lline !~# '^\s*$' + let l:ind = l:ind + &shiftwidth + + elseif l:lline ==# '' && getline(l:lnum - 1) !=# '' + let l:ind = indent(search('^\s*\S+', 'bWn')) + + endif + + return l:ind +endfunc diff --git a/runtime/indent/sqlanywhere.vim b/runtime/indent/sqlanywhere.vim index ba35d76715..601c567adc 100644 --- a/runtime/indent/sqlanywhere.vim +++ b/runtime/indent/sqlanywhere.vim @@ -1,7 +1,8 @@ " Vim indent file " Language: SQL " Maintainer: David Fishburn <dfishburn dot vim at gmail dot com> -" Last Change: 2017 Jun 13 +" Last Change By Maintainer: 2017 Jun 13 +" Last Change: by Stephen Wall, #5578, 2020 Jun 07 " Version: 3.0 " Download: http://vim.sourceforge.net/script.php?script_id=495 @@ -67,68 +68,73 @@ set cpo&vim " IS is excluded, since it is difficult to determine when the " ending block is (especially for procedures/functions). let s:SQLBlockStart = '^\s*\%('. - \ 'if\|else\|elseif\|elsif\|'. - \ 'while\|loop\|do\|for\|'. - \ 'begin\|'. + \ 'if\>.*\<then\|'. + \ 'then\|else\>\|'. + \ 'elseif\>.*\<then\|'. + \ 'elsif\>.(\<then\|'. + \ 'while\>.*\<loop\|'. + \ 'for\>.*\<loop\|'. + \ 'foreach\>.*\<loop\|'. + \ 'loop\|do\|declare\|begin\|'. \ 'case\|when\|merge\|exception'. \ '\)\>' let s:SQLBlockEnd = '^\s*\(end\)\>' -" The indent level is also based on unmatched paranethesis +" The indent level is also based on unmatched parentheses " If a line has an extra "(" increase the indent " If a line has an extra ")" decrease the indent -function! s:CountUnbalancedParan( line, paran_to_check ) +function! s:CountUnbalancedParen( line, paren_to_check ) let l = a:line let lp = substitute(l, '[^(]', '', 'g') let l = a:line let rp = substitute(l, '[^)]', '', 'g') - if a:paran_to_check =~ ')' - " echom 'CountUnbalancedParan ) returning: ' . + if a:paren_to_check =~ ')' + " echom 'CountUnbalancedParen ) returning: ' . " \ (strlen(rp) - strlen(lp)) return (strlen(rp) - strlen(lp)) - elseif a:paran_to_check =~ '(' - " echom 'CountUnbalancedParan ( returning: ' . + elseif a:paren_to_check =~ '(' + " echom 'CountUnbalancedParen ( returning: ' . " \ (strlen(lp) - strlen(rp)) return (strlen(lp) - strlen(rp)) else - " echom 'CountUnbalancedParan unknown paran to check: ' . - " \ a:paran_to_check + " echom 'CountUnbalancedParen unknown paren to check: ' . + " \ a:paren_to_check return 0 endif endfunction " Unindent commands based on previous indent level -function! s:CheckToIgnoreRightParan( prev_lnum, num_levels ) +function! s:CheckToIgnoreRightParen( prev_lnum, num_levels ) let lnum = a:prev_lnum let line = getline(lnum) let ends = 0 - let num_right_paran = a:num_levels - let ignore_paran = 0 + let num_right_paren = a:num_levels + let ignore_paren = 0 let vircol = 1 - while num_right_paran > 0 + while num_right_paren > 0 silent! exec 'norm! '.lnum."G\<bar>".vircol."\<bar>" - let right_paran = search( ')', 'W' ) - if right_paran != lnum + let right_paren = search( ')', 'W' ) + if right_paren != lnum " This should not happen since there should be at least - " num_right_paran matches for this line + " num_right_paren matches for this line break endif let vircol = virtcol(".") " if getline(".") =~ '^)' - let matching_paran = searchpair('(', '', ')', 'bW', + let matching_paren = searchpair('(', '', ')', 'bW', \ 's:IsColComment(line("."), col("."))') - if matching_paran < 1 + if matching_paren < 1 " No match found " echom 'CTIRP - no match found, ignoring' break endif - if matching_paran == lnum - " This was not an unmatched parantenses, start the search again + if matching_paren == lnum + " This was not an unmatched parentheses, start the search again " again after this column " echom 'CTIRP - same line match, ignoring' continue @@ -136,23 +142,23 @@ function! s:CheckToIgnoreRightParan( prev_lnum, num_levels ) " echom 'CTIRP - match: ' . line(".") . ' ' . getline(".") - if getline(matching_paran) =~? '\(if\|while\)\>' + if getline(matching_paren) =~? '\(if\|while\)\>' " echom 'CTIRP - if/while ignored: ' . line(".") . ' ' . getline(".") - let ignore_paran = ignore_paran + 1 + let ignore_paren = ignore_paren + 1 endif " One match found, decrease and check for further matches - let num_right_paran = num_right_paran - 1 + let num_right_paren = num_right_paren - 1 endwhile " Fallback - just move back one " return a:prev_indent - shiftwidth() - return ignore_paran + return ignore_paren endfunction " Based on the keyword provided, loop through previous non empty -" non comment lines to find the statement that initated the keyword. +" non comment lines to find the statement that initiated the keyword. " Return its indent level " CASE .. " WHEN ... @@ -295,26 +301,26 @@ function! GetSQLIndent() " echom 'prevl - SQLBlockStart - indent ' . ind . ' line: ' . prevline elseif prevline =~ '[()]' if prevline =~ '(' - let num_unmatched_left = s:CountUnbalancedParan( prevline, '(' ) + let num_unmatched_left = s:CountUnbalancedParen( prevline, '(' ) else let num_unmatched_left = 0 endif if prevline =~ ')' - let num_unmatched_right = s:CountUnbalancedParan( prevline, ')' ) + let num_unmatched_right = s:CountUnbalancedParen( prevline, ')' ) else let num_unmatched_right = 0 - " let num_unmatched_right = s:CountUnbalancedParan( prevline, ')' ) + " let num_unmatched_right = s:CountUnbalancedParen( prevline, ')' ) endif if num_unmatched_left > 0 - " There is a open left paranethesis + " There is a open left parenthesis " increase indent let ind = ind + ( shiftwidth() * num_unmatched_left ) elseif num_unmatched_right > 0 - " if it is an unbalanced paranethesis only unindent if + " if it is an unbalanced parenthesis only unindent if " it was part of a command (ie create table(..) ) " instead of part of an if (ie if (....) then) which should " maintain the indent level - let ignore = s:CheckToIgnoreRightParan( prevlnum, num_unmatched_right ) + let ignore = s:CheckToIgnoreRightParen( prevlnum, num_unmatched_right ) " echom 'prevl - ) unbalanced - CTIRP - ignore: ' . ignore if prevline =~ '^\s*)' @@ -357,8 +363,8 @@ function! GetSQLIndent() " elseif line =~ '^\s*)\s*;\?\s*$' " elseif line =~ '^\s*)' elseif line =~ '^\s*)' - let num_unmatched_right = s:CountUnbalancedParan( line, ')' ) - let ignore = s:CheckToIgnoreRightParan( v:lnum, num_unmatched_right ) + let num_unmatched_right = s:CountUnbalancedParen( line, ')' ) + let ignore = s:CheckToIgnoreRightParen( v:lnum, num_unmatched_right ) " If the line ends in a ), then reduce the indent " This catches items like: " CREATE TABLE T1( @@ -368,7 +374,7 @@ function! GetSQLIndent() " But we do not want to unindent a line like: " IF ( c1 = 1 " AND c2 = 3 ) THEN - " let num_unmatched_right = s:CountUnbalancedParan( line, ')' ) + " let num_unmatched_right = s:CountUnbalancedParen( line, ')' ) " if num_unmatched_right > 0 " elseif strpart( line, strlen(line)-1, 1 ) =~ ')' " let ind = ind - shiftwidth() diff --git a/runtime/indent/testdir/yaml.in b/runtime/indent/testdir/yaml.in index e3d77e2543..8515e1752c 100644 --- a/runtime/indent/testdir/yaml.in +++ b/runtime/indent/testdir/yaml.in @@ -12,3 +12,8 @@ map2: map: &anchor map: val # END_INDENT + +# START_INDENT +map: multiline +value +# END_INDENT diff --git a/runtime/indent/testdir/yaml.ok b/runtime/indent/testdir/yaml.ok index b97b2e5896..5ca2871fc9 100644 --- a/runtime/indent/testdir/yaml.ok +++ b/runtime/indent/testdir/yaml.ok @@ -12,3 +12,8 @@ map2: map: &anchor map: val # END_INDENT + +# START_INDENT +map: multiline + value +# END_INDENT diff --git a/runtime/indent/yaml.vim b/runtime/indent/yaml.vim index 9621b2b6ed..26e14effb2 100644 --- a/runtime/indent/yaml.vim +++ b/runtime/indent/yaml.vim @@ -1,7 +1,8 @@ " Vim indent file -" Language: YAML -" Maintainer: Nikolai Pavlov <zyx.vim@gmail.com> -" Last Change: 2019 Sep 28 +" Language: YAML +" Maintainer: Nikolai Pavlov <zyx.vim@gmail.com> +" Last Update: Lukas Reineke +" Last Change: 2020 Jun 07 " Only load this indent file when no other was loaded. if exists('b:did_indent') @@ -53,7 +54,7 @@ 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:ns_tag_char = '\v%('.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\!' @@ -62,7 +63,7 @@ let s:c_tag_handle = '\v%('.s:c_named_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:ns_uri_char = '\v%('.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. |