1
0
mirror of https://github.com/SpaceVim/SpaceVim.git synced 2025-02-13 19:18:00 +08:00
SpaceVim/autoload/SpaceVim/custom.vim

87 lines
2.7 KiB
VimL
Raw Normal View History

"=============================================================================
" custom.vim --- custom API in SpaceVim
" Copyright (c) 2016-2017 Wang Shidong & Contributors
" Author: Wang Shidong < wsdjeg at 163.com >
" URL: https://spacevim.org
" License: GPLv3
"=============================================================================
2017-04-13 23:02:15 +08:00
function! SpaceVim#custom#profile(dict) abort
for key in keys(a:dict)
call s:set(key, a:dict[key])
endfor
endfunction
function! s:set(key,val) abort
if !exists('g:spacevim_' . a:key)
call SpaceVim#logger#warn('no option named ' . a:key)
else
exe 'let ' . 'g:spacevim_' . a:key . '=' . a:val
endif
endfunction
2017-04-19 00:33:49 +08:00
" What is your preferred editing style?
" - Among the stars aboard the Evil flagship (vim)
" - On the planet Emacs in the Holy control tower (emacs)
"
" What distribution of spacemacs would you like to start with?
" The standard distribution, recommended (spacemacs)
" A minimalist distribution that you can build on (spacemacs-base)
2017-04-19 22:06:08 +08:00
function! SpaceVim#custom#autoconfig(...) abort
let menu = SpaceVim#api#import('cmdlinemenu')
let ques = [
\ ['dark powered mode', function('s:awesome_mode')],
\ ['basic mode', function('s:basic_mode')],
\ ]
call menu.menu(ques)
endfunction
function! s:awesome_mode() abort
2017-04-20 19:14:30 +08:00
let sep = SpaceVim#api#import('file').separator
let f = fnamemodify(g:_spacevim_root_dir, ':h') . join(['', 'mode', 'dark_powered.vim'], sep)
2017-04-20 19:14:30 +08:00
let config = readfile(f, '')
2017-04-19 22:06:08 +08:00
call s:write_to_config(config)
endfunction
function! s:basic_mode() abort
2017-04-20 19:14:30 +08:00
let sep = SpaceVim#api#import('file').separator
let f = fnamemodify(g:_spacevim_root_dir, ':h') . join(['', 'mode', 'basic.vim'], sep)
2017-04-20 19:14:30 +08:00
let config = readfile(f, '')
2017-04-19 22:06:08 +08:00
call s:write_to_config(config)
endfunction
function! s:write_to_config(config) abort
let cf = expand('~/.SpaceVim.d/init.vim')
if filereadable(cf)
return
endif
if !isdirectory(fnamemodify(cf, ':p:h'))
call mkdir(expand(fnamemodify(cf, ':p:h')), 'p')
endif
call writefile(a:config, cf, '')
endfunction
2017-12-01 20:16:24 +08:00
function! SpaceVim#custom#SPC(m, keys, cmd, desc, is_cmd) abort
call add(g:_spacevim_mappings_space_custom,[a:m, a:keys, a:cmd, a:desc, a:is_cmd])
endfunction
2017-12-01 20:16:24 +08:00
function! SpaceVim#custom#SPCGroupName(keys, name) abort
call add(g:_spacevim_mappings_space_custom_group_name, [a:keys, a:name])
endfunction
function! SpaceVim#custom#apply(config) abort
let config = json_decode(a:config)
for key in keys(config)
if exists('g:spacevim_' . key)
exe 'let g:spacevim_' . key . ' = "' . config[key] . '"'
endif
endfor
endfunction
function! SpaceVim#custom#write(force) abort
endfunction