【问题标题】:emacs can invoke shell and execute commands-- can they act on Emacs buffers?emacs 可以调用 shell 并执行命令——它们可以作用于 Emacs 缓冲区吗?
【发布时间】:2010-08-24 21:12:50
【问题描述】:

我使用 Alt-! (Alt-Bang)在 Emacs 中很多。我用它做的一件大事是

Alt-! cat $logfile | grep 'this' # show me one kind of event

有时

Alt-! cat $logfile | grep 'this' | wc -l # count that one event's occurrences

两件事:

1) 此提示没有制表符补全:为什么不呢?

2) 如果我想扫描一个 Emacs 缓冲区而不是 $logfile,该怎么办?

【问题讨论】:

  • 您使用的是哪个版本的 Emacs?我有来自shell-command 提示的制表符完成。 (标签绑定到minibuffer-complete-shell-command

标签: shell emacs buffer


【解决方案1】:

要扫描 Emacs 缓冲区,请使用 M-| 而不是 M-!:它将区域作为输入传递给命令。如果您希望命令的输出替换区域,请使用M-1 M-|

对于您提到的特定命令,如果您想查看所有匹配项,请使用 M-x grep。或者您可以打开它并查看 M-x occur 的匹配项。

【讨论】:

    【解决方案2】:

    Alt-| 确实是 shell-command-on-region

    带有 (ny) 数字前缀(例如 C-u 1 Alt-|)的区域被结果替换,否则出现在新缓冲区中

    【讨论】:

    • n.b. C-u 提供了一个默认值(按C-u n 次时为 4^n),因此当数字无关紧要,或者只是需要为某个正整数时,您无需使用 C-u 1,而可以使用C-u 单独使用(或 M-1C-1)。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-03-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-01-24
    相关资源
    最近更新 更多