1

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.

1 Answer 1

1
(insert "echo hello")
(term-send-input)

?

I suspect you'll want to use term-line-mode rather than the default term-char-mode to avoid issues with your other editing commands.

YMMV. I mostly use char mode so that things behave like they would in a normal terminal, and only switch to line mode to do Emacsy things; but in your use-case you might find it easier the other way around?

2
  • Gah, 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. Mar 3, 2015 at 4:19
  • Yep, and you can also cause great confusion by trying to switch between them while writing a single command. I'm no expert with term-mode, so I'm afraid I can't point you at an ideal solution. I can imagine this potentially being tricky to get right, but perhaps someone else knows better.
    – phils
    Mar 3, 2015 at 4:23

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.