我想设置一个功能,相当于标记整个缓冲区,并运行C-u M-|
以提示输入命令,将缓冲区传递给命令并用输出替换缓冲区。然后可能将其设置为 shift-f5 或其他东西。
我只有这个:
(defun shell-command-on-buffer ()
(interactive)
(mark-whole-buffer))
我该怎么做?
这对我有用:
(defun shell-command-on-buffer (command)
(interactive "sShell command on buffer: ")
(shell-command-on-region (point-min) (point-max) command t))
这个的优点是使用“shell 命令”minibuffer 历史而不是一般的 minibuffer 历史。
(defun shell-command-on-buffer ()
(interactive)
(shell-command-on-region (point-min) (point-max) (read-shell-command "Shell command on buffer: ") t))
@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)))