Emacs shell command in buffer

I would like to set up a function that performs the equivalent of marking the entire buffer, and run C-u M-|to request a command, pass the buffer to the command and replace the buffer with the output. Then maybe set it to shift-f5 or something like that.

I just got to this:

(defun shell-command-on-buffer ()
  (interactive)
  (mark-whole-buffer))

How can I do the rest?

+5
source share
2 answers

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))
+5
source

This 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))
+4
source

All Articles