vim-signify/autoload/sy.vim

126 lines
2.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:44:21 -04:00
" Init: values {{{1
let g:signify_sign_overwrite = get(g:, 'signify_sign_overwrite')
2013-09-30 03:40:46 -04:00
if g:signify_sign_overwrite && (v:version < 703 || (v:version == 703 && !has('patch596')))
echohl WarningMsg
echomsg 'signify: Sign overwriting was disabled. See :help signify-option-sign_overwrite'
2013-09-30 03:40:46 -04:00
echohl NONE
let g:signify_sign_overwrite = 0
endif
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
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
2013-11-21 20:57:43 -05:00
if !exists('b:sy') || b:sy.path != a:path
let b:sy = { 'path': a:path, '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'
2013-07-17 06:30:58 -04:00
return
endif
2013-07-29 10:14:49 -04:00
" register file as active with found VCS
2013-11-21 20:57:43 -05:00
let b:sy.stats = [0, 0, 0]
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
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
" 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'
" no VCS found
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]
2013-07-17 06:30:58 -04:00
if empty(diff)
2013-11-21 20:57:43 -05:00
call sy#sign#remove_all(b:sy.buffer)
2013-07-17 06:30:58 -04:00
return
endif
2013-11-21 20:57:43 -05:00
let b:sy.id_top = g:id_top
2013-07-17 06:30:58 -04:00
endif
if get(g:, 'signify_line_highlight')
call sy#highlight#line_enable()
else
call sy#highlight#line_disable()
endif
2013-11-21 20:57:43 -05:00
execute 'sign place 99999 line=1 name=SignifyPlaceholder buffer='. b:sy.buffer
call sy#sign#remove_all(b:sy.buffer)
2013-07-17 06:30:58 -04:00
if !g:signify_sign_overwrite
2013-11-21 20:57:43 -05:00
call sy#sign#get_others()
2013-07-17 06:30:58 -04:00
endif
2013-11-21 20:57:43 -05:00
call sy#repo#process_diff(diff)
2013-07-17 06:30:58 -04:00
sign unplace 99999
2013-11-21 20:57:43 -05:00
let b:sy.id_top = (g:id_top - 1)
2013-07-17 06:30:58 -04:00
endfunction
" Function: #stop {{{1
2013-11-21 20:57:43 -05:00
function! sy#stop(bnum) abort
if !exists('b:sy')
2013-07-17 06:30:58 -04:00
return
endif
2013-11-21 20:57:43 -05:00
call sy#sign#remove_all(a:bnum)
2013-07-17 06:30:58 -04:00
augroup signify
2013-11-21 20:57:43 -05:00
execute 'autocmd! * <buffer='. a:bnum .'>'
2013-07-17 06:30:58 -04:00
augroup END
endfunction
" Function: #toggle {{{1
function! sy#toggle() abort
2013-11-21 20:57:43 -05:00
if empty(b:sy.path)
2013-07-17 06:30:58 -04:00
echomsg 'signify: I cannot sy empty buffers!'
return
endif
2013-11-21 20:57:43 -05:00
if b:sy.active
call sy#stop(b:sy.buffer)
let b:sy.active = 0
let b:sy.stats = [-1, -1, -1]
2013-07-17 06:30:58 -04:00
else
2013-11-21 20:57:43 -05:00
let b:sy.active = 1
call sy#start(b:sy.path)
2013-07-17 06:30:58 -04:00
endif
endfunction