fix: add indent in template

This commit is contained in:
yemai
2018-09-28 17:46:07 +08:00
parent 71980e9b57
commit b82b7df062

View File

@@ -12,6 +12,8 @@ endif
se sw=2 ts=2
let s:name = 'vim-vue-plugin'
let s:__DEBUG__ = 1
" Save the current JavaScript indentexpr.
let b:vue_js_indentexpr = &indentexpr
@@ -30,6 +32,7 @@ setlocal indentkeys=0{,0},0),0],0\,,!^F,o,O,e
setlocal indentkeys+=*<Return>,<>>,<<>,/
let s:vue_tag = '\v\<\/?(template|script|style)'
let s:vue_tag_no_indent = '\v\<\/?(script|style)'
let s:end_tag = '^\s*\/\?>\s*;\='
setlocal indentexpr=GetVueIndent()
@@ -62,6 +65,7 @@ function! GetVueIndent()
let prevsyns = SynsEOL(v:lnum - 1)
if SynsHTMLish(prevsyns)
call LogMsg('type: xml')
let ind = XmlIndentGet(v:lnum, 0)
" Align '/>' and '>' with '<' for multiline tags.
@@ -69,8 +73,10 @@ function! GetVueIndent()
let ind = ind - &sw
endif
elseif SynsCSSish(prevsyns)
call LogMsg('type: css')
let ind = GetCSSIndent()
else
call LogMsg('type: javascript')
if len(b:vue_js_indentexpr)
let ind = eval(b:vue_js_indentexpr)
else
@@ -79,16 +85,27 @@ function! GetVueIndent()
endif
if curline =~? s:vue_tag
call LogMsg('cur vue tag')
let ind = 0
elseif (exists("g:vim_vue_plugin_has_init_indent")
\ && g:vim_vue_plugin_has_init_indent != 0)
if SynsVueScope(cursyns) && ind == 0
call LogMsg('add init')
let ind = &sw
endif
else
if prevline =~? s:vue_tag
if prevline =~? s:vue_tag_no_indent
call LogMsg('prev vue tag')
let ind = 0
endif
endif
call LogMsg('result ind: '.ind)
return ind
endfunction
function! LogMsg(msg)
if s:__DEBUG__
echom '['.s:name.'] '. a:msg
endif
endfunction