Support custom blocks syntax and indent

This commit is contained in:
leafOfTree
2021-03-11 14:52:38 +08:00
parent db71d38675
commit 9af7723bd1
6 changed files with 299 additions and 123 deletions

View File

@@ -0,0 +1,45 @@
if exists("b:did_indent")
finish
endif
let s:custom_blocks = vue#GetConfig("custom_blocks", {})
let s:indent = {}
function! s:GetSyntaxList()
let syntax_list = []
for syntax in values(s:custom_blocks)
let type = type(syntax)
if type == v:t_string
if !count(syntax_list, syntax)
call add(syntax_list, syntax)
endif
elseif type == v:t_list && len(syntax)
for syn in syntax
if !count(syntax_list, syn)
call add(syntax_list, syn)
endif
endfor
else
echoerr '[vim-vue-plugin] custom_blocks value type'
\.' must be either string or list'
endif
endfor
return syntax_list
endfunction
function! s:GetIndentExpr(syntax_list)
for syntax in a:syntax_list
unlet! b:did_indent
execute 'runtime indent/'.syntax.'.vim'
let s:indent[syntax] = &l:indentexpr
endfor
endfunction
function! GetVueCustomBlocksIndent(syn)
let syntax = matchstr(a:syn, '^\l\+')
call vue#Log('custom block syntax: '.syntax)
let ind = eval(s:indent[syntax])
return ind
endfunction
call s:GetIndentExpr(s:GetSyntaxList())