2016-11-22 03:36:31 -05:00
|
|
|
scriptencoding utf-8
|
|
|
|
|
|
|
|
if exists('g:loaded_gitgutter') || !has('signs') || &cp
|
|
|
|
finish
|
|
|
|
endif
|
|
|
|
let g:loaded_gitgutter = 1
|
|
|
|
|
|
|
|
" Initialisation {{{
|
|
|
|
|
|
|
|
if v:version < 703 || (v:version == 703 && !has("patch105"))
|
2018-03-31 10:56:26 -04:00
|
|
|
call gitgutter#utility#warn('requires Vim 7.3.105')
|
|
|
|
finish
|
2016-11-22 03:36:31 -05:00
|
|
|
endif
|
|
|
|
|
|
|
|
function! s:set(var, default) abort
|
|
|
|
if !exists(a:var)
|
|
|
|
if type(a:default)
|
|
|
|
execute 'let' a:var '=' string(a:default)
|
|
|
|
else
|
|
|
|
execute 'let' a:var '=' a:default
|
|
|
|
endif
|
|
|
|
endif
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
call s:set('g:gitgutter_enabled', 1)
|
|
|
|
call s:set('g:gitgutter_max_signs', 500)
|
|
|
|
call s:set('g:gitgutter_signs', 1)
|
|
|
|
call s:set('g:gitgutter_highlight_lines', 0)
|
|
|
|
call s:set('g:gitgutter_sign_column_always', 0)
|
2017-09-02 06:43:18 -04:00
|
|
|
if g:gitgutter_sign_column_always && exists('&signcolumn')
|
2018-03-31 10:56:26 -04:00
|
|
|
" Vim 7.4.2201.
|
2017-09-02 06:43:18 -04:00
|
|
|
set signcolumn=yes
|
|
|
|
let g:gitgutter_sign_column_always = 0
|
|
|
|
call gitgutter#utility#warn('please replace "let g:gitgutter_sign_column_always=1" with "set signcolumn=yes"')
|
|
|
|
endif
|
2016-11-22 03:36:31 -05:00
|
|
|
call s:set('g:gitgutter_override_sign_column_highlight', 1)
|
2018-11-01 06:03:42 -04:00
|
|
|
call s:set('g:gitgutter_sign_added', '+')
|
|
|
|
call s:set('g:gitgutter_sign_modified', '~')
|
|
|
|
call s:set('g:gitgutter_sign_removed', '_')
|
2018-03-31 10:56:26 -04:00
|
|
|
|
|
|
|
if gitgutter#utility#supports_overscore_sign()
|
2016-11-22 03:36:31 -05:00
|
|
|
call s:set('g:gitgutter_sign_removed_first_line', '‾')
|
2018-03-31 10:56:26 -04:00
|
|
|
else
|
|
|
|
call s:set('g:gitgutter_sign_removed_first_line', '_^')
|
|
|
|
endif
|
2016-11-22 03:36:31 -05:00
|
|
|
|
2018-11-01 06:03:42 -04:00
|
|
|
call s:set('g:gitgutter_sign_removed_above_and_below', '[')
|
|
|
|
call s:set('g:gitgutter_sign_modified_removed', '~_')
|
|
|
|
call s:set('g:gitgutter_git_args', '')
|
|
|
|
call s:set('g:gitgutter_diff_args', '')
|
|
|
|
call s:set('g:gitgutter_diff_base', '')
|
|
|
|
call s:set('g:gitgutter_map_keys', 1)
|
|
|
|
call s:set('g:gitgutter_terminal_reports_focus', 1)
|
|
|
|
call s:set('g:gitgutter_async', 1)
|
|
|
|
call s:set('g:gitgutter_log', 0)
|
2016-11-22 03:36:31 -05:00
|
|
|
|
2018-03-31 10:56:26 -04:00
|
|
|
call s:set('g:gitgutter_git_executable', 'git')
|
2016-11-22 03:36:31 -05:00
|
|
|
if !executable(g:gitgutter_git_executable)
|
|
|
|
call gitgutter#utility#warn('cannot find git. Please set g:gitgutter_git_executable.')
|
|
|
|
endif
|
|
|
|
|
2018-03-31 10:56:26 -04:00
|
|
|
let default_grep = 'grep'
|
|
|
|
call s:set('g:gitgutter_grep', default_grep)
|
|
|
|
if !empty(g:gitgutter_grep)
|
|
|
|
if executable(split(g:gitgutter_grep)[0])
|
|
|
|
if $GREP_OPTIONS =~# '--color=always'
|
|
|
|
let g:gitgutter_grep .= ' --color=never'
|
|
|
|
endif
|
|
|
|
else
|
|
|
|
if g:gitgutter_grep !=# default_grep
|
|
|
|
call gitgutter#utility#warn('cannot find '.g:gitgutter_grep.'. Please check g:gitgutter_grep.')
|
|
|
|
endif
|
|
|
|
let g:gitgutter_grep = ''
|
|
|
|
endif
|
|
|
|
endif
|
|
|
|
|
2016-11-22 03:36:31 -05:00
|
|
|
call gitgutter#highlight#define_sign_column_highlight()
|
|
|
|
call gitgutter#highlight#define_highlights()
|
|
|
|
call gitgutter#highlight#define_signs()
|
|
|
|
|
2018-06-14 06:31:12 -04:00
|
|
|
" Prevent infinite loop where:
|
|
|
|
" - executing a job in the foreground launches a new window which takes the focus;
|
|
|
|
" - when the job finishes, focus returns to gvim;
|
|
|
|
" - the FocusGained event triggers a new job (see below).
|
|
|
|
if gitgutter#utility#windows() && !(g:gitgutter_async && gitgutter#async#available())
|
|
|
|
set noshelltemp
|
|
|
|
endif
|
|
|
|
|
2016-11-22 03:36:31 -05:00
|
|
|
" }}}
|
|
|
|
|
|
|
|
" Primary functions {{{
|
|
|
|
|
2018-03-31 10:56:26 -04:00
|
|
|
command! -bar GitGutterAll call gitgutter#all(1)
|
|
|
|
command! -bar GitGutter call gitgutter#process_buffer(bufnr(''), 1)
|
2016-11-22 03:36:31 -05:00
|
|
|
|
2018-03-31 10:56:26 -04:00
|
|
|
command! -bar GitGutterDisable call gitgutter#disable()
|
|
|
|
command! -bar GitGutterEnable call gitgutter#enable()
|
|
|
|
command! -bar GitGutterToggle call gitgutter#toggle()
|
2016-11-22 03:36:31 -05:00
|
|
|
|
|
|
|
" }}}
|
|
|
|
|
|
|
|
" Line highlights {{{
|
|
|
|
|
2018-03-31 10:56:26 -04:00
|
|
|
command! -bar GitGutterLineHighlightsDisable call gitgutter#highlight#line_disable()
|
|
|
|
command! -bar GitGutterLineHighlightsEnable call gitgutter#highlight#line_enable()
|
|
|
|
command! -bar GitGutterLineHighlightsToggle call gitgutter#highlight#line_toggle()
|
2016-11-22 03:36:31 -05:00
|
|
|
|
|
|
|
" }}}
|
|
|
|
|
|
|
|
" Signs {{{
|
|
|
|
|
2018-03-31 10:56:26 -04:00
|
|
|
command! -bar GitGutterSignsEnable call gitgutter#sign#enable()
|
|
|
|
command! -bar GitGutterSignsDisable call gitgutter#sign#disable()
|
|
|
|
command! -bar GitGutterSignsToggle call gitgutter#sign#toggle()
|
2016-11-22 03:36:31 -05:00
|
|
|
|
|
|
|
" }}}
|
|
|
|
|
|
|
|
" Hunks {{{
|
|
|
|
|
2018-03-31 10:56:26 -04:00
|
|
|
command! -bar -count=1 GitGutterNextHunk call gitgutter#hunk#next_hunk(<count>)
|
|
|
|
command! -bar -count=1 GitGutterPrevHunk call gitgutter#hunk#prev_hunk(<count>)
|
2016-11-22 03:36:31 -05:00
|
|
|
|
2018-03-31 10:56:26 -04:00
|
|
|
command! -bar GitGutterStageHunk call gitgutter#hunk#stage()
|
|
|
|
command! -bar GitGutterUndoHunk call gitgutter#hunk#undo()
|
|
|
|
command! -bar GitGutterPreviewHunk call gitgutter#hunk#preview()
|
2016-11-22 03:36:31 -05:00
|
|
|
|
|
|
|
" Hunk text object
|
|
|
|
onoremap <silent> <Plug>GitGutterTextObjectInnerPending :<C-U>call gitgutter#hunk#text_object(1)<CR>
|
|
|
|
onoremap <silent> <Plug>GitGutterTextObjectOuterPending :<C-U>call gitgutter#hunk#text_object(0)<CR>
|
|
|
|
xnoremap <silent> <Plug>GitGutterTextObjectInnerVisual :<C-U>call gitgutter#hunk#text_object(1)<CR>
|
|
|
|
xnoremap <silent> <Plug>GitGutterTextObjectOuterVisual :<C-U>call gitgutter#hunk#text_object(0)<CR>
|
|
|
|
|
|
|
|
|
|
|
|
" Returns the git-diff hunks for the file or an empty list if there
|
|
|
|
" aren't any hunks.
|
|
|
|
"
|
|
|
|
" The return value is a list of lists. There is one inner list per hunk.
|
|
|
|
"
|
|
|
|
" [
|
|
|
|
" [from_line, from_count, to_line, to_count],
|
|
|
|
" [from_line, from_count, to_line, to_count],
|
|
|
|
" ...
|
|
|
|
" ]
|
|
|
|
"
|
|
|
|
" where:
|
|
|
|
"
|
|
|
|
" `from` - refers to the staged file
|
|
|
|
" `to` - refers to the working tree's file
|
|
|
|
" `line` - refers to the line number where the change starts
|
|
|
|
" `count` - refers to the number of lines the change covers
|
|
|
|
function! GitGutterGetHunks()
|
2018-03-31 10:56:26 -04:00
|
|
|
let bufnr = bufnr('')
|
|
|
|
return gitgutter#utility#is_active(bufnr) ? gitgutter#hunk#hunks(bufnr) : []
|
2016-11-22 03:36:31 -05:00
|
|
|
endfunction
|
|
|
|
|
|
|
|
" Returns an array that contains a summary of the hunk status for the current
|
|
|
|
" window. The format is [ added, modified, removed ], where each value
|
|
|
|
" represents the number of lines added/modified/removed respectively.
|
|
|
|
function! GitGutterGetHunkSummary()
|
|
|
|
return gitgutter#hunk#summary(winbufnr(0))
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
" }}}
|
|
|
|
|
2018-03-31 10:56:26 -04:00
|
|
|
command! -bar GitGutterDebug call gitgutter#debug#debug()
|
2016-11-22 03:36:31 -05:00
|
|
|
|
|
|
|
" Maps {{{
|
|
|
|
|
|
|
|
nnoremap <silent> <expr> <Plug>GitGutterNextHunk &diff ? ']c' : ":\<C-U>execute v:count1 . 'GitGutterNextHunk'\<CR>"
|
|
|
|
nnoremap <silent> <expr> <Plug>GitGutterPrevHunk &diff ? '[c' : ":\<C-U>execute v:count1 . 'GitGutterPrevHunk'\<CR>"
|
|
|
|
|
|
|
|
nnoremap <silent> <Plug>GitGutterStageHunk :GitGutterStageHunk<CR>
|
|
|
|
nnoremap <silent> <Plug>GitGutterUndoHunk :GitGutterUndoHunk<CR>
|
|
|
|
nnoremap <silent> <Plug>GitGutterPreviewHunk :GitGutterPreviewHunk<CR>
|
|
|
|
|
2018-06-14 06:31:12 -04:00
|
|
|
" }}}
|
2016-11-22 03:36:31 -05:00
|
|
|
|
2018-06-14 06:31:12 -04:00
|
|
|
function! s:on_bufenter()
|
|
|
|
if exists('t:gitgutter_didtabenter') && t:gitgutter_didtabenter
|
|
|
|
let t:gitgutter_didtabenter = 0
|
2018-07-19 08:52:53 -04:00
|
|
|
call gitgutter#all(!g:gitgutter_terminal_reports_focus)
|
2018-06-14 06:31:12 -04:00
|
|
|
else
|
|
|
|
call gitgutter#init_buffer(bufnr(''))
|
|
|
|
call gitgutter#process_buffer(bufnr(''), !g:gitgutter_terminal_reports_focus)
|
|
|
|
endif
|
|
|
|
endfunction
|
2016-11-22 03:36:31 -05:00
|
|
|
|
|
|
|
" Autocommands {{{
|
|
|
|
|
|
|
|
augroup gitgutter
|
|
|
|
autocmd!
|
|
|
|
|
2018-03-31 10:56:26 -04:00
|
|
|
autocmd TabEnter * let t:gitgutter_didtabenter = 1
|
2016-11-22 03:36:31 -05:00
|
|
|
|
2018-06-14 06:31:12 -04:00
|
|
|
autocmd BufEnter * call s:on_bufenter()
|
2016-11-22 03:36:31 -05:00
|
|
|
|
2018-07-19 08:52:53 -04:00
|
|
|
autocmd CursorHold,CursorHoldI * call gitgutter#process_buffer(bufnr(''), 0)
|
|
|
|
autocmd FileChangedShellPost * call gitgutter#process_buffer(bufnr(''), 1)
|
2016-11-22 03:36:31 -05:00
|
|
|
|
2018-03-31 10:56:26 -04:00
|
|
|
" Ensure that all buffers are processed when opening vim with multiple files, e.g.:
|
|
|
|
"
|
|
|
|
" vim -o file1 file2
|
|
|
|
autocmd VimEnter * if winnr() != winnr('$') | call gitgutter#all(0) | endif
|
2017-09-02 06:43:18 -04:00
|
|
|
|
2018-07-19 08:52:53 -04:00
|
|
|
autocmd FocusGained,ShellCmdPost * call gitgutter#all(1)
|
2016-11-22 03:36:31 -05:00
|
|
|
|
2018-08-25 12:13:42 -04:00
|
|
|
if exists('##VimResume')
|
|
|
|
autocmd VimResume * call gitgutter#all(1)
|
|
|
|
endif
|
|
|
|
|
2016-11-22 03:36:31 -05:00
|
|
|
autocmd ColorScheme * call gitgutter#highlight#define_sign_column_highlight() | call gitgutter#highlight#define_highlights()
|
|
|
|
|
|
|
|
" Disable during :vimgrep
|
|
|
|
autocmd QuickFixCmdPre *vimgrep* let g:gitgutter_enabled = 0
|
|
|
|
autocmd QuickFixCmdPost *vimgrep* let g:gitgutter_enabled = 1
|
|
|
|
augroup END
|
|
|
|
|
|
|
|
" }}}
|
|
|
|
|
|
|
|
" vim:set et sw=2 fdm=marker:
|