2013-09-30 04:19:31 -04:00
|
|
|
" vim: et sw=2 sts=2
|
|
|
|
|
2013-08-19 11:36:16 -04:00
|
|
|
scriptencoding utf-8
|
|
|
|
|
2013-07-17 06:44:21 -04:00
|
|
|
" Init: values {{{1
|
2013-07-17 06:30:58 -04:00
|
|
|
let g:id_top = 0x100
|
2013-09-12 19:23:05 -04:00
|
|
|
let g:sy_cache = {}
|
2013-07-17 06:30:58 -04:00
|
|
|
|
2016-07-21 10:56:39 -04:00
|
|
|
let s:has_doau_modeline = v:version > 703 || v:version == 703 && has('patch442')
|
|
|
|
|
2013-07-17 06:30:58 -04:00
|
|
|
" Function: #start {{{1
|
2014-10-04 13:48:10 -04:00
|
|
|
function! sy#start() abort
|
2013-11-25 17:33:31 -05:00
|
|
|
if g:signify_locked
|
|
|
|
return
|
|
|
|
endif
|
|
|
|
|
2015-06-01 06:10:28 -04:00
|
|
|
let sy_path = resolve(expand('%:p'))
|
2014-10-04 13:48:10 -04:00
|
|
|
|
2016-03-03 06:50:55 -05:00
|
|
|
if s:skip(sy_path)
|
2015-06-01 06:04:50 -04:00
|
|
|
if exists('b:sy')
|
|
|
|
call sy#sign#remove_all_signs(bufnr(''))
|
|
|
|
unlet! b:sy b:sy_info
|
|
|
|
endif
|
2013-07-17 06:30:58 -04:00
|
|
|
return
|
|
|
|
endif
|
|
|
|
|
2016-10-06 18:51:19 -04:00
|
|
|
|
|
|
|
function! s:chdir()
|
2016-12-30 23:13:13 -05:00
|
|
|
return haslocaldir() ? 'lcd' : (exists(':tcd') && haslocaldir(-1, 0)) ? 'tcd' : 'cd'
|
2016-10-06 18:51:19 -04:00
|
|
|
endfunction
|
|
|
|
|
2015-05-20 08:00:39 -04:00
|
|
|
" sy_info is used in autoload/sy/repo
|
2015-06-01 05:13:28 -04:00
|
|
|
let b:sy_info = {
|
2016-10-06 18:51:19 -04:00
|
|
|
\ 'chdir': s:chdir(),
|
2015-06-01 05:13:28 -04:00
|
|
|
\ 'cwd': fnameescape(getcwd()),
|
2015-06-01 06:10:28 -04:00
|
|
|
\ 'dir': fnamemodify(sy_path, ':p:h'),
|
|
|
|
\ 'path': sy#util#escape(sy_path),
|
|
|
|
\ 'file': sy#util#escape(fnamemodify(sy_path, ':t')),
|
2015-06-01 05:13:28 -04:00
|
|
|
\ }
|
2015-05-20 08:00:39 -04:00
|
|
|
|
2013-07-29 10:14:49 -04:00
|
|
|
" new buffer.. add to list of registered files
|
2015-06-01 06:10:28 -04:00
|
|
|
if !exists('b:sy') || b:sy.path != sy_path
|
2014-10-04 09:55:49 -04:00
|
|
|
let b:sy = {
|
2015-06-01 06:10:28 -04:00
|
|
|
\ 'path' : sy_path,
|
2014-10-04 09:55:49 -04:00
|
|
|
\ 'buffer': bufnr(''),
|
|
|
|
\ 'active': 0,
|
|
|
|
\ 'type' : 'unknown',
|
|
|
|
\ 'hunks' : [],
|
|
|
|
\ 'id_top': g:id_top,
|
|
|
|
\ 'stats' : [-1, -1, -1] }
|
2013-07-29 10:14:49 -04:00
|
|
|
if get(g:, 'signify_disable_by_default')
|
2013-07-17 06:30:58 -04:00
|
|
|
return
|
|
|
|
endif
|
2013-07-29 10:14:49 -04:00
|
|
|
|
2013-11-21 20:57:43 -05:00
|
|
|
" register buffer as active
|
|
|
|
let b:sy.active = 1
|
|
|
|
|
|
|
|
let [ diff, b:sy.type ] = sy#repo#detect()
|
|
|
|
if b:sy.type == 'unknown'
|
2016-01-14 20:04:59 -05:00
|
|
|
call sy#disable()
|
2013-07-17 06:30:58 -04:00
|
|
|
return
|
|
|
|
endif
|
2013-07-29 10:14:49 -04:00
|
|
|
|
2013-11-03 12:50:42 -05:00
|
|
|
" register file as active with found VCS
|
2013-11-21 20:57:43 -05:00
|
|
|
let b:sy.stats = [0, 0, 0]
|
2013-08-01 05:40:41 -04:00
|
|
|
|
2013-11-21 20:57:43 -05:00
|
|
|
let dir = fnamemodify(b:sy.path, ':h')
|
2013-09-12 19:23:05 -04:00
|
|
|
if !has_key(g:sy_cache, dir)
|
2013-11-21 20:57:43 -05:00
|
|
|
let g:sy_cache[dir] = b:sy.type
|
2013-09-12 19:23:05 -04:00
|
|
|
endif
|
|
|
|
|
2013-11-03 12:50:42 -05:00
|
|
|
if empty(diff)
|
|
|
|
" no changes found
|
|
|
|
return
|
|
|
|
endif
|
|
|
|
|
2013-07-17 06:30:58 -04:00
|
|
|
" inactive buffer.. bail out
|
2013-11-21 20:57:43 -05:00
|
|
|
elseif !b:sy.active
|
2013-07-17 06:30:58 -04:00
|
|
|
return
|
2013-08-01 05:40:41 -04:00
|
|
|
|
2013-11-03 12:50:42 -05:00
|
|
|
" retry detecting VCS
|
2013-11-21 20:57:43 -05:00
|
|
|
elseif b:sy.type == 'unknown'
|
|
|
|
let [ diff, b:sy.type ] = sy#repo#detect()
|
|
|
|
if b:sy.type == 'unknown'
|
2013-11-03 12:50:42 -05:00
|
|
|
" no VCS found
|
2016-01-14 20:04:59 -05:00
|
|
|
call sy#disable()
|
2013-08-01 05:40:41 -04:00
|
|
|
return
|
|
|
|
endif
|
|
|
|
|
2013-07-17 06:30:58 -04:00
|
|
|
" update signs
|
|
|
|
else
|
2013-11-21 20:57:43 -05:00
|
|
|
let diff = sy#repo#get_diff_{b:sy.type}()[1]
|
|
|
|
let b:sy.id_top = g:id_top
|
2013-07-17 06:30:58 -04:00
|
|
|
endif
|
|
|
|
|
|
|
|
if get(g:, 'signify_line_highlight')
|
2014-10-04 09:55:49 -04:00
|
|
|
call sy#highlight#line_enable()
|
2014-10-04 10:20:17 -04:00
|
|
|
else
|
2014-10-04 09:55:49 -04:00
|
|
|
call sy#highlight#line_disable()
|
2013-07-17 06:30:58 -04:00
|
|
|
endif
|
|
|
|
|
2014-10-04 09:55:49 -04:00
|
|
|
call sy#sign#process_diff(diff)
|
2013-07-17 06:30:58 -04:00
|
|
|
|
2013-11-21 20:57:43 -05:00
|
|
|
let b:sy.id_top = (g:id_top - 1)
|
2016-03-31 10:47:33 -04:00
|
|
|
|
2016-07-21 10:56:39 -04:00
|
|
|
if exists('#User#Signify')
|
|
|
|
execute 'doautocmd' (s:has_doau_modeline ? '<nomodeline>' : '') 'User Signify'
|
|
|
|
endif
|
2013-07-17 06:30:58 -04:00
|
|
|
endfunction
|
|
|
|
|
|
|
|
" Function: #stop {{{1
|
2014-11-25 11:25:40 -05:00
|
|
|
function! sy#stop(bufnr) abort
|
|
|
|
let sy = getbufvar(a:bufnr, 'sy')
|
|
|
|
if empty(sy)
|
2013-07-17 06:30:58 -04:00
|
|
|
return
|
|
|
|
endif
|
|
|
|
|
2014-11-25 11:25:40 -05:00
|
|
|
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
|
2014-10-04 09:55:49 -04:00
|
|
|
if !exists('b:sy')
|
2014-10-24 05:39:05 -04:00
|
|
|
call sy#start()
|
2013-07-17 06:30:58 -04:00
|
|
|
return
|
|
|
|
endif
|
|
|
|
|
2016-01-06 18:00:21 -05:00
|
|
|
if !b:sy.active
|
|
|
|
let b:sy.active = 1
|
|
|
|
call sy#start()
|
|
|
|
endif
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
" Function: #disable {{{1
|
|
|
|
function! sy#disable() abort
|
|
|
|
if exists('b:sy') && b:sy.active
|
2014-11-25 11:25:40 -05:00
|
|
|
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
|
2016-01-15 06:56:20 -05:00
|
|
|
|
|
|
|
" 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
|
2016-01-15 06:56:20 -05:00
|
|
|
endfunction
|
2016-03-03 06:50:55 -05:00
|
|
|
|
|
|
|
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
|