Function: grep
grep is an autoloaded, interactive and byte-compiled function defined
in grep.el.gz.
Signature
(grep COMMAND-ARGS)
Documentation
Run Grep with user-specified COMMAND-ARGS.
The output from the command goes to the "*grep*" buffer.
While Grep runs asynchronously, you can use C-x ` (next-error) (M-x next-error),
or RET (compile-goto-error) in the *grep* buffer, to go to the lines where Grep found
matches. To kill the Grep job before it finishes, type C-c C-k (kill-compilation).
Noninteractively, COMMAND-ARGS should specify the Grep command-line arguments.
For doing a recursive grep, see the rgrep command. For running
Grep in a specific directory, see lgrep.
This command uses a special history list for its COMMAND-ARGS, so you can easily repeat a grep command.
A prefix argument says to default the COMMAND-ARGS based on the current
tag the cursor is over, substituting it into the last Grep command
in the Grep command history (or into grep-command if that history
list is empty).
Probably introduced at or before Emacs version 1.4.
Key Bindings
Source Code
;; Defined in /usr/src/emacs/lisp/progmodes/grep.el.gz
;;;###autoload
(defun grep (command-args)
"Run Grep with user-specified COMMAND-ARGS.
The output from the command goes to the \"*grep*\" buffer.
While Grep runs asynchronously, you can use \\[next-error] (M-x next-error),
or \\<grep-mode-map>\\[compile-goto-error] in the *grep* \
buffer, to go to the lines where Grep found
matches. To kill the Grep job before it finishes, type \\[kill-compilation].
Noninteractively, COMMAND-ARGS should specify the Grep command-line
arguments.
For doing a recursive `grep', see the `rgrep' command. For running
Grep in a specific directory, see `lgrep'.
This command uses a special history list for its COMMAND-ARGS, so you
can easily repeat a grep command.
A prefix argument says to default the COMMAND-ARGS based on the current
tag the cursor is over, substituting it into the last Grep command
in the Grep command history (or into `grep-command' if that history
list is empty)."
(interactive
(progn
(grep-compute-defaults)
(let ((default (grep-default-command)))
(list (read-shell-command "Run grep (like this): "
(if current-prefix-arg default grep-command)
'grep-history
(if current-prefix-arg nil default))))))
;; If called non-interactively, also compute the defaults if we
;; haven't already.
(when (eq grep-highlight-matches 'auto-detect)
(grep-compute-defaults))
(grep--save-buffers)
;; Setting process-setup-function makes exit-message-function work
;; even when async processes aren't supported.
(compilation-start (if (and grep-use-null-device null-device (null-device))
(concat command-args " " (null-device))
command-args)
#'grep-mode))