1
0
mirror of https://github.com/SpaceVim/SpaceVim.git synced 2025-02-03 01:40:05 +08:00

Remove some code && fix windows support (#2874)

This commit is contained in:
Wang Shidong 2019-06-08 15:09:53 +08:00 committed by GitHub
parent 82aaec57a8
commit 81b56a907c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
19 changed files with 488 additions and 495 deletions

View File

@ -1157,6 +1157,20 @@ function! SpaceVim#end() abort
let &softtabstop = g:spacevim_default_indent let &softtabstop = g:spacevim_default_indent
let &shiftwidth = g:spacevim_default_indent let &shiftwidth = g:spacevim_default_indent
let g:unite_source_menu_menus =
\ get(g:,'unite_source_menu_menus',{})
let g:unite_source_menu_menus.CustomKeyMaps = {'description':
\ 'Custom mapped keyboard shortcuts [unite]<SPACE>'}
let g:unite_source_menu_menus.CustomKeyMaps.command_candidates =
\ get(g:unite_source_menu_menus.CustomKeyMaps,'command_candidates', [])
let g:unite_source_menu_menus.MyStarredrepos = {'description':
\ 'All github repos starred by me <leader>ls'}
let g:unite_source_menu_menus.MyStarredrepos.command_candidates =
\ get(g:unite_source_menu_menus.MyStarredrepos,'command_candidates', [])
let g:unite_source_menu_menus.MpvPlayer = {'description':
\ 'Musics list <leader>lm'}
let g:unite_source_menu_menus.MpvPlayer.command_candidates =
\ get(g:unite_source_menu_menus.MpvPlayer,'command_candidates', [])
if g:spacevim_realtime_leader_guide if g:spacevim_realtime_leader_guide
nnoremap <silent><nowait> <leader> :<c-u>LeaderGuide get(g:, 'mapleader', '\')<CR> nnoremap <silent><nowait> <leader> :<c-u>LeaderGuide get(g:, 'mapleader', '\')<CR>
@ -1167,17 +1181,17 @@ function! SpaceVim#end() abort
call SpaceVim#plugins#projectmanager#RootchandgeCallback() call SpaceVim#plugins#projectmanager#RootchandgeCallback()
call zvim#util#source_rc('general.vim') call SpaceVim#util#loadConfig('general.vim')
call SpaceVim#autocmds#init() call SpaceVim#autocmds#init()
if has('nvim') if has('nvim')
call zvim#util#source_rc('neovim.vim') call SpaceVim#util#loadConfig('neovim.vim')
endif endif
call zvim#util#source_rc('commands.vim') call SpaceVim#util#loadConfig('commands.vim')
filetype plugin indent on filetype plugin indent on
syntax on syntax on
endfunction endfunction
@ -1208,8 +1222,8 @@ endfunction
function! SpaceVim#begin() abort function! SpaceVim#begin() abort
call zvim#util#source_rc('functions.vim') call SpaceVim#util#loadConfig('functions.vim')
call zvim#util#source_rc('init.vim') call SpaceVim#util#loadConfig('init.vim')
" Before loading SpaceVim, We need to parser argvs. " Before loading SpaceVim, We need to parser argvs.
let s:status = s:parser_argv() let s:status = s:parser_argv()

View File

@ -48,7 +48,7 @@ function! SpaceVim#autocmds#init() abort
autocmd FileType cs set comments=sO:*\ -,mO:*\ \ ,exO:*/,s1:/*,mb:*,ex:*/,:///,:// autocmd FileType cs set comments=sO:*\ -,mO:*\ \ ,exO:*/,s1:/*,mb:*,ex:*/,:///,://
autocmd FileType vim set comments=sO:\"\ -,mO:\"\ \ ,eO:\"\",:\" autocmd FileType vim set comments=sO:\"\ -,mO:\"\ \ ,eO:\"\",:\"
autocmd Filetype qf setlocal nobuflisted autocmd Filetype qf setlocal nobuflisted
autocmd FileType python,coffee call zvim#util#check_if_expand_tab() autocmd FileType python,coffee call SpaceVim#util#check_if_expand_tab()
au StdinReadPost * call s:disable_welcome() au StdinReadPost * call s:disable_welcome()
autocmd InsertEnter * call s:fixindentline() autocmd InsertEnter * call s:fixindentline()
autocmd BufEnter,FileType * call SpaceVim#mapping#space#refrashLSPC() autocmd BufEnter,FileType * call SpaceVim#mapping#space#refrashLSPC()

View File

@ -1,13 +1,13 @@
let s:debug_message = [] let s:debug_message = []
function! zvim#debug#completion_debug(ArgLead, CmdLine, CursorPos) abort function! SpaceVim#commands#debug#completion_debug(ArgLead, CmdLine, CursorPos) abort
call add(s:debug_message, 'arglead:['.a:ArgLead .'] cmdline:[' .a:CmdLine .'] cursorpos:[' .a:CursorPos .']') call add(s:debug_message, 'arglead:['.a:ArgLead .'] cmdline:[' .a:CmdLine .'] cursorpos:[' .a:CursorPos .']')
endfunction endfunction
function! zvim#debug#get_message() abort function! SpaceVim#commands#debug#get_message() abort
return join(s:debug_message, "\n") return join(s:debug_message, "\n")
endfunction endfunction
function! zvim#debug#clean_message() abort function! SpaceVim#commands#debug#clean_message() abort
let s:debug_message = [] let s:debug_message = []
return s:debug_message return s:debug_message
endfunction endfunction

View File

@ -0,0 +1,53 @@
"=============================================================================
" mpv.vim --- mpv layer for SpaceVim
" Copyright (c) 2016-2017 Wang Shidong & Contributors
" Author: Wang Shidong < wsdjeg at 163.com >
" URL: https://spacevim.org
" License: GPLv3
"=============================================================================
let s:JOB = SpaceVim#api#import('job')
function! SpaceVim#layers#tools#mpv#config() abort
endfunction
function! SpaceVim#layers#tools#mpv#loadMusics() abort
let musics = SpaceVim#util#globpath('~/Musics', '*.mp3')
let g:unite_source_menu_menus.MpvPlayer.command_candidates = []
for m in musics
call add(g:unite_source_menu_menus.MpvPlayer.command_candidates,
\ [fnamemodify(m, ':t'),
\ "call SpaceVim#layers#tools#mpv#play('" . m . "')"])
endfor
endfunction
let s:playId = 0
fu! s:handler(id, data, event) abort
if a:event ==# 'exit'
echom 'job ' . a:id . ' exit with code:' . string(a:data)
let s:playId = 0
endif
endf
function! s:stop() abort
if s:playId != 0
call jobstop(s:playId)
let s:playId = 0
endif
delcommand MStop
endfunction
function! s:play(file,...) abort
if s:playId != 0
call s:JOB.stop(s:playId)
let s:playId = 0
endif
let s:playId = s:JOB.start(['mpv','--vid=no',a:file],{
\ 'on_stdout': function('s:handler'),
\ 'on_stderr': function('s:handler'),
\ 'on_exit': function('s:handler'),
\ })
command! MStop call zvim#mpv#stop()
endfunction

View File

@ -51,9 +51,9 @@ function! SpaceVim#layers#ui#config() abort
endif endif
if !empty(g:spacevim_windows_smartclose) if !empty(g:spacevim_windows_smartclose)
call SpaceVim#mapping#def('nnoremap <silent>', g:spacevim_windows_smartclose, ':<C-u>call zvim#util#SmartClose()<cr>', call SpaceVim#mapping#def('nnoremap <silent>', g:spacevim_windows_smartclose, ':<C-u>call SpaceVim#mapping#SmartClose()<cr>',
\ 'Smart close windows', \ 'Smart close windows',
\ 'call zvim#util#SmartClose()') \ 'call SpaceVim#mapping#SmartClose()')
endif endif
" Ui toggles " Ui toggles
call SpaceVim#mapping#space#def('nnoremap', ['t', '8'], 'call call(' call SpaceVim#mapping#space#def('nnoremap', ['t', '8'], 'call call('

