mirror of
https://github.com/leafOfTree/vim-vue-plugin.git
synced 2025-12-09 06:04:46 +08:00
feat: support sass/scss
This commit is contained in:
@@ -26,13 +26,17 @@ let b:vue_js_indentexpr = &indentexpr
|
||||
unlet! b:did_indent
|
||||
runtime! indent/xml.vim
|
||||
|
||||
" load css indent method
|
||||
unlet! b:did_indent
|
||||
runtime! indent/css.vim
|
||||
|
||||
" load pug indent method
|
||||
unlet! b:did_indent
|
||||
runtime! indent/pug.vim
|
||||
|
||||
" load css indent method
|
||||
" load sass indent method
|
||||
unlet! b:did_indent
|
||||
runtime! indent/css.vim
|
||||
runtime! indent/sass.vim
|
||||
|
||||
let b:did_indent = 1
|
||||
let b:did_vue_indent = 1
|
||||
@@ -65,6 +69,11 @@ function! SynsCSS(syns)
|
||||
return first_syn =~? '\v^(vueStyle)'
|
||||
endfunction
|
||||
|
||||
function! SynsSASS(syns)
|
||||
let first_syn = get(a:syns, 0)
|
||||
return first_syn =~? '\v^(vueStyleSASS)'
|
||||
endfunction
|
||||
|
||||
function! SynsVueScope(syns)
|
||||
let first_syn = get(a:syns, 0)
|
||||
return first_syn =~? '\v^(vueStyle)|(vueScript)'
|
||||
@@ -96,6 +105,9 @@ function! GetVueIndent()
|
||||
elseif SynsCSS(prevsyns)
|
||||
call s:LogMsg('syntax: css')
|
||||
let ind = GetCSSIndent()
|
||||
elseif SynsSASS(prevsyns)
|
||||
call s:LogMsg('syntax: sass')
|
||||
let ind = GetSassIndent()
|
||||
else
|
||||
call s:LogMsg('syntax: javascript')
|
||||
if len(b:vue_js_indentexpr)
|
||||
@@ -109,12 +121,12 @@ function! GetVueIndent()
|
||||
call s:LogMsg('current is vue tag')
|
||||
let ind = 0
|
||||
elseif (exists("g:vim_vue_plugin_has_init_indent")
|
||||
\ && g:vim_vue_plugin_has_init_indent != 0)
|
||||
\ && g:vim_vue_plugin_has_init_indent == 1)
|
||||
if SynsVueScope(cursyns) && ind == 0
|
||||
call s:LogMsg('add initial indent')
|
||||
let ind = &sw
|
||||
endif
|
||||
elseif prevline =~? s:vue_end_tag
|
||||
elseif prevline =~? s:vue_tag || prevline =~? s:vue_end_tag
|
||||
call s:LogMsg('prev is vue tag')
|
||||
let ind = 0
|
||||
endif
|
||||
|
||||
@@ -7,6 +7,10 @@
|
||||
" CREDITS: Inspired by mxw/vim-jsx.
|
||||
"
|
||||
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
|
||||
if exists("b:current_syntax") && b:current_syntax == 'vue'
|
||||
finish
|
||||
endif
|
||||
|
||||
function! s:LoadDefaultSyntax(group, type)
|
||||
unlet! b:current_syntax
|
||||
exec 'syn include '.a:group.' $VIMRUNTIME/syntax/'.a:type.'.vim'
|
||||
@@ -45,19 +49,27 @@ if exists("g:vim_vue_plugin_use_pug")
|
||||
call s:LoadFullSyntax('@PugSyntax', 'pug')
|
||||
endif
|
||||
|
||||
" If less is enabled, load vim-pug syntax
|
||||
" If less is enabled, load less syntax
|
||||
if exists("g:vim_vue_plugin_use_less")
|
||||
\ && g:vim_vue_plugin_use_less == 1
|
||||
call s:LoadFullSyntax('@LessSyntax', 'less')
|
||||
syn clear cssDefinition
|
||||
syn region lessDefinition
|
||||
\ matchgroup=cssBraces
|
||||
\ contains=@LessSyntax
|
||||
syn region lessDefinition matchgroup=cssBraces contains=@LessSyntax
|
||||
\ start="{"
|
||||
\ end="}"
|
||||
|
||||
endif
|
||||
|
||||
" If sass is enabled, load sass syntax
|
||||
if exists("g:vim_vue_plugin_use_sass")
|
||||
\ && g:vim_vue_plugin_use_sass == 1
|
||||
call s:LoadFullSyntax('@SassSyntax', 'sass')
|
||||
syn clear cssDefinition
|
||||
syn region sassDefinition matchgroup=cssBraces contains=@SassSyntax
|
||||
\ start="{"
|
||||
\ end="}"
|
||||
endif
|
||||
|
||||
let b:current_syntax = 'vue'
|
||||
|
||||
" Find tag <template> / <script> / <style> and enable currespond syntax
|
||||
@@ -83,6 +95,14 @@ syn region vueStyleLESS
|
||||
\ start=+<style lang="less"\(\s.\{-}\)\?>+
|
||||
\ end=+</style>+
|
||||
\ keepend contains=@LessSyntax,vueTag
|
||||
syn region vueStyleSASS
|
||||
\ start=+<style lang="sass"\(\s.\{-}\)\?>+
|
||||
\ end=+</style>+
|
||||
\ keepend contains=@SassSyntax,vueTag
|
||||
syn region vueStyleSCSS
|
||||
\ start=+<style lang="scss"\(\s.\{-}\)\?>+
|
||||
\ end=+</style>+
|
||||
\ keepend contains=@SassSyntax,vueTag
|
||||
|
||||
syn region vueTag contained start=+<[^/]+ end=+>+ contains=htmlTagN,htmlString,htmlArg
|
||||
syn region vueTag contained start=+</+ end=+>+ contains=htmlTagN,htmlString,htmlArg
|
||||
|
||||
Reference in New Issue
Block a user