I wrote an interpreter by leveraging --batch, read-from-minibuffer and princ. Now, reading input is relatively limited, you can type consecutive characters, erase the last character with <backspace>, send a line with RET and cancel input with C-d (or C-c, but that aborts the entire program). This is good enough for testing, but I'd like to shoot for more readline-like editing. Is it possible to intercept individual control keys before printing them and how?

  • Why not simply start Emacs in interactive mode and run the interpreter as a REPL in an Emacs buffer? That way you have access to all your Emacs editing tools. – Lindydancer Mar 15 '16 at 10:57
  • That would indeed be the easiest option, but wouldn't fit the requirements. – wasamasa Mar 15 '16 at 12:18
  • Ok, new approach: You can build an external executable than links with a "readline" library that you can call from Emacs to read a line. I'm not 100% sure Emacs lets a foreign program use input and output when in batch mode, but it might be worth a shot to try it. – Lindydancer Mar 15 '16 at 12:42
  • Yeah, an Emacs module could work or an executable wrapping it, the latter would be equal to rewriting rlwrap though. I'd accept an answer involving the former. – wasamasa Mar 15 '16 at 12:50

I ended up writing my own readline thing with the help of @ack006. It consists of a shell script enabling raw mode and sending one character at a time to an Emacs in batch mode which interprets the key sequences accordingly and emits ANSI escapes to pretend line editing.

I'd still appreciate an answer involving the new module support.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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