15: Moved Log function to autoload and replace echom

This commit is contained in:
DCRichards
2019-10-08 10:34:52 +01:00
parent 4b0e807db4
commit 2da2a2fe03
3 changed files with 22 additions and 22 deletions

9
autoload/vue.vim Normal file
View File

@@ -0,0 +1,9 @@
let s:name = 'vim-vue-plugin'
let s:debug = exists("g:vim_vue_plugin_debug")
\ && g:vim_vue_plugin_debug == 1
function! vue#Log(msg)
if s:debug
echom '['.s:name.']['.v:lnum.'] '.a:msg
endif
endfunction

View File

@@ -16,7 +16,6 @@ endif
" Variables {{{ " Variables {{{
" "
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
let s:name = 'vim-vue-plugin'
" Let <template> handled by HTML " Let <template> handled by HTML
let s:vue_tag_start = '\v^\s*\<(script|style)' let s:vue_tag_start = '\v^\s*\<(script|style)'
let s:vue_tag_end = '\v^\s*\<\/(script|style)' let s:vue_tag_end = '\v^\s*\<\/(script|style)'
@@ -33,8 +32,6 @@ let s:tag_end = '\v^\s*\/?\>\s*'
" Config {{{ " Config {{{
" "
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
let s:debug = exists("g:vim_vue_plugin_debug")
\ && g:vim_vue_plugin_debug == 1
let s:use_pug = exists("g:vim_vue_plugin_use_pug") let s:use_pug = exists("g:vim_vue_plugin_use_pug")
\ && g:vim_vue_plugin_use_pug == 1 \ && g:vim_vue_plugin_use_pug == 1
let s:use_sass = exists("g:vim_vue_plugin_use_sass") let s:use_sass = exists("g:vim_vue_plugin_use_sass")
@@ -115,10 +112,10 @@ function! GetVueIndent()
let cursyn = get(cursyns, 0, '') let cursyn = get(cursyns, 0, '')
if s:SynHTML(prevsyn) if s:SynHTML(prevsyn)
call s:Log('syntax: xml') call vue#Log('syntax: xml')
let ind = XmlIndentGet(v:lnum, 0) let ind = XmlIndentGet(v:lnum, 0)
if prevline =~? s:empty_tag if prevline =~? s:empty_tag
call s:Log('prev line is an empty tag') call vue#Log('prev line is an empty tag')
let ind = ind - &sw let ind = ind - &sw
endif endif
@@ -133,24 +130,24 @@ function! GetVueIndent()
"Decrease indent if prevlines are a multiline empty tag "Decrease indent if prevlines are a multiline empty tag
let [start, end] = s:PrevMultilineEmptyTag(v:lnum) let [start, end] = s:PrevMultilineEmptyTag(v:lnum)
if end == prevlnum if end == prevlnum
call s:Log('prev line is a multiline empty tag') call vue#Log('prev line is a multiline empty tag')
let ind = ind - &sw let ind = ind - &sw
endif endif
endif endif
elseif s:SynPug(prevsyn) elseif s:SynPug(prevsyn)
call s:Log('syntax: pug') call vue#Log('syntax: pug')
let ind = GetPugIndent() let ind = GetPugIndent()
elseif s:SynCoffee(prevsyn) elseif s:SynCoffee(prevsyn)
call s:Log('syntax: coffee') call vue#Log('syntax: coffee')
let ind = GetCoffeeIndent(v:lnum) let ind = GetCoffeeIndent(v:lnum)
elseif s:SynSASS(prevsyn) elseif s:SynSASS(prevsyn)
call s:Log('syntax: sass') call vue#Log('syntax: sass')
let ind = GetSassIndent() let ind = GetSassIndent()
elseif s:SynStyle(prevsyn) elseif s:SynStyle(prevsyn)
call s:Log('syntax: style') call vue#Log('syntax: style')
let ind = GetCSSIndent() let ind = GetCSSIndent()
else else
call s:Log('syntax: javascript') call vue#Log('syntax: javascript')
if len(b:javascript_indentexpr) if len(b:javascript_indentexpr)
let ind = eval(b:javascript_indentexpr) let ind = eval(b:javascript_indentexpr)
else else
@@ -161,23 +158,23 @@ function! GetVueIndent()
if curline =~? s:vue_tag_start || curline =~? s:vue_tag_end if curline =~? s:vue_tag_start || curline =~? s:vue_tag_end
\|| prevline =~? s:vue_tag_end \|| prevline =~? s:vue_tag_end
\|| (curline =~ s:vue_template_tag_end && s:SynPug(prevsyn)) \|| (curline =~ s:vue_template_tag_end && s:SynPug(prevsyn))
call s:Log('current line is vue (end) tag or prev line is vue end tag') call vue#Log('current line is vue (end) tag or prev line is vue end tag')
let ind = 0 let ind = 0
elseif s:has_init_indent elseif s:has_init_indent
if s:SynVueScriptOrStyle(cursyn) && ind == 0 if s:SynVueScriptOrStyle(cursyn) && ind == 0
call s:Log('add initial indent') call vue#Log('add initial indent')
let ind = &sw let ind = &sw
endif endif
else else
let prevlnum_noncomment = s:PrevNonBlacnkNonComment(v:lnum) let prevlnum_noncomment = s:PrevNonBlacnkNonComment(v:lnum)
let prevline_noncomment = getline(prevlnum_noncomment) let prevline_noncomment = getline(prevlnum_noncomment)
if prevline_noncomment =~? s:vue_tag_start if prevline_noncomment =~? s:vue_tag_start
call s:Log('prev line is vue tag') call vue#Log('prev line is vue tag')
let ind = 0 let ind = 0
endif endif
endif endif
call s:Log('indent: '.ind) call vue#Log('indent: '.ind)
return ind return ind
endfunction endfunction
@@ -248,12 +245,6 @@ function! s:PrevNonBlacnkNonComment(lnum)
return prevlnum return prevlnum
endfunction endfunction
function! s:Log(msg)
if s:debug
echom '['.s:name.']['.v:lnum.'] '.a:msg
endif
endfunction
function! GetVueTag() function! GetVueTag()
let lnum = getcurpos()[1] let lnum = getcurpos()[1]
let cursyns = s:SynsEOL(lnum) let cursyns = s:SynsEOL(lnum)

View File

@@ -90,7 +90,7 @@ endif
" Avoid overload " Avoid overload
if hlexists('javaScriptComment') == 0 if hlexists('javaScriptComment') == 0
echom 'load javascript cluster' call vue#Log('load javascript cluster')
call s:LoadSyntax('@htmlJavaScript', 'javascript') call s:LoadSyntax('@htmlJavaScript', 'javascript')
endif endif
"}}} "}}}