2021-08-17 22:54:06 +08:00
|
|
|
--=============================================================================
|
|
|
|
-- layer.lua --- spacevim layer module
|
|
|
|
-- Copyright (c) 2016-2019 Wang Shidong & Contributors
|
|
|
|
-- Author: Wang Shidong < wsdjeg@outlook.com >
|
|
|
|
-- URL: https://spacevim.org
|
|
|
|
-- License: GPLv3
|
|
|
|
--=============================================================================
|
2019-05-31 21:45:09 +08:00
|
|
|
|
|
|
|
|
2021-08-17 22:54:06 +08:00
|
|
|
local M = {}
|
|
|
|
local sp = require('spacevim')
|
2022-06-19 11:25:56 +08:00
|
|
|
local spsys = require('spacevim.api').import('system')
|
2021-08-17 22:54:06 +08:00
|
|
|
|
|
|
|
-- local mt = {
|
2022-06-19 11:25:56 +08:00
|
|
|
-- __newindex = function(layer, layer_name, layer_obj)
|
|
|
|
-- rawset(layer, layer_name, layer_obj)
|
|
|
|
-- end,
|
|
|
|
-- __index = function(layer, layer_name)
|
|
|
|
-- if vim.g ~= nil then
|
|
|
|
-- return vim.g['spacevim_' .. key] or nil
|
|
|
|
-- else
|
|
|
|
-- return sp.eval('get(g:, "spacevim_' .. key .. '", v:null)')
|
|
|
|
-- end
|
|
|
|
-- end
|
2021-08-17 22:54:06 +08:00
|
|
|
-- }
|
|
|
|
-- setmetatable(M, mt)
|
|
|
|
|
|
|
|
function M.isLoaded(layer)
|
|
|
|
return sp.call('SpaceVim#layers#isLoaded', layer) == 1
|
2019-05-31 21:45:09 +08:00
|
|
|
end
|
|
|
|
|
2022-06-19 11:25:56 +08:00
|
|
|
local function find_layers()
|
2022-06-19 11:53:25 +08:00
|
|
|
local layers = sp.fn.globpath(sp.vim_options.runtimepath, 'autoload/SpaceVim/layers/**/*.vim', 0, 1)
|
2022-06-19 11:25:56 +08:00
|
|
|
local pattern = '/autoload/SpaceVim/layers/'
|
|
|
|
local rst = {}
|
|
|
|
for _, layer in pairs(layers) do
|
2022-06-19 12:03:48 +08:00
|
|
|
local name = layer:gsub('.+SpaceVim[\\/]layers[\\/]', ''):gsub('.vim$', ''):gsub('[\\/]', '/')
|
2022-06-19 19:46:21 +08:00
|
|
|
local status = ''
|
|
|
|
local url = ''
|
|
|
|
local website = ''
|
2022-06-19 12:03:48 +08:00
|
|
|
if M.isLoaded(name) then
|
2022-06-19 19:46:21 +08:00
|
|
|
status = 'loaded'
|
2022-06-19 12:03:48 +08:00
|
|
|
else
|
2022-06-19 19:46:21 +08:00
|
|
|
status = 'not loaded'
|
2022-06-19 12:03:48 +08:00
|
|
|
end
|
|
|
|
if name == 'lsp' then
|
2022-06-19 19:46:21 +08:00
|
|
|
url = 'language-server-protocol'
|
2022-06-19 12:03:48 +08:00
|
|
|
else
|
2022-06-19 19:46:21 +08:00
|
|
|
url = name
|
2022-06-19 12:03:48 +08:00
|
|
|
end
|
|
|
|
if sp.fn.filereadable(sp.fn.expand('~/.SpaceVim/docs/layers/' .. url .. '.md')) then
|
2022-06-19 19:46:21 +08:00
|
|
|
website = 'https://spacevim.org/layers/' .. url .. '/'
|
2022-06-19 12:03:48 +08:00
|
|
|
else
|
2022-06-19 19:46:21 +08:00
|
|
|
website = 'no exists'
|
2022-06-19 12:03:48 +08:00
|
|
|
end
|
2022-06-19 19:46:21 +08:00
|
|
|
name = sp.fn.substitute(name, '/', '#','g')
|
2022-06-19 12:03:48 +08:00
|
|
|
if status == 'loaded' then
|
2022-06-19 19:46:21 +08:00
|
|
|
table.insert(rst, '+ ' .. name .. ':' .. sp.fn['repeat'](' ', 25 - sp.fn.len(name)) .. status .. sp.fn['repeat'](' ', 10) .. website)
|
2022-06-19 12:03:48 +08:00
|
|
|
else
|
2022-06-19 19:46:21 +08:00
|
|
|
table.insert(rst, '- ' .. name .. ':' .. sp.fn['repeat'](' ', 25 - sp.fn.len(name)) .. status .. sp.fn['repeat'](' ', 10) .. website)
|
2022-06-19 12:03:48 +08:00
|
|
|
end
|
2022-06-19 11:25:56 +08:00
|
|
|
end
|
|
|
|
return rst
|
|
|
|
end
|
|
|
|
|
2022-06-16 23:38:10 +08:00
|
|
|
local function list_layers()
|
|
|
|
vim.cmd('tabnew SpaceVimLayers')
|
|
|
|
vim.cmd('nnoremap <buffer> q :q<cr>')
|
|
|
|
vim.cmd('setlocal buftype=nofile bufhidden=wipe nobuflisted nolist noswapfile nowrap cursorline nospell')
|
|
|
|
vim.cmd('setf SpaceVimLayerManager')
|
|
|
|
vim.cmd('nnoremap <silent> <buffer> q :bd<CR>')
|
|
|
|
local info = {'SpaceVim layers:', ''}
|
2022-06-19 11:25:56 +08:00
|
|
|
for k,v in pairs(find_layers()) do table.insert(info, v) end
|
|
|
|
sp.fn.setline(1,info)
|
2022-06-16 23:38:10 +08:00
|
|
|
vim.cmd('setl nomodifiable')
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
function M.load(layer, ...)
|
|
|
|
if layer == '-l' then
|
|
|
|
list_layers()
|
|
|
|
return
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-05-31 21:45:09 +08:00
|
|
|
|
2021-08-17 22:54:06 +08:00
|
|
|
return M
|