2

elpy-mode internally uses this command to search for a regexp in *.py files.

(setq elpy-rgrep-file-pattern "*.py")

(rgrep regexp
       elpy-rgrep-file-pattern
       default-directory))

However elpy-rgrep-file-pattern is customisable. I want to include html files also while searching.

I have tried the following patterns

(setq elpy-rgrep-file-pattern "*.py|*.html")
(setq elpy-rgrep-file-pattern "*.py\|*.html")
(setq elpy-rgrep-file-pattern "*.(py\|html)")
(setq elpy-rgrep-file-pattern "py\|html")
(setq elpy-rgrep-file-pattern '(("html" . "*.html") ("py" . "*.py")))

but nothing seems to work. How do I correctly specify file pattern to search *.py & *.html files?

  • If that's a regexp, you need two backslashes. First to escape the following backslash. – wvxvw Sep 16 '15 at 17:26
  • @wvxvw Not sure if that is a regexp, tried double back slash but it didn't work – ChillarAnand Sep 16 '15 at 17:39
  • OK, judging by the style of its definition, it must be a glob (similar to how Python or Bash glob works: github.com/jorgenschaefer/elpy/blob/… . Oh, wait, *.py is a glob! but you cannot have union operator (pipe) in globs, it can only have * and ?. And if you wanted to make it a regexp: "\\.\\(:?py\\|html\\)$". – wvxvw Sep 16 '15 at 18:05
  • 1
    Oh, I think I figured that out, can you try this: "*.py *.htm?"? Also see documentation for grep-files-aliases. – wvxvw Sep 16 '15 at 18:47
  • 1
    What if you define an alias similar to other aliases in that variable and try to use that instead? If I do (push (cons "pyml" "*.py *.htm *.html") grep-files-aliases) and then M-x rgerp whatever RET pyml RET, then I get results for both *.html and *.py files. – wvxvw Sep 16 '15 at 18:58
4

rgrep takes as its second argument file description in a format similar to shell globbing, which also exists in other languages, for example, in Python.

There's also a useful variable in Emacs related to rgrep: grep-files-aliases, which can be customized to alias various file groups, for instance

(push (cons "pyml" "*.py *.htm *.html") grep-files-aliases)

will add an alias pyml for files with extensions py, htm and html. After evaluating the code above, one should be able to execute:

M-xrgrepRETsearch queryRETpymlRET in order to search in files with the extensions aliased by pyml.

  • 1
    Instead of constructing pyml and we can also pass "*.py *.htm *.html" directly as a pattern. – ChillarAnand Sep 17 '15 at 4:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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