help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to supply the current word as a parameter to grep?


From: harven
Subject: Re: How to supply the current word as a parameter to grep?
Date: Fri, 19 Sep 2008 08:34:26 -0700 (PDT)
User-agent: G2/1.0

On Sep 19, 2:01 pm, etay.me...@gmail.com wrote:
> Hi,
>
> I have the following entries in my .emacs:
>
> (setq grep-command "cd ~/work && find -name \"*.cpp\" -or -name \"*.h
> \" | xargs grep -nH -e ")
>
> I'd like have the current word supplied as a parameter to grep
> whenever I hit the above key combination.
> How do I accomplish that?
>
> Thanks,
>
> -Etay Meiri

The commands lgrep and rgrep are somehow more user-friendly than the M-
x grep command. The word at point can be captured using the
command (thing-at-point 'word). So you may try:

(defun my-grep ()
  "look for word at point in files ending by .cpp and .h
   recursively starting from the work directory"
  (interactive)
  (rgrep (thing-at-point 'word) "*.cpp *.h" "~/work"))

(global-set-key [(control shift f)] 'my-grep)


reply via email to

[Prev in Thread] Current Thread [Next in Thread]