Mercurial > vim
comparison runtime/autoload/htmlcomplete.vim @ 838:8e5830943bff v7.0e04
updated for version 7.0e04
author | vimboss |
---|---|
date | Thu, 20 Apr 2006 22:17:20 +0000 |
parents | 6bb1fa855dc9 |
children | c2cae213194d |
comparison
equal
deleted
inserted
replaced
837:6bb1fa855dc9 | 838:8e5830943bff |
---|---|
1 " Vim completion script | 1 " Vim completion script |
2 " Language: HTML (XHTML 1.0 Strict by default) | 2 " Language: HTML and XHTML |
3 " Maintainer: Mikolaj Machowski ( mikmach AT wp DOT pl ) | 3 " Maintainer: Mikolaj Machowski ( mikmach AT wp DOT pl ) |
4 " Last Change: 2006 Apr 17 | 4 " Last Change: 2006 Apr 20 |
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('.') |
157 unlet! b:compl_context | 157 unlet! b:compl_context |
158 " Entities completion {{{ | 158 " Entities completion {{{ |
159 if exists("b:entitiescompl") | 159 if exists("b:entitiescompl") |
160 unlet! b:entitiescompl | 160 unlet! b:entitiescompl |
161 | 161 |
162 if !exists("g:html_omni") | 162 if !exists("b:html_omni") |
163 "runtime! autoload/xml/xhtml10s.vim | 163 "runtime! autoload/xml/xhtml10s.vim |
164 call htmlcomplete#LoadData() | 164 call htmlcomplete#LoadData() |
165 endif | 165 endif |
166 | 166 |
167 let entities = g:html_omni['vimxmlentities'] | 167 let entities = b:html_omni['vimxmlentities'] |
168 | 168 |
169 if len(a:base) == 1 | 169 if len(a:base) == 1 |
170 for m in entities | 170 for m in entities |
171 if m =~ '^'.a:base | 171 if m =~ '^'.a:base |
172 call add(res, m.';') | 172 call add(res, m.';') |
460 for i in oneelement | 460 for i in oneelement |
461 let values += ['#'.matchstr(i, "^[a-zA-Z][a-zA-Z0-9%_-]*")] | 461 let values += ['#'.matchstr(i, "^[a-zA-Z][a-zA-Z0-9%_-]*")] |
462 endfor | 462 endfor |
463 endif | 463 endif |
464 else | 464 else |
465 if has_key(g:html_omni, tag) && has_key(g:html_omni[tag][1], attrname) | 465 if has_key(b:html_omni, tag) && has_key(b:html_omni[tag][1], attrname) |
466 let values = g:html_omni[tag][1][attrname] | 466 let values = b:html_omni[tag][1][attrname] |
467 else | 467 else |
468 return [] | 468 return [] |
469 endif | 469 endif |
470 endif | 470 endif |
471 | 471 |
501 " Attribute completion {{{ | 501 " Attribute completion {{{ |
502 " Shorten context to not include last word | 502 " Shorten context to not include last word |
503 let sbase = matchstr(context, '.*\ze\s.*') | 503 let sbase = matchstr(context, '.*\ze\s.*') |
504 | 504 |
505 " Load data {{{ | 505 " Load data {{{ |
506 if !exists("g:html_omni_gen") | 506 if !exists("b:html_omni_gen") |
507 call htmlcomplete#LoadData() | 507 call htmlcomplete#LoadData() |
508 endif | 508 endif |
509 " }}} | 509 " }}} |
510 | 510 |
511 if has_key(g:html_omni, tag) | 511 if has_key(b:html_omni, tag) |
512 let attrs = keys(g:html_omni[tag][1]) | 512 let attrs = keys(b:html_omni[tag][1]) |
513 else | 513 else |
514 return [] | 514 return [] |
515 endif | 515 endif |
516 | 516 |
517 for m in sort(attrs) | 517 for m in sort(attrs) |
520 elseif m =~ attr | 520 elseif m =~ attr |
521 call add(res2, m) | 521 call add(res2, m) |
522 endif | 522 endif |
523 endfor | 523 endfor |
524 let menu = res + res2 | 524 let menu = res + res2 |
525 if has_key(g:html_omni, 'vimxmlattrinfo') | 525 if has_key(b:html_omni, 'vimxmlattrinfo') |
526 let final_menu = [] | 526 let final_menu = [] |
527 for i in range(len(menu)) | 527 for i in range(len(menu)) |
528 let item = menu[i] | 528 let item = menu[i] |
529 if has_key(g:html_omni['vimxmlattrinfo'], item) | 529 if has_key(b:html_omni['vimxmlattrinfo'], item) |
530 let m_menu = g:html_omni['vimxmlattrinfo'][item][0] | 530 let m_menu = b:html_omni['vimxmlattrinfo'][item][0] |
531 let m_info = g:html_omni['vimxmlattrinfo'][item][1] | 531 let m_info = b:html_omni['vimxmlattrinfo'][item][1] |
532 if m_menu !~ 'Bool' | 532 if m_menu !~ 'Bool' |
533 let item .= '="' | 533 let item .= '="' |
534 endif | 534 endif |
535 else | 535 else |
536 let m_menu = '' | 536 let m_menu = '' |
556 return [opentag.">"] | 556 return [opentag.">"] |
557 endif | 557 endif |
558 endif | 558 endif |
559 " }}} | 559 " }}} |
560 " Load data {{{ | 560 " Load data {{{ |
561 if !exists("g:html_omni") | 561 if !exists("b:html_omni") |
562 "runtime! autoload/xml/xhtml10s.vim | 562 "runtime! autoload/xml/xhtml10s.vim |
563 call htmlcomplete#LoadData() | 563 call htmlcomplete#LoadData() |
564 endif | 564 endif |
565 " }}} | 565 " }}} |
566 " Tag completion {{{ | 566 " Tag completion {{{ |
567 " Deal with tag completion. | 567 " Deal with tag completion. |
568 let opentag = tolower(xmlcomplete#GetLastOpenTag("b:unaryTagsStack")) | 568 let opentag = tolower(xmlcomplete#GetLastOpenTag("b:unaryTagsStack")) |
569 " 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 |
570 " behaves as intended in HTML but screws in PHP | 570 " behaves as intended in HTML but screws in PHP |
571 if opentag == '' || &ft == 'php' && !has_key(g:html_omni, opentag) | 571 if opentag == '' || &ft == 'php' && !has_key(b:html_omni, opentag) |
572 " Hack for sometimes failing GetLastOpenTag. | 572 " Hack for sometimes failing GetLastOpenTag. |
573 " 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 |
574 " of invalid document - not properly closed tags and other mish-mash. | 574 " of invalid document - not properly closed tags and other mish-mash. |
575 " Also when document is empty. Return list of *all* tags. | 575 " Also when document is empty. Return list of *all* tags. |
576 let tags = keys(g:html_omni) | 576 let tags = keys(b:html_omni) |
577 call filter(tags, 'v:val !~ "^vimxml"') | 577 call filter(tags, 'v:val !~ "^vimxml"') |
578 else | 578 else |
579 if has_key(g:html_omni, opentag) | 579 if has_key(b:html_omni, opentag) |
580 let tags = g:html_omni[opentag][0] | 580 let tags = b:html_omni[opentag][0] |
581 else | 581 else |
582 return [] | 582 return [] |
583 endif | 583 endif |
584 endif | 584 endif |
585 " }}} | 585 " }}} |
594 elseif m =~ context | 594 elseif m =~ context |
595 call add(res2, m) | 595 call add(res2, m) |
596 endif | 596 endif |
597 endfor | 597 endfor |
598 let menu = res + res2 | 598 let menu = res + res2 |
599 if has_key(g:html_omni, 'vimxmltaginfo') | 599 if has_key(b:html_omni, 'vimxmltaginfo') |
600 let final_menu = [] | 600 let final_menu = [] |
601 for i in range(len(menu)) | 601 for i in range(len(menu)) |
602 let item = menu[i] | 602 let item = menu[i] |
603 if has_key(g:html_omni['vimxmltaginfo'], item) | 603 if has_key(b:html_omni['vimxmltaginfo'], item) |
604 let m_menu = g:html_omni['vimxmltaginfo'][item][0] | 604 let m_menu = b:html_omni['vimxmltaginfo'][item][0] |
605 let m_info = g:html_omni['vimxmltaginfo'][item][1] | 605 let m_info = b:html_omni['vimxmltaginfo'][item][1] |
606 else | 606 else |
607 let m_menu = '' | 607 let m_menu = '' |
608 let m_info = '' | 608 let m_info = '' |
609 endif | |
610 if &ft == 'html' && exists("uppercase_tag") && uppercase_tag == 1 | |
611 let item = toupper(item) | |
609 endif | 612 endif |
610 let final_menu += [{'word':item, 'menu':m_menu, 'info':m_info}] | 613 let final_menu += [{'word':item, 'menu':m_menu, 'info':m_info}] |
611 endfor | 614 endfor |
612 else | 615 else |
613 let final_menu = menu | 616 let final_menu = menu |
617 " }}} | 620 " }}} |
618 endif | 621 endif |
619 endfunction | 622 endfunction |
620 | 623 |
621 function! htmlcomplete#LoadData() " {{{ | 624 function! htmlcomplete#LoadData() " {{{ |
622 if !exists("g:html_omni_flavor") | 625 if !exists("b:html_omni_flavor") |
623 let g:html_omni_flavor = 'xhtml10s' | 626 if &ft == 'html' |
624 endif | 627 let b:html_omni_flavor = 'html401t' |
625 exe 'runtime! autoload/xml/'.g:html_omni_flavor.'.vim' | 628 else |
626 " This one is necessary because we don't know if | 629 let b:html_omni_flavor = 'xhtml10s' |
627 " g:html_omni_flavor file exists and was sourced | 630 endif |
631 endif | |
632 " With that if we still have bloated memory but create new buffer | |
633 " variables only by linking to existing g:variable, not sourcing whole | |
634 " file. | |
635 if exists('g:xmldata_'.b:html_omni_flavor) | |
636 exe 'let b:html_omni = g:xmldata_'.b:html_omni_flavor | |
637 else | |
638 exe 'runtime! autoload/xml/'.b:html_omni_flavor.'.vim' | |
639 exe 'let b:html_omni = g:xmldata_'.b:html_omni_flavor | |
640 endif | |
641 " This repetition is necessary because we don't know if | |
642 " b:html_omni_flavor file exists and was sourced | |
628 " Proper checking for files would require iterating through 'rtp' | 643 " Proper checking for files would require iterating through 'rtp' |
629 " and could introduce OS dependent mess. | 644 " and could introduce OS dependent mess. |
630 if !exists("g:xmldata_".g:html_omni_flavor) | 645 if !exists("g:xmldata_".b:html_omni_flavor) |
631 let g:html_omni_flavor = 'xhtml10s' | 646 if &ft == 'html' |
632 runtime! autoload/xml/xhtml10s.vim | 647 let b:html_omni_flavor = 'html401t' |
633 endif | 648 else |
634 | 649 let b:html_omni_flavor = 'xhtml10s' |
635 exe 'let g:html_omni = g:xmldata_'.g:html_omni_flavor | 650 endif |
636 | 651 endif |
637 " Free some memory | 652 if exists('g:xmldata_'.b:html_omni_flavor) |
638 exe 'unlet! g:xmldata_'.g:html_omni_flavor | 653 exe 'let b:html_omni = g:xmldata_'.b:html_omni_flavor |
639 | 654 else |
640 "call htmlcomplete#LoadData() | 655 exe 'runtime! autoload/xml/'.b:html_omni_flavor.'.vim' |
656 exe 'let b:html_omni = g:xmldata_'.b:html_omni_flavor | |
657 endif | |
641 endfunction | 658 endfunction |
642 " }}} | 659 " }}} |
643 " vim:set foldmethod=marker: | 660 " vim:set foldmethod=marker: |