comparison runtime/autoload/htmlcomplete.vim @ 844:d3bbb5dd3913 v7.0f02

updated for version 7.0f02
author vimboss
date Thu, 27 Apr 2006 00:02:13 +0000
parents a209672376fd
children 8cd729851562
comparison
equal deleted inserted replaced
843:9f279ebda751 844:d3bbb5dd3913
125 " Initialize base return lists 125 " Initialize base return lists
126 let res = [] 126 let res = []
127 let res2 = [] 127 let res2 = []
128 " a:base is very short - we need context 128 " a:base is very short - we need context
129 let context = b:compl_context 129 let context = b:compl_context
130 let g:ab = a:base
131 let g:co = context
132 " Check if we should do CSS completion inside of <style> tag 130 " Check if we should do CSS completion inside of <style> tag
133 " or JS completion inside of <script> tag or PHP completion in case of <? 131 " or JS completion inside of <script> tag or PHP completion in case of <?
134 " tag AND &ft==php 132 " tag AND &ft==php
135 if exists("b:csscompl") 133 if exists("b:csscompl")
136 unlet! b:csscompl 134 unlet! b:csscompl
153 unlet! b:compl_context 151 unlet! b:compl_context
154 " Entities completion {{{ 152 " Entities completion {{{
155 if exists("b:entitiescompl") 153 if exists("b:entitiescompl")
156 unlet! b:entitiescompl 154 unlet! b:entitiescompl
157 155
156 if !exists("b:html_doctype")
157 call htmlcomplete#CheckDoctype()
158 endif
158 if !exists("b:html_omni") 159 if !exists("b:html_omni")
159 "runtime! autoload/xml/xhtml10s.vim 160 "runtime! autoload/xml/xhtml10s.vim
160 call htmlcomplete#LoadData() 161 call htmlcomplete#LoadData()
161 endif 162 endif
162 163
498 " Attribute completion {{{ 499 " Attribute completion {{{
499 " Shorten context to not include last word 500 " Shorten context to not include last word
500 let sbase = matchstr(context, '.*\ze\s.*') 501 let sbase = matchstr(context, '.*\ze\s.*')
501 502
502 " Load data {{{ 503 " Load data {{{
503 if !exists("b:html_omni_gen") 504 if !exists("b:html_doctype")
505 call htmlcomplete#CheckDoctype()
506 endif
507 if !exists("b:html_omni")
504 call htmlcomplete#LoadData() 508 call htmlcomplete#LoadData()
505 endif 509 endif
506 " }}} 510 " }}}
507 511
508 if has_key(b:html_omni, tag) 512 if has_key(b:html_omni, tag)
524 for i in range(len(menu)) 528 for i in range(len(menu))
525 let item = menu[i] 529 let item = menu[i]
526 if has_key(b:html_omni['vimxmlattrinfo'], item) 530 if has_key(b:html_omni['vimxmlattrinfo'], item)
527 let m_menu = b:html_omni['vimxmlattrinfo'][item][0] 531 let m_menu = b:html_omni['vimxmlattrinfo'][item][0]
528 let m_info = b:html_omni['vimxmlattrinfo'][item][1] 532 let m_info = b:html_omni['vimxmlattrinfo'][item][1]
529 if m_menu !~ 'Bool'
530 let item .= '="'
531 endif
532 else 533 else
533 let m_menu = '' 534 let m_menu = ''
534 let m_info = '' 535 let m_info = ''
536 endif
537 if len(b:html_omni[tag][1][item]) > 0 && b:html_omni[tag][1][item][0] =~ '^\(BOOL\|'.item.'\)$'
538 let item = item
539 let m_menu = 'Bool'
540 else
535 let item .= '="' 541 let item .= '="'
536 endif 542 endif
537 let final_menu += [{'word':item, 'menu':m_menu, 'info':m_info}] 543 let final_menu += [{'word':item, 'menu':m_menu, 'info':m_info}]
538 endfor 544 endfor
539 else 545 else
540 let final_menu = map(menu, 'v:val."=\""') 546 let final_menu = []
547 for i in range(len(menu))
548 let item = menu[i]
549 if len(b:html_omni[tag][1][item]) > 0 && b:html_omni[tag][1][item][0] =~ '^\(BOOL\|'.item.'\)$'
550 let item = item
551 else
552 let item .= '="'
553 endif
554 let final_menu += [item]
555 endfor
556 return final_menu
557
541 endif 558 endif
542 return final_menu 559 return final_menu
543 560
544 endif 561 endif
545 " }}} 562 " }}}
553 return [opentag.">"] 570 return [opentag.">"]
554 endif 571 endif
555 endif 572 endif
556 " }}} 573 " }}}
557 " Load data {{{ 574 " Load data {{{
575 if !exists("b:html_doctype")
576 call htmlcomplete#CheckDoctype()
577 endif
558 if !exists("b:html_omni") 578 if !exists("b:html_omni")
559 "runtime! autoload/xml/xhtml10s.vim 579 "runtime! autoload/xml/xhtml10s.vim
560 call htmlcomplete#LoadData() 580 call htmlcomplete#LoadData()
561 endif 581 endif
562 " }}} 582 " }}}
583 603
584 if exists("uppercase_tag") && uppercase_tag == 1 604 if exists("uppercase_tag") && uppercase_tag == 1
585 let context = tolower(context) 605 let context = tolower(context)
586 endif 606 endif
587 " Handle XML keywords: DOCTYPE and CDATA. 607 " Handle XML keywords: DOCTYPE and CDATA.
588 if opentag == '' || opentag ==? 'head' 608 if opentag == ''
589 let tags += [ 609 let tags += [
590 \ '!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">', 610 \ '!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">',
591 \ '!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd">', 611 \ '!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd">',
592 \ '!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">', 612 \ '!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">',
593 \ '!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Frameset//EN" "http://www.w3.org/TR/REC-html40/frameset.dtd">', 613 \ '!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Frameset//EN" "http://www.w3.org/TR/REC-html40/frameset.dtd">',
608 elseif m =~ context 628 elseif m =~ context
609 call add(res2, m) 629 call add(res2, m)
610 endif 630 endif
611 endfor 631 endfor
612 let menu = res + res2 632 let menu = res + res2
613 let g:me = menu
614 if has_key(b:html_omni, 'vimxmltaginfo') 633 if has_key(b:html_omni, 'vimxmltaginfo')
615 let final_menu = [] 634 let final_menu = []
616 for i in range(len(menu)) 635 for i in range(len(menu))
617 let item = menu[i] 636 let item = menu[i]
618 if has_key(b:html_omni['vimxmltaginfo'], item) 637 if has_key(b:html_omni['vimxmltaginfo'], item)
654 " file. 673 " file.
655 if exists('g:xmldata_'.b:html_omni_flavor) 674 if exists('g:xmldata_'.b:html_omni_flavor)
656 exe 'let b:html_omni = g:xmldata_'.b:html_omni_flavor 675 exe 'let b:html_omni = g:xmldata_'.b:html_omni_flavor
657 else 676 else
658 exe 'runtime! autoload/xml/'.b:html_omni_flavor.'.vim' 677 exe 'runtime! autoload/xml/'.b:html_omni_flavor.'.vim'
659 endif 678 exe 'let b:html_omni = g:xmldata_'.b:html_omni_flavor
660 " This repetition is necessary because we don't know if 679 endif
661 " b:html_omni_flavor file exists and was sourced 680 endfunction
662 " Proper checking for files would require iterating through 'rtp' 681 " }}}
663 " and could introduce OS dependent mess. 682 function! htmlcomplete#CheckDoctype() " {{{
664 if !exists("g:xmldata_".b:html_omni_flavor) 683 if exists('b:html_omni_flavor')
665 if &filetype == 'html' 684 let old_flavor = b:html_omni_flavor
685 else
686 let old_flavor = ''
687 endif
688 let i = 1
689 while i < 10 && i < line("$")
690 let line = getline(i)
691 if line =~ '<!DOCTYPE.*\<DTD HTML 3\.2'
692 let b:html_omni_flavor = 'html32'
693 let b:html_doctype = 1
694 break
695 elseif line =~ '<!DOCTYPE.*\<DTD HTML 4\.0 Transitional'
696 let b:html_omni_flavor = 'html40t'
697 let b:html_doctype = 1
698 break
699 elseif line =~ '<!DOCTYPE.*\<DTD HTML 4\.0 Frameset'
700 let b:html_omni_flavor = 'html40f'
701 let b:html_doctype = 1
702 break
703 elseif line =~ '<!DOCTYPE.*\<DTD HTML 4\.0'
704 let b:html_omni_flavor = 'html40s'
705 let b:html_doctype = 1
706 break
707 elseif line =~ '<!DOCTYPE.*\<DTD HTML 4\.01 Transitional'
666 let b:html_omni_flavor = 'html401t' 708 let b:html_omni_flavor = 'html401t'
667 else 709 let b:html_doctype = 1
710 break
711 elseif line =~ '<!DOCTYPE.*\<DTD HTML 4\.01 Frameset'
712 let b:html_omni_flavor = 'html401f'
713 let b:html_doctype = 1
714 break
715 elseif line =~ '<!DOCTYPE.*\<DTD HTML 4\.01'
716 let b:html_omni_flavor = 'html401s'
717 let b:html_doctype = 1
718 break
719 elseif line =~ '<!DOCTYPE.*\<DTD XHTML 1\.0 Transitional'
720 let b:html_omni_flavor = 'xhtml10t'
721 let b:html_doctype = 1
722 break
723 elseif line =~ '<!DOCTYPE.*\<DTD XHTML 1\.0 Frameset'
724 let b:html_omni_flavor = 'xhtml10f'
725 let b:html_doctype = 1
726 break
727 elseif line =~ '<!DOCTYPE.*\<DTD XHTML 1\.0 Strict'
668 let b:html_omni_flavor = 'xhtml10s' 728 let b:html_omni_flavor = 'xhtml10s'
669 endif 729 let b:html_doctype = 1
670 endif 730 break
671 if exists('g:xmldata_'.b:html_omni_flavor) 731 elseif line =~ '<!DOCTYPE.*\<DTD XHTML 1\.1'
672 exe 'let b:html_omni = g:xmldata_'.b:html_omni_flavor 732 let b:html_omni_flavor = 'xhtml11'
733 let b:html_doctype = 1
734 break
735 endif
736 let i += 1
737 endwhile
738 if !exists("b:html_doctype")
739 return
673 else 740 else
674 exe 'runtime! autoload/xml/'.b:html_omni_flavor.'.vim' 741 " Tie g:xmldata with b:html_omni this way we need to sourca data file only
675 exe 'let b:html_omni = g:xmldata_'.b:html_omni_flavor 742 " once, not every time per buffer.
743 if old_flavor == b:html_omni_flavor
744 return
745 else
746 if exists('g:xmldata_'.b:html_omni_flavor)
747 exe 'let b:html_omni = g:xmldata_'.b:html_omni_flavor
748 else
749 exe 'runtime! autoload/xml/'.b:html_omni_flavor.'.vim'
750 exe 'let b:html_omni = g:xmldata_'.b:html_omni_flavor
751 endif
752 return
753 endif
676 endif 754 endif
677 endfunction 755 endfunction
678 " }}} 756 " }}}
679 " vim:set foldmethod=marker: 757 " vim:set foldmethod=marker: