在grep-mode中评估sexp并在新缓冲区中显示输出

时间:2013-01-31 12:57:48

标签: emacs lisp

this recipe之后,我准备了这个搜索命令:

(shell-command "grep . /tmp/listoffiles | xargs grep -n mystring" 1)

如果我使用eval-last-sexp ^ + x + e )运行此选项,则会显示包含匹配项的列表在命令之后,以grep-mode中的缓冲区识别的相同格式。但是这个缓冲区在grep-mode,所以我无法自动跳转到所需的文件/行。

我想要的是以下内容:我将使用缓冲区在哪里输入我的搜索命令;转到其中一个命令的末尾,按下一个组合键将触发一个函数run-grep-in-other-buffer。此功能必须执行以下操作:

  1. 评估point处的搜索命令,由eval-last-sexp
  2. 完成
  3. 创建缓冲区
  4. 在新缓冲区中输出搜索命令的结果
  5. grep-mode
  6. 中设置新缓冲区
  7. 激活新缓冲区。
  8. 我的lisp非常有限。我怎么能做到这一点?

1 个答案:

答案 0 :(得分:1)

您可以直接使用此功能,而不是使用shell-command构建:

(defun run-grep-in-other-buffer (str)
  (interactive)
  (let ((grep-host-defaults-alist nil)
        (grep-command str))
    (call-interactively 'grep)))

使用eval-last-sexp

运行此操作
(run-grep-in-other-buffer "grep . /tmp/listoffiles1 | xargs grep -n list")
(run-grep-in-other-buffer "grep . /tmp/listoffiles2 | xargs grep -n list")