From 400f4ce49d2f85b5ba329099ced58222af436ae2 Mon Sep 17 00:00:00 2001 From: yemai Date: Fri, 19 Oct 2018 11:27:09 +0800 Subject: [PATCH] fix: use unix fileformat for .vim files --- filetype.vim | 32 +++---- indent/vue.vim | 250 ++++++++++++++++++++++++------------------------- syntax/vue.vim | 118 +++++++++++------------ 3 files changed, 200 insertions(+), 200 deletions(-) diff --git a/filetype.vim b/filetype.vim index dd70d1e..724205a 100644 --- a/filetype.vim +++ b/filetype.vim @@ -1,16 +1,16 @@ -au BufNewFile,BufRead *.vue,*.wpy call s:setFileType() - -function! s:setFileType() - " enable javascript autocmds first - let &filetype = 'javascript' - - " then set filetype - let &filetype = 'javascript.vue' -endfunction - -if !exists("g:vim_vue_plugin_has_init_indent") - let ext = expand("%:e") - if ext == 'wpy' - let g:vim_vue_plugin_has_init_indent = 1 - endif -endif +au BufNewFile,BufRead *.vue,*.wpy call s:setFileType() + +function! s:setFileType() + " enable javascript autocmds first + let &filetype = 'javascript' + + " then set filetype + let &filetype = 'javascript.vue' +endfunction + +if !exists("g:vim_vue_plugin_has_init_indent") + let ext = expand("%:e") + if ext == 'wpy' + let g:vim_vue_plugin_has_init_indent = 1 + endif +endif diff --git a/indent/vue.vim b/indent/vue.vim index 79e7780..7db1ce2 100644 --- a/indent/vue.vim +++ b/indent/vue.vim @@ -1,125 +1,125 @@ -""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" -" Vim indent file -" -" Language: Vue (Wepy) -" Maintainer: leafOfTree -" -""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" -se sw=2 ts=2 - -let s:name = 'vim-vue-plugin' - -" Save the current JavaScript indentexpr. -let b:vue_js_indentexpr = &indentexpr - -" load xml indent method -unlet b:did_indent -runtime! indent/xml.vim - -" load pug indent method -unlet b:did_indent -runtime! indent/pug.vim - -" load css indent method -unlet b:did_indent -runtime! indent/css.vim - -let b:did_indent = 1 -let b:did_vue_indent = 1 - -" JavaScript indentkeys -setlocal indentkeys=0{,0},0),0],0\,,!^F,o,O,e -" XML indentkeys -setlocal indentkeys+=*,<>>,<<>,/ - -let s:vue_tag = '\v\<\/?(template|script|style)' -let s:vue_tag_no_indent = '\v\<\/?(script|style)' -let s:end_tag = '^\s*\/\?>\s*' - -setlocal indentexpr=GetVueIndent() - -function! SynsEOL(lnum) - let lnum = prevnonblank(a:lnum) - let col = strlen(getline(lnum)) - return map(synstack(lnum, col), 'synIDattr(v:val, "name")') -endfunction - -function! SynsHTMLish(syns) - let first_syn = get(a:syns, 0) - return first_syn =~? '\v^(vueTemplate)' -endfunction - -function! SynsPugish(syns) - let second_syn = get(a:syns, 1) - return second_syn =~? '\v^(vueTemplatePug)' -endfunction - -function! SynsCSSish(syns) - let first_syn = get(a:syns, 0) - return first_syn =~? '\v^(vueStyle)' -endfunction - -function! SynsVueScope(syns) - let first_syn = get(a:syns, 0) - return first_syn =~? '\v^(vueStyle)|(vueTemplate)|(vueScript)' -endfunction - -function! GetVueIndent() - let curline = getline(v:lnum) - let prevline = getline(v:lnum - 1) - let cursyns = SynsEOL(v:lnum) - let prevsyns = SynsEOL(v:lnum - 1) - - if SynsPugish(prevsyns) - call LogMsg('type: pug') - let ind = GetPugIndent() - elseif SynsHTMLish(prevsyns) - call LogMsg('type: html') - let ind = XmlIndentGet(v:lnum, 0) - - " Align '/>' and '>' with '<' for multiline tags. - if curline =~? s:end_tag - let ind = ind - &sw - endif - " Then correct the indentation of any element following '/>' or '>'. - if prevline =~? s:end_tag - let ind = ind + &sw - endif - - elseif SynsCSSish(prevsyns) - call LogMsg('type: css') - let ind = GetCSSIndent() - else - call LogMsg('type: javascript') - if len(b:vue_js_indentexpr) - let ind = eval(b:vue_js_indentexpr) - else - let ind = cindent(v:lnum) - endif - endif - - if curline =~? s:vue_tag - call LogMsg('cur vue tag') - let ind = 0 - elseif (exists("g:vim_vue_plugin_has_init_indent") - \ && g:vim_vue_plugin_has_init_indent != 0) - if SynsVueScope(cursyns) && ind == 0 - call LogMsg('add init') - let ind = &sw - endif - else - if prevline =~? s:vue_tag_no_indent - call LogMsg('prev vue tag') - let ind = 0 - endif - endif - call LogMsg('result ind: '.ind) - - return ind -endfunction - -function! LogMsg(msg) - if g:vim_vue_plugin_debug - echom '['.s:name.'] '. a:msg - endif -endfunction +""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" +" Vim indent file +" +" Language: Vue (Wepy) +" Maintainer: leafOfTree +" +""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" +se sw=2 ts=2 + +let s:name = 'vim-vue-plugin' + +" Save the current JavaScript indentexpr. +let b:vue_js_indentexpr = &indentexpr + +" load xml indent method +unlet b:did_indent +runtime! indent/xml.vim + +" load pug indent method +unlet b:did_indent +runtime! indent/pug.vim + +" load css indent method +unlet b:did_indent +runtime! indent/css.vim + +let b:did_indent = 1 +let b:did_vue_indent = 1 + +" JavaScript indentkeys +setlocal indentkeys=0{,0},0),0],0\,,!^F,o,O,e +" XML indentkeys +setlocal indentkeys+=*,<>>,<<>,/ + +let s:vue_tag = '\v\<\/?(template|script|style)' +let s:vue_tag_no_indent = '\v\<\/?(script|style)' +let s:end_tag = '^\s*\/\?>\s*' + +setlocal indentexpr=GetVueIndent() + +function! SynsEOL(lnum) + let lnum = prevnonblank(a:lnum) + let col = strlen(getline(lnum)) + return map(synstack(lnum, col), 'synIDattr(v:val, "name")') +endfunction + +function! SynsHTMLish(syns) + let first_syn = get(a:syns, 0) + return first_syn =~? '\v^(vueTemplate)' +endfunction + +function! SynsPugish(syns) + let second_syn = get(a:syns, 1) + return second_syn =~? '\v^(vueTemplatePug)' +endfunction + +function! SynsCSSish(syns) + let first_syn = get(a:syns, 0) + return first_syn =~? '\v^(vueStyle)' +endfunction + +function! SynsVueScope(syns) + let first_syn = get(a:syns, 0) + return first_syn =~? '\v^(vueStyle)|(vueTemplate)|(vueScript)' +endfunction + +function! GetVueIndent() + let curline = getline(v:lnum) + let prevline = getline(v:lnum - 1) + let cursyns = SynsEOL(v:lnum) + let prevsyns = SynsEOL(v:lnum - 1) + + if SynsPugish(prevsyns) + call LogMsg('type: pug') + let ind = GetPugIndent() + elseif SynsHTMLish(prevsyns) + call LogMsg('type: html') + let ind = XmlIndentGet(v:lnum, 0) + + " Align '/>' and '>' with '<' for multiline tags. + if curline =~? s:end_tag + let ind = ind - &sw + endif + " Then correct the indentation of any element following '/>' or '>'. + if prevline =~? s:end_tag + let ind = ind + &sw + endif + + elseif SynsCSSish(prevsyns) + call LogMsg('type: css') + let ind = GetCSSIndent() + else + call LogMsg('type: javascript') + if len(b:vue_js_indentexpr) + let ind = eval(b:vue_js_indentexpr) + else + let ind = cindent(v:lnum) + endif + endif + + if curline =~? s:vue_tag + call LogMsg('cur vue tag') + let ind = 0 + elseif (exists("g:vim_vue_plugin_has_init_indent") + \ && g:vim_vue_plugin_has_init_indent != 0) + if SynsVueScope(cursyns) && ind == 0 + call LogMsg('add init') + let ind = &sw + endif + else + if prevline =~? s:vue_tag_no_indent + call LogMsg('prev vue tag') + let ind = 0 + endif + endif + call LogMsg('result ind: '.ind) + + return ind +endfunction + +function! LogMsg(msg) + if g:vim_vue_plugin_debug + echom '['.s:name.'] '. a:msg + endif +endfunction diff --git a/syntax/vue.vim b/syntax/vue.vim index 7c92547..68302c1 100644 --- a/syntax/vue.vim +++ b/syntax/vue.vim @@ -1,59 +1,59 @@ -""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" -" Vim syntax file -" -" Language: Vue (Wepy) -" Maintainer: leaf -" Depends: pangloss/vim-javascript -" -" CREDITS: Inspired by mxw/vim-jsx. -" -""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" -" Load syntax/*.vim to syntax group -if exists("g:vim_vue_plugin_load_full_syntax") - \ && g:vim_vue_plugin_load_full_syntax == 1 - unlet b:current_syntax - syn include @HTMLSyntax syntax/html.vim - - unlet! b:current_syntax - syn include @CSSSyntax syntax/css.vim -else - unlet b:current_syntax - syn include @HTMLSyntax $vimruntime/syntax/html.vim - silent! syn include @HTMLSyntax $vimruntime/../vimfiles/syntax/html.vim - - unlet! b:current_syntax - syn include @CSSSyntax $vimruntime/syntax/css.vim - silent! syn include @HTMLSyntax $vimruntime/../vimfiles/syntax/css.vim -endif - -if exists("g:vim_vue_plugin_use_pug") - \ && g:vim_vue_plugin_use_pug == 1 - unlet b:current_syntax - syn include @PugSyntax syntax/pug.vim -endif - -let b:current_syntax='vue' - -" Find tag