For the speech recognition mode for emacs I'm working on I'd like to have support for working with the shell. I have shell-mode working fine but I'd really like to get ansi-term working since some apps are only usable in it, and completion and history work so much better.
The issue is that all of my custom speech commands for editing text expect they can operate on the buffer directly, while ansi-term only listens to keyboard events. If I use a speech command (which sends commands with
emacsclient -e) to run
(insert "echo hello") the text gets inserted into the ansi-term buffer, but then when I press enter "hello" is not echo'd because the underlying shell didn't get any keyboard events. Likewise if I use some voice navigation commands and then press a key, the text looks like it's inserted in the right place but when I hit enter I can see from the errors that the shell thinks the keypress inserted text wherever the cursor was before -- the emacs point and the shell cursor are out of sync.
The only solution I see is to track where the shell thinks the cursor is, and whenever I do an editing action to emulate a series of keypresses to move the cursor there, and likewise simulate keypresses for inserting text. This approach could also work for tab completion. I see this as being pretty laborious and error prone though. Is there a better way? Or a package that already tackles this?
Edit: I forgot that I'd tried line mode before and run into other problems. In line mode completion doesn't work and nothing is read only so you can wreck the prompt and previous output. If there were solutions for each of those it could work.