Skip to content

Commit e0f65b7

Browse files
authored
Merge pull request #25 from i18n-fork/master
add support for stylus
2 parents fcc8129 + aed1ec5 commit e0f65b7

File tree

3 files changed

+36
-2
lines changed

3 files changed

+36
-2
lines changed

README.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
</a>
1111
</p>
1212

13-
Vim syntax and indent plugin for `.svelte` files. Forked from [vim-vue-plugin][3].
13+
Vim syntax and indent plugin for `.svelte` files. Forked from [vim-vue-plugin][3].
1414

1515
## Installation
1616

@@ -71,11 +71,12 @@ Set global variable to `1` to enable or `0` to disable. Ex:
7171
| g:vim_svelte_plugin_use_typescript | Enable typescript syntax for `<script lang="ts">`. | 0 |
7272
| g:vim_svelte_plugin_use_less | Enable less syntax for `<style lang="less">`. | 0 |
7373
| g:vim_svelte_plugin_use_sass | Enable scss syntax for `<style lang="scss">`(or sass for `lang="sass"`). | 0 |
74+
| g:vim_svelte_plugin_use_stylus | Enable stylus syntax for `<style lang="stylus">`. | 0 |
7475
| g:vim_svelte_plugin_has_init_indent | Initially indent one tab inside `style/script` tags. | 1 |
7576
| g:vim_svelte_plugin_use_foldexpr | Enable builtin `foldexpr` foldmethod. | 0 |
7677
| g:vim_svelte_plugin_debug | Echo debug messages in `messages` list. Useful to debug if unexpected indents occur. | 0 |
7778

78-
\*: Vim may be slow if the feature is enabled. Find a balance between syntax highlight and speed. By the way, custom syntax can be added in `~/.vim/syntax` or `$VIM/vimfiles/syntax`.
79+
\*: Vim may be slow if the feature is enabled. Find a balance between syntax highlight and speed. By the way, custom syntax can be added in `~/.vim/syntax` or `$VIM/vimfiles/syntax`.
7980

8081
**Note**
8182

indent/svelte.vim

+13
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ let s:oneline_block = '^\s*{#.*{/.*}\s*$'
3939
let s:use_pug = svelte#GetConfig('use_pug', 0)
4040
let s:use_sass = svelte#GetConfig('use_sass', 0)
4141
let s:use_coffee = svelte#GetConfig('use_coffee', 0)
42+
let s:use_stylus = svelte#GetConfig('use_stylus', 0)
4243
let s:use_typescript = svelte#GetConfig('use_typescript', 0)
4344
let s:has_init_indent = svelte#GetConfig('has_init_indent', 1)
4445
let s:debug = svelte#GetConfig('debug', 0)
@@ -71,6 +72,11 @@ if s:use_pug
7172
let &formatoptions = s:save_formatoptions
7273
endif
7374

75+
if s:use_stylus
76+
unlet! b:did_indent
77+
runtime! indent/stylus.vim
78+
endif
79+
7480
if s:use_sass
7581
unlet! b:did_indent
7682
runtime! indent/sass.vim
@@ -168,6 +174,9 @@ function! GetSvelteIndent()
168174
elseif s:SynSASS(cursyn)
169175
call s:Log('syntax: sass')
170176
let ind = GetSassIndent()
177+
elseif s:SynStylus(cursyn)
178+
call s:Log('syntax: stylus')
179+
let ind = GetStylusIndent()
171180
elseif s:SynStyle(cursyn)
172181
call s:Log('syntax: style')
173182
let ind = GetCSSIndent()
@@ -296,6 +305,10 @@ function! s:SynTypeScript(syn)
296305
return a:syn ==? 'typescriptSvelteScript'
297306
endfunction
298307

308+
function! s:SynStylus(syn)
309+
return a:syn ==? 'cssStylusSvelteStyle'
310+
endfunction
311+
299312
function! s:SynSASS(syn)
300313
return a:syn ==? 'cssSassSvelteStyle'
301314
endfunction

syntax/svelte.vim

+20
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ let s:load_full_syntax = svelte#GetConfig('load_full_syntax', 0)
2222
let s:use_pug = svelte#GetConfig('use_pug', 0)
2323
let s:use_less = svelte#GetConfig('use_less', 0)
2424
let s:use_sass = svelte#GetConfig('use_sass', 0)
25+
let s:use_stylus = svelte#GetConfig('use_stylus', 0)
2526
let s:use_coffee = svelte#GetConfig('use_coffee', 0)
2627
let s:use_typescript = svelte#GetConfig('use_typescript', 0)
2728
"}}}
@@ -104,6 +105,12 @@ if s:use_less
104105
runtime! after/syntax/less.vim
105106
endif
106107

108+
" If sass is enabled, load sass syntax
109+
if s:use_stylus
110+
call s:LoadSyntax('@StylusSyntax', 'stylus')
111+
runtime! after/syntax/stylus.vim
112+
endif
113+
107114
" If sass is enabled, load sass syntax
108115
if s:use_sass
109116
call s:LoadSyntax('@SassSyntax', 'sass')
@@ -204,6 +211,10 @@ syntax region cssScssSvelteStyle fold
204211
\ start=+<style[^>]*lang="scss"[^>]*>+
205212
\ end=+</style>+
206213
\ keepend contains=@SassSyntax,svelteTag
214+
syntax region cssStylusSvelteStyle fold
215+
\ start=+<style[^>]*lang="stylus"[^>]*>+
216+
\ end=+</style>+
217+
\ keepend contains=@StylusSyntax,svelteTag
207218

208219
syntax region svelteTag
209220
\ start=+^<[^/]+ end=+>+ skip=+></+
@@ -243,6 +254,7 @@ if s:use_less
243254
\ contained containedin=cssLessSvelteStyle
244255
\ start="{" end="}"
245256
endif
257+
246258
if s:use_sass
247259
silent! syntax clear sassDefinition
248260
syntax region cssSassDefinition matchgroup=cssBraces
@@ -251,6 +263,14 @@ if s:use_sass
251263
\ start="{" end="}"
252264
endif
253265

266+
if s:use_stylus
267+
silent! syntax clear stylusDefinition
268+
syntax region cssStylusDefinition matchgroup=cssBraces
269+
\ contains=@StylusSyntax,cssStylusDefinition
270+
\ contained containedin=cssStylusSvelteStyle
271+
\ start="{" end="}"
272+
endif
273+
254274
" Avoid css syntax interference
255275
silent! syntax clear cssUnitDecorators
256276
" Have to use a different name

0 commit comments

Comments
 (0)