" Vim completion script " Language: XHTML 1.0 Strict " Maintainer: Mikolaj Machowski ( mikmach AT wp DOT pl ) " Last Change: 2006 Jan 30 function! htmlcomplete#CompleteTags(findstart, base) if a:findstart " locate the start of the word let line = getline('.') let start = col('.') - 1 let curline = line('.') let compl_begin = col('.') - 2 while start >= 0 && line[start - 1] =~ '\(\k\|[:.-]\)' let start -= 1 endwhile if start >= 0 && line[start - 1] =~ '&' let b:entitiescompl = 1 let b:compl_context = '' return start endif let stylestart = searchpair('', '', '<\/style\>', "bnW") let styleend = searchpair('', '', '<\/style\>', "nW") if stylestart != 0 && styleend != 0 if stylestart <= curline && styleend >= curline let start = col('.') - 1 let b:csscompl = 1 while start >= 0 && line[start - 1] =~ '\(\k\|-\)' let start -= 1 endwhile endif endif let scriptstart = searchpair('', '', '<\/script\>', "bnW") let scriptend = searchpair('', '', '<\/script\>', "nW") if scriptstart != 0 && scriptend != 0 if scriptstart <= curline && scriptend >= curline let start = col('.') - 1 let b:jscompl = 1 let b:jsrange = [scriptstart, scriptend] while start >= 0 && line[start - 1] =~ '\(\k\|-\)' let start -= 1 endwhile endif endif if !exists("b:csscompl") && !exists("b:jscompl") let b:compl_context = getline('.')[0:(compl_begin)] if b:compl_context !~ '<[^>]*$' " Look like we may have broken tag. Check previous lines. Up to " 10? let i = 1 while 1 let context_line = getline(curline-i) if context_line =~ '<[^>]*$' " Yep, this is this line let context_lines = getline(curline-i, curline) let b:compl_context = join(context_lines, ' ') break elseif context_line =~ '>[^<]*$' " Normal tag line, no need for completion at all let b:compl_context = '' break endif let i += 1 endwhile " Make sure we don't have counter unlet! i endif let b:compl_context = matchstr(b:compl_context, '.*\zs<.*') else let b:compl_context = getline('.')[0:compl_begin] endif return start else " Initialize base return lists let res = [] let res2 = [] " a:base is very short - we need context let context = b:compl_context " Check if we should do CSS completion inside of