From 9e55939c896374e51c6b0f8a9e8e3b720d53fd3c Mon Sep 17 00:00:00 2001 From: leafOfTree Date: Fri, 23 Apr 2021 12:49:55 +0800 Subject: [PATCH] Rename subtype to syntax --- README.md | 22 ++++++++++++---------- autoload/vue.vim | 27 +++++++++++++++++++-------- 2 files changed, 31 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index b40104d..6f03805 100644 --- a/README.md +++ b/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= setlocal comments=s: - 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 diff --git a/autoload/vue.vim b/autoload/vue.vim index 082d53a..0afe86b 100644 --- a/autoload/vue.vim +++ b/autoload/vue.vim @@ -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)