我想设置一个相当于标记整个缓冲区的函数,并运行C-u M-|
来提示命令,将缓冲区传递给命令并用输出替换缓冲区。然后可能将它设置为shift-f5或其他东西。
我只有这个:
(defun shell-command-on-buffer ()
(interactive)
(mark-whole-buffer))
我该怎么办呢?
答案 0 :(得分:5)
这对我有用:
(defun shell-command-on-buffer (command)
(interactive "sShell command on buffer: ")
(shell-command-on-region (point-min) (point-max) command t))
答案 1 :(得分:4)
这个具有使用“shell命令”迷你缓冲历史而不是一般迷你缓冲历史的优点。
(defun shell-command-on-buffer ()
(interactive)
(shell-command-on-region (point-min) (point-max) (read-shell-command "Shell command on buffer: ") t))
答案 2 :(得分:0)
对@killdash9 的回答的逐步改进,即:
使用 emacs 27.1 测试
(defun shell-command-on-buffer ()
(interactive)
(let ((line (line-number-at-pos)))
;; replace buffer with output of shell command
(shell-command-on-region (point-min) (point-max) (read-shell-command "Shell command on buffer: ") nil t)
;; restore cursor position
(goto-line line)
(recenter-top-bottom)))