View File

@ -278,6 +278,34 @@ function! SpaceVim#mapping#format() abort
call setpos('.', save_cursor) call setpos('.', save_cursor)
endfunction endfunction
function! SpaceVim#mapping#BufferEmpty() abort
let l:current = bufnr('%')
if ! getbufvar(l:current, '&modified')
enew
silent! execute 'bdelete '.l:current
endif
endfunction
fu! SpaceVim#mapping#SmartClose() abort
let ignorewin = get(g:,'spacevim_smartcloseignorewin',[])
let ignoreft = get(g:, 'spacevim_smartcloseignoreft',[])
let win_count = winnr('$')
let num = win_count
for i in range(1,win_count)
if index(ignorewin , bufname(winbufnr(i))) != -1 || index(ignoreft, getbufvar(bufname(winbufnr(i)),'&filetype')) != -1
let num = num - 1
elseif getbufvar(winbufnr(i),'&buftype') ==# 'quickfix'
let num = num - 1
elseif getwinvar(i, '&previewwindow') == 1 && winnr() !=# i
let num = num - 1
endif
endfor
if num == 1
else
quit
endif
endf
function! SpaceVim#mapping#gf() abort function! SpaceVim#mapping#gf() abort
if &filetype isnot# 'vim' if &filetype isnot# 'vim'
return 0 return 0

View File

