mirror of
https://github.com/SpaceVim/SpaceVim.git
synced 2025-03-23 01:09:56 +08:00
feat(api): improve SpaceVim#api#register
function
This commit is contained in:
parent
b53538deda
commit
8e7ffefc11
@ -32,7 +32,6 @@ 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
|
||||||
@ -48,12 +47,34 @@ 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
|
||||||
|
" the name must be string
|
||||||
|
if type(a:name) ==# type('') && strlen(a:name) >= 1
|
||||||
if !empty(SpaceVim#api#import(a:name))
|
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
|
else
|
||||||
let s:apis[a:name] = deepcopy(a:api)
|
let s:apis[a:name] = deepcopy(a:api)
|
||||||
endif
|
endif
|
||||||
|
else
|
||||||
|
call SpaceVim#logger#warn('failed to register api, the name must be a no empty string!')
|
||||||
|
endif
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
" vim:set fdm=marker sw=2 nowrap:
|
" 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
|
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…
x
Reference in New Issue
Block a user