mirror of
https://github.com/SpaceVim/SpaceVim.git
synced 2025-03-23 17:49:57 +08:00
Lua api (#3711)
This commit is contained in:
parent
88f9554122
commit
169ad9748a
@ -45,13 +45,37 @@ function! SpaceVim#api#data#dict#get() abort
|
|||||||
\ )
|
\ )
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:entrys(dict) abort
|
|
||||||
|
if has('lua') || has('nvim')
|
||||||
|
function! s:entrys(dict) abort
|
||||||
|
lua require("spacevim.api.data.dict").entrys(
|
||||||
|
\ require("spacevim").eval("a:dict")
|
||||||
|
\ )
|
||||||
|
endfunction
|
||||||
|
function! s:pick(dict, keys) abort
|
||||||
|
lua require("spacevim.api.data.dict").pick(
|
||||||
|
\ require("spacevim").eval("a:dict"),
|
||||||
|
\ require("spacevim").eval("a:keys")
|
||||||
|
\ )
|
||||||
|
endfunction
|
||||||
|
else
|
||||||
|
function! s:entrys(dict) abort
|
||||||
let entrys = []
|
let entrys = []
|
||||||
for key in keys(a:dict)
|
for key in keys(a:dict)
|
||||||
call add(entrys, {key : a:dict[key]})
|
call add(entrys, {key : a:dict[key]})
|
||||||
endfor
|
endfor
|
||||||
return entrys
|
return entrys
|
||||||
endfunction
|
endfunction
|
||||||
|
function! s:pick(dict, keys) abort
|
||||||
|
let new_dict = {}
|
||||||
|
for key in a:keys
|
||||||
|
if has_key(a:dict, key)
|
||||||
|
let new_dict[key] = a:dict[key]
|
||||||
|
endif
|
||||||
|
endfor
|
||||||
|
return new_dict
|
||||||
|
endfunction
|
||||||
|
endif
|
||||||
|
|
||||||
function! s:make(keys, values, ...) abort
|
function! s:make(keys, values, ...) abort
|
||||||
let dict = {}
|
let dict = {}
|
||||||
@ -77,15 +101,6 @@ function! s:make_index(list, ...) abort
|
|||||||
return s:make(a:list, [], value)
|
return s:make(a:list, [], value)
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:pick(dict, keys) abort
|
|
||||||
let new_dict = {}
|
|
||||||
for key in a:keys
|
|
||||||
if has_key(a:dict, key)
|
|
||||||
let new_dict[key] = a:dict[key]
|
|
||||||
endif
|
|
||||||
endfor
|
|
||||||
return new_dict
|
|
||||||
endfunction
|
|
||||||
|
|
||||||
function! s:omit(dict, keys) abort
|
function! s:omit(dict, keys) abort
|
||||||
let new_dict = copy(a:dict)
|
let new_dict = copy(a:dict)
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
local spacevim = {}
|
local M = {}
|
||||||
|
|
||||||
|
|
||||||
local options = require('spacevim.opt')
|
local options = require('spacevim.opt')
|
||||||
@ -6,11 +6,19 @@ local layers = require('spacevim.layer')
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
function spacevim.bootstrap()
|
function M.bootstrap()
|
||||||
|
|
||||||
options.init()
|
options.init()
|
||||||
layers.init()
|
layers.init()
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
return spacevim
|
function M.eval(l)
|
||||||
|
if vim['api'] ~= nil then
|
||||||
|
return vim.eval(l)
|
||||||
|
else
|
||||||
|
return vim.api.nvim_eval(l)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return M
|
||||||
|
@ -0,0 +1,19 @@
|
|||||||
|
local M = {}
|
||||||
|
|
||||||
|
|
||||||
|
function M.entrys(d)
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
function M.pick(d, keys)
|
||||||
|
local new_d = {}
|
||||||
|
for key, value in pairs(d) do
|
||||||
|
end
|
||||||
|
return new_d
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
return M
|
||||||
|
|
||||||
|
|
9
lua/spacevim/neovim.lua
Normal file
9
lua/spacevim/neovim.lua
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
|
||||||
|
|
||||||
|
local M = {}
|
||||||
|
|
||||||
|
function M.eval(l)
|
||||||
|
return vim.api.nvim_eval(l)
|
||||||
|
end
|
||||||
|
|
||||||
|
return M
|
0
lua/spacevim/vim.lua
Normal file
0
lua/spacevim/vim.lua
Normal file
4
test/lua/spacevim.vader
Normal file
4
test/lua/spacevim.vader
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
Execute ( lua module spacevim ):
|
||||||
|
let g:test_lua = 'abc'
|
||||||
|
AssertEqual luaeval('require("spacevim").eval("g:test_lua")'), 'abc'
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user