Skip to content

Commit

Permalink
Speed up work done on FocusGained.
Browse files Browse the repository at this point in the history
When vim-gitgutter is configured to update on `BufEnter`, which is the
default, we only need to update visible buffers on `FocusGained`.
Other buffers will be updated as and when the user enters them.
  • Loading branch information
airblade committed Mar 19, 2013
1 parent fd7fb6c commit 2a5ae17
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion plugin/gitgutter.vim
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,14 @@ function! s:buffers()
return filter(range(1, bufnr('$')), 'buflisted(v:val)')
endfunction

function! s:visible_buffers()
let visible = []
for i in range(tabpagenr('$'))
call extend(visible, tabpagebuflist(i + 1))
endfor
return visible
endfunction

" }}}

" Highlights and signs {{{
Expand Down Expand Up @@ -388,7 +396,8 @@ endfunction
" Public interface {{{

function! GitGutterAll()
for buffer_id in s:buffers()
let buffer_ids = g:gitgutter_on_bufenter ? s:visible_buffers() : s:buffers()
for buffer_id in buffer_ids
call GitGutter(fnamemodify(bufname(buffer_id), ':p'))
endfor
endfunction
Expand Down

2 comments on commit 2a5ae17

@majutsushi
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are you iterating over all tabpages here? Shouldn't the current one be enough? If you switch to a different tabpage BufEnter will be called again.

@airblade
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right. The same thing occurred to me after I made the change but I hadn't got around to doing anything about it.

Anyway, I've updated this in 93288af. A further improvement would be on TabEnter to skip the buffer that's about to be entered because that will be updated on BufEnter – but I'll wait until the double-update for that buffer is an actual problem.

Please sign in to comment.