Core: cleanup buffer handling (stage 2).

This commit is contained in:
LCD 47 2016-10-04 19:39:26 +03:00
parent 59cc80a8f7
commit 9648145ab1
5 changed files with 51 additions and 28 deletions

View File

@ -21,7 +21,7 @@ function! syntastic#log#warn(msg) abort " {{{2
endfunction " }}}2
function! syntastic#log#error(msg) abort " {{{2
execute "normal \<Esc>"
execute 'normal! \<Esc>'
echohl ErrorMsg
echomsg 'syntastic: error: ' . a:msg
echohl None

View File

@ -102,6 +102,10 @@ function! syntastic#util#rmrf(what) abort " {{{2
endif
endfunction " }}}2
function! syntastic#util#getbufvar(buf, name, ...) abort " {{{2
return a:0 ? s:_getbufvar(a:buf, a:name, a:1) : getbufvar(a:buf, a:name)
endfunction " }}}2
" Search the first 5 lines of the file for a magic number and return a map
" containing the args and the executable
"
@ -126,6 +130,16 @@ function! syntastic#util#parseShebang() abort " {{{2
return { 'exe': '', 'args': [] }
endfunction " }}}2
" Get the value of a Vim variable. Allow buffer variables to override global ones.
function! syntastic#util#bufRawVar(buf, name, ...) abort " {{{2
return s:_getbufvar(a:buf, a:name, get(g:, a:name, a:0 > 0 ? a:1 : ''))
endfunction "}}}2
" Get the value of a syntastic variable. Allow buffer variables to override global ones.
function! syntastic#util#bufVar(buf, name, ...) abort " {{{2
return call('syntastic#util#bufRawVar', [a:buf, 'syntastic_' . a:name] + a:000)
endfunction "}}}2
" Get the value of a Vim variable. Allow local variables to override global ones.
function! syntastic#util#rawVar(name, ...) abort " {{{2
return get(b:, a:name, get(g:, a:name, a:0 > 0 ? a:1 : ''))
@ -165,11 +179,6 @@ function! syntastic#util#compareLexi(a, b) abort " {{{2
return 0
endfunction " }}}2
" strwidth() was added in Vim 7.3; if it doesn't exist, we use strlen()
" and hope for the best :)
let s:_width = function(exists('*strwidth') ? 'strwidth' : 'strlen')
lockvar s:_width
function! syntastic#util#screenWidth(str, tabstop) abort " {{{2
let chunks = split(a:str, "\t", 1)
let width = s:_width(chunks[-1])
@ -391,9 +400,6 @@ function! syntastic#util#setWids() abort " {{{2
endfor
endfunction " }}}2
let s:_str2float = function(exists('*str2float') ? 'str2float' : 'str2nr')
lockvar s:_str2float
function! syntastic#util#str2float(val) abort " {{{2
return s:_str2float(a:val)
endfunction " }}}2
@ -515,6 +521,11 @@ function! s:_translateElement(key, term) abort " {{{2
return ret
endfunction " }}}2
" strwidth() was added in Vim 7.3; if it doesn't exist, we use strlen()
" and hope for the best :)
let s:_width = function(exists('*strwidth') ? 'strwidth' : 'strlen')
lockvar s:_width
" @vimlint(EVL103, 1, a:flags)
function! s:_delete_dumb(what, flags) abort " {{{2
if !exists('s:rmrf')
@ -561,6 +572,9 @@ function! s:_rmrf(what) abort " {{{2
endif
endfunction " }}}2
let s:_str2float = function(exists('*str2float') ? 'str2float' : 'str2nr')
lockvar s:_str2float
function! s:_float2str_smart(val) abort " {{{2
return printf('%.1f', a:val)
endfunction " }}}2
@ -572,6 +586,18 @@ endfunction " }}}2
let s:_float2str = function(has('float') ? 's:_float2str_smart' : 's:_float2str_dumb')
lockvar s:_float2str
function! s:_getbufvar_dumb(buf, name, ...) abort " {{{2
let ret = getbufvar(a:buf, a:name)
if a:0 > 0 && ret ==# ''
unlet! ret
let ret = a:1
endif
return ret
endfunction "}}}2
let s:_getbufvar = function(v:version > 703 || (v:version == 703 && has('patch831')) ? 'getbufvar' : 's:_getbufvar_dumb')
lockvar s:_getbufvar
" }}}1
let &cpo = s:save_cpo

