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:

function! plugin#eval(str) call s:send_to_repl(str) echomsg s:get_response() endfunction

as the get_response function is working with the terminal buffer before it gets updated.

Currently, I'm using neovim's job control, though if this can be accomplished in vanilla vim, all the better.

Here's the code I'm using to initialize the terminal:

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

Here's how I'm sending the command to the REPL:

function! s:send(str) call jobsend(g:intero_job_id, add([a:str], '')) endfunction

I've tried adding an edit command to refresh, but that doesn't seem to work in the REPL.

The code for communicating with the REPL is here. The code for managing the process is here.