Configuring Emacs rgrep

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

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

This function simply launches rgrep for the term entered in the files / directories that interest me. However, I want to combine the original rgrep functionality with the fact that the default search term is a word in a dot (I think the term?). How do I achieve this? I tried several things, including startup (grep-read-regexp), but was not successful.

+4
source share
2 answers

You can use the 'thingatpt package like this:

 (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]*" "../")) 
+5
source

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

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

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

+2
source

All Articles