View File

@ -19,7 +19,7 @@ if has('reltime')
lockvar! g:_SYNTASTIC_START
endif
let g:_SYNTASTIC_VERSION = '3.7.0-226'
let g:_SYNTASTIC_VERSION = '3.7.0-227'
lockvar g:_SYNTASTIC_VERSION
" Sanity checks {{{1
@ -136,9 +136,9 @@ let s:_DEBUG_DUMP_OPTIONS = [
\ 'shellxquote'
\ ]
for s:feature in [
\ 'shellxescape',
\ 'shellslash',
\ 'autochdir',
\ 'shellslash',
\ 'shellxescape',
\ ]
if exists('+' . s:feature)

View File

@ -15,7 +15,7 @@ function! g:SyntasticChecker.New(args, ...) abort " {{{2
if a:0
" redirected checker
let newObj._exec = get(a:args, 'exec', a:1['_exec'])
let newObj._exec_default = get(a:args, 'exec', a:1['_exec'])
let filetype = a:1['_filetype']
let name = a:1['_name']
@ -31,7 +31,7 @@ function! g:SyntasticChecker.New(args, ...) abort " {{{2
let newObj._enable = a:1['_enable']
endif
else
let newObj._exec = get(a:args, 'exec', newObj._name)
let newObj._exec_default = get(a:args, 'exec', newObj._name)
let prefix = 'SyntaxCheckers_' . newObj._filetype . '_' . newObj._name . '_'
if has_key(a:args, 'enable')
@ -69,17 +69,9 @@ endfunction " }}}2
" automatically, but you should keep still this in mind if you change the
" current checker workflow.
function! g:SyntasticChecker.syncExec() abort " {{{2
let user_exec =
\ expand( exists('b:syntastic_' . self._name . '_exec') ? b:syntastic_{self._name}_exec :
\ syntastic#util#var(self._filetype . '_' . self._name . '_exec'), 1 )
if user_exec !=# '' && user_exec !=# self._exec
let self._exec = user_exec
if has_key(self, '_available')
" we have a new _exec on the block, it has to be validated
call remove(self, '_available')
endif
endif
let suffix = self._name . '_exec'
let user_exec = expand( syntastic#util#var(self._filetype . '_' . suffix, syntastic#util#var(suffix)), 1 )
let self._exec = user_exec !=# '' ? user_exec : self._exec_default
endfunction " }}}2
function! g:SyntasticChecker.getExec() abort " {{{2
@ -187,10 +179,15 @@ endfunction " }}}2
function! g:SyntasticChecker.isAvailable() abort " {{{2
call self.syncExec()
if !has_key(self, '_available')
let self._available = self._isAvailableFunc()
let self._available = {}
endif
return self._available
if !has_key(self._available, self._exec)
let self._available[self._exec] = self._isAvailableFunc()
endif
return self._available[self._exec]
endfunction " }}}2
function! g:SyntasticChecker.isDisabled() abort " {{{2

View File

@ -29,7 +29,7 @@ endfunction " }}}2
function! g:SyntasticLoclist.current(...) abort " {{{2
let buf = a:0 > 1 ? a:1 : bufnr('')
let loclist = getbufvar(buf, 'syntastic_loclist')
let loclist = syntastic#util#getbufvar(buf, 'syntastic_loclist', {})
if type(loclist) != type({}) || empty(loclist)
unlet! loclist
let loclist = g:SyntasticLoclist.New([])