mirror of
https://github.com/leafOfTree/vim-vue-plugin.git
synced 2025-12-10 06:31:51 +08:00
feat: support css indent
This commit is contained in:
@@ -1,27 +1,28 @@
|
||||
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
|
||||
" Vim ftplugin file
|
||||
" Vim indent file
|
||||
"
|
||||
" Language: Vue (Wepy)
|
||||
" Maintainer: leafOfTree <leafvocation@gmail.com>
|
||||
"
|
||||
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
|
||||
|
||||
if exists("b:did_vue_indent")
|
||||
finish
|
||||
endif
|
||||
|
||||
se sw=2 ts=2
|
||||
|
||||
" Save the current JavaScript indentexpr.
|
||||
let b:vue_js_indentexpr = &indentexpr
|
||||
|
||||
" Prologue; load XML indentation.
|
||||
if exists('b:did_indent')
|
||||
let s:did_indent=b:did_indent
|
||||
unlet b:did_indent
|
||||
endif
|
||||
|
||||
unlet b:did_indent
|
||||
runtime! indent/xml.vim
|
||||
|
||||
if exists('s:did_indent')
|
||||
let b:did_indent=s:did_indent
|
||||
endif
|
||||
unlet b:did_indent
|
||||
runtime! indent/css.vim
|
||||
|
||||
let b:did_indent = 1
|
||||
let b:did_vue_indent = 1
|
||||
|
||||
" JavaScript indentkeys
|
||||
setlocal indentkeys=0{,0},0),0],0\,,!^F,o,O,e
|
||||
@@ -44,6 +45,11 @@ function! SynsHTMLish(syns)
|
||||
return last_syn =~? '\v^(html)'
|
||||
endfunction
|
||||
|
||||
function! SynsCSSish(syns)
|
||||
let last_syn = get(a:syns, -1)
|
||||
return last_syn =~? '\v^(css)|(less)|(sass)'
|
||||
endfunction
|
||||
|
||||
function! SynsVueScope(syns)
|
||||
let first_syn = get(a:syns, 0)
|
||||
return first_syn =~? '\v^(vueStyle)|(vueTemplate)|(vueScript)'
|
||||
@@ -51,6 +57,7 @@ endfunction
|
||||
|
||||
function! GetVueIndent()
|
||||
let curline = getline(v:lnum)
|
||||
let prevline = getline(v:lnum - 1)
|
||||
let cursyns = SynsEOL(v:lnum)
|
||||
let prevsyns = SynsEOL(v:lnum - 1)
|
||||
|
||||
@@ -61,21 +68,27 @@ function! GetVueIndent()
|
||||
if curline =~? s:end_tag
|
||||
let ind = ind - &sw
|
||||
endif
|
||||
elseif SynsCSSish(prevsyns)
|
||||
let ind = GetCSSIndent()
|
||||
else
|
||||
if curline =~ s:vue_tag
|
||||
let ind = 0
|
||||
if len(b:vue_js_indentexpr)
|
||||
let ind = eval(b:vue_js_indentexpr)
|
||||
else
|
||||
if len(b:vue_js_indentexpr)
|
||||
let ind = eval(b:vue_js_indentexpr)
|
||||
else
|
||||
let ind = cindent(v:lnum)
|
||||
endif
|
||||
let ind = cindent(v:lnum)
|
||||
endif
|
||||
endif
|
||||
|
||||
if SynsVueScope(cursyns) && ind == 0
|
||||
let ind = &sw
|
||||
if curline =~? s: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
|
||||
let ind = &sw
|
||||
endif
|
||||
else
|
||||
if prevline =~? s:vue_tag
|
||||
let ind = 0
|
||||
endif
|
||||
endif
|
||||
|
||||
return ind
|
||||
endfunction
|
||||
|
||||
Reference in New Issue
Block a user