I'd like to set up a function that does the equivalent of marking the whole buffer, and running C-u M-|
to prompt for a command, pipe the buffer to the command and replace the buffer with the output. Then maybe set it to shift-f5 or something.
I've only got as far as this:
(defun shell-command-on-buffer ()
(interactive)
(mark-whole-buffer))
How can I do the rest?
You can execute an external shell command from within Emacs using ` M-! ' ( 'shell-command' ). The output from the shell command is displayed in the minibuffer or in a separate buffer, depending on the output size.
Emacs has commands for passing single command lines to shell subprocesses, and for running a shell interactively with input and output to an Emacs buffer, and for running a shell in a terminal emulator window. M-! cmd RET. Run the shell command cmd and display the output ( shell-command ).
To enter Emacs, type emacs at the shell prompt. When you want to leave Emacs for a short time, type a C-z and Emacs will be suspended. To get back into Emacs, type %emacs at the shell prompt.
To move between the buffers, type C-x b. Emacs shows you a default buffer name. Press Enter if that's the buffer you want, or type the first few characters of the correct buffer name and press Tab. Emacs fills in the rest of the name.
This works for me:
(defun shell-command-on-buffer (command)
(interactive "sShell command on buffer: ")
(shell-command-on-region (point-min) (point-max) command t))
This one has the advantage of using the "shell command" minibuffer history instead of the general minibuffer history.
(defun shell-command-on-buffer ()
(interactive)
(shell-command-on-region (point-min) (point-max) (read-shell-command "Shell command on buffer: ") t))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With