How to make Emacs read buffer from stdin on start?
You could use process substitution:
$ emacs --insert <(echo 123)
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
andC-c
continue to have their normal effect. The functionsprin1
,princ
andstdout
instead of the echo area, whilemessage
and error messages output tostderr
. Functions that would normally read from the minibuffer take their input fromstdin
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.
You can redirect to a file, then open the file. e.g.
echo 123 > temp; emacs temp
jweede notes that if you want the temp file to automatically be removed, you can:
echo 123 > temp; emacs temp; rm temp
The Emacsy way to do this is to run the shell command in Emacs.
M-! echo 123 RET
That gives you a buffer named *Shell Command Output* with the results of the command.