Add commands to enable/disable/toggle GitGutter per buffer.

This commit is contained in:
Andy Stewart
2019-01-08 12:47:10 +00:00
parent b11d74ca8f
commit 2dce8e032b
4 changed files with 33 additions and 1 deletions

View File

@@ -17,7 +17,7 @@ Features:
* Handles line endings correctly, even with repos that do CRLF conversion.
* Optional line highlighting.
* Fully customisable (signs, sign column, line highlights, mappings, extra git-diff arguments, etc).
* Can be toggled on/off.
* Can be toggled on/off, globally or per buffer.
* Preserves signs from other plugins.
* Easy to integrate diff stats into status line; built-in integration with [vim-airline](https://github.com/bling/vim-airline/).
* Works with fish shell (in addition to the usual shells).
@@ -119,6 +119,12 @@ You can explicitly turn vim-gitgutter off and on (defaults to on):
* turn on with `:GitGutterEnable`
* toggle with `:GitGutterToggle`.
To toggle vim-gitgutter per buffer:
* turn off with `:GitGutterBufferDisable`
* turn on with `:GitGutterBufferEnable`
* toggle with `:GitGutterBufferToggle`
You can turn the signs on and off (defaults to on):
* turn on with `:GitGutterSignsEnable`

View File

@@ -85,6 +85,27 @@ function! gitgutter#toggle() abort
endif
endfunction
function! gitgutter#buffer_disable() abort
let bufnr = bufnr('')
call gitgutter#utility#setbufvar(bufnr, 'enabled', 0)
call s:clear(bufnr)
endfunction
function! gitgutter#buffer_enable() abort
let bufnr = bufnr('')
call gitgutter#utility#setbufvar(bufnr, 'enabled', 1)
call gitgutter#process_buffer(bufnr, 1)
endfunction
function! gitgutter#buffer_toggle() abort
if gitgutter#utility#getbufvar(bufnr(''), 'enabled', 1)
call gitgutter#buffer_disable()
else
call gitgutter#buffer_enable()
endif
endfunction
" }}}
function! s:setup_maps()

View File

@@ -53,6 +53,7 @@ endfunction
" This function does not and should not make any system calls.
function! gitgutter#utility#is_active(bufnr) abort
return g:gitgutter_enabled &&
\ gitgutter#utility#getbufvar(a:bufnr, 'enabled', 1) &&
\ !pumvisible() &&
\ s:is_file_buffer(a:bufnr) &&
\ s:exists_file(a:bufnr) &&

View File

@@ -97,6 +97,10 @@ command! -bar GitGutterDisable call gitgutter#disable()
command! -bar GitGutterEnable call gitgutter#enable()
command! -bar GitGutterToggle call gitgutter#toggle()
command! -bar GitGutterBufferDisable call gitgutter#buffer_disable()
command! -bar GitGutterBufferEnable call gitgutter#buffer_enable()
command! -bar GitGutterBufferToggle call gitgutter#buffer_toggle()
" }}}
" Line highlights {{{