From 3ab2f38fbe52d9e9d094719a6a8badf6c2724899 Mon Sep 17 00:00:00 2001 From: Andy Stewart Date: Thu, 28 Feb 2013 09:59:29 +0100 Subject: [PATCH] Extract method to avoid repetition. --- plugin/gitgutter.vim | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/plugin/gitgutter.vim b/plugin/gitgutter.vim index 348ec08..e477d02 100644 --- a/plugin/gitgutter.vim +++ b/plugin/gitgutter.vim @@ -51,6 +51,10 @@ 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() +endfunction + function! s:update_line_highlights(highlight_lines) let s:highlight_lines = a:highlight_lines call s:define_signs() @@ -234,7 +238,7 @@ endfunction " Public interface {{{ function! GitGutter() - if g:gitgutter_enabled && s:exists_current_file() && s:is_in_a_git_repo() && s:is_tracked_by_git() + if s:is_active() call s:init() let diff = s:run_diff() let s:hunks = s:parse_diff(diff) @@ -277,7 +281,7 @@ function! ToggleGitGutterLineHighlights() endfunction function! GitGutterNextHunk() - if g:gitgutter_enabled && s:exists_current_file() && s:is_in_a_git_repo() && s:is_tracked_by_git() + if s:is_active() let current_line = line('.') for hunk in s:hunks if hunk[2] > current_line @@ -289,7 +293,7 @@ function! GitGutterNextHunk() endfunction function! GitGutterPrevHunk() - if g:gitgutter_enabled && s:exists_current_file() && s:is_in_a_git_repo() && s:is_tracked_by_git() + if s:is_active() let current_line = line('.') for hunk in reverse(copy(s:hunks)) if hunk[2] < current_line