2018-02-19 22:07:04 +08:00
|
|
|
"=============================================================================
|
|
|
|
" layers.vim --- layers public API
|
|
|
|
" Copyright (c) 2016-2017 Wang Shidong & Contributors
|
|
|
|
" Author: Wang Shidong < wsdjeg at 163.com >
|
|
|
|
" URL: https://spacevim.org
|
|
|
|
" License: GPLv3
|
|
|
|
"=============================================================================
|
|
|
|
|
2017-01-18 20:52:19 +08:00
|
|
|
""
|
|
|
|
" @section Layers, layers
|
|
|
|
" SpaceVim support such layers:
|
|
|
|
|
2018-03-03 21:52:08 +08:00
|
|
|
let s:enabled_layers = []
|
2018-07-28 15:25:12 +08:00
|
|
|
let s:layers_vars = {}
|
2017-01-18 20:52:19 +08:00
|
|
|
|
|
|
|
""
|
2017-02-17 13:56:55 +08:00
|
|
|
" Load the {layer} you want. For all the layers SpaceVim supports, see @section(layers).
|
2017-07-28 05:22:12 +08:00
|
|
|
" the second argv is the layer variable.
|
2017-03-08 20:39:25 +08:00
|
|
|
function! SpaceVim#layers#load(layer, ...) abort
|
2018-03-03 21:52:08 +08:00
|
|
|
if a:layer ==# '-l'
|
2017-05-09 21:55:01 +08:00
|
|
|
call s:list_layers()
|
|
|
|
endif
|
2018-03-03 21:52:08 +08:00
|
|
|
if index(s:enabled_layers, a:layer) == -1
|
|
|
|
call add(s:enabled_layers, a:layer)
|
2017-08-26 20:17:33 +08:00
|
|
|
endif
|
|
|
|
if a:0 == 1 && type(a:1) == 4
|
|
|
|
try
|
2017-07-28 05:22:12 +08:00
|
|
|
call SpaceVim#layers#{a:layer}#set_variable(a:1)
|
2018-07-28 15:25:12 +08:00
|
|
|
let s:layers_vars[a:layer] = a:1
|
2017-08-26 20:17:33 +08:00
|
|
|
catch /^Vim\%((\a\+)\)\=:E117/
|
|
|
|
endtry
|
2017-03-06 23:26:26 +08:00
|
|
|
endif
|
2017-07-28 05:22:12 +08:00
|
|
|
if a:0 > 0 && type(a:1) == 1
|
2017-03-08 20:39:25 +08:00
|
|
|
for l in a:000
|
|
|
|
call SpaceVim#layers#load(l)
|
|
|
|
endfor
|
|
|
|
endif
|
2017-01-18 20:52:19 +08:00
|
|
|
endfunction
|
2017-03-06 23:26:26 +08:00
|
|
|
|
2017-12-21 20:13:56 +08:00
|
|
|
function! SpaceVim#layers#disable(layer) abort
|
2018-03-03 21:52:08 +08:00
|
|
|
let index = index(s:enabled_layers, a:layer)
|
2017-12-21 20:13:56 +08:00
|
|
|
if index != -1
|
2018-03-03 21:52:08 +08:00
|
|
|
call remove(s:enabled_layers, index)
|
2017-12-21 20:13:56 +08:00
|
|
|
endif
|
|
|
|
endfunction
|
|
|
|
|
2017-05-09 21:55:01 +08:00
|
|
|
function! s:list_layers() abort
|
|
|
|
tabnew SpaceVimLayers
|
|
|
|
nnoremap <buffer> q :q<cr>
|
|
|
|
setlocal buftype=nofile bufhidden=wipe nobuflisted nolist noswapfile nowrap cursorline nospell
|
|
|
|
setf SpaceVimLayerManager
|
|
|
|
nnoremap <silent> <buffer> q :bd<CR>
|
|
|
|
let info = [
|
|
|
|
\ 'SpaceVim layers:',
|
|
|
|
\ '',
|
|
|
|
\ ]
|
|
|
|
call setline(1,info + s:find_layers())
|
|
|
|
setl nomodifiable
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! s:find_layers() abort
|
2018-07-28 15:25:12 +08:00
|
|
|
let layers = SpaceVim#util#globpath(&rtp, 'autoload/SpaceVim/layers/**/*.vim')
|
2017-05-09 21:55:01 +08:00
|
|
|
let pattern = '/autoload/SpaceVim/layers/'
|
|
|
|
let rst = []
|
|
|
|
for layer in layers
|
|
|
|
if layer =~# pattern
|
|
|
|
let name = layer[matchend(layer, pattern):-5]
|
2018-03-03 21:52:08 +08:00
|
|
|
let status = (index(s:enabled_layers, substitute(name, '/', '#','g')) != -1) ? 'loaded' : 'not loaded'
|
2017-05-09 22:22:03 +08:00
|
|
|
if filereadable(expand('~/.SpaceVim/docs/layers/' . name . '.md'))
|
|
|
|
let website = 'https://spacevim.org/layers/' . name
|
|
|
|
else
|
|
|
|
let website = 'no exists'
|
|
|
|
endif
|
2018-07-28 15:25:12 +08:00
|
|
|
if status ==# 'loaded'
|
2017-05-09 22:22:03 +08:00
|
|
|
call add(rst, '+ ' . name . ':' . repeat(' ', 25 - len(name)) . status . repeat(' ', 10) . website)
|
|
|
|
else
|
2017-05-28 13:27:12 +08:00
|
|
|
call add(rst, '- ' . name . ':' . repeat(' ', 21 - len(name)) . status . repeat(' ', 10) . website)
|
2017-05-09 22:22:03 +08:00
|
|
|
endif
|
2017-05-09 21:55:01 +08:00
|
|
|
endif
|
|
|
|
endfor
|
|
|
|
return rst
|
|
|
|
endfunction
|
|
|
|
|
2018-03-03 21:52:08 +08:00
|
|
|
function! SpaceVim#layers#get() abort
|
|
|
|
return s:enabled_layers
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! SpaceVim#layers#isLoaded(layer) abort
|
|
|
|
return index(s:enabled_layers, a:layer) != -1
|
|
|
|
endfunction
|
|
|
|
|
2018-07-28 15:25:12 +08:00
|
|
|
function! SpaceVim#layers#report() abort
|
|
|
|
let info = "```toml\n"
|
|
|
|
for name in s:enabled_layers
|
|
|
|
let info .= "[[layers]]\n"
|
|
|
|
let info .= ' name="' . name . '"' . "\n"
|
|
|
|
if has_key(s:layers_vars, name)
|
|
|
|
for var in keys(s:layers_vars[name])
|
|
|
|
if var !=# 'name'
|
|
|
|
let info .= ' ' . var . '=' . string(s:layers_vars[name][var]) . "\n"
|
|
|
|
endif
|
|
|
|
endfor
|
|
|
|
endif
|
|
|
|
endfor
|
|
|
|
let info .= "```\n"
|
|
|
|
return info
|
|
|
|
endfunction
|
|
|
|
|
2017-05-09 21:55:01 +08:00
|
|
|
|
|
|
|
|
2017-03-06 23:26:26 +08:00
|
|
|
" vim:set et sw=2:
|