) are not here (when encountering
we can find " the matching, but not the other way around). " Old HTML tags: call s:AddITags(s:indent_tags, [ \ 'a', 'abbr', 'acronym', 'address', 'b', 'bdo', 'big', \ 'blockquote', 'body', 'button', 'caption', 'center', 'cite', 'code', \ 'colgroup', 'del', 'dfn', 'dir', 'div', 'dl', 'em', 'fieldset', 'font', \ 'form', 'frameset', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'head', 'html', \ 'i', 'iframe', 'ins', 'kbd', 'label', 'legend', 'li', \ 'map', 'menu', 'noframes', 'noscript', 'object', 'ol', \ 'optgroup', 'q', 's', 'samp', 'select', 'small', 'span', 'strong', 'sub', \ 'sup', 'table', 'textarea', 'title', 'tt', 'u', 'ul', 'var', 'th', 'td', \ 'tr', 'tbody', 'tfoot', 'thead']) " Tags added 2011 Sep 09 (especially HTML5 tags): call s:AddITags(s:indent_tags, [ \ 'area', 'article', 'aside', 'audio', 'bdi', 'canvas', \ 'command', 'datalist', 'details', 'embed', 'figure', 'footer', \ 'header', 'group', 'keygen', 'mark', 'math', 'meter', 'nav', 'output', \ 'progress', 'ruby', 'section', 'svg', 'texture', 'time', 'video', \ 'wbr', 'text']) "}}} " Add Block Tags: these contain alien content "{{{ call s:AddBlockTag('pre', 2) call s:AddBlockTag('script', 3) call s:AddBlockTag('style', 4) call s:AddBlockTag('') "}}} " Return non-zero when "tagname" is an opening tag, not being a block tag, for " which there should be a closing tag. Can be used by scripts that include " HTML indenting. func! HtmlIndent_IsOpenTag(tagname) "{{{ if get(s:indent_tags, a:tagname) == 1 return 1 endif return get(b:hi_tags, a:tagname) == 1 endfunc "}}} " Get the value for "tagname", taking care of buffer-local tags. func! s:get_tag(tagname) "{{{ let i = get(s:indent_tags, a:tagname) if (i == 1 || i == -1) && get(b:hi_removed_tags, a:tagname) != 0 return 0 endif if i == 0 let i = get(b:hi_tags, a:tagname) endif return i endfunc "}}} " Count the number of start and end tags in "text". func! s:CountITags(text) "{{{ " Store the result in s:curind and s:nextrel. let s:curind = 0 " relative indent steps for current line [unit &sw]: let s:nextrel = 0 " relative indent steps for next line [unit &sw]: let s:block = 0 " assume starting outside of a block let s:countonly = 1 " don't change state call substitute(a:text, '<\zs/\=\w\+\>\|', '\=s:CheckTag(submatch(0))', 'g') let s:countonly = 0 endfunc "}}} " Count the number of start and end tags in text. func! s:CountTagsAndState(text) "{{{ " Store the result in s:curind and s:nextrel. Update b:hi_newstate.block. let s:curind = 0 " relative indent steps for current line [unit &sw]: let s:nextrel = 0 " relative indent steps for next line [unit &sw]: let s:block = b:hi_newstate.block let tmp = substitute(a:text, '<\zs/\=\w\+\>\|', '\=s:CheckTag(submatch(0))', 'g') if s:block == 3 let b:hi_newstate.scripttype = s:GetScriptType(matchstr(tmp, '\C.*) " if comment opener found, " assume a:lnum within comment " else " assume usual html for a:lnum " if a:lnum-1 has a closing comment " look back to get indent of comment opener " FI " look back for a blocktag call cursor(a:lnum, 1) let [stopline, stopcol] = searchpos('\c<\zs\/\=\%(pre\>\|script\>\|style\>\)', "bW") if stopline > 0 " fugly ... why isn't there searchstr() let tagline = tolower(getline(stopline)) let blocktag = matchstr(tagline, '\/\=\%(pre\>\|script\>\|style\>\)', stopcol - 1) if blocktag[0] != "/" " opening tag found, assume a:lnum within block let state.block = s:indent_tags[blocktag] if state.block == 3 let state.scripttype = s:GetScriptType(matchstr(tagline, '\>[^>]*', stopcol)) endif let state.blocklnr = stopline " check preceding tags in the line: call s:CountITags(tagline[: stopcol-2]) let state.blocktagind = indent(stopline) + (s:curind + s:nextrel) * s:ShiftWidth() return state elseif stopline == state.lnum " handle special case: previous line (= state.lnum) contains a " closing blocktag which is preceded by line-noise; " blocktag == "/..." let swendtag = match(tagline, '^\s*') >= 0 if !swendtag let [bline, bcol] = searchpos('<'.blocktag[1:].'\>', "bW") call s:CountITags(tolower(getline(bline)[: bcol-2])) let state.baseindent = indent(bline) + (s:curind + s:nextrel) * s:ShiftWidth() return state endif endif endif " else look back for comment call cursor(a:lnum, 1) let [comlnum, comcol, found] = searchpos('\(', 'bpW', stopline) if found == 2 " comment opener found, assume a:lnum within comment let state.block = 5 let state.blocklnr = comlnum " check preceding tags in the line: call s:CountITags(tolower(getline(comlnum)[: comcol-2])) let state.blocktagind = indent(comlnum) + (s:curind + s:nextrel) * s:ShiftWidth() return state endif " else within usual HTML let text = tolower(getline(state.lnum)) " Check a:lnum-1 for closing comment (we need indent from the opening line). " Not when other tags follow (might be --> inside a string). let comcol = stridx(text, '-->') if comcol >= 0 && match(text, '[<>]', comcol) <= 0 call cursor(state.lnum, comcol + 1) let [comlnum, comcol] = searchpos('" return state endif " Check if the previous line starts with end tag. let swendtag = match(text, '^\s*') >= 0 " If previous line ended in a closing tag, line up with the opening tag. if !swendtag && text =~ '\w\+\s*>\s*$' call cursor(state.lnum, 99999) normal! F< let start_lnum = HtmlIndent_FindStartTag() if start_lnum > 0 let state.baseindent = indent(start_lnum) if col('.') > 2 " check for tags before the matching opening tag. let text = getline(start_lnum) let swendtag = match(text, '^\s*') >= 0 call s:CountITags(text[: col('.') - 2]) let state.baseindent += s:nextrel * s:ShiftWidth() if !swendtag let state.baseindent += s:curind * s:ShiftWidth() endif endif return state endif endif " Else: no comments. Skip backwards to find the tag we're inside. let [state.lnum, found] = HtmlIndent_FindTagStart(state.lnum) " Check if that line starts with end tag. let text = getline(state.lnum) let swendtag = match(text, '^\s*') >= 0 call s:CountITags(tolower(text)) let state.baseindent = indent(state.lnum) + s:nextrel * s:ShiftWidth() if !swendtag let state.baseindent += s:curind * s:ShiftWidth() endif return state endfunc "}}} " Indent inside a
block: Keep indent as-is. func! s:Alien2() "{{{ return -1 endfunc "}}} " Return the indent inside a