Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add support for stylus #25

Merged
merged 3 commits into from
Feb 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
</a>
</p>

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

## Installation

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

\*: 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`.
\*: 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`.

**Note**

Expand Down
13 changes: 13 additions & 0 deletions indent/svelte.vim
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ let s:oneline_block = '^\s*{#.*{/.*}\s*$'
let s:use_pug = svelte#GetConfig('use_pug', 0)
let s:use_sass = svelte#GetConfig('use_sass', 0)
let s:use_coffee = svelte#GetConfig('use_coffee', 0)
let s:use_stylus = svelte#GetConfig('use_stylus', 0)
let s:use_typescript = svelte#GetConfig('use_typescript', 0)
let s:has_init_indent = svelte#GetConfig('has_init_indent', 1)
let s:debug = svelte#GetConfig('debug', 0)
Expand Down Expand Up @@ -71,6 +72,11 @@ if s:use_pug
let &formatoptions = s:save_formatoptions
endif

if s:use_stylus
unlet! b:did_indent
runtime! indent/stylus.vim
endif

if s:use_sass
unlet! b:did_indent
runtime! indent/sass.vim
Expand Down Expand Up @@ -168,6 +174,9 @@ function! GetSvelteIndent()
elseif s:SynSASS(cursyn)
call s:Log('syntax: sass')
let ind = GetSassIndent()
elseif s:SynStylus(cursyn)
call s:Log('syntax: stylus')
let ind = GetStylusIndent()
elseif s:SynStyle(cursyn)
call s:Log('syntax: style')
let ind = GetCSSIndent()
Expand Down Expand Up @@ -296,6 +305,10 @@ function! s:SynTypeScript(syn)
return a:syn ==? 'typescriptSvelteScript'
endfunction

function! s:SynStylus(syn)
return a:syn ==? 'cssStylusSvelteStyle'
endfunction

function! s:SynSASS(syn)
return a:syn ==? 'cssSassSvelteStyle'
endfunction
Expand Down
20 changes: 20 additions & 0 deletions syntax/svelte.vim
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ let s:load_full_syntax = svelte#GetConfig('load_full_syntax', 0)
let s:use_pug = svelte#GetConfig('use_pug', 0)
let s:use_less = svelte#GetConfig('use_less', 0)
let s:use_sass = svelte#GetConfig('use_sass', 0)
let s:use_stylus = svelte#GetConfig('use_stylus', 0)
let s:use_coffee = svelte#GetConfig('use_coffee', 0)
let s:use_typescript = svelte#GetConfig('use_typescript', 0)
"}}}
Expand Down Expand Up @@ -104,6 +105,12 @@ if s:use_less
runtime! after/syntax/less.vim
endif

" If sass is enabled, load sass syntax
if s:use_stylus
call s:LoadSyntax('@StylusSyntax', 'stylus')
runtime! after/syntax/stylus.vim
endif

" If sass is enabled, load sass syntax
if s:use_sass
call s:LoadSyntax('@SassSyntax', 'sass')
Expand Down Expand Up @@ -204,6 +211,10 @@ syntax region cssScssSvelteStyle fold
\ start=+<style[^>]*lang="scss"[^>]*>+
\ end=+</style>+
\ keepend contains=@SassSyntax,svelteTag
syntax region cssStylusSvelteStyle fold
\ start=+<style[^>]*lang="stylus"[^>]*>+
\ end=+</style>+
\ keepend contains=@StylusSyntax,svelteTag

syntax region svelteTag
\ start=+^<[^/]+ end=+>+ skip=+></+
Expand Down Expand Up @@ -243,6 +254,7 @@ if s:use_less
\ contained containedin=cssLessSvelteStyle
\ start="{" end="}"
endif

if s:use_sass
silent! syntax clear sassDefinition
syntax region cssSassDefinition matchgroup=cssBraces
Expand All @@ -251,6 +263,14 @@ if s:use_sass
\ start="{" end="}"
endif

if s:use_stylus
silent! syntax clear stylusDefinition
syntax region cssStylusDefinition matchgroup=cssBraces
\ contains=@StylusSyntax,cssStylusDefinition
\ contained containedin=cssStylusSvelteStyle
\ start="{" end="}"
endif

" Avoid css syntax interference
silent! syntax clear cssUnitDecorators
" Have to use a different name
Expand Down