Mercurial > vim
comparison runtime/autoload/htmlcomplete.vim @ 529:0d6092bb72e6
updated for version 7.0148
author | vimboss |
---|---|
date | Fri, 16 Sep 2005 21:47:57 +0000 |
parents | 1f8d8c37d6ec |
children | da9142bd190a |
comparison
equal
deleted
inserted
replaced
528:66475621f0bf | 529:0d6092bb72e6 |
---|---|
1 " Vim completion script | 1 " Vim completion script |
2 " Language: XHTML 1.0 Strict | 2 " Language: XHTML 1.0 Strict |
3 " Maintainer: Mikolaj Machowski ( mikmach AT wp DOT pl ) | 3 " Maintainer: Mikolaj Machowski ( mikmach AT wp DOT pl ) |
4 " Last Change: 2005 Sep 13 | 4 " Last Change: 2005 Sep 15 |
5 | 5 |
6 function! htmlcomplete#CompleteTags(findstart, base) | 6 function! htmlcomplete#CompleteTags(findstart, base) |
7 if a:findstart | 7 if a:findstart |
8 " locate the start of the word | 8 " locate the start of the word |
9 let line = getline('.') | 9 let line = getline('.') |
233 endif | 233 endif |
234 endfor | 234 endfor |
235 return res | 235 return res |
236 endif | 236 endif |
237 " Close tag | 237 " Close tag |
238 if a:base =~ '^\/' && exists("*GetLastOpenTag") | 238 let b:unaryTagsStack = "base meta link hr br param img area input col" |
239 let b:unaryTagsStack = "base meta link hr br param img area input col" | 239 if a:base =~ '^\/' |
240 let opentag = GetLastOpenTag("b:unaryTagsStack") | 240 let opentag = htmlcomplete#GetLastOpenTag("b:unaryTagsStack") |
241 return ["/".opentag.">"] | 241 return ["/".opentag.">"] |
242 endif | 242 endif |
243 " Deal with tag completion. | 243 " Deal with tag completion. |
244 if exists("*GetLastOpenTag") | 244 let opentag = htmlcomplete#GetLastOpenTag("b:unaryTagsStack") |
245 " set b:unaryTagsStack to proper value for xhtml 1.0 or html 4.01 | 245 " Clusters |
246 let b:unaryTagsStack = "base meta link hr br param img area input col" | 246 let special = "br span bdo map object img" |
247 let opentag = GetLastOpenTag("b:unaryTagsStack") | 247 let phrase = "em strong dfn code q samp kbd var cite abbr acronym sub sup" |
248 " Clusters | 248 let inlineforms = "input select textarea label button" |
249 let special = "br span bdo map object img" | 249 let miscinline = "ins del script" |
250 let phrase = "em strong dfn code q samp kbd var cite abbr acronym sub sup" | 250 let inline = "a ".special." ".phrase." ".inlineforms." tt i b big small" |
251 let inlineforms = "input select textarea label button" | 251 let misc = "noscript ".miscinline |
252 let miscinline = "ins del script" | 252 let block = "p h1 h2 h3 h4 h5 h6 div ul ol dl pre hr blockquote address fieldset table" |
253 let inline = "a ".special." ".phrase." ".inlineforms." tt i b big small" | 253 |
254 let misc = "noscript ".miscinline | 254 if opentag == 'a' |
255 let block = "p h1 h2 h3 h4 h5 h6 div ul ol dl pre hr blockquote address fieldset table" | 255 let tags = split("tt i b big small ".special." ".phrase." ".inlineforms." ".miscinline) |
256 | 256 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\)$' |
257 if opentag == 'a' | 257 let tags = split(inline." ".miscinline) |
258 let tags = split("tt i b big small ".special." ".phrase." ".inlineforms." ".miscinline) | 258 elseif opentag == 'pre' |
259 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\)$' | 259 let tags = split("a tt i b big small br span bdo map ".phrase." ".miscinline." ".inlineforms) |
260 let tags = split(inline." ".miscinline) | 260 elseif opentag == 'html' |
261 elseif opentag == 'pre' | 261 let tags = split("head body") |
262 let tags = split("a tt i b big small br span bdo map ".phrase." ".miscinline." ".inlineforms) | 262 elseif opentag == 'legend' |
263 elseif opentag == 'html' | 263 let tags = split(inline." ".miscinline) |
264 let tags = split("head body") | 264 elseif opentag == 'head' |
265 elseif opentag == 'legend' | 265 let tags = split("title base scipt style meta link object") |
266 let tags = split(inline." ".miscinline) | 266 elseif opentag =~ '^\(noscript\|body\|blockquote\)$' |
267 elseif opentag == 'head' | 267 let tags = split("form ".block." ".misc) |
268 let tags = split("title base scipt style meta link object") | 268 elseif opentag =~ '^\(ul\|ol\)$' |
269 elseif opentag =~ '^\(noscript\|body\|blockquote\)$' | 269 let tags = ["li"] |
270 let tags = split("form ".block." ".misc) | 270 elseif opentag == 'dl' |
271 elseif opentag =~ '^\(ul\|ol\)$' | 271 let tags = split("dt dd") |
272 let tags = ["li"] | 272 elseif opentag =~ '^\(ins\|del\|th\|td\|dd\|div\|li\)$' |
273 elseif opentag == 'dl' | 273 let tags = split("form ".block." ".inline." ".misc) |
274 let tags = split("dt dd") | 274 elseif opentag == 'object' |
275 elseif opentag =~ '^\(ins\|del\|th\|td\|dd\|div\|li\)$' | 275 let tags = split("param form ".block." ".inline." ".misc) |
276 let tags = split("form ".block." ".inline." ".misc) | 276 elseif opentag == 'fieldset' |
277 elseif opentag == 'object' | 277 let tags = split("legend form ".block." ".inline." ".misc) |
278 let tags = split("param form ".block." ".inline." ".misc) | 278 elseif opentag == 'map' |
279 elseif opentag == 'fieldset' | 279 let tags = split("area form ".block." ".misc) |
280 let tags = split("legend form ".block." ".inline." ".misc) | 280 elseif opentag == 'form' |
281 elseif opentag == 'map' | 281 let tags = split(block." ".misc) |
282 let tags = split("area form ".block." ".misc) | 282 elseif opentag == 'select' |
283 elseif opentag == 'form' | 283 let tags = split("optgroup option") |
284 let tags = split(block." ".misc) | 284 elseif opentag == 'optgroup' |
285 elseif opentag == 'select' | 285 let tags = ["option"] |
286 let tags = split("optgroup option") | 286 elseif opentag == 'colgroup' |
287 elseif opentag == 'optgroup' | 287 let tags = ["col"] |
288 let tags = ["option"] | 288 elseif opentag == '^\(textarea\|option\|script\|style\|title\)$' |
289 elseif opentag == 'colgroup' | 289 let tags = [] |
290 let tags = ["col"] | 290 elseif opentag == 'button' |
291 elseif opentag == '^\(textarea\|option\|script\|style\|title\)$' | 291 let tags = split("p h1 h2 h3 h4 h5 h6 div ul ol dl table") |
292 let tags = [] | 292 elseif opentag =~ '^\(thead\|tfoot\|tbody)$' |
293 elseif opentag == 'button' | 293 let tags = ["tr"] |
294 let tags = split("p h1 h2 h3 h4 h5 h6 div ul ol dl table") | 294 elseif opentag == 'tr' |
295 elseif opentag =~ '^\(thead\|tfoot\|tbody)$' | 295 let tags = split("th td") |
296 let tags = ["tr"] | 296 elseif opentag == 'table' |
297 elseif opentag == 'tr' | 297 let tags = split("caption col colgroup thead tfoot tbody tr") |
298 let tags = split("th td") | 298 endif |
299 elseif opentag == 'table' | 299 |
300 let tags = split("caption col colgroup thead tfoot tbody tr") | 300 for m in tags |
301 endif | |
302 | |
303 for m in tags | |
304 if m =~ a:base | |
305 call add(res, m) | |
306 endif | |
307 endfor | |
308 return res | |
309 | |
310 endif | |
311 | |
312 for m in split("a abbr acronym address area b base bdo big blockquote body br button caption cite code col colgroup dd del dfn div dl dt em fieldset form head h1 h2 h3 h4 h5 h6 hr html i img input ins kbd label legend li link map meta noscript object ol optgroup option p param pre q samp script select small span strong style sub sup table tbody td textarea tfoot th thead title tr tt ul var") | |
313 if m =~ a:base | 301 if m =~ a:base |
314 call add(res, m) | 302 call add(res, m) |
315 endif | 303 endif |
316 endfor | 304 endfor |
317 return res | 305 |
306 return res | |
307 | |
318 endif | 308 endif |
319 endfunction | 309 endfunction |
310 | |
311 " MM: This is greatly reduced closetag.vim used with kind permission of Steven | |
312 " Mueller | |
313 " Changes: strip all comments; delete error messages | |
314 " Author: Steven Mueller <diffusor@ugcs.caltech.edu> | |
315 " Last Modified: Tue May 24 13:29:48 PDT 2005 | |
316 " Version: 0.9.1 | |
317 | |
318 function! htmlcomplete#GetLastOpenTag(unaryTagsStack) | |
319 let linenum=line(".") | |
320 let lineend=col(".") - 1 " start: cursor position | |
321 let first=1 " flag for first line searched | |
322 let b:TagStack="" " main stack of tags | |
323 let startInComment=s:InComment() | |
324 | |
325 let tagpat='</\=\(\k\|[-:]\)\+\|/>' | |
326 while (linenum>0) | |
327 let line=getline(linenum) | |
328 if first | |
329 let line=strpart(line,0,lineend) | |
330 else | |
331 let lineend=strlen(line) | |
332 endif | |
333 let b:lineTagStack="" | |
334 let mpos=0 | |
335 let b:TagCol=0 | |
336 while (mpos > -1) | |
337 let mpos=matchend(line,tagpat) | |
338 if mpos > -1 | |
339 let b:TagCol=b:TagCol+mpos | |
340 let tag=matchstr(line,tagpat) | |
341 | |
342 if exists("b:closetag_disable_synID") || startInComment==s:InCommentAt(linenum, b:TagCol) | |
343 let b:TagLine=linenum | |
344 call s:Push(matchstr(tag,'[^<>]\+'),"b:lineTagStack") | |
345 endif | |
346 let lineend=lineend-mpos | |
347 let line=strpart(line,mpos,lineend) | |
348 endif | |
349 endwhile | |
350 while (!s:EmptystackP("b:lineTagStack")) | |
351 let tag=s:Pop("b:lineTagStack") | |
352 if match(tag, "^/") == 0 "found end tag | |
353 call s:Push(tag,"b:TagStack") | |
354 elseif s:EmptystackP("b:TagStack") && !s:Instack(tag, a:unaryTagsStack) "found unclosed tag | |
355 return tag | |
356 else | |
357 let endtag=s:Peekstack("b:TagStack") | |
358 if endtag == "/".tag || endtag == "/" | |
359 call s:Pop("b:TagStack") "found a open/close tag pair | |
360 elseif !s:Instack(tag, a:unaryTagsStack) "we have a mismatch error | |
361 return "" | |
362 endif | |
363 endif | |
364 endwhile | |
365 let linenum=linenum-1 | let first=0 | |
366 endwhile | |
367 return "" | |
368 endfunction | |
369 | |
370 function! s:InComment() | |
371 return synIDattr(synID(line("."), col("."), 0), "name") =~ 'Comment' | |
372 endfunction | |
373 | |
374 function! s:InCommentAt(line, col) | |
375 return synIDattr(synID(a:line, a:col, 0), "name") =~ 'Comment' | |
376 endfunction | |
377 | |
378 | |
379 function! s:SetKeywords() | |
380 let g:IsKeywordBak=&iskeyword | |
381 let &iskeyword="33-255" | |
382 endfunction | |
383 | |
384 function! s:RestoreKeywords() | |
385 let &iskeyword=g:IsKeywordBak | |
386 endfunction | |
387 | |
388 function! s:Push(el, sname) | |
389 if !s:EmptystackP(a:sname) | |
390 exe "let ".a:sname."=a:el.' '.".a:sname | |
391 else | |
392 exe "let ".a:sname."=a:el" | |
393 endif | |
394 endfunction | |
395 | |
396 function! s:EmptystackP(sname) | |
397 exe "let stack=".a:sname | |
398 if match(stack,"^ *$") == 0 | |
399 return 1 | |
400 else | |
401 return 0 | |
402 endif | |
403 endfunction | |
404 | |
405 function! s:Instack(el, sname) | |
406 exe "let stack=".a:sname | |
407 call s:SetKeywords() | |
408 let m=match(stack, "\\<".a:el."\\>") | |
409 call s:RestoreKeywords() | |
410 if m < 0 | |
411 return 0 | |
412 else | |
413 return 1 | |
414 endif | |
415 endfunction | |
416 | |
417 function! s:Peekstack(sname) | |
418 call s:SetKeywords() | |
419 exe "let stack=".a:sname | |
420 let top=matchstr(stack, "\\<.\\{-1,}\\>") | |
421 call s:RestoreKeywords() | |
422 return top | |
423 endfunction | |
424 | |
425 function! s:Pop(sname) | |
426 if s:EmptystackP(a:sname) | |
427 return "" | |
428 endif | |
429 exe "let stack=".a:sname | |
430 call s:SetKeywords() | |
431 let loc=matchend(stack,"\\<.\\{-1,}\\>") | |
432 exe "let ".a:sname."=strpart(stack, loc+1, strlen(stack))" | |
433 let top=strpart(stack, match(stack, "\\<"), loc) | |
434 call s:RestoreKeywords() | |
435 return top | |
436 endfunction | |
437 | |
438 function! s:Clearstack(sname) | |
439 exe "let ".a:sname."=''" | |
440 endfunction |