Skip to content

Commit 1d045ca

Browse files
authored
Merge pull request #86 from weirongxu/patch-fix-alone-tag-indent
fix self enclosing tag indent
2 parents 9aa4a1c + c959165 commit 1d045ca

1 file changed

Lines changed: 19 additions & 10 deletions

File tree

indent/html.vim

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -258,20 +258,28 @@ let s:html_indent_tags = '[a-z_][a-z0-9_.-]*'
258258
let s:cpo_save = &cpo
259259
set cpo-=C
260260

261-
" [-- count indent-increasing tags of line a:lnum --]
262-
fun! <SID>HtmlIndentOpen(lnum, pattern)
263-
let s = substitute('x'.getline(a:lnum),
264-
\ '.\{-}\(\(<\)\('.a:pattern.'\)\>\)', "\1", 'g')
261+
func! <SID>HtmlIndentPatternCount(content, pattern)
262+
let s = substitute('x'.a:content, a:pattern, "\1", 'g')
265263
let s = substitute(s, "[^\1].*$", '', '')
266264
return strlen(s)
267265
endfun
268266

267+
" [-- count indent-increasing tags of line a:lnum --]
268+
fun! <SID>HtmlIndentOpen(lnum, pattern)
269+
return <SID>HtmlIndentPatternCount(getline(a:lnum),
270+
\ '.\{-}\(\(<\)\('.a:pattern.'\)\>\)')
271+
endfun
272+
269273
" [-- count indent-decreasing tags of line a:lnum --]
270274
fun! <SID>HtmlIndentClose(lnum, pattern)
271-
let s = substitute('x'.getline(a:lnum),
272-
\ '.\{-}\(\(<\)/\('.a:pattern.'\)\>>\)', "\1", 'g')
273-
let s = substitute(s, "[^\1].*$", '', '')
274-
return strlen(s)
275+
return <SID>HtmlIndentPatternCount(getline(a:lnum),
276+
\ '.\{-}\(\(<\)/\('.a:pattern.'\)\>>\)')
277+
endfun
278+
279+
" [-- count self close tags of line a:lnum --]
280+
fun! <SID>HtmlIndentSelfClose(lnum, pattern)
281+
return <SID>HtmlIndentPatternCount(getline(a:lnum),
282+
\ '.\{-}\(\(<\('.a:pattern.'\).*\)\@<!\/>\)')
275283
endfun
276284

277285
" [-- count indent-increasing '{' of (java|css) line a:lnum --]
@@ -290,8 +298,9 @@ fun! <SID>HtmlIndentSum(lnum, style)
290298
if a:style == match(getline(a:lnum), '^\s*</\<\('.s:html_indent_tags.'\)\>')
291299
let open = <SID>HtmlIndentOpen(a:lnum, s:html_indent_tags) - <SID>HtmlIndentOpen(a:lnum, s:html_noindent_tags)
292300
let close = <SID>HtmlIndentClose(a:lnum, s:html_indent_tags) - <SID>HtmlIndentClose(a:lnum, s:html_noindent_tags)
293-
if 0 != open || 0 != close
294-
return open - close
301+
let self_close = <SID>HtmlIndentSelfClose(a:lnum, s:html_noindent_tags)
302+
if 0 != open || 0 != close || 0 != self_close
303+
return open - close - self_close
295304
endif
296305
endif
297306
endif

0 commit comments

Comments
 (0)