1

Trying to do something with job output in exit_cb or close_cb, but it's all buffered, how to flush it. e.g.:

function! s:exit_cb(job, status)
  echom getbufline(s:bufnr, '$')
endfunction

function! s:close_cb(channel)
  echom getbufline(s:bufnr, '$')
endfunction

let s:bufnr = term_start('seq 1000',
      \ {'exit_cb': function("s:exit_cb"), 'close_cb':function("s:close_cb") })

None of them echo 1000, how to flush it ?

One work around is to call :h :sleep, but i don't think that's the right way.

update

As B Layer pointed out, result of close_cb depends on terminal window height. e.g., if it's height is 30, it prints 971, as 971 = 1000 - 30 + 1.

I reread :h close_cb , it says:

Vim will invoke callbacks that handle data before invoking close_cb, thus when this function is called no more data will be passed to the callbacks.

I guess the callback vim invoked to handle data haven't finished by the time close_cb is called. Tried to call term_wait() in close_cb, but it cause hang.

  • How do you know it's being buffered? What are you observing exactly? Did you strace it? BTW, there's no guarantee they'd echo 1000 even if things weren't "stuck"...could be 782,. :) – B Layer Jun 24 at 0:26
  • :h job-exit_cb Says data can be buffered, i guess the same thing happen for job-close_cb. I havn't straced it. I will try it later. – dedowsdi Jun 24 at 0:30
  • @BLayer Why it could be 782 even if things weren't "stuck" ? – dedowsdi Jun 24 at 0:34
  • 1
    That's a typo, I meant to write 982. Back to that in a minute...something strange is going on. I was curious to see if I could reproduce your hang so I rather quickly entered something close to your code and ran it. No hang. Just saw that one of the callbacks prints the first line of the term buffer and that is wholly dependent on window heights (I saw 977 and 982). BUT now I realize that you're asking, properly as far as I can see, for the last line so I should be getting 1000. D'oh! Maybe I fat fingered something...forget I mentioned it! :D – B Layer Jun 24 at 1:09
  • @BLayer You are right about window height. I think vim alread read all the data from channel in exit_cb, but it havn't finished updating it. See update. – dedowsdi Jun 24 at 8:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.