kopoli/helm-grepint

Bug matching some regexs

Closed this issue · 10 comments

If I try to match a character class with a space in it, e.g. [ ], then I get matches in my files for the string nil. This suggests that an elisp nil is somewhere being made into a string! Indeed, that character class does not seem to work in general with helm-grepint, though in other cases it simply produces no matches, for example FOO[ ], where I know that the string FOO exists.

Other character classes seem to work fine, for example [A-Z].

Additional observation: I get exactly the same result (matches of the string nil) if I try to search for the character class [^ ]. It may also matter that in all cases I've tested I'm in a git clone, so git grep should be being used as the grep command.

Another observation: if I search with helm-grepint for AB (space, A, B), the space seems to be ignored, whereas if I run git grep " AB", I get matches for space followed by AB.

The odd space behaviour is most likely caused by the following crude line in helm-grepint-grep-process:

	   :extra-arguments (replace-regexp-in-string "  *" ".*" helm-pattern)

I.e. all consecutive spaces in the given argument are replaced with .*. The goal of this is to have quickly grep for lines that match given group of words. IIUC helm-occur works in a similar manner.

Probably a more sophisticated approach to this is needed. At least returning nils for the text of every non-empty line is not desirable.

There's a further, more serious (for me) problem here: any space in a pattern becomes ".*". helm-occur does indeed work like this. I can't see any configuration mechanism for helm-occur. For a grep command this is most unexpected!

It seems that also the default helm-grep functionality follows this splitting behaviour. E.g. helm-do-grep-ag splits the given arguments abc def ghi to the following command line:

ag --line-numbers -S --hidden --color --nogroup  abc /tmp/ | ag -S --color  def | ag -S --color  ghi

(This also achieves that the space separated words can be in any order in the line. I prefer that the words are in the given order, hence the -> .*)

With some digging, it's possible in the helm-occur/helm-grep to concatenate the space separated words to a single argument by escaping the spaces. E.g.: abc\ def\ ghi. Though, I haven't found a way to get it support character classes with spaces in them.

Most likely supporting the above kind of escaping is quite easy to do. It is implemented in helm-mm-split-pattern in helm-multi-match.el.

Perhaps also some raw-argument -mode to the grep can be implemented (i.e. with some flag or argument it would do no processing to the string).

Thanks for looking into this. I confess I hadn't used helm-grep at all, and helm-occurs only a little.

The pull-request #6 should fix the mentioned issues (unless I forgot something).

I don't want to lose the default ' ' -> '.*' conversion, but the pull-request makes it configurable.

The printing-nil's -problem is made better (no nils are printed, but no highlighting is done either on those lines) in the final commit. It needs more testing, though.

That's great, thanks very much!

I merged the pull-request #6 which should solve the problems in this issue.

With some testing, it doesn't seem to cause any ill effects.

Thanks for reporting the issue !

That's brilliant, thanks again!