From time to time I happen to M-! some_command
just to find that the command runs longer than I expected and keeps my emacs frozen for long seconds. So I glaze at my frozen emacs and kick myself for not using M-& some_command
and promise myself to use M-&
next time. But M-!
is in my muscle memory for decades…
And of course there is Ctrl-G
, but there are cases when breaking command and re-running it is not preferable (mayhaps it may break sth, mayhaps would be costly to rerun…).
Similar mistake in shell konsole is trivial to correct, Ctrl-Z
, bg
and job is running in the background.
Does there exist some similar trick in emacs - a way to turn currently running foreground (synchronous) command into backgroundized (asynchronous) one?
Note: in case it is impossible for default M-!
, I am open to suggestions of how to rebind M-!
into something else (what would be functionally equivalent apart from this trick).
&
to the end of a regularshell-command
(M-!
) will make it asynchronous. Of course, you must do this before running a command, but at least you can use the same keybinding.M-!
toasync-shell-command
. :-) Seems like the only thing you lose is getting the output in the echo area when it is short enough.async-shell-command
does. It adds an&
to the end of theCOMMAND
string and executesshell-command
.