Update runtime files.

This commit is contained in:
Bram Moolenaar
2012-12-05 19:01:43 +01:00
parent 32c8f1cb19
commit 34feacbcce
15 changed files with 1236 additions and 547 deletions

View File

@ -1,8 +1,8 @@
" Vim indent file
" Language: SQL
" Maintainer: David Fishburn <fishburn at ianywhere dot com>
" Last Change: Mon Apr 02 2007 9:13:47 AM
" Version: 1.5
" Maintainer: David Fishburn <dfishburn dot vim at gmail dot com>
" Last Change: 2012 Dec 05
" Version: 3.0
" Download: http://vim.sourceforge.net/script.php?script_id=495
" Notes:
@ -18,6 +18,17 @@
" Known Issues:
" The Oracle MERGE statement does not have an end tag associated with
" it, this can leave the indent hanging to the right one too many.
"
" History:
" 3.0 (Dec 2012)
" Added cpo check
"
" 2.0
" Added the FOR keyword to SQLBlockStart to handle (Alec Tica):
" for i in 1..100 loop
" |<-- I expect to have indentation here
" end loop;
"
" Only load this indent file when no other was loaded.
if exists("b:did_indent")
@ -25,6 +36,8 @@ if exists("b:did_indent")
endif
let b:did_indent = 1
let b:current_indent = "sqlanywhere"
let s:keepcpo= &cpo
set cpo&vim
setlocal indentkeys-=0{
setlocal indentkeys-=0}
@ -44,20 +57,13 @@ setlocal indentkeys+==~end,=~else,=~elseif,=~elsif,0=~when,0=)
" in the indentkeys is typed
setlocal indentexpr=GetSQLIndent()
" Only define the functions once.
if exists("*GetSQLIndent")
finish
endif
let s:keepcpo= &cpo
set cpo&vim
" List of all the statements that start a new block.
" These are typically words that start a line.
" 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\|'.
\ 'if\|else\|elseif\|elsif\|'.
\ 'while\|loop\|do\|for\|'.
\ 'begin\|'.
\ 'case\|when\|merge\|exception'.
\ '\)\>'
@ -66,7 +72,7 @@ let s:SQLBlockEnd = '^\s*\(end\)\>'
" The indent level is also based on unmatched paranethesis
" 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:CountUnbalancedParan( line, paran_to_check )
let l = a:line
let lp = substitute(l, '[^(]', '', 'g')
let l = a:line
@ -88,7 +94,7 @@ function s:CountUnbalancedParan( line, paran_to_check )
endfunction
" Unindent commands based on previous indent level
function s:CheckToIgnoreRightParan( prev_lnum, num_levels )
function! s:CheckToIgnoreRightParan( prev_lnum, num_levels )
let lnum = a:prev_lnum
let line = getline(lnum)
let ends = 0
@ -151,7 +157,7 @@ endfunction
" something;
" WHEN ...
" Should return indent level of exception.
function s:GetStmtStarterIndent( keyword, curr_lnum )
function! s:GetStmtStarterIndent( keyword, curr_lnum )
let lnum = a:curr_lnum
" Default - reduce indent by 1
@ -193,7 +199,7 @@ endfunction
" Check if the line is a comment
function s:IsLineComment(lnum)
function! s:IsLineComment(lnum)
let rc = synIDattr(
\ synID(a:lnum,
\ match(getline(a:lnum), '\S')+1, 0)
@ -205,7 +211,7 @@ endfunction
" Check if the column is a comment
function s:IsColComment(lnum, cnum)
function! s:IsColComment(lnum, cnum)
let rc = synIDattr(synID(a:lnum, a:cnum, 0), "name")
\ =~? "comment"
@ -215,7 +221,7 @@ endfunction
" Instead of returning a column position, return
" an appropriate value as a factor of shiftwidth.
function s:ModuloIndent(ind)
function! s:ModuloIndent(ind)
let ind = a:ind
if ind > 0
@ -231,7 +237,7 @@ endfunction
" Find correct indent of a new line based upon the previous line
function GetSQLIndent()
function! GetSQLIndent()
let lnum = v:lnum
let ind = indent(lnum)
@ -242,35 +248,27 @@ function GetSQLIndent()
" return ind
" endif
" while 1
" Get previous non-blank line
let prevlnum = prevnonblank(lnum - 1)
if prevlnum <= 0
return ind
endif
" Get previous non-blank line
let prevlnum = prevnonblank(lnum - 1)
if prevlnum <= 0
return ind
endif
if s:IsLineComment(prevlnum) == 1
if getline(v:lnum) =~ '^\s*\*'
let ind = s:ModuloIndent(indent(prevlnum))
return ind + 1
endif
" If the previous line is a comment, then return -1
" to tell Vim to use the formatoptions setting to determine
" the indent to use
" But only if the next line is blank. This would be true if
" the user is typing, but it would not be true if the user
" is reindenting the file
if getline(v:lnum) =~ '^\s*$'
return -1
endif
if s:IsLineComment(prevlnum) == 1
if getline(v:lnum) =~ '^\s*\*'
let ind = s:ModuloIndent(indent(prevlnum))
return ind + 1
endif
" let prevline = getline(prevlnum)
" if prevline !~ '^\s*$'
" " echom 'previous non blank - break: ' . prevline
" break
" endif
" endwhile
" If the previous line is a comment, then return -1
" to tell Vim to use the formatoptions setting to determine
" the indent to use
" But only if the next line is blank. This would be true if
" the user is typing, but it would not be true if the user
" is reindenting the file
if getline(v:lnum) =~ '^\s*$'
return -1
endif
endif
" echom 'PREVIOUS INDENT: ' . indent(prevlnum) . ' LINE: ' . getline(prevlnum)
@ -384,7 +382,7 @@ function GetSQLIndent()
return s:ModuloIndent(ind)
endfunction
let &cpo = s:keepcpo
" Restore:
let &cpo= s:keepcpo
unlet s:keepcpo
" vim:sw=4:
" vim: ts=4 fdm=marker sw=4

132
runtime/indent/yaml.vim Normal file
View File

@ -0,0 +1,132 @@
" Vim indent file
" Language: YAML
" Maintainer: Nikolai Pavlov <zyx.vim@gmail.com>
" Only load this indent file when no other was loaded.
if exists('b:did_indent')
finish
endif
let s:save_cpo = &cpo
set cpo&vim
let b:did_indent = 1
setlocal indentexpr=GetYAMLIndent(v:lnum)
setlocal indentkeys=!^F,o,O,0#,0},0],<:>,-
setlocal nosmartindent
let b:undo_indent = 'setlocal indentexpr< indentkeys< smartindent<'
" Only define the function once.
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*#'
let prevlnum = prevnonblank(prevlnum-1)
endwhile
return prevlnum
endfunction
function s:FindPrevLEIndentedLineMatchingRegex(lnum, regex)
let plilnum = s:FindPrevLessIndentedLine(a:lnum, indent(a:lnum)+1)
while plilnum && getline(plilnum) !~# a:regex
let plilnum = s:FindPrevLessIndentedLine(plilnum)
endwhile
return plilnum
endfunction
let s:mapkeyregex='\v^\s*%(\''%([^'']|'''')*\'''.
\ '|\"%([^"\\]|\\.)*\"'.
\ '|%(%(\:\ )@!.)*)\:%(\ |$)'
let s:liststartregex='\v^\s*%(\-%(\ |$))'
function GetYAMLIndent(lnum)
if a:lnum == 1 || !prevnonblank(a:lnum-1)
return 0
endif
let prevlnum = prevnonblank(a:lnum-1)
let previndent = indent(prevlnum)
let line = getline(a:lnum)
if line =~# '^\s*#' && getline(a:lnum-1) =~# '^\s*#'
" Comment blocks should have identical indent
return previndent
elseif line =~# '^\s*[\]}]'
" Lines containing only closing braces should have previous indent
return indent(s:FindPrevLessIndentedLine(a:lnum))
endif
" Ignore comment lines when calculating indent
while getline(prevlnum) =~# '^\s*#'
let prevlnum = prevnonblank(prevlnum-1)
if !prevlnum
return previndent
endif
endwhile
let prevline = getline(prevlnum)
let previndent = indent(prevlnum)
" Any examples below assume that shiftwidth=2
if prevline =~# '\v[{[:]$|[:-]\ [|>][+\-]?%(\s+\#.*|\s*)$'
" Mapping key:
" nested mapping: ...
"
" - {
" key: [
" list value
" ]
" }
"
" - |-
" Block scalar without indentation indicator
return previndent+s:shiftwidth()
elseif prevline =~# '\v[:-]\ [|>]%(\d+[+\-]?|[+\-]?\d+)%(\#.*|\s*)$'
" - |+2
" block scalar with indentation indicator
"#^^ indent+2, not indent+shiftwidth
return previndent + str2nr(matchstr(prevline,
\'\v([:-]\ [|>])@<=[+\-]?\d+%([+\-]?%(\s+\#.*|\s*)$)@='))
elseif prevline =~# '\v\"%([^"\\]|\\.)*\\$'
" "Multiline string \
" with escaped end"
let qidx = match(prevline, '\v\"%([^"\\]|\\.)*\\')
return virtcol([prevlnum, qidx+1])
elseif line =~# s:liststartregex
" List line should have indent equal to previous list line unless it was
" caught by one of the previous rules
return indent(s:FindPrevLEIndentedLineMatchingRegex(a:lnum,
\ s:liststartregex))
elseif line =~# s:mapkeyregex
" Same for line containing mapping key
return indent(s:FindPrevLEIndentedLineMatchingRegex(a:lnum,
\ s:mapkeyregex))
elseif prevline =~# '^\s*- '
" - List with
" multiline scalar
return previndent+2
elseif prevline =~# s:mapkeyregex
" Mapping with: value
" that is multiline scalar
return previndent+s:shiftwidth()
endif
return previndent
endfunction
let &cpo = s:save_cpo