mirror of
https://github.com/leafOfTree/vim-vue-plugin.git
synced 2026-03-01 12:57:01 +08:00
fix: add indent in template
This commit is contained in:
@@ -12,6 +12,8 @@ endif
|
|||||||
|
|
||||||
se sw=2 ts=2
|
se sw=2 ts=2
|
||||||
|
|
||||||
|
let s:name = 'vim-vue-plugin'
|
||||||
|
let s:__DEBUG__ = 1
|
||||||
" Save the current JavaScript indentexpr.
|
" Save the current JavaScript indentexpr.
|
||||||
let b:vue_js_indentexpr = &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>,<>>,<<>,/
|
setlocal indentkeys+=*<Return>,<>>,<<>,/
|
||||||
|
|
||||||
let s:vue_tag = '\v\<\/?(template|script|style)'
|
let s:vue_tag = '\v\<\/?(template|script|style)'
|
||||||
|
let s:vue_tag_no_indent = '\v\<\/?(script|style)'
|
||||||
let s:end_tag = '^\s*\/\?>\s*;\='
|
let s:end_tag = '^\s*\/\?>\s*;\='
|
||||||
|
|
||||||
setlocal indentexpr=GetVueIndent()
|
setlocal indentexpr=GetVueIndent()
|
||||||
@@ -62,6 +65,7 @@ function! GetVueIndent()
|
|||||||
let prevsyns = SynsEOL(v:lnum - 1)
|
let prevsyns = SynsEOL(v:lnum - 1)
|
||||||
|
|
||||||
if SynsHTMLish(prevsyns)
|
if SynsHTMLish(prevsyns)
|
||||||
|
call LogMsg('type: xml')
|
||||||
let ind = XmlIndentGet(v:lnum, 0)
|
let ind = XmlIndentGet(v:lnum, 0)
|
||||||
|
|
||||||
" Align '/>' and '>' with '<' for multiline tags.
|
" Align '/>' and '>' with '<' for multiline tags.
|
||||||
@@ -69,8 +73,10 @@ function! GetVueIndent()
|
|||||||
let ind = ind - &sw
|
let ind = ind - &sw
|
||||||
endif
|
endif
|
||||||
elseif SynsCSSish(prevsyns)
|
elseif SynsCSSish(prevsyns)
|
||||||
|
call LogMsg('type: css')
|
||||||
let ind = GetCSSIndent()
|
let ind = GetCSSIndent()
|
||||||
else
|
else
|
||||||
|
call LogMsg('type: javascript')
|
||||||
if len(b:vue_js_indentexpr)
|
if len(b:vue_js_indentexpr)
|
||||||
let ind = eval(b:vue_js_indentexpr)
|
let ind = eval(b:vue_js_indentexpr)
|
||||||
else
|
else
|
||||||
@@ -79,16 +85,27 @@ function! GetVueIndent()
|
|||||||
endif
|
endif
|
||||||
|
|
||||||
if curline =~? s:vue_tag
|
if curline =~? s:vue_tag
|
||||||
|
call LogMsg('cur vue tag')
|
||||||
let ind = 0
|
let ind = 0
|
||||||
elseif (exists("g:vim_vue_plugin_has_init_indent")
|
elseif (exists("g:vim_vue_plugin_has_init_indent")
|
||||||
\ && g:vim_vue_plugin_has_init_indent != 0)
|
\ && g:vim_vue_plugin_has_init_indent != 0)
|
||||||
if SynsVueScope(cursyns) && ind == 0
|
if SynsVueScope(cursyns) && ind == 0
|
||||||
|
call LogMsg('add init')
|
||||||
let ind = &sw
|
let ind = &sw
|
||||||
endif
|
endif
|
||||||
else
|
else
|
||||||
if prevline =~? s:vue_tag
|
if prevline =~? s:vue_tag_no_indent
|
||||||
|
call LogMsg('prev vue tag')
|
||||||
let ind = 0
|
let ind = 0
|
||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
|
call LogMsg('result ind: '.ind)
|
||||||
|
|
||||||
return ind
|
return ind
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
function! LogMsg(msg)
|
||||||
|
if s:__DEBUG__
|
||||||
|
echom '['.s:name.'] '. a:msg
|
||||||
|
endif
|
||||||
|
endfunction
|
||||||
|
|||||||
Reference in New Issue
Block a user