Search code examples
emacselisp

Emacs shell command on buffer


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?


Solution

  • 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))