From 7910b14e849361b6cd5035d21dfd804236fa2a2d Mon Sep 17 00:00:00 2001 From: wsdjeg Date: Mon, 23 Oct 2017 21:02:54 +0800 Subject: [PATCH] Fix shell layer --- autoload/SpaceVim/layers/shell.vim | 113 +++++++++++++++-------------- 1 file changed, 59 insertions(+), 54 deletions(-) diff --git a/autoload/SpaceVim/layers/shell.vim b/autoload/SpaceVim/layers/shell.vim index 914f7ec0f..8322c5a5e 100644 --- a/autoload/SpaceVim/layers/shell.vim +++ b/autoload/SpaceVim/layers/shell.vim @@ -8,72 +8,77 @@ " function! SpaceVim#layers#shell#plugins() abort - let plugins = [] - if has('nvim') - call add(plugins,['Shougo/deol.nvim']) - endif - call add(plugins,['Shougo/vimshell.vim', { 'on_cmd':['VimShell']}]) - return plugins + let plugins = [] + if has('nvim') + call add(plugins,['Shougo/deol.nvim']) + endif + call add(plugins,['Shougo/vimshell.vim', { 'on_cmd':['VimShell']}]) + return plugins endfunction let s:file = expand(':~') let s:lnum = expand('') + 2 function! SpaceVim#layers#shell#config() abort - call SpaceVim#mapping#space#def('nnoremap', ["'"], 'call call(' - \ . string(function('s:open_default_shell')) . ', [])', - \ ['open shell', - \ [ - \ "[SPC '] is to open or jump to default shell window", - \ '', - \ 'Definition: ' . s:file . ':' . s:lnum, - \ ] - \ ], 1) + call SpaceVim#mapping#space#def('nnoremap', ["'"], 'call call(' + \ . string(function('s:open_default_shell')) . ', [])', + \ ['open shell', + \ [ + \ "[SPC '] is to open or jump to default shell window", + \ '', + \ 'Definition: ' . s:file . ':' . s:lnum, + \ ] + \ ], 1) endfunction + +let s:default_shell = 'terminal' +let s:default_position = 'top' +let s:default_height = 30 + function! SpaceVim#layers#shell#set_variable(var) abort - let s:default_shell = get(a:var, 'default_shell', 'terminal') - let s:default_position = get(a:var, 'default_position', 'top') - let s:default_height = get(a:var, 'default_height', 30) + let s:default_shell = get(a:var, 'default_shell', 'terminal') + let s:default_position = get(a:var, 'default_position', 'top') + let s:default_height = get(a:var, 'default_height', 30) endfunction let s:shell_win_nr = 0 function! s:open_default_shell() abort - if s:shell_win_nr != 0 && getwinvar(s:shell_win_nr, '&buftype') ==# 'terminal' && &buftype !=# 'terminal' - exe s:shell_win_nr . 'wincmd w' - startinsert - return - endif - if &buftype ==# 'terminal' - bwipeout! % - return - endif - let cmd = s:default_position ==# 'top' ? - \ 'topleft split' : - \ s:default_position ==# 'bottom' ? - \ 'botright split' : - \ s:default_position ==# 'right' ? - \ 'rightbelow vsplit' : 'leftabove vsplit' - exe cmd - let lines = &lines * s:default_height / 100 - if lines < winheight(0) && (s:default_position ==# 'top' || s:default_position ==# 'bottom') - exe 'resize ' . lines - endif - if s:default_shell ==# 'terminal' - if exists(':terminal') - if has('nvim') - exe 'terminal' - else - call term_start('bash', {'curwin' : 1, 'term_finish' : 'close'}) - endif - let s:shell_win_nr = winnr() - let w:shell_layer_win = 1 - startinsert - else - echo ':terminal is not supported in this version' - endif - elseif s:default_shell ==# 'VimShell' - VimShell - imap exit(vimshell_enter) + if s:shell_win_nr != 0 && getwinvar(s:shell_win_nr, '&buftype') ==# 'terminal' && &buftype !=# 'terminal' + exe s:shell_win_nr . 'wincmd w' + startinsert + return + endif + if &buftype ==# 'terminal' + bwipeout! % + return + endif + let cmd = s:default_position ==# 'top' ? + \ 'topleft split' : + \ s:default_position ==# 'bottom' ? + \ 'botright split' : + \ s:default_position ==# 'right' ? + \ 'rightbelow vsplit' : 'leftabove vsplit' + exe cmd + let lines = &lines * s:default_height / 100 + if lines < winheight(0) && (s:default_position ==# 'top' || s:default_position ==# 'bottom') + exe 'resize ' . lines + endif + if s:default_shell ==# 'terminal' + if exists(':terminal') + if has('nvim') + exe 'terminal' + else + call term_start('bash', {'curwin' : 1, 'term_finish' : 'close'}) + endif + let s:shell_win_nr = winnr() + let w:shell_layer_win = 1 + startinsert + else + echo ':terminal is not supported in this version' endif + elseif s:default_shell ==# 'VimShell' + VimShell + imap exit(vimshell_enter) + endif endfunction