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.
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]*" "../"))
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With