Either_Consequence90 · 2022-09-04 02:19
Hello, folks. I started learning Emacs and Elisp about a week ago and it's been a blast.
I just started adding a handful of simple functions and key bindings to open MPlayer in "slave" mode and control it by piping commands through a named pipe (FIFO). On opening, all of MPlayer's output is sent to the \*Async Shell Command\* buffer.
The key-bound functions simply use the builtin "shell-command" to echo MPlayer commands to /tmp/mplayerfifo just as you would from Bash:
echo "pause" > /tmp/mplayerfifo
echo "get_time_pos > /tmp/mplayerfifo
I have no use for the output when I'm simply controlling the video, but the output of commands like "get\_time\_pos" are printed out at the bottom of \*Async Shell Command\* and I would really like to stuff them in a variable. In short, how might I grab the content of \*Async Shell Command\* while working in a different buffer? I can work out transforming the text, I just need to get my hands on it. Also, could I clear that buffer after each command?
ieure · 2022-09-04 02:52
You need to write some functions. One that starts the mplayer process, and an output filter function to [receive its output](https://www.gnu.org/software/emacs/manual/html_node/elisp/Output-from-Processes.html).
But instead of that, why not look at [EMMS](https://www.gnu.org/software/emms/)? It already has an MPlayer backend, along with many others.
Either_Consequence90 · 2022-09-04 03:49
Thank you! I came across EMMS and thought that there was way more to it than I needed, though I'd like to tinker with it once I'm more comfortable with Emacs. I simply need to pause/unpause/rewind video and audio for legal and medical transcription, which I'm already able to do, but I was lost on how to insert timestamps. You put me on the right track by pointing out filter functions. Much appreciated.
ieure · 2022-09-04 03:54
Glad I could help, and good luck on your project.
IMO, wrangling EMMS is a lot less work than writing a well-behaved filter function, but to each their own. Looking at / basing your work on the EMMS code is probably a good idea.
ramin-honary-xc · 2022-09-04 14:18
You may also want to look into ["Transaction Queues"](https://www.gnu.org/software/emacs/manual/html_node/elisp/Transaction-Queues.html ), which wrap up a child process in an object to which you can send queries and receive replies, it is a good way to create an Emacs Lisp API around a process with a well-defined communication protocol.
You create the queue, and then you issue transactions. The transaction consists of a:
- a "question" string that is flushed to the STDIN of the child process,
- a regex that matches the end of a transaction (e.g. the CLI prompt printed after running a command), all text that is output that does not match this regex is buffered as a "response"
- a "closure", which is basically an object you construct use to store replies
- a response handling callback which is called with the buffered response, and a reference to the closure so you can update it with the content of the response.