mirror of
https://github.com/leafOfTree/vim-vue-plugin.git
synced 2025-12-10 14:41:52 +08:00
Rename subtype to syntax
This commit is contained in:
22
README.md
22
README.md
@@ -223,9 +223,9 @@ ja:
|
|||||||
|
|
||||||
## Context-based behavior
|
## Context-based behavior
|
||||||
|
|
||||||
As there are more than one language in `.vue` file, different mapping, completion and local options may be required under different tags or subtypes (current language filetype/syntax)
|
As there are more than one language in `.vue` file, different mapping, completion and local options may be required under different tags or syntax (current language filetype)
|
||||||
|
|
||||||
This plugin provides functions to get the tag/subtype where the cursor is in
|
This plugin provides functions to get the tag/syntax where the cursor is in
|
||||||
|
|
||||||
- `GetVueTag() => String` Return value is one of `'template', 'script', 'style'`
|
- `GetVueTag() => String` Return value is one of `'template', 'script', 'style'`
|
||||||
|
|
||||||
@@ -239,20 +239,20 @@ This plugin provides functions to get the tag/subtype where the cursor is in
|
|||||||
endfunction
|
endfunction
|
||||||
```
|
```
|
||||||
|
|
||||||
- `GetVueSubtype() => String` Return value is one of `'html', 'javascript', 'css', 'scss', ...`
|
- `GetVueSyntax() => String` Return value is one of `'html', 'javascript', 'css', 'scss', ...`
|
||||||
|
|
||||||
- `OnChangeVueSubtype(subtype)` An event listener that is called when subtype changes
|
- `OnChangeVueSyntax(syntax)` An event listener that is called when syntax changes
|
||||||
|
|
||||||
You can define it in your `vimrc` to set local options once the subtype changes
|
You can define it in your `vimrc` to set local options based on current syntax
|
||||||
|
|
||||||
```vim
|
```vim
|
||||||
" Example: set local options based on subtype
|
" Example: set local options based on syntax
|
||||||
function! OnChangeVueSubtype(subtype)
|
function! OnChangeVueSyntax(syntax)
|
||||||
echom 'Subtype is '.a:subtype
|
echom 'Syntax is '.a:syntax
|
||||||
if a:subtype == 'html'
|
if a:syntax == 'html'
|
||||||
setlocal commentstring=<!--%s-->
|
setlocal commentstring=<!--%s-->
|
||||||
setlocal comments=s:<!--,m:\ \ \ \ ,e:-->
|
setlocal comments=s:<!--,m:\ \ \ \ ,e:-->
|
||||||
elseif a:subtype =~ 'css'
|
elseif a:syntax =~ 'css'
|
||||||
setlocal comments=s1:/*,mb:*,ex:*/ commentstring&
|
setlocal comments=s1:/*,mb:*,ex:*/ commentstring&
|
||||||
else
|
else
|
||||||
setlocal commentstring=//%s
|
setlocal commentstring=//%s
|
||||||
@@ -261,6 +261,8 @@ This plugin provides functions to get the tag/subtype where the cursor is in
|
|||||||
endfunction
|
endfunction
|
||||||
```
|
```
|
||||||
|
|
||||||
|
> It has been renamed to `GetVueSyntax, OnChangeVueSyntax` from `GetVueSubtype, OnChangeVueSubtype` for consistency
|
||||||
|
|
||||||
### emmet-vim
|
### emmet-vim
|
||||||
|
|
||||||
Currently emmet-vim works regarding your `html, javascript, css, ...` emmet settings, but it depends on how emmet-vim gets `filetype` and may change in the future. Feel free to report an issue if any problem appears
|
Currently emmet-vim works regarding your `html, javascript, css, ...` emmet settings, but it depends on how emmet-vim gets `filetype` and may change in the future. Feel free to report an issue if any problem appears
|
||||||
|
|||||||
@@ -115,20 +115,26 @@ function! vue#GetConfig(name, default)
|
|||||||
return s:GetConfig(a:name, a:default)
|
return s:GetConfig(a:name, a:default)
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
if exists('##CursorMoved') && exists('*OnChangeVueSubtype')
|
if exists('##CursorMoved') && (exists('*OnChangeVueSyntax') || exists('*OnChangeVueSubtype'))
|
||||||
augroup vim_vue_plugin
|
augroup vim_vue_plugin
|
||||||
autocmd!
|
autocmd!
|
||||||
autocmd CursorMoved,CursorMovedI,WinEnter *.vue,*.wpy
|
autocmd CursorMoved,CursorMovedI,WinEnter *.vue,*.wpy
|
||||||
\ call s:CheckSubtype()
|
\ call s:CheckSyntax()
|
||||||
augroup END
|
augroup END
|
||||||
|
|
||||||
let s:subtype = ''
|
if exists('*OnChangeVueSyntax')
|
||||||
function! s:CheckSubtype()
|
let s:OnChangeListener = function('OnChangeVueSyntax')
|
||||||
let subtype = GetVueSubtype()
|
else
|
||||||
|
let s:OnChangeListener = function('OnChangeVueSubtype')
|
||||||
|
endif
|
||||||
|
|
||||||
if s:subtype != subtype
|
let s:syntax = ''
|
||||||
call OnChangeVueSubtype(subtype)
|
function! s:CheckSyntax()
|
||||||
let s:subtype = subtype
|
let syntax = GetVueSyntax()
|
||||||
|
|
||||||
|
if s:syntax != syntax
|
||||||
|
call s:OnChangeListener(syntax)
|
||||||
|
let s:syntax = syntax
|
||||||
endif
|
endif
|
||||||
endfunction
|
endfunction
|
||||||
endif
|
endif
|
||||||
@@ -203,6 +209,11 @@ function! GetVueSubtype()
|
|||||||
return syntax
|
return syntax
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
function! GetVueSyntax()
|
||||||
|
let syntax = vue#GetBlockSyntax(line('.'))
|
||||||
|
return syntax
|
||||||
|
endfunction
|
||||||
|
|
||||||
function! GetVueTag(...)
|
function! GetVueTag(...)
|
||||||
let lnum = a:0 > 0 ? a:1 : line('.')
|
let lnum = a:0 > 0 ? a:1 : line('.')
|
||||||
return vue#GetBlockTag(lnum)
|
return vue#GetBlockTag(lnum)
|
||||||
|
|||||||
Reference in New Issue
Block a user