523
|
1 " Vim completion script
|
|
2 " Language: XHTML 1.0 Strict
|
|
3 " Maintainer: Mikolaj Machowski ( mikmach AT wp DOT pl )
|
553
|
4 " Last Change: 2005 Oct 12
|
523
|
5
|
|
6 function! htmlcomplete#CompleteTags(findstart, base)
|
|
7 if a:findstart
|
|
8 " locate the start of the word
|
|
9 let line = getline('.')
|
|
10 let start = col('.') - 1
|
548
|
11 let compl_begin = col('.') - 2
|
|
12 while start >= 0 && line[start - 1] =~ '\(\k\|[:.-]\)'
|
|
13 let start -= 1
|
523
|
14 endwhile
|
548
|
15 if start >= 0 && line[start - 1] =~ '&'
|
|
16 let b:entitiescompl = 1
|
|
17 let b:compl_context = ''
|
|
18 return start
|
|
19 endif
|
|
20 let stylestart = searchpair('<style\>', '', '<\/style\>', "bnW")
|
|
21 let styleend = searchpair('<style\>', '', '<\/style\>', "nW")
|
|
22 if stylestart != 0 && styleend != 0
|
531
|
23 let curpos = line('.')
|
548
|
24 if stylestart <= curpos && styleend >= curpos
|
|
25 let start = col('.') - 1
|
|
26 let b:csscompl = 1
|
|
27 while start >= 0 && line[start - 1] =~ '\(\k\|-\)'
|
|
28 let start -= 1
|
|
29 endwhile
|
531
|
30 endif
|
|
31 endif
|
548
|
32 if !exists("b:csscompl")
|
|
33 let b:compl_context = getline('.')[0:(compl_begin)]
|
|
34 let b:compl_context = matchstr(b:compl_context, '.*<\zs.*')
|
|
35 else
|
|
36 let b:compl_context = getline('.')[0:compl_begin]
|
|
37 endif
|
523
|
38 return start
|
|
39 else
|
548
|
40 " Initialize base return lists
|
|
41 let res = []
|
|
42 let res2 = []
|
|
43 " a:base is very short - we need context
|
|
44 let context = b:compl_context
|
|
45 unlet! b:compl_context
|
531
|
46 " Check if we should do CSS completion inside of <style> tag
|
|
47 if exists("b:csscompl")
|
|
48 unlet! b:csscompl
|
548
|
49 return csscomplete#CompleteCSS(0, context)
|
531
|
50 endif
|
548
|
51 " Make entities completion
|
|
52 if exists("b:entitiescompl")
|
|
53 unlet! b:entitiescompl
|
|
54
|
|
55 " Very, very long line
|
553
|
56 let values = ["AElig", "Aacute", "Acirc", "Agrave", "Alpha", "Aring", "Atilde", "Auml", "Beta", "Ccedil", "Chi", "Dagger", "Delta", "ETH", "Eacute", "Ecirc", "Egrave", "Epsilon", "Eta", "Euml", "Gamma", "Iacute", "Icirc", "Igrave", "Iota", "Iuml", "Kappa", "Lambda", "Mu", "Ntilde", "Nu", "OElig", "Oacute", "Ocirc", "Ograve", "Omega", "Omicron", "Oslash", "Otilde", "Ouml", "Phi", "Pi", "Prime", "Psi", "Rho", "Scaron", "Sigma", "THORN", "TITY", "Tau", "Theta", "Uacute", "Ucirc", "Ugrave", "Upsilon", "Uuml", "Xi", "Yacute", "Yuml", "Zeta", "amp", "aacute", "acirc", "acute", "aelig", "agrave", "alefsym", "alpha", "and", "ang", "apos", "aring", "asymp", "atilde", "auml", "bdquo", "beta", "brvbar", "bull", "cap", "ccedil", "cedil", "cent", "chi", "circ", "clubs", "copy", "cong", "crarr", "cup", "curren", "dArr", "dagger", "darr", "deg", "delta", "diams", "divide", "eacute", "ecirc", "egrave", "empty", "ensp", "emsp", "epsilon", "equiv", "eta", "eth", "euro", "euml", "exist", "fnof", "forall", "frac12", "frac14", "frac34", "frasl", "gt", "gamma", "ge", "hArr", "harr", "hearts", "hellip", "iacute", "icirc", "iexcl", "igrave", "image", "infin", "int", "iota", "iquest", "isin", "iuml", "kappa", "lt", "laquo", "lArr", "lambda", "lang", "larr", "lceil", "ldquo", "le", "lfloor", "lowast", "loz", "lrm", "lsaquo", "lsquo", "macr", "mdash", "micro", "middot", "minus", "mu", "nbsp", "nabla", "ndash", "ne", "ni", "not", "notin", "nsub", "ntilde", "nu", "oacute", "ocirc", "oelig", "ograve", "oline", "omega", "omicron", "oplus", "or", "ordf", "ordm", "oslash", "otilde", "otimes", "ouml", "para", "part", "permil", "perp", "phi", "pi", "piv", "plusmn", "pound", "prime", "prod", "prop", "psi", "quot", "rArr", "raquo", "radic", "rang", "rarr", "rceil", "rdquo", "real", "reg", "rfloor", "rho", "rlm", "rsaquo", "rsquo", "sbquo", "scaron", "sdot", "sect", "shy", "sigma", "sigmaf", "sim", "spades", "sub", "sube", "sum", "sup", "sup1", "sup2", "sup3", "supe", "szlig", "tau", "there4", "theta", "thetasym", "thinsp", "thorn", "tilde", "times", "trade", "uArr", "uacute", "uarr", "ucirc", "ugrave", "uml", "upsih", "upsilon", "uuml", "weierp", "xi", "yacute", "yen", "yuml", "zeta", "zwj", "zwnj"]
|
548
|
57
|
553
|
58 for m in values
|
|
59 if m =~ '^'.a:base
|
548
|
60 call add(res, m.';')
|
|
61 endif
|
|
62 endfor
|
|
63
|
553
|
64 return res
|
548
|
65
|
|
66 endif
|
|
67 if context =~ '>'
|
|
68 " Generally if context contains > it means we are outside of tag and
|
531
|
69 " should abandon action - with one exception: <style> span { bo
|
548
|
70 if context =~ 'style[^>]\{-}>[^<]\{-}$'
|
|
71 return csscomplete#CompleteCSS(0, context)
|
531
|
72 else
|
|
73 return []
|
|
74 endif
|
|
75 endif
|
|
76
|
523
|
77 " Set attribute groups
|
531
|
78 let coreattrs = ["id", "class", "style", "title"]
|
|
79 let i18n = ["lang", "xml:lang", "dir=\"ltr\" ", "dir=\"rtl\" "]
|
|
80 let events = ["onclick", "ondblclick", "onmousedown", "onmouseup", "onmousemove",
|
548
|
81 \ "onmouseover", "onmouseout", "onkeypress", "onkeydown", "onkeyup"]
|
531
|
82 let focus = ["accesskey", "tabindex", "onfocus", "onblur"]
|
|
83 let coregroup = coreattrs + i18n + events
|
548
|
84 " find tags matching with "context"
|
|
85 " If context contains > it means we are already outside of tag and we
|
523
|
86 " should abandon action
|
548
|
87 " If context contains white space it is attribute.
|
523
|
88 " It could be also value of attribute...
|
531
|
89 " We have to get first word to offer
|
|
90 " proper completions
|
548
|
91 if context == ''
|
|
92 let tag = ''
|
|
93 else
|
|
94 let tag = split(context)[0]
|
|
95 endif
|
531
|
96 " Get last word, it should be attr name
|
548
|
97 let attr = matchstr(context, '.*\s\zs.*')
|
523
|
98 " Possible situations where any prediction would be difficult:
|
|
99 " 1. Events attributes
|
548
|
100 if context =~ '\s'
|
523
|
101 " Sort out style, class, and on* cases
|
548
|
102 if context =~ "\\(on[a-z]*\\|id\\|style\\|class\\)\\s*=\\s*[\"']"
|
|
103 if context =~ "\\(id\\|class\\)\\s*=\\s*[\"'][a-zA-Z0-9_ -]*$"
|
|
104 if context =~ "class\\s*=\\s*[\"'][a-zA-Z0-9_ -]*$"
|
532
|
105 let search_for = "class"
|
548
|
106 elseif context =~ "id\\s*=\\s*[\"'][a-zA-Z0-9_ -]*$"
|
532
|
107 let search_for = "id"
|
|
108 endif
|
531
|
109 " Handle class name completion
|
|
110 " 1. Find lines of <link stylesheet>
|
|
111 " 1a. Check file for @import
|
|
112 " 2. Extract filename(s?) of stylesheet,
|
|
113 call cursor(1,1)
|
|
114 let head = getline(search('<head\>'), search('<\/head>'))
|
|
115 let headjoined = join(copy(head), ' ')
|
|
116 if headjoined =~ '<style'
|
532
|
117 let stylehead = substitute(headjoined, '+>\*[,', ' ', 'g')
|
|
118 if search_for == 'class'
|
|
119 let styleheadlines = split(stylehead)
|
|
120 let headclasslines = filter(copy(styleheadlines), "v:val =~ '\\([a-zA-Z0-9:]\\+\\)\\?\\.[a-zA-Z0-9_-]\\+'")
|
|
121 else
|
|
122 let stylesheet = split(headjoined, '[{}]')
|
|
123 " Get all lines which fit id syntax
|
|
124 let classlines = filter(copy(stylesheet), "v:val =~ '#[a-zA-Z0-9_-]\\+'")
|
|
125 " Filter out possible color definitions
|
|
126 call filter(classlines, "v:val !~ ':\\s*#[a-zA-Z0-9_-]\\+'")
|
|
127 " Filter out complex border definitions
|
|
128 call filter(classlines, "v:val !~ '\\(none\\|hidden\\|dotted\\|dashed\\|solid\\|double\\|groove\\|ridge\\|inset\\|outset\\)\\s*#[a-zA-Z0-9_-]\\+'")
|
|
129 let templines = join(classlines, ' ')
|
|
130 let headclasslines = split(templines)
|
|
131 call filter(headclasslines, "v:val =~ '#[a-zA-Z0-9_-]\\+'")
|
|
132 endif
|
531
|
133 let internal = 1
|
|
134 else
|
|
135 let internal = 0
|
|
136 endif
|
|
137 let styletable = []
|
|
138 let secimportfiles = []
|
|
139 let filestable = filter(copy(head), "v:val =~ '\\(@import\\|link.*stylesheet\\)'")
|
|
140 for line in filestable
|
|
141 if line =~ "@import"
|
|
142 let styletable += [matchstr(line, "import\\s\\+\\(url(\\)\\?[\"']\\?\\zs\\f\\+\\ze")]
|
|
143 elseif line =~ "<link"
|
|
144 let styletable += [matchstr(line, "href\\s*=\\s*[\"']\\zs\\f\\+\\ze")]
|
|
145 endif
|
|
146 endfor
|
532
|
147 for file in styletable
|
531
|
148 if filereadable(file)
|
|
149 let stylesheet = readfile(file)
|
|
150 let secimport = filter(copy(stylesheet), "v:val =~ '@import'")
|
|
151 if len(secimport) > 0
|
|
152 for line in secimport
|
532
|
153 let secfile = matchstr(line, "import\\s\\+\\(url(\\)\\?[\"']\\?\\zs\\f\\+\\ze")
|
|
154 let secfile = fnamemodify(file, ":p:h").'/'.secfile
|
|
155 let secimportfiles += [secfile]
|
531
|
156 endfor
|
|
157 endif
|
|
158 endif
|
|
159 endfor
|
|
160 let cssfiles = styletable + secimportfiles
|
|
161 let classes = []
|
|
162 for file in cssfiles
|
|
163 if filereadable(file)
|
|
164 let stylesheet = readfile(file)
|
532
|
165 let stylefile = join(stylesheet, ' ')
|
|
166 let stylefile = substitute(stylefile, '+>\*[,', ' ', 'g')
|
|
167 if search_for == 'class'
|
|
168 let stylesheet = split(stylefile)
|
|
169 let classlines = filter(copy(stylesheet), "v:val =~ '\\([a-zA-Z0-9:]\\+\\)\\?\\.[a-zA-Z0-9_-]\\+'")
|
|
170 else
|
|
171 let stylesheet = split(stylefile, '[{}]')
|
|
172 " Get all lines which fit id syntax
|
|
173 let classlines = filter(copy(stylesheet), "v:val =~ '#[a-zA-Z0-9_-]\\+'")
|
|
174 " Filter out possible color definitions
|
|
175 call filter(classlines, "v:val !~ ':\\s*#[a-zA-Z0-9_-]\\+'")
|
|
176 " Filter out complex border definitions
|
|
177 call filter(classlines, "v:val !~ '\\(none\\|hidden\\|dotted\\|dashed\\|solid\\|double\\|groove\\|ridge\\|inset\\|outset\\)\\s*#[a-zA-Z0-9_-]\\+'")
|
|
178 let templines = join(classlines, ' ')
|
|
179 let stylelines = split(templines)
|
|
180 let classlines = filter(stylelines, "v:val =~ '#[a-zA-Z0-9_-]\\+'")
|
|
181
|
|
182 endif
|
531
|
183 endif
|
|
184 " We gathered classes definitions from all external files
|
|
185 let classes += classlines
|
|
186 endfor
|
|
187 if internal == 1
|
|
188 let classes += headclasslines
|
|
189 endif
|
532
|
190
|
|
191 if search_for == 'class'
|
|
192 let elements = {}
|
|
193 for element in classes
|
|
194 if element =~ '^\.'
|
|
195 let class = matchstr(element, '^\.\zs[a-zA-Z][a-zA-Z0-9_-]*\ze')
|
|
196 let class = substitute(class, ':.*', '', '')
|
|
197 if has_key(elements, 'common')
|
|
198 let elements['common'] .= ' '.class
|
|
199 else
|
|
200 let elements['common'] = class
|
|
201 endif
|
531
|
202 else
|
532
|
203 let class = matchstr(element, '[a-zA-Z1-6]*\.\zs[a-zA-Z][a-zA-Z0-9_-]*\ze')
|
|
204 let tagname = tolower(matchstr(element, '[a-zA-Z1-6]*\ze.'))
|
|
205 if tagname != ''
|
|
206 if has_key(elements, tagname)
|
|
207 let elements[tagname] .= ' '.class
|
|
208 else
|
|
209 let elements[tagname] = class
|
|
210 endif
|
531
|
211 endif
|
|
212 endif
|
532
|
213 endfor
|
|
214
|
|
215 if has_key(elements, tag) && has_key(elements, 'common')
|
|
216 let values = split(elements[tag]." ".elements['common'])
|
|
217 elseif has_key(elements, tag) && !has_key(elements, 'common')
|
|
218 let values = split(elements[tag])
|
|
219 elseif !has_key(elements, tag) && has_key(elements, 'common')
|
|
220 let values = split(elements['common'])
|
|
221 else
|
|
222 return []
|
531
|
223 endif
|
|
224
|
532
|
225 elseif search_for == 'id'
|
|
226 " Find used IDs
|
|
227 " 1. Catch whole file
|
|
228 let filelines = getline(1, line('$'))
|
|
229 " 2. Find lines with possible id
|
|
230 let used_id_lines = filter(filelines, 'v:val =~ "id\\s*=\\s*[\"''][a-zA-Z0-9_-]\\+"')
|
|
231 " 3a. Join all filtered lines
|
|
232 let id_string = join(used_id_lines, ' ')
|
|
233 " 3b. And split them to be sure each id is in separate item
|
|
234 let id_list = split(id_string, 'id\s*=\s*')
|
|
235 " 4. Extract id values
|
|
236 let used_id = map(id_list, 'matchstr(v:val, "[\"'']\\zs[a-zA-Z0-9_-]\\+\\ze")')
|
|
237 let joined_used_id = ','.join(used_id, ',').','
|
|
238
|
|
239 let allvalues = map(classes, 'matchstr(v:val, ".*#\\zs[a-zA-Z0-9_-]\\+")')
|
|
240
|
|
241 let values = []
|
|
242
|
|
243 for element in classes
|
|
244 if joined_used_id !~ ','.element.','
|
|
245 let values += [element]
|
|
246 endif
|
|
247
|
|
248 endfor
|
|
249
|
531
|
250 endif
|
|
251
|
|
252 " We need special version of sbase
|
548
|
253 let classbase = matchstr(context, ".*[\"']")
|
532
|
254 let classquote = matchstr(classbase, '.$')
|
531
|
255
|
|
256 let entered_class = matchstr(attr, ".*=\\s*[\"']\\zs.*")
|
|
257
|
|
258 for m in sort(values)
|
|
259 if m =~? '^'.entered_class
|
548
|
260 call add(res, m . classquote)
|
531
|
261 elseif m =~? entered_class
|
548
|
262 call add(res2, m . classquote)
|
531
|
263 endif
|
|
264 endfor
|
|
265
|
|
266 return res + res2
|
|
267
|
548
|
268 elseif context =~ "style\\s*=\\s*[\"'][^\"']*$"
|
|
269 return csscomplete#CompleteCSS(0, context)
|
531
|
270
|
|
271 endif
|
548
|
272 let stripbase = matchstr(context, ".*\\(on[a-z]*\\|style\\|class\\)\\s*=\\s*[\"']\\zs.*")
|
|
273 " Now we have context stripped from all chars up to style/class.
|
523
|
274 " It may fail with some strange style value combinations.
|
|
275 if stripbase !~ "[\"']"
|
|
276 return []
|
|
277 endif
|
|
278 endif
|
|
279 " If attr contains =\s*[\"'] we catched value of attribute
|
|
280 if attr =~ "=\s*[\"']"
|
|
281 " Let do attribute specific completion
|
|
282 let attrname = matchstr(attr, '.*\ze\s*=')
|
|
283 let entered_value = matchstr(attr, ".*=\\s*[\"']\\zs.*")
|
|
284 let values = []
|
|
285 if attrname == 'media'
|
|
286 let values = ["screen", "tty", "tv", "projection", "handheld", "print", "braille", "aural", "all"]
|
|
287 elseif attrname == 'xml:space'
|
|
288 let values = ["preserve"]
|
|
289 elseif attrname == 'shape'
|
553
|
290 let values = ["rect", "circle", "poly", "default"]
|
523
|
291 elseif attrname == 'valuetype'
|
|
292 let values = ["data", "ref", "object"]
|
|
293 elseif attrname == 'method'
|
|
294 let values = ["get", "post"]
|
525
|
295 elseif attrname == 'dir'
|
|
296 let values = ["ltr", "rtl"]
|
523
|
297 elseif attrname == 'frame'
|
|
298 let values = ["void", "above", "below", "hsides", "lhs", "rhs", "vsides", "box", "border"]
|
|
299 elseif attrname == 'rules'
|
|
300 let values = ["none", "groups", "rows", "all"]
|
|
301 elseif attrname == 'align'
|
|
302 let values = ["left", "center", "right", "justify", "char"]
|
|
303 elseif attrname == 'valign'
|
|
304 let values = ["top", "middle", "bottom", "baseline"]
|
|
305 elseif attrname == 'scope'
|
|
306 let values = ["row", "col", "rowgroup", "colgroup"]
|
|
307 elseif attrname == 'href'
|
|
308 " Now we are looking for local anchors defined by name or id
|
|
309 if entered_value =~ '^#'
|
|
310 let file = join(getline(1, line('$')), ' ')
|
|
311 " Split it be sure there will be one id/name element in
|
|
312 " item, it will be also first word [a-zA-Z0-9_-] in element
|
|
313 let oneelement = split(file, "\\(meta \\)\\@<!\\(name\\|id\\)\\s*=\\s*[\"']")
|
|
314 for i in oneelement
|
|
315 let values += ['#'.matchstr(i, "^[a-zA-Z][a-zA-Z0-9%_-]*")]
|
|
316 endfor
|
|
317 endif
|
|
318 elseif attrname == 'type'
|
548
|
319 if context =~ '^input'
|
531
|
320 let values = ["text", "password", "checkbox", "radio", "submit", "reset", "file", "hidden", "image", "button"]
|
548
|
321 elseif context =~ '^button'
|
523
|
322 let values = ["button", "submit", "reset"]
|
548
|
323 elseif context =~ '^style'
|
532
|
324 let values = ["text/css"]
|
548
|
325 elseif context =~ '^script'
|
532
|
326 let values = ["text/javascript"]
|
523
|
327 endif
|
|
328 else
|
|
329 return []
|
|
330 endif
|
|
331
|
|
332 if len(values) == 0
|
|
333 return []
|
|
334 endif
|
|
335
|
|
336 " We need special version of sbase
|
548
|
337 let attrbase = matchstr(context, ".*[\"']")
|
531
|
338 let attrquote = matchstr(attrbase, '.$')
|
523
|
339
|
|
340 for m in values
|
531
|
341 " This if is needed to not offer all completions as-is
|
|
342 " alphabetically but sort them. Those beginning with entered
|
|
343 " part will be as first choices
|
|
344 if m =~ '^'.entered_value
|
548
|
345 call add(res, m . attrquote.' ')
|
531
|
346 elseif m =~ entered_value
|
548
|
347 call add(res2, m . attrquote.' ')
|
523
|
348 endif
|
|
349 endfor
|
531
|
350
|
|
351 return res + res2
|
|
352
|
523
|
353 endif
|
548
|
354 " Shorten context to not include last word
|
|
355 let sbase = matchstr(context, '.*\ze\s.*')
|
|
356 if tag =~ '^\(abbr\|acronym\|address\|b\|bdo\|big\|caption\|cite\|code\|dd\|dfn\|div\|dl\|dt\|em\|fieldset\|h\d\|hr\|i\|kbd\|li\|noscript\|ol\|p\|samp\|small\|span\|strong\|sub\|sup\|tt\|ul\|var\)$'
|
531
|
357 let attrs = coregroup
|
523
|
358 elseif tag == 'a'
|
531
|
359 let attrs = coregroup + focus + ["charset", "type", "name", "href", "hreflang", "rel", "rev", "shape", "coords"]
|
523
|
360 elseif tag == 'area'
|
548
|
361 let attrs = coregroup + focus + ["shape", "coords", "href", "nohref", "alt"]
|
523
|
362 elseif tag == 'base'
|
|
363 let attrs = ["href", "id"]
|
|
364 elseif tag == 'blockquote'
|
531
|
365 let attrs = coregroup + ["cite"]
|
523
|
366 elseif tag == 'body'
|
531
|
367 let attrs = coregroup + ["onload", "onunload"]
|
523
|
368 elseif tag == 'br'
|
531
|
369 let attrs = coreattrs
|
523
|
370 elseif tag == 'button'
|
548
|
371 let attrs = coregroup + focus + ["name", "value", "type"]
|
523
|
372 elseif tag == '^\(col\|colgroup\)$'
|
548
|
373 let attrs = coregroup + ["span", "width", "align", "char", "charoff", "valign"]
|
523
|
374 elseif tag =~ '^\(del\|ins\)$'
|
548
|
375 let attrs = coregroup + ["cite", "datetime"]
|
523
|
376 elseif tag == 'form'
|
548
|
377 let attrs = coregroup + ["action", "method=\"get\" ", "method=\"post\" ", "enctype", "onsubmit", "onreset", "accept", "accept-charset"]
|
523
|
378 elseif tag == 'head'
|
531
|
379 let attrs = i18n + ["id", "profile"]
|
523
|
380 elseif tag == 'html'
|
531
|
381 let attrs = i18n + ["id", "xmlns"]
|
523
|
382 elseif tag == 'img'
|
548
|
383 let attrs = coregroup + ["src", "alt", "longdesc", "height", "width", "usemap", "ismap"]
|
523
|
384 elseif tag == 'input'
|
548
|
385 let attrs = coregroup + ["type", "name", "value", "checked", "disabled", "readonly", "size", "maxlength", "src", "alt", "usemap", "onselect", "onchange", "accept"]
|
523
|
386 elseif tag == 'label'
|
548
|
387 let attrs = coregroup + ["for", "accesskey", "onfocus", "onblur"]
|
523
|
388 elseif tag == 'legend'
|
548
|
389 let attrs = coregroup + ["accesskey"]
|
523
|
390 elseif tag == 'link'
|
548
|
391 let attrs = coregroup + ["charset", "href", "hreflang", "type", "rel", "rev", "media"]
|
523
|
392 elseif tag == 'map'
|
531
|
393 let attrs = i18n + events + ["id", "class", "style", "title", "name"]
|
523
|
394 elseif tag == 'meta'
|
531
|
395 let attrs = i18n + ["id", "http-equiv", "content", "scheme", "name"]
|
523
|
396 elseif tag == 'title'
|
531
|
397 let attrs = i18n + ["id"]
|
523
|
398 elseif tag == 'object'
|
548
|
399 let attrs = coregroup + ["declare", "classid", "codebase", "data", "type", "codetype", "archive", "standby", "height", "width", "usemap", "name", "tabindex"]
|
523
|
400 elseif tag == 'optgroup'
|
548
|
401 let attrs = coregroup + ["disbled", "label"]
|
523
|
402 elseif tag == 'option'
|
548
|
403 let attrs = coregroup + ["disbled", "selected", "value", "label"]
|
523
|
404 elseif tag == 'param'
|
|
405 let attrs = ["id", "name", "value", "valuetype", "type"]
|
|
406 elseif tag == 'pre'
|
548
|
407 let attrs = coregroup + ["xml:space"]
|
523
|
408 elseif tag == 'q'
|
548
|
409 let attrs = coregroup + ["cite"]
|
523
|
410 elseif tag == 'script'
|
532
|
411 let attrs = ["id", "charset", "type=\"text/javascript\"", "type", "src", "defer", "xml:space"]
|
523
|
412 elseif tag == 'select'
|
548
|
413 let attrs = coregroup + ["name", "size", "multiple", "disabled", "tabindex", "onfocus", "onblur", "onchange"]
|
523
|
414 elseif tag == 'style'
|
532
|
415 let attrs = coreattrs + ["id", "type=\"text/css\"", "type", "media", "title", "xml:space"]
|
523
|
416 elseif tag == 'table'
|
548
|
417 let attrs = coregroup + ["summary", "width", "border", "frame", "rules", "cellspacing", "cellpadding"]
|
523
|
418 elseif tag =~ '^\(thead\|tfoot\|tbody\|tr\)$'
|
548
|
419 let attrs = coregroup + ["align", "char", "charoff", "valign"]
|
523
|
420 elseif tag == 'textarea'
|
548
|
421 let attrs = coregroup + ["name", "rows", "cols", "disabled", "readonly", "onselect", "onchange"]
|
523
|
422 elseif tag =~ '^\(th\|td\)$'
|
548
|
423 let attrs = coregroup + ["abbr", "headers", "scope", "rowspan", "colspan", "align", "char", "charoff", "valign"]
|
531
|
424 else
|
|
425 return []
|
523
|
426 endif
|
|
427
|
|
428 for m in sort(attrs)
|
531
|
429 if m =~ '^'.attr
|
|
430 if m =~ '^\(ismap\|defer\|declare\|nohref\|checked\|disabled\|selected\|readonly\)$' || m =~ '='
|
548
|
431 call add(res, m)
|
523
|
432 else
|
548
|
433 call add(res, m.'="')
|
523
|
434 endif
|
531
|
435 elseif m =~ attr
|
|
436 if m =~ '^\(ismap\|defer\|declare\|nohref\|checked\|disabled\|selected\|readonly\)$' || m =~ '='
|
548
|
437 call add(res2, m)
|
531
|
438 else
|
548
|
439 call add(res2, m.'="')
|
531
|
440 endif
|
523
|
441 endif
|
|
442 endfor
|
531
|
443
|
|
444 return res + res2
|
|
445
|
523
|
446 endif
|
525
|
447 " Close tag
|
529
|
448 let b:unaryTagsStack = "base meta link hr br param img area input col"
|
548
|
449 if context =~ '^\/'
|
529
|
450 let opentag = htmlcomplete#GetLastOpenTag("b:unaryTagsStack")
|
548
|
451 return [opentag.">"]
|
525
|
452 endif
|
|
453 " Deal with tag completion.
|
529
|
454 let opentag = htmlcomplete#GetLastOpenTag("b:unaryTagsStack")
|
|
455 " Clusters
|
|
456 let special = "br span bdo map object img"
|
|
457 let phrase = "em strong dfn code q samp kbd var cite abbr acronym sub sup"
|
|
458 let inlineforms = "input select textarea label button"
|
|
459 let miscinline = "ins del script"
|
|
460 let inline = "a ".special." ".phrase." ".inlineforms." tt i b big small"
|
|
461 let misc = "noscript ".miscinline
|
|
462 let block = "p h1 h2 h3 h4 h5 h6 div ul ol dl pre hr blockquote address fieldset table"
|
525
|
463
|
529
|
464 if opentag == 'a'
|
|
465 let tags = split("tt i b big small ".special." ".phrase." ".inlineforms." ".miscinline)
|
|
466 elseif opentag =~ '^\(abbr\|acronym\|address\|b\|p\|h\d\|dt\|span\|bdo\|em\|strong\|dfn\|code\|samp\|kbd\|var\|cite\|q\|sub\|sup\|tt\|i\|big\|small\|label\|caption\)$'
|
|
467 let tags = split(inline." ".miscinline)
|
|
468 elseif opentag == 'pre'
|
|
469 let tags = split("a tt i b big small br span bdo map ".phrase." ".miscinline." ".inlineforms)
|
|
470 elseif opentag == 'html'
|
531
|
471 let tags = ["head", "body"]
|
529
|
472 elseif opentag == 'legend'
|
|
473 let tags = split(inline." ".miscinline)
|
|
474 elseif opentag == 'head'
|
531
|
475 let tags = ["title", "base", "scipt", "style", "meta", "link", "object"]
|
529
|
476 elseif opentag =~ '^\(noscript\|body\|blockquote\)$'
|
|
477 let tags = split("form ".block." ".misc)
|
|
478 elseif opentag =~ '^\(ul\|ol\)$'
|
|
479 let tags = ["li"]
|
|
480 elseif opentag == 'dl'
|
531
|
481 let tags = ["dt", "dd"]
|
529
|
482 elseif opentag =~ '^\(ins\|del\|th\|td\|dd\|div\|li\)$'
|
|
483 let tags = split("form ".block." ".inline." ".misc)
|
|
484 elseif opentag == 'object'
|
|
485 let tags = split("param form ".block." ".inline." ".misc)
|
|
486 elseif opentag == 'fieldset'
|
|
487 let tags = split("legend form ".block." ".inline." ".misc)
|
|
488 elseif opentag == 'map'
|
|
489 let tags = split("area form ".block." ".misc)
|
|
490 elseif opentag == 'form'
|
|
491 let tags = split(block." ".misc)
|
|
492 elseif opentag == 'select'
|
531
|
493 let tags = ["optgroup", "option"]
|
529
|
494 elseif opentag == 'optgroup'
|
|
495 let tags = ["option"]
|
|
496 elseif opentag == 'colgroup'
|
|
497 let tags = ["col"]
|
|
498 elseif opentag == '^\(textarea\|option\|script\|style\|title\)$'
|
531
|
499 let tags = ['empty']
|
529
|
500 elseif opentag == 'button'
|
531
|
501 let tags = ["p", "h1", "h2", "h3", "h4", "h5", "h6", "div", "ul", "ol", "dl", "table"]
|
|
502 elseif opentag =~ '^\(thead\|tfoot\|tbody\)$'
|
529
|
503 let tags = ["tr"]
|
|
504 elseif opentag == 'tr'
|
531
|
505 let tags = ["th", "td"]
|
529
|
506 elseif opentag == 'table'
|
531
|
507 let tags = ["caption", "col", "colgroup", "thead", "tfoot", "tbody", "tr"]
|
|
508 else
|
|
509 return []
|
525
|
510 endif
|
|
511
|
529
|
512 for m in tags
|
548
|
513 if m =~ '^'.context
|
523
|
514 call add(res, m)
|
548
|
515 elseif m =~ context
|
531
|
516 call add(res2, m)
|
523
|
517 endif
|
529
|
518 endfor
|
|
519
|
531
|
520 return res + res2
|
529
|
521
|
523
|
522 endif
|
|
523 endfunction
|
529
|
524
|
|
525 " MM: This is greatly reduced closetag.vim used with kind permission of Steven
|
|
526 " Mueller
|
|
527 " Changes: strip all comments; delete error messages
|
|
528 " Author: Steven Mueller <diffusor@ugcs.caltech.edu>
|
|
529 " Last Modified: Tue May 24 13:29:48 PDT 2005
|
|
530 " Version: 0.9.1
|
|
531
|
|
532 function! htmlcomplete#GetLastOpenTag(unaryTagsStack)
|
531
|
533 let linenum=line('.')
|
|
534 let lineend=col('.') - 1 " start: cursor position
|
529
|
535 let first=1 " flag for first line searched
|
531
|
536 let b:TagStack='' " main stack of tags
|
529
|
537 let startInComment=s:InComment()
|
|
538
|
|
539 let tagpat='</\=\(\k\|[-:]\)\+\|/>'
|
|
540 while (linenum>0)
|
|
541 let line=getline(linenum)
|
|
542 if first
|
|
543 let line=strpart(line,0,lineend)
|
|
544 else
|
|
545 let lineend=strlen(line)
|
|
546 endif
|
531
|
547 let b:lineTagStack=''
|
529
|
548 let mpos=0
|
|
549 let b:TagCol=0
|
|
550 while (mpos > -1)
|
|
551 let mpos=matchend(line,tagpat)
|
|
552 if mpos > -1
|
|
553 let b:TagCol=b:TagCol+mpos
|
|
554 let tag=matchstr(line,tagpat)
|
|
555
|
531
|
556 if exists('b:closetag_disable_synID') || startInComment==s:InCommentAt(linenum, b:TagCol)
|
529
|
557 let b:TagLine=linenum
|
531
|
558 call s:Push(matchstr(tag,'[^<>]\+'),'b:lineTagStack')
|
529
|
559 endif
|
|
560 let lineend=lineend-mpos
|
|
561 let line=strpart(line,mpos,lineend)
|
|
562 endif
|
|
563 endwhile
|
531
|
564 while (!s:EmptystackP('b:lineTagStack'))
|
|
565 let tag=s:Pop('b:lineTagStack')
|
|
566 if match(tag, '^/') == 0 "found end tag
|
|
567 call s:Push(tag,'b:TagStack')
|
|
568 elseif s:EmptystackP('b:TagStack') && !s:Instack(tag, a:unaryTagsStack) "found unclosed tag
|
529
|
569 return tag
|
|
570 else
|
531
|
571 let endtag=s:Peekstack('b:TagStack')
|
|
572 if endtag == '/'.tag || endtag == '/'
|
|
573 call s:Pop('b:TagStack') "found a open/close tag pair
|
|
574 elseif !s:Instack(tag, a:unaryTagsStack) "we have a mismatch error
|
|
575 return ''
|
|
576 endif
|
529
|
577 endif
|
531
|
578 endwhile
|
|
579 let linenum=linenum-1 | let first=0
|
529
|
580 endwhile
|
531
|
581 return ''
|
529
|
582 endfunction
|
|
583
|
|
584 function! s:InComment()
|
531
|
585 return synIDattr(synID(line('.'), col('.'), 0), 'name') =~ 'Comment'
|
529
|
586 endfunction
|
|
587
|
|
588 function! s:InCommentAt(line, col)
|
531
|
589 return synIDattr(synID(a:line, a:col, 0), 'name') =~ 'Comment'
|
529
|
590 endfunction
|
|
591
|
|
592 function! s:SetKeywords()
|
|
593 let g:IsKeywordBak=&iskeyword
|
531
|
594 let &iskeyword='33-255'
|
529
|
595 endfunction
|
|
596
|
|
597 function! s:RestoreKeywords()
|
|
598 let &iskeyword=g:IsKeywordBak
|
|
599 endfunction
|
|
600
|
|
601 function! s:Push(el, sname)
|
|
602 if !s:EmptystackP(a:sname)
|
531
|
603 exe 'let '.a:sname."=a:el.' '.".a:sname
|
529
|
604 else
|
531
|
605 exe 'let '.a:sname.'=a:el'
|
529
|
606 endif
|
|
607 endfunction
|
|
608
|
|
609 function! s:EmptystackP(sname)
|
531
|
610 exe 'let stack='.a:sname
|
|
611 if match(stack,'^ *$') == 0
|
529
|
612 return 1
|
|
613 else
|
|
614 return 0
|
|
615 endif
|
|
616 endfunction
|
|
617
|
|
618 function! s:Instack(el, sname)
|
531
|
619 exe 'let stack='.a:sname
|
529
|
620 call s:SetKeywords()
|
531
|
621 let m=match(stack, '\<'.a:el.'\>')
|
529
|
622 call s:RestoreKeywords()
|
|
623 if m < 0
|
|
624 return 0
|
|
625 else
|
|
626 return 1
|
|
627 endif
|
|
628 endfunction
|
|
629
|
|
630 function! s:Peekstack(sname)
|
|
631 call s:SetKeywords()
|
531
|
632 exe 'let stack='.a:sname
|
|
633 let top=matchstr(stack, '\<.\{-1,}\>')
|
529
|
634 call s:RestoreKeywords()
|
|
635 return top
|
|
636 endfunction
|
|
637
|
|
638 function! s:Pop(sname)
|
|
639 if s:EmptystackP(a:sname)
|
531
|
640 return ''
|
529
|
641 endif
|
531
|
642 exe 'let stack='.a:sname
|
529
|
643 call s:SetKeywords()
|
531
|
644 let loc=matchend(stack,'\<.\{-1,}\>')
|
|
645 exe 'let '.a:sname.'=strpart(stack, loc+1, strlen(stack))'
|
|
646 let top=strpart(stack, match(stack, '\<'), loc)
|
529
|
647 call s:RestoreKeywords()
|
|
648 return top
|
|
649 endfunction
|
|
650
|
|
651 function! s:Clearstack(sname)
|
531
|
652 exe 'let '.a:sname."=''"
|
529
|
653 endfunction
|