From 24da07159ad31300300d5bbba608d24f50aa8977 Mon Sep 17 00:00:00 2001
From: Wang Shidong <wsdjeg@outlook.com>
Date: Sat, 7 Dec 2019 16:04:55 +0800
Subject: [PATCH] Add git plugin (#3244)

---
 autoload/SpaceVim/layers/core/statusline.vim |  9 +++++
 autoload/SpaceVim/layers/git.vim             | 42 ++++++++++++--------
 autoload/SpaceVim/layers/lang/elm.vim        | 32 ++++++++++++---
 doc/SpaceVim.txt                             | 29 ++++++++++++--
 4 files changed, 86 insertions(+), 26 deletions(-)

diff --git a/autoload/SpaceVim/layers/core/statusline.vim b/autoload/SpaceVim/layers/core/statusline.vim
index e671b2828..b62dbc889 100644
--- a/autoload/SpaceVim/layers/core/statusline.vim
+++ b/autoload/SpaceVim/layers/core/statusline.vim
@@ -386,6 +386,15 @@ function! SpaceVim#layers#core#statusline#get(...) abort
       let st .= '%#SpaceVim_statusline_c# %{b:_spacevim_shell} %#SpaceVim_statusline_c_SpaceVim_statusline_z#' . s:lsep
     endif
     return st
+  elseif &filetype ==# 'git-status'
+    return '%#SpaceVim_statusline_ia#' . s:winnr(1) . '%#SpaceVim_statusline_ia_SpaceVim_statusline_b#' . s:lsep
+          \ . '%#SpaceVim_statusline_b# Git status %#SpaceVim_statusline_b_SpaceVim_statusline_c#' . s:lsep . ' '
+  elseif &filetype ==# 'git-commit'
+    return '%#SpaceVim_statusline_ia#' . s:winnr(1) . '%#SpaceVim_statusline_ia_SpaceVim_statusline_b#' . s:lsep
+          \ . '%#SpaceVim_statusline_b# Git commit %#SpaceVim_statusline_b_SpaceVim_statusline_c#' . s:lsep . ' '
+  elseif &filetype ==# 'git-diff'
+    return '%#SpaceVim_statusline_ia#' . s:winnr(1) . '%#SpaceVim_statusline_ia_SpaceVim_statusline_b#' . s:lsep
+          \ . '%#SpaceVim_statusline_b# Git diff %#SpaceVim_statusline_b_SpaceVim_statusline_c#' . s:lsep . ' '
   elseif &filetype ==# 'gina-status'
     return '%#SpaceVim_statusline_ia#' . s:winnr(1) . '%#SpaceVim_statusline_ia_SpaceVim_statusline_b#' . s:lsep
           \ . '%#SpaceVim_statusline_b# Gina status %#SpaceVim_statusline_b_SpaceVim_statusline_c#' . s:lsep . ' '
diff --git a/autoload/SpaceVim/layers/git.vim b/autoload/SpaceVim/layers/git.vim
index 76da8ab16..8785f0486 100644
--- a/autoload/SpaceVim/layers/git.vim
+++ b/autoload/SpaceVim/layers/git.vim
@@ -11,11 +11,7 @@
 " s:git_plugin which plugin is used as the background plugin in git layer
 
 
-if has('patch-8.0.0027') || has('nvim')
-  let s:git_plugin = 'gina'
-else
-  let s:git_plugin = 'gita'
-endif
+let s:git_plugin = 'git'
 
 
 
@@ -23,14 +19,16 @@ function! SpaceVim#layers#git#plugins() abort
   let plugins = [
         \ ['junegunn/gv.vim',      { 'on_cmd' : ['GV']}],
         \ ]
-  call add(plugins, ['tpope/vim-fugitive',   { 'merged' : 0}])
   call add(plugins, ['airblade/vim-gitgutter',   { 'merged' : 0}])
   if s:git_plugin ==# 'gina'
     call add(plugins, ['lambdalisue/gina.vim', { 'on_cmd' : 'Gina'}])
   elseif s:git_plugin ==# 'fugitive'
+    call add(plugins, ['tpope/vim-fugitive',   { 'merged' : 0}])
     call add(plugins, ['tpope/vim-dispatch', { 'merged' : 0}])
-  else
+  elseif s:git_plugin ==# 'gita'
     call add(plugins, ['lambdalisue/vim-gita', { 'on_cmd' : 'Gita'}])
+  else
+    call add(plugins, ['wsdjeg/git.vim', { 'on_cmd' : 'Git'}])
   endif
   if g:spacevim_filemanager ==# 'nerdtree'
     call add(plugins, ['Xuyuanp/nerdtree-git-plugin', {'merged' : 0}])
@@ -60,7 +58,8 @@ function! SpaceVim#layers#git#config() abort
     call SpaceVim#mapping#space#def('nnoremap', ['g', 'd'], 'Gdiff', 'view-git-diff', 1)
     call SpaceVim#mapping#space#def('nnoremap', ['g', 'A'], 'Git add .', 'stage-all-files', 1)
     call SpaceVim#mapping#space#def('nnoremap', ['g', 'b'], 'Gblame', 'view-git-blame', 1)
-  else
+  elseif s:git_plugin ==# 'gita'
+    let g:gita#suppress_warning = 1
     call SpaceVim#mapping#space#def('nnoremap', ['g', 's'], 'Gita status', 'git-status', 1)
     call SpaceVim#mapping#space#def('nnoremap', ['g', 'S'], 'Gita add %', 'stage-current-file', 1)
     call SpaceVim#mapping#space#def('nnoremap', ['g', 'U'], 'Gita reset %', 'unstage-current-file', 1)
@@ -69,6 +68,15 @@ function! SpaceVim#layers#git#config() abort
     call SpaceVim#mapping#space#def('nnoremap', ['g', 'd'], 'Gita diff', 'view-git-diff', 1)
     call SpaceVim#mapping#space#def('nnoremap', ['g', 'A'], 'Gita add .', 'stage-all-files', 1)
     call SpaceVim#mapping#space#def('nnoremap', ['g', 'b'], 'Gina blame', 'view-git-blame', 1)
+  else
+    call SpaceVim#mapping#space#def('nnoremap', ['g', 's'], 'Git status', 'git-status', 1)
+    call SpaceVim#mapping#space#def('nnoremap', ['g', 'S'], 'Git add %', 'stage-current-file', 1)
+    call SpaceVim#mapping#space#def('nnoremap', ['g', 'U'], 'Git reset %', 'unstage-current-file', 1)
+    call SpaceVim#mapping#space#def('nnoremap', ['g', 'c'], 'Git commit', 'edit-git-commit', 1)
+    call SpaceVim#mapping#space#def('nnoremap', ['g', 'p'], 'Git push', 'git-push', 1)
+    call SpaceVim#mapping#space#def('nnoremap', ['g', 'd'], 'Git diff', 'view-git-diff', 1)
+    call SpaceVim#mapping#space#def('nnoremap', ['g', 'A'], 'Git add .', 'stage-all-files', 1)
+    call SpaceVim#mapping#space#def('nnoremap', ['g', 'b'], 'Git blame', 'view-git-blame', 1)
   endif
   augroup spacevim_layer_git
     autocmd!
@@ -85,16 +93,16 @@ function! SpaceVim#layers#git#config() abort
   call SpaceVim#mapping#space#def('nnoremap', ['g', 'V'], 'GV!', 'git-log-of-current-file', 1)
   call SpaceVim#mapping#space#def('nnoremap', ['g', 'v'], 'GV', 'git-log-of-current-repo', 1)
 
-	if !exists('g:_spacevim_mappings_space.g.h')
-		let g:_spacevim_mappings_space.g.h = {'name' : ''}
-	endif
-	let l:h_submenu_name = SpaceVim#layers#isLoaded('github') ? '+GitHub/Hunks' : '+Hunks'
-	let g:_spacevim_mappings_space.g.h['name'] = l:h_submenu_name
+  if !exists('g:_spacevim_mappings_space.g.h')
+    let g:_spacevim_mappings_space.g.h = {'name' : ''}
+  endif
+  let l:h_submenu_name = SpaceVim#layers#isLoaded('github') ? '+GitHub/Hunks' : '+Hunks'
+  let g:_spacevim_mappings_space.g.h['name'] = l:h_submenu_name
 
-	let l:stage_hunk_key = SpaceVim#layers#isLoaded('github') ? 's' : 'a'
-	call SpaceVim#mapping#space#def('nmap', ['g', 'h', l:stage_hunk_key], '<Plug>(GitGutterStageHunk)', 'stage-current-hunk', 0)
-	call SpaceVim#mapping#space#def('nmap', ['g', 'h', 'r'], '<Plug>(GitGutterUndoHunk)', 'undo-cursor-hunk', 0)
-	call SpaceVim#mapping#space#def('nmap', ['g', 'h', 'v'], '<Plug>(GitGutterPreviewHunk)', 'preview-cursor-hunk', 0)
+  let l:stage_hunk_key = SpaceVim#layers#isLoaded('github') ? 's' : 'a'
+  call SpaceVim#mapping#space#def('nmap', ['g', 'h', l:stage_hunk_key], '<Plug>(GitGutterStageHunk)', 'stage-current-hunk', 0)
+  call SpaceVim#mapping#space#def('nmap', ['g', 'h', 'r'], '<Plug>(GitGutterUndoHunk)', 'undo-cursor-hunk', 0)
+  call SpaceVim#mapping#space#def('nmap', ['g', 'h', 'v'], '<Plug>(GitGutterPreviewHunk)', 'preview-cursor-hunk', 0)
 endfunction
 
 function! SpaceVim#layers#git#set_variable(var) abort
diff --git a/autoload/SpaceVim/layers/lang/elm.vim b/autoload/SpaceVim/layers/lang/elm.vim
index 7d88e73a5..afa08364c 100644
--- a/autoload/SpaceVim/layers/lang/elm.vim
+++ b/autoload/SpaceVim/layers/lang/elm.vim
@@ -9,11 +9,31 @@
 ""
 " @section lang#elm, layer-lang-elm
 " @parentsection layers
-" @subsection Intro
-" The lang#elm layer provides code completion, documentation lookup, jump to
-" definition, mix integration, and iex integration for elm. SpaceVim
-" uses neomake as default syntax checker which is loaded in
-" @section(layer-checkers)
+" This layer is for elm development, disabled by default, to enable this
+" layer, add following snippet to your SpaceVim configuration file.
+" >
+"   [[layers]]
+"     name = 'lang#elm'
+" <
+"
+" @subsection Key bindings
+" >
+"   Mode            Key             Function
+"   ---------------------------------------------
+"   normal          SPC l r         run current file
+" <
+"
+" This layer also provides REPL support for elm, the key bindings are:
+" >
+"   Key             Function
+"   ---------------------------------------------
+"   SPC l s i       Start a inferior REPL process
+"   SPC l s b       send whole buffer
+"   SPC l s l       send current line
+"   SPC l s s       send selection text
+" <
+"
+
 
 function! SpaceVim#layers#lang#elm#plugins() abort
   let plugins = []
@@ -24,10 +44,12 @@ endfunction
 
 function! SpaceVim#layers#lang#elm#config() abort
   call SpaceVim#plugins#repl#reg('elm', 'elm repl')
+  call SpaceVim#plugins#runner#reg_runner('elm', 'elm %s')
   call SpaceVim#mapping#space#regesit_lang_mappings('elm', function('s:language_specified_mappings'))
 endfunction
 
 function! s:language_specified_mappings() abort
+  call SpaceVim#mapping#space#langSPC('nmap', ['l','r'], 'call SpaceVim#plugins#runner#open()', 'execute current file', 1)
   let g:_spacevim_mappings_space.l.s = {'name' : '+Send'}
   call SpaceVim#mapping#space#langSPC('nmap', ['l','s', 'i'],
         \ 'call SpaceVim#plugins#repl#start("elm")',
diff --git a/doc/SpaceVim.txt b/doc/SpaceVim.txt
index 1288fe086..e9dfb53e5 100644
--- a/doc/SpaceVim.txt
+++ b/doc/SpaceVim.txt
@@ -1583,10 +1583,31 @@ This layer also provides REPL support for d, the key bindings are:
 ==============================================================================
 LANG#ELM                                             *SpaceVim-layer-lang-elm*
 
-INTRO
-The lang#elm layer provides code completion, documentation lookup, jump to
-definition, mix integration, and iex integration for elm. SpaceVim uses
-neomake as default syntax checker which is loaded in |SpaceVim-layer-checkers|
+This layer is for elm development, disabled by default, to enable this layer,
+add following snippet to your SpaceVim configuration file.
+>
+  [[layers]]
+    name = 'lang#elm'
+<
+
+KEY BINDINGS
+
+>
+  Mode            Key             Function
+  ---------------------------------------------
+  normal          SPC l r         run current file
+<
+
+This layer also provides REPL support for elm, the key bindings are:
+>
+  Key             Function
+  ---------------------------------------------
+  SPC l s i       Start a inferior REPL process
+  SPC l s b       send whole buffer
+  SPC l s l       send current line
+  SPC l s s       send selection text
+<
+
 
 ==============================================================================
 LANG#ERLANG                                       *SpaceVim-layer-lang-erlang*