annotate runtime/autoload/xmlcomplete.vim @ 841:c2cae213194d v7.0e07

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