mirror of
https://github.com/SpaceVim/SpaceVim.git
synced 2025-02-02 23:50: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
|
||||
"available APIs please check |spacevim-api|
|
||||
" Import API base the given {name}, and return the API object. for all
|
||||
" available APIs please check |spacevim-api|
|
||||
function! SpaceVim#api#import(name) abort
|
||||
if has_key(s:apis, a:name)
|
||||
return deepcopy(s:apis[a:name])
|
||||
@ -48,12 +47,34 @@ function! SpaceVim#api#import(name) abort
|
||||
return p
|
||||
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
|
||||
" the name must be string
|
||||
if type(a:name) ==# type('') && strlen(a:name) >= 1
|
||||
if !empty(SpaceVim#api#import(a:name))
|
||||
echoerr '[SpaceVim api] Api : ' . a:name . ' already existed!'
|
||||
call SpaceVim#logger#warn('API:' . a:name . ' already existed!')
|
||||
else
|
||||
let s:apis[a:name] = deepcopy(a:api)
|
||||
endif
|
||||
else
|
||||
call SpaceVim#logger#warn('failed to register api, the name must be a no empty string!')
|
||||
endif
|
||||
endfunction
|
||||
|
||||
" vim:set fdm=marker sw=2 nowrap:
|
||||
|
@ -1472,6 +1472,24 @@ SpaceVim#api#import({name}) *SpaceVim#api#import()*
|
||||
Import API base the given {name}, and return the API object. for all
|
||||
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()*
|
||||
The first parameter sets the type of shortcut key, which can be `nnoremap`
|
||||
|
Loading…
Reference in New Issue
Block a user