6

How can I modify the default FILES pattern in rgrep for C++ mode?

For C mode the default is *.[ch]. For C++, it is *.cc *.cxx *.cpp *.C *.CC *.c++.

I would like to change it to *.cc *.[ch]xx *.[ch]pp *.[CHh] *.CC *.HH *.[ch]++.

1 Answer 1

6

M-xcustomize-variableRETgrep-files-aliases and then use the interface to change the value of this variable.

Alternatively, you could put:

(setf (cdr (assoc "cc" grep-files-aliases))
      (assoc "cchh" grep-files-aliases))

For future reference, you could have looked up the help for rgrep (by typing C-h frgrep) where it says:

Recursively grep for REGEXP in FILES in directory tree rooted at DIR. The search is limited to file names matching shell pattern FILES. FILES may use abbreviations defined in grep-files-aliases, e.g. entering ch is equivalent to *.[ch].

3
  • I had to use (eval-after-load "grep" '(setf (cdr (assoc "cc" grep-files-aliases)) (cdr (assoc "cchh" grep-files-aliases)))), because grep-files-aliases was void while loading my init file.
    – 0x5453
    Commented Aug 12, 2016 at 13:52
  • @0x5453 Right, I didn't think grep package wouldn't be loaded by default.
    – wvxvw
    Commented Aug 13, 2016 at 14:27
  • When I add the above to my init.el file I get the following message upon using rgrep: split-string: Wrong type argument: stringp, ("cchh" . "*.cc *.[ch]xx *.[ch]pp *.[CHh] *.CC *.HH *.[ch]++") Commented Oct 12, 2017 at 18:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.