Mac – How to make Emacs read buffer from stdin on start


With Vim I can easily do

$ echo 123 | vim -

Is it possible to do with Emacs?

$ echo 123 | emacs23
... Emacs starts with a Welcome message

$ echo 123 | emacs23 -
... Emacs starts with an empty *scratch* buffer and “Unknown option”

$ echo 123 | emacs23 --insert -
... “No such file or directory”, empty *scratch* buffer

Is it really impossible to read a buffer from a unix pipe?

Edit: As a solution, I wrote a shell wrapper named emacspipe:

TMP=$(mktemp) && cat > $TMP && emacs23 $TMP ; rm $TMP

Best Answer

Correct, it is impossible to read a buffer from stdin.

The only mention of stdin in the Emacs info pages is this, which says:

In batch mode, Emacs does not display the text being edited, and the standard terminal interrupt characters such as C-z and C-c continue to have their normal effect. The functions prin1, princ and print output to stdout instead of the echo area, while message and error messages output to stderr. Functions that would normally read from the minibuffer take their input from stdin instead.

And the read function can read from stdin, but only in batch mode.

So, you can't even work around this by writing custom elisp.