esta função solicita um comando e o executa no arquivo de buffer atual. se nenhum arquivo estiver associado ao buffer atual, haverá um erro
(defun shell-command-on-buffer-file ()
"prompts for a command and executes that command on to the associated
file of current buffer. if no buffer is associated gives an error"
(interactive)
(or (buffer-file-name) (error "no file is associated file to this buffer"))
(let* ((my-cmd (read-shell-command "Command to run: "))
(cmd-to-run (concat my-cmd " " (buffer-file-name))))
(shell-command cmd-to-run)))
como de costume, o emacs salva o histórico dos comandos que você deu até agora, que podem ser acessados usando M-p, M-n