| Re: How to supply the current word as a parameter to grep? |
|
 |
|
 |
|
 |
|
 |
Group: gnu.emacs.help · Group Profile
Author: harvenharven Date: Sep 19, 2008 08:34
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)
|