From 1eeb7b4d421c5ca7409e152b57c51df27df71220 Mon Sep 17 00:00:00 2001 From: leafOfTree Date: Tue, 14 Jul 2020 19:53:19 +0800 Subject: [PATCH] Support third party scss plugins --- indent/vue.vim | 22 +++++++++++++++++++++- syntax/vue.vim | 31 +++++++++++++++++++++++++------ 2 files changed, 46 insertions(+), 7 deletions(-) diff --git a/indent/vue.vim b/indent/vue.vim index 1e0fd0b..1afa801 100644 --- a/indent/vue.vim +++ b/indent/vue.vim @@ -37,6 +37,8 @@ let s:use_pug = exists("g:vim_vue_plugin_use_pug") \ && g:vim_vue_plugin_use_pug == 1 let s:use_sass = exists("g:vim_vue_plugin_use_sass") \ && g:vim_vue_plugin_use_sass == 1 +let s:use_scss = exists("g:vim_vue_plugin_use_scss") + \ && g:vim_vue_plugin_use_scss == 1 let s:use_stylus = exists("g:vim_vue_plugin_use_stylus") \ && g:vim_vue_plugin_use_stylus == 1 let s:use_coffee = exists("g:vim_vue_plugin_use_coffee") @@ -84,6 +86,11 @@ if s:use_sass runtime! indent/sass.vim endif +if s:use_scss + unlet! b:did_indent + runtime! indent/scss.vim +endif + if s:use_stylus unlet! b:did_indent runtime! indent/stylus.vim @@ -163,11 +170,20 @@ function! GetVueIndent() elseif s:SynSASS(cursyn) call vue#Log('syntax: sass') let ind = GetSassIndent() + elseif s:SynSCSS(cursyn) + call vue#Log('syntax: scss') + if exists('*GetSCSSIndent') + call vue#Log('indent: scss') + let ind = GetSCSSIndent() + else + call vue#Log('indent: css') + let ind = GetCSSIndent() + endif elseif s:SynStylus(cursyn) call vue#Log('syntax: stylus') let ind = GetStylusIndent() elseif s:SynStyle(cursyn) - call vue#Log('syntax: style') + call vue#Log('syntax: css') let ind = GetCSSIndent() else call vue#Log('syntax: javascript') @@ -228,6 +244,10 @@ function! s:SynSASS(syn) return a:syn ==? 'sassVueStyle' endfunction +function! s:SynSCSS(syn) + return a:syn ==? 'cssScssVueStyle' +endfunction + function! s:SynStylus(syn) return a:syn ==? 'cssStylusVueStyle' endfunction diff --git a/syntax/vue.vim b/syntax/vue.vim index 4177ad5..8445ac0 100644 --- a/syntax/vue.vim +++ b/syntax/vue.vim @@ -26,6 +26,8 @@ let s:use_less = exists("g:vim_vue_plugin_use_less") \ && g:vim_vue_plugin_use_less == 1 let s:use_sass = exists("g:vim_vue_plugin_use_sass") \ && g:vim_vue_plugin_use_sass == 1 +let s:use_scss = exists("g:vim_vue_plugin_use_scss") + \ && g:vim_vue_plugin_use_scss == 1 let s:use_stylus = exists("g:vim_vue_plugin_use_stylus") \ && g:vim_vue_plugin_use_stylus == 1 let s:use_coffee = exists("g:vim_vue_plugin_use_coffee") @@ -125,6 +127,12 @@ if s:use_sass runtime! after/syntax/sass.vim endif +" If scss is enabled, load sass syntax +if s:use_scss + call s:LoadSyntax('@ScssSyntax', 'scss') + runtime! after/syntax/scss.vim +endif + " If stylus is enabled, load stylus syntax if s:use_stylus call s:LoadFullSyntax('@StylusSyntax', 'stylus') @@ -197,7 +205,7 @@ syntax region sassVueStyle fold syntax region cssScssVueStyle fold \ start=+]*lang=["']scss["'][^>]*>+ \ end=++ - \ keepend contains=@SassSyntax,vueTag + \ keepend contains=@ScssSyntax,vueTag syntax region cssStylusVueStyle fold \ start=+]*lang=["']stylus["'][^>]*>+ \ end=++ @@ -237,26 +245,37 @@ endif " enable emmet-vim css type. if s:use_less silent! syntax clear lessDefinition - syntax region cssLessDefinition matchgroup=cssBraces contains=@LessSyntax + syntax region cssLessDefinition matchgroup=cssBraces + \ contains=@LessSyntax,cssLessDefinition \ contained containedin=cssLessVueStyle \ start="{" end="}" endif if s:use_sass silent! syntax clear sassDefinition - syntax region cssSassDefinition matchgroup=cssBraces contains=@SassSyntax - \ contained containedin=sassVueStyle,cssScssVueStyle + syntax region sassDefinition matchgroup=cssBraces + \ contains=@SassSyntax,sassDefinition + \ contained containedin=sassVueStyle + \ start="{" end="}" +endif +" Active if not loading https://github.com/cakebaker/scss-syntax.vim +if s:use_scss && hlexists('scssNestedProperty') == 0 + silent! syntax clear scssDefinition + syntax region cssScssDefinition transparent matchgroup=cssBraces + \ contains=@ScssSyntax,cssScssDefinition + \ contained containedin=cssScssVueStyle \ start="{" end="}" endif if s:use_stylus silent! syntax clear stylusDefinition - syntax region cssStylusDefinition matchgroup=cssBraces contains=@StylusSyntax + syntax region cssStylusDefinition matchgroup=cssBraces + \ contains=@StylusSyntax,cssStylusDefinition \ contained containedin=cssStylusVueStyle \ start="{" end="}" endif " Avoid css syntax interference -silent! syntax clear cssUnitDecorators " Have to use a different name +silent! syntax clear cssUnitDecorators syntax match cssUnitDecorators2 \ /\(#\|-\|+\|%\|mm\|cm\|in\|pt\|pc\|em\|ex\|px\|ch\|rem\|vh\|vw\|vmin\|vmax\|dpi\|dppx\|dpcm\|Hz\|kHz\|s\|ms\|deg\|grad\|rad\)\ze\(;\|$\)/ \ contained