On Sunday, 1 May 2016 21:37:13 UTC+1, Bram Moolenaar  wrote:

> Note that adding "DETACH" was removed, so you can drop this check.
[snip]
> A couple of problems have been fixed.  Please give it another try and
> report back if you still see a problem.
[snip]
> > I also implemented my job_start using an out_cb handler again instead
> > of a close_cb handler.  The occasional-missing-callback problem has
> > disappeared and it all worked perfectly.  Thanks!
> 
> That is the preferred way.  Reading the output in the close callback
> might only work if there isn't much to read.

I upgraded from Vim 7.4.1795 to 7.4.1816 and found DETACH was no longer sent to 
the `out_cb` handler to demarcate the end of my job's output on stdout.

So I added a `close_cb` handler which does what my `out_cb` handler used to do 
on receiving DETACH: it gathers together all the preceding job output and then 
processes it.

When I edit a file my job runs.  When I trigger a second run, Vim always 
crashes with a segfault:

Vim: Caught deadly signal SEGV
Vim: Finished.
Segmentation fault: 11

Here's my code:

let job = job_start([&shell, &shellcmdflag, a:cmd], {
      \ 'out_cb':   'OutHandler',
      \ 'close_cb': 'CloseHandler'
      \ })

" Channel is in NL mode.
function! OutHandler(channel, line)
  let channel_id = matchstr(a:channel, '\d\+')
  call s:accumulate_job_output(channel_id, a:line)
endfunction

function! CloseHandler(channel)
  let channel_id = matchstr(a:channel, '\d\+')
  call ProcessOutput(s:job_output(channel_id))
  call s:job_finished(channel_id)
  " redraw!
endfunction

function! s:job_started(id)
  let s:jobs[a:id] = 1
endfunction

function! s:is_job_started(id)
  return has_key(s:jobs, a:id)
endfunction

function! s:accumulate_job_output(id, line)
  if has_key(s:jobs, a:id)
    let s:jobs[a:id] = add(s:jobs[a:id], a:line)
  else
    let s:jobs[a:id] = [a:line]
  endif
endfunction

" Returns a string
function! s:job_output(id)
  if has_key(s:jobs, a:id)
    return join(s:jobs[a:id], "\n")."\n"
  else
    return ""
  endif
endfunction

function! s:job_finished(id)
  if has_key(s:jobs, a:id)
    unlet s:jobs[a:id]
  endif
endfunction

Regarding redrawing: adding a redraw! as the last line of my close handler 
doesn't redraw the screen.  Should I be doing this somewhere else?

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Raspunde prin e-mail lui