annotate runtime/indent/dtd.vim @ 29079:9781c150eddd v8.2.5061

patch 8.2.5061: C89 requires signal handlers to return void Commit: https://github.com/vim/vim/commit/99c48fe9974b8d70ca33674658a3da722b0d6466 Author: Bram Moolenaar <Bram@vim.org> Date: Sun Jun 5 22:05:19 2022 +0100 patch 8.2.5061: C89 requires signal handlers to return void Problem: C89 requires signal handlers to return void. Solution: Drop RETSIGTYPE and hard-code a void return value.
author Bram Moolenaar <Bram@vim.org>
date Sun, 05 Jun 2022 23:15:02 +0200
parents 9c221ad9634a
children 1e9e9d89f0ee
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1698
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
1 " Vim indent file
25880
9c221ad9634a Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 25773
diff changeset
2 " Language: DTD (Document Type Definition for XML)
9c221ad9634a Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 25773
diff changeset
3 " Maintainer: Doug Kearns <dougkearns@gmail.com>
9c221ad9634a Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 25773
diff changeset
4 " Previous Maintainer: Nikolai Weibull <now@bitwi.se>
9c221ad9634a Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 25773
diff changeset
5 " Last Change: 24 Sep 2021
1698
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
6
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
7 setlocal indentexpr=GetDTDIndent()
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
8 setlocal indentkeys=!^F,o,O,>
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
9 setlocal nosmartindent
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
10
25880
9c221ad9634a Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 25773
diff changeset
11 let b:undo_indent = "setl inde< indk< si<"
9c221ad9634a Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 25773
diff changeset
12
1698
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
13 if exists("*GetDTDIndent")
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
14 finish
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
15 endif
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
16
14637
0ecb909e3249 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11160
diff changeset
17 let s:cpo_save = &cpo
0ecb909e3249 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11160
diff changeset
18 set cpo&vim
0ecb909e3249 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11160
diff changeset
19
1698
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
20 " TODO: Needs to be adjusted to stop at [, <, and ].
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
21 let s:token_pattern = '^[^[:space:]]\+'
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
22
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
23 function s:lex1(input, start, ...)
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
24 let pattern = a:0 > 0 ? a:1 : s:token_pattern
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
25 let start = matchend(a:input, '^\_s*', a:start)
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
26 if start == -1
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
27 return ["", a:start]
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
28 endif
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
29 let end = matchend(a:input, pattern, start)
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
30 if end == -1
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
31 return ["", a:start]
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
32 endif
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
33 let token = strpart(a:input, start, end - start)
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
34 return [token, end]
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
35 endfunction
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
36
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
37 function s:lex(input, start, ...)
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
38 let pattern = a:0 > 0 ? a:1 : s:token_pattern
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
39 let info = s:lex1(a:input, a:start, pattern)
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
40 while info[0] == '--'
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
41 let info = s:lex1(a:input, info[1], pattern)
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
42 while info[0] != "" && info[0] != '--'
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
43 let info = s:lex1(a:input, info[1], pattern)
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
44 endwhile
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
45 if info[0] == ""
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
46 return info
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
47 endif
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
48 let info = s:lex1(a:input, info[1], pattern)
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
49 endwhile
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
50 return info
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
51 endfunction
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
52
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
53 function s:indent_to_innermost_parentheses(line, end)
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
54 let token = '('
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
55 let end = a:end
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
56 let parentheses = [end - 1]
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
57 while token != ""
2965
f2de38a019a2 Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2587
diff changeset
58 let [token, end] = s:lex(a:line, end, '^\%([(),|]\|[A-Za-z0-9_-]\+\|#P\=CDATA\|%[A-Za-z0-9_-]\+;\)[?*+]\=')
1698
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
59 if token[0] == '('
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
60 call add(parentheses, end - 1)
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
61 elseif token[0] == ')'
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
62 if len(parentheses) == 1
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
63 return [-1, end]
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
64 endif
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
65 call remove(parentheses, -1)
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
66 endif
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
67 endwhile
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
68 return [parentheses[-1] - strridx(a:line, "\n", parentheses[-1]), end]
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
69 endfunction
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
70
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
71 " TODO: Line and end could be script global (think OO members).
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
72 function GetDTDIndent()
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
73 if v:lnum == 1
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
74 return 0
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
75 endif
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
76
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
77 " Begin by searching back for a <! that isn’t inside a comment.
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
78 " From here, depending on what follows immediately after, parse to
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
79 " where we’re at to determine what to do.
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
80 if search('<!', 'bceW') == 0
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
81 return indent(v:lnum - 1)
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
82 endif
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
83 let lnum = line('.')
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
84 let col = col('.')
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
85 let indent = indent('.')
2587
d0049ff5969e Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 1698
diff changeset
86 let line = lnum == v:lnum ? getline(lnum) : join(getline(lnum, v:lnum - 1), "\n")
1698
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
87
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
88 let [declaration, end] = s:lex1(line, col)
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
89 if declaration == ""
11160
d0a20101ecb2 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11062
diff changeset
90 return indent + shiftwidth()
1698
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
91 elseif declaration == '--'
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
92 " We’re looking at a comment. Now, simply determine if the comment is
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
93 " terminated or not. If it isn’t, let Vim take care of that using
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
94 " 'comments' and 'autoindent'. Otherwise, indent to the first lines level.
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
95 while declaration != ""
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
96 let [declaration, end] = s:lex(line, end)
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
97 if declaration == "-->"
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
98 return indent
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
99 endif
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
100 endwhile
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
101 return -1
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
102 elseif declaration == 'ELEMENT'
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
103 " Check for element name. If none exists, indent one level.
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
104 let [name, end] = s:lex(line, end)
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
105 if name == ""
11160
d0a20101ecb2 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11062
diff changeset
106 return indent + shiftwidth()
1698
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
107 endif
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
108
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
109 " Check for token following element name. This can be a specification of
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
110 " whether the start or end tag may be omitted. If nothing is found, indent
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
111 " one level.
2587
d0049ff5969e Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 1698
diff changeset
112 let [token, end] = s:lex(line, end, '^\%([-O(]\|ANY\|EMPTY\)')
1698
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
113 let n = 0
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
114 while token =~ '[-O]' && n < 2
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
115 let [token, end] = s:lex(line, end, '^\%([-O(]\|ANY\|EMPTY\)')
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
116 let n += 1
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
117 endwhile
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
118 if token == ""
11160
d0a20101ecb2 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11062
diff changeset
119 return indent + shiftwidth()
1698
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
120 endif
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
121
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
122 " Next comes the content model. If the token we’ve found isn’t a
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
123 " parenthesis it must be either ANY, EMPTY or some random junk. Either
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
124 " way, we’re done indenting this element, so set it to that of the first
25773
11b656e74444 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 14637
diff changeset
125 " line so that the terminating “>” winds up having the same indentation.
1698
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
126 if token != '('
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
127 return indent
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
128 endif
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
129
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
130 " Now go through the content model. We need to keep track of the nesting
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
131 " of parentheses. As soon as we hit 0 we’re done. If that happens we must
25773
11b656e74444 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 14637
diff changeset
132 " have a complete content model. Thus set indentation to be the same as that
1698
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
133 " of the first line so that the terminating “>” winds up having the same
25773
11b656e74444 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents: 14637
diff changeset
134 " indentation. Otherwise, we’ll indent to the innermost parentheses not yet
1698
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
135 " matched.
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
136 let [indent_of_innermost, end] = s:indent_to_innermost_parentheses(line, end)
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
137 if indent_of_innermost != -1
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
138 return indent_of_innermost
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
139 endif
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
140
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
141 " Finally, look for any additions and/or exceptions to the content model.
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
142 " This is defined by a “+” or “-” followed by another content model
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
143 " declaration.
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
144 " TODO: Can the “-” be separated by whitespace from the “(”?
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
145 let seen = { '+(': 0, '-(': 0 }
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
146 while 1
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
147 let [additions_exceptions, end] = s:lex(line, end, '^[+-](')
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
148 if additions_exceptions != '+(' && additions_exceptions != '-('
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
149 let [token, end] = s:lex(line, end)
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
150 if token == '>'
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
151 return indent
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
152 endif
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
153 " TODO: Should use s:lex here on getline(v:lnum) and check for >.
11160
d0a20101ecb2 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11062
diff changeset
154 return getline(v:lnum) =~ '^\s*>' || count(values(seen), 0) == 0 ? indent : (indent + shiftwidth())
1698
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
155 endif
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
156
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
157 " If we’ve seen an addition or exception already and this is of the same
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
158 " kind, the user is writing a broken DTD. Time to bail.
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
159 if seen[additions_exceptions]
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
160 return indent
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
161 endif
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
162 let seen[additions_exceptions] = 1
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
163
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
164 let [indent_of_innermost, end] = s:indent_to_innermost_parentheses(line, end)
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
165 if indent_of_innermost != -1
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
166 return indent_of_innermost
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
167 endif
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
168 endwhile
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
169 elseif declaration == 'ATTLIST'
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
170 " Check for element name. If none exists, indent one level.
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
171 let [name, end] = s:lex(line, end)
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
172 if name == ""
11160
d0a20101ecb2 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11062
diff changeset
173 return indent + shiftwidth()
1698
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
174 endif
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
175
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
176 " Check for any number of attributes.
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
177 while 1
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
178 " Check for attribute name. If none exists, indent one level, unless the
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
179 " current line is a lone “>”, in which case we indent to the same level
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
180 " as the first line. Otherwise, if the attribute name is “>”, we have
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
181 " actually hit the end of the attribute list, in which case we indent to
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
182 " the same level as the first line.
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
183 let [name, end] = s:lex(line, end)
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
184 if name == ""
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
185 " TODO: Should use s:lex here on getline(v:lnum) and check for >.
11160
d0a20101ecb2 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11062
diff changeset
186 return getline(v:lnum) =~ '^\s*>' ? indent : (indent + shiftwidth())
1698
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
187 elseif name == ">"
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
188 return indent
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
189 endif
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
190
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
191 " Check for attribute value declaration. If none exists, indent two
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
192 " levels. Otherwise, if it’s an enumerated value, check for nested
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
193 " parentheses and indent to the innermost one if we don’t reach the end
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
194 " of the listc. Otherwise, just continue with looking for the default
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
195 " attribute value.
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
196 " TODO: Do validation of keywords
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
197 " (CDATA|NMTOKEN|NMTOKENS|ID|IDREF|IDREFS|ENTITY|ENTITIES)?
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
198 let [value, end] = s:lex(line, end, '^\%((\|[^[:space:]]\+\)')
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
199 if value == ""
11160
d0a20101ecb2 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11062
diff changeset
200 return indent + shiftwidth() * 2
1698
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
201 elseif value == 'NOTATION'
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
202 " If this is a enumerated value based on notations, read another token
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
203 " for the actual value. If it doesn’t exist, indent three levels.
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
204 " TODO: If validating according to above, value must be equal to '('.
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
205 let [value, end] = s:lex(line, end, '^\%((\|[^[:space:]]\+\)')
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
206 if value == ""
11160
d0a20101ecb2 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11062
diff changeset
207 return indent + shiftwidth() * 3
1698
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
208 endif
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
209 endif
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
210
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
211 if value == '('
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
212 let [indent_of_innermost, end] = s:indent_to_innermost_parentheses(line, end)
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
213 if indent_of_innermost != -1
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
214 return indent_of_innermost
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
215 endif
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
216 endif
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
217
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
218 " Finally look for the attribute’s default value. If non exists, indent
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
219 " two levels.
2587
d0049ff5969e Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 1698
diff changeset
220 let [default, end] = s:lex(line, end, '^\%("\_[^"]*"\|#\(REQUIRED\|IMPLIED\|FIXED\)\)')
1698
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
221 if default == ""
11160
d0a20101ecb2 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11062
diff changeset
222 return indent + shiftwidth() * 2
1698
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
223 elseif default == '#FIXED'
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
224 " We need to look for the fixed value. If non exists, indent three
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
225 " levels.
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
226 let [default, end] = s:lex(line, end, '^"\_[^"]*"')
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
227 if default == ""
11160
d0a20101ecb2 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11062
diff changeset
228 return indent + shiftwidth() * 3
1698
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
229 endif
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
230 endif
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
231 endwhile
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
232 elseif declaration == 'ENTITY'
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
233 " Check for entity name. If none exists, indent one level. Otherwise, if
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
234 " the name actually turns out to be a percent sign, “%”, this is a
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
235 " parameter entity. Read another token to determine the entity name and,
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
236 " again, if none exists, indent one level.
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
237 let [name, end] = s:lex(line, end)
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
238 if name == ""
11160
d0a20101ecb2 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11062
diff changeset
239 return indent + shiftwidth()
1698
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
240 elseif name == '%'
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
241 let [name, end] = s:lex(line, end)
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
242 if name == ""
11160
d0a20101ecb2 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11062
diff changeset
243 return indent + shiftwidth()
1698
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
244 endif
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
245 endif
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
246
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
247 " Now check for the entity value. If none exists, indent one level. If it
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
248 " does exist, indent to same level as first line, as we’re now done with
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
249 " this entity.
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
250 "
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
251 " The entity value can be a string in single or double quotes (no escapes
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
252 " to worry about, as entities are used instead). However, it can also be
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
253 " that this is an external unparsed entity. In that case we have to look
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
254 " further for (possibly) a public ID and an URI followed by the NDATA
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
255 " keyword and the actual notation name. For the public ID and URI, indent
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
256 " two levels, if they don’t exist. If the NDATA keyword doesn’t exist,
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
257 " indent one level. Otherwise, if the actual notation name doesn’t exist,
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
258 " indent two level. If it does, indent to same level as first line, as
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
259 " we’re now done with this entity.
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
260 let [value, end] = s:lex(line, end)
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
261 if value == ""
11160
d0a20101ecb2 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11062
diff changeset
262 return indent + shiftwidth()
1698
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
263 elseif value == 'SYSTEM' || value == 'PUBLIC'
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
264 let [quoted_string, end] = s:lex(line, end, '\%("[^"]\+"\|''[^'']\+''\)')
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
265 if quoted_string == ""
11160
d0a20101ecb2 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11062
diff changeset
266 return indent + shiftwidth() * 2
1698
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
267 endif
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
268
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
269 if value == 'PUBLIC'
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
270 let [quoted_string, end] = s:lex(line, end, '\%("[^"]\+"\|''[^'']\+''\)')
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
271 if quoted_string == ""
11160
d0a20101ecb2 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11062
diff changeset
272 return indent + shiftwidth() * 2
1698
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
273 endif
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
274 endif
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
275
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
276 let [ndata, end] = s:lex(line, end)
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
277 if ndata == ""
11160
d0a20101ecb2 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11062
diff changeset
278 return indent + shiftwidth()
1698
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
279 endif
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
280
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
281 let [name, end] = s:lex(line, end)
11160
d0a20101ecb2 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11062
diff changeset
282 return name == "" ? (indent + shiftwidth() * 2) : indent
1698
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
283 else
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
284 return indent
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
285 endif
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
286 elseif declaration == 'NOTATION'
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
287 " Check for notation name. If none exists, indent one level.
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
288 let [name, end] = s:lex(line, end)
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
289 if name == ""
11160
d0a20101ecb2 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11062
diff changeset
290 return indent + shiftwidth()
1698
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
291 endif
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
292
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
293 " Now check for the external ID. If none exists, indent one level.
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
294 let [id, end] = s:lex(line, end)
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
295 if id == ""
11160
d0a20101ecb2 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11062
diff changeset
296 return indent + shiftwidth()
1698
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
297 elseif id == 'SYSTEM' || id == 'PUBLIC'
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
298 let [quoted_string, end] = s:lex(line, end, '\%("[^"]\+"\|''[^'']\+''\)')
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
299 if quoted_string == ""
11160
d0a20101ecb2 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11062
diff changeset
300 return indent + shiftwidth() * 2
1698
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
301 endif
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
302
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
303 if id == 'PUBLIC'
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
304 let [quoted_string, end] = s:lex(line, end, '\%("[^"]\+"\|''[^'']\+''\|>\)')
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
305 if quoted_string == ""
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
306 " TODO: Should use s:lex here on getline(v:lnum) and check for >.
11160
d0a20101ecb2 Update runtime files.
Christian Brabandt <cb@256bit.org>
parents: 11062
diff changeset
307 return getline(v:lnum) =~ '^\s*>' ? indent : (indent + shiftwidth() * 2)
1698
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
308 elseif quoted_string == '>'
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
309 return indent
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
310 endif
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
311 endif
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
312 endif
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
313
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
314 return indent
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
315 endif
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
316
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
317 " TODO: Processing directives could be indented I suppose. But perhaps it’s
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
318 " just as well to let the user decide how to indent them (perhaps extending
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
319 " this function to include proper support for whatever processing directive
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
320 " language they want to use).
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
321
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
322 " Conditional sections are simply passed along to let Vim decide what to do
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
323 " (and hence the user).
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
324 return -1
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
325 endfunction
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
326
f4f8014d516e updated for version 7.2c-000
vimboss
parents:
diff changeset
327 let &cpo = s:cpo_save
3445
2cfb68fa26cd Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 2965
diff changeset
328 unlet s:cpo_save