annotate runtime/autoload/htmlcomplete.vim @ 3306:ded8f5add04c v7.3.420

updated for version 7.3.420 Problem: "it" and "at" don't work properly with a dash in the tag name. Solution: Require a space to match the tag name. (Christian Brabandt)
author Bram Moolenaar <bram@vim.org>
date Thu, 26 Jan 2012 20:58:26 +0100
parents 0877b8d6370e
children 7b83c190d370
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
523
a7ae7e043e43 updated for version 7.0146
vimboss
parents:
diff changeset
1 " Vim completion script
838
8e5830943bff updated for version 7.0e04
vimboss
parents: 837
diff changeset
2 " Language: HTML and XHTML
523
a7ae7e043e43 updated for version 7.0146
vimboss
parents:
diff changeset
3 " Maintainer: Mikolaj Machowski ( mikmach AT wp DOT pl )
2788
0877b8d6370e Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 1120
diff changeset
4 " Last Change: 2011 Apr 28
523
a7ae7e043e43 updated for version 7.0146
vimboss
parents:
diff changeset
5
a7ae7e043e43 updated for version 7.0146
vimboss
parents:
diff changeset
6 function! htmlcomplete#CompleteTags(findstart, base)
a7ae7e043e43 updated for version 7.0146
vimboss
parents:
diff changeset
7 if a:findstart
a7ae7e043e43 updated for version 7.0146
vimboss
parents:
diff changeset
8 " locate the start of the word
a7ae7e043e43 updated for version 7.0146
vimboss
parents:
diff changeset
9 let line = getline('.')
a7ae7e043e43 updated for version 7.0146
vimboss
parents:
diff changeset
10 let start = col('.') - 1
643
d3c978b4c7ce updated for version 7.0187
vimboss
parents: 641
diff changeset
11 let curline = line('.')
548
f43150a669dc updated for version 7.0155
vimboss
parents: 532
diff changeset
12 let compl_begin = col('.') - 2
841
c2cae213194d updated for version 7.0e07
vimboss
parents: 838
diff changeset
13 while start >= 0 && line[start - 1] =~ '\(\k\|[!:.-]\)'
548
f43150a669dc updated for version 7.0155
vimboss
parents: 532
diff changeset
14 let start -= 1
523
a7ae7e043e43 updated for version 7.0146
vimboss
parents:
diff changeset
15 endwhile
659
d6a69271cb9a updated for version 7.0194
vimboss
parents: 649
diff changeset
16 " Handling of entities {{{
548
f43150a669dc updated for version 7.0155
vimboss
parents: 532
diff changeset
17 if start >= 0 && line[start - 1] =~ '&'
f43150a669dc updated for version 7.0155
vimboss
parents: 532
diff changeset
18 let b:entitiescompl = 1
f43150a669dc updated for version 7.0155
vimboss
parents: 532
diff changeset
19 let b:compl_context = ''
f43150a669dc updated for version 7.0155
vimboss
parents: 532
diff changeset
20 return start
f43150a669dc updated for version 7.0155
vimboss
parents: 532
diff changeset
21 endif
659
d6a69271cb9a updated for version 7.0194
vimboss
parents: 649
diff changeset
22 " }}}
d6a69271cb9a updated for version 7.0194
vimboss
parents: 649
diff changeset
23 " Handling of <style> tag {{{
548
f43150a669dc updated for version 7.0155
vimboss
parents: 532
diff changeset
24 let stylestart = searchpair('<style\>', '', '<\/style\>', "bnW")
f43150a669dc updated for version 7.0155
vimboss
parents: 532
diff changeset
25 let styleend = searchpair('<style\>', '', '<\/style\>', "nW")
856
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
26 if stylestart != 0 && styleend != 0
643
d3c978b4c7ce updated for version 7.0187
vimboss
parents: 641
diff changeset
27 if stylestart <= curline && styleend >= curline
548
f43150a669dc updated for version 7.0155
vimboss
parents: 532
diff changeset
28 let start = col('.') - 1
f43150a669dc updated for version 7.0155
vimboss
parents: 532
diff changeset
29 let b:csscompl = 1
f43150a669dc updated for version 7.0155
vimboss
parents: 532
diff changeset
30 while start >= 0 && line[start - 1] =~ '\(\k\|-\)'
f43150a669dc updated for version 7.0155
vimboss
parents: 532
diff changeset
31 let start -= 1
f43150a669dc updated for version 7.0155
vimboss
parents: 532
diff changeset
32 endwhile
531
da9142bd190a updated for version 7.0149
vimboss
parents: 529
diff changeset
33 endif
da9142bd190a updated for version 7.0149
vimboss
parents: 529
diff changeset
34 endif
659
d6a69271cb9a updated for version 7.0194
vimboss
parents: 649
diff changeset
35 " }}}
d6a69271cb9a updated for version 7.0194
vimboss
parents: 649
diff changeset
36 " Handling of <script> tag {{{
649
8157079cea85 updated for version 7.0191
vimboss
parents: 643
diff changeset
37 let scriptstart = searchpair('<script\>', '', '<\/script\>', "bnW")
8157079cea85 updated for version 7.0191
vimboss
parents: 643
diff changeset
38 let scriptend = searchpair('<script\>', '', '<\/script\>', "nW")
856
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
39 if scriptstart != 0 && scriptend != 0
649
8157079cea85 updated for version 7.0191
vimboss
parents: 643
diff changeset
40 if scriptstart <= curline && scriptend >= curline
8157079cea85 updated for version 7.0191
vimboss
parents: 643
diff changeset
41 let start = col('.') - 1
8157079cea85 updated for version 7.0191
vimboss
parents: 643
diff changeset
42 let b:jscompl = 1
8157079cea85 updated for version 7.0191
vimboss
parents: 643
diff changeset
43 let b:jsrange = [scriptstart, scriptend]
667
9090f866cd57 updated for version 7.0197
vimboss
parents: 659
diff changeset
44 while start >= 0 && line[start - 1] =~ '\k'
649
8157079cea85 updated for version 7.0191
vimboss
parents: 643
diff changeset
45 let start -= 1
8157079cea85 updated for version 7.0191
vimboss
parents: 643
diff changeset
46 endwhile
659
d6a69271cb9a updated for version 7.0194
vimboss
parents: 649
diff changeset
47 " We are inside of <script> tag. But we should also get contents
d6a69271cb9a updated for version 7.0194
vimboss
parents: 649
diff changeset
48 " of all linked external files and (secondary, less probably) other <script> tags
d6a69271cb9a updated for version 7.0194
vimboss
parents: 649
diff changeset
49 " This logic could possible be done in separate function - may be
d6a69271cb9a updated for version 7.0194
vimboss
parents: 649
diff changeset
50 " reused in events scripting (also with option could be reused for
d6a69271cb9a updated for version 7.0194
vimboss
parents: 649
diff changeset
51 " CSS
d6a69271cb9a updated for version 7.0194
vimboss
parents: 649
diff changeset
52 let b:js_extfiles = []
d6a69271cb9a updated for version 7.0194
vimboss
parents: 649
diff changeset
53 let l = line('.')
d6a69271cb9a updated for version 7.0194
vimboss
parents: 649
diff changeset
54 let c = col('.')
d6a69271cb9a updated for version 7.0194
vimboss
parents: 649
diff changeset
55 call cursor(1,1)
d6a69271cb9a updated for version 7.0194
vimboss
parents: 649
diff changeset
56 while search('<\@<=script\>', 'W') && line('.') <= l
d6a69271cb9a updated for version 7.0194
vimboss
parents: 649
diff changeset
57 if synIDattr(synID(line('.'),col('.')-1,0),"name") !~? 'comment'
d6a69271cb9a updated for version 7.0194
vimboss
parents: 649
diff changeset
58 let sname = matchstr(getline('.'), '<script[^>]*src\s*=\s*\([''"]\)\zs.\{-}\ze\1')
d6a69271cb9a updated for version 7.0194
vimboss
parents: 649
diff changeset
59 if filereadable(sname)
d6a69271cb9a updated for version 7.0194
vimboss
parents: 649
diff changeset
60 let b:js_extfiles += readfile(sname)
d6a69271cb9a updated for version 7.0194
vimboss
parents: 649
diff changeset
61 endif
d6a69271cb9a updated for version 7.0194
vimboss
parents: 649
diff changeset
62 endif
d6a69271cb9a updated for version 7.0194
vimboss
parents: 649
diff changeset
63 endwhile
d6a69271cb9a updated for version 7.0194
vimboss
parents: 649
diff changeset
64 call cursor(1,1)
d6a69271cb9a updated for version 7.0194
vimboss
parents: 649
diff changeset
65 let js_scripttags = []
d6a69271cb9a updated for version 7.0194
vimboss
parents: 649
diff changeset
66 while search('<script\>', 'W') && line('.') < l
d6a69271cb9a updated for version 7.0194
vimboss
parents: 649
diff changeset
67 if matchstr(getline('.'), '<script[^>]*src') == ''
d6a69271cb9a updated for version 7.0194
vimboss
parents: 649
diff changeset
68 let js_scripttag = getline(line('.'), search('</script>', 'W'))
d6a69271cb9a updated for version 7.0194
vimboss
parents: 649
diff changeset
69 let js_scripttags += js_scripttag
d6a69271cb9a updated for version 7.0194
vimboss
parents: 649
diff changeset
70 endif
d6a69271cb9a updated for version 7.0194
vimboss
parents: 649
diff changeset
71 endwhile
d6a69271cb9a updated for version 7.0194
vimboss
parents: 649
diff changeset
72 let b:js_extfiles += js_scripttags
d6a69271cb9a updated for version 7.0194
vimboss
parents: 649
diff changeset
73 call cursor(l,c)
d6a69271cb9a updated for version 7.0194
vimboss
parents: 649
diff changeset
74 unlet! l c
649
8157079cea85 updated for version 7.0191
vimboss
parents: 643
diff changeset
75 endif
8157079cea85 updated for version 7.0191
vimboss
parents: 643
diff changeset
76 endif
659
d6a69271cb9a updated for version 7.0194
vimboss
parents: 649
diff changeset
77 " }}}
649
8157079cea85 updated for version 7.0191
vimboss
parents: 643
diff changeset
78 if !exists("b:csscompl") && !exists("b:jscompl")
548
f43150a669dc updated for version 7.0155
vimboss
parents: 532
diff changeset
79 let b:compl_context = getline('.')[0:(compl_begin)]
643
d3c978b4c7ce updated for version 7.0187
vimboss
parents: 641
diff changeset
80 if b:compl_context !~ '<[^>]*$'
659
d6a69271cb9a updated for version 7.0194
vimboss
parents: 649
diff changeset
81 " Look like we may have broken tag. Check previous lines.
643
d3c978b4c7ce updated for version 7.0187
vimboss
parents: 641
diff changeset
82 let i = 1
d3c978b4c7ce updated for version 7.0187
vimboss
parents: 641
diff changeset
83 while 1
d3c978b4c7ce updated for version 7.0187
vimboss
parents: 641
diff changeset
84 let context_line = getline(curline-i)
d3c978b4c7ce updated for version 7.0187
vimboss
parents: 641
diff changeset
85 if context_line =~ '<[^>]*$'
d3c978b4c7ce updated for version 7.0187
vimboss
parents: 641
diff changeset
86 " Yep, this is this line
1120
e6db096b07a1 updated for version 7.1a
vimboss
parents: 856
diff changeset
87 let context_lines = getline(curline-i, curline-1) + [b:compl_context]
643
d3c978b4c7ce updated for version 7.0187
vimboss
parents: 641
diff changeset
88 let b:compl_context = join(context_lines, ' ')
d3c978b4c7ce updated for version 7.0187
vimboss
parents: 641
diff changeset
89 break
784
1cc5f2c523ee updated for version 7.0229
vimboss
parents: 714
diff changeset
90 elseif context_line =~ '>[^<]*$' || i == curline
1cc5f2c523ee updated for version 7.0229
vimboss
parents: 714
diff changeset
91 " We are in normal tag line, no need for completion at all
1cc5f2c523ee updated for version 7.0229
vimboss
parents: 714
diff changeset
92 " OR reached first line without tag at all
643
d3c978b4c7ce updated for version 7.0187
vimboss
parents: 641
diff changeset
93 let b:compl_context = ''
d3c978b4c7ce updated for version 7.0187
vimboss
parents: 641
diff changeset
94 break
d3c978b4c7ce updated for version 7.0187
vimboss
parents: 641
diff changeset
95 endif
d3c978b4c7ce updated for version 7.0187
vimboss
parents: 641
diff changeset
96 let i += 1
d3c978b4c7ce updated for version 7.0187
vimboss
parents: 641
diff changeset
97 endwhile
d3c978b4c7ce updated for version 7.0187
vimboss
parents: 641
diff changeset
98 " Make sure we don't have counter
d3c978b4c7ce updated for version 7.0187
vimboss
parents: 641
diff changeset
99 unlet! i
d3c978b4c7ce updated for version 7.0187
vimboss
parents: 641
diff changeset
100 endif
641
6a944e0bd5d2 updated for version 7.0186
vimboss
parents: 573
diff changeset
101 let b:compl_context = matchstr(b:compl_context, '.*\zs<.*')
784
1cc5f2c523ee updated for version 7.0229
vimboss
parents: 714
diff changeset
102
659
d6a69271cb9a updated for version 7.0194
vimboss
parents: 649
diff changeset
103 " Return proper start for on-events. Without that beginning of
d6a69271cb9a updated for version 7.0194
vimboss
parents: 649
diff changeset
104 " completion will be badly reported
d6a69271cb9a updated for version 7.0194
vimboss
parents: 649
diff changeset
105 if b:compl_context =~? 'on[a-z]*\s*=\s*\(''[^'']*\|"[^"]*\)$'
d6a69271cb9a updated for version 7.0194
vimboss
parents: 649
diff changeset
106 let start = col('.') - 1
667
9090f866cd57 updated for version 7.0197
vimboss
parents: 659
diff changeset
107 while start >= 0 && line[start - 1] =~ '\k'
659
d6a69271cb9a updated for version 7.0194
vimboss
parents: 649
diff changeset
108 let start -= 1
d6a69271cb9a updated for version 7.0194
vimboss
parents: 649
diff changeset
109 endwhile
d6a69271cb9a updated for version 7.0194
vimboss
parents: 649
diff changeset
110 endif
784
1cc5f2c523ee updated for version 7.0229
vimboss
parents: 714
diff changeset
111 " If b:compl_context begins with <? we are inside of PHP code. It
856
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
112 " wasn't closed so PHP completion passed it to HTML
784
1cc5f2c523ee updated for version 7.0229
vimboss
parents: 714
diff changeset
113 if &filetype =~? 'php' && b:compl_context =~ '^<?'
1cc5f2c523ee updated for version 7.0229
vimboss
parents: 714
diff changeset
114 let b:phpcompl = 1
1cc5f2c523ee updated for version 7.0229
vimboss
parents: 714
diff changeset
115 let start = col('.') - 1
1cc5f2c523ee updated for version 7.0229
vimboss
parents: 714
diff changeset
116 while start >= 0 && line[start - 1] =~ '[a-zA-Z_0-9\x7f-\xff$]'
1cc5f2c523ee updated for version 7.0229
vimboss
parents: 714
diff changeset
117 let start -= 1
1cc5f2c523ee updated for version 7.0229
vimboss
parents: 714
diff changeset
118 endwhile
1cc5f2c523ee updated for version 7.0229
vimboss
parents: 714
diff changeset
119 endif
548
f43150a669dc updated for version 7.0155
vimboss
parents: 532
diff changeset
120 else
f43150a669dc updated for version 7.0155
vimboss
parents: 532
diff changeset
121 let b:compl_context = getline('.')[0:compl_begin]
f43150a669dc updated for version 7.0155
vimboss
parents: 532
diff changeset
122 endif
523
a7ae7e043e43 updated for version 7.0146
vimboss
parents:
diff changeset
123 return start
a7ae7e043e43 updated for version 7.0146
vimboss
parents:
diff changeset
124 else
548
f43150a669dc updated for version 7.0155
vimboss
parents: 532
diff changeset
125 " Initialize base return lists
f43150a669dc updated for version 7.0155
vimboss
parents: 532
diff changeset
126 let res = []
f43150a669dc updated for version 7.0155
vimboss
parents: 532
diff changeset
127 let res2 = []
f43150a669dc updated for version 7.0155
vimboss
parents: 532
diff changeset
128 " a:base is very short - we need context
f43150a669dc updated for version 7.0155
vimboss
parents: 532
diff changeset
129 let context = b:compl_context
531
da9142bd190a updated for version 7.0149
vimboss
parents: 529
diff changeset
130 " Check if we should do CSS completion inside of <style> tag
784
1cc5f2c523ee updated for version 7.0229
vimboss
parents: 714
diff changeset
131 " or JS completion inside of <script> tag or PHP completion in case of <?
1cc5f2c523ee updated for version 7.0229
vimboss
parents: 714
diff changeset
132 " tag AND &ft==php
531
da9142bd190a updated for version 7.0149
vimboss
parents: 529
diff changeset
133 if exists("b:csscompl")
da9142bd190a updated for version 7.0149
vimboss
parents: 529
diff changeset
134 unlet! b:csscompl
641
6a944e0bd5d2 updated for version 7.0186
vimboss
parents: 573
diff changeset
135 let context = b:compl_context
659
d6a69271cb9a updated for version 7.0194
vimboss
parents: 649
diff changeset
136 unlet! b:compl_context
548
f43150a669dc updated for version 7.0155
vimboss
parents: 532
diff changeset
137 return csscomplete#CompleteCSS(0, context)
649
8157079cea85 updated for version 7.0191
vimboss
parents: 643
diff changeset
138 elseif exists("b:jscompl")
8157079cea85 updated for version 7.0191
vimboss
parents: 643
diff changeset
139 unlet! b:jscompl
659
d6a69271cb9a updated for version 7.0194
vimboss
parents: 649
diff changeset
140 return javascriptcomplete#CompleteJS(0, a:base)
784
1cc5f2c523ee updated for version 7.0229
vimboss
parents: 714
diff changeset
141 elseif exists("b:phpcompl")
1cc5f2c523ee updated for version 7.0229
vimboss
parents: 714
diff changeset
142 unlet! b:phpcompl
1cc5f2c523ee updated for version 7.0229
vimboss
parents: 714
diff changeset
143 let context = b:compl_context
1cc5f2c523ee updated for version 7.0229
vimboss
parents: 714
diff changeset
144 return phpcomplete#CompletePHP(0, a:base)
641
6a944e0bd5d2 updated for version 7.0186
vimboss
parents: 573
diff changeset
145 else
6a944e0bd5d2 updated for version 7.0186
vimboss
parents: 573
diff changeset
146 if len(b:compl_context) == 0 && !exists("b:entitiescompl")
6a944e0bd5d2 updated for version 7.0186
vimboss
parents: 573
diff changeset
147 return []
6a944e0bd5d2 updated for version 7.0186
vimboss
parents: 573
diff changeset
148 endif
6a944e0bd5d2 updated for version 7.0186
vimboss
parents: 573
diff changeset
149 let context = matchstr(b:compl_context, '.\zs.*')
531
da9142bd190a updated for version 7.0149
vimboss
parents: 529
diff changeset
150 endif
641
6a944e0bd5d2 updated for version 7.0186
vimboss
parents: 573
diff changeset
151 unlet! b:compl_context
659
d6a69271cb9a updated for version 7.0194
vimboss
parents: 649
diff changeset
152 " Entities completion {{{
548
f43150a669dc updated for version 7.0155
vimboss
parents: 532
diff changeset
153 if exists("b:entitiescompl")
f43150a669dc updated for version 7.0155
vimboss
parents: 532
diff changeset
154 unlet! b:entitiescompl
f43150a669dc updated for version 7.0155
vimboss
parents: 532
diff changeset
155
844
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 842
diff changeset
156 if !exists("b:html_doctype")
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 842
diff changeset
157 call htmlcomplete#CheckDoctype()
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 842
diff changeset
158 endif
838
8e5830943bff updated for version 7.0e04
vimboss
parents: 837
diff changeset
159 if !exists("b:html_omni")
836
5a7843c57316 updated for version 7.0e02
vimboss
parents: 829
diff changeset
160 "runtime! autoload/xml/xhtml10s.vim
5a7843c57316 updated for version 7.0e02
vimboss
parents: 829
diff changeset
161 call htmlcomplete#LoadData()
557
862863033fdd updated for version 7.0158
vimboss
parents: 553
diff changeset
162 endif
548
f43150a669dc updated for version 7.0155
vimboss
parents: 532
diff changeset
163
838
8e5830943bff updated for version 7.0e04
vimboss
parents: 837
diff changeset
164 let entities = b:html_omni['vimxmlentities']
557
862863033fdd updated for version 7.0158
vimboss
parents: 553
diff changeset
165
641
6a944e0bd5d2 updated for version 7.0186
vimboss
parents: 573
diff changeset
166 if len(a:base) == 1
6a944e0bd5d2 updated for version 7.0186
vimboss
parents: 573
diff changeset
167 for m in entities
6a944e0bd5d2 updated for version 7.0186
vimboss
parents: 573
diff changeset
168 if m =~ '^'.a:base
6a944e0bd5d2 updated for version 7.0186
vimboss
parents: 573
diff changeset
169 call add(res, m.';')
6a944e0bd5d2 updated for version 7.0186
vimboss
parents: 573
diff changeset
170 endif
6a944e0bd5d2 updated for version 7.0186
vimboss
parents: 573
diff changeset
171 endfor
6a944e0bd5d2 updated for version 7.0186
vimboss
parents: 573
diff changeset
172 return res
6a944e0bd5d2 updated for version 7.0186
vimboss
parents: 573
diff changeset
173 else
6a944e0bd5d2 updated for version 7.0186
vimboss
parents: 573
diff changeset
174 for m in entities
6a944e0bd5d2 updated for version 7.0186
vimboss
parents: 573
diff changeset
175 if m =~? '^'.a:base
6a944e0bd5d2 updated for version 7.0186
vimboss
parents: 573
diff changeset
176 call add(res, m.';')
6a944e0bd5d2 updated for version 7.0186
vimboss
parents: 573
diff changeset
177 elseif m =~? a:base
6a944e0bd5d2 updated for version 7.0186
vimboss
parents: 573
diff changeset
178 call add(res2, m.';')
6a944e0bd5d2 updated for version 7.0186
vimboss
parents: 573
diff changeset
179 endif
6a944e0bd5d2 updated for version 7.0186
vimboss
parents: 573
diff changeset
180 endfor
548
f43150a669dc updated for version 7.0155
vimboss
parents: 532
diff changeset
181
641
6a944e0bd5d2 updated for version 7.0186
vimboss
parents: 573
diff changeset
182 return res + res2
6a944e0bd5d2 updated for version 7.0186
vimboss
parents: 573
diff changeset
183 endif
6a944e0bd5d2 updated for version 7.0186
vimboss
parents: 573
diff changeset
184
548
f43150a669dc updated for version 7.0155
vimboss
parents: 532
diff changeset
185
f43150a669dc updated for version 7.0155
vimboss
parents: 532
diff changeset
186 endif
659
d6a69271cb9a updated for version 7.0194
vimboss
parents: 649
diff changeset
187 " }}}
548
f43150a669dc updated for version 7.0155
vimboss
parents: 532
diff changeset
188 if context =~ '>'
f43150a669dc updated for version 7.0155
vimboss
parents: 532
diff changeset
189 " Generally if context contains > it means we are outside of tag and
531
da9142bd190a updated for version 7.0149
vimboss
parents: 529
diff changeset
190 " should abandon action - with one exception: <style> span { bo
548
f43150a669dc updated for version 7.0155
vimboss
parents: 532
diff changeset
191 if context =~ 'style[^>]\{-}>[^<]\{-}$'
f43150a669dc updated for version 7.0155
vimboss
parents: 532
diff changeset
192 return csscomplete#CompleteCSS(0, context)
649
8157079cea85 updated for version 7.0191
vimboss
parents: 643
diff changeset
193 elseif context =~ 'script[^>]\{-}>[^<]\{-}$'
8157079cea85 updated for version 7.0191
vimboss
parents: 643
diff changeset
194 let b:jsrange = [line('.'), search('<\/script\>', 'nW')]
8157079cea85 updated for version 7.0191
vimboss
parents: 643
diff changeset
195 return javascriptcomplete#CompleteJS(0, context)
531
da9142bd190a updated for version 7.0149
vimboss
parents: 529
diff changeset
196 else
da9142bd190a updated for version 7.0149
vimboss
parents: 529
diff changeset
197 return []
da9142bd190a updated for version 7.0149
vimboss
parents: 529
diff changeset
198 endif
da9142bd190a updated for version 7.0149
vimboss
parents: 529
diff changeset
199 endif
da9142bd190a updated for version 7.0149
vimboss
parents: 529
diff changeset
200
548
f43150a669dc updated for version 7.0155
vimboss
parents: 532
diff changeset
201 " If context contains > it means we are already outside of tag and we
523
a7ae7e043e43 updated for version 7.0146
vimboss
parents:
diff changeset
202 " should abandon action
856
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
203 " If context contains white space it is attribute.
659
d6a69271cb9a updated for version 7.0194
vimboss
parents: 649
diff changeset
204 " It can be also value of attribute.
d6a69271cb9a updated for version 7.0194
vimboss
parents: 649
diff changeset
205 " We have to get first word to offer proper completions
548
f43150a669dc updated for version 7.0155
vimboss
parents: 532
diff changeset
206 if context == ''
f43150a669dc updated for version 7.0155
vimboss
parents: 532
diff changeset
207 let tag = ''
f43150a669dc updated for version 7.0155
vimboss
parents: 532
diff changeset
208 else
f43150a669dc updated for version 7.0155
vimboss
parents: 532
diff changeset
209 let tag = split(context)[0]
841
c2cae213194d updated for version 7.0e07
vimboss
parents: 838
diff changeset
210 " Detect if tag is uppercase to return in proper case,
c2cae213194d updated for version 7.0e07
vimboss
parents: 838
diff changeset
211 " we need to make it lowercase for processing
c2cae213194d updated for version 7.0e07
vimboss
parents: 838
diff changeset
212 if tag =~ '^[A-Z]*$'
837
6bb1fa855dc9 updated for version 7.0e03
vimboss
parents: 836
diff changeset
213 let uppercase_tag = 1
6bb1fa855dc9 updated for version 7.0e03
vimboss
parents: 836
diff changeset
214 let tag = tolower(tag)
6bb1fa855dc9 updated for version 7.0e03
vimboss
parents: 836
diff changeset
215 else
6bb1fa855dc9 updated for version 7.0e03
vimboss
parents: 836
diff changeset
216 let uppercase_tag = 0
6bb1fa855dc9 updated for version 7.0e03
vimboss
parents: 836
diff changeset
217 endif
548
f43150a669dc updated for version 7.0155
vimboss
parents: 532
diff changeset
218 endif
531
da9142bd190a updated for version 7.0149
vimboss
parents: 529
diff changeset
219 " Get last word, it should be attr name
548
f43150a669dc updated for version 7.0155
vimboss
parents: 532
diff changeset
220 let attr = matchstr(context, '.*\s\zs.*')
523
a7ae7e043e43 updated for version 7.0146
vimboss
parents:
diff changeset
221 " Possible situations where any prediction would be difficult:
a7ae7e043e43 updated for version 7.0146
vimboss
parents:
diff changeset
222 " 1. Events attributes
548
f43150a669dc updated for version 7.0155
vimboss
parents: 532
diff changeset
223 if context =~ '\s'
523
a7ae7e043e43 updated for version 7.0146
vimboss
parents:
diff changeset
224 " Sort out style, class, and on* cases
659
d6a69271cb9a updated for version 7.0194
vimboss
parents: 649
diff changeset
225 if context =~? "\\(on[a-z]*\\|id\\|style\\|class\\)\\s*=\\s*[\"']"
d6a69271cb9a updated for version 7.0194
vimboss
parents: 649
diff changeset
226 " Id, class completion {{{
d6a69271cb9a updated for version 7.0194
vimboss
parents: 649
diff changeset
227 if context =~? "\\(id\\|class\\)\\s*=\\s*[\"'][a-zA-Z0-9_ -]*$"
d6a69271cb9a updated for version 7.0194
vimboss
parents: 649
diff changeset
228 if context =~? "class\\s*=\\s*[\"'][a-zA-Z0-9_ -]*$"
532
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 531
diff changeset
229 let search_for = "class"
659
d6a69271cb9a updated for version 7.0194
vimboss
parents: 649
diff changeset
230 elseif context =~? "id\\s*=\\s*[\"'][a-zA-Z0-9_ -]*$"
532
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 531
diff changeset
231 let search_for = "id"
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 531
diff changeset
232 endif
531
da9142bd190a updated for version 7.0149
vimboss
parents: 529
diff changeset
233 " Handle class name completion
da9142bd190a updated for version 7.0149
vimboss
parents: 529
diff changeset
234 " 1. Find lines of <link stylesheet>
da9142bd190a updated for version 7.0149
vimboss
parents: 529
diff changeset
235 " 1a. Check file for @import
da9142bd190a updated for version 7.0149
vimboss
parents: 529
diff changeset
236 " 2. Extract filename(s?) of stylesheet,
da9142bd190a updated for version 7.0149
vimboss
parents: 529
diff changeset
237 call cursor(1,1)
da9142bd190a updated for version 7.0149
vimboss
parents: 529
diff changeset
238 let head = getline(search('<head\>'), search('<\/head>'))
da9142bd190a updated for version 7.0149
vimboss
parents: 529
diff changeset
239 let headjoined = join(copy(head), ' ')
da9142bd190a updated for version 7.0149
vimboss
parents: 529
diff changeset
240 if headjoined =~ '<style'
557
862863033fdd updated for version 7.0158
vimboss
parents: 553
diff changeset
241 " Remove possibly confusing CSS operators
532
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 531
diff changeset
242 let stylehead = substitute(headjoined, '+>\*[,', ' ', 'g')
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 531
diff changeset
243 if search_for == 'class'
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 531
diff changeset
244 let styleheadlines = split(stylehead)
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 531
diff changeset
245 let headclasslines = filter(copy(styleheadlines), "v:val =~ '\\([a-zA-Z0-9:]\\+\\)\\?\\.[a-zA-Z0-9_-]\\+'")
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 531
diff changeset
246 else
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 531
diff changeset
247 let stylesheet = split(headjoined, '[{}]')
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 531
diff changeset
248 " Get all lines which fit id syntax
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 531
diff changeset
249 let classlines = filter(copy(stylesheet), "v:val =~ '#[a-zA-Z0-9_-]\\+'")
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 531
diff changeset
250 " Filter out possible color definitions
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 531
diff changeset
251 call filter(classlines, "v:val !~ ':\\s*#[a-zA-Z0-9_-]\\+'")
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 531
diff changeset
252 " Filter out complex border definitions
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 531
diff changeset
253 call filter(classlines, "v:val !~ '\\(none\\|hidden\\|dotted\\|dashed\\|solid\\|double\\|groove\\|ridge\\|inset\\|outset\\)\\s*#[a-zA-Z0-9_-]\\+'")
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 531
diff changeset
254 let templines = join(classlines, ' ')
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 531
diff changeset
255 let headclasslines = split(templines)
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 531
diff changeset
256 call filter(headclasslines, "v:val =~ '#[a-zA-Z0-9_-]\\+'")
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 531
diff changeset
257 endif
531
da9142bd190a updated for version 7.0149
vimboss
parents: 529
diff changeset
258 let internal = 1
da9142bd190a updated for version 7.0149
vimboss
parents: 529
diff changeset
259 else
da9142bd190a updated for version 7.0149
vimboss
parents: 529
diff changeset
260 let internal = 0
da9142bd190a updated for version 7.0149
vimboss
parents: 529
diff changeset
261 endif
da9142bd190a updated for version 7.0149
vimboss
parents: 529
diff changeset
262 let styletable = []
da9142bd190a updated for version 7.0149
vimboss
parents: 529
diff changeset
263 let secimportfiles = []
da9142bd190a updated for version 7.0149
vimboss
parents: 529
diff changeset
264 let filestable = filter(copy(head), "v:val =~ '\\(@import\\|link.*stylesheet\\)'")
da9142bd190a updated for version 7.0149
vimboss
parents: 529
diff changeset
265 for line in filestable
da9142bd190a updated for version 7.0149
vimboss
parents: 529
diff changeset
266 if line =~ "@import"
da9142bd190a updated for version 7.0149
vimboss
parents: 529
diff changeset
267 let styletable += [matchstr(line, "import\\s\\+\\(url(\\)\\?[\"']\\?\\zs\\f\\+\\ze")]
da9142bd190a updated for version 7.0149
vimboss
parents: 529
diff changeset
268 elseif line =~ "<link"
da9142bd190a updated for version 7.0149
vimboss
parents: 529
diff changeset
269 let styletable += [matchstr(line, "href\\s*=\\s*[\"']\\zs\\f\\+\\ze")]
da9142bd190a updated for version 7.0149
vimboss
parents: 529
diff changeset
270 endif
da9142bd190a updated for version 7.0149
vimboss
parents: 529
diff changeset
271 endfor
532
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 531
diff changeset
272 for file in styletable
531
da9142bd190a updated for version 7.0149
vimboss
parents: 529
diff changeset
273 if filereadable(file)
da9142bd190a updated for version 7.0149
vimboss
parents: 529
diff changeset
274 let stylesheet = readfile(file)
da9142bd190a updated for version 7.0149
vimboss
parents: 529
diff changeset
275 let secimport = filter(copy(stylesheet), "v:val =~ '@import'")
da9142bd190a updated for version 7.0149
vimboss
parents: 529
diff changeset
276 if len(secimport) > 0
da9142bd190a updated for version 7.0149
vimboss
parents: 529
diff changeset
277 for line in secimport
532
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 531
diff changeset
278 let secfile = matchstr(line, "import\\s\\+\\(url(\\)\\?[\"']\\?\\zs\\f\\+\\ze")
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 531
diff changeset
279 let secfile = fnamemodify(file, ":p:h").'/'.secfile
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 531
diff changeset
280 let secimportfiles += [secfile]
531
da9142bd190a updated for version 7.0149
vimboss
parents: 529
diff changeset
281 endfor
da9142bd190a updated for version 7.0149
vimboss
parents: 529
diff changeset
282 endif
da9142bd190a updated for version 7.0149
vimboss
parents: 529
diff changeset
283 endif
da9142bd190a updated for version 7.0149
vimboss
parents: 529
diff changeset
284 endfor
da9142bd190a updated for version 7.0149
vimboss
parents: 529
diff changeset
285 let cssfiles = styletable + secimportfiles
da9142bd190a updated for version 7.0149
vimboss
parents: 529
diff changeset
286 let classes = []
da9142bd190a updated for version 7.0149
vimboss
parents: 529
diff changeset
287 for file in cssfiles
2788
0877b8d6370e Updated runtime files.
Bram Moolenaar <bram@vim.org>
parents: 1120
diff changeset
288 let classlines = []
531
da9142bd190a updated for version 7.0149
vimboss
parents: 529
diff changeset
289 if filereadable(file)
da9142bd190a updated for version 7.0149
vimboss
parents: 529
diff changeset
290 let stylesheet = readfile(file)
532
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 531
diff changeset
291 let stylefile = join(stylesheet, ' ')
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 531
diff changeset
292 let stylefile = substitute(stylefile, '+>\*[,', ' ', 'g')
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 531
diff changeset
293 if search_for == 'class'
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 531
diff changeset
294 let stylesheet = split(stylefile)
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 531
diff changeset
295 let classlines = filter(copy(stylesheet), "v:val =~ '\\([a-zA-Z0-9:]\\+\\)\\?\\.[a-zA-Z0-9_-]\\+'")
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 531
diff changeset
296 else
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 531
diff changeset
297 let stylesheet = split(stylefile, '[{}]')
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 531
diff changeset
298 " Get all lines which fit id syntax
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 531
diff changeset
299 let classlines = filter(copy(stylesheet), "v:val =~ '#[a-zA-Z0-9_-]\\+'")
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 531
diff changeset
300 " Filter out possible color definitions
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 531
diff changeset
301 call filter(classlines, "v:val !~ ':\\s*#[a-zA-Z0-9_-]\\+'")
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 531
diff changeset
302 " Filter out complex border definitions
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 531
diff changeset
303 call filter(classlines, "v:val !~ '\\(none\\|hidden\\|dotted\\|dashed\\|solid\\|double\\|groove\\|ridge\\|inset\\|outset\\)\\s*#[a-zA-Z0-9_-]\\+'")
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 531
diff changeset
304 let templines = join(classlines, ' ')
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 531
diff changeset
305 let stylelines = split(templines)
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 531
diff changeset
306 let classlines = filter(stylelines, "v:val =~ '#[a-zA-Z0-9_-]\\+'")
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 531
diff changeset
307
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 531
diff changeset
308 endif
531
da9142bd190a updated for version 7.0149
vimboss
parents: 529
diff changeset
309 endif
da9142bd190a updated for version 7.0149
vimboss
parents: 529
diff changeset
310 " We gathered classes definitions from all external files
da9142bd190a updated for version 7.0149
vimboss
parents: 529
diff changeset
311 let classes += classlines
da9142bd190a updated for version 7.0149
vimboss
parents: 529
diff changeset
312 endfor
da9142bd190a updated for version 7.0149
vimboss
parents: 529
diff changeset
313 if internal == 1
da9142bd190a updated for version 7.0149
vimboss
parents: 529
diff changeset
314 let classes += headclasslines
da9142bd190a updated for version 7.0149
vimboss
parents: 529
diff changeset
315 endif
532
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 531
diff changeset
316
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 531
diff changeset
317 if search_for == 'class'
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 531
diff changeset
318 let elements = {}
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 531
diff changeset
319 for element in classes
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 531
diff changeset
320 if element =~ '^\.'
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 531
diff changeset
321 let class = matchstr(element, '^\.\zs[a-zA-Z][a-zA-Z0-9_-]*\ze')
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 531
diff changeset
322 let class = substitute(class, ':.*', '', '')
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 531
diff changeset
323 if has_key(elements, 'common')
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 531
diff changeset
324 let elements['common'] .= ' '.class
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 531
diff changeset
325 else
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 531
diff changeset
326 let elements['common'] = class
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 531
diff changeset
327 endif
531
da9142bd190a updated for version 7.0149
vimboss
parents: 529
diff changeset
328 else
532
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 531
diff changeset
329 let class = matchstr(element, '[a-zA-Z1-6]*\.\zs[a-zA-Z][a-zA-Z0-9_-]*\ze')
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 531
diff changeset
330 let tagname = tolower(matchstr(element, '[a-zA-Z1-6]*\ze.'))
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 531
diff changeset
331 if tagname != ''
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 531
diff changeset
332 if has_key(elements, tagname)
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 531
diff changeset
333 let elements[tagname] .= ' '.class
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 531
diff changeset
334 else
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 531
diff changeset
335 let elements[tagname] = class
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 531
diff changeset
336 endif
531
da9142bd190a updated for version 7.0149
vimboss
parents: 529
diff changeset
337 endif
da9142bd190a updated for version 7.0149
vimboss
parents: 529
diff changeset
338 endif
532
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 531
diff changeset
339 endfor
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 531
diff changeset
340
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 531
diff changeset
341 if has_key(elements, tag) && has_key(elements, 'common')
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 531
diff changeset
342 let values = split(elements[tag]." ".elements['common'])
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 531
diff changeset
343 elseif has_key(elements, tag) && !has_key(elements, 'common')
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 531
diff changeset
344 let values = split(elements[tag])
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 531
diff changeset
345 elseif !has_key(elements, tag) && has_key(elements, 'common')
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 531
diff changeset
346 let values = split(elements['common'])
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 531
diff changeset
347 else
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 531
diff changeset
348 return []
531
da9142bd190a updated for version 7.0149
vimboss
parents: 529
diff changeset
349 endif
da9142bd190a updated for version 7.0149
vimboss
parents: 529
diff changeset
350
532
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 531
diff changeset
351 elseif search_for == 'id'
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 531
diff changeset
352 " Find used IDs
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 531
diff changeset
353 " 1. Catch whole file
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 531
diff changeset
354 let filelines = getline(1, line('$'))
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 531
diff changeset
355 " 2. Find lines with possible id
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 531
diff changeset
356 let used_id_lines = filter(filelines, 'v:val =~ "id\\s*=\\s*[\"''][a-zA-Z0-9_-]\\+"')
856
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
357 " 3a. Join all filtered lines
532
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 531
diff changeset
358 let id_string = join(used_id_lines, ' ')
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 531
diff changeset
359 " 3b. And split them to be sure each id is in separate item
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 531
diff changeset
360 let id_list = split(id_string, 'id\s*=\s*')
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 531
diff changeset
361 " 4. Extract id values
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 531
diff changeset
362 let used_id = map(id_list, 'matchstr(v:val, "[\"'']\\zs[a-zA-Z0-9_-]\\+\\ze")')
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 531
diff changeset
363 let joined_used_id = ','.join(used_id, ',').','
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 531
diff changeset
364
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 531
diff changeset
365 let allvalues = map(classes, 'matchstr(v:val, ".*#\\zs[a-zA-Z0-9_-]\\+")')
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 531
diff changeset
366
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 531
diff changeset
367 let values = []
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 531
diff changeset
368
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 531
diff changeset
369 for element in classes
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 531
diff changeset
370 if joined_used_id !~ ','.element.','
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 531
diff changeset
371 let values += [element]
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 531
diff changeset
372 endif
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 531
diff changeset
373
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 531
diff changeset
374 endfor
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 531
diff changeset
375
531
da9142bd190a updated for version 7.0149
vimboss
parents: 529
diff changeset
376 endif
da9142bd190a updated for version 7.0149
vimboss
parents: 529
diff changeset
377
da9142bd190a updated for version 7.0149
vimboss
parents: 529
diff changeset
378 " We need special version of sbase
548
f43150a669dc updated for version 7.0155
vimboss
parents: 532
diff changeset
379 let classbase = matchstr(context, ".*[\"']")
532
7052f11a3dc9 updated for version 7.0150
vimboss
parents: 531
diff changeset
380 let classquote = matchstr(classbase, '.$')
531
da9142bd190a updated for version 7.0149
vimboss
parents: 529
diff changeset
381
da9142bd190a updated for version 7.0149
vimboss
parents: 529
diff changeset
382 let entered_class = matchstr(attr, ".*=\\s*[\"']\\zs.*")
da9142bd190a updated for version 7.0149
vimboss
parents: 529
diff changeset
383
da9142bd190a updated for version 7.0149
vimboss
parents: 529
diff changeset
384 for m in sort(values)
da9142bd190a updated for version 7.0149
vimboss
parents: 529
diff changeset
385 if m =~? '^'.entered_class
548
f43150a669dc updated for version 7.0155
vimboss
parents: 532
diff changeset
386 call add(res, m . classquote)
531
da9142bd190a updated for version 7.0149
vimboss
parents: 529
diff changeset
387 elseif m =~? entered_class
548
f43150a669dc updated for version 7.0155
vimboss
parents: 532
diff changeset
388 call add(res2, m . classquote)
531
da9142bd190a updated for version 7.0149
vimboss
parents: 529
diff changeset
389 endif
da9142bd190a updated for version 7.0149
vimboss
parents: 529
diff changeset
390 endfor
da9142bd190a updated for version 7.0149
vimboss
parents: 529
diff changeset
391
da9142bd190a updated for version 7.0149
vimboss
parents: 529
diff changeset
392 return res + res2
da9142bd190a updated for version 7.0149
vimboss
parents: 529
diff changeset
393
659
d6a69271cb9a updated for version 7.0194
vimboss
parents: 649
diff changeset
394 elseif context =~? "style\\s*=\\s*[\"'][^\"']*$"
548
f43150a669dc updated for version 7.0155
vimboss
parents: 532
diff changeset
395 return csscomplete#CompleteCSS(0, context)
531
da9142bd190a updated for version 7.0149
vimboss
parents: 529
diff changeset
396
da9142bd190a updated for version 7.0149
vimboss
parents: 529
diff changeset
397 endif
659
d6a69271cb9a updated for version 7.0194
vimboss
parents: 649
diff changeset
398 " }}}
d6a69271cb9a updated for version 7.0194
vimboss
parents: 649
diff changeset
399 " Complete on-events {{{
d6a69271cb9a updated for version 7.0194
vimboss
parents: 649
diff changeset
400 if context =~? 'on[a-z]*\s*=\s*\(''[^'']*\|"[^"]*\)$'
d6a69271cb9a updated for version 7.0194
vimboss
parents: 649
diff changeset
401 " We have to:
d6a69271cb9a updated for version 7.0194
vimboss
parents: 649
diff changeset
402 " 1. Find external files
d6a69271cb9a updated for version 7.0194
vimboss
parents: 649
diff changeset
403 let b:js_extfiles = []
d6a69271cb9a updated for version 7.0194
vimboss
parents: 649
diff changeset
404 let l = line('.')
d6a69271cb9a updated for version 7.0194
vimboss
parents: 649
diff changeset
405 let c = col('.')
d6a69271cb9a updated for version 7.0194
vimboss
parents: 649
diff changeset
406 call cursor(1,1)
d6a69271cb9a updated for version 7.0194
vimboss
parents: 649
diff changeset
407 while search('<\@<=script\>', 'W') && line('.') <= l
d6a69271cb9a updated for version 7.0194
vimboss
parents: 649
diff changeset
408 if synIDattr(synID(line('.'),col('.')-1,0),"name") !~? 'comment'
d6a69271cb9a updated for version 7.0194
vimboss
parents: 649
diff changeset
409 let sname = matchstr(getline('.'), '<script[^>]*src\s*=\s*\([''"]\)\zs.\{-}\ze\1')
d6a69271cb9a updated for version 7.0194
vimboss
parents: 649
diff changeset
410 if filereadable(sname)
d6a69271cb9a updated for version 7.0194
vimboss
parents: 649
diff changeset
411 let b:js_extfiles += readfile(sname)
d6a69271cb9a updated for version 7.0194
vimboss
parents: 649
diff changeset
412 endif
d6a69271cb9a updated for version 7.0194
vimboss
parents: 649
diff changeset
413 endif
d6a69271cb9a updated for version 7.0194
vimboss
parents: 649
diff changeset
414 endwhile
d6a69271cb9a updated for version 7.0194
vimboss
parents: 649
diff changeset
415 " 2. Find at least one <script> tag
d6a69271cb9a updated for version 7.0194
vimboss
parents: 649
diff changeset
416 call cursor(1,1)
d6a69271cb9a updated for version 7.0194
vimboss
parents: 649
diff changeset
417 let js_scripttags = []
d6a69271cb9a updated for version 7.0194
vimboss
parents: 649
diff changeset
418 while search('<script\>', 'W') && line('.') < l
d6a69271cb9a updated for version 7.0194
vimboss
parents: 649
diff changeset
419 if matchstr(getline('.'), '<script[^>]*src') == ''
d6a69271cb9a updated for version 7.0194
vimboss
parents: 649
diff changeset
420 let js_scripttag = getline(line('.'), search('</script>', 'W'))
d6a69271cb9a updated for version 7.0194
vimboss
parents: 649
diff changeset
421 let js_scripttags += js_scripttag
d6a69271cb9a updated for version 7.0194
vimboss
parents: 649
diff changeset
422 endif
d6a69271cb9a updated for version 7.0194
vimboss
parents: 649
diff changeset
423 endwhile
d6a69271cb9a updated for version 7.0194
vimboss
parents: 649
diff changeset
424 let b:js_extfiles += js_scripttags
d6a69271cb9a updated for version 7.0194
vimboss
parents: 649
diff changeset
425
d6a69271cb9a updated for version 7.0194
vimboss
parents: 649
diff changeset
426 " 3. Proper call for javascriptcomplete#CompleteJS
d6a69271cb9a updated for version 7.0194
vimboss
parents: 649
diff changeset
427 call cursor(l,c)
667
9090f866cd57 updated for version 7.0197
vimboss
parents: 659
diff changeset
428 let js_context = matchstr(a:base, '\k\+$')
659
d6a69271cb9a updated for version 7.0194
vimboss
parents: 649
diff changeset
429 let js_shortcontext = substitute(a:base, js_context.'$', '', '')
d6a69271cb9a updated for version 7.0194
vimboss
parents: 649
diff changeset
430 let b:compl_context = context
d6a69271cb9a updated for version 7.0194
vimboss
parents: 649
diff changeset
431 let b:jsrange = [l, l]
d6a69271cb9a updated for version 7.0194
vimboss
parents: 649
diff changeset
432 unlet! l c
d6a69271cb9a updated for version 7.0194
vimboss
parents: 649
diff changeset
433 return javascriptcomplete#CompleteJS(0, js_context)
d6a69271cb9a updated for version 7.0194
vimboss
parents: 649
diff changeset
434
d6a69271cb9a updated for version 7.0194
vimboss
parents: 649
diff changeset
435 endif
856
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
436
659
d6a69271cb9a updated for version 7.0194
vimboss
parents: 649
diff changeset
437 " }}}
d6a69271cb9a updated for version 7.0194
vimboss
parents: 649
diff changeset
438 let stripbase = matchstr(context, ".*\\(on[a-zA-Z]*\\|style\\|class\\)\\s*=\\s*[\"']\\zs.*")
548
f43150a669dc updated for version 7.0155
vimboss
parents: 532
diff changeset
439 " Now we have context stripped from all chars up to style/class.
523
a7ae7e043e43 updated for version 7.0146
vimboss
parents:
diff changeset
440 " It may fail with some strange style value combinations.
a7ae7e043e43 updated for version 7.0146
vimboss
parents:
diff changeset
441 if stripbase !~ "[\"']"
a7ae7e043e43 updated for version 7.0146
vimboss
parents:
diff changeset
442 return []
a7ae7e043e43 updated for version 7.0146
vimboss
parents:
diff changeset
443 endif
a7ae7e043e43 updated for version 7.0146
vimboss
parents:
diff changeset
444 endif
659
d6a69271cb9a updated for version 7.0194
vimboss
parents: 649
diff changeset
445 " Value of attribute completion {{{
523
a7ae7e043e43 updated for version 7.0146
vimboss
parents:
diff changeset
446 " If attr contains =\s*[\"'] we catched value of attribute
837
6bb1fa855dc9 updated for version 7.0e03
vimboss
parents: 836
diff changeset
447 if attr =~ "=\s*[\"']" || attr =~ "=\s*$"
523
a7ae7e043e43 updated for version 7.0146
vimboss
parents:
diff changeset
448 " Let do attribute specific completion
a7ae7e043e43 updated for version 7.0146
vimboss
parents:
diff changeset
449 let attrname = matchstr(attr, '.*\ze\s*=')
837
6bb1fa855dc9 updated for version 7.0e03
vimboss
parents: 836
diff changeset
450 let entered_value = matchstr(attr, ".*=\\s*[\"']\\?\\zs.*")
523
a7ae7e043e43 updated for version 7.0146
vimboss
parents:
diff changeset
451 let values = []
1120
e6db096b07a1 updated for version 7.1a
vimboss
parents: 856
diff changeset
452 " Load data {{{
e6db096b07a1 updated for version 7.1a
vimboss
parents: 856
diff changeset
453 if !exists("b:html_doctype")
e6db096b07a1 updated for version 7.1a
vimboss
parents: 856
diff changeset
454 call htmlcomplete#CheckDoctype()
e6db096b07a1 updated for version 7.1a
vimboss
parents: 856
diff changeset
455 endif
e6db096b07a1 updated for version 7.1a
vimboss
parents: 856
diff changeset
456 if !exists("b:html_omni")
e6db096b07a1 updated for version 7.1a
vimboss
parents: 856
diff changeset
457 "runtime! autoload/xml/xhtml10s.vim
e6db096b07a1 updated for version 7.1a
vimboss
parents: 856
diff changeset
458 call htmlcomplete#LoadData()
e6db096b07a1 updated for version 7.1a
vimboss
parents: 856
diff changeset
459 endif
e6db096b07a1 updated for version 7.1a
vimboss
parents: 856
diff changeset
460 " }}}
836
5a7843c57316 updated for version 7.0e02
vimboss
parents: 829
diff changeset
461 if attrname == 'href'
523
a7ae7e043e43 updated for version 7.0146
vimboss
parents:
diff changeset
462 " Now we are looking for local anchors defined by name or id
a7ae7e043e43 updated for version 7.0146
vimboss
parents:
diff changeset
463 if entered_value =~ '^#'
a7ae7e043e43 updated for version 7.0146
vimboss
parents:
diff changeset
464 let file = join(getline(1, line('$')), ' ')
a7ae7e043e43 updated for version 7.0146
vimboss
parents:
diff changeset
465 " Split it be sure there will be one id/name element in
a7ae7e043e43 updated for version 7.0146
vimboss
parents:
diff changeset
466 " item, it will be also first word [a-zA-Z0-9_-] in element
a7ae7e043e43 updated for version 7.0146
vimboss
parents:
diff changeset
467 let oneelement = split(file, "\\(meta \\)\\@<!\\(name\\|id\\)\\s*=\\s*[\"']")
a7ae7e043e43 updated for version 7.0146
vimboss
parents:
diff changeset
468 for i in oneelement
a7ae7e043e43 updated for version 7.0146
vimboss
parents:
diff changeset
469 let values += ['#'.matchstr(i, "^[a-zA-Z][a-zA-Z0-9%_-]*")]
a7ae7e043e43 updated for version 7.0146
vimboss
parents:
diff changeset
470 endfor
a7ae7e043e43 updated for version 7.0146
vimboss
parents:
diff changeset
471 endif
836
5a7843c57316 updated for version 7.0e02
vimboss
parents: 829
diff changeset
472 else
838
8e5830943bff updated for version 7.0e04
vimboss
parents: 837
diff changeset
473 if has_key(b:html_omni, tag) && has_key(b:html_omni[tag][1], attrname)
8e5830943bff updated for version 7.0e04
vimboss
parents: 837
diff changeset
474 let values = b:html_omni[tag][1][attrname]
836
5a7843c57316 updated for version 7.0e02
vimboss
parents: 829
diff changeset
475 else
5a7843c57316 updated for version 7.0e02
vimboss
parents: 829
diff changeset
476 return []
523
a7ae7e043e43 updated for version 7.0146
vimboss
parents:
diff changeset
477 endif
a7ae7e043e43 updated for version 7.0146
vimboss
parents:
diff changeset
478 endif
a7ae7e043e43 updated for version 7.0146
vimboss
parents:
diff changeset
479
a7ae7e043e43 updated for version 7.0146
vimboss
parents:
diff changeset
480 if len(values) == 0
a7ae7e043e43 updated for version 7.0146
vimboss
parents:
diff changeset
481 return []
a7ae7e043e43 updated for version 7.0146
vimboss
parents:
diff changeset
482 endif
a7ae7e043e43 updated for version 7.0146
vimboss
parents:
diff changeset
483
a7ae7e043e43 updated for version 7.0146
vimboss
parents:
diff changeset
484 " We need special version of sbase
548
f43150a669dc updated for version 7.0155
vimboss
parents: 532
diff changeset
485 let attrbase = matchstr(context, ".*[\"']")
531
da9142bd190a updated for version 7.0149
vimboss
parents: 529
diff changeset
486 let attrquote = matchstr(attrbase, '.$')
837
6bb1fa855dc9 updated for version 7.0e03
vimboss
parents: 836
diff changeset
487 if attrquote !~ "['\"]"
6bb1fa855dc9 updated for version 7.0e03
vimboss
parents: 836
diff changeset
488 let attrquoteopen = '"'
6bb1fa855dc9 updated for version 7.0e03
vimboss
parents: 836
diff changeset
489 let attrquote = '"'
6bb1fa855dc9 updated for version 7.0e03
vimboss
parents: 836
diff changeset
490 else
6bb1fa855dc9 updated for version 7.0e03
vimboss
parents: 836
diff changeset
491 let attrquoteopen = ''
6bb1fa855dc9 updated for version 7.0e03
vimboss
parents: 836
diff changeset
492 endif
523
a7ae7e043e43 updated for version 7.0146
vimboss
parents:
diff changeset
493
a7ae7e043e43 updated for version 7.0146
vimboss
parents:
diff changeset
494 for m in values
531
da9142bd190a updated for version 7.0149
vimboss
parents: 529
diff changeset
495 " This if is needed to not offer all completions as-is
da9142bd190a updated for version 7.0149
vimboss
parents: 529
diff changeset
496 " alphabetically but sort them. Those beginning with entered
da9142bd190a updated for version 7.0149
vimboss
parents: 529
diff changeset
497 " part will be as first choices
da9142bd190a updated for version 7.0149
vimboss
parents: 529
diff changeset
498 if m =~ '^'.entered_value
842
a209672376fd updated for version 7.0f
vimboss
parents: 841
diff changeset
499 call add(res, attrquoteopen . m . attrquote)
531
da9142bd190a updated for version 7.0149
vimboss
parents: 529
diff changeset
500 elseif m =~ entered_value
842
a209672376fd updated for version 7.0f
vimboss
parents: 841
diff changeset
501 call add(res2, attrquoteopen . m . attrquote)
523
a7ae7e043e43 updated for version 7.0146
vimboss
parents:
diff changeset
502 endif
a7ae7e043e43 updated for version 7.0146
vimboss
parents:
diff changeset
503 endfor
531
da9142bd190a updated for version 7.0149
vimboss
parents: 529
diff changeset
504
da9142bd190a updated for version 7.0149
vimboss
parents: 529
diff changeset
505 return res + res2
da9142bd190a updated for version 7.0149
vimboss
parents: 529
diff changeset
506
523
a7ae7e043e43 updated for version 7.0146
vimboss
parents:
diff changeset
507 endif
659
d6a69271cb9a updated for version 7.0194
vimboss
parents: 649
diff changeset
508 " }}}
d6a69271cb9a updated for version 7.0194
vimboss
parents: 649
diff changeset
509 " Attribute completion {{{
548
f43150a669dc updated for version 7.0155
vimboss
parents: 532
diff changeset
510 " Shorten context to not include last word
f43150a669dc updated for version 7.0155
vimboss
parents: 532
diff changeset
511 let sbase = matchstr(context, '.*\ze\s.*')
667
9090f866cd57 updated for version 7.0197
vimboss
parents: 659
diff changeset
512
9090f866cd57 updated for version 7.0197
vimboss
parents: 659
diff changeset
513 " Load data {{{
844
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 842
diff changeset
514 if !exists("b:html_doctype")
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 842
diff changeset
515 call htmlcomplete#CheckDoctype()
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 842
diff changeset
516 endif
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 842
diff changeset
517 if !exists("b:html_omni")
836
5a7843c57316 updated for version 7.0e02
vimboss
parents: 829
diff changeset
518 call htmlcomplete#LoadData()
523
a7ae7e043e43 updated for version 7.0146
vimboss
parents:
diff changeset
519 endif
667
9090f866cd57 updated for version 7.0197
vimboss
parents: 659
diff changeset
520 " }}}
856
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
521
838
8e5830943bff updated for version 7.0e04
vimboss
parents: 837
diff changeset
522 if has_key(b:html_omni, tag)
8e5830943bff updated for version 7.0e04
vimboss
parents: 837
diff changeset
523 let attrs = keys(b:html_omni[tag][1])
837
6bb1fa855dc9 updated for version 7.0e03
vimboss
parents: 836
diff changeset
524 else
6bb1fa855dc9 updated for version 7.0e03
vimboss
parents: 836
diff changeset
525 return []
6bb1fa855dc9 updated for version 7.0e03
vimboss
parents: 836
diff changeset
526 endif
523
a7ae7e043e43 updated for version 7.0146
vimboss
parents:
diff changeset
527
a7ae7e043e43 updated for version 7.0146
vimboss
parents:
diff changeset
528 for m in sort(attrs)
531
da9142bd190a updated for version 7.0149
vimboss
parents: 529
diff changeset
529 if m =~ '^'.attr
667
9090f866cd57 updated for version 7.0197
vimboss
parents: 659
diff changeset
530 call add(res, m)
531
da9142bd190a updated for version 7.0149
vimboss
parents: 529
diff changeset
531 elseif m =~ attr
667
9090f866cd57 updated for version 7.0197
vimboss
parents: 659
diff changeset
532 call add(res2, m)
523
a7ae7e043e43 updated for version 7.0146
vimboss
parents:
diff changeset
533 endif
a7ae7e043e43 updated for version 7.0146
vimboss
parents:
diff changeset
534 endfor
667
9090f866cd57 updated for version 7.0197
vimboss
parents: 659
diff changeset
535 let menu = res + res2
838
8e5830943bff updated for version 7.0e04
vimboss
parents: 837
diff changeset
536 if has_key(b:html_omni, 'vimxmlattrinfo')
667
9090f866cd57 updated for version 7.0197
vimboss
parents: 659
diff changeset
537 let final_menu = []
9090f866cd57 updated for version 7.0197
vimboss
parents: 659
diff changeset
538 for i in range(len(menu))
9090f866cd57 updated for version 7.0197
vimboss
parents: 659
diff changeset
539 let item = menu[i]
838
8e5830943bff updated for version 7.0e04
vimboss
parents: 837
diff changeset
540 if has_key(b:html_omni['vimxmlattrinfo'], item)
8e5830943bff updated for version 7.0e04
vimboss
parents: 837
diff changeset
541 let m_menu = b:html_omni['vimxmlattrinfo'][item][0]
8e5830943bff updated for version 7.0e04
vimboss
parents: 837
diff changeset
542 let m_info = b:html_omni['vimxmlattrinfo'][item][1]
667
9090f866cd57 updated for version 7.0197
vimboss
parents: 659
diff changeset
543 else
9090f866cd57 updated for version 7.0197
vimboss
parents: 659
diff changeset
544 let m_menu = ''
9090f866cd57 updated for version 7.0197
vimboss
parents: 659
diff changeset
545 let m_info = ''
844
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 842
diff changeset
546 endif
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 842
diff changeset
547 if len(b:html_omni[tag][1][item]) > 0 && b:html_omni[tag][1][item][0] =~ '^\(BOOL\|'.item.'\)$'
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 842
diff changeset
548 let item = item
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 842
diff changeset
549 let m_menu = 'Bool'
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 842
diff changeset
550 else
667
9090f866cd57 updated for version 7.0197
vimboss
parents: 659
diff changeset
551 let item .= '="'
9090f866cd57 updated for version 7.0197
vimboss
parents: 659
diff changeset
552 endif
9090f866cd57 updated for version 7.0197
vimboss
parents: 659
diff changeset
553 let final_menu += [{'word':item, 'menu':m_menu, 'info':m_info}]
9090f866cd57 updated for version 7.0197
vimboss
parents: 659
diff changeset
554 endfor
9090f866cd57 updated for version 7.0197
vimboss
parents: 659
diff changeset
555 else
844
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 842
diff changeset
556 let final_menu = []
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 842
diff changeset
557 for i in range(len(menu))
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 842
diff changeset
558 let item = menu[i]
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 842
diff changeset
559 if len(b:html_omni[tag][1][item]) > 0 && b:html_omni[tag][1][item][0] =~ '^\(BOOL\|'.item.'\)$'
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 842
diff changeset
560 let item = item
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 842
diff changeset
561 else
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 842
diff changeset
562 let item .= '="'
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 842
diff changeset
563 endif
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 842
diff changeset
564 let final_menu += [item]
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 842
diff changeset
565 endfor
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 842
diff changeset
566 return final_menu
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 842
diff changeset
567
667
9090f866cd57 updated for version 7.0197
vimboss
parents: 659
diff changeset
568 endif
9090f866cd57 updated for version 7.0197
vimboss
parents: 659
diff changeset
569 return final_menu
531
da9142bd190a updated for version 7.0149
vimboss
parents: 529
diff changeset
570
523
a7ae7e043e43 updated for version 7.0146
vimboss
parents:
diff changeset
571 endif
659
d6a69271cb9a updated for version 7.0194
vimboss
parents: 649
diff changeset
572 " }}}
d6a69271cb9a updated for version 7.0194
vimboss
parents: 649
diff changeset
573 " Close tag {{{
529
0d6092bb72e6 updated for version 7.0148
vimboss
parents: 525
diff changeset
574 let b:unaryTagsStack = "base meta link hr br param img area input col"
548
f43150a669dc updated for version 7.0155
vimboss
parents: 532
diff changeset
575 if context =~ '^\/'
714
0f9f4761ad9c updated for version 7.0216
vimboss
parents: 674
diff changeset
576 if context =~ '^\/.'
0f9f4761ad9c updated for version 7.0216
vimboss
parents: 674
diff changeset
577 return []
0f9f4761ad9c updated for version 7.0216
vimboss
parents: 674
diff changeset
578 else
0f9f4761ad9c updated for version 7.0216
vimboss
parents: 674
diff changeset
579 let opentag = xmlcomplete#GetLastOpenTag("b:unaryTagsStack")
0f9f4761ad9c updated for version 7.0216
vimboss
parents: 674
diff changeset
580 return [opentag.">"]
0f9f4761ad9c updated for version 7.0216
vimboss
parents: 674
diff changeset
581 endif
525
1f8d8c37d6ec updated for version 7.0147
vimboss
parents: 523
diff changeset
582 endif
837
6bb1fa855dc9 updated for version 7.0e03
vimboss
parents: 836
diff changeset
583 " }}}
674
4b8583e82cb8 updated for version 7.0201
vimboss
parents: 667
diff changeset
584 " Load data {{{
844
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 842
diff changeset
585 if !exists("b:html_doctype")
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 842
diff changeset
586 call htmlcomplete#CheckDoctype()
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 842
diff changeset
587 endif
838
8e5830943bff updated for version 7.0e04
vimboss
parents: 837
diff changeset
588 if !exists("b:html_omni")
836
5a7843c57316 updated for version 7.0e02
vimboss
parents: 829
diff changeset
589 "runtime! autoload/xml/xhtml10s.vim
5a7843c57316 updated for version 7.0e02
vimboss
parents: 829
diff changeset
590 call htmlcomplete#LoadData()
674
4b8583e82cb8 updated for version 7.0201
vimboss
parents: 667
diff changeset
591 endif
4b8583e82cb8 updated for version 7.0201
vimboss
parents: 667
diff changeset
592 " }}}
4b8583e82cb8 updated for version 7.0201
vimboss
parents: 667
diff changeset
593 " Tag completion {{{
525
1f8d8c37d6ec updated for version 7.0147
vimboss
parents: 523
diff changeset
594 " Deal with tag completion.
837
6bb1fa855dc9 updated for version 7.0e03
vimboss
parents: 836
diff changeset
595 let opentag = tolower(xmlcomplete#GetLastOpenTag("b:unaryTagsStack"))
714
0f9f4761ad9c updated for version 7.0216
vimboss
parents: 674
diff changeset
596 " MM: TODO: GLOT works always the same but with some weird situation it
0f9f4761ad9c updated for version 7.0216
vimboss
parents: 674
diff changeset
597 " behaves as intended in HTML but screws in PHP
841
c2cae213194d updated for version 7.0e07
vimboss
parents: 838
diff changeset
598 if opentag == '' || &filetype == 'php' && !has_key(b:html_omni, opentag)
641
6a944e0bd5d2 updated for version 7.0186
vimboss
parents: 573
diff changeset
599 " Hack for sometimes failing GetLastOpenTag.
6a944e0bd5d2 updated for version 7.0186
vimboss
parents: 573
diff changeset
600 " As far as I tested fail isn't GLOT fault but problem
6a944e0bd5d2 updated for version 7.0186
vimboss
parents: 573
diff changeset
601 " of invalid document - not properly closed tags and other mish-mash.
674
4b8583e82cb8 updated for version 7.0201
vimboss
parents: 667
diff changeset
602 " Also when document is empty. Return list of *all* tags.
838
8e5830943bff updated for version 7.0e04
vimboss
parents: 837
diff changeset
603 let tags = keys(b:html_omni)
674
4b8583e82cb8 updated for version 7.0201
vimboss
parents: 667
diff changeset
604 call filter(tags, 'v:val !~ "^vimxml"')
4b8583e82cb8 updated for version 7.0201
vimboss
parents: 667
diff changeset
605 else
838
8e5830943bff updated for version 7.0e04
vimboss
parents: 837
diff changeset
606 if has_key(b:html_omni, opentag)
8e5830943bff updated for version 7.0e04
vimboss
parents: 837
diff changeset
607 let tags = b:html_omni[opentag][0]
837
6bb1fa855dc9 updated for version 7.0e03
vimboss
parents: 836
diff changeset
608 else
6bb1fa855dc9 updated for version 7.0e03
vimboss
parents: 836
diff changeset
609 return []
6bb1fa855dc9 updated for version 7.0e03
vimboss
parents: 836
diff changeset
610 endif
641
6a944e0bd5d2 updated for version 7.0186
vimboss
parents: 573
diff changeset
611 endif
659
d6a69271cb9a updated for version 7.0194
vimboss
parents: 649
diff changeset
612 " }}}
856
8cd729851562 updated for version 7.0g
vimboss
parents: 844
diff changeset
613
837
6bb1fa855dc9 updated for version 7.0e03
vimboss
parents: 836
diff changeset
614 if exists("uppercase_tag") && uppercase_tag == 1
6bb1fa855dc9 updated for version 7.0e03
vimboss
parents: 836
diff changeset
615 let context = tolower(context)
6bb1fa855dc9 updated for version 7.0e03
vimboss
parents: 836
diff changeset
616 endif
1120
e6db096b07a1 updated for version 7.1a
vimboss
parents: 856
diff changeset
617 " Handle XML keywords: DOCTYPE
844
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 842
diff changeset
618 if opentag == ''
841
c2cae213194d updated for version 7.0e07
vimboss
parents: 838
diff changeset
619 let tags += [
1120
e6db096b07a1 updated for version 7.1a
vimboss
parents: 856
diff changeset
620 \ '!DOCTYPE html PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">',
e6db096b07a1 updated for version 7.1a
vimboss
parents: 856
diff changeset
621 \ '!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd">',
e6db096b07a1 updated for version 7.1a
vimboss
parents: 856
diff changeset
622 \ '!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">',
e6db096b07a1 updated for version 7.1a
vimboss
parents: 856
diff changeset
623 \ '!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Frameset//EN" "http://www.w3.org/TR/REC-html40/frameset.dtd">',
e6db096b07a1 updated for version 7.1a
vimboss
parents: 856
diff changeset
624 \ '!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">',
e6db096b07a1 updated for version 7.1a
vimboss
parents: 856
diff changeset
625 \ '!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">',
e6db096b07a1 updated for version 7.1a
vimboss
parents: 856
diff changeset
626 \ '!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">',
e6db096b07a1 updated for version 7.1a
vimboss
parents: 856
diff changeset
627 \ '!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">',
e6db096b07a1 updated for version 7.1a
vimboss
parents: 856
diff changeset
628 \ '!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">',
e6db096b07a1 updated for version 7.1a
vimboss
parents: 856
diff changeset
629 \ '!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">',
e6db096b07a1 updated for version 7.1a
vimboss
parents: 856
diff changeset
630 \ '!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/1999/xhtml">'
841
c2cae213194d updated for version 7.0e07
vimboss
parents: 838
diff changeset
631 \ ]
c2cae213194d updated for version 7.0e07
vimboss
parents: 838
diff changeset
632 endif
525
1f8d8c37d6ec updated for version 7.0147
vimboss
parents: 523
diff changeset
633
573
c85bf6a4999b updated for version 7.0163
vimboss
parents: 557
diff changeset
634 for m in sort(tags)
548
f43150a669dc updated for version 7.0155
vimboss
parents: 532
diff changeset
635 if m =~ '^'.context
523
a7ae7e043e43 updated for version 7.0146
vimboss
parents:
diff changeset
636 call add(res, m)
548
f43150a669dc updated for version 7.0155
vimboss
parents: 532
diff changeset
637 elseif m =~ context
531
da9142bd190a updated for version 7.0149
vimboss
parents: 529
diff changeset
638 call add(res2, m)
523
a7ae7e043e43 updated for version 7.0146
vimboss
parents:
diff changeset
639 endif
529
0d6092bb72e6 updated for version 7.0148
vimboss
parents: 525
diff changeset
640 endfor
667
9090f866cd57 updated for version 7.0197
vimboss
parents: 659
diff changeset
641 let menu = res + res2
838
8e5830943bff updated for version 7.0e04
vimboss
parents: 837
diff changeset
642 if has_key(b:html_omni, 'vimxmltaginfo')
667
9090f866cd57 updated for version 7.0197
vimboss
parents: 659
diff changeset
643 let final_menu = []
9090f866cd57 updated for version 7.0197
vimboss
parents: 659
diff changeset
644 for i in range(len(menu))
9090f866cd57 updated for version 7.0197
vimboss
parents: 659
diff changeset
645 let item = menu[i]
838
8e5830943bff updated for version 7.0e04
vimboss
parents: 837
diff changeset
646 if has_key(b:html_omni['vimxmltaginfo'], item)
8e5830943bff updated for version 7.0e04
vimboss
parents: 837
diff changeset
647 let m_menu = b:html_omni['vimxmltaginfo'][item][0]
8e5830943bff updated for version 7.0e04
vimboss
parents: 837
diff changeset
648 let m_info = b:html_omni['vimxmltaginfo'][item][1]
667
9090f866cd57 updated for version 7.0197
vimboss
parents: 659
diff changeset
649 else
9090f866cd57 updated for version 7.0197
vimboss
parents: 659
diff changeset
650 let m_menu = ''
9090f866cd57 updated for version 7.0197
vimboss
parents: 659
diff changeset
651 let m_info = ''
9090f866cd57 updated for version 7.0197
vimboss
parents: 659
diff changeset
652 endif
841
c2cae213194d updated for version 7.0e07
vimboss
parents: 838
diff changeset
653 if &filetype == 'html' && exists("uppercase_tag") && uppercase_tag == 1 && item !~ 'DOCTYPE'
838
8e5830943bff updated for version 7.0e04
vimboss
parents: 837
diff changeset
654 let item = toupper(item)
8e5830943bff updated for version 7.0e04
vimboss
parents: 837
diff changeset
655 endif
841
c2cae213194d updated for version 7.0e07
vimboss
parents: 838
diff changeset
656 if item =~ 'DOCTYPE'
c2cae213194d updated for version 7.0e07
vimboss
parents: 838
diff changeset
657 let abbr = 'DOCTYPE '.matchstr(item, 'DTD \zsX\?HTML .\{-}\ze\/\/')
c2cae213194d updated for version 7.0e07
vimboss
parents: 838
diff changeset
658 else
c2cae213194d updated for version 7.0e07
vimboss
parents: 838
diff changeset
659 let abbr = item
c2cae213194d updated for version 7.0e07
vimboss
parents: 838
diff changeset
660 endif
c2cae213194d updated for version 7.0e07
vimboss
parents: 838
diff changeset
661 let final_menu += [{'abbr':abbr, 'word':item, 'menu':m_menu, 'info':m_info}]
667
9090f866cd57 updated for version 7.0197
vimboss
parents: 659
diff changeset
662 endfor
9090f866cd57 updated for version 7.0197
vimboss
parents: 659
diff changeset
663 else
9090f866cd57 updated for version 7.0197
vimboss
parents: 659
diff changeset
664 let final_menu = menu
9090f866cd57 updated for version 7.0197
vimboss
parents: 659
diff changeset
665 endif
9090f866cd57 updated for version 7.0197
vimboss
parents: 659
diff changeset
666 return final_menu
529
0d6092bb72e6 updated for version 7.0148
vimboss
parents: 525
diff changeset
667
659
d6a69271cb9a updated for version 7.0194
vimboss
parents: 649
diff changeset
668 " }}}
523
a7ae7e043e43 updated for version 7.0146
vimboss
parents:
diff changeset
669 endif
a7ae7e043e43 updated for version 7.0146
vimboss
parents:
diff changeset
670 endfunction
836
5a7843c57316 updated for version 7.0e02
vimboss
parents: 829
diff changeset
671
5a7843c57316 updated for version 7.0e02
vimboss
parents: 829
diff changeset
672 function! htmlcomplete#LoadData() " {{{
838
8e5830943bff updated for version 7.0e04
vimboss
parents: 837
diff changeset
673 if !exists("b:html_omni_flavor")
841
c2cae213194d updated for version 7.0e07
vimboss
parents: 838
diff changeset
674 if &filetype == 'html'
838
8e5830943bff updated for version 7.0e04
vimboss
parents: 837
diff changeset
675 let b:html_omni_flavor = 'html401t'
8e5830943bff updated for version 7.0e04
vimboss
parents: 837
diff changeset
676 else
8e5830943bff updated for version 7.0e04
vimboss
parents: 837
diff changeset
677 let b:html_omni_flavor = 'xhtml10s'
8e5830943bff updated for version 7.0e04
vimboss
parents: 837
diff changeset
678 endif
836
5a7843c57316 updated for version 7.0e02
vimboss
parents: 829
diff changeset
679 endif
838
8e5830943bff updated for version 7.0e04
vimboss
parents: 837
diff changeset
680 " With that if we still have bloated memory but create new buffer
8e5830943bff updated for version 7.0e04
vimboss
parents: 837
diff changeset
681 " variables only by linking to existing g:variable, not sourcing whole
8e5830943bff updated for version 7.0e04
vimboss
parents: 837
diff changeset
682 " file.
8e5830943bff updated for version 7.0e04
vimboss
parents: 837
diff changeset
683 if exists('g:xmldata_'.b:html_omni_flavor)
8e5830943bff updated for version 7.0e04
vimboss
parents: 837
diff changeset
684 exe 'let b:html_omni = g:xmldata_'.b:html_omni_flavor
8e5830943bff updated for version 7.0e04
vimboss
parents: 837
diff changeset
685 else
8e5830943bff updated for version 7.0e04
vimboss
parents: 837
diff changeset
686 exe 'runtime! autoload/xml/'.b:html_omni_flavor.'.vim'
8e5830943bff updated for version 7.0e04
vimboss
parents: 837
diff changeset
687 exe 'let b:html_omni = g:xmldata_'.b:html_omni_flavor
8e5830943bff updated for version 7.0e04
vimboss
parents: 837
diff changeset
688 endif
836
5a7843c57316 updated for version 7.0e02
vimboss
parents: 829
diff changeset
689 endfunction
5a7843c57316 updated for version 7.0e02
vimboss
parents: 829
diff changeset
690 " }}}
844
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 842
diff changeset
691 function! htmlcomplete#CheckDoctype() " {{{
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 842
diff changeset
692 if exists('b:html_omni_flavor')
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 842
diff changeset
693 let old_flavor = b:html_omni_flavor
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 842
diff changeset
694 else
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 842
diff changeset
695 let old_flavor = ''
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 842
diff changeset
696 endif
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 842
diff changeset
697 let i = 1
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 842
diff changeset
698 while i < 10 && i < line("$")
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 842
diff changeset
699 let line = getline(i)
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 842
diff changeset
700 if line =~ '<!DOCTYPE.*\<DTD HTML 3\.2'
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 842
diff changeset
701 let b:html_omni_flavor = 'html32'
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 842
diff changeset
702 let b:html_doctype = 1
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 842
diff changeset
703 break
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 842
diff changeset
704 elseif line =~ '<!DOCTYPE.*\<DTD HTML 4\.0 Transitional'
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 842
diff changeset
705 let b:html_omni_flavor = 'html40t'
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 842
diff changeset
706 let b:html_doctype = 1
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 842
diff changeset
707 break
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 842
diff changeset
708 elseif line =~ '<!DOCTYPE.*\<DTD HTML 4\.0 Frameset'
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 842
diff changeset
709 let b:html_omni_flavor = 'html40f'
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 842
diff changeset
710 let b:html_doctype = 1
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 842
diff changeset
711 break
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 842
diff changeset
712 elseif line =~ '<!DOCTYPE.*\<DTD HTML 4\.0'
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 842
diff changeset
713 let b:html_omni_flavor = 'html40s'
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 842
diff changeset
714 let b:html_doctype = 1
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 842
diff changeset
715 break
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 842
diff changeset
716 elseif line =~ '<!DOCTYPE.*\<DTD HTML 4\.01 Transitional'
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 842
diff changeset
717 let b:html_omni_flavor = 'html401t'
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 842
diff changeset
718 let b:html_doctype = 1
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 842
diff changeset
719 break
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 842
diff changeset
720 elseif line =~ '<!DOCTYPE.*\<DTD HTML 4\.01 Frameset'
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 842
diff changeset
721 let b:html_omni_flavor = 'html401f'
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 842
diff changeset
722 let b:html_doctype = 1
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 842
diff changeset
723 break
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 842
diff changeset
724 elseif line =~ '<!DOCTYPE.*\<DTD HTML 4\.01'
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 842
diff changeset
725 let b:html_omni_flavor = 'html401s'
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 842
diff changeset
726 let b:html_doctype = 1
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 842
diff changeset
727 break
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 842
diff changeset
728 elseif line =~ '<!DOCTYPE.*\<DTD XHTML 1\.0 Transitional'
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 842
diff changeset
729 let b:html_omni_flavor = 'xhtml10t'
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 842
diff changeset
730 let b:html_doctype = 1
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 842
diff changeset
731 break
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 842
diff changeset
732 elseif line =~ '<!DOCTYPE.*\<DTD XHTML 1\.0 Frameset'
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 842
diff changeset
733 let b:html_omni_flavor = 'xhtml10f'
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 842
diff changeset
734 let b:html_doctype = 1
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 842
diff changeset
735 break
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 842
diff changeset
736 elseif line =~ '<!DOCTYPE.*\<DTD XHTML 1\.0 Strict'
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 842
diff changeset
737 let b:html_omni_flavor = 'xhtml10s'
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 842
diff changeset
738 let b:html_doctype = 1
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 842
diff changeset
739 break
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 842
diff changeset
740 elseif line =~ '<!DOCTYPE.*\<DTD XHTML 1\.1'
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 842
diff changeset
741 let b:html_omni_flavor = 'xhtml11'
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 842
diff changeset
742 let b:html_doctype = 1
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 842
diff changeset
743 break
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 842
diff changeset
744 endif
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 842
diff changeset
745 let i += 1
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 842
diff changeset
746 endwhile
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 842
diff changeset
747 if !exists("b:html_doctype")
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 842
diff changeset
748 return
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 842
diff changeset
749 else
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 842
diff changeset
750 " Tie g:xmldata with b:html_omni this way we need to sourca data file only
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 842
diff changeset
751 " once, not every time per buffer.
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 842
diff changeset
752 if old_flavor == b:html_omni_flavor
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 842
diff changeset
753 return
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 842
diff changeset
754 else
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 842
diff changeset
755 if exists('g:xmldata_'.b:html_omni_flavor)
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 842
diff changeset
756 exe 'let b:html_omni = g:xmldata_'.b:html_omni_flavor
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 842
diff changeset
757 else
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 842
diff changeset
758 exe 'runtime! autoload/xml/'.b:html_omni_flavor.'.vim'
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 842
diff changeset
759 exe 'let b:html_omni = g:xmldata_'.b:html_omni_flavor
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 842
diff changeset
760 endif
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 842
diff changeset
761 return
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 842
diff changeset
762 endif
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 842
diff changeset
763 endif
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 842
diff changeset
764 endfunction
d3bbb5dd3913 updated for version 7.0f02
vimboss
parents: 842
diff changeset
765 " }}}
659
d6a69271cb9a updated for version 7.0194
vimboss
parents: 649
diff changeset
766 " vim:set foldmethod=marker: