Move Sy's data from g:sy to b:sy

This commit is contained in:
James McCoy 2013-11-21 20:57:43 -05:00 committed by Marco Hinz
parent 1c762af02e
commit 5211c19ee7
7 changed files with 104 additions and 125 deletions

View File

@ -26,26 +26,26 @@ function! sy#start(path) abort
endif endif
" new buffer.. add to list of registered files " new buffer.. add to list of registered files
if !has_key(g:sy, a:path) 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] }
if get(g:, 'signify_disable_by_default') if get(g:, 'signify_disable_by_default')
" register file as inactive
let g:sy[a:path] = { 'active': 0, 'type': 'unknown', 'hunks': [], 'id_top': g:id_top, 'stats': [-1, -1, -1] }
return return
endif endif
let [ diff, type ] = sy#repo#detect(a:path) " register buffer as active
if type == 'unknown' let b:sy.active = 1
" register file as active with no found VCS
let g:sy[a:path] = { 'active': 1, 'type': 'unknown', 'hunks': [], 'id_top': g:id_top, 'stats': [0, 0, 0] } let [ diff, b:sy.type ] = sy#repo#detect()
if b:sy.type == 'unknown'
return return
endif endif
" register file as active with found VCS " register file as active with found VCS
let g:sy[a:path] = { 'active': 1, 'type': type, 'hunks': [], 'id_top': g:id_top, 'stats': [0, 0, 0] } let b:sy.stats = [0, 0, 0]
let dir = fnamemodify(a:path, ':h') let dir = fnamemodify(b:sy.path, ':h')
if !has_key(g:sy_cache, dir) if !has_key(g:sy_cache, dir)
let g:sy_cache[dir] = type let g:sy_cache[dir] = b:sy.type
endif endif
if empty(diff) if empty(diff)
@ -54,26 +54,25 @@ function! sy#start(path) abort
endif endif
" inactive buffer.. bail out " inactive buffer.. bail out
elseif !g:sy[a:path].active elseif !b:sy.active
return return
" retry detecting VCS " retry detecting VCS
elseif g:sy[a:path].type == 'unknown' elseif b:sy.type == 'unknown'
let [ diff, type ] = sy#repo#detect(a:path) let [ diff, b:sy.type ] = sy#repo#detect()
if type == 'unknown' if b:sy.type == 'unknown'
" no VCS found " no VCS found
return return
endif endif
let g:sy[a:path].type = type
" update signs " update signs
else else
let diff = sy#repo#get_diff_{g:sy[a:path].type}(a:path)[1] let diff = sy#repo#get_diff_{b:sy.type}()[1]
if empty(diff) if empty(diff)
call sy#sign#remove_all(a:path) call sy#sign#remove_all(b:sy.buffer)
return return
endif endif
let g:sy[a:path].id_top = g:id_top let b:sy.id_top = g:id_top
endif endif
if get(g:, 'signify_line_highlight') if get(g:, 'signify_line_highlight')
@ -82,52 +81,46 @@ function! sy#start(path) abort
call sy#highlight#line_disable() call sy#highlight#line_disable()
endif endif
execute 'sign place 99999 line=1 name=SignifyPlaceholder file='. a:path execute 'sign place 99999 line=1 name=SignifyPlaceholder buffer='. b:sy.buffer
call sy#sign#remove_all(a:path) call sy#sign#remove_all(b:sy.buffer)
if !g:signify_sign_overwrite if !g:signify_sign_overwrite
call sy#sign#get_others(a:path) call sy#sign#get_others()
endif endif
call sy#repo#process_diff(a:path, diff) call sy#repo#process_diff(diff)
sign unplace 99999 sign unplace 99999
let g:sy[a:path].id_top = (g:id_top - 1) let b:sy.id_top = (g:id_top - 1)
endfunction endfunction
" Function: #stop {{{1 " Function: #stop {{{1
function! sy#stop(path) abort function! sy#stop(bnum) abort
if !has_key(g:sy, a:path) let bvars = getbufvar(a:bnum, '', {})
if !has_key(bvars, 'sy')
return return
endif endif
call sy#sign#remove_all(a:path) call sy#sign#remove_all(a:bnum)
silent! nunmap <buffer> ]c
silent! nunmap <buffer> [c
augroup signify augroup signify
autocmd! * <buffer> execute 'autocmd! * <buffer='. a:bnum .'>'
augroup END augroup END
endfunction endfunction
" Function: #toggle {{{1 " Function: #toggle {{{1
function! sy#toggle() abort function! sy#toggle() abort
if empty(g:sy_path) if empty(b:sy.path)
echomsg 'signify: I cannot sy empty buffers!' echomsg 'signify: I cannot sy empty buffers!'
return return
endif endif
if has_key(g:sy, g:sy_path) if b:sy.active
if g:sy[g:sy_path].active call sy#stop(b:sy.buffer)
call sy#stop(g:sy_path) let b:sy.active = 0
let g:sy[g:sy_path].active = 0 let b:sy.stats = [-1, -1, -1]
let g:sy[g:sy_path].stats = [-1, -1, -1]
else else
let g:sy[g:sy_path].active = 1 let b:sy.active = 1
call sy#start(g:sy_path) call sy#start(b:sy.path)
endif
else
call sy#start(g:sy_path)
endif endif
endfunction endfunction

View File

@ -4,15 +4,16 @@ scriptencoding utf-8
" Function: #list_active_buffers {{{1 " Function: #list_active_buffers {{{1
function! sy#debug#list_active_buffers() abort function! sy#debug#list_active_buffers() abort
if empty(g:sy) for b in range(bufnr('$'))
echomsg 'No active buffers!' if !buflisted(b) || empty(getbufvar(b, 'sy', {}))
return continue
endif endif
for [path, stats] in items(g:sy) let sy = copy(getbufvar(b, 'sy'))
let path = remove(sy, 'path')
echo "\n". path ."\n". repeat('=', strlen(path)) echo "\n". path ."\n". repeat('=', strlen(path))
for stat in sort(keys(stats)) for stat in sort(keys(sy))
echo printf("%20s = %s\n", stat, string(stats[stat])) echo printf("%20s = %s\n", stat, string(sy[stat]))
endfor endfor
endfor endfor
endfunction endfunction

View File

@ -85,7 +85,7 @@ endfunction
" Function: #line_toggle {{{1 " Function: #line_toggle {{{1
function! sy#highlight#line_toggle() abort function! sy#highlight#line_toggle() abort
if !has_key(g:sy, g:sy_path) if !exists('b:sy')
echomsg 'signify: I cannot detect any changes!' echomsg 'signify: I cannot detect any changes!'
return return
endif endif
@ -96,5 +96,5 @@ function! sy#highlight#line_toggle() abort
call sy#highlight#line_enable() call sy#highlight#line_enable()
endif endif
call sy#start(g:sy_path) call sy#start(b:sy.path)
endfunction endfunction

View File

@ -4,32 +4,32 @@ scriptencoding utf-8
" Function: #next_hunk {{{1 " Function: #next_hunk {{{1
function! sy#jump#next_hunk(count) function! sy#jump#next_hunk(count)
if !has_key(g:sy, g:sy_path) if !exists('b:sy')
echomsg 'signify: I cannot detect any changes!' echomsg 'signify: I cannot detect any changes!'
return return
endif endif
let lnum = line('.') let lnum = line('.')
let hunks = filter(copy(g:sy[g:sy_path].hunks), 'v:val.start > lnum') let hunks = filter(copy(b:sy.hunks), 'v:val.start > lnum')
let hunk = get(hunks, a:count - 1, get(hunks, -1, {})) let hunk = get(hunks, a:count - 1, get(hunks, -1, {}))
if !empty(hunk) if !empty(hunk)
execute 'sign jump '. hunk.ids[0] .' file='. g:sy_path execute 'sign jump '. hunk.ids[0] .' buffer='. b:sy.buffer
endif endif
endfunction endfunction
" Function: #prev_hunk {{{1 " Function: #prev_hunk {{{1
function! sy#jump#prev_hunk(count) function! sy#jump#prev_hunk(count)
if !has_key(g:sy, g:sy_path) if !exists('b:sy')
echomsg 'signify: I cannot detect any changes!' echomsg 'signify: I cannot detect any changes!'
return return
endif endif
let lnum = line('.') let lnum = line('.')
let hunks = filter(copy(g:sy[g:sy_path].hunks), 'v:val.start < lnum') let hunks = filter(copy(b:sy.hunks), 'v:val.start < lnum')
let hunk = get(hunks, 0 - a:count, get(hunks, 0, {})) let hunk = get(hunks, 0 - a:count, get(hunks, 0, {}))
if !empty(hunk) if !empty(hunk)
execute 'sign jump '. hunk.ids[0] .' file='. g:sy_path execute 'sign jump '. hunk.ids[0] .' buffer='. b:sy.buffer
endif endif
endfunction endfunction

View File

@ -41,8 +41,8 @@ if empty(s:vcs_list)
endif endif
" Function: #detect {{{1 " Function: #detect {{{1
function! sy#repo#detect(path) abort function! sy#repo#detect() abort
let dir = fnamemodify(a:path, ':h') let dir = fnamemodify(b:sy.path, ':h')
" Simple cache. If there is a registered VCS-controlled file in this " Simple cache. If there is a registered VCS-controlled file in this
" directory already, assume that this file is probably controlled by " directory already, assume that this file is probably controlled by
@ -56,7 +56,7 @@ function! sy#repo#detect(path) abort
endif endif
for type in s:vcs_list for type in s:vcs_list
let [istype, diff] = sy#repo#get_diff_{type}(a:path) let [istype, diff] = sy#repo#get_diff_{type}()
if istype if istype
return [ diff, type ] return [ diff, type ]
endif endif
@ -66,9 +66,9 @@ function! sy#repo#detect(path) abort
endfunction endfunction
" Function: #get_diff_git {{{1 " Function: #get_diff_git {{{1
function! sy#repo#get_diff_git(path) abort function! sy#repo#get_diff_git() abort
let diffoptions = has_key(g:signify_diffoptions, 'git') ? g:signify_diffoptions.git : '' let diffoptions = has_key(g:signify_diffoptions, 'git') ? g:signify_diffoptions.git : ''
let diff = system('cd '. sy#util#escape(fnamemodify(a:path, ':h')) .' && git diff --no-color --no-ext-diff -U0 '. diffoptions .' -- '. sy#util#escape(fnamemodify(a:path, ':t'))) let diff = system('cd '. sy#util#escape(fnamemodify(b:sy.path, ':h')) .' && git diff --no-color --no-ext-diff -U0 '. diffoptions .' -- '. sy#util#escape(fnamemodify(b:sy.path, ':t')))
return v:shell_error ? [0, ''] : [1, diff] return v:shell_error ? [0, ''] : [1, diff]
endfunction endfunction
@ -76,9 +76,9 @@ endfunction
" Function: #get_stat_git {{{1 " Function: #get_stat_git {{{1
function! sy#repo#get_stat_git() abort function! sy#repo#get_stat_git() abort
let s:stats = [] let s:stats = []
let root = finddir('.git', fnamemodify(g:sy_path, ':h') .';') let root = finddir('.git', fnamemodify(b:sy.path, ':h') .';')
if empty(root) if empty(root)
echohl ErrorMsg | echomsg 'Cannot find the git root directory: '. g:sy_path | echohl None echohl ErrorMsg | echomsg 'Cannot find the git root directory: '. b:sy.path | echohl None
return return
endif endif
let root = fnamemodify(root, ':h') let root = fnamemodify(root, ':h')
@ -105,73 +105,73 @@ function! sy#repo#get_stat_git() abort
endfunction endfunction
" Function: #get_diff_hg {{{1 " Function: #get_diff_hg {{{1
function! sy#repo#get_diff_hg(path) abort function! sy#repo#get_diff_hg() abort
let diffoptions = has_key(g:signify_diffoptions, 'hg') ? g:signify_diffoptions.hg : '' let diffoptions = has_key(g:signify_diffoptions, 'hg') ? g:signify_diffoptions.hg : ''
let diff = system('hg diff --nodates -U0 '. diffoptions .' -- '. sy#util#escape(a:path)) let diff = system('hg diff --nodates -U0 '. diffoptions .' -- '. sy#util#escape(b:sy.path))
return v:shell_error ? [0, ''] : [1, diff] return v:shell_error ? [0, ''] : [1, diff]
endfunction endfunction
" Function: #get_diff_svn {{{1 " Function: #get_diff_svn {{{1
function! sy#repo#get_diff_svn(path) abort function! sy#repo#get_diff_svn() abort
let diffoptions = has_key(g:signify_diffoptions, 'svn') ? g:signify_diffoptions.svn : '' let diffoptions = has_key(g:signify_diffoptions, 'svn') ? g:signify_diffoptions.svn : ''
let diff = system('svn diff --diff-cmd '. s:difftool .' -x -U0 '. diffoptions .' -- '. sy#util#escape(a:path)) let diff = system('svn diff --diff-cmd '. s:difftool .' -x -U0 '. diffoptions .' -- '. sy#util#escape(b:sy.path))
return v:shell_error ? [0, ''] : [1, diff] return v:shell_error ? [0, ''] : [1, diff]
endfunction endfunction
" Function: #get_diff_bzr {{{1 " Function: #get_diff_bzr {{{1
function! sy#repo#get_diff_bzr(path) abort function! sy#repo#get_diff_bzr() abort
let diffoptions = has_key(g:signify_diffoptions, 'bzr') ? g:signify_diffoptions.bzr : '' let diffoptions = has_key(g:signify_diffoptions, 'bzr') ? g:signify_diffoptions.bzr : ''
let diff = system('bzr diff --using '. s:difftool .' --diff-options=-U0 '. diffoptions .' -- '. sy#util#escape(a:path)) let diff = system('bzr diff --using '. s:difftool .' --diff-options=-U0 '. diffoptions .' -- '. sy#util#escape(b:sy.path))
return (v:shell_error =~ '[012]') ? [1, diff] : [0, ''] return (v:shell_error =~ '[012]') ? [1, diff] : [0, '']
endfunction endfunction
" Function: #get_diff_darcs {{{1 " Function: #get_diff_darcs {{{1
function! sy#repo#get_diff_darcs(path) abort function! sy#repo#get_diff_darcs() abort
let diffoptions = has_key(g:signify_diffoptions, 'darcs') ? g:signify_diffoptions.darcs : '' let diffoptions = has_key(g:signify_diffoptions, 'darcs') ? g:signify_diffoptions.darcs : ''
let diff = system('cd '. sy#util#escape(fnamemodify(a:path, ':h')) .' && darcs diff --no-pause-for-gui --diff-command="'. s:difftool .' -U0 %1 %2 '. diffoptions .'" -- '. sy#util#escape(a:path)) let diff = system('cd '. sy#util#escape(fnamemodify(b:sy.path, ':h')) .' && darcs diff --no-pause-for-gui --diff-command="'. s:difftool .' -U0 %1 %2 '. diffoptions .'" -- '. sy#util#escape(b:sy.path))
return v:shell_error ? [0, ''] : [1, diff] return v:shell_error ? [0, ''] : [1, diff]
endfunction endfunction
" Function: #get_diff_fossil {{{1 " Function: #get_diff_fossil {{{1
function! sy#repo#get_diff_fossil(path) abort function! sy#repo#get_diff_fossil() abort
let diffoptions = has_key(g:signify_diffoptions, 'fossil') ? g:signify_diffoptions.fossil : '' let diffoptions = has_key(g:signify_diffoptions, 'fossil') ? g:signify_diffoptions.fossil : ''
let diff = system('cd '. sy#util#escape(fnamemodify(a:path, ':h')) .' && fossil set diff-command "'. s:difftool .' -U 0" && fossil diff --unified -c 0 '. diffoptions .' -- '. sy#util#escape(a:path)) let diff = system('cd '. sy#util#escape(fnamemodify(b:sy.path, ':h')) .' && fossil set diff-command "'. s:difftool .' -U 0" && fossil diff --unified -c 0 '. diffoptions .' -- '. sy#util#escape(b:sy.path))
return v:shell_error ? [0, ''] : [1, diff] return v:shell_error ? [0, ''] : [1, diff]
endfunction endfunction
" Function: #get_diff_cvs {{{1 " Function: #get_diff_cvs {{{1
function! sy#repo#get_diff_cvs(path) abort function! sy#repo#get_diff_cvs() abort
let diffoptions = has_key(g:signify_diffoptions, 'cvs') ? g:signify_diffoptions.cvs : '' let diffoptions = has_key(g:signify_diffoptions, 'cvs') ? g:signify_diffoptions.cvs : ''
let diff = system('cd '. sy#util#escape(fnamemodify(a:path, ':h')) .' && cvs diff -U0 '. diffoptions .' -- '. sy#util#escape(fnamemodify(a:path, ':t'))) let diff = system('cd '. sy#util#escape(fnamemodify(b:sy.path, ':h')) .' && cvs diff -U0 '. diffoptions .' -- '. sy#util#escape(fnamemodify(b:sy.path, ':t')))
return ((v:shell_error == 1) && (diff =~ '+++')) ? [1, diff] : [0, ''] return ((v:shell_error == 1) && (diff =~ '+++')) ? [1, diff] : [0, '']
endfunction endfunction
" Function: #get_diff_rcs {{{1 " Function: #get_diff_rcs {{{1
function! sy#repo#get_diff_rcs(path) abort function! sy#repo#get_diff_rcs() abort
let diffoptions = has_key(g:signify_diffoptions, 'rcs') ? g:signify_diffoptions.rcs : '' let diffoptions = has_key(g:signify_diffoptions, 'rcs') ? g:signify_diffoptions.rcs : ''
let diff = system('rcsdiff -U0 '. diffoptions .' '. sy#util#escape(a:path) .' 2>/dev/null') let diff = system('rcsdiff -U0 '. diffoptions .' '. sy#util#escape(b:sy.path) .' 2>/dev/null')
return v:shell_error ? [0, ''] : [1, diff] return v:shell_error ? [0, ''] : [1, diff]
endfunction endfunction
" Function: #get_diff_accurev {{{1 " Function: #get_diff_accurev {{{1
function! sy#repo#get_diff_accurev(path) abort function! sy#repo#get_diff_accurev() abort
let diffoptions = has_key(g:signify_diffoptions, 'accurev') ? g:signify_diffoptions.accurev : '' let diffoptions = has_key(g:signify_diffoptions, 'accurev') ? g:signify_diffoptions.accurev : ''
let diff = system('cd '. sy#util#escape(fnamemodify(a:path, ':h')) .' && accurev diff '. sy#util#escape(fnamemodify(a:path, ':t')) . ' -- -U0 '. diffoptions) let diff = system('cd '. sy#util#escape(fnamemodify(b:sy.path, ':h')) .' && accurev diff '. sy#util#escape(fnamemodify(b:sy.path, ':t')) . ' -- -U0 '. diffoptions)
return (v:shell_error != 1) ? [0, ''] : [1, diff] return (v:shell_error != 1) ? [0, ''] : [1, diff]
endfunction endfunction
" Function: #get_diff_perforce {{{1 " Function: #get_diff_perforce {{{1
function! sy#repo#get_diff_perforce(path) abort function! sy#repo#get_diff_perforce() abort
let diffoptions = has_key(s:diffoptions, 'perforce') ? s:diffoptions.perforce : '' let diffoptions = has_key(s:diffoptions, 'perforce') ? s:diffoptions.perforce : ''
let diff = system('env P4DIFF=diff p4 diff -dU0 '. diffoptions .' '. sy#util#escape(a:path)) let diff = system('env P4DIFF=diff p4 diff -dU0 '. diffoptions .' '. sy#util#escape(b:sy.path))
return v:shell_error ? [0, ''] : [1, diff] return v:shell_error ? [0, ''] : [1, diff]
endfunction endfunction
" Function: #process_diff {{{1 " Function: #process_diff {{{1
function! sy#repo#process_diff(path, diff) abort function! sy#repo#process_diff(diff) abort
let added = 0 let added = 0
let deleted = 0 let deleted = 0
let modified = 0 let modified = 0
@ -201,8 +201,7 @@ function! sy#repo#process_diff(path, diff) abort
while offset < new_count while offset < new_count
call add(signs, { call add(signs, {
\ 'type': 'SignifyAdd', \ 'type': 'SignifyAdd',
\ 'lnum': new_line + offset, \ 'lnum': new_line + offset })
\ 'path': a:path })
let offset += 1 let offset += 1
endwhile endwhile
@ -218,13 +217,11 @@ function! sy#repo#process_diff(path, diff) abort
if new_line == 0 if new_line == 0
call add(signs, { call add(signs, {
\ 'type': 'SignifyDeleteFirstLine', \ 'type': 'SignifyDeleteFirstLine',
\ 'lnum': 1, \ 'lnum': 1 })
\ 'path': a:path })
else else
call add(signs, { call add(signs, {
\ 'type': (old_count > 9) ? 'SignifyDeleteMore' : 'SignifyDelete'. old_count, \ 'type': (old_count > 9) ? 'SignifyDeleteMore' : 'SignifyDelete'. old_count,
\ 'lnum': new_line, \ 'lnum': new_line })
\ 'path': a:path })
endif endif
" 2 lines changed: " 2 lines changed:
@ -242,8 +239,7 @@ function! sy#repo#process_diff(path, diff) abort
while offset < new_count while offset < new_count
call add(signs, { call add(signs, {
\ 'type': 'SignifyChange', \ 'type': 'SignifyChange',
\ 'lnum': new_line + offset, \ 'lnum': new_line + offset })
\ 'path': a:path })
let offset += 1 let offset += 1
endwhile endwhile
else else
@ -267,15 +263,13 @@ function! sy#repo#process_diff(path, diff) abort
while offset < (new_count - 1) while offset < (new_count - 1)
call add(signs, { call add(signs, {
\ 'type': 'SignifyChange', \ 'type': 'SignifyChange',
\ 'lnum': new_line + offset, \ 'lnum': new_line + offset })
\ 'path': a:path })
let offset += 1 let offset += 1
endwhile endwhile
call add(signs, { call add(signs, {
\ 'type': (removed > 9) ? 'SignifyChangeDeleteMore' : 'SignifyChangeDelete'. removed, \ 'type': (removed > 9) ? 'SignifyChangeDeleteMore' : 'SignifyChangeDelete'. removed,
\ 'lnum': new_line, \ 'lnum': new_line })
\ 'path': a:path })
" lines changed and added: " lines changed and added:
@ -293,16 +287,14 @@ function! sy#repo#process_diff(path, diff) abort
while offset < old_count while offset < old_count
call add(signs, { call add(signs, {
\ 'type': 'SignifyChange', \ 'type': 'SignifyChange',
\ 'lnum': new_line + offset, \ 'lnum': new_line + offset })
\ 'path': a:path })
let offset += 1 let offset += 1
endwhile endwhile
while offset < new_count while offset < new_count
call add(signs, { call add(signs, {
\ 'type': 'SignifyAdd', \ 'type': 'SignifyAdd',
\ 'lnum': new_line + offset, \ 'lnum': new_line + offset })
\ 'path': a:path })
let offset += 1 let offset += 1
endwhile endwhile
endif endif
@ -311,14 +303,14 @@ function! sy#repo#process_diff(path, diff) abort
call sy#sign#set(signs) call sy#sign#set(signs)
endfor endfor
let g:sy[g:sy_path].stats = [added, modified, deleted] let b:sy.stats = [added, modified, deleted]
endfunction endfunction
" Function: #get_stats {{{1 " Function: #get_stats {{{1
function! sy#repo#get_stats() abort function! sy#repo#get_stats() abort
if !exists('g:sy_path') || !has_key(g:sy, g:sy_path) if !exists('b:sy') || !has_key(b:sy, 'stats')
return [-1, -1, -1] return [-1, -1, -1]
endif endif
return g:sy[g:sy_path].stats return b:sy.stats
endfunction endfunction

View File

@ -3,14 +3,14 @@
scriptencoding utf-8 scriptencoding utf-8
" Function: #get_others {{{1 " Function: #get_others {{{1
function! sy#sign#get_others(path) abort function! sy#sign#get_others() abort
let s:other_signs_line_numbers = {} let s:other_signs_line_numbers = {}
let lang = v:lang let lang = v:lang
silent! execute 'language C' silent! execute 'language C'
redir => signlist redir => signlist
silent! execute 'sign place file='. a:path silent! execute 'sign place buffer='. b:sy.buffer
redir END redir END
for line in filter(split(signlist, '\n'), 'v:val =~ "^\\s\\+line"') for line in filter(split(signlist, '\n'), 'v:val =~ "^\\s\\+line"')
@ -32,26 +32,27 @@ function! sy#sign#set(signs)
endif endif
call add(hunk.ids, g:id_top) call add(hunk.ids, g:id_top)
execute 'sign place' g:id_top 'line='. sign.lnum 'name='. sign.type 'file='. sign.path execute 'sign place' g:id_top 'line='. sign.lnum 'name='. sign.type 'buffer='. b:sy.buffer
let g:id_top += 1 let g:id_top += 1
endfor endfor
call add(g:sy[sign.path].hunks, hunk) call add(b:sy.hunks, hunk)
endfunction endfunction
" Function: #remove_all {{{1 " Function: #remove_all {{{1
function! sy#sign#remove_all(path) abort function! sy#sign#remove_all(bnum) abort
let sy = getbufvar(a:bnum, 'sy')
if g:signify_sign_overwrite if g:signify_sign_overwrite
execute 'sign unplace * file='. a:path execute 'sign unplace * buffer='. sy.buffer
else else
for hunk in g:sy[a:path].hunks for hunk in sy.hunks
for id in hunk.ids for id in hunk.ids
execute 'sign unplace' id execute 'sign unplace' id
endfor endfor
endfor endfor
endif endif
let g:sy[a:path].hunks = [] let sy.hunks = []
let g:sy[a:path].stats = [0, 0, 0] let sy.stats = [0, 0, 0]
endfunction endfunction

View File

@ -7,47 +7,39 @@ if exists('g:loaded_signify') || !has('signs') || &cp
endif endif
let g:loaded_signify = 1 let g:loaded_signify = 1
" Init: values {{{1
let g:sy = {}
" Init: autocmds {{{1 " Init: autocmds {{{1
augroup signify augroup signify
autocmd! autocmd!
autocmd VimEnter * call sy#highlight#setup() autocmd VimEnter * call sy#highlight#setup()
autocmd BufRead,BufEnter * let g:sy_path = resolve(expand('<afile>:p')) autocmd BufRead,BufEnter * let b:sy_path = resolve(expand('<afile>:p'))
autocmd BufRead,BufWritePost * call sy#start(g:sy_path) autocmd BufRead,BufWritePost * call sy#start(b:sy_path)
autocmd BufDelete * autocmd BufDelete * call sy#stop(expand('<abuf>'))
\ let path = resolve(expand('<afile>:p')) |
\ call sy#stop(path) |
\ if has_key(g:sy, path) |
\ call remove(g:sy, path) |
\ endif
if get(g:, 'signify_update_on_bufenter') if get(g:, 'signify_update_on_bufenter')
autocmd BufEnter * nested autocmd BufEnter * nested
\ if has_key(g:sy, g:sy_path) && g:sy[g:sy_path].active && &modified | \ if exists('b:sy') && b:sy.active && &modified |
\ write | \ write |
\ endif \ endif
endif endif
if get(g:, 'signify_cursorhold_normal') if get(g:, 'signify_cursorhold_normal')
autocmd CursorHold * nested autocmd CursorHold * nested
\ if has_key(g:sy, g:sy_path) && g:sy[g:sy_path].active && &modified | \ if exists('b:sy') && b:sy.active && &modified |
\ write | \ write |
\ endif \ endif
endif endif
if get(g:, 'signify_cursorhold_insert') if get(g:, 'signify_cursorhold_insert')
autocmd CursorHoldI * nested autocmd CursorHoldI * nested
\ if has_key(g:sy, g:sy_path) && g:sy[g:sy_path].active && &modified | \ if exists('b:sy') && b:sy.active && &modified |
\ write | \ write |
\ endif \ endif
endif endif
if get(g:, 'signify_update_on_focusgained') && !has('gui_win32') if get(g:, 'signify_update_on_focusgained') && !has('gui_win32')
autocmd FocusGained * call sy#start(g:sy_path) autocmd FocusGained * if exists('b:sy') | call sy#start(b:sy.path) | endif
endif endif
augroup END augroup END