GPT-4 AsyncRun custom handler function for sending output to the buffer rather than the QuickFix window (seems hallucinated). Kind of close to a "custom runner" in https://github.com/skywind3000/asyncrun.vim/wiki/Customize-Runner but I can't see which ones get data from the process output, so unsure which type of runner to adapt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
You can customize the behavior of the AsyncRun plugin to insert the output into the current buffer by using a custom handler function. | |
Follow these steps to set up the custom handler: | |
- In your .vimrc, add the following function: | |
```vim | |
function! MyAsyncHandler(job, data) abort | |
let l:lines = split(a:data, "\n") | |
call append(line('$'), l:lines[:-2]) | |
call cursor(line('$'), 0) | |
redraw | |
endfunction | |
``` | |
This function takes the job ID and data as input, splits the data into lines, appends the lines to the current buffer, and moves the cursor to the last line. | |
- Configure AsyncRun to use the custom handler by adding the following line to your .vimrc: | |
```vim | |
let g:asyncrun_handler = function("MyAsyncHandler") | |
``` | |
- Open Vim and create a new buffer to receive the streamed data. You can do this by typing :e stream_buffer.txt in normal mode. | |
- Run the following command in Vim to execute your Python script asynchronously and read the output into the current buffer: | |
```vim | |
:AsyncRun -mode=term python3 stream | |
``` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment