mirror of
https://github.com/SpaceVim/SpaceVim.git
synced 2025-02-03 19:00:06 +08:00
56 lines
1.3 KiB
VimL
56 lines
1.3 KiB
VimL
" ___vital___
|
|
" NOTE: lines between '" ___vital___' is generated by :Vitalize.
|
|
" Do not mofidify the code nor insert new lines before '" ___vital___'
|
|
function! s:_SID() abort
|
|
return matchstr(expand('<sfile>'), '<SNR>\zs\d\+\ze__SID$')
|
|
endfunction
|
|
execute join(['function! vital#_over#Unlocker#Rocker#HolderBase#import() abort', printf("return map({'make': '', 'has_concept': ''}, \"vital#_over#function('<SNR>%s_' . v:key)\")", s:_SID()), 'endfunction'], "\n")
|
|
delfunction s:_SID
|
|
" ___vital___
|
|
scriptencoding utf-8
|
|
let s:save_cpo = &cpo
|
|
set cpo&vim
|
|
|
|
|
|
let s:locker = {}
|
|
function! s:locker.lock()
|
|
let self.__old = self.get()
|
|
return self
|
|
endfunction
|
|
|
|
|
|
function! s:locker.unlock()
|
|
if !has_key(self, "__old")
|
|
return -1
|
|
endif
|
|
call self.set(self.__old)
|
|
unlet self.__old
|
|
endfunction
|
|
|
|
|
|
function! s:locker.relock()
|
|
call self.unlock()
|
|
call self.lock()
|
|
endfunction
|
|
|
|
|
|
function! s:has_concept(obj)
|
|
return type(a:obj) == type({})
|
|
\ && type(get(a:obj, "get", "")) == type(function("tr"))
|
|
\ && type(get(a:obj, "set", "")) == type(function("tr"))
|
|
endfunction
|
|
|
|
|
|
function! s:make(derived)
|
|
if !s:has_concept(a:derived)
|
|
throw "vital-unlocker Unlocker.Rocker.HolderBase.make() : Don't has locker concept."
|
|
endif
|
|
let result = extend(deepcopy(s:locker), a:derived)
|
|
return result
|
|
endfunction
|
|
|
|
|
|
|
|
let &cpo = s:save_cpo
|
|
unlet s:save_cpo
|