mirror of
https://github.com/leafOfTree/vim-vue-plugin.git
synced 2025-12-08 13:44:46 +08:00
Support custom blocks syntax and indent
This commit is contained in:
@@ -1,6 +1,15 @@
|
||||
" Since vue#Log and vue#GetConfig are always called
|
||||
" in syntax and indent files,
|
||||
" this file will be sourced when opening the first vue file
|
||||
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
|
||||
function! s:GetConfig(name, default)
|
||||
let name = 'g:vim_vue_plugin_'.a:name
|
||||
return exists(name) ? eval(name) : a:default
|
||||
endfunction
|
||||
|
||||
let s:name = 'vim-vue-plugin'
|
||||
let s:debug = exists("g:vim_vue_plugin_debug")
|
||||
\ && g:vim_vue_plugin_debug == 1
|
||||
let s:load_full_syntax = s:GetConfig("load_full_syntax", 0)
|
||||
let s:debug = s:GetConfig("debug", 0)
|
||||
|
||||
function! vue#Log(msg)
|
||||
if s:debug
|
||||
@@ -9,13 +18,9 @@ function! vue#Log(msg)
|
||||
endfunction
|
||||
|
||||
function! vue#GetConfig(name, default)
|
||||
let name = 'g:vim_vue_plugin_'.a:name
|
||||
return exists(name) ? eval(name) : a:default
|
||||
return s:GetConfig(a:name, a:default)
|
||||
endfunction
|
||||
|
||||
" Since vue#Log and vue#GetConfig are always called
|
||||
" in syntax and indent files,
|
||||
" this file will be sourced when opening the first vue file
|
||||
if exists('##CursorMoved') && exists('*OnChangeVueSubtype')
|
||||
augroup vim_vue_plugin
|
||||
autocmd!
|
||||
@@ -70,3 +75,42 @@ function! GetVueTag(...)
|
||||
|
||||
return tag
|
||||
endfunction
|
||||
|
||||
function! vue#LoadSyntax(group, type)
|
||||
if s:load_full_syntax
|
||||
call vue#LoadFullSyntax(a:group, a:type)
|
||||
else
|
||||
call vue#LoadDefaultSyntax(a:group, a:type)
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! vue#LoadDefaultSyntax(group, type)
|
||||
unlet! b:current_syntax
|
||||
let syntaxPaths = ['$VIMRUNTIME', '$VIM/vimfiles', '$HOME/.vim']
|
||||
for path in syntaxPaths
|
||||
let file = expand(path).'/syntax/'.a:type.'.vim'
|
||||
if filereadable(file)
|
||||
execute 'syntax include '.a:group.' '.file
|
||||
endif
|
||||
endfor
|
||||
endfunction
|
||||
|
||||
" Load all syntax files in 'runtimepath'
|
||||
" Useful if there is no default syntax file provided by vim
|
||||
function! vue#LoadFullSyntax(group, type)
|
||||
call s:SetCurrentSyntax(a:type)
|
||||
execute 'syntax include '.a:group.' syntax/'.a:type.'.vim'
|
||||
endfunction
|
||||
|
||||
" Settings to avoid syntax overload
|
||||
function! s:SetCurrentSyntax(type)
|
||||
if a:type == 'coffee'
|
||||
syntax cluster coffeeJS contains=@htmlJavaScript
|
||||
|
||||
" Avoid overload of `javascript.vim`
|
||||
let b:current_syntax = 'vue'
|
||||
else
|
||||
unlet! b:current_syntax
|
||||
endif
|
||||
endfunction
|
||||
"}}}
|
||||
|
||||
Reference in New Issue
Block a user