该函数的 Emacs 帮助页面显示shell-command-on-region
(省略空格):
(shell-command-on-region START END COMMAND &optional OUTPUT-BUFFER
REPLACE ERROR-BUFFER DISPLAY-ERROR-BUFFER)
...
The noninteractive arguments are START, END, COMMAND,
OUTPUT-BUFFER, REPLACE, ERROR-BUFFER, and DISPLAY-ERROR-BUFFER.
...
If the optional fourth argument OUTPUT-BUFFER is non-nil,
that says to put the output in some other buffer.
If OUTPUT-BUFFER is a buffer or buffer name, put the output there.
If OUTPUT-BUFFER is not a buffer and not nil,
insert output in the current buffer.
In either case, the output is inserted after point (leaving mark after it).
If REPLACE, the optional fifth argument, is non-nil, that means insert
the output in place of text from START to END, putting point and mark
around it.
这不是最清楚的,但刚刚引用的最后几句话似乎是说,如果我希望将 shell 命令的输出插入到当前缓冲区中,而缓冲区的其他内容保持不变,我应该传递一个非nil
论据 forOUTPUT-BUFFER
和nil
for REPLACE
。
但是,如果我在缓冲区中执行此代码*scratch*
(不是我正在处理的真实代码,而是演示问题的最小案例):
(shell-command-on-region
(point-min) (point-max) "wc" t nil)
缓冲区的全部内容被删除并替换为wc
!
shell-command-on-region
非交互使用时坏了,还是我误读了文档?如果是后者,我如何更改上面的代码以插入wc
at point 的输出而不是替换缓冲区的内容?理想情况下,我想要一个通用的解决方案,它不仅可以像在最小示例中那样在整个缓冲区上运行命令(即(point-min)
通过(point-max)
),而且还可以用于以区域作为输入运行命令然后插入结果的情况在不删除区域的情况下。