From 3d3edac39daba7a3da7c70df56a2876ebcb1022c Mon Sep 17 00:00:00 2001 From: Marco Hinz Date: Sun, 15 Apr 2018 22:00:17 +0200 Subject: [PATCH] Refactoring --- autoload/sy/fold.vim | 5 +---- autoload/sy/jump.vim | 10 ++-------- autoload/sy/repo.vim | 12 +++--------- autoload/sy/util.vim | 14 +++++++++++--- 4 files changed, 17 insertions(+), 24 deletions(-) diff --git a/autoload/sy/fold.vim b/autoload/sy/fold.vim index 4c1900e..bc5835c 100644 --- a/autoload/sy/fold.vim +++ b/autoload/sy/fold.vim @@ -42,10 +42,7 @@ endfunction " Function: #enable {{{1 function! sy#fold#enable(do_tab) abort - if !exists('b:sy') - echomsg 'signify: I cannot detect any changes!' - return - endif + execute sy#util#return_if_no_changes() if a:do_tab tabedit % diff --git a/autoload/sy/jump.vim b/autoload/sy/jump.vim index fe37581..69756b1 100644 --- a/autoload/sy/jump.vim +++ b/autoload/sy/jump.vim @@ -4,10 +4,7 @@ scriptencoding utf-8 " Function: #next_hunk {{{1 function! sy#jump#next_hunk(count) - if !exists('b:sy') - echomsg 'signify: I cannot detect any changes!' - return - endif + execute sy#util#return_if_no_changes() let lnum = line('.') let hunks = filter(copy(b:sy.hunks), 'v:val.start > lnum') @@ -20,10 +17,7 @@ endfunction " Function: #prev_hunk {{{1 function! sy#jump#prev_hunk(count) - if !exists('b:sy') - echomsg 'signify: I cannot detect any changes!' - return - endif + execute sy#util#return_if_no_changes() let lnum = line('.') let hunks = filter(copy(b:sy.hunks), 'v:val.start < lnum') diff --git a/autoload/sy/repo.vim b/autoload/sy/repo.vim index 75c4217..ad6e04e 100644 --- a/autoload/sy/repo.vim +++ b/autoload/sy/repo.vim @@ -210,11 +210,7 @@ endfunction " Function: #get_stats {{{1 function! sy#repo#get_stats() abort - if !exists('b:sy') || !has_key(b:sy, 'stats') - return [-1, -1, -1] - endif - - return b:sy.stats + return exists('b:sy') ? b:sy.stats : [-1, -1, -1] endfunction " Function: #debug_detection {{{1 @@ -245,10 +241,8 @@ endfunction " Function: #diffmode {{{1 function! sy#repo#diffmode() abort - if !exists('b:sy') - echomsg 'signify: I cannot detect any changes!' - return - endif + execute sy#util#return_if_no_changes() + let vcs = b:sy.updated_by if !has_key(g:signify_vcs_cmds_diffmode, vcs) echomsg 'SignifyDiff has no support for: '. vcs diff --git a/autoload/sy/util.vim b/autoload/sy/util.vim index 9f100d8..4da42b0 100644 --- a/autoload/sy/util.vim +++ b/autoload/sy/util.vim @@ -43,14 +43,13 @@ endfunction " Function: #hunk_text_object {{{1 function! sy#util#hunk_text_object(emptylines) abort - if !exists('b:sy') - return - endif + execute sy#util#return_if_no_changes() let lnum = line('.') let hunks = filter(copy(b:sy.hunks), 'v:val.start <= lnum && v:val.end >= lnum') if empty(hunks) + echomsg 'signify: Here is no hunk.' return endif @@ -89,3 +88,12 @@ function! sy#util#chdir() abort \ : (exists(':tcd') && haslocaldir(-1, 0)) ? 'tcd' : 'cd' return [getcwd(), chdir] endfunction + +" Function: #has_changes {{{1 +function! sy#util#return_if_no_changes() abort + if !exists('b:sy') || empty(b:sy.hunks) + echomsg 'signify: There are no changes.' + return 'return' + endif + return '' +endfunction