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?

Chillar Anand
  • 4,042
  • 1
  • 23
  • 52
  • 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 – Chillar Anand 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: https://github.com/jorgenschaefer/elpy/blob/7e81e3e995ac1c64a9a3d298d86b6858cce802d0/elpy.el#L298 . 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
  • Even that is not working. May be we are missing something? – Chillar Anand Sep 16 '15 at 18:30
  • What I'm saying is that this variable uses globbing. This is not really a regular expression, it's just a pattern that can match strings using `?` as a placeholder for any character and `*` as a placeholder for multiple unknown characters. So you cannot really make it accept files with different extensions. I'm not sure why would anyone use this in Emacs Lisp though, rather than regular expression. – wvxvw Sep 16 '15 at 18:40
  • 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
  • That is grepping only `*.py` but ignoring `*.htm?`. I have checked `grep-files-aliases` and tried last pattern as mentioned in question. – Chillar Anand Sep 16 '15 at 18:54
  • 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
  • Post it as answer please :) – Chillar Anand Sep 16 '15 at 19:08
  • Let us [continue this discussion in chat](http://chat.stackexchange.com/rooms/29201/discussion-between-chillaranand-and-wvxvw). – Chillar Anand Sep 16 '15 at 19:17
  • Regarding "I'm not sure why would anyone use this in Emacs Lisp though, rather than regular expression", that would be because it's *not* used in elisp -- those patterns are passed through to the `find` command (which can't be depended on to support regexp options; although if you were confident that it could, you could probably bind `find-name-arg` and use regexp patterns in place of the globs). – phils Sep 16 '15 at 22:25

2 Answers2

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.

wvxvw
  • 11,222
  • 2
  • 30
  • 55
0

rgrep does not accept spaces in the mini-buffer at the "files matching wildcard" prompt.

The workaround is to pass in:

*[.py,.htm,.html,pyml]

If just looking through extensions:

*.[py,htm,html]
young_souvlaki
  • 526
  • 2
  • 13