@@ -23,7 +23,6 @@ function! sy#start(...) abort
2323 let new_sy = {
2424 \ ' path' : path ,
2525 \ ' buffer' : bufnr ,
26- \ ' active' : 0 ,
2726 \ ' detecting' : 0 ,
2827 \ ' vcs' : [],
2928 \ ' hunks' : [],
@@ -36,19 +35,11 @@ function! sy#start(...) abort
3635 \ ' file' : sy#util#escape (fnamemodify (path , ' :t' ))
3736 \ }}
3837 call setbufvar (bufnr , ' sy' , new_sy)
39- if get (g: , ' signify_disable_by_default' )
40- call sy#verbose (' Disabled by default.' )
41- return
42- endif
43- let new_sy.active = 1
44- call setbufvar (bufnr , ' sy' , new_sy)
38+ call sy#set_buflocal_autocmds (bufnr )
4539 call sy#repo#detect (bufnr )
4640 elseif has (' vim_starting' )
4741 call sy#verbose (" Don't run Sy more than once during startup." )
4842 return
49- elseif ! sy .active
50- call sy#verbose (' Inactive buffer.' )
51- return
5243 elseif empty (sy .vcs)
5344 if get (sy , ' retry' )
5445 let sy .retry = 0
@@ -59,7 +50,7 @@ function! sy#start(...) abort
5950 call sy#verbose (' Detection is already in progress.' )
6051 else
6152 call sy#verbose (' No VCS found. Disabling.' )
62- call sy#disable (sy .buffer )
53+ call sy#stop (sy .buffer )
6354 endif
6455 endif
6556 else
@@ -76,50 +67,40 @@ function! sy#start(...) abort
7667endfunction
7768
7869" #stop {{{1
79- function ! sy#stop (bufnr ) abort
80- if empty (getbufvar (a: bufnr , ' sy' ))
81- return
82- endif
83- call sy#sign#remove_all_signs (a: bufnr )
70+ function ! sy#stop (... ) abort
71+ let bufnr = bufnr (' ' )
72+ if empty (getbufvar (a: 0 ? a: 1 : bufnr , ' sy' )) | return | endif
73+ call sy#sign#remove_all_signs (bufnr )
74+ execute printf (' autocmd! signify * <buffer=%d>' , bufnr )
75+ call setbufvar (bufnr , ' sy' , {})
8476endfunction
8577
86- " #enable {{{1
87- function ! sy#enable () abort
88- if ! exists (' b:sy' )
89- call sy#start ()
90- return
91- endif
92-
93- if ! b: sy .active
94- let b: sy .active = 1
95- let b: sy .retry = 1
96- call sy#start ()
97- endif
78+ " #toggle {{{1
79+ function ! sy#toggle () abort
80+ call call (empty (getbufvar (bufnr (' ' ), ' sy' )) ? ' sy#start' : ' sy#stop' , [])
9881endfunction
9982
100- " #disable {{{1
101- function ! sy#disable (... ) abort
102- let sy = getbufvar (a: 0 ? a: 1 : bufnr (' ' ), ' sy' )
103-
104- if ! empty (sy ) && sy .active
105- call sy#stop (sy .buffer )
106- let b: sy .active = 0
107- let b: sy .stats = [-1 , -1 , -1 ]
108- endif
83+ " #start_all {{{1
84+ function ! sy#start_all () abort
85+ for bufnr in range (1 , bufnr (' ' ))
86+ call sy#start ({' bufnr' : bufnr })
87+ endfor
88+ let g: signify_disable_by_default = 0
10989endfunction
11090
111- " #toggle {{{1
112- function ! sy#toggle () abort
113- if ! exists (' b:sy' ) || ! b: sy .active
114- call sy#enable ()
115- else
116- call sy#disable ()
117- endif
91+ " #stop_all {{{1
92+ function ! sy#stop_all () abort
93+ for bufnr in range (1 , bufnr (' ' ))
94+ if ! empty (getbufvar (bufnr , ' sy' ))
95+ call sy#stop (bufnr )
96+ endif
97+ endfor
98+ let g: signify_disable_by_default = 1
11899endfunction
119100
120101" #buffer_is_active {{{1
121102function ! sy#buffer_is_active ()
122- return exists ( ' b:sy ' ) && b: sy .active
103+ return ! empty ( getbufvar ( bufnr ( ' ' ), ' sy ' ))
123104endfunction
124105
125106" #verbose {{{1
@@ -135,6 +116,35 @@ function! sy#verbose(msg, ...) abort
135116 endif
136117endfunction
137118
119+ " #set_buflocal_autocmds {{{1
120+ function ! sy#set_buflocal_autocmds (bufnr ) abort
121+ augroup signify
122+ execute printf (' autocmd! * <buffer=%d>' , a: bufnr )
123+
124+ execute printf (' autocmd BufEnter <buffer=%d> call sy#start()' , a: bufnr )
125+ execute printf (' autocmd WinEnter <buffer=%d> call sy#start()' , a: bufnr )
126+ execute printf (' autocmd BufWritePost <buffer=%d> call sy#start()' , a: bufnr )
127+
128+ execute printf (' autocmd CursorHold <buffer=%d> call sy#start()' , a: bufnr )
129+ execute printf (' autocmd CursorHoldI <buffer=%d> call sy#start()' , a: bufnr )
130+
131+ execute printf (' autocmd FocusGained <buffer=%d> SignifyRefresh' , a: bufnr )
132+
133+ execute printf (' autocmd CmdwinEnter <buffer=%d> let g:signify_cmdwin_active = 1' , a: bufnr )
134+ execute printf (' autocmd CmdwinLeave <buffer=%d> let g:signify_cmdwin_active = 0' , a: bufnr )
135+
136+ execute printf (' autocmd ShellCmdPost <buffer=%d> call sy#start()' , a: bufnr )
137+
138+ if exists (' ##VimResume' )
139+ execute printf (' autocmd VimResume <buffer=%d> call sy#start()' , a: bufnr )
140+ endif
141+ augroup END
142+
143+ if exists (' #User#SignifyAutocmds' )
144+ doautocmd <nomodeline> User SignifyAutocmds
145+ endif
146+ endfunction
147+
138148" s:get_path {{{1
139149function ! s: get_path (bufnr )
140150 let path = resolve (fnamemodify (bufname (a: bufnr ), ' :p' ))
0 commit comments