I have a program which can run as a command in bash.

Can I run the program in emacs, in some way similar to run emacs' command (i.e.M-x , e.g. M-x occur), instead of first explicitly running a shell in a buffer of emacs and then running the program in the shell?



M-! runs the command shell-command. This will prompt you for the actual command to run in the minibuffer, which then runs. You can run it in the background by putting a & at the end, just as you would in a terminal. alternatively, you can use M-&, async-shell-command.

The output from the shell command will be placed in a temporary buffer. If you want it inserted in the current buffer, use a prefix argument. (i.e., C-u M-!.

A very useful related function is shell-command-on-region, bound to M-| by default. This will run a shell command on the contents of the region. The output will go in a temporary buffer, or, as with M-!, if you use a prefix argument the selected region will be replaced by the output of the shell command.

See (emacs) Single Shell in the manual for more details.

  • @p_wiersig I rejected your edit because I don't fully understand how Compile mode works in this context. With more details, and/or an example, it is probably worth making a separate answer for that! – Tyler Apr 12 '16 at 20:37

As mentioned in another answer, shell-command and async-shell-command are the generic way to go.

However, there are also a few tools that can be better in specific contexts.


This one will give you a completion similar to your DE's start menu, allowing to start a usually graphical application, provided it has a configured *.desktop file.

Available from the counsel package on MELPA and here.


If you have a complicated recipe for transforming a file or a set of files into other files, make-it-so might be useful for you. It's on MELPA as well.

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.