From e68fb5f706d617af6ea4faf3ed4df8a6a380730c Mon Sep 17 00:00:00 2001 From: wsdjeg Date: Fri, 28 Jul 2017 05:22:12 +0800 Subject: [PATCH] Improve shell layer --- autoload/SpaceVim/layers.vim | 6 +++- autoload/SpaceVim/layers/shell.vim | 32 +++++++++++++++++ doc/SpaceVim.txt | 5 ++- docs/layers/index.md | 25 +++++++------- docs/layers/shell.md | 55 ++++++++++++++++++++++++++++++ 5 files changed, 109 insertions(+), 14 deletions(-) create mode 100644 docs/layers/shell.md diff --git a/autoload/SpaceVim/layers.vim b/autoload/SpaceVim/layers.vim index ef85e5cd9..736499758 100644 --- a/autoload/SpaceVim/layers.vim +++ b/autoload/SpaceVim/layers.vim @@ -5,14 +5,18 @@ "" " Load the {layer} you want. For all the layers SpaceVim supports, see @section(layers). +" the second argv is the layer variable. function! SpaceVim#layers#load(layer, ...) abort if a:layer == '-l' call s:list_layers() endif if index(g:spacevim_plugin_groups, a:layer) == -1 call add(g:spacevim_plugin_groups, a:layer) + if a:0 == 1 && type(a:1) == 4 + call SpaceVim#layers#{a:layer}#set_variable(a:1) + endif endif - if a:0 > 1 + if a:0 > 0 && type(a:1) == 1 for l in a:000 call SpaceVim#layers#load(l) endfor diff --git a/autoload/SpaceVim/layers/shell.vim b/autoload/SpaceVim/layers/shell.vim index 487fd17b9..523dba2be 100644 --- a/autoload/SpaceVim/layers/shell.vim +++ b/autoload/SpaceVim/layers/shell.vim @@ -3,6 +3,9 @@ " @parentsection layers " SpaceVim uses deol.nvim for shell support in neovim and uses vimshell for " vim. For more info, read |deol| and |vimshell|. +" @subsection variable +" default_shell +" function! SpaceVim#layers#shell#plugins() abort let plugins = [] @@ -13,3 +16,32 @@ function! SpaceVim#layers#shell#plugins() abort endif return plugins endfunction + +function! SpaceVim#layers#shell#config() + + call SpaceVim#mapping#space#def('nnoremap', ["'"], 'call call(' + \ . string(function('s:open_default_shell')) . ', [])', + \ 'open shell', 1) + +endfunction + +function! SpaceVim#layers#shell#set_variable(var) + let s:default_shell = get(a:var, 'defaut_shell', 'terminal') + let s:default_position = get(a:var, 'default_position', 'top') + let s:default_height = get(a:var, 'default_height', 30) +endfunction + + +function! s:open_default_shell() abort + 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 +endfunction diff --git a/doc/SpaceVim.txt b/doc/SpaceVim.txt index 3e16be40a..8edca69d6 100644 --- a/doc/SpaceVim.txt +++ b/doc/SpaceVim.txt @@ -414,7 +414,7 @@ FUNCTIONS *SpaceVim-functions* SpaceVim#layers#load({layer}) *SpaceVim#layers#load()* Load the {layer} you want. For all the layers SpaceVim supports, see - |SpaceVim-layers|. + |SpaceVim-layers|. the second argv is the layer variable. SpaceVim#logger#setLevel({level}) *SpaceVim#logger#setLevel()* Set debug level of SpaceVim. Default is 1. @@ -922,6 +922,9 @@ SHELL *SpaceVim-layer-shell* SpaceVim uses deol.nvim for shell support in neovim and uses vimshell for vim. For more info, read |deol| and |vimshell|. +VARIABLE +default_shell + ============================================================================== TMUX *SpaceVim-layer-tmux* diff --git a/docs/layers/index.md b/docs/layers/index.md index e90b2b059..6f1c3e5b6 100644 --- a/docs/layers/index.md +++ b/docs/layers/index.md @@ -1,14 +1,15 @@ # SpaceVim Layers -Name | Description | Documentation ------ |:----:| ------------------ -default | better default for vim and neovim | [documentation](https://spacevim.org/layers/default) -checkers | checking in vim | [documentation](https://spacevim.org/layers/checkers) -autocomplete | autocomplete in vim | [documentation](https://spacevim.org/layers/autocomplete) -chinese | layer for chinese vimer | [documentation](https://spacevim.org/layers/chinese) -colorscheme | all colorscheme in spacevim | [documentation](https://spacevim.org/layers/colorscheme) -chat | chatting in vim | [documentation](https://spacevim.org/layers/chat) -lang#java | java development in vim | [documentation](https://spacevim.org/layers/lang/java) -lang#lisp | lisp development in vim | [documentation](https://spacevim.org/layers/lang/lisp) -lang#markdown | layer for editing markdown in vim | [documentation](https://spacevim.org/layers/lang/markdown) -lang#php | php development in vim | [documentation](https://spacevim.org/layers/lang/php) +| Name | Description | Documentation | +| ------------- | :-------------------------------: | ---------------------------------------------------------- | +| default | better default for vim and neovim | [documentation](https://spacevim.org/layers/default) | +| shell | shell support for SpaceVim | [documentation](https://spacevim.org/layers/shell) | +| checkers | checking in vim | [documentation](https://spacevim.org/layers/checkers) | +| autocomplete | autocomplete in vim | [documentation](https://spacevim.org/layers/autocomplete) | +| chinese | layer for chinese vimer | [documentation](https://spacevim.org/layers/chinese) | +| colorscheme | all colorscheme in spacevim | [documentation](https://spacevim.org/layers/colorscheme) | +| chat | chatting in vim | [documentation](https://spacevim.org/layers/chat) | +| lang#java | java development in vim | [documentation](https://spacevim.org/layers/lang/java) | +| lang#lisp | lisp development in vim | [documentation](https://spacevim.org/layers/lang/lisp) | +| lang#markdown | layer for editing markdown in vim | [documentation](https://spacevim.org/layers/lang/markdown) | +| lang#php | php development in vim | [documentation](https://spacevim.org/layers/lang/php) | diff --git a/docs/layers/shell.md b/docs/layers/shell.md new file mode 100644 index 000000000..1e3ed3f04 --- /dev/null +++ b/docs/layers/shell.md @@ -0,0 +1,55 @@ +--- +title: "SpaceVim shell layer" +--- + +# [SpaceVim Layers:](https://spacevim.org/layers) shell + + +* [Description](#description) +* [Install](#install) +* [Configuration](#configuration) + * [Default shell](#default-shell) + * [Default shell position and height](#default-shell-position-and-height) +* [Key bindings](#key-bindings) + + + +## Description + +This layer provide shell support in SpaceVim. + +## Install + +To use this configuration layer, add `SPLayer 'shell'` to your custom configuration file. + +## Configuration + +### Default shell + +Vim support these kinds of shell: + +To define the default shell you can set the layer variable `default_shell` to the following variables: + +- terminal +- VimShell + +The default shell is quickly accessible via a the default shortcut key `SPC '`. + +### Default shell position and height + +It is possible to choose where the shell should pop up by setting the variable `default_position` to either `top`, `bottom`, `left`, `right`, or `full`. Default value is `top`. It is also possible to set the default height in percents with the variable `default_height`. Default value is 30. + +```vim +call SpaceVim#layers#load('shell', + \ { + \ 'default_position' : 'top', + \ 'default_height' : 30, + \ } + \ ) +``` + +## Key bindings + +| Key Binding | Description | +| ----------- | -------------------------------------- | +| `SPC '` | Open, close or go to the default shell |