mirror of
https://github.com/leafOfTree/vim-vue-plugin.git
synced 2025-12-09 22:25:12 +08:00
Set syntax sync by each block syntax
This commit is contained in:
@@ -265,17 +265,25 @@ function! vue#GetSyntaxList(config_syntax)
|
|||||||
endif
|
endif
|
||||||
endfor
|
endfor
|
||||||
|
|
||||||
" Move basic syntaxes to the end of the list, so we can check
|
call s:ModifySyntaxOrder(syntax_list)
|
||||||
|
|
||||||
|
return syntax_list
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! s:ModifySyntaxOrder(syntax_list)
|
||||||
|
let syntax_list = a:syntax_list
|
||||||
|
|
||||||
|
" Move basic syntax to the end of the list, so we can check
|
||||||
" if they are already loaded by other syntax.
|
" if they are already loaded by other syntax.
|
||||||
" Order matters
|
" Order matters
|
||||||
for syntax in ['html', 'javascript', 'css']
|
let load_last = ['html', 'javascript', 'css']
|
||||||
|
for syntax in load_last
|
||||||
let idx = index(syntax_list, syntax)
|
let idx = index(syntax_list, syntax)
|
||||||
if idx >= 0
|
if idx >= 0
|
||||||
call remove(syntax_list, idx)
|
call remove(syntax_list, idx)
|
||||||
call add(syntax_list, syntax)
|
call add(syntax_list, syntax)
|
||||||
endif
|
endif
|
||||||
endfor
|
endfor
|
||||||
return syntax_list
|
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
call s:Main()
|
call s:Main()
|
||||||
|
|||||||
@@ -2,13 +2,15 @@
|
|||||||
" Maintainer: leaf <https://github.com/leafOfTree>
|
" Maintainer: leaf <https://github.com/leafOfTree>
|
||||||
" Credits: Inspired by mxw/vim-jsx.
|
" Credits: Inspired by mxw/vim-jsx.
|
||||||
|
|
||||||
if exists('b:current_syntax') && b:current_syntax == 'vue'
|
if !exists('main_syntax')
|
||||||
finish
|
if exists('b:current_syntax') && b:current_syntax == 'vue'
|
||||||
|
finish
|
||||||
|
endif
|
||||||
|
let main_syntax = 'vue'
|
||||||
endif
|
endif
|
||||||
|
|
||||||
" <sfile> is replaced with the file name of the sourced file
|
" <sfile> is replaced with the file name of the sourced file
|
||||||
let s:patch_path = expand('<sfile>:p:h').'/patch'
|
let s:patch_path = expand('<sfile>:p:h').'/patch'
|
||||||
|
|
||||||
let s:test = exists('g:vim_vue_plugin_test')
|
let s:test = exists('g:vim_vue_plugin_test')
|
||||||
|
|
||||||
function! s:Init()
|
function! s:Init()
|
||||||
@@ -99,15 +101,19 @@ function! s:GetSyntaxLangName(syntax)
|
|||||||
return syntax
|
return syntax
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:SetSyntax(block, syntax, lang)
|
function! s:SetSyntax(block, syntax, has_lang)
|
||||||
let block = a:block
|
let block = a:block
|
||||||
let syntax = a:syntax
|
let syntax = a:syntax
|
||||||
let lang = a:lang
|
let has_lang = a:has_lang
|
||||||
|
|
||||||
let name = s:GetSynatxName(block, syntax)
|
let name = s:GetSynatxName(block, syntax)
|
||||||
let syntax_lang_name = s:GetSyntaxLangName(syntax)
|
if has_lang
|
||||||
let syntax_lang = lang ? 'lang=["'']'.syntax_lang_name.'["''][^>]*' : ''
|
let lang_name = s:GetSyntaxLangName(syntax)
|
||||||
let start = '^<'.block.'[^>]*'.syntax_lang.'>'
|
let lang = 'lang=["'']'.lang_name.'["''][^>]*'
|
||||||
|
else
|
||||||
|
let lang = ''
|
||||||
|
endif
|
||||||
|
let start = '^<'.block.'[^>]*'.lang.'>'
|
||||||
let end = '^</'.block.'>'
|
let end = '^</'.block.'>'
|
||||||
let syntax_group = s:GetGroupNameForHighlight(syntax)
|
let syntax_group = s:GetGroupNameForHighlight(syntax)
|
||||||
|
|
||||||
@@ -115,9 +121,14 @@ function! s:SetSyntax(block, syntax, lang)
|
|||||||
\.' start=+'.start.'+'
|
\.' start=+'.start.'+'
|
||||||
\.' end=+'.end.'+'
|
\.' end=+'.end.'+'
|
||||||
\.' keepend contains='.syntax_group.', vueTag'
|
\.' keepend contains='.syntax_group.', vueTag'
|
||||||
|
|
||||||
|
execute 'syntax sync match vueSync groupthere '.name.' +'.start.'+'
|
||||||
|
execute 'syntax sync match vueSync groupthere NONE +'.end.'+'
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:SetBlockSyntax(config_syntax)
|
function! s:SetBlockSyntax(config_syntax)
|
||||||
|
syntax sync clear
|
||||||
|
|
||||||
for [block, syntax] in items(a:config_syntax)
|
for [block, syntax] in items(a:config_syntax)
|
||||||
let type = type(syntax)
|
let type = type(syntax)
|
||||||
if type == v:t_string
|
if type == v:t_string
|
||||||
@@ -141,10 +152,6 @@ function! s:HighlightVueTag()
|
|||||||
highlight default link vueTag htmlTag
|
highlight default link vueTag htmlTag
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:SetSyntaxSync()
|
|
||||||
syntax sync fromstart
|
|
||||||
endfunction
|
|
||||||
|
|
||||||
function! s:SetIsKeyword()
|
function! s:SetIsKeyword()
|
||||||
if has("patch-7.4-1142")
|
if has("patch-7.4-1142")
|
||||||
if has("win32")
|
if has("win32")
|
||||||
@@ -162,7 +169,6 @@ function! VimVuePluginSyntaxMain(...)
|
|||||||
let syntax_list = vue#GetSyntaxList(s:config_syntax)
|
let syntax_list = vue#GetSyntaxList(s:config_syntax)
|
||||||
call s:LoadSyntaxList(syntax_list)
|
call s:LoadSyntaxList(syntax_list)
|
||||||
call s:SetBlockSyntax(s:config_syntax)
|
call s:SetBlockSyntax(s:config_syntax)
|
||||||
" call s:SetSyntaxSync()
|
|
||||||
call s:SetIsKeyword()
|
call s:SetIsKeyword()
|
||||||
call s:HighlightVueTag()
|
call s:HighlightVueTag()
|
||||||
endfunction
|
endfunction
|
||||||
@@ -174,3 +180,6 @@ else
|
|||||||
endif
|
endif
|
||||||
|
|
||||||
let b:current_syntax = 'vue'
|
let b:current_syntax = 'vue'
|
||||||
|
if main_syntax == 'vue'
|
||||||
|
unlet main_syntax
|
||||||
|
endif
|
||||||
|
|||||||
Reference in New Issue
Block a user