spacevim/bundle/vim-choosewin/autoload/choosewin/util.vim
JIe 2bb7059579
Some checks failed
Detach Plugins / check (FlyGrep.vim) (push) Has been cancelled
Detach Plugins / check (GitHub.vim) (push) Has been cancelled
Detach Plugins / check (JavaUnit.vim) (push) Has been cancelled
Detach Plugins / check (SourceCounter.vim) (push) Has been cancelled
Detach Plugins / check (cpicker.nvim) (push) Has been cancelled
Detach Plugins / check (dein-ui.vim) (push) Has been cancelled
Detach Plugins / check (git.vim) (push) Has been cancelled
Detach Plugins / check (iedit.vim) (push) Has been cancelled
Detach Plugins / check (scrollbar.vim) (push) Has been cancelled
Detach Plugins / check (vim-chat) (push) Has been cancelled
Detach Plugins / check (vim-cheat) (push) Has been cancelled
Detach Plugins / check (vim-todo) (push) Has been cancelled
Detach Plugins / check (xmake.vim) (push) Has been cancelled
test / Linux (nvim, nightly) (push) Has been cancelled
test / Linux (nvim, v0.3.8) (push) Has been cancelled
test / Linux (nvim, v0.4.0) (push) Has been cancelled
test / Linux (nvim, v0.4.2) (push) Has been cancelled
test / Linux (nvim, v0.4.3) (push) Has been cancelled
test / Linux (nvim, v0.4.4) (push) Has been cancelled
test / Linux (nvim, v0.5.0) (push) Has been cancelled
test / Linux (nvim, v0.5.1) (push) Has been cancelled
test / Linux (nvim, v0.6.0) (push) Has been cancelled
test / Linux (nvim, v0.6.1) (push) Has been cancelled
test / Linux (nvim, v0.7.0) (push) Has been cancelled
test / Linux (nvim, v0.7.2) (push) Has been cancelled
test / Linux (nvim, v0.8.0) (push) Has been cancelled
test / Linux (nvim, v0.8.1) (push) Has been cancelled
test / Linux (nvim, v0.8.2) (push) Has been cancelled
test / Linux (nvim, v0.8.3) (push) Has been cancelled
test / Linux (nvim, v0.9.0) (push) Has been cancelled
test / Linux (nvim, v0.9.1) (push) Has been cancelled
test / Linux (true, vim, v7.4.052) (push) Has been cancelled
test / Linux (true, vim, v7.4.1689) (push) Has been cancelled
test / Linux (true, vim, v7.4.629) (push) Has been cancelled
test / Linux (true, vim, v8.0.0027) (push) Has been cancelled
test / Linux (true, vim, v8.0.0183) (push) Has been cancelled
test / Linux (vim, nightly) (push) Has been cancelled
test / Linux (vim, v8.0.0184) (push) Has been cancelled
test / Linux (vim, v8.0.1453) (push) Has been cancelled
test / Linux (vim, v8.1.2269) (push) Has been cancelled
test / Linux (vim, v8.2.2434) (push) Has been cancelled
test / Linux (vim, v8.2.3995) (push) Has been cancelled
test / Windows (nvim, nightly) (push) Has been cancelled
test / Windows (nvim, v0.3.8) (push) Has been cancelled
test / Windows (nvim, v0.4.2) (push) Has been cancelled
test / Windows (nvim, v0.4.3) (push) Has been cancelled
test / Windows (nvim, v0.4.4) (push) Has been cancelled
test / Windows (nvim, v0.5.0) (push) Has been cancelled
test / Windows (nvim, v0.5.1) (push) Has been cancelled
test / Windows (nvim, v0.6.0) (push) Has been cancelled
test / Windows (nvim, v0.6.1) (push) Has been cancelled
test / Windows (nvim, v0.7.0) (push) Has been cancelled
test / Windows (nvim, v0.7.2) (push) Has been cancelled
test / Windows (nvim, v0.8.0) (push) Has been cancelled
test / Windows (nvim, v0.8.1) (push) Has been cancelled
test / Windows (nvim, v0.8.2) (push) Has been cancelled
test / Windows (nvim, v0.8.3) (push) Has been cancelled
test / Windows (nvim, v0.9.0) (push) Has been cancelled
test / Windows (nvim, v0.9.1) (push) Has been cancelled
test / Windows (vim, nightly) (push) Has been cancelled
test / Windows (vim, v7.4.1185) (push) Has been cancelled
test / Windows (vim, v7.4.1689) (push) Has been cancelled
test / Windows (vim, v8.0.0027) (push) Has been cancelled
test / Windows (vim, v8.0.1453) (push) Has been cancelled
test / Windows (vim, v8.1.2269) (push) Has been cancelled
test / Windows (vim, v8.2.2434) (push) Has been cancelled
test / Windows (vim, v8.2.3995) (push) Has been cancelled
docker / docker (push) Has been cancelled
mirror / check (coding) (push) Has been cancelled
mirror / check (gitee) (push) Has been cancelled
mirror / check (gitlab) (push) Has been cancelled
init
2024-08-21 14:17:26 +08:00

