mirror of
https://github.com/SpaceVim/SpaceVim.git
synced 2025-04-14 23:49:19 +08:00
Imporve compatible api (#2349)
* Imporve compatible api * Fix debug info close #2126
This commit is contained in:
parent
493d3273af
commit
6a4c7768e6
@ -28,22 +28,9 @@
|
||||
"
|
||||
" check if {feature} is supported in current version.
|
||||
|
||||
function! SpaceVim#api#vim#compatible#get() abort
|
||||
return map({
|
||||
\ 'execute' : '',
|
||||
\ 'system' : '',
|
||||
\ 'systemlist' : '',
|
||||
\ 'version' : '',
|
||||
\ 'has' : '',
|
||||
\ 'globpath' : '',
|
||||
\ 'matchaddpos' : '',
|
||||
\ 'win_screenpos' : '',
|
||||
\ },
|
||||
\ "function('s:' . v:key)"
|
||||
\ )
|
||||
endfunction
|
||||
let s:self = {}
|
||||
|
||||
function! s:has(feature) abort
|
||||
function! s:self.has(feature) abort
|
||||
if a:feature ==# 'python'
|
||||
try
|
||||
py import vim
|
||||
@ -71,11 +58,11 @@ function! s:has(feature) abort
|
||||
endfunction
|
||||
|
||||
if has('patch-8.0.1364')
|
||||
function! s:win_screenpos(nr) abort
|
||||
function! s:self.win_screenpos(nr) abort
|
||||
return win_screenpos(a:nr)
|
||||
endfunction
|
||||
elseif s:has('python')
|
||||
function! s:win_screenpos(nr) abort
|
||||
elseif s:self.has('python')
|
||||
function! s:self.win_screenpos(nr) abort
|
||||
if winnr('$') < a:nr || a:nr < 0
|
||||
return [0, 0]
|
||||
elseif a:nr == 0
|
||||
@ -85,8 +72,8 @@ elseif s:has('python')
|
||||
return [pyeval('vim.windows[' . a:nr . '].row'),
|
||||
\ pyeval('vim.windows[' . a:nr . '].col')]
|
||||
endfunction
|
||||
elseif s:has('python3')
|
||||
function! s:win_screenpos(nr) abort
|
||||
elseif s:self.has('python3')
|
||||
function! s:self.win_screenpos(nr) abort
|
||||
if winnr('$') < a:nr || a:nr < 0
|
||||
return [0, 0]
|
||||
elseif a:nr == 0
|
||||
@ -97,17 +84,17 @@ elseif s:has('python3')
|
||||
\ py3eval('vim.windows[' . a:nr . '].col')]
|
||||
endfunction
|
||||
else
|
||||
function! s:win_screenpos(nr) abort
|
||||
function! s:self.win_screenpos(nr) abort
|
||||
return [0, 0]
|
||||
endfunction
|
||||
endif
|
||||
|
||||
if exists('*execute')
|
||||
function! s:execute(cmd, ...) abort
|
||||
function! s:self.execute(cmd, ...) abort
|
||||
return call('execute', [a:cmd] + a:000)
|
||||
endfunction
|
||||
else
|
||||
function! s:execute(cmd, ...) abort
|
||||
function! s:self.execute(cmd, ...) abort
|
||||
if a:0 == 0
|
||||
let s = 'silent'
|
||||
else
|
||||
@ -128,14 +115,14 @@ else
|
||||
endif
|
||||
|
||||
if has('nvim')
|
||||
function! s:system(cmd, ...) abort
|
||||
function! s:self.system(cmd, ...) abort
|
||||
return a:0 == 0 ? system(a:cmd) : system(a:cmd, a:1)
|
||||
endfunction
|
||||
function! s:systemlist(cmd, ...) abort
|
||||
function! s:self.systemlist(cmd, ...) abort
|
||||
return a:0 == 0 ? systemlist(a:cmd) : systemlist(a:cmd, a:1)
|
||||
endfunction
|
||||
else
|
||||
function! s:system(cmd, ...) abort
|
||||
function! s:self.system(cmd, ...) abort
|
||||
if type(a:cmd) == 3
|
||||
let cmd = map(a:cmd, 'shellescape(v:val)')
|
||||
let cmd = join(cmd, ' ')
|
||||
@ -145,7 +132,7 @@ else
|
||||
endif
|
||||
endfunction
|
||||
if exists('*systemlist')
|
||||
function! s:systemlist(cmd, ...) abort
|
||||
function! s:self.systemlist(cmd, ...) abort
|
||||
if type(a:cmd) == 3
|
||||
let cmd = map(a:cmd, 'shellescape(v:val)')
|
||||
let excmd = join(cmd, ' ')
|
||||
@ -155,7 +142,7 @@ else
|
||||
endif
|
||||
endfunction
|
||||
else
|
||||
function! s:systemlist(cmd, ...) abort
|
||||
function! s:self.systemlist(cmd, ...) abort
|
||||
if type(a:cmd) == 3
|
||||
let cmd = map(a:cmd, 'shellescape(v:val)')
|
||||
let excmd = join(cmd, ' ')
|
||||
@ -170,22 +157,22 @@ else
|
||||
endif
|
||||
|
||||
if has('patch-7.4.279')
|
||||
function! s:globpath(dir, expr) abort
|
||||
function! s:self.globpath(dir, expr) abort
|
||||
return globpath(a:dir, a:expr, 1, 1)
|
||||
endfunction
|
||||
else
|
||||
function! s:globpath(dir, expr) abort
|
||||
function! s:self.globpath(dir, expr) abort
|
||||
return split(globpath(a:dir, a:expr), '\n')
|
||||
endfunction
|
||||
endif
|
||||
|
||||
if has('nvim')
|
||||
function! s:version() abort
|
||||
function! s:self.version() abort
|
||||
let v = api_info().version
|
||||
return v.major . '.' . v.minor . '.' . v.patch
|
||||
endfunction
|
||||
else
|
||||
function! s:version() abort
|
||||
function! s:self.version() abort
|
||||
redir => l:msg
|
||||
silent! execute ':version'
|
||||
redir END
|
||||
@ -219,14 +206,14 @@ endif
|
||||
" the third number gives the length of the highlight in bytes.
|
||||
|
||||
if exists('*matchaddpos')
|
||||
function! s:matchaddpos(group, pos, ...) abort
|
||||
function! s:self.matchaddpos(group, pos, ...) abort
|
||||
let priority = get(a:000, 0, 10)
|
||||
let id = get(a:000, 1, -1)
|
||||
let dict = get(a:000, 2, {})
|
||||
return matchaddpos(a:group, a:pos, priority, id, dict)
|
||||
endfunction
|
||||
else
|
||||
function! s:matchaddpos(group, pos, ...) abort
|
||||
function! s:self.matchaddpos(group, pos, ...) abort
|
||||
let priority = get(a:000, 0, 10)
|
||||
let id = get(a:000, 1, -1)
|
||||
let dict = get(a:000, 2, {})
|
||||
@ -261,5 +248,9 @@ else
|
||||
endfunction
|
||||
endif
|
||||
|
||||
function! SpaceVim#api#vim#compatible#get() abort
|
||||
return deepcopy(s:self)
|
||||
endfunction
|
||||
|
||||
|
||||
" vim:set et sw=2 cc=80:
|
||||
|
@ -23,10 +23,23 @@ endfunction
|
||||
|
||||
function! s:spacevim_status() abort
|
||||
let pwd = getcwd()
|
||||
exe 'cd ' . fnamemodify(g:_spacevim_root_dir, ':p:h:h')
|
||||
let status = system('git status')
|
||||
try
|
||||
exe 'cd ' . fnamemodify(g:_spacevim_root_dir, ':p:h:h')
|
||||
let status = s:CMP.systemlist('git status')
|
||||
catch
|
||||
exe 'cd ~/.SpaceVim'
|
||||
let status = s:CMP.systemlist('git status')
|
||||
endtry
|
||||
exe 'cd ' . pwd
|
||||
return split(status, "\n")
|
||||
if type(status) == 3
|
||||
return status
|
||||
else
|
||||
return [status]
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! Test() abort
|
||||
return s:spacevim_status()
|
||||
endfunction
|
||||
|
||||
function! s:template() abort
|
||||
@ -44,8 +57,8 @@ function! s:template() abort
|
||||
\ '',
|
||||
\ '```'
|
||||
\ ]
|
||||
\ + s:spacevim_status() +
|
||||
\ [
|
||||
let info = info + s:spacevim_status()
|
||||
let info = info + [
|
||||
\ '```',
|
||||
\ '',
|
||||
\ '## The reproduce ways from Vim starting (Required!)',
|
||||
|
Loading…
x
Reference in New Issue
Block a user