Mercurial > vim
comparison runtime/autoload/htmlcomplete.vim @ 837:6bb1fa855dc9 v7.0e03
updated for version 7.0e03
author | vimboss |
---|---|
date | Wed, 19 Apr 2006 21:23:36 +0000 |
parents | 5a7843c57316 |
children | 8e5830943bff |
comparison
equal
deleted
inserted
replaced
836:5a7843c57316 | 837:6bb1fa855dc9 |
---|---|
208 " We have to get first word to offer proper completions | 208 " We have to get first word to offer proper completions |
209 if context == '' | 209 if context == '' |
210 let tag = '' | 210 let tag = '' |
211 else | 211 else |
212 let tag = split(context)[0] | 212 let tag = split(context)[0] |
213 endif | 213 if tag =~ '[A-Z]' |
214 let uppercase_tag = 1 | |
215 let tag = tolower(tag) | |
216 else | |
217 let uppercase_tag = 0 | |
218 endif | |
219 endif | |
220 let g:ta = tag | |
214 " Get last word, it should be attr name | 221 " Get last word, it should be attr name |
215 let attr = matchstr(context, '.*\s\zs.*') | 222 let attr = matchstr(context, '.*\s\zs.*') |
216 " Possible situations where any prediction would be difficult: | 223 " Possible situations where any prediction would be difficult: |
217 " 1. Events attributes | 224 " 1. Events attributes |
218 if context =~ '\s' | 225 if context =~ '\s' |
436 return [] | 443 return [] |
437 endif | 444 endif |
438 endif | 445 endif |
439 " Value of attribute completion {{{ | 446 " Value of attribute completion {{{ |
440 " If attr contains =\s*[\"'] we catched value of attribute | 447 " If attr contains =\s*[\"'] we catched value of attribute |
441 if attr =~ "=\s*[\"']" | 448 if attr =~ "=\s*[\"']" || attr =~ "=\s*$" |
442 " Let do attribute specific completion | 449 " Let do attribute specific completion |
443 let attrname = matchstr(attr, '.*\ze\s*=') | 450 let attrname = matchstr(attr, '.*\ze\s*=') |
444 let entered_value = matchstr(attr, ".*=\\s*[\"']\\zs.*") | 451 let entered_value = matchstr(attr, ".*=\\s*[\"']\\?\\zs.*") |
445 let values = [] | 452 let values = [] |
446 if attrname == 'href' | 453 if attrname == 'href' |
447 " Now we are looking for local anchors defined by name or id | 454 " Now we are looking for local anchors defined by name or id |
448 if entered_value =~ '^#' | 455 if entered_value =~ '^#' |
449 let file = join(getline(1, line('$')), ' ') | 456 let file = join(getline(1, line('$')), ' ') |
467 endif | 474 endif |
468 | 475 |
469 " We need special version of sbase | 476 " We need special version of sbase |
470 let attrbase = matchstr(context, ".*[\"']") | 477 let attrbase = matchstr(context, ".*[\"']") |
471 let attrquote = matchstr(attrbase, '.$') | 478 let attrquote = matchstr(attrbase, '.$') |
479 if attrquote !~ "['\"]" | |
480 let attrquoteopen = '"' | |
481 let attrquote = '"' | |
482 else | |
483 let attrquoteopen = '' | |
484 endif | |
472 | 485 |
473 for m in values | 486 for m in values |
474 " This if is needed to not offer all completions as-is | 487 " This if is needed to not offer all completions as-is |
475 " alphabetically but sort them. Those beginning with entered | 488 " alphabetically but sort them. Those beginning with entered |
476 " part will be as first choices | 489 " part will be as first choices |
477 if m =~ '^'.entered_value | 490 if m =~ '^'.entered_value |
478 call add(res, m . attrquote.' ') | 491 call add(res, attrquoteopen . m . attrquote.' ') |
479 elseif m =~ entered_value | 492 elseif m =~ entered_value |
480 call add(res2, m . attrquote.' ') | 493 call add(res2, attrquoteopen . m . attrquote.' ') |
481 endif | 494 endif |
482 endfor | 495 endfor |
483 | 496 |
484 return res + res2 | 497 return res + res2 |
485 | 498 |
492 " Load data {{{ | 505 " Load data {{{ |
493 if !exists("g:html_omni_gen") | 506 if !exists("g:html_omni_gen") |
494 call htmlcomplete#LoadData() | 507 call htmlcomplete#LoadData() |
495 endif | 508 endif |
496 " }}} | 509 " }}} |
497 " | 510 |
498 let attrs = keys(g:html_omni[tag][1]) | 511 if has_key(g:html_omni, tag) |
512 let attrs = keys(g:html_omni[tag][1]) | |
513 else | |
514 return [] | |
515 endif | |
499 | 516 |
500 for m in sort(attrs) | 517 for m in sort(attrs) |
501 if m =~ '^'.attr | 518 if m =~ '^'.attr |
502 call add(res, m) | 519 call add(res, m) |
503 elseif m =~ attr | 520 elseif m =~ attr |
537 else | 554 else |
538 let opentag = xmlcomplete#GetLastOpenTag("b:unaryTagsStack") | 555 let opentag = xmlcomplete#GetLastOpenTag("b:unaryTagsStack") |
539 return [opentag.">"] | 556 return [opentag.">"] |
540 endif | 557 endif |
541 endif | 558 endif |
559 " }}} | |
542 " Load data {{{ | 560 " Load data {{{ |
543 if !exists("g:html_omni") | 561 if !exists("g:html_omni") |
544 "runtime! autoload/xml/xhtml10s.vim | 562 "runtime! autoload/xml/xhtml10s.vim |
545 call htmlcomplete#LoadData() | 563 call htmlcomplete#LoadData() |
546 endif | 564 endif |
547 " }}} | 565 " }}} |
548 " Tag completion {{{ | 566 " Tag completion {{{ |
549 " Deal with tag completion. | 567 " Deal with tag completion. |
550 let opentag = xmlcomplete#GetLastOpenTag("b:unaryTagsStack") | 568 let opentag = tolower(xmlcomplete#GetLastOpenTag("b:unaryTagsStack")) |
551 " MM: TODO: GLOT works always the same but with some weird situation it | 569 " MM: TODO: GLOT works always the same but with some weird situation it |
552 " behaves as intended in HTML but screws in PHP | 570 " behaves as intended in HTML but screws in PHP |
553 let g:ot = opentag | |
554 if opentag == '' || &ft == 'php' && !has_key(g:html_omni, opentag) | 571 if opentag == '' || &ft == 'php' && !has_key(g:html_omni, opentag) |
555 " Hack for sometimes failing GetLastOpenTag. | 572 " Hack for sometimes failing GetLastOpenTag. |
556 " As far as I tested fail isn't GLOT fault but problem | 573 " As far as I tested fail isn't GLOT fault but problem |
557 " of invalid document - not properly closed tags and other mish-mash. | 574 " of invalid document - not properly closed tags and other mish-mash. |
558 " Also when document is empty. Return list of *all* tags. | 575 " Also when document is empty. Return list of *all* tags. |
559 let tags = keys(g:html_omni) | 576 let tags = keys(g:html_omni) |
560 call filter(tags, 'v:val !~ "^vimxml"') | 577 call filter(tags, 'v:val !~ "^vimxml"') |
561 else | 578 else |
562 let tags = g:html_omni[opentag][0] | 579 if has_key(g:html_omni, opentag) |
563 endif | 580 let tags = g:html_omni[opentag][0] |
564 " }}} | 581 else |
582 return [] | |
583 endif | |
584 endif | |
585 " }}} | |
586 | |
587 if exists("uppercase_tag") && uppercase_tag == 1 | |
588 let context = tolower(context) | |
589 endif | |
565 | 590 |
566 for m in sort(tags) | 591 for m in sort(tags) |
567 if m =~ '^'.context | 592 if m =~ '^'.context |
568 call add(res, m) | 593 call add(res, m) |
569 elseif m =~ context | 594 elseif m =~ context |