Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Emacs rgrep customization

Tags:

emacs

elisp

I have the following custom function in ~/.emacs:

(defun xi-rgrep (term)
  (grep-compute-defaults)
    (interactive "sSearch Term: ")
    (rgrep term "*.[ch]*" "../"))

This function just runs rgrep for the term entered in the files/directories I'm interested in. However, I want to match the original rgrep functionality of having the default search term be the word at the point (I think that's the term?). How do I achieve this? I've tried several things, including running (grep-read-regexp) but haven't been successful.

like image 529
Matthew Talbert Avatar asked Jan 03 '10 05:01

Matthew Talbert


2 Answers

You can use the 'thingatpt package like so:

(require 'thingatpt)
(defun xi-rgrep (term)
   (interactive (list (completing-read "Search Term: " nil nil nil (thing-at-point 'word))))
  (grep-compute-defaults)
  (rgrep term "*.[ch]*" "../"))
like image 177
Trey Jackson Avatar answered Sep 29 '22 19:09

Trey Jackson


Here is another way which does not require the 'thingatpt package and uses (grep-read-regexp):

(defun xi-rgrep ()
  (interactive)
  (grep-compute-defaults)
  (rgrep (grep-read-regexp) "*.[ch]*" "../"))

I prefer this as 'thingatpt requires setting boundaries if you want to rgrep words with symbols, such as underscores, which is often the case for variables.

like image 24
Pepino Avatar answered Sep 29 '22 18:09

Pepino