Skip to content

Commit

Permalink
Extract common code into function
Browse files Browse the repository at this point in the history
  • Loading branch information
airblade committed Feb 2, 2022
1 parent 23a65f3 commit d845704
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions autoload/gitgutter.vim
Original file line number Diff line number Diff line change
Expand Up @@ -59,29 +59,28 @@ endfunction


function! gitgutter#disable() abort
for bufnr in range(1, bufnr('$') + 1)
if buflisted(bufnr)
let file = expand('#'.bufnr.':p')
if !empty(file)
call gitgutter#buffer_disable(bufnr)
endif
endif
endfor

call s:toggle_each_buffer(0)
let g:gitgutter_enabled = 0
endfunction

function! gitgutter#enable() abort
call s:toggle_each_buffer(1)
let g:gitgutter_enabled = 1
endfunction

function s:toggle_each_buffer(enable)
for bufnr in range(1, bufnr('$') + 1)
if buflisted(bufnr)
let file = expand('#'.bufnr.':p')
if !empty(file)
call gitgutter#buffer_enable(bufnr)
if a:enable
call gitgutter#buffer_enable(bufnr)
else
call gitgutter#buffer_disable(bufnr)
end
endif
endif
endfor

let g:gitgutter_enabled = 1
endfunction

function! gitgutter#toggle() abort
Expand Down

0 comments on commit d845704

Please sign in to comment.