1

Imagine in the current buffer I have the text:

Hello
Bye

I want to call an external program and add the output of it at the end of the buffer. The tricky thing is that the external program provides output little by little, and I want the output to show up as it arrives.

For example, let's say the external program is the following (called slow-process.sh):

#!/bin/bash
 
IN=$(</dev/stdin)
TEXT="Document with ${#IN} characters"
 
for i in $(seq 1 ${#TEXT}); do
    echo -n "${TEXT:i-1:1}"
    sleep 0.1
done
echo

The when calling the slow process on the initial buffer, I should get:

Hello
Bye
D... o... c... u... m... e...

(You get the idea, the last line is updated little by little).

How can all this be done without blocking Emacs?

Ideally, I want to have a function with the following signature:

(call-slow-updating-process PROCESS BUFFER)
1
  • 1
    I suggest reading C-h i g (elisp)Output from Processes
    – phils
    Dec 5, 2022 at 3:28

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.