Refactor job callbacks with partial
This commit is contained in:
		
							parent
							
								
									b32169ff30
								
							
						
					
					
						commit
						759103d074
					
				
							
								
								
									
										38
									
								
								plug.vim
									
									
									
									
									
								
							
							
						
						
									
										38
									
								
								plug.vim
									
									
									
									
									
								
							|  | @ -1110,7 +1110,7 @@ function! s:job_abort() | ||||||
|   let s:jobs = {} |   let s:jobs = {} | ||||||
| endfunction | endfunction | ||||||
| 
 | 
 | ||||||
| function! s:job_out_cb(self, ch, data) abort | function! s:job_out_cb(self, data) abort | ||||||
|   let self = a:self |   let self = a:self | ||||||
|   let complete = empty(a:data[-1]) |   let complete = empty(a:data[-1]) | ||||||
|   let lines = map(filter(a:data, 'v:val =~ "[^\r\n]"'), 'split(v:val, "[\r\n]")[-1]') |   let lines = map(filter(a:data, 'v:val =~ "[^\r\n]"'), 'split(v:val, "[\r\n]")[-1]') | ||||||
|  | @ -1126,39 +1126,17 @@ function! s:job_out_cb(self, ch, data) abort | ||||||
|   endif |   endif | ||||||
| endfunction | endfunction | ||||||
| 
 | 
 | ||||||
| function! s:job_exit_cb(self, ch, data) abort | function! s:job_exit_cb(self, data) abort | ||||||
|   let self = a:self |   let self = a:self | ||||||
|   call s:reap(self.name) |   call s:reap(self.name) | ||||||
|   call s:tick() |   call s:tick() | ||||||
| endfunction | endfunction | ||||||
| 
 | 
 | ||||||
| function! s:find_job(ch) | function! s:vim8_cb(fn, job, ch, data) | ||||||
|   for j in keys(s:jobs) |  | ||||||
|     if s:jobs[j].jobid == a:ch |  | ||||||
|       return s:jobs[j] |  | ||||||
|     endif |  | ||||||
|   endfor |  | ||||||
|   return {} |  | ||||||
| endfunction |  | ||||||
| 
 |  | ||||||
| function! s:vim8_out_cb(ch, data) |  | ||||||
|   if !s:plug_window_exists() " plug window closed |   if !s:plug_window_exists() " plug window closed | ||||||
|     return s:job_abort() |     return s:job_abort() | ||||||
|   endif |   endif | ||||||
|   let self = s:find_job(a:ch) |   call call(a:fn, [a:job, split(a:data, '[\r\n]', 1)]) | ||||||
|   if !empty(self) |  | ||||||
|     call s:job_out_cb(self, a:ch, a:data) |  | ||||||
|   endif |  | ||||||
| endfunction |  | ||||||
| 
 |  | ||||||
| function! s:vim8_exit_cb(ch, data) |  | ||||||
|   if !s:plug_window_exists() " plug window closed |  | ||||||
|     return s:job_abort() |  | ||||||
|   endif |  | ||||||
|   let self = s:find_job(a:ch) |  | ||||||
|   if !empty(self) |  | ||||||
|     call s:job_exit_cb(self, a:ch, a:data) |  | ||||||
|   endif |  | ||||||
| endfunction | endfunction | ||||||
| 
 | 
 | ||||||
| " When a:event == 'stdout', data = list of strings | " When a:event == 'stdout', data = list of strings | ||||||
|  | @ -1169,9 +1147,9 @@ function! s:nvim_job_handler(job_id, data, event) abort | ||||||
|   endif |   endif | ||||||
| 
 | 
 | ||||||
|   if a:event == 'stdout' |   if a:event == 'stdout' | ||||||
|     call s:job_out_cb(self, a:job_id, a:data) |     call s:job_out_cb(self, a:data) | ||||||
|   elseif a:event == 'exit' |   elseif a:event == 'exit' | ||||||
|     call s:job_exit_cb(self, a:job_id, a:data) |     call s:job_exit_cb(self, a:data) | ||||||
|   endif |   endif | ||||||
| endfunction | endfunction | ||||||
| 
 | 
 | ||||||
|  | @ -1198,8 +1176,8 @@ function! s:spawn(name, cmd, opts) | ||||||
|     endif |     endif | ||||||
|   elseif s:vim8 |   elseif s:vim8 | ||||||
|     let jid = job_start(argv, { |     let jid = job_start(argv, { | ||||||
|     \ 'out_cb':  function('s:vim8_out_cb'), |     \ 'callback': function('s:vim8_cb', ['s:job_out_cb',  job]), | ||||||
|     \ 'exit_cb': function('s:vim8_exit_cb') |     \ 'exit_cb':  function('s:vim8_cb', ['s:job_exit_cb', job]) | ||||||
|     \}) |     \}) | ||||||
|     if job_status(jid) == 'run' |     if job_status(jid) == 'run' | ||||||
|       let job.jobid = jid |       let job.jobid = jid | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue
	
	Block a user