mirror of
https://github.com/SpaceVim/SpaceVim.git
synced 2025-02-09 08:40:04 +08:00
feat(api): improve SpaceVim#api#register
function
This commit is contained in:
parent
b53538deda
commit
8e7ffefc11
@ -32,9 +32,8 @@ let s:apis = {}
|
|||||||
|
|
||||||
|
|
||||||
""
|
""
|
||||||
"@public
|
" Import API base the given {name}, and return the API object. for all
|
||||||
"Import API base the given {name}, and return the API object. for all
|
" available APIs please check |spacevim-api|
|
||||||
"available APIs please check |spacevim-api|
|
|
||||||
function! SpaceVim#api#import(name) abort
|
function! SpaceVim#api#import(name) abort
|
||||||
if has_key(s:apis, a:name)
|
if has_key(s:apis, a:name)
|
||||||
return deepcopy(s:apis[a:name])
|
return deepcopy(s:apis[a:name])
|
||||||
@ -48,11 +47,33 @@ function! SpaceVim#api#import(name) abort
|
|||||||
return p
|
return p
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
""
|
||||||
|
" Register new {api} named {name}, 1 will be returned if succeed. for all
|
||||||
|
" available APIs please check |spacevim-api|
|
||||||
|
"
|
||||||
|
" Example:
|
||||||
|
" >
|
||||||
|
" let s:hello = {}
|
||||||
|
" function! s:hello.say(who)
|
||||||
|
" echo 'hello! ' . a:who
|
||||||
|
" endfunction
|
||||||
|
" call SpaceVim#api#register('hello', s:hello)
|
||||||
|
"
|
||||||
|
" " after registering api, you can use this api
|
||||||
|
" " in other vim scripts like this:
|
||||||
|
" let s:H = SpaceVim#api#import('hello')
|
||||||
|
" call s:H.say('wsdjeg')
|
||||||
|
" <
|
||||||
function! SpaceVim#api#register(name, api) abort
|
function! SpaceVim#api#register(name, api) abort
|
||||||
if !empty(SpaceVim#api#import(a:name))
|
" the name must be string
|
||||||
echoerr '[SpaceVim api] Api : ' . a:name . ' already existed!'
|
if type(a:name) ==# type('') && strlen(a:name) >= 1
|
||||||
|
if !empty(SpaceVim#api#import(a:name))
|
||||||
|
call SpaceVim#logger#warn('API:' . a:name . ' already existed!')
|
||||||
|
else
|
||||||
|
let s:apis[a:name] = deepcopy(a:api)
|
||||||
|
endif
|
||||||
else
|
else
|
||||||
let s:apis[a:name] = deepcopy(a:api)
|
call SpaceVim#logger#warn('failed to register api, the name must be a no empty string!')
|
||||||
endif
|
endif
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
@ -1472,6 +1472,24 @@ SpaceVim#api#import({name}) *SpaceVim#api#import()*
|
|||||||
Import API base the given {name}, and return the API object. for all
|
Import API base the given {name}, and return the API object. for all
|
||||||
available APIs please check |spacevim-api|
|
available APIs please check |spacevim-api|
|
||||||
|
|
||||||
|
SpaceVim#api#register({name}, {api}) *SpaceVim#api#register()*
|
||||||
|
Register new {api} named {name}, 1 will be returned if succeed. for all
|
||||||
|
available APIs please check |spacevim-api|
|
||||||
|
|
||||||
|
Example:
|
||||||
|
>
|
||||||
|
let s:hello = {}
|
||||||
|
function! s:hello.say(who)
|
||||||
|
echo 'hello! ' . a:who
|
||||||
|
endfunction
|
||||||
|
call SpaceVim#api#register('hello', s:hello)
|
||||||
|
|
||||||
|
" after registering api, you can use this api
|
||||||
|
" in other vim scripts like this:
|
||||||
|
let s:H = SpaceVim#api#import('hello')
|
||||||
|
call s:H.say('wsdjeg')
|
||||||
|
<
|
||||||
|
|
||||||
SpaceVim#custom#SPC({m}, {keys}, {cmd}, {desc}, {is_cmd})
|
SpaceVim#custom#SPC({m}, {keys}, {cmd}, {desc}, {is_cmd})
|
||||||
*SpaceVim#custom#SPC()*
|
*SpaceVim#custom#SPC()*
|
||||||
The first parameter sets the type of shortcut key, which can be `nnoremap`
|
The first parameter sets the type of shortcut key, which can be `nnoremap`
|
||||||
|
Loading…
Reference in New Issue
Block a user