annotate runtime/autoload/xmlcomplete.vim @ 20835:097884058719

Added tag v8.2.0969 for changeset 9a624c1672a31f5dd77a4b200fd2e2459ef036c3
author Bram Moolenaar <Bram@vim.org>
date Sat, 13 Jun 2020 15:15:04 +0200
parents c458ff35497e
children 11b656e74444
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
557
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
1 " Vim completion script
644
e4fa26ce8769 updated for version 7.0187
vimboss
parents: 574
diff changeset
2 " Language: XML
557
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
3 " Maintainer: Mikolaj Machowski ( mikmach AT wp DOT pl )
5055
c458ff35497e Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 1620
diff changeset
4 " Last Change: 2013 Jun 29
1620
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
5 " Version: 1.9
1121
e63691e7c504 updated for version 7.1a
vimboss
parents: 856
diff changeset
6 "
e63691e7c504 updated for version 7.1a
vimboss
parents: 856
diff changeset
7 " Changelog:
1620
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
8 " 1.9 - 2007 Aug 15
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
9 " - fix closing of namespaced tags (Johannes Weiss)
1121
e63691e7c504 updated for version 7.1a
vimboss
parents: 856
diff changeset
10 " 1.8 - 2006 Jul 18
e63691e7c504 updated for version 7.1a
vimboss
parents: 856
diff changeset
11 " - allow for closing of xml tags even when data file isn't available
557
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
12
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
13 " This function will create Dictionary with users namespace strings and values
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
14 " canonical (system) names of data files. Names should be lowercase,
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
15 " descriptive to avoid any future conflicts. For example 'xhtml10s' should be
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
16 " name for data of XHTML 1.0 Strict and 'xhtml10t' for XHTML 1.0 Transitional
819
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 785
diff changeset
17 " User interface will be provided by XMLns command defined in ftplugin/xml.vim
557
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
18 " Currently supported canonicals are:
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
19 " xhtml10s - XHTML 1.0 Strict
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
20 " xsl - XSL
827
fd1b3406fd1c updated for version 7.0d02
vimboss
parents: 819
diff changeset
21 function! xmlcomplete#CreateConnection(canonical, ...) " {{{
557
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
22
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
23 " When only one argument provided treat name as default namespace (without
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
24 " 'prefix:').
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
25 if exists("a:1")
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
26 let users = a:1
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
27 else
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
28 let users = 'DEFAULT'
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
29 endif
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
30
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
31 " Source data file. Due to suspected errors in autoload do it with
856
8cd729851562 updated for version 7.0g
vimboss
parents: 837
diff changeset
32 " :runtime.
557
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
33 " TODO: make it properly (using autoload, that is) later
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
34 exe "runtime autoload/xml/".a:canonical.".vim"
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
35
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
36 " Remove all traces of unexisting files to return [] when trying
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
37 " omnicomplete something
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
38 " TODO: give warning about non-existing canonicals - should it be?
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
39 if !exists("g:xmldata_".a:canonical)
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
40 unlet! g:xmldata_connection
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
41 return 0
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
42 endif
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
43
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
44 " We need to initialize Dictionary to add key-value pair
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
45 if !exists("g:xmldata_connection")
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
46 let g:xmldata_connection = {}
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
47 endif
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
48
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
49 let g:xmldata_connection[users] = a:canonical
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
50
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
51 endfunction
827
fd1b3406fd1c updated for version 7.0d02
vimboss
parents: 819
diff changeset
52 " }}}
557
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
53
827
fd1b3406fd1c updated for version 7.0d02
vimboss
parents: 819
diff changeset
54 function! xmlcomplete#CreateEntConnection(...) " {{{
557
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
55 if a:0 > 0
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
56 let g:xmldata_entconnect = a:1
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
57 else
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
58 let g:xmldata_entconnect = 'DEFAULT'
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
59 endif
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
60 endfunction
827
fd1b3406fd1c updated for version 7.0d02
vimboss
parents: 819
diff changeset
61 " }}}
557
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
62
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
63 function! xmlcomplete#CompleteTags(findstart, base)
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
64 if a:findstart
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
65 " locate the start of the word
644
e4fa26ce8769 updated for version 7.0187
vimboss
parents: 574
diff changeset
66 let curline = line('.')
557
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
67 let line = getline('.')
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
68 let start = col('.') - 1
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
69 let compl_begin = col('.') - 2
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
70
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
71 while start >= 0 && line[start - 1] =~ '\(\k\|[:.-]\)'
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
72 let start -= 1
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
73 endwhile
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
74
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
75 if start >= 0 && line[start - 1] =~ '&'
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
76 let b:entitiescompl = 1
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
77 let b:compl_context = ''
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
78 return start
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
79 endif
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
80
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
81 let b:compl_context = getline('.')[0:(compl_begin)]
644
e4fa26ce8769 updated for version 7.0187
vimboss
parents: 574
diff changeset
82 if b:compl_context !~ '<[^>]*$'
e4fa26ce8769 updated for version 7.0187
vimboss
parents: 574
diff changeset
83 " Look like we may have broken tag. Check previous lines. Up to
e4fa26ce8769 updated for version 7.0187
vimboss
parents: 574
diff changeset
84 " 10?
e4fa26ce8769 updated for version 7.0187
vimboss
parents: 574
diff changeset
85 let i = 1
e4fa26ce8769 updated for version 7.0187
vimboss
parents: 574
diff changeset
86 while 1
e4fa26ce8769 updated for version 7.0187
vimboss
parents: 574
diff changeset
87 let context_line = getline(curline-i)
e4fa26ce8769 updated for version 7.0187
vimboss
parents: 574
diff changeset
88 if context_line =~ '<[^>]*$'
e4fa26ce8769 updated for version 7.0187
vimboss
parents: 574
diff changeset
89 " Yep, this is this line
1121
e63691e7c504 updated for version 7.1a
vimboss
parents: 856
diff changeset
90 let context_lines = getline(curline-i, curline-1) + [b:compl_context]
644
e4fa26ce8769 updated for version 7.0187
vimboss
parents: 574
diff changeset
91 let b:compl_context = join(context_lines, ' ')
e4fa26ce8769 updated for version 7.0187
vimboss
parents: 574
diff changeset
92 break
785
fd60bacf955b updated for version 7.0229
vimboss
parents: 674
diff changeset
93 elseif context_line =~ '>[^<]*$' || i == curline
644
e4fa26ce8769 updated for version 7.0187
vimboss
parents: 574
diff changeset
94 " Normal tag line, no need for completion at all
785
fd60bacf955b updated for version 7.0229
vimboss
parents: 674
diff changeset
95 " OR reached first line without tag at all
644
e4fa26ce8769 updated for version 7.0187
vimboss
parents: 574
diff changeset
96 let b:compl_context = ''
e4fa26ce8769 updated for version 7.0187
vimboss
parents: 574
diff changeset
97 break
e4fa26ce8769 updated for version 7.0187
vimboss
parents: 574
diff changeset
98 endif
e4fa26ce8769 updated for version 7.0187
vimboss
parents: 574
diff changeset
99 let i += 1
e4fa26ce8769 updated for version 7.0187
vimboss
parents: 574
diff changeset
100 endwhile
e4fa26ce8769 updated for version 7.0187
vimboss
parents: 574
diff changeset
101 " Make sure we don't have counter
e4fa26ce8769 updated for version 7.0187
vimboss
parents: 574
diff changeset
102 unlet! i
e4fa26ce8769 updated for version 7.0187
vimboss
parents: 574
diff changeset
103 endif
e4fa26ce8769 updated for version 7.0187
vimboss
parents: 574
diff changeset
104 let b:compl_context = matchstr(b:compl_context, '.*\zs<.*')
557
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
105
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
106 " Make sure we will have only current namespace
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
107 unlet! b:xml_namespace
644
e4fa26ce8769 updated for version 7.0187
vimboss
parents: 574
diff changeset
108 let b:xml_namespace = matchstr(b:compl_context, '^<\zs\k*\ze:')
557
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
109 if b:xml_namespace == ''
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
110 let b:xml_namespace = 'DEFAULT'
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
111 endif
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
112
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
113 return start
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
114
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
115 else
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
116 " Initialize base return lists
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
117 let res = []
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
118 let res2 = []
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
119 " a:base is very short - we need context
644
e4fa26ce8769 updated for version 7.0187
vimboss
parents: 574
diff changeset
120 if len(b:compl_context) == 0 && !exists("b:entitiescompl")
e4fa26ce8769 updated for version 7.0187
vimboss
parents: 574
diff changeset
121 return []
e4fa26ce8769 updated for version 7.0187
vimboss
parents: 574
diff changeset
122 endif
e4fa26ce8769 updated for version 7.0187
vimboss
parents: 574
diff changeset
123 let context = matchstr(b:compl_context, '^<\zs.*')
557
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
124 unlet! b:compl_context
1121
e63691e7c504 updated for version 7.1a
vimboss
parents: 856
diff changeset
125 " There is no connection of namespace and data file.
e63691e7c504 updated for version 7.1a
vimboss
parents: 856
diff changeset
126 if !exists("g:xmldata_connection") || g:xmldata_connection == {}
e63691e7c504 updated for version 7.1a
vimboss
parents: 856
diff changeset
127 " There is still possibility we may do something - eg. close tag
e63691e7c504 updated for version 7.1a
vimboss
parents: 856
diff changeset
128 let b:unaryTagsStack = "base meta link hr br param img area input col"
e63691e7c504 updated for version 7.1a
vimboss
parents: 856
diff changeset
129 if context =~ '^\/'
e63691e7c504 updated for version 7.1a
vimboss
parents: 856
diff changeset
130 let opentag = xmlcomplete#GetLastOpenTag("b:unaryTagsStack")
e63691e7c504 updated for version 7.1a
vimboss
parents: 856
diff changeset
131 return [opentag.">"]
e63691e7c504 updated for version 7.1a
vimboss
parents: 856
diff changeset
132 else
e63691e7c504 updated for version 7.1a
vimboss
parents: 856
diff changeset
133 return []
e63691e7c504 updated for version 7.1a
vimboss
parents: 856
diff changeset
134 endif
e63691e7c504 updated for version 7.1a
vimboss
parents: 856
diff changeset
135 endif
557
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
136
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
137 " Make entities completion
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
138 if exists("b:entitiescompl")
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
139 unlet! b:entitiescompl
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
140
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
141 if !exists("g:xmldata_entconnect") || g:xmldata_entconnect == 'DEFAULT'
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
142 let values = g:xmldata{'_'.g:xmldata_connection['DEFAULT']}['vimxmlentities']
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
143 else
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
144 let values = g:xmldata{'_'.g:xmldata_entconnect}['vimxmlentities']
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
145 endif
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
146
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
147 " Get only lines with entity declarations but throw out
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
148 " parameter-entities - they may be completed in future
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
149 let entdecl = filter(getline(1, "$"), 'v:val =~ "<!ENTITY\\s\\+[^%]"')
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
150
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
151 if len(entdecl) > 0
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
152 let intent = map(copy(entdecl), 'matchstr(v:val, "<!ENTITY\\s\\+\\zs\\(\\k\\|[.-:]\\)\\+\\ze")')
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
153 let values = intent + values
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
154 endif
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
155
644
e4fa26ce8769 updated for version 7.0187
vimboss
parents: 574
diff changeset
156 if len(a:base) == 1
e4fa26ce8769 updated for version 7.0187
vimboss
parents: 574
diff changeset
157 for m in values
e4fa26ce8769 updated for version 7.0187
vimboss
parents: 574
diff changeset
158 if m =~ '^'.a:base
e4fa26ce8769 updated for version 7.0187
vimboss
parents: 574
diff changeset
159 call add(res, m.';')
e4fa26ce8769 updated for version 7.0187
vimboss
parents: 574
diff changeset
160 endif
e4fa26ce8769 updated for version 7.0187
vimboss
parents: 574
diff changeset
161 endfor
e4fa26ce8769 updated for version 7.0187
vimboss
parents: 574
diff changeset
162 return res
e4fa26ce8769 updated for version 7.0187
vimboss
parents: 574
diff changeset
163 else
e4fa26ce8769 updated for version 7.0187
vimboss
parents: 574
diff changeset
164 for m in values
e4fa26ce8769 updated for version 7.0187
vimboss
parents: 574
diff changeset
165 if m =~? '^'.a:base
e4fa26ce8769 updated for version 7.0187
vimboss
parents: 574
diff changeset
166 call add(res, m.';')
e4fa26ce8769 updated for version 7.0187
vimboss
parents: 574
diff changeset
167 elseif m =~? a:base
e4fa26ce8769 updated for version 7.0187
vimboss
parents: 574
diff changeset
168 call add(res2, m.';')
e4fa26ce8769 updated for version 7.0187
vimboss
parents: 574
diff changeset
169 endif
e4fa26ce8769 updated for version 7.0187
vimboss
parents: 574
diff changeset
170 endfor
557
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
171
644
e4fa26ce8769 updated for version 7.0187
vimboss
parents: 574
diff changeset
172 return res + res2
e4fa26ce8769 updated for version 7.0187
vimboss
parents: 574
diff changeset
173 endif
557
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
174
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
175 endif
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
176 if context =~ '>'
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
177 " Generally if context contains > it means we are outside of tag and
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
178 " should abandon action
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
179 return []
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
180 endif
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
181
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
182 " find tags matching with "a:base"
856
8cd729851562 updated for version 7.0g
vimboss
parents: 837
diff changeset
183 " If a:base contains white space it is attribute.
557
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
184 " It could be also value of attribute...
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
185 " We have to get first word to offer
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
186 " proper completions
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
187 if context == ''
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
188 let tag = ''
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
189 else
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
190 let tag = split(context)[0]
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
191 endif
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
192 " Get rid of namespace
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
193 let tag = substitute(tag, '^'.b:xml_namespace.':', '', '')
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
194
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
195
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
196 " Get last word, it should be attr name
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
197 let attr = matchstr(context, '.*\s\zs.*')
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
198 " Possible situations where any prediction would be difficult:
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
199 " 1. Events attributes
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
200 if context =~ '\s'
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
201
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
202 " If attr contains =\s*[\"'] we catched value of attribute
837
6bb1fa855dc9 updated for version 7.0e03
vimboss
parents: 827
diff changeset
203 if attr =~ "=\s*[\"']" || attr =~ "=\s*$"
557
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
204 " Let do attribute specific completion
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
205 let attrname = matchstr(attr, '.*\ze\s*=')
837
6bb1fa855dc9 updated for version 7.0e03
vimboss
parents: 827
diff changeset
206 let entered_value = matchstr(attr, ".*=\\s*[\"']\\?\\zs.*")
557
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
207
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
208 if tag =~ '^[?!]'
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
209 " Return nothing if we are inside of ! or ? tag
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
210 return []
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
211 else
837
6bb1fa855dc9 updated for version 7.0e03
vimboss
parents: 827
diff changeset
212 if has_key(g:xmldata{'_'.g:xmldata_connection[b:xml_namespace]}, tag) && has_key(g:xmldata{'_'.g:xmldata_connection[b:xml_namespace]}[tag][1], attrname)
6bb1fa855dc9 updated for version 7.0e03
vimboss
parents: 827
diff changeset
213 let values = g:xmldata{'_'.g:xmldata_connection[b:xml_namespace]}[tag][1][attrname]
6bb1fa855dc9 updated for version 7.0e03
vimboss
parents: 827
diff changeset
214 else
6bb1fa855dc9 updated for version 7.0e03
vimboss
parents: 827
diff changeset
215 return []
6bb1fa855dc9 updated for version 7.0e03
vimboss
parents: 827
diff changeset
216 endif
557
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
217 endif
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
218
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
219 if len(values) == 0
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
220 return []
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
221 endif
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
222
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
223 " We need special version of sbase
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
224 let attrbase = matchstr(context, ".*[\"']")
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
225 let attrquote = matchstr(attrbase, '.$')
837
6bb1fa855dc9 updated for version 7.0e03
vimboss
parents: 827
diff changeset
226 if attrquote !~ "['\"]"
6bb1fa855dc9 updated for version 7.0e03
vimboss
parents: 827
diff changeset
227 let attrquoteopen = '"'
6bb1fa855dc9 updated for version 7.0e03
vimboss
parents: 827
diff changeset
228 let attrquote = '"'
6bb1fa855dc9 updated for version 7.0e03
vimboss
parents: 827
diff changeset
229 else
6bb1fa855dc9 updated for version 7.0e03
vimboss
parents: 827
diff changeset
230 let attrquoteopen = ''
6bb1fa855dc9 updated for version 7.0e03
vimboss
parents: 827
diff changeset
231 endif
557
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
232
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
233 for m in values
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
234 " This if is needed to not offer all completions as-is
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
235 " alphabetically but sort them. Those beginning with entered
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
236 " part will be as first choices
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
237 if m =~ '^'.entered_value
837
6bb1fa855dc9 updated for version 7.0e03
vimboss
parents: 827
diff changeset
238 call add(res, attrquoteopen . m . attrquote.' ')
557
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
239 elseif m =~ entered_value
837
6bb1fa855dc9 updated for version 7.0e03
vimboss
parents: 827
diff changeset
240 call add(res2, attrquoteopen . m . attrquote.' ')
557
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
241 endif
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
242 endfor
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
243
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
244 return res + res2
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
245
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
246 endif
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
247
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
248 if tag =~ '?xml'
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
249 " Two possible arguments for <?xml> plus variation
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
250 let attrs = ['encoding', 'version="1.0"', 'version']
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
251 elseif tag =~ '^!'
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
252 " Don't make completion at all
819
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 785
diff changeset
253 "
557
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
254 return []
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
255 else
819
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 785
diff changeset
256 if !has_key(g:xmldata{'_'.g:xmldata_connection[b:xml_namespace]}, tag)
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 785
diff changeset
257 " Abandon when data file isn't complete
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 785
diff changeset
258 return []
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 785
diff changeset
259 endif
557
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
260 let attrs = keys(g:xmldata{'_'.g:xmldata_connection[b:xml_namespace]}[tag][1])
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
261 endif
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
262
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
263 for m in sort(attrs)
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
264 if m =~ '^'.attr
667
9090f866cd57 updated for version 7.0197
vimboss
parents: 659
diff changeset
265 call add(res, m)
557
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
266 elseif m =~ attr
667
9090f866cd57 updated for version 7.0197
vimboss
parents: 659
diff changeset
267 call add(res2, m)
557
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
268 endif
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
269 endfor
667
9090f866cd57 updated for version 7.0197
vimboss
parents: 659
diff changeset
270 let menu = res + res2
9090f866cd57 updated for version 7.0197
vimboss
parents: 659
diff changeset
271 let final_menu = []
9090f866cd57 updated for version 7.0197
vimboss
parents: 659
diff changeset
272 if has_key(g:xmldata{'_'.g:xmldata_connection[b:xml_namespace]}, 'vimxmlattrinfo')
9090f866cd57 updated for version 7.0197
vimboss
parents: 659
diff changeset
273 for i in range(len(menu))
9090f866cd57 updated for version 7.0197
vimboss
parents: 659
diff changeset
274 let item = menu[i]
9090f866cd57 updated for version 7.0197
vimboss
parents: 659
diff changeset
275 if has_key(g:xmldata{'_'.g:xmldata_connection[b:xml_namespace]}['vimxmlattrinfo'], item)
9090f866cd57 updated for version 7.0197
vimboss
parents: 659
diff changeset
276 let m_menu = g:xmldata{'_'.g:xmldata_connection[b:xml_namespace]}['vimxmlattrinfo'][item][0]
9090f866cd57 updated for version 7.0197
vimboss
parents: 659
diff changeset
277 let m_info = g:xmldata{'_'.g:xmldata_connection[b:xml_namespace]}['vimxmlattrinfo'][item][1]
9090f866cd57 updated for version 7.0197
vimboss
parents: 659
diff changeset
278 else
9090f866cd57 updated for version 7.0197
vimboss
parents: 659
diff changeset
279 let m_menu = ''
9090f866cd57 updated for version 7.0197
vimboss
parents: 659
diff changeset
280 let m_info = ''
9090f866cd57 updated for version 7.0197
vimboss
parents: 659
diff changeset
281 endif
9090f866cd57 updated for version 7.0197
vimboss
parents: 659
diff changeset
282 if tag !~ '^[?!]' && len(g:xmldata{'_'.g:xmldata_connection[b:xml_namespace]}[tag][1][item]) > 0 && g:xmldata{'_'.g:xmldata_connection[b:xml_namespace]}[tag][1][item][0] =~ '^\(BOOL\|'.item.'\)$'
9090f866cd57 updated for version 7.0197
vimboss
parents: 659
diff changeset
283 let item = item
9090f866cd57 updated for version 7.0197
vimboss
parents: 659
diff changeset
284 else
9090f866cd57 updated for version 7.0197
vimboss
parents: 659
diff changeset
285 let item .= '="'
9090f866cd57 updated for version 7.0197
vimboss
parents: 659
diff changeset
286 endif
9090f866cd57 updated for version 7.0197
vimboss
parents: 659
diff changeset
287 let final_menu += [{'word':item, 'menu':m_menu, 'info':m_info}]
9090f866cd57 updated for version 7.0197
vimboss
parents: 659
diff changeset
288 endfor
9090f866cd57 updated for version 7.0197
vimboss
parents: 659
diff changeset
289 else
9090f866cd57 updated for version 7.0197
vimboss
parents: 659
diff changeset
290 for i in range(len(menu))
9090f866cd57 updated for version 7.0197
vimboss
parents: 659
diff changeset
291 let item = menu[i]
9090f866cd57 updated for version 7.0197
vimboss
parents: 659
diff changeset
292 if tag !~ '^[?!]' && len(g:xmldata{'_'.g:xmldata_connection[b:xml_namespace]}[tag][1][item]) > 0 && g:xmldata{'_'.g:xmldata_connection[b:xml_namespace]}[tag][1][item][0] =~ '^\(BOOL\|'.item.'\)$'
9090f866cd57 updated for version 7.0197
vimboss
parents: 659
diff changeset
293 let item = item
9090f866cd57 updated for version 7.0197
vimboss
parents: 659
diff changeset
294 else
9090f866cd57 updated for version 7.0197
vimboss
parents: 659
diff changeset
295 let item .= '="'
9090f866cd57 updated for version 7.0197
vimboss
parents: 659
diff changeset
296 endif
9090f866cd57 updated for version 7.0197
vimboss
parents: 659
diff changeset
297 let final_menu += [item]
9090f866cd57 updated for version 7.0197
vimboss
parents: 659
diff changeset
298 endfor
9090f866cd57 updated for version 7.0197
vimboss
parents: 659
diff changeset
299 endif
9090f866cd57 updated for version 7.0197
vimboss
parents: 659
diff changeset
300 return final_menu
557
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
301
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
302 endif
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
303 " Close tag
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
304 let b:unaryTagsStack = "base meta link hr br param img area input col"
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
305 if context =~ '^\/'
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
306 let opentag = xmlcomplete#GetLastOpenTag("b:unaryTagsStack")
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
307 return [opentag.">"]
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
308 endif
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
309
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
310 " Complete elements of XML structure
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
311 " TODO: #REQUIRED, #IMPLIED, #FIXED, #PCDATA - but these should be detected like
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
312 " entities - in first run
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
313 " keywords: CDATA, ID, IDREF, IDREFS, ENTITY, ENTITIES, NMTOKEN, NMTOKENS
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
314 " are hardly recognizable but keep it in reserve
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
315 " also: EMPTY ANY SYSTEM PUBLIC DATA
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
316 if context =~ '^!'
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
317 let tags = ['!ELEMENT', '!DOCTYPE', '!ATTLIST', '!ENTITY', '!NOTATION', '![CDATA[', '![INCLUDE[', '![IGNORE[']
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
318
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
319 for m in tags
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
320 if m =~ '^'.context
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
321 let m = substitute(m, '^!\[\?', '', '')
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
322 call add(res, m)
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
323 elseif m =~ context
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
324 let m = substitute(m, '^!\[\?', '', '')
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
325 call add(res2, m)
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
326 endif
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
327 endfor
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
328
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
329 return res + res2
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
330
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
331 endif
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
332
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
333 " Complete text declaration
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
334 if context =~ '^?'
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
335 let tags = ['?xml']
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
336
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
337 for m in tags
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
338 if m =~ '^'.context
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
339 call add(res, substitute(m, '^?', '', ''))
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
340 elseif m =~ context
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
341 call add(res, substitute(m, '^?', '', ''))
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
342 endif
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
343 endfor
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
344
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
345 return res + res2
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
346
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
347 endif
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
348
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
349 " Deal with tag completion.
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
350 let opentag = xmlcomplete#GetLastOpenTag("b:unaryTagsStack")
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
351 let opentag = substitute(opentag, '^\k*:', '', '')
644
e4fa26ce8769 updated for version 7.0187
vimboss
parents: 574
diff changeset
352 if opentag == ''
674
4b8583e82cb8 updated for version 7.0201
vimboss
parents: 667
diff changeset
353 "return []
4b8583e82cb8 updated for version 7.0201
vimboss
parents: 667
diff changeset
354 let tags = keys(g:xmldata{'_'.g:xmldata_connection[b:xml_namespace]})
4b8583e82cb8 updated for version 7.0201
vimboss
parents: 667
diff changeset
355 call filter(tags, 'v:val !~ "^vimxml"')
4b8583e82cb8 updated for version 7.0201
vimboss
parents: 667
diff changeset
356 else
827
fd1b3406fd1c updated for version 7.0d02
vimboss
parents: 819
diff changeset
357 if !has_key(g:xmldata{'_'.g:xmldata_connection[b:xml_namespace]}, opentag)
819
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 785
diff changeset
358 " Abandon when data file isn't complete
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 785
diff changeset
359 return []
23f82b5d2814 updated for version 7.0c10
vimboss
parents: 785
diff changeset
360 endif
674
4b8583e82cb8 updated for version 7.0201
vimboss
parents: 667
diff changeset
361 let tags = g:xmldata{'_'.g:xmldata_connection[b:xml_namespace]}[opentag][0]
644
e4fa26ce8769 updated for version 7.0187
vimboss
parents: 574
diff changeset
362 endif
557
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
363
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
364 let context = substitute(context, '^\k*:', '', '')
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
365
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
366 for m in tags
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
367 if m =~ '^'.context
667
9090f866cd57 updated for version 7.0197
vimboss
parents: 659
diff changeset
368 call add(res, m)
557
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
369 elseif m =~ context
667
9090f866cd57 updated for version 7.0197
vimboss
parents: 659
diff changeset
370 call add(res2, m)
557
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
371 endif
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
372 endfor
667
9090f866cd57 updated for version 7.0197
vimboss
parents: 659
diff changeset
373 let menu = res + res2
827
fd1b3406fd1c updated for version 7.0d02
vimboss
parents: 819
diff changeset
374 if b:xml_namespace == 'DEFAULT'
fd1b3406fd1c updated for version 7.0d02
vimboss
parents: 819
diff changeset
375 let xml_namespace = ''
fd1b3406fd1c updated for version 7.0d02
vimboss
parents: 819
diff changeset
376 else
fd1b3406fd1c updated for version 7.0d02
vimboss
parents: 819
diff changeset
377 let xml_namespace = b:xml_namespace.':'
fd1b3406fd1c updated for version 7.0d02
vimboss
parents: 819
diff changeset
378 endif
667
9090f866cd57 updated for version 7.0197
vimboss
parents: 659
diff changeset
379 if has_key(g:xmldata{'_'.g:xmldata_connection[b:xml_namespace]}, 'vimxmltaginfo')
9090f866cd57 updated for version 7.0197
vimboss
parents: 659
diff changeset
380 let final_menu = []
9090f866cd57 updated for version 7.0197
vimboss
parents: 659
diff changeset
381 for i in range(len(menu))
9090f866cd57 updated for version 7.0197
vimboss
parents: 659
diff changeset
382 let item = menu[i]
9090f866cd57 updated for version 7.0197
vimboss
parents: 659
diff changeset
383 if has_key(g:xmldata{'_'.g:xmldata_connection[b:xml_namespace]}['vimxmltaginfo'], item)
9090f866cd57 updated for version 7.0197
vimboss
parents: 659
diff changeset
384 let m_menu = g:xmldata{'_'.g:xmldata_connection[b:xml_namespace]}['vimxmltaginfo'][item][0]
9090f866cd57 updated for version 7.0197
vimboss
parents: 659
diff changeset
385 let m_info = g:xmldata{'_'.g:xmldata_connection[b:xml_namespace]}['vimxmltaginfo'][item][1]
9090f866cd57 updated for version 7.0197
vimboss
parents: 659
diff changeset
386 else
9090f866cd57 updated for version 7.0197
vimboss
parents: 659
diff changeset
387 let m_menu = ''
9090f866cd57 updated for version 7.0197
vimboss
parents: 659
diff changeset
388 let m_info = ''
9090f866cd57 updated for version 7.0197
vimboss
parents: 659
diff changeset
389 endif
9090f866cd57 updated for version 7.0197
vimboss
parents: 659
diff changeset
390 let final_menu += [{'word':xml_namespace.item, 'menu':m_menu, 'info':m_info}]
9090f866cd57 updated for version 7.0197
vimboss
parents: 659
diff changeset
391 endfor
9090f866cd57 updated for version 7.0197
vimboss
parents: 659
diff changeset
392 else
827
fd1b3406fd1c updated for version 7.0d02
vimboss
parents: 819
diff changeset
393 let final_menu = map(menu, 'xml_namespace.v:val')
667
9090f866cd57 updated for version 7.0197
vimboss
parents: 659
diff changeset
394 endif
827
fd1b3406fd1c updated for version 7.0d02
vimboss
parents: 819
diff changeset
395
667
9090f866cd57 updated for version 7.0197
vimboss
parents: 659
diff changeset
396 return final_menu
557
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
397
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
398 endif
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
399 endfunction
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
400
827
fd1b3406fd1c updated for version 7.0d02
vimboss
parents: 819
diff changeset
401 " MM: This is severely reduced closetag.vim used with kind permission of Steven
557
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
402 " Mueller
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
403 " Changes: strip all comments; delete error messages; add checking for
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
404 " namespace
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
405 " Author: Steven Mueller <diffusor@ugcs.caltech.edu>
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
406 " Last Modified: Tue May 24 13:29:48 PDT 2005
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
407 " Version: 0.9.1
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
408
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
409 function! xmlcomplete#GetLastOpenTag(unaryTagsStack)
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
410 let linenum=line('.')
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
411 let lineend=col('.') - 1 " start: cursor position
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
412 let first=1 " flag for first line searched
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
413 let b:TagStack='' " main stack of tags
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
414 let startInComment=s:InComment()
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
415
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
416 if exists("b:xml_namespace")
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
417 if b:xml_namespace == 'DEFAULT'
1620
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
418 let tagpat='</\=\(\k\|[.:-]\)\+\|/>'
557
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
419 else
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
420 let tagpat='</\='.b:xml_namespace.':\(\k\|[.-]\)\+\|/>'
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
421 endif
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
422 else
1620
73fe8baea242 updated for version 7.2a
vimboss
parents: 1121
diff changeset
423 let tagpat='</\=\(\k\|[.:-]\)\+\|/>'
557
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
424 endif
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
425 while (linenum>0)
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
426 let line=getline(linenum)
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
427 if first
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
428 let line=strpart(line,0,lineend)
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
429 else
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
430 let lineend=strlen(line)
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
431 endif
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
432 let b:lineTagStack=''
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
433 let mpos=0
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
434 let b:TagCol=0
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
435 while (mpos > -1)
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
436 let mpos=matchend(line,tagpat)
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
437 if mpos > -1
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
438 let b:TagCol=b:TagCol+mpos
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
439 let tag=matchstr(line,tagpat)
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
440
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
441 if exists('b:closetag_disable_synID') || startInComment==s:InCommentAt(linenum, b:TagCol)
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
442 let b:TagLine=linenum
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
443 call s:Push(matchstr(tag,'[^<>]\+'),'b:lineTagStack')
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
444 endif
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
445 let lineend=lineend-mpos
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
446 let line=strpart(line,mpos,lineend)
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
447 endif
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
448 endwhile
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
449 while (!s:EmptystackP('b:lineTagStack'))
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
450 let tag=s:Pop('b:lineTagStack')
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
451 if match(tag, '^/') == 0 "found end tag
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
452 call s:Push(tag,'b:TagStack')
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
453 elseif s:EmptystackP('b:TagStack') && !s:Instack(tag, a:unaryTagsStack) "found unclosed tag
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
454 return tag
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
455 else
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
456 let endtag=s:Peekstack('b:TagStack')
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
457 if endtag == '/'.tag || endtag == '/'
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
458 call s:Pop('b:TagStack') "found a open/close tag pair
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
459 elseif !s:Instack(tag, a:unaryTagsStack) "we have a mismatch error
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
460 return ''
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
461 endif
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
462 endif
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
463 endwhile
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
464 let linenum=linenum-1 | let first=0
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
465 endwhile
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
466 return ''
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
467 endfunction
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
468
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
469 function! s:InComment()
659
d6a69271cb9a updated for version 7.0194
vimboss
parents: 644
diff changeset
470 return synIDattr(synID(line('.'), col('.'), 0), 'name') =~ 'Comment\|String'
557
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
471 endfunction
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
472
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
473 function! s:InCommentAt(line, col)
659
d6a69271cb9a updated for version 7.0194
vimboss
parents: 644
diff changeset
474 return synIDattr(synID(a:line, a:col, 0), 'name') =~ 'Comment\|String'
557
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
475 endfunction
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
476
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
477 function! s:SetKeywords()
5055
c458ff35497e Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 1620
diff changeset
478 let s:IsKeywordBak=&l:iskeyword
c458ff35497e Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 1620
diff changeset
479 let &l:iskeyword='33-255'
557
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
480 endfunction
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
481
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
482 function! s:RestoreKeywords()
5055
c458ff35497e Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 1620
diff changeset
483 let &l:iskeyword=s:IsKeywordBak
557
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
484 endfunction
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
485
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
486 function! s:Push(el, sname)
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
487 if !s:EmptystackP(a:sname)
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
488 exe 'let '.a:sname."=a:el.' '.".a:sname
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
489 else
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
490 exe 'let '.a:sname.'=a:el'
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
491 endif
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
492 endfunction
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
493
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
494 function! s:EmptystackP(sname)
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
495 exe 'let stack='.a:sname
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
496 if match(stack,'^ *$') == 0
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
497 return 1
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
498 else
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
499 return 0
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
500 endif
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
501 endfunction
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
502
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
503 function! s:Instack(el, sname)
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
504 exe 'let stack='.a:sname
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
505 call s:SetKeywords()
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
506 let m=match(stack, '\<'.a:el.'\>')
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
507 call s:RestoreKeywords()
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
508 if m < 0
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
509 return 0
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
510 else
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
511 return 1
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
512 endif
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
513 endfunction
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
514
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
515 function! s:Peekstack(sname)
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
516 call s:SetKeywords()
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
517 exe 'let stack='.a:sname
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
518 let top=matchstr(stack, '\<.\{-1,}\>')
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
519 call s:RestoreKeywords()
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
520 return top
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
521 endfunction
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
522
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
523 function! s:Pop(sname)
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
524 if s:EmptystackP(a:sname)
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
525 return ''
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
526 endif
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
527 exe 'let stack='.a:sname
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
528 call s:SetKeywords()
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
529 let loc=matchend(stack,'\<.\{-1,}\>')
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
530 exe 'let '.a:sname.'=strpart(stack, loc+1, strlen(stack))'
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
531 let top=strpart(stack, match(stack, '\<'), loc)
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
532 call s:RestoreKeywords()
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
533 return top
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
534 endfunction
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
535
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
536 function! s:Clearstack(sname)
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
537 exe 'let '.a:sname."=''"
862863033fdd updated for version 7.0158
vimboss
parents:
diff changeset
538 endfunction
827
fd1b3406fd1c updated for version 7.0d02
vimboss
parents: 819
diff changeset
539 " vim:set foldmethod=marker: