1
0
mirror of https://github.com/SpaceVim/SpaceVim.git synced 2025-01-23 12:50:04 +08:00

Merge branch 'dev' of github.com:SpaceVim/SpaceVim into dev

This commit is contained in:
wsdjeg 2017-10-28 21:09:03 +08:00
commit 45f63183f5
5 changed files with 140 additions and 1 deletions

View File

@ -0,0 +1,123 @@
let s:self = {}
if has('python')
" @vimlint(EVL103, 1, a:text)
function! s:self.encode(text) abort
py import vim
py import base64
py ret = base64.b64encode(vim.eval('a:text'))
py vim.command("return '{}'".format(ret))
endfunction
" base64Test => YmFzZTY0VGVzdA==
function! s:self.decode(text) abort
python <<EOF
import vim
import base64
ret = vim.eval('a:text')
try:
ret = base64.b64decode(ret)
vim.command("return '{}'".format(ret))
except TypeError, e:
vim.command("return '{}'".format(ret))
EOF
endfunction
" @vimlint(EVL103, 0, a:text)
else
function! s:self.encode(data) abort
let b64 = self._b64encode(self._str2bytes(a:data), self.standard_table, '=')
return join(b64, '')
endfunction
function! s:self.encodebin(data) abort
let b64 = self._b64encode(self._binstr2bytes(a:data), self.standard_table, '=')
return join(b64, '')
endfunction
function! s:self.decode(data) abort
let bytes = self._b64decode(split(a:data, '\zs'), self.standard_table, '=')
return self._bytes2str(bytes)
endfunction
let s:self.standard_table = [
\ 'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P',
\ 'Q','R','S','T','U','V','W','X','Y','Z','a','b','c','d','e','f',
\ 'g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v',
\ 'w','x','y','z','0','1','2','3','4','5','6','7','8','9','+','/']
let s:self.urlsafe_table = [
\ 'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P',
\ 'Q','R','S','T','U','V','W','X','Y','Z','a','b','c','d','e','f',
\ 'g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v',
\ 'w','x','y','z','0','1','2','3','4','5','6','7','8','9','-','_']
function! s:self._b64encode(bytes, table, pad) abort
let b64 = []
for i in range(0, len(a:bytes) - 1, 3)
let n = a:bytes[i] * 0x10000
\ + get(a:bytes, i + 1, 0) * 0x100
\ + get(a:bytes, i + 2, 0)
call add(b64, a:table[n / 0x40000])
call add(b64, a:table[n / 0x1000 % 0x40])
call add(b64, a:table[n / 0x40 % 0x40])
call add(b64, a:table[n % 0x40])
endfor
if len(a:bytes) % 3 == 1
let b64[-1] = a:pad
let b64[-2] = a:pad
endif
if len(a:bytes) % 3 == 2
let b64[-1] = a:pad
endif
return b64
endfunction
function! s:self._b64decode(b64, table, pad) abort
let a2i = {}
for i in range(len(a:table))
let a2i[a:table[i]] = i
endfor
let bytes = []
for i in range(0, len(a:b64) - 1, 4)
let n = a2i[a:b64[i]] * 0x40000
\ + a2i[a:b64[i + 1]] * 0x1000
\ + (a:b64[i + 2] == a:pad ? 0 : a2i[a:b64[i + 2]]) * 0x40
\ + (a:b64[i + 3] == a:pad ? 0 : a2i[a:b64[i + 3]])
call add(bytes, n / 0x10000)
call add(bytes, n / 0x100 % 0x100)
call add(bytes, n % 0x100)
endfor
if a:b64[-1] == a:pad
unlet a:b64[-1]
endif
if a:b64[-2] == a:pad
unlet a:b64[-1]
endif
return bytes
endfunction
function! s:self._binstr2bytes(str) abort
return map(range(len(a:str)/2), 'eval("0x".a:str[v:val*2 : v:val*2+1])')
endfunction
function! s:self._str2bytes(str) abort
return map(range(len(a:str)), 'char2nr(a:str[v:val])')
endfunction
function! s:self._bytes2str(bytes) abort
return eval('"' . join(map(copy(a:bytes), 'printf(''\x%02x'', v:val)'), '') . '"')
endfunction
endif
function! SpaceVim#api#data#base64#get()
return deepcopy(s:self)
endfunction

View File

@ -9,7 +9,7 @@ function! SpaceVim#layers#checkers#plugins() abort
if g:spacevim_enable_neomake
call add(plugins, ['neomake/neomake', {'merged' : 0, 'loadconf' : 1 , 'loadconf_before' : 1}])
elseif g:spacevim_enable_ale
call add(plugins, ['w0rp/ale', {'merged' : 0, 'loadconf' : 1 , 'loadconf_before' : 1}])
call add(plugins, ['w0rp/ale', {'merged' : 0, 'loadconf_before' : 1}])
else
call add(plugins, ['wsdjeg/syntastic', {'on_event': 'WinEnter', 'loadconf' : 1, 'merged' : 0}])
endif

View File

@ -125,6 +125,18 @@ if g:spacevim_enable_neomake
let l .= errors ? (warnings ? '' : ' ') . '%#SpaceVim_statusline_error#●' . errors . ' ' : ''
return l
endfunction
elseif g:spacevim_enable_ale
function! s:syntax_checking()
if !exists('g:ale_enabled')
return ''
endif
let counts = ale#statusline#Count(bufnr(''))
let warnings = counts.warning + counts.style_warning
let errors = counts.error + counts.style_error
let l = warnings ? ' %#SpaceVim_statusline_warn#●' . warnings . ' ' : ''
let l .= errors ? (warnings ? '' : ' ') . '%#SpaceVim_statusline_error#●' . errors . ' ' : ''
return l
endfunction
else
function! s:syntax_checking()
if !exists(':SyntasticCheck')

View File

@ -1,6 +1,7 @@
scriptencoding utf-8
let g:ale_sign_error = get(g:, 'spacevim_error_symbol', '✖')
let g:ale_sign_warning = get(g:,'spacevim_warning_symbol', '➤')
let g:ale_echo_msg_format = get(g:, 'ale_echo_msg_format', '%severity%: %linter%: %s')
if g:spacevim_colorscheme == 'gruvbox'
highlight link ALEErrorSign GruvboxRedSign

View File

@ -0,0 +1,3 @@
Execute ( SpaceVim api: data#list ):
let base64 = SpaceVim#api#import('data#base64')
AssertEqual "helloworld", base64.decode(base64.encode("helloworld"))