Emacs grep-find选择

时间:2014-12-29 14:44:31

标签: emacs grep elisp

当我在emacs中使用grep-find时,我想搜索我选择的文本是很常见的。我目前的解决方法是选择文本,然后选择M-x grep-find并粘贴选择。如何自动进行键绑定?

1 个答案:

答案 0 :(得分:0)

此处有修改后的grep-find - 如果该区域处于有效状态,则搜索区域 内容。它似乎适用于我的系统:

(defun grep-find (command-args)
  "Run grep via find, with user-specified args COMMAND-ARGS.
Collect output in a buffer.
While find runs asynchronously, you can use the \\[next-error] command
to find the text that grep hits refer to.

This command uses a special history list for its arguments, so you can
easily repeat a find command."
  (interactive
   (progn
     (grep-compute-defaults)
     (if grep-find-command
         (list
          (read-shell-command
           "Run find (like this): "
           (if (region-active-p)
               (let ((str
                      (buffer-substring-no-properties
                       (region-beginning)
                       (region-end))))
                 (cons (replace-regexp-in-string
                        " {}"
                        (concat str " {}")
                        (car grep-find-command))
                       (+ (cdr grep-find-command)
                          (length str))))
             grep-find-command) 'grep-find-history))
       ;; No default was set
       (read-string
        "compile.el: No `grep-find-command' command available. Press RET.")
       (list nil))))
  (when command-args
    (let ((null-device nil))
      (grep command-args))))