7
Late edit: As much as I appreciate the upvotes, Jurta's answer is the way to go. And Greg's hack is neater than mine.
延迟编辑:尽管我很欣赏赞成票,但是Jurta的回答是要走的路。格雷格的黑客比我的还要整洁。
I'll leave the rest of this here because it might be worth something, but...
我会在这里留下其余部分,因为它可能是值得的,但......
M-x shell-command-on-region
, which appears to be bound to M-|
by default.
M-x shell-command-on-region,似乎与M- |绑定默认情况下。
I see that this does not do exactly what Rohit asked for. Using C-h f shell-command-on-region
reveals that the desired behavior is available in the non-interactive version of the command (by setting the argument replace
to non-nil). We should be able to write a wrapper to do this.
我发现这并不完全符合Rohit所要求的。使用C-h f shell-command-on-region显示在命令的非交互版本中可以使用所需的行为(通过将参数replace设置为non-nil)。我们应该能够编写一个包装器来执行此操作。
Try this (load it into *scratch*
and run M-x eval-buffer
, if it works, copy it to your .emacs file):
试试这个(将它加载到* scratch *并运行M-x eval-buffer,如果有效,将其复制到.emacs文件中):
(defun shell-command-on-region-replace (start end command)
"Run shell-command-on-region interactivly replacing the region in place"
(interactive (let (string)
(unless (mark)
(error "The mark is not set now, so there is no region"))
;; Do this before calling region-beginning
;; and region-end, in case subprocess output
;; relocates them while we are in the minibuffer.
;; call-interactively recognizes region-beginning and
;; region-end specially, leaving them in the history.
(setq string (read-from-minibuffer "Shell command on region: "
nil nil nil
'shell-command-history))
(list (region-beginning) (region-end)
string)))
(shell-command-on-region start end command t t)
)
And note as I say in the comments that this is not a very emacsy thing to do. But I think it works.
请注意,正如我在评论中所说,这不是一件非常麻烦的事情。但我认为它有效。
For any readers who don't know how to select a region:
对于任何不知道如何选择地区的读者:
- Move the "point" (current cursor position) to one end of the region, and use
C-space
to activate the "mark"
将“点”(当前光标位置)移动到区域的一端,并使用C空格激活“标记”
- Move the point to the other end of the region
将该点移动到该区域的另一端
- Your done, invoke the command
完成后,调用命令