1
0
mirror of https://github.com/SpaceVim/SpaceVim.git synced 2025-02-03 06:20:05 +08:00
SpaceVim/lua/spacevim.lua

77 lines
1.7 KiB
Lua
Raw Normal View History

2020-12-20 20:22:11 +08:00
local M = {}
2019-05-31 21:45:09 +08:00
local options = require('spacevim.opt')
local layers = require('spacevim.layer')
2020-12-20 20:22:11 +08:00
function M.bootstrap()
2019-05-31 21:45:09 +08:00
options.init()
layers.init()
2021-08-14 09:30:57 +08:00
2019-05-31 21:45:09 +08:00
end
2020-12-20 20:22:11 +08:00
function M.eval(l)
2021-08-14 09:30:57 +08:00
if vim.api ~= nil then
return vim.api.nvim_eval(l)
else
2020-12-20 20:22:11 +08:00
return vim.eval(l)
2021-08-14 09:30:57 +08:00
end
end
-- there is no want to call viml function in old vim and neovim
function M.call(funcname, ...)
if vim.call ~= nil then
return vim.call(funcname, ...)
2020-12-20 20:22:11 +08:00
else
2021-08-14 09:30:57 +08:00
if vim.api ~= nil then
return vim.api.nvim_call_function(funcname, {...})
else
end
2020-12-20 20:22:11 +08:00
end
end
2021-08-14 09:30:57 +08:00
-- this is for Vim and old neovim
M.fn = setmetatable({}, {
__index = function(t, key)
local _fn
if vim.api ~= nil and vim.api[key] ~= nil then
_fn = function()
error(string.format("Tried to call API function with vim.fn: use vim.api.%s instead", key))
end
else
_fn = function(...)
return M.call(key, ...)
end
end
t[key] = _fn
return _fn
end
})
-- This is for vim and old neovim to use vim.o
M.vim_options = setmetatable({}, {
__index = function(t, key)
local _fn
if vim.api ~= nil then
-- for neovim
return vim.api.nvim_get_option(key)
else
-- for vim
_fn = M.eval('&' .. key)
end
t[key] = _fn
return _fn
end
})
-- this function is only for vim
function M.has(feature)
return M.eval('float2nr(has("' .. feature .. '"))')
end
2020-12-20 20:22:11 +08:00
return M