,<>>,{,},!^F
let b:indent = {"lnum": -1}
let b:undo_indent = "set inde< indk<| unlet b:indent"
" Load Once:
if exists("*HtmlIndent")
call HtmlIndent_CheckUserSettings()
finish
endif
" Patch 7.3.694
if exists('*shiftwidth')
let s:ShiftWidth = function('shiftwidth')
else
func! s:ShiftWidth()
return &shiftwidth
endfunc
endif
let s:cpo_save = &cpo
set cpo-=C
"}}}
func! HtmlIndent_CheckUserSettings() "{{{
if exists("g:html_indent_inctags")
call s:AddITags(split(g:html_indent_inctags, ","))
endif
if exists("g:html_indent_autotags")
call s:RemoveITags(split(g:html_indent_autotags, ","))
endif
let indone = {"zero": 0
\,"auto": "indent(prevnonblank(v:lnum-1))"
\,"inc": "b:indent.blocktagind + s:ShiftWidth()"}
if exists("g:html_indent_script1")
let s:js1indent = get(indone, g:html_indent_script1, indone.zero)
endif
if exists("g:html_indent_style1")
let s:css1indent = get(indone, g:html_indent_style1, indone.zero)
endif
endfunc "}}}
" Init Script Vars "{{{
let s:usestate = 1
let s:css1indent = 0
let s:js1indent = 0
" not to be changed:
let s:endtags = [0,0,0,0,0,0,0,0] " some places unused
let s:newstate = {}
let s:countonly = 0
"}}}
func! s:AddITags(taglist) "{{{
for itag in a:taglist
let s:indent_tags[itag] = 1
let s:indent_tags['/'.itag] = -1
endfor
endfunc "}}}
func! s:AddBlockTag(tag, id, ...) "{{{
if !(a:id >= 2 && a:id < 2+len(s:endtags))
return
endif
let s:indent_tags[a:tag] = a:id
if a:0 == 0
let s:indent_tags['/'.a:tag] = -a:id
let s:endtags[a:id-2] = "".a:tag.">"
else
let s:indent_tags[a:1] = -a:id
let s:endtags[a:id-2] = a:1
endif
endfunc "}}}
func! s:RemoveITags(taglist) "{{{
" remove itags (protect blocktags from being removed)
for itag in a:taglist
if !has_key(s:indent_tags, itag) || s:indent_tags[itag] != 1
continue
endif
unlet s:indent_tags[itag]
if itag =~ '^\w\+$'
unlet s:indent_tags["/".itag]
endif
endfor
endfunc "}}}
" Add Indent Tags: {{{
if !exists("s:indent_tags")
let s:indent_tags = {}
endif
" old tags:
call s:AddITags(['a', 'abbr', 'acronym', 'address', 'b', 'bdo', 'big',
\ 'blockquote', 'button', 'caption', 'center', 'cite', 'code', 'colgroup',
\ 'del', 'dfn', 'dir', 'div', 'dl', 'em', 'fieldset', 'font', 'form',
\ 'frameset', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'i', 'iframe', 'ins', 'kbd',
\ 'label', 'legend', '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', 'tfoot', 'thead'])
" tags added 2011 Sep 09 (especially HTML5 tags):
call s:AddITags(['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: contain alien content "{{{
call s:AddBlockTag('pre', 2)
call s:AddBlockTag('script', 3)
call s:AddBlockTag('style', 4)
call s:AddBlockTag('')
"}}}
func! s:CountITags(...) "{{{
" relative indent steps for current line [unit &sw]:
let s:curind = 0
" relative indent steps for next line [unit &sw]:
let s:nextrel = 0
if a:0==0
let s:block = s:newstate.block
let tmpline = substitute(s:curline, '<\zs\/\=\w\+\>\|', '\=s:CheckTag(submatch(0))', 'g')
if s:block == 3
let s:newstate.scripttype = s:GetScriptType(matchstr(tmpline, '\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 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) * 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")
let s:altline = tolower(getline(bline)[: bcol-2])
call s:CountITags(1)
let state.baseindent = indent(bline) + (s:nextrel+s:curline) * s: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) * s: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 * s:ShiftWidth()
" line starts with end tag
let swendtag = match(s:altline, '^\s*') >= 0
if !swendtag
let state.baseindent += s:curind * s:ShiftWidth()
endif
return state
endfunc "}}}
func! s:Alien2() "{{{
" block
return -1
endfunc "}}}
func! s:Alien3() "{{{
"