@ -81,9 +81,9 @@ function! SpaceVim#mapping#leader#defindWindowsLeader(key) abort
\ ] \ ]
\ ] \ ]
nnoremap <silent> [Window]x nnoremap <silent> [Window]x
\ :<C-u>call zvim#util#BufferEmpty()<CR> \ :<C-u>call SpaceVim#mapping#BufferEmpty()<CR>
let lnum = expand('<slnum>') + s:lnum - 4 let lnum = expand('<slnum>') + s:lnum - 4
let g:_spacevim_mappings_windows.x = ['call zvim#util#BufferEmpty()', let g:_spacevim_mappings_windows.x = ['call SpaceVim#mapping#BufferEmpty()',
\ 'Empty current buffer', \ 'Empty current buffer',
\ [ \ [
\ '[WIN x] is to empty current buffer', \ '[WIN x] is to empty current buffer',

View File

@ -8,12 +8,12 @@
scriptencoding utf-8 scriptencoding utf-8
function! SpaceVim#plugins#load() abort function! SpaceVim#plugins#load() abort
if zvim#plug#enable_plug() if SpaceVim#plugins#enable_plug()
call zvim#plug#begin(g:spacevim_plugin_bundle_dir) call SpaceVim#plugins#begin(g:spacevim_plugin_bundle_dir)
call zvim#plug#fetch() call SpaceVim#plugins#fetch()
call s:load_plugins() call s:load_plugins()
call s:disable_plugins(g:spacevim_disabled_plugins) call s:disable_plugins(g:spacevim_disabled_plugins)
call zvim#plug#end() call SpaceVim#plugins#end()
endif endif
endfunction endfunction
@ -22,15 +22,15 @@ function! s:load_plugins() abort
let g:_spacevim_plugin_layer = group let g:_spacevim_plugin_layer = group
for plugin in s:getLayerPlugins(group) for plugin in s:getLayerPlugins(group)
if len(plugin) == 2 if len(plugin) == 2
call zvim#plug#add(plugin[0], plugin[1]) call SpaceVim#plugins#add(plugin[0], plugin[1])
if zvim#plug#tap(split(plugin[0], '/')[-1]) && get(plugin[1], 'loadconf', 0 ) if SpaceVim#plugins#tap(split(plugin[0], '/')[-1]) && get(plugin[1], 'loadconf', 0 )
call zvim#plug#defind_hooks(split(plugin[0], '/')[-1]) call SpaceVim#plugins#defind_hooks(split(plugin[0], '/')[-1])
endif endif
if zvim#plug#tap(split(plugin[0], '/')[-1]) && get(plugin[1], 'loadconf_before', 0 ) if SpaceVim#plugins#tap(split(plugin[0], '/')[-1]) && get(plugin[1], 'loadconf_before', 0 )
call zvim#plug#loadPluginBefore(split(plugin[0], '/')[-1]) call SpaceVim#plugins#loadPluginBefore(split(plugin[0], '/')[-1])
endif endif
else else
call zvim#plug#add(plugin[0]) call SpaceVim#plugins#add(plugin[0])
endif endif
endfor endfor
call s:loadLayerConfig(group) call s:loadLayerConfig(group)
@ -38,9 +38,9 @@ function! s:load_plugins() abort
unlet g:_spacevim_plugin_layer unlet g:_spacevim_plugin_layer
for plugin in g:spacevim_custom_plugins for plugin in g:spacevim_custom_plugins
if len(plugin) == 2 if len(plugin) == 2
call zvim#plug#add(plugin[0], plugin[1]) call SpaceVim#plugins#add(plugin[0], plugin[1])
else else
call zvim#plug#add(plugin[0]) call SpaceVim#plugins#add(plugin[0])
endif endif
endfor endfor
endfunction endfunction
@ -62,6 +62,34 @@ function! s:loadLayerConfig(layer) abort
endfunction endfunction
let s:plugins_argv = ['-update', '-openurl']
function! SpaceVim#plugins#complete_plugs(ArgLead, CmdLine, CursorPos) abort
call SpaceVim#commands#debug#completion_debug(a:ArgLead, a:CmdLine, a:CursorPos)
if a:CmdLine =~# 'Plugin\s*$' || a:ArgLead =~# '^-[a-zA-Z]*'
return join(s:plugins_argv, "\n")
endif
return join(plugins#list(), "\n")
endfunction
function! SpaceVim#plugins#Plugin(...) abort
let adds = []
let updates = []
let flag = 0
for a in a:000
if flag == 1
call add(adds, a)
elseif flag == 2
call add(updates, a)
endif
if a ==# '-update'
let flag = 1
elseif a ==# '-openurl'
let flag = 2
endif
endfor
echo string(adds) . "\n" . string(updates)
endfunction
function! s:disable_plugins(plugin_list) abort function! s:disable_plugins(plugin_list) abort
if g:spacevim_plugin_manager ==# 'dein' if g:spacevim_plugin_manager ==# 'dein'
for name in a:plugin_list for name in a:plugin_list
@ -78,4 +106,217 @@ function! SpaceVim#plugins#get(...) abort
endfunction endfunction
function! s:install_manager() abort
" Fsep && Psep
if has('win16') || has('win32') || has('win64')
let s:Psep = ';'
let s:Fsep = '\'
else
let s:Psep = ':'
let s:Fsep = '/'
endif
" auto install plugin manager
if g:spacevim_plugin_manager ==# 'neobundle'
"auto install neobundle
if filereadable(expand(g:spacevim_plugin_bundle_dir)
\ . 'neobundle.vim'. s:Fsep. 'README.md')
let g:_spacevim_neobundle_installed = 1
else
if executable('git')
exec '!git clone '
\ .'https://github.com/'
\ .'Shougo/neobundle.vim'
\ . ' '
\ . fnameescape(g:spacevim_plugin_bundle_dir)
\ . 'neobundle.vim'
let g:_spacevim_neobundle_installed = 1
else
echohl WarningMsg
echom 'You need install git!'
echohl None
endif
endif
exec 'set runtimepath+='
\ . fnameescape(g:spacevim_plugin_bundle_dir)
\ . 'neobundle.vim'
elseif g:spacevim_plugin_manager ==# 'dein'
"auto install dein
if filereadable(expand(g:spacevim_plugin_bundle_dir)
\ . join(['repos', 'github.com',
\ 'Shougo', 'dein.vim', 'README.md'],
\ s:Fsep))
let g:_spacevim_dein_installed = 1
else
if executable('git')
exec '!git clone https://github.com/Shougo/dein.vim "'
\ . expand(g:spacevim_plugin_bundle_dir)
\ . join(['repos', 'github.com',
\ 'Shougo', 'dein.vim"'], s:Fsep)
let g:_spacevim_dein_installed = 1
else
echohl WarningMsg
echom 'You need install git!'
echohl None
endif
endif
exec 'set runtimepath+='. fnameescape(g:spacevim_plugin_bundle_dir)
\ . join(['repos', 'github.com', 'Shougo',
\ 'dein.vim'], s:Fsep)
elseif g:spacevim_plugin_manager ==# 'vim-plug'
"auto install vim-plug
if filereadable(expand('~/.cache/vim-plug/autoload/plug.vim'))
let g:_spacevim_vim_plug_installed = 1
else
if executable('curl')
exec '!curl -fLo '
\ . '~/.cache/vim-plug/autoload/plug.vim'
\ . ' --create-dirs '
\ . 'https://raw.githubusercontent.com/'
\ . 'junegunn/vim-plug/master/plug.vim'
let g:_spacevim_vim_plug_installed = 1
else
echohl WarningMsg
echom 'You need install curl!'
echohl None
endif
endif
exec 'set runtimepath+=~/.cache/vim-plug/'
endif
endf
if get(g:,'spacevim_enable_plugins', 1)
call s:install_manager()
endif
function! SpaceVim#plugins#begin(path) abort
let g:unite_source_menu_menus.AddedPlugins =
\ {'description':
\ 'All the Added plugins'
\ . ' <leader>lp'}
let g:unite_source_menu_menus.AddedPlugins.command_candidates = []
if g:spacevim_plugin_manager ==# 'neobundle'
call neobundle#begin(a:path)
elseif g:spacevim_plugin_manager ==# 'dein'
call dein#begin(a:path)
elseif g:spacevim_plugin_manager ==# 'vim-plug'
call plug#begin(a:path)
endif
endfunction
function! SpaceVim#plugins#end() abort
if g:spacevim_plugin_manager ==# 'neobundle'
call neobundle#end()
if g:spacevim_checkinstall == 1
silent! let g:_spacevim_checking_flag = neobundle#exists_not_installed_bundles()
if g:_spacevim_checking_flag
augroup SpaceVimCheckInstall
au!
au VimEnter * SPInstall
augroup END
endif
endif
elseif g:spacevim_plugin_manager ==# 'dein'
call dein#end()
if g:spacevim_checkinstall == 1
silent! let g:_spacevim_checking_flag = dein#check_install()
if g:_spacevim_checking_flag
augroup SpaceVimCheckInstall
au!
au VimEnter * SPInstall
augroup END
endif
endif
call dein#call_hook('source')
elseif g:spacevim_plugin_manager ==# 'vim-plug'
call plug#end()
endif
endfunction
function! SpaceVim#plugins#defind_hooks(bundle) abort
if g:spacevim_plugin_manager ==# 'neobundle'
let s:hooks = neobundle#get_hooks(a:bundle)
func! s:hooks.on_source(bundle) abort
call SpaceVim#util#loadConfig('plugins/' . split(a:bundle['name'],'\.')[0] . '.vim')
endf
elseif g:spacevim_plugin_manager ==# 'dein'
call dein#config(g:dein#name, {
\ 'hook_source' : "call SpaceVim#util#loadConfig('plugins/" . split(g:dein#name,'\.')[0] . ".vim')"
\ })
endif
endfunction
function! SpaceVim#plugins#fetch() abort
if g:spacevim_plugin_manager ==# 'neobundle'
NeoBundleFetch 'Shougo/neobundle.vim'
elseif g:spacevim_plugin_manager ==# 'dein'
call dein#add('Shougo/dein.vim')
endif
endfunction
let s:plugins = []
fu! s:parser(args) abort
return a:args
endf
let g:_spacevim_plugins = []
function! SpaceVim#plugins#add(repo,...) abort
let g:spacevim_plugin_name = ''
if g:spacevim_plugin_manager ==# 'neobundle'
exec 'NeoBundle "'.a:repo.'"'.','.join(a:000,',')
let g:spacevim_plugin_name = split(a:repo, '/')[-1]
elseif g:spacevim_plugin_manager ==# 'dein'
if len(a:000) > 0
call dein#add(a:repo,s:parser(a:000[0]))
else
call dein#add(a:repo)
endif
let g:spacevim_plugin_name = g:dein#name
call add(g:_spacevim_plugins, g:dein#name)
elseif g:spacevim_plugin_manager ==# 'vim-plug'
if len(a:000) > 0
exec "Plug '".a:repo."', ".join(a:000,',')
else
exec "Plug '".a:repo."'"
endif
let g:spacevim_plugin_name = split(a:repo, '/')[-1]
endif
let str = get(g:,'_spacevim_plugin_layer', 'custom plugin')
let str = '[' . str . ']'
let str = str . repeat(' ', 25 - len(str))
exec 'call add(g:unite_source_menu_menus'
\ . '.AddedPlugins.command_candidates, ["'. str . '['
\ . a:repo
\ . (len(a:000) > 0 ? (']'
\ . repeat(' ', 40 - len(a:repo))
\ . '[lazy loaded] [' . string(a:000[0])) : '')
\ . ']","OpenBrowser https://github.com/'
\ . a:repo
\ . '"])'
call add(s:plugins, a:repo)
endfunction
function! SpaceVim#plugins#tap(plugin) abort
if g:spacevim_plugin_manager ==# 'neobundle'
return neobundle#tap(a:plugin)
elseif g:spacevim_plugin_manager ==# 'dein'
return dein#tap(a:plugin)
endif
endfunction
function! SpaceVim#plugins#enable_plug() abort
return g:_spacevim_neobundle_installed
\ || g:_spacevim_dein_installed
\ || g:_spacevim_vim_plug_installed
endfunction
function! SpaceVim#plugins#loadPluginBefore(plugin) abort
if matchend(a:plugin, "\\.vim") == len(a:plugin)
call SpaceVim#util#loadConfig('plugins_before/' . a:plugin)
elseif matchend(a:plugin, "\\.nvim") == len(a:plugin)
call SpaceVim#util#loadConfig('plugins_before/' . a:plugin[:-6] . '.vim')
else
call SpaceVim#util#loadConfig('plugins_before/' . a:plugin . '.vim')
endif
endfunction
" vim:set et sw=2: " vim:set et sw=2:

View File

@ -191,5 +191,24 @@ function! s:compare(d1, d2) abort
return len(split(a:d2, '/')) - len(split(a:d1, '/')) return len(split(a:d2, '/')) - len(split(a:d1, '/'))
endfunction endfunction
function! SpaceVim#plugins#projectmanager#complete_project(ArgLead, CmdLine, CursorPos) abort
call SpaceVim#commands#debug#completion_debug(a:ArgLead, a:CmdLine, a:CursorPos)
let dir = get(g:,'spacevim_src_root', '~')
"return globpath(dir, '*')
let result = split(globpath(dir, '*'), "\n")
let ps = []
for p in result
if isdirectory(p) && isdirectory(p. '\' . '.git')
call add(ps, fnamemodify(p, ':t'))
endif
endfor
return join(ps, "\n")
endfunction
function! SpaceVim#plugins#projectmanager#OpenProject(p) abort
let dir = get(g:, 'spacevim_src_root', '~') . a:p
exe 'CtrlP '. dir
endfunction
" vim:set et nowrap sw=2 cc=80: " vim:set et nowrap sw=2 cc=80:

View File

@ -6,6 +6,9 @@
" License: GPLv3 " License: GPLv3
"============================================================================= "=============================================================================
let s:SYSTEM = SpaceVim#api#import('system')
function! SpaceVim#util#globpath(path, expr) abort function! SpaceVim#util#globpath(path, expr) abort
if has('patch-7.4.279') if has('patch-7.4.279')
return globpath(a:path, a:expr, 1, 1) return globpath(a:path, a:expr, 1, 1)
@ -22,6 +25,47 @@ function! SpaceVim#util#findFileInParent(what, where) abort
return file return file
endfunction endfunction
fu! SpaceVim#util#loadConfig(file) abort
if filereadable(g:_spacevim_root_dir. '/config/' . a:file)
execute 'source ' . g:_spacevim_root_dir . '/config/' . a:file
endif
endf
fu! SpaceVim#util#check_if_expand_tab() abort
let has_noexpandtab = search('^\t','wn')
let has_expandtab = search('^ ','wn')
if has_noexpandtab && has_expandtab
let idx = inputlist ( ['ERROR: current file exists both expand and noexpand TAB, python can only use one of these two mode in one file.\nSelect Tab Expand Type:',
\ '1. expand (tab=space, recommended)',
\ '2. noexpand (tab=\t, currently have risk)',
\ '3. do nothing (I will handle it by myself)'])
let tab_space = printf('%*s',&tabstop,'')
if idx == 1
let has_noexpandtab = 0
let has_expandtab = 1
silent exec '%s/\t/' . tab_space . '/g'
elseif idx == 2
let has_noexpandtab = 1
let has_expandtab = 0
silent exec '%s/' . tab_space . '/\t/g'
else
return
endif
endif
if has_noexpandtab == 1 && has_expandtab == 0
echomsg 'substitute space to TAB...'
set noexpandtab
echomsg 'done!'
elseif has_noexpandtab == 0 && has_expandtab == 1
echomsg 'substitute TAB to space...'
set expandtab
echomsg 'done!'
else
" it may be a new file
" we use original vim setting
endif
endf
function! SpaceVim#util#findDirInParent(what, where) abort function! SpaceVim#util#findDirInParent(what, where) abort
let old_suffixesadd = &suffixesadd let old_suffixesadd = &suffixesadd
let &suffixesadd = '' let &suffixesadd = ''
@ -156,4 +200,52 @@ fu! SpaceVim#util#CopyToClipboard(...) abort
endif endif
endf endf
fu! SpaceVim#util#Generate_ignore(ignore,tool, ...) abort
let ignore = []
if a:tool ==# 'ag'
for ig in split(a:ignore,',')
call add(ignore, '--ignore')
call add(ignore, "'" . ig . "'")
endfor
elseif a:tool ==# 'rg'
for ig in split(a:ignore,',')
call add(ignore, '-g')
if get(a:000, 0, 0) == 1
call add(ignore, "'!" . ig . "'")
else
call add(ignore, '!' . ig)
endif
endfor
endif
return ignore
endf
function! SpaceVim#util#UpdateHosts(...) abort
if len(a:000) == 0
let url = get(g:,'spacevim_hosts_url', '')
else
let url = a:1
endif
let hosts = systemlist('curl -s ' . url)
if s:SYSTEM.isWindows
let local_hosts = $SystemRoot . expand('\System32\drivers\etc\hosts')
else
let local_hosts = '/etc/hosts'
endif
if writefile(hosts, local_hosts, 'a') == -1
echo 'failed!'
else
echo 'successfully!'
endif
endfunction
function! SpaceVim#util#listDirs(dir) abort
let dir = fnamemodify(a:dir, ':p')
if isdirectory(dir)
let cmd = printf('ls -F %s | grep /$', dir)
return map(systemlist(cmd), 'v:val[:-2]')
endif
return []
endfunction
" vim:set et sw=2 cc=80: " vim:set et sw=2 cc=80:

View File

@ -1,34 +0,0 @@
let s:playId = 0
fu! s:handler(id, data, event) abort
if a:event ==# 'exit'
echom 'job ' . a:id . ' exit with code:' . string(a:data)
let s:playId = 0
endif
endf
function! zvim#mpv#stop() abort
if s:playId != 0
call jobstop(s:playId)
let s:playId = 0
endif
delcommand MStop
endfunction
function! zvim#mpv#play(file,...) abort
if has('nvim')
if s:playId != 0
call jobstop(s:playId)
let s:playId = 0
endif
let s:playId = jobstart(['mpv','--vid=no',a:file],{
\ 'on_stdout': function('s:handler'),
\ 'on_stderr': function('s:handler'),
\ 'on_exit': function('s:handler'),
\ })
else
if type(s:playId) == 8 && job_status(s:playId) ==# 'run'
call job_stop(s:playId)
let s:playId =0
endif
let s:playId = job_start(['mpv','--vid=no',a:file])
endif
command! MStop call zvim#mpv#stop()
endfunction

View File

@ -1,217 +0,0 @@
let s:save_cpo = &cpo
set cpo&vim
function! s:install_manager() abort
" Fsep && Psep
if has('win16') || has('win32') || has('win64')
let s:Psep = ';'
let s:Fsep = '\'
else
let s:Psep = ':'
let s:Fsep = '/'
endif
" auto install plugin manager
if g:spacevim_plugin_manager ==# 'neobundle'
"auto install neobundle
if filereadable(expand(g:spacevim_plugin_bundle_dir)
\ . 'neobundle.vim'. s:Fsep. 'README.md')
let g:_spacevim_neobundle_installed = 1
else
if executable('git')
exec '!git clone '
\ .'https://github.com/'
\ .'Shougo/neobundle.vim'
\ . ' '
\ . fnameescape(g:spacevim_plugin_bundle_dir)
\ . 'neobundle.vim'
let g:_spacevim_neobundle_installed = 1
else
echohl WarningMsg
echom 'You need install git!'
echohl None
endif
endif
exec 'set runtimepath+='
\ . fnameescape(g:spacevim_plugin_bundle_dir)
\ . 'neobundle.vim'
elseif g:spacevim_plugin_manager ==# 'dein'
"auto install dein
if filereadable(expand(g:spacevim_plugin_bundle_dir)
\ . join(['repos', 'github.com',
\ 'Shougo', 'dein.vim', 'README.md'],
\ s:Fsep))
let g:_spacevim_dein_installed = 1
else
if executable('git')
exec '!git clone https://github.com/Shougo/dein.vim "'
\ . expand(g:spacevim_plugin_bundle_dir)
\ . join(['repos', 'github.com',
\ 'Shougo', 'dein.vim"'], s:Fsep)
let g:_spacevim_dein_installed = 1
else
echohl WarningMsg
echom 'You need install git!'
echohl None
endif
endif
exec 'set runtimepath+='. fnameescape(g:spacevim_plugin_bundle_dir)
\ . join(['repos', 'github.com', 'Shougo',
\ 'dein.vim'], s:Fsep)
elseif g:spacevim_plugin_manager ==# 'vim-plug'
"auto install vim-plug
if filereadable(expand('~/.cache/vim-plug/autoload/plug.vim'))
let g:_spacevim_vim_plug_installed = 1
else
if executable('curl')
exec '!curl -fLo '
\ . '~/.cache/vim-plug/autoload/plug.vim'
\ . ' --create-dirs '
\ . 'https://raw.githubusercontent.com/'
\ . 'junegunn/vim-plug/master/plug.vim'
let g:_spacevim_vim_plug_installed = 1
else
echohl WarningMsg
echom 'You need install curl!'
echohl None
endif
endif
exec 'set runtimepath+=~/.cache/vim-plug/'
endif
endf
if get(g:,'spacevim_enable_plugins', 1)
call s:install_manager()
endif
function! zvim#plug#begin(path) abort
let g:unite_source_menu_menus.AddedPlugins =
\ {'description':
\ 'All the Added plugins'
\ . ' <leader>lp'}
let g:unite_source_menu_menus.AddedPlugins.command_candidates = []
if g:spacevim_plugin_manager ==# 'neobundle'
call neobundle#begin(a:path)
elseif g:spacevim_plugin_manager ==# 'dein'
call dein#begin(a:path)
elseif g:spacevim_plugin_manager ==# 'vim-plug'
call plug#begin(a:path)
endif
endfunction
function! zvim#plug#end() abort
if g:spacevim_plugin_manager ==# 'neobundle'
call neobundle#end()
if g:spacevim_checkinstall == 1
silent! let g:_spacevim_checking_flag = neobundle#exists_not_installed_bundles()
if g:_spacevim_checking_flag
augroup SpaceVimCheckInstall
au!
au VimEnter * SPInstall
augroup END
endif
endif
elseif g:spacevim_plugin_manager ==# 'dein'
call dein#end()
if g:spacevim_checkinstall == 1
silent! let g:_spacevim_checking_flag = dein#check_install()
if g:_spacevim_checking_flag
augroup SpaceVimCheckInstall
au!
au VimEnter * SPInstall
augroup END
endif
endif
call dein#call_hook('source')
elseif g:spacevim_plugin_manager ==# 'vim-plug'
call plug#end()
endif
endfunction
function! zvim#plug#defind_hooks(bundle) abort
if g:spacevim_plugin_manager ==# 'neobundle'
let s:hooks = neobundle#get_hooks(a:bundle)
func! s:hooks.on_source(bundle) abort
call zvim#util#source_rc('plugins/' . split(a:bundle['name'],'\.')[0] . '.vim')
endf
elseif g:spacevim_plugin_manager ==# 'dein'
call dein#config(g:dein#name, {
\ 'hook_source' : "call zvim#util#source_rc('plugins/" . split(g:dein#name,'\.')[0] . ".vim')"
\ })
endif
endfunction
function! zvim#plug#fetch() abort
if g:spacevim_plugin_manager ==# 'neobundle'
NeoBundleFetch 'Shougo/neobundle.vim'
elseif g:spacevim_plugin_manager ==# 'dein'
call dein#add('Shougo/dein.vim')
endif
endfunction
let s:plugins = []
fu! s:parser(args) abort
return a:args
endf
let g:_spacevim_plugins = []
function! zvim#plug#add(repo,...) abort
let g:spacevim_plugin_name = ''
if g:spacevim_plugin_manager ==# 'neobundle'
exec 'NeoBundle "'.a:repo.'"'.','.join(a:000,',')
let g:spacevim_plugin_name = split(a:repo, '/')[-1]
elseif g:spacevim_plugin_manager ==# 'dein'
if len(a:000) > 0
call dein#add(a:repo,s:parser(a:000[0]))
else
call dein#add(a:repo)
endif
let g:spacevim_plugin_name = g:dein#name
call add(g:_spacevim_plugins, g:dein#name)
elseif g:spacevim_plugin_manager ==# 'vim-plug'
if len(a:000) > 0
exec "Plug '".a:repo."', ".join(a:000,',')
else
exec "Plug '".a:repo."'"
endif
let g:spacevim_plugin_name = split(a:repo, '/')[-1]
endif
let str = get(g:,'_spacevim_plugin_layer', 'custom plugin')
let str = '[' . str . ']'
let str = str . repeat(' ', 25 - len(str))
exec 'call add(g:unite_source_menu_menus'
\ . '.AddedPlugins.command_candidates, ["'. str . '['
\ . a:repo
\ . (len(a:000) > 0 ? (']'
\ . repeat(' ', 40 - len(a:repo))
\ . '[lazy loaded] [' . string(a:000[0])) : '')
\ . ']","OpenBrowser https://github.com/'
\ . a:repo
\ . '"])'
call add(s:plugins, a:repo)
endfunction
function! zvim#plug#tap(plugin) abort
if g:spacevim_plugin_manager ==# 'neobundle'
return neobundle#tap(a:plugin)
elseif g:spacevim_plugin_manager ==# 'dein'
return dein#tap(a:plugin)
endif
endfunction
function! zvim#plug#enable_plug() abort
return g:_spacevim_neobundle_installed
\ || g:_spacevim_dein_installed
\ || g:_spacevim_vim_plug_installed
endfunction
function! zvim#plug#loadPluginBefore(plugin) abort
if matchend(a:plugin, "\\.vim") == len(a:plugin)
call zvim#util#source_rc('plugins_before/' . a:plugin)
elseif matchend(a:plugin, "\\.nvim") == len(a:plugin)
call zvim#util#source_rc('plugins_before/' . a:plugin[:-6] . '.vim')
else
call zvim#util#source_rc('plugins_before/' . a:plugin . '.vim')
endif
endfunction
let &cpo = s:save_cpo
unlet s:save_cpo

View File

@ -1,204 +0,0 @@
scriptencoding utf-8
let s:SYSTEM = SpaceVim#api#import('system')
let s:save_cpo = &cpo
set cpo&vim
let g:unite_source_menu_menus =
\ get(g:,'unite_source_menu_menus',{})
let g:unite_source_menu_menus.CustomKeyMaps = {'description':
\ 'Custom mapped keyboard shortcuts [unite]<SPACE>'}
let g:unite_source_menu_menus.CustomKeyMaps.command_candidates =
\ get(g:unite_source_menu_menus.CustomKeyMaps,'command_candidates', [])
let g:unite_source_menu_menus.MyStarredrepos = {'description':
\ 'All github repos starred by me <leader>ls'}
let g:unite_source_menu_menus.MyStarredrepos.command_candidates =
\ get(g:unite_source_menu_menus.MyStarredrepos,'command_candidates', [])
let g:unite_source_menu_menus.MpvPlayer = {'description':
\ 'Musics list <leader>lm'}
let g:unite_source_menu_menus.MpvPlayer.command_candidates =
\ get(g:unite_source_menu_menus.MpvPlayer,'command_candidates', [])
fu! zvim#util#defineMap(type,key,value,desc,...) abort
exec a:type . ' ' . a:key . ' ' . a:value
let description = '➤ '
\. a:desc
\. repeat(' ', 80 - len(a:desc) - len(a:key))
\. a:key
let cmd = len(a:000) > 0 ? a:000[0] : a:value
call add(g:unite_source_menu_menus.CustomKeyMaps.command_candidates, [description,cmd])
endf
fu! zvim#util#source_rc(file) abort
if filereadable(g:_spacevim_root_dir. '/config/' . a:file)
execute 'source ' . g:_spacevim_root_dir . '/config/' . a:file
endif
endf
fu! zvim#util#SmartClose() abort
let ignorewin = get(g:,'spacevim_smartcloseignorewin',[])
let ignoreft = get(g:, 'spacevim_smartcloseignoreft',[])
let win_count = winnr('$')
let num = win_count
for i in range(1,win_count)
if index(ignorewin , bufname(winbufnr(i))) != -1 || index(ignoreft, getbufvar(bufname(winbufnr(i)),'&filetype')) != -1
let num = num - 1
elseif getbufvar(winbufnr(i),'&buftype') ==# 'quickfix'
let num = num - 1
elseif getwinvar(i, '&previewwindow') == 1 && winnr() !=# i
let num = num - 1
endif
endfor
if num == 1
else
quit
endif
endf
fu! zvim#util#check_if_expand_tab() abort
let has_noexpandtab = search('^\t','wn')
let has_expandtab = search('^ ','wn')
if has_noexpandtab && has_expandtab
let idx = inputlist ( ['ERROR: current file exists both expand and noexpand TAB, python can only use one of these two mode in one file.\nSelect Tab Expand Type:',
\ '1. expand (tab=space, recommended)',
\ '2. noexpand (tab=\t, currently have risk)',
\ '3. do nothing (I will handle it by myself)'])
let tab_space = printf('%*s',&tabstop,'')
if idx == 1
let has_noexpandtab = 0
let has_expandtab = 1
silent exec '%s/\t/' . tab_space . '/g'
elseif idx == 2
let has_noexpandtab = 1
let has_expandtab = 0
silent exec '%s/' . tab_space . '/\t/g'
else
return
endif
endif
if has_noexpandtab == 1 && has_expandtab == 0
echomsg 'substitute space to TAB...'
set noexpandtab
echomsg 'done!'
elseif has_noexpandtab == 0 && has_expandtab == 1
echomsg 'substitute TAB to space...'
set expandtab
echomsg 'done!'
else
" it may be a new file
" we use original vim setting
endif
endf
function! zvim#util#BufferEmpty() abort
let l:current = bufnr('%')
if ! getbufvar(l:current, '&modified')
enew
silent! execute 'bdelete '.l:current
endif
endfunction
function! zvim#util#loadMusics() abort
let musics = SpaceVim#util#globpath('~/Musics', '*.mp3')
let g:unite_source_menu_menus.MpvPlayer.command_candidates = []
for m in musics
call add(g:unite_source_menu_menus.MpvPlayer.command_candidates,
\ [fnamemodify(m, ':t'),
\ "call zvim#mpv#play('" . m . "')"])
endfor
endfunction
function! zvim#util#listDirs(dir) abort
let dir = fnamemodify(a:dir, ':p')
if isdirectory(dir)
let cmd = printf('ls -F %s | grep /$', dir)
return map(systemlist(cmd), 'v:val[:-2]')
endif
return []
endfunction
let s:plugins_argv = ['-update', '-openurl']
function! zvim#util#complete_plugs(ArgLead, CmdLine, CursorPos) abort
call zvim#debug#completion_debug(a:ArgLead, a:CmdLine, a:CursorPos)
if a:CmdLine =~# 'Plugin\s*$' || a:ArgLead =~# '^-[a-zA-Z]*'
return join(s:plugins_argv, "\n")
endif
return join(plugins#list(), "\n")
endfunction
function! zvim#util#Plugin(...) abort
let adds = []
let updates = []
let flag = 0
for a in a:000
if flag == 1
call add(adds, a)
elseif flag == 2
call add(updates, a)
endif
if a ==# '-update'
let flag = 1
elseif a ==# '-openurl'
let flag = 2
endif
endfor
echo string(adds) . "\n" . string(updates)
endfunction
function! zvim#util#complete_project(ArgLead, CmdLine, CursorPos) abort
call zvim#debug#completion_debug(a:ArgLead, a:CmdLine, a:CursorPos)
let dir = get(g:,'spacevim_src_root', '~')
"return globpath(dir, '*')
let result = split(globpath(dir, '*'), "\n")
let ps = []
for p in result
if isdirectory(p) && isdirectory(p. '\' . '.git')
call add(ps, fnamemodify(p, ':t'))
endif
endfor
return join(ps, "\n")
endfunction
function! zvim#util#OpenProject(p) abort
let dir = get(g:, 'spacevim_src_root', '~') . a:p
exe 'CtrlP '. dir
endfunction
function! zvim#util#UpdateHosts(...) abort
if len(a:000) == 0
let url = get(g:,'spacevim_hosts_url', '')
else
let url = a:1
endif
let hosts = systemlist('curl -s ' . url)
if s:SYSTEM.isWindows
let local_hosts = $SystemRoot . expand('\System32\drivers\etc\hosts')
else
let local_hosts = '/etc/hosts'
endif
if writefile(hosts, local_hosts, 'a') == -1
echo 'failed!'
else
echo 'successfully!'
endif
endfunction
fu! zvim#util#Generate_ignore(ignore,tool, ...) abort
let ignore = []
if a:tool ==# 'ag'
for ig in split(a:ignore,',')
call add(ignore, '--ignore')
call add(ignore, "'" . ig . "'")
endfor
elseif a:tool ==# 'rg'
for ig in split(a:ignore,',')
call add(ignore, '-g')
if get(a:000, 0, 0) == 1
call add(ignore, "'!" . ig . "'")
else
call add(ignore, '!' . ig)
endif
endfor
endif
return ignore
endf
let &cpo = s:save_cpo
unlet s:save_cpo

View File

@ -3,9 +3,9 @@
" defined already. " defined already.
command! DiffOrig vert new | set bt=nofile | r # | 0d_ | diffthis command! DiffOrig vert new | set bt=nofile | r # | 0d_ | diffthis
\ | wincmd p | diffthis \ | wincmd p | diffthis
command! -nargs=* -complete=custom,zvim#util#complete_plugs Plugin :call zvim#util#Plugin(<f-args>) command! -nargs=* -complete=custom,SpaceVim#plugins#complete_plugs Plugin :call SpaceVim#plugins#Plugin(<f-args>)
"command for open project "command for open project
command! -nargs=+ -complete=custom,zvim#util#complete_project OpenProject :call zvim#util#OpenProject(<f-args>) command! -nargs=+ -complete=custom,SpaceVim#plugins#projectmanager#complete_project OpenProject :call SpaceVim#plugins#projectmanager#OpenProject(<f-args>)
command! -nargs=* -complete=custom,SpaceVim#plugins#pmd#complete PMD :call SpaceVim#plugins#pmd#run(<f-args>) command! -nargs=* -complete=custom,SpaceVim#plugins#pmd#complete PMD :call SpaceVim#plugins#pmd#run(<f-args>)

View File

@ -55,13 +55,8 @@ if has('nvim')
else else
let &rtp = g:_spacevim_root_dir . ',' . $VIMRUNTIME let &rtp = g:_spacevim_root_dir . ',' . $VIMRUNTIME
endif endif
try
call SpaceVim#begin() call SpaceVim#begin()
catch
" Update the rtp only when SpaceVim is not contained in runtimepath.
let &runtimepath .= ',' . fnamemodify(g:_spacevim_root_dir, ':p:h')
call SpaceVim#begin()
endtry
call SpaceVim#custom#load() call SpaceVim#custom#load()

View File

@ -20,9 +20,9 @@ let g:ctrlp_custom_ignore = get(g:, 'ctrlp_custom_ignore', {
\ }) \ })
if executable('rg') && !exists('g:ctrlp_user_command') if executable('rg') && !exists('g:ctrlp_user_command')
let g:ctrlp_user_command = 'rg %s --no-ignore --hidden --files -g "" ' let g:ctrlp_user_command = 'rg %s --no-ignore --hidden --files -g "" '
\ . join(zvim#util#Generate_ignore(get(g:, 'spacevim_wildignore', ''),'rg', SpaceVim#api#import('system').isWindows ? 0 : 1)) \ . join(SpaceVim#util#Generate_ignore(get(g:, 'spacevim_wildignore', ''),'rg', SpaceVim#api#import('system').isWindows ? 0 : 1))
elseif executable('ag') && !exists('g:ctrlp_user_command') elseif executable('ag') && !exists('g:ctrlp_user_command')
let g:ctrlp_user_command = 'ag --hidden -i -g "" ' . join(zvim#util#Generate_ignore(g:spacevim_wildignore,'ag')) . ' %s' let g:ctrlp_user_command = 'ag --hidden -i -g "" ' . join(SpaceVim#util#Generate_ignore(g:spacevim_wildignore,'ag')) . ' %s'
elseif s:SYS.isWindows elseif s:SYS.isWindows
let g:ctrlp_user_command = let g:ctrlp_user_command =
\ 'dir %s /-n /b /s /a-d | findstr /v /l ".jpg \\tmp\\"' " Windows \ 'dir %s /-n /b /s /a-d | findstr /v /l ".jpg \\tmp\\"' " Windows

View File

@ -38,13 +38,13 @@ if !s:sys.isWindows
" Note: It is slower than ag " Note: It is slower than ag
call denite#custom#var('file/rec', 'command', call denite#custom#var('file/rec', 'command',
\ ['rg', '--hidden', '--files', '--glob', '!.git', '--glob', ''] \ ['rg', '--hidden', '--files', '--glob', '!.git', '--glob', '']
\ + zvim#util#Generate_ignore(g:spacevim_wildignore, 'rg') \ + SpaceVim#util#Generate_ignore(g:spacevim_wildignore, 'rg')
\ ) \ )
elseif executable('ag') elseif executable('ag')
" Change file/rec command. " Change file/rec command.
call denite#custom#var('file/rec', 'command', call denite#custom#var('file/rec', 'command',
\ ['ag' , '--nocolor', '--nogroup', '-g', ''] \ ['ag' , '--nocolor', '--nogroup', '-g', '']
\ + zvim#util#Generate_ignore(g:spacevim_wildignore, 'ag') \ + SpaceVim#util#Generate_ignore(g:spacevim_wildignore, 'ag')
\ ) \ )
endif endif
else else

View File

@ -259,7 +259,9 @@ function! s:view_github_starred_repos() abort
Unite -silent -ignorecase -winheight=17 -start-insert menu:MyStarredrepos Unite -silent -ignorecase -winheight=17 -start-insert menu:MyStarredrepos
endif endif
endfunction endfunction
call zvim#util#loadMusics() if SpaceVim#layers#isLoaded('tools#mpv')
call SpaceVim#layers#tools#mpv#loadMusics()
endif
augroup unite_buffer_feature augroup unite_buffer_feature
autocmd FileType unite call s:unite_my_settings() autocmd FileType unite call s:unite_my_settings()
augroup END augroup END

View File

@ -1,5 +1,9 @@
Execute ( SpaceVim api: SpaceVim main code ): Execute ( SpaceVim api: SpaceVim main code ):
unlock g:_spacevim_root_dir unlock g:_spacevim_root_dir
if has('nvim')
source init.vim source init.vim
else
source vimrc
endif
SPInstall SPInstall
AssertEqual fnamemodify(g:_spacevim_root_dir, ':.'), '' AssertEqual fnamemodify(g:_spacevim_root_dir, ':.'), ''