mirror of
https://github.com/leafOfTree/vim-vue-plugin.git
synced 2025-12-08 13:44:46 +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
|
||||
|
||||
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'`
|
||||
|
||||
@@ -239,20 +239,20 @@ This plugin provides functions to get the tag/subtype where the cursor is in
|
||||
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
|
||||
" Example: set local options based on subtype
|
||||
function! OnChangeVueSubtype(subtype)
|
||||
echom 'Subtype is '.a:subtype
|
||||
if a:subtype == 'html'
|
||||
" Example: set local options based on syntax
|
||||
function! OnChangeVueSyntax(syntax)
|
||||
echom 'Syntax is '.a:syntax
|
||||
if a:syntax == 'html'
|
||||
setlocal commentstring=<!--%s-->
|
||||
setlocal comments=s:<!--,m:\ \ \ \ ,e:-->
|
||||
elseif a:subtype =~ 'css'
|
||||
elseif a:syntax =~ 'css'
|
||||
setlocal comments=s1:/*,mb:*,ex:*/ commentstring&
|
||||
else
|
||||
setlocal commentstring=//%s
|
||||
@@ -261,6 +261,8 @@ This plugin provides functions to get the tag/subtype where the cursor is in
|
||||
endfunction
|
||||
```
|
||||
|
||||
> It has been renamed to `GetVueSyntax, OnChangeVueSyntax` from `GetVueSubtype, OnChangeVueSubtype` for consistency
|
||||
|
||||
### 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
|
||||
|
||||
@@ -115,20 +115,26 @@ function! vue#GetConfig(name, default)
|
||||
return s:GetConfig(a:name, a:default)
|
||||
endfunction
|
||||
|
||||
if exists('##CursorMoved') && exists('*OnChangeVueSubtype')
|
||||
if exists('##CursorMoved') && (exists('*OnChangeVueSyntax') || exists('*OnChangeVueSubtype'))
|
||||
augroup vim_vue_plugin
|
||||
autocmd!
|
||||
autocmd CursorMoved,CursorMovedI,WinEnter *.vue,*.wpy
|
||||
\ call s:CheckSubtype()
|
||||
\ call s:CheckSyntax()
|
||||
augroup END
|
||||
|
||||
let s:subtype = ''
|
||||
function! s:CheckSubtype()
|
||||
let subtype = GetVueSubtype()
|
||||
if exists('*OnChangeVueSyntax')
|
||||
let s:OnChangeListener = function('OnChangeVueSyntax')
|
||||
else
|
||||
let s:OnChangeListener = function('OnChangeVueSubtype')
|
||||
endif
|
||||
|
||||
if s:subtype != subtype
|
||||
call OnChangeVueSubtype(subtype)
|
||||
let s:subtype = subtype
|
||||
let s:syntax = ''
|
||||
function! s:CheckSyntax()
|
||||
let syntax = GetVueSyntax()
|
||||
|
||||
if s:syntax != syntax
|
||||
call s:OnChangeListener(syntax)
|
||||
let s:syntax = syntax
|
||||
endif
|
||||
endfunction
|
||||
endif
|
||||
@@ -203,6 +209,11 @@ function! GetVueSubtype()
|
||||
return syntax
|
||||
endfunction
|
||||
|
||||
function! GetVueSyntax()
|
||||
let syntax = vue#GetBlockSyntax(line('.'))
|
||||
return syntax
|
||||
endfunction
|
||||
|
||||
function! GetVueTag(...)
|
||||
let lnum = a:0 > 0 ? a:1 : line('.')
|
||||
return vue#GetBlockTag(lnum)
|
||||
|
||||
Reference in New Issue
Block a user