vim-signify/autoload/sy.vim

169 lines
3.9 KiB
VimL
Raw Normal View History

2013-09-30 04:19:31 -04:00
" vim: et sw=2 sts=2
scriptencoding utf-8
2013-07-17 06:30:58 -04:00
" Function: #start {{{1
function! sy#start() abort
if g:signify_locked
2017-01-17 11:03:34 -05:00
call sy#verbose('Locked.')
return
endif
2015-06-01 06:10:28 -04:00
let sy_path = resolve(expand('%:p'))
if has('win32')
let sy_path = substitute(sy_path, '\v^(\w):\\\\', '\1:\\', '')
endif
if s:skip(sy_path)
2018-04-13 07:16:30 -04:00
call sy#verbose('Skip file: '. sy_path)
if exists('b:sy')
call sy#sign#remove_all_signs(bufnr(''))
2018-04-13 08:49:25 -04:00
unlet! b:sy
endif
2013-07-17 06:30:58 -04:00
return
endif
2015-06-01 06:10:28 -04:00
if !exists('b:sy') || b:sy.path != sy_path
call sy#verbose('Register new file: '. sy_path)
2014-10-04 09:55:49 -04:00
let b:sy = {
\ 'path': sy_path,
\ 'buffer': bufnr(''),
\ 'active': 0,
\ 'detecting': 0,
\ 'vcs': [],
\ 'hunks': [],
\ 'signid': 0x100,
\ 'updated_by': '',
2018-04-13 08:49:25 -04:00
\ 'stats': [-1, -1, -1],
\ 'info': {
\ 'dir': fnamemodify(sy_path, ':p:h'),
\ 'path': sy#util#escape(sy_path),
\ 'file': sy#util#escape(fnamemodify(sy_path, ':t'))
\ }}
2013-07-29 10:14:49 -04:00
if get(g:, 'signify_disable_by_default')
2017-01-17 11:03:34 -05:00
call sy#verbose('Disabled by default.')
2013-07-17 06:30:58 -04:00
return
endif
2013-11-21 20:57:43 -05:00
let b:sy.active = 1
2017-04-18 11:13:17 -04:00
call sy#repo#detect()
elseif has('vim_starting')
call sy#verbose("Don't run Sy more than once during startup.")
return
2017-01-17 08:22:19 -05:00
elseif !b:sy.active
2017-01-17 11:03:34 -05:00
call sy#verbose('Inactive buffer.')
2017-01-17 08:22:19 -05:00
return
elseif empty(b:sy.vcs)
if get(b:sy, 'retry')
let b:sy.retry = 0
call sy#verbose('Redetecting VCS.')
2017-04-18 11:13:17 -04:00
call sy#repo#detect()
else
if get(b:sy, 'detecting')
call sy#verbose('Detection is already in progress.')
else
call sy#verbose('No VCS found. Disabling.')
call sy#disable()
endif
endif
2017-01-17 08:22:19 -05:00
else
for vcs in b:sy.vcs
let job_id = get(b:, 'sy_job_id_'. vcs)
if type(job_id) != type(0) || job_id > 0
call sy#verbose('Update is already in progress.', vcs)
else
call sy#verbose('Updating signs.', vcs)
call sy#repo#get_diff(vcs, function('sy#sign#set_signs'))
endif
endfor
2017-01-17 08:22:19 -05:00
endif
endfunction
2013-07-29 10:14:49 -04:00
2013-07-17 06:30:58 -04:00
" Function: #stop {{{1
function! sy#stop(bufnr) abort
let sy = getbufvar(a:bufnr, 'sy')
if empty(sy)
2013-07-17 06:30:58 -04:00
return
endif
call sy#sign#remove_all_signs(a:bufnr)
2013-07-17 06:30:58 -04:00
endfunction
2016-01-06 18:00:21 -05:00
" Function: #enable {{{1
function! sy#enable() abort
if !exists('b:sy')
call sy#start()
return
endif
if !b:sy.active
let b:sy.active = 1
let b:sy.retry = 1
call sy#start()
endif
2016-01-06 18:00:21 -05:00
endfunction
" Function: #disable {{{1
function! sy#disable() abort
if exists('b:sy') && b:sy.active
call sy#stop(b:sy.buffer)
2013-11-21 20:57:43 -05:00
let b:sy.active = 0
let b:sy.stats = [-1, -1, -1]
2016-01-06 18:00:21 -05:00
endif
endfunction
" Function: #toggle {{{1
function! sy#toggle() abort
if !exists('b:sy') || !b:sy.active
call sy#enable()
2013-07-17 06:30:58 -04:00
else
2016-01-06 18:00:21 -05:00
call sy#disable()
2013-07-17 06:30:58 -04:00
endif
endfunction
" Function: #buffer_is_active {{{1
function! sy#buffer_is_active()
2016-01-15 11:02:53 -05:00
return exists('b:sy') && b:sy.active
endfunction
2017-01-17 13:41:55 -05:00
" Function: #verbose {{{1
2017-01-17 17:57:29 -05:00
function! sy#verbose(msg, ...) abort
2017-01-17 13:41:55 -05:00
if &verbose
2018-12-27 09:37:51 -05:00
if type(a:msg) == type([])
for msg in a:msg
echomsg printf('[sy%s] %s', (a:0 ? ':'.a:1 : ''), msg)
endfor
else
echomsg printf('[sy%s] %s', (a:0 ? ':'.a:1 : ''), a:msg)
endif
2017-01-17 13:41:55 -05:00
endif
endfunction
2017-01-10 08:45:28 -05:00
" Function: s:skip {{{1
function! s:skip(path)
if &diff || !filereadable(a:path)
return 1
endif
if exists('g:signify_skip_filetype')
if has_key(g:signify_skip_filetype, &filetype)
return 1
elseif has_key(g:signify_skip_filetype, 'help') && (&buftype == 'help')
return 1
endif
endif
if exists('g:signify_skip_filename') && has_key(g:signify_skip_filename, a:path)
return 1
endif
if exists('g:signify_skip_filename_pattern')
for pattern in g:signify_skip_filename_pattern
if a:path =~ pattern
return 1
endif
endfor
endif
return 0
endfunction