GNU Emacs has a function called "suspend-emacs" which will suspend the Emacs
process. It takes an optional argument called "string", about which the
manual [1] says,
| If "string" is non-nil, its characters are sent to Emacs's superior shell,
| to be read as terminal input. The characters in "string" are not echoed by
| the superior shell; only the results appear.
And it does work as advertised: I tried running [2]
(suspend-emacs "date")
which had the effect of putting Emacs into the background and running the
"date" command in my shell. It appeared in every way like I had run "date"
myself: below the message saying "zsh: suspended emacs" was my shell prompt
with "date" after it, followed by the "date" output and then another prompt
line.
I found this very surprising! My mental model of running programs from a
shell did not include the possibility of a program reaching up into the
shell and forcing it to run a command. Can anyone explain the mechanism by
which Emacs is communicating with my shell in this situation? Does it rely
on the process still being running (albeit in the background)?
Thanks,
Benjamin
[1]:
https://www.gnu.org/software/emacs/manual/html_node/elisp/Suspending-Emacs.html
[2]: If like me you're an Emacs neophyte, you can try this out by launching
Emacs, typing M-: (i.e. Meta-Colon), typing that line above, and
pressing Return.
--
Benjamin Esham
https://esham.io