vim-signify/autoload/sy.vim

120 lines
2.9 KiB
VimL
Raw Normal View History

scriptencoding utf-8
2013-07-17 06:30:58 -04:00
if exists('b:autoloaded_sy')
finish
endif
let b:autoloaded_sy = 1
2013-07-17 06:44:21 -04:00
" Init: values {{{1
2013-07-17 06:30:58 -04:00
let g:signify_sign_overwrite = get(g:, 'signify_sign_overwrite', 1)
let g:id_top = 0x100
sign define SignifyPlaceholder text=. texthl=SignifySignChange linehl=
2013-07-17 06:30:58 -04:00
" Function: #start {{{1
function! sy#start(path) abort
2013-07-17 07:45:06 -04:00
if &diff
\ || !filereadable(a:path)
2013-07-17 06:30:58 -04:00
\ || (exists('g:signify_skip_filetype') && has_key(g:signify_skip_filetype, &ft))
\ || (exists('g:signify_skip_filename') && has_key(g:signify_skip_filename, a:path))
return
endif
2013-07-29 10:14:49 -04:00
" new buffer.. add to list of registered files
if !has_key(g:sy, a:path)
2013-07-29 10:14:49 -04:00
if get(g:, 'signify_disable_by_default')
2013-08-22 13:06:02 -04:00
let g:sy[a:path] = { 'active': 0, 'type': 'unknown', 'hunks': [], 'id_top': g:id_top, 'stats': [-1, -1, -1] }
2013-07-17 06:30:58 -04:00
return
endif
2013-07-29 10:14:49 -04:00
let [ diff, type ] = sy#repo#detect(a:path)
if empty(diff)
" register file as active with either no changes or no found VCS
2013-08-20 06:50:36 -04:00
let g:sy[a:path] = { 'active': 1, 'type': 'unknown', 'hunks': [], 'id_top': g:id_top, 'stats': [0, 0, 0] }
2013-07-17 06:30:58 -04:00
return
endif
2013-07-29 10:14:49 -04:00
" register file as active and containing changes
2013-08-20 06:50:36 -04:00
let g:sy[a:path] = { 'active': 1, 'type': type, 'hunks': [], 'id_top': g:id_top, 'stats': [0, 0, 0] }
2013-07-17 06:30:58 -04:00
" inactive buffer.. bail out
elseif !g:sy[a:path].active
return
" retry detecting changes or VCS
elseif g:sy[a:path].type == 'unknown'
let [ diff, type ] = sy#repo#detect(a:path)
if empty(diff)
" no changes or VCS found
return
endif
let g:sy[a:path].type = type
2013-07-17 06:30:58 -04:00
" update signs
else
let diff = sy#repo#get_diff_{g:sy[a:path].type}(a:path)
if empty(diff)
call sy#sign#remove_all(a:path)
return
endif
let g:sy[a:path].id_top = g:id_top
endif
if get(g:, 'signify_line_highlight')
call sy#highlight#line_enable()
else
call sy#highlight#line_disable()
endif
if !g:signify_sign_overwrite
call sy#sign#get_others(a:path)
endif
execute 'sign place 99999 line=1 name=SignifyPlaceholder file='. a:path
call sy#sign#remove_all(a:path)
call sy#repo#process_diff(a:path, diff)
sign unplace 99999
let g:sy[a:path].id_top = (g:id_top - 1)
endfunction
" vim: et sw=2 sts=2
" Function: #stop {{{1
function! sy#stop(path) abort
if !has_key(g:sy, a:path)
return
endif
call sy#sign#remove_all(a:path)
silent! nunmap <buffer> ]c
silent! nunmap <buffer> [c
augroup signify
autocmd! * <buffer>
augroup END
endfunction
" Function: #toggle {{{1
function! sy#toggle() abort
if empty(g:sy_path)
echomsg 'signify: I cannot sy empty buffers!'
return
endif
if has_key(g:sy, g:sy_path)
if g:sy[g:sy_path].active
call sy#stop(g:sy_path)
let g:sy[g:sy_path].active = 0
let g:sy[g:sy_path].stats = [-1, -1, -1]
2013-07-17 06:30:58 -04:00
else
let g:sy[g:sy_path].active = 1
call sy#start(g:sy_path)
endif
else
call sy#start(g:sy_path)
endif
endfunction
2013-07-17 06:44:21 -04:00
" vim: et sw=2 sts=2