annotate runtime/indent/yaml.vim @ 6520:70793fedd25a v7.4.587

updated for version 7.4.587 Problem: Conceal does not work properly with 'linebreak'. (cs86661) Solution: Save and restore boguscols. (Christian Brabandt)
author Bram Moolenaar <bram@vim.org>
date Tue, 20 Jan 2015 19:01:35 +0100
parents b3f3237a3d72
children c590de398af9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3996
b3f3237a3d72 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
1 " Vim indent file
b3f3237a3d72 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
2 " Language: YAML
b3f3237a3d72 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
3 " Maintainer: Nikolai Pavlov <zyx.vim@gmail.com>
b3f3237a3d72 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
4
b3f3237a3d72 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
5 " Only load this indent file when no other was loaded.
b3f3237a3d72 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
6 if exists('b:did_indent')
b3f3237a3d72 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
7 finish
b3f3237a3d72 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
8 endif
b3f3237a3d72 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
9
b3f3237a3d72 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
10 let s:save_cpo = &cpo
b3f3237a3d72 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
11 set cpo&vim
b3f3237a3d72 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
12
b3f3237a3d72 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
13 let b:did_indent = 1
b3f3237a3d72 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
14
b3f3237a3d72 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
15 setlocal indentexpr=GetYAMLIndent(v:lnum)
b3f3237a3d72 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
16 setlocal indentkeys=!^F,o,O,0#,0},0],<:>,-
b3f3237a3d72 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
17 setlocal nosmartindent
b3f3237a3d72 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
18
b3f3237a3d72 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
19 let b:undo_indent = 'setlocal indentexpr< indentkeys< smartindent<'
b3f3237a3d72 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
20
b3f3237a3d72 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
21 " Only define the function once.
b3f3237a3d72 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
22 if exists('*GetYAMLIndent')
b3f3237a3d72 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
23 finish
b3f3237a3d72 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
24 endif
b3f3237a3d72 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
25
b3f3237a3d72 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
26 if exists('*shiftwidth')
b3f3237a3d72 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
27 let s:shiftwidth = function('shiftwidth')
b3f3237a3d72 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
28 else
b3f3237a3d72 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
29 function s:shiftwidth()
b3f3237a3d72 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
30 return &shiftwidth
b3f3237a3d72 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
31 endfunction
b3f3237a3d72 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
32 endif
b3f3237a3d72 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
33
b3f3237a3d72 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
34 function s:FindPrevLessIndentedLine(lnum, ...)
b3f3237a3d72 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
35 let prevlnum = prevnonblank(a:lnum-1)
b3f3237a3d72 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
36 let curindent = a:0 ? a:1 : indent(a:lnum)
b3f3237a3d72 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
37 while prevlnum
b3f3237a3d72 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
38 \&& indent(prevlnum) >= curindent
b3f3237a3d72 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
39 \&& getline(prevlnum) !~# '^\s*#'
b3f3237a3d72 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
40 let prevlnum = prevnonblank(prevlnum-1)
b3f3237a3d72 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
41 endwhile
b3f3237a3d72 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
42 return prevlnum
b3f3237a3d72 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
43 endfunction
b3f3237a3d72 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
44
b3f3237a3d72 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
45 function s:FindPrevLEIndentedLineMatchingRegex(lnum, regex)
b3f3237a3d72 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
46 let plilnum = s:FindPrevLessIndentedLine(a:lnum, indent(a:lnum)+1)
b3f3237a3d72 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
47 while plilnum && getline(plilnum) !~# a:regex
b3f3237a3d72 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
48 let plilnum = s:FindPrevLessIndentedLine(plilnum)
b3f3237a3d72 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
49 endwhile
b3f3237a3d72 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
50 return plilnum
b3f3237a3d72 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
51 endfunction
b3f3237a3d72 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
52
b3f3237a3d72 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
53 let s:mapkeyregex='\v^\s*%(\''%([^'']|'''')*\'''.
b3f3237a3d72 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
54 \ '|\"%([^"\\]|\\.)*\"'.
b3f3237a3d72 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
55 \ '|%(%(\:\ )@!.)*)\:%(\ |$)'
b3f3237a3d72 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
56 let s:liststartregex='\v^\s*%(\-%(\ |$))'
b3f3237a3d72 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
57
b3f3237a3d72 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
58 function GetYAMLIndent(lnum)
b3f3237a3d72 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
59 if a:lnum == 1 || !prevnonblank(a:lnum-1)
b3f3237a3d72 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
60 return 0
b3f3237a3d72 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
61 endif
b3f3237a3d72 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
62
b3f3237a3d72 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
63 let prevlnum = prevnonblank(a:lnum-1)
b3f3237a3d72 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
64 let previndent = indent(prevlnum)
b3f3237a3d72 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
65
b3f3237a3d72 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
66 let line = getline(a:lnum)
b3f3237a3d72 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
67 if line =~# '^\s*#' && getline(a:lnum-1) =~# '^\s*#'
b3f3237a3d72 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
68 " Comment blocks should have identical indent
b3f3237a3d72 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
69 return previndent
b3f3237a3d72 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
70 elseif line =~# '^\s*[\]}]'
b3f3237a3d72 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
71 " Lines containing only closing braces should have previous indent
b3f3237a3d72 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
72 return indent(s:FindPrevLessIndentedLine(a:lnum))
b3f3237a3d72 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
73 endif
b3f3237a3d72 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
74
b3f3237a3d72 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
75 " Ignore comment lines when calculating indent
b3f3237a3d72 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
76 while getline(prevlnum) =~# '^\s*#'
b3f3237a3d72 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
77 let prevlnum = prevnonblank(prevlnum-1)
b3f3237a3d72 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
78 if !prevlnum
b3f3237a3d72 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
79 return previndent
b3f3237a3d72 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
80 endif
b3f3237a3d72 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
81 endwhile
b3f3237a3d72 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
82
b3f3237a3d72 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
83 let prevline = getline(prevlnum)
b3f3237a3d72 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
84 let previndent = indent(prevlnum)
b3f3237a3d72 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
85
b3f3237a3d72 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
86 " Any examples below assume that shiftwidth=2
b3f3237a3d72 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
87 if prevline =~# '\v[{[:]$|[:-]\ [|>][+\-]?%(\s+\#.*|\s*)$'
b3f3237a3d72 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
88 " Mapping key:
b3f3237a3d72 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
89 " nested mapping: ...
b3f3237a3d72 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
90 "
b3f3237a3d72 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
91 " - {
b3f3237a3d72 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
92 " key: [
b3f3237a3d72 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
93 " list value
b3f3237a3d72 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
94 " ]
b3f3237a3d72 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
95 " }
b3f3237a3d72 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
96 "
b3f3237a3d72 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
97 " - |-
b3f3237a3d72 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
98 " Block scalar without indentation indicator
b3f3237a3d72 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
99 return previndent+s:shiftwidth()
b3f3237a3d72 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
100 elseif prevline =~# '\v[:-]\ [|>]%(\d+[+\-]?|[+\-]?\d+)%(\#.*|\s*)$'
b3f3237a3d72 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
101 " - |+2
b3f3237a3d72 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
102 " block scalar with indentation indicator
b3f3237a3d72 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
103 "#^^ indent+2, not indent+shiftwidth
b3f3237a3d72 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
104 return previndent + str2nr(matchstr(prevline,
b3f3237a3d72 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
105 \'\v([:-]\ [|>])@<=[+\-]?\d+%([+\-]?%(\s+\#.*|\s*)$)@='))
b3f3237a3d72 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
106 elseif prevline =~# '\v\"%([^"\\]|\\.)*\\$'
b3f3237a3d72 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
107 " "Multiline string \
b3f3237a3d72 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
108 " with escaped end"
b3f3237a3d72 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
109 let qidx = match(prevline, '\v\"%([^"\\]|\\.)*\\')
b3f3237a3d72 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
110 return virtcol([prevlnum, qidx+1])
b3f3237a3d72 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
111 elseif line =~# s:liststartregex
b3f3237a3d72 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
112 " List line should have indent equal to previous list line unless it was
b3f3237a3d72 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
113 " caught by one of the previous rules
b3f3237a3d72 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
114 return indent(s:FindPrevLEIndentedLineMatchingRegex(a:lnum,
b3f3237a3d72 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
115 \ s:liststartregex))
b3f3237a3d72 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
116 elseif line =~# s:mapkeyregex
b3f3237a3d72 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
117 " Same for line containing mapping key
b3f3237a3d72 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
118 return indent(s:FindPrevLEIndentedLineMatchingRegex(a:lnum,
b3f3237a3d72 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
119 \ s:mapkeyregex))
b3f3237a3d72 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
120 elseif prevline =~# '^\s*- '
b3f3237a3d72 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
121 " - List with
b3f3237a3d72 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
122 " multiline scalar
b3f3237a3d72 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
123 return previndent+2
b3f3237a3d72 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
124 elseif prevline =~# s:mapkeyregex
b3f3237a3d72 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
125 " Mapping with: value
b3f3237a3d72 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
126 " that is multiline scalar
b3f3237a3d72 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
127 return previndent+s:shiftwidth()
b3f3237a3d72 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
128 endif
b3f3237a3d72 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
129 return previndent
b3f3237a3d72 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
130 endfunction
b3f3237a3d72 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
131
b3f3237a3d72 Update runtime files.
Bram Moolenaar <bram@vim.org>
parents:
diff changeset
132 let &cpo = s:save_cpo