Refactoring

This commit is contained in:
Marco Hinz 2018-04-15 22:00:17 +02:00
parent a804002c21
commit 3d3edac39d
No known key found for this signature in database
GPG Key ID: 1C980A1B657B4A4F
4 changed files with 17 additions and 24 deletions

View File

@ -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 %

View File

@ -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')

View File

@ -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

View File

@ -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