1
0
mirror of https://github.com/SpaceVim/SpaceVim.git synced 2025-02-03 21:50:05 +08:00
SpaceVim/bundle/vim-over/autoload/vital/_over/Unlocker/Holder/Any.vim

83 lines
2.2 KiB
VimL
Raw Normal View History

" ___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#Holder#Any#import() abort', printf("return map({'is_option': '', '_vital_depends': '', 'throw': '', 'is_variable': '', 'is_value': '', 'is_holder': '', 'make': '', '_vital_loaded': ''}, \"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
function! s:_is_string(src)
return type(a:src) == type("")
endfunction
function! s:_vital_loaded(V)
let s:V = a:V
let s:Value = a:V.import("Unlocker.Holder.Value")
let s:Variable = a:V.import("Unlocker.Holder.Variable")
let s:Multi = a:V.import("Unlocker.Holder.Multi")
let s:Register = a:V.import("Unlocker.Holder.Register")
endfunction
function! s:_vital_depends()
return [
\ "Unlocker.Holder.Variable",
\ "Unlocker.Holder.Value",
\ "Unlocker.Holder.Multi",
\ "Unlocker.Holder.Register",
\ ]
endfunction
function! s:is_holder(rhs)
return type(a:rhs) == type({})
\ && type(get(a:rhs, "get", "")) == type(function("tr"))
\ && type(get(a:rhs, "set", "")) == type(function("tr"))
endfunction
function! s:is_option(rhs)
return type(a:rhs) == type("")
\ && exists("&" . a:rhs)
endfunction
function! s:is_variable(rhs)
return !s:is_option(a:rhs)
\ && s:_is_string(a:rhs)
\ && a:rhs =~ '^[a-zA-Z&]'
\ && exists(a:rhs)
endfunction
function! s:is_value(rhs)
let type = type(a:rhs)
return type == type({}) || type == type([])
endfunction
function! s:throw(exp)
execute "throw" string(a:exp)
endfunction
function! s:make(rhs, ...)
return a:0 >= 1 ? s:Multi.make(map([a:rhs] + a:000, "s:make(v:val)"))
\ : s:is_holder(a:rhs) ? a:rhs
\ : s:Value.is_makeable(a:rhs) ? s:Value.make(a:rhs)
\ : s:Variable.is_makeable(a:rhs) ? s:Variable.make(a:rhs)
\ : s:Register.is_makeable(a:rhs) ? s:Register.make(a:rhs)
\ : s:is_option(a:rhs) ? s:Variable.make("&" . a:rhs)
\ : s:throw("vital-unlocker Unlocker.Holder.Any.make() : No supported value.")
endfunction
let &cpo = s:save_cpo
unlet s:save_cpo