mirror of
https://github.com/airblade/vim-gitgutter.git
synced 2025-11-10 12:33:47 -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>
|
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.
|
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*
|
:GitGutterToggle *:GitGutterToggle*
|
||||||
Explicitly turn Git Gutter on if it was off and vice versa.
|
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):
|
Commands for turning line highlighting on and off (defaults to off):
|
||||||
|
|
||||||
:GitGutterLineHighlightsEnable *:GitGutterLineHighlightsEnable*
|
:GitGutterLineHighlightsEnable *:GitGutterLineHighlightsEnable*
|
||||||
@@ -75,10 +81,10 @@ Commands for turning line highlighting on and off (defaults to off):
|
|||||||
Commands for jumping between marked hunks:
|
Commands for jumping between marked hunks:
|
||||||
|
|
||||||
:GitGutterNextHunk *:GitGutterNextHunk*
|
:GitGutterNextHunk *:GitGutterNextHunk*
|
||||||
Jump to the next marked hunk.
|
Jump to the next marked hunk. Takes a count.
|
||||||
|
|
||||||
:GitGutterPrevHunk *:GitGutterPrevHunk*
|
:GitGutterPrevHunk *:GitGutterPrevHunk*
|
||||||
Jump to the previous marked hunk.
|
Jump to the previous marked hunk. Takes a count.
|
||||||
|
|
||||||
===============================================================================
|
===============================================================================
|
||||||
5. CUSTOMISATION *GitGutterCustomisation*
|
5. CUSTOMISATION *GitGutterCustomisation*
|
||||||
|
|||||||
@@ -44,19 +44,27 @@ endfunction
|
|||||||
" Utility {{{
|
" Utility {{{
|
||||||
|
|
||||||
function! s:is_active()
|
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
|
endfunction
|
||||||
|
|
||||||
function! s:current_file()
|
function! s:current_file()
|
||||||
return expand("%:p")
|
return expand('%:p')
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:exists_current_file()
|
function! s:set_file(file)
|
||||||
return strlen(s:current_file()) > 0
|
let s:file = a:file
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:directory_of_current_file()
|
function! s:file()
|
||||||
return shellescape(expand("%:p:h"))
|
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
|
endfunction
|
||||||
|
|
||||||
function! s:discard_stdout_and_stderr()
|
function! s:discard_stdout_and_stderr()
|
||||||
@@ -70,19 +78,19 @@ function! s:discard_stdout_and_stderr()
|
|||||||
return s:discard
|
return s:discard
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:command_in_directory_of_current_file(cmd)
|
function! s:command_in_directory_of_file(cmd)
|
||||||
return 'cd ' . s:directory_of_current_file() . ' && ' . a:cmd
|
return 'cd ' . s:directory_of_file() . ' && ' . a:cmd
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:is_in_a_git_repo()
|
function! s:is_in_a_git_repo()
|
||||||
let cmd = 'git rev-parse' . s:discard_stdout_and_stderr()
|
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
|
return !v:shell_error
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:is_tracked_by_git()
|
function! s:is_tracked_by_git()
|
||||||
let cmd = 'git ls-files --error-unmatch' . s:discard_stdout_and_stderr() . ' ' . shellescape(s:current_file())
|
let cmd = 'git ls-files --error-unmatch' . s:discard_stdout_and_stderr() . ' ' . shellescape(s:file())
|
||||||
call system(s:command_in_directory_of_current_file(cmd))
|
call system(s:command_in_directory_of_file(cmd))
|
||||||
return !v:shell_error
|
return !v:shell_error
|
||||||
endfunction
|
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', '')
|
return substitute(a:text, '\v(.)(\a+)(_(.)(.+))?', '\u\1\l\2\u\4\l\5', '')
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
function! s:buffers()
|
||||||
|
return range(1, bufnr('$'))
|
||||||
|
endfunction
|
||||||
|
|
||||||
" }}}
|
" }}}
|
||||||
|
|
||||||
" Highlights and signs {{{
|
" Highlights and signs {{{
|
||||||
@@ -164,9 +176,9 @@ endfunction
|
|||||||
" Diff processing {{{
|
" Diff processing {{{
|
||||||
|
|
||||||
function! s:run_diff()
|
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 "^@@ "'
|
\ ' | 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
|
return diff
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
@@ -303,7 +315,7 @@ function! s:clear_signs(file_name)
|
|||||||
endif
|
endif
|
||||||
endfunction
|
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
|
" If this is untenable we could change the regexp to exclude GitGutter's
|
||||||
" signs.
|
" signs.
|
||||||
function! s:find_other_signs(file_name)
|
function! s:find_other_signs(file_name)
|
||||||
@@ -344,12 +356,12 @@ endfunction
|
|||||||
|
|
||||||
function! s:remember_sign(id, file_name)
|
function! s:remember_sign(id, file_name)
|
||||||
if has_key(s:sign_ids, a:file_name)
|
if has_key(s:sign_ids, a:file_name)
|
||||||
let sign_ids_for_current_file = s:sign_ids[a:file_name]
|
let sign_ids_for_file = s:sign_ids[a:file_name]
|
||||||
call add(sign_ids_for_current_file, a:id)
|
call add(sign_ids_for_file, a:id)
|
||||||
else
|
else
|
||||||
let sign_ids_for_current_file = [a:id]
|
let sign_ids_for_file = [a:id]
|
||||||
endif
|
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
|
endfunction
|
||||||
|
|
||||||
function! s:is_other_sign(line_number)
|
function! s:is_other_sign(line_number)
|
||||||
@@ -358,33 +370,40 @@ endfunction
|
|||||||
|
|
||||||
function! s:add_dummy_sign()
|
function! s:add_dummy_sign()
|
||||||
let last_line = line('$')
|
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
|
endfunction
|
||||||
|
|
||||||
" }}}
|
" }}}
|
||||||
|
|
||||||
" Public interface {{{
|
" 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()
|
if s:is_active()
|
||||||
call s:init()
|
call s:init()
|
||||||
let diff = s:run_diff()
|
let diff = s:run_diff()
|
||||||
let s:hunks = s:parse_diff(diff)
|
let s:hunks = s:parse_diff(diff)
|
||||||
let modified_lines = s:process_hunks(s:hunks)
|
let modified_lines = s:process_hunks(s:hunks)
|
||||||
let file_name = s:current_file()
|
|
||||||
if g:gitgutter_sign_column_always
|
if g:gitgutter_sign_column_always
|
||||||
call s:add_dummy_sign()
|
call s:add_dummy_sign()
|
||||||
endif
|
endif
|
||||||
call s:clear_signs(file_name)
|
call s:clear_signs(a:file)
|
||||||
call s:find_other_signs(file_name)
|
call s:find_other_signs(a:file)
|
||||||
call s:show_signs(file_name, modified_lines)
|
call s:show_signs(a:file, modified_lines)
|
||||||
endif
|
endif
|
||||||
endfunction
|
endfunction
|
||||||
command GitGutter call GitGutter()
|
command GitGutter call GitGutter(s:current_file())
|
||||||
|
|
||||||
function! GitGutterDisable()
|
function! GitGutterDisable()
|
||||||
let g:gitgutter_enabled = 0
|
let g:gitgutter_enabled = 0
|
||||||
call s:clear_signs(s:current_file())
|
call s:clear_signs(s:file())
|
||||||
endfunction
|
endfunction
|
||||||
command GitGutterDisable call GitGutterDisable()
|
command GitGutterDisable call GitGutterDisable()
|
||||||
|
|
||||||
@@ -455,7 +474,7 @@ function! GitGutterPrevHunk(count)
|
|||||||
endfunction
|
endfunction
|
||||||
command -count=1 GitGutterPrevHunk call GitGutterPrevHunk(<count>)
|
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.
|
" aren't any hunks.
|
||||||
"
|
"
|
||||||
" The return value is a list of lists. There is one inner list per hunk.
|
" The return value is a list of lists. There is one inner list per hunk.
|
||||||
@@ -478,9 +497,9 @@ endfunction
|
|||||||
|
|
||||||
augroup gitgutter
|
augroup gitgutter
|
||||||
autocmd!
|
autocmd!
|
||||||
autocmd BufReadPost,BufWritePost,FileReadPost,FileWritePost * call GitGutter()
|
autocmd BufReadPost,BufWritePost,FileReadPost,FileWritePost * call GitGutter(s:current_file())
|
||||||
if !has('gui_win32')
|
if !has('gui_win32')
|
||||||
autocmd FocusGained * call GitGutter()
|
autocmd FocusGained * call GitGutterAll()
|
||||||
endif
|
endif
|
||||||
augroup END
|
augroup END
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user