title: Neovim asynchronous buffer waiting
body: <p>I am working on a Neovim plugin that interacts with a REPL in a terminal buffer. I want to be able to send a command to the REPL, copy the response, and display it to the user somehow. Currently, the terminal buffer doesn't seem to refresh output until the current vimscript function terminates, so I can't have a single function that does, eg:</p>
  
  <pre><code>function! plugin#eval(str)
      call s:send_to_repl(str)
      echomsg s:get_response()
  endfunction
  </code></pre>
  
  <p>as the <code>get_response</code> function is working with the terminal buffer before it gets updated.</p>
  
  <p>Currently, I'm using neovim's job control, though if this can be accomplished in vanilla vim, all the better.</p>
  
  <p>Here's the code I'm using to initialize the terminal:</p>
  
  <pre><code>function! s:start_buffer(height)
      set bufhidden=hide
      set noswapfile
      set buftype=nofile
      set hidden
      terminal! stack ghci --with-ghc intero
      let l:buffer_id = bufnr('%')
      let g:intero_job_id = b:terminal_job_id
  endfunction
  </code></pre>
  
  <p>Here's how I'm sending the command to the REPL:</p>
  
  <pre><code>function! s:send(str)
      call jobsend(g:intero_job_id, add([a:str], ''))
  endfunction
  </code></pre>
  
  <p>I've tried adding an <code>edit</code> command to refresh, but that doesn't seem to work in the REPL.</p>
  
  <p>The code for communicating with the REPL is <a href="https://github.com/parsonsmatt/intero-neovim/blob/master/autoload/intero/repl.vim" rel="nofollow">here</a>. The code for managing the process is <a href="https://github.com/parsonsmatt/intero-neovim/blob/master/autoload/intero/process.vim" rel="nofollow">here</a>.</p>