175 lines
3.5 KiB
VimL

function! s:SID() abort "{{{1
let fullname = expand('<sfile>')
return matchstr(fullname, '<SNR>\d\+_')
endfunction
"}}}
let s:sid = s:SID()
function! s:uniq(list) abort "{{{1
let R = []
for e in a:list
if index(R, e) is -1
call add(R, e)
endif
endfor
return R
endfunction
"}}}
function! s:debug(msg) abort "{{{1
if !get(g:,'choosewin_debug')
return
endif
if exists('*Plog')
call Plog(a:msg)
endif
endfunction
function! s:buffer_options_set(bufnr, options) abort "{{{1
let R = {}
for [var, val] in items(a:options)
let R[var] = getbufvar(a:bufnr, var)
call setbufvar(a:bufnr, var, val)
unlet var val
endfor
return R
endfunction
function! s:window_options_set(winnr, options) abort "{{{1
let R = {}
for [var, val] in items(a:options)
let R[var] = getwinvar(a:winnr, var)
call setwinvar(a:winnr, var, val)
unlet var val
endfor
return R
endfunction
"}}}
" s:strchars() "{{{1
if exists('*strchars')
function! s:strchars(str) abort
return strchars(a:str)
endfunction
else
function! s:strchars(str) abort
return strlen(substitute(a:str, '.', 'x', 'g'))
endfunction
endif
"}}}
function! s:include_multibyte_char(str) abort "{{{1
return strlen(a:str) !=# s:strchars(a:str)
endfunction
function! s:str_split(str) abort "{{{1
return split(a:str, '\zs')
endfunction
function! s:define_type_checker() abort "{{{1
" dynamically define s:is_Number(v) etc..
let types = {
\ 'Number': 0,
\ 'String': 1,
\ 'Funcref': 2,
\ 'List': 3,
\ 'Dictionary': 4,
\ 'Float': 5,
\ }
for [type, number] in items(types)
let s = ''
let s .= 'function! s:is_' . type . '(v)' . "\n"
let s .= ' return type(a:v) is ' . number . "\n"
let s .= 'endfunction' . "\n"
execute s
endfor
endfunction
"}}}
call s:define_type_checker()
function! s:get_ic(table, char, ...) abort "{{{1
let default = get(a:000, 0)
" get() with ignore case
let keys = keys(a:table)
let i = index(keys, a:char, 0, 1)
if i is -1
return default
endif
return a:table[keys[i]]
endfunction
function! s:dict_invert(d) abort "{{{1
return s:dict_create(values(a:d), keys(a:d))
endfunction
function! s:dict_create(keys, values) abort "{{{1
" Create dict from two List.
let R = {}
for i in range(0, min([len(a:keys), len(a:values)]) - 1)
let R[a:keys[i]] = a:values[i]
endfor
return R
endfunction
function! s:blink(count, color, pattern) abort "{{{1
for i in range(a:count)
let id = matchadd(a:color, a:pattern)
redraw
sleep 80m
call matchdelete(id)
redraw
sleep 80m
endfor
endfunction
function! s:message(msg) abort "{{{1
echohl Type
echon 'choosewin: '
echohl Normal
echon a:msg
endfunction
function! s:read_char(prompt) abort "{{{1
redraw
echohl PreProc
echon a:prompt
echohl Normal
return nr2char(getchar())
endfunction
"}}}
let s:functions = [
\ 'debug',
\ 'uniq',
\ 'dict_invert',
\ 'dict_create',
\ 'str_split',
\ 'buffer_options_set',
\ 'window_options_set',
\ 'strchars',
\ 'include_multibyte_char',
\ 'is_Number',
\ 'is_String',
\ 'is_Funcref',
\ 'is_List',
\ 'is_Dictionary',
\ 'is_Float',
\ 'get_ic',
\ 'blink',
\ 'message',
\ 'read_char',
\ ]
function! choosewin#util#get() abort "{{{1
let R = {}
for fname in s:functions
let R[fname] = function(s:sid . fname)
endfor
return R
endfunction
"}}}
" vim: foldmethod=marker