" Vim indent script " General: "{{{ " File: html.vim (Vimscript #2075) " Author: Andy Wokula, anwoku#yahoo*de (#* -> @.) " Last Change: 2008 Mar 07 " Version: 0.5 " Vim Version: Vim7 " Description: " improved version of the distributed html indent script " - Based on: " indent/html.vim from J. Zellner (2006 Jun 05) " indent/css.vim from N. Weibull (2006 Dec 20) " - indenting regions: " Blocktag : Indent-Expr "
: -1 (= keep indent) " ) " 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 blocktag call cursor(a:lnum, 1) let [stopline, stopcol] = searchpos('\c<\zs\/\=\%(pre\>\|script\>\|style\>\)', "bW") " fugly ... why isn't there searchstr() let tagline = tolower(getline(stopline)) let blocktag = matchstr(tagline, '\/\=\%(pre\>\|script\>\|style\>\)', stopcol-1) if stopline > 0 && 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: let s:altline = tagline[: stopcol-2] call s:CountITags(1) let state.blocktagind = indent(stopline) + (s:curind + s:nextrel) * &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") let s:altline = tolower(getline(bline)[: bcol-2]) call s:CountITags(1) let state.baseindent = indent(bline) + (s:nextrel+s:curline) * &shiftwidth return state endif endif " else look back for comment call cursor(a:lnum, 1) let [comline, comcol, found] = searchpos('\(', 'bpW', stopline) if found == 2 " comment opener found, assume a:lnum within comment let state.block = 5 let state.blocklnr = comline " check preceding tags in the line: let s:altline = tolower(getline(comline)[: comcol-2]) call s:CountITags(1) let state.blocktagind = indent(comline) + (s:curind + s:nextrel) * &shiftwidth return state endif " else within usual html let s:altline = tolower(getline(state.lnum)) " check a:lnum-1 for closing comment (we need indent from the opening line) let comcol = stridx(s:altline, '-->') if comcol >= 0 call cursor(state.lnum, comcol+1) let [comline, comcol] = searchpos('" endif " else no comments call s:CountITags(1) let state.baseindent = indent(state.lnum) + s:nextrel * &shiftwidth " line starts with end tag let swendtag = match(s:altline, '^\s*') >= 0 if !swendtag let state.baseindent += s:curind * &shiftwidth endif return state endfunc "}}} func! s:Alien2() "{{{ "block return -1 endfunc "}}} func! s:Alien3() "{{{ "