mirror of
https://github.com/airblade/vim-gitgutter.git
synced 2025-11-09 20:13:46 -05:00
Update signs across all buffers on FocusGained.
This commit is contained in:
@@ -63,6 +63,8 @@ nmap <silent> ]h :<C-U>execute v:count1 . "GitGutterNextHunk"<CR>
|
||||
nmap <silent> [h :<C-U>execute v:count1 . "GitGutterPrevHunk"<CR>
|
||||
```
|
||||
|
||||
Finally, you can force vim-gitgutter to update its signs across all buffers with `:GitGutterAll`.
|
||||
|
||||
See the customisation section below for how to change the defaults.
|
||||
|
||||
|
||||
|
||||
@@ -61,6 +61,12 @@ Commands for turning Git Gutter on and off:
|
||||
:GitGutterToggle *:GitGutterToggle*
|
||||
Explicitly turn Git Gutter on if it was off and vice versa.
|
||||
|
||||
:GitGutter *:GitGutter*
|
||||
Update signs for the current buffer.
|
||||
|
||||
:GitGutterAll *:GitGutterAll*
|
||||
Update signs across all buffers.
|
||||
|
||||
Commands for turning line highlighting on and off (defaults to off):
|
||||
|
||||
:GitGutterLineHighlightsEnable *:GitGutterLineHighlightsEnable*
|
||||
@@ -75,10 +81,10 @@ Commands for turning line highlighting on and off (defaults to off):
|
||||
Commands for jumping between marked hunks:
|
||||
|
||||
:GitGutterNextHunk *:GitGutterNextHunk*
|
||||
Jump to the next marked hunk.
|
||||
Jump to the next marked hunk. Takes a count.
|
||||
|
||||
:GitGutterPrevHunk *:GitGutterPrevHunk*
|
||||
Jump to the previous marked hunk.
|
||||
Jump to the previous marked hunk. Takes a count.
|
||||
|
||||
===============================================================================
|
||||
5. CUSTOMISATION *GitGutterCustomisation*
|
||||
|
||||
@@ -44,19 +44,27 @@ endfunction
|
||||
" Utility {{{
|
||||
|
||||
function! s:is_active()
|
||||
return g:gitgutter_enabled && s:exists_current_file() && s:is_in_a_git_repo() && s:is_tracked_by_git()
|
||||
return g:gitgutter_enabled && s:exists_file() && s:is_in_a_git_repo() && s:is_tracked_by_git()
|
||||
endfunction
|
||||
|
||||
function! s:current_file()
|
||||
return expand("%:p")
|
||||
return expand('%:p')
|
||||
endfunction
|
||||
|
||||
function! s:exists_current_file()
|
||||
return strlen(s:current_file()) > 0
|
||||
function! s:set_file(file)
|
||||
let s:file = a:file
|
||||
endfunction
|
||||
|
||||
function! s:directory_of_current_file()
|
||||
return shellescape(expand("%:p:h"))
|
||||
function! s:file()
|
||||
return s:file
|
||||
endfunction
|
||||
|
||||
function! s:exists_file()
|
||||
return strlen(s:file()) > 0
|
||||
endfunction
|
||||
|
||||
function! s:directory_of_file()
|
||||
return shellescape(fnamemodify(s:file(), ':h'))
|
||||
endfunction
|
||||
|
||||
function! s:discard_stdout_and_stderr()
|
||||
@@ -70,19 +78,19 @@ function! s:discard_stdout_and_stderr()
|
||||
return s:discard
|
||||
endfunction
|
||||
|
||||
function! s:command_in_directory_of_current_file(cmd)
|
||||
return 'cd ' . s:directory_of_current_file() . ' && ' . a:cmd
|
||||
function! s:command_in_directory_of_file(cmd)
|
||||
return 'cd ' . s:directory_of_file() . ' && ' . a:cmd
|
||||
endfunction
|
||||
|
||||
function! s:is_in_a_git_repo()
|
||||
let cmd = 'git rev-parse' . s:discard_stdout_and_stderr()
|
||||
call system(s:command_in_directory_of_current_file(cmd))
|
||||
call system(s:command_in_directory_of_file(cmd))
|
||||
return !v:shell_error
|
||||
endfunction
|
||||
|
||||
function! s:is_tracked_by_git()
|
||||
let cmd = 'git ls-files --error-unmatch' . s:discard_stdout_and_stderr() . ' ' . shellescape(s:current_file())
|
||||
call system(s:command_in_directory_of_current_file(cmd))
|
||||
let cmd = 'git ls-files --error-unmatch' . s:discard_stdout_and_stderr() . ' ' . shellescape(s:file())
|
||||
call system(s:command_in_directory_of_file(cmd))
|
||||
return !v:shell_error
|
||||
endfunction
|
||||
|
||||
@@ -90,6 +98,10 @@ function! s:snake_case_to_camel_case(text)
|
||||
return substitute(a:text, '\v(.)(\a+)(_(.)(.+))?', '\u\1\l\2\u\4\l\5', '')
|
||||
endfunction
|
||||
|
||||
function! s:buffers()
|
||||
return range(1, bufnr('$'))
|
||||
endfunction
|
||||
|
||||
" }}}
|
||||
|
||||
" Highlights and signs {{{
|
||||
@@ -164,9 +176,9 @@ endfunction
|
||||
" Diff processing {{{
|
||||
|
||||
function! s:run_diff()
|
||||
let cmd = 'git diff --no-ext-diff --no-color -U0 ' . shellescape(s:current_file()) .
|
||||
let cmd = 'git diff --no-ext-diff --no-color -U0 ' . shellescape(s:file()) .
|
||||
\ ' | grep -e "^@@ "'
|
||||
let diff = system(s:command_in_directory_of_current_file(cmd))
|
||||
let diff = system(s:command_in_directory_of_file(cmd))
|
||||
return diff
|
||||
endfunction
|
||||
|
||||
@@ -303,7 +315,7 @@ function! s:clear_signs(file_name)
|
||||
endif
|
||||
endfunction
|
||||
|
||||
" This assumes there are no GitGutter signs in the current file.
|
||||
" This assumes there are no GitGutter signs in the file.
|
||||
" If this is untenable we could change the regexp to exclude GitGutter's
|
||||
" signs.
|
||||
function! s:find_other_signs(file_name)
|
||||
@@ -344,12 +356,12 @@ endfunction
|
||||
|
||||
function! s:remember_sign(id, file_name)
|
||||
if has_key(s:sign_ids, a:file_name)
|
||||
let sign_ids_for_current_file = s:sign_ids[a:file_name]
|
||||
call add(sign_ids_for_current_file, a:id)
|
||||
let sign_ids_for_file = s:sign_ids[a:file_name]
|
||||
call add(sign_ids_for_file, a:id)
|
||||
else
|
||||
let sign_ids_for_current_file = [a:id]
|
||||
let sign_ids_for_file = [a:id]
|
||||
endif
|
||||
let s:sign_ids[a:file_name] = sign_ids_for_current_file
|
||||
let s:sign_ids[a:file_name] = sign_ids_for_file
|
||||
endfunction
|
||||
|
||||
function! s:is_other_sign(line_number)
|
||||
@@ -358,33 +370,40 @@ endfunction
|
||||
|
||||
function! s:add_dummy_sign()
|
||||
let last_line = line('$')
|
||||
exe ":sign place " . s:dummy_sign_id . " line=" . (last_line + 1) . " name=GitGutterDummy file=" . s:current_file()
|
||||
exe ":sign place " . s:dummy_sign_id . " line=" . (last_line + 1) . " name=GitGutterDummy file=" . s:file()
|
||||
endfunction
|
||||
|
||||
" }}}
|
||||
|
||||
" Public interface {{{
|
||||
|
||||
function! GitGutter()
|
||||
function! GitGutterAll()
|
||||
for buffer_id in s:buffers()
|
||||
call GitGutter(fnamemodify(bufname(buffer_id), ':p'))
|
||||
endfor
|
||||
endfunction
|
||||
command GitGutterAll call GitGutterAll()
|
||||
|
||||
function! GitGutter(file)
|
||||
call s:set_file(a:file)
|
||||
if s:is_active()
|
||||
call s:init()
|
||||
let diff = s:run_diff()
|
||||
let s:hunks = s:parse_diff(diff)
|
||||
let modified_lines = s:process_hunks(s:hunks)
|
||||
let file_name = s:current_file()
|
||||
if g:gitgutter_sign_column_always
|
||||
call s:add_dummy_sign()
|
||||
endif
|
||||
call s:clear_signs(file_name)
|
||||
call s:find_other_signs(file_name)
|
||||
call s:show_signs(file_name, modified_lines)
|
||||
call s:clear_signs(a:file)
|
||||
call s:find_other_signs(a:file)
|
||||
call s:show_signs(a:file, modified_lines)
|
||||
endif
|
||||
endfunction
|
||||
command GitGutter call GitGutter()
|
||||
command GitGutter call GitGutter(s:current_file())
|
||||
|
||||
function! GitGutterDisable()
|
||||
let g:gitgutter_enabled = 0
|
||||
call s:clear_signs(s:current_file())
|
||||
call s:clear_signs(s:file())
|
||||
endfunction
|
||||
command GitGutterDisable call GitGutterDisable()
|
||||
|
||||
@@ -455,7 +474,7 @@ function! GitGutterPrevHunk(count)
|
||||
endfunction
|
||||
command -count=1 GitGutterPrevHunk call GitGutterPrevHunk(<count>)
|
||||
|
||||
" Returns the git-diff hunks for the current file or an empty list if there
|
||||
" 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.
|
||||
@@ -478,9 +497,9 @@ endfunction
|
||||
|
||||
augroup gitgutter
|
||||
autocmd!
|
||||
autocmd BufReadPost,BufWritePost,FileReadPost,FileWritePost * call GitGutter()
|
||||
autocmd BufReadPost,BufWritePost,FileReadPost,FileWritePost * call GitGutter(s:current_file())
|
||||
if !has('gui_win32')
|
||||
autocmd FocusGained * call GitGutter()
|
||||
autocmd FocusGained * call GitGutterAll()
|
||||
endif
|
||||
augroup END
|
||||
|
||||
|
||||
Reference in New Issue
Block a user