hlissner / evil-snipe

2-char searching ala vim-sneak & vim-seek, for evil-mode
MIT License
340 stars 25 forks source link

User-defined regexes? #12

Closed ghost closed 9 years ago

ghost commented 9 years ago

This is slightly related to the idea of symbol groups #10 . Another idea might be to have a char for regexes, for example æ, the key to the left of the right pinky. Then the key coming after the æ would stand for a user defined regex.

I would use it like this: sæf to search with the regex (defined by me in a dotfile) ^def \w+):.

This way I could quickly find all python function definitions with sæfsss (I always forget the function names). Another one could be sæp to find @property, etc.

I would probably create a different regex map for the different language modes.

This is probably more of a poweruser feature, but just throwing it out there. You could even have a crowd-configured library of useful regexes like yasnippet.

hlissner commented 9 years ago

Actually, this was exactly what I had planned to implement to solve #10. User-defined [regex] symbol groups. Additionally, each symbol group can be differently scoped.

For instance: (add-to-list 'evil-snipe-symbol-groups '("[" "[[{(]" buffer)) would make searches for sa[ jump to the next instance of a[, a{ or a( anywhere in the entire buffer. The third parameter would be take anything that evil-snipe-scope accepts, or can be omitted to use the default scope.

I haven't implemented it yet, but that's the plan.

hlissner commented 9 years ago

And done. I haven't implemented symbol-group specific scopes, so right now it only takes character => regex pattern, like so:

(add-to-list 'evil-snipe-symbol-groups '(?[ "[[{(]"))

This should also fix/address #10

halbtuerke commented 9 years ago

Shouldn't this be?

(add-to-list 'evil-snipe-symbol-groups '(?\[ "[[{(]"))
hlissner commented 9 years ago

Yes, it should. My mistake!

halbtuerke commented 9 years ago

Ok, then you might have to correct the docstring for evil-snipe-symbol-groups.

ghost commented 9 years ago

How would you add the opposite, i.e. ] matches ])}? No regex I produce seem work (which isn't strange since ] closes the regex brackets. I couldn't get escaping it to work either. (]|)|}) did not do the trick either....

halbtuerke commented 9 years ago

How would you add the opposite, i.e. ] matches ])}?

(add-to-list 'evil-snipe-symbol-groups '(?\] "[]})]"))
ghost commented 9 years ago

Brilliant, thanks.

hlissner commented 9 years ago

Ok, then you might have to correct the docstring for evil-snipe-symbol-groups.

And done. Also, I've discovered a bug: symbol groups are ignored when repeating searches. I'm on that now.

ghost commented 9 years ago

I'm now unable to repeat searches with fFtT. Anyone else have the same problem?

hlissner commented 9 years ago

At all? Just in case this is a MELPA issue, could you check out evil-snipe.el and tell me if you have 1.6.2 or 1.6.3?

(A quick way to get to that file is to do M-x describe-function RET evil-snipe-s and clicking the "evil-snipe.el" link in the help buffer.)

ghost commented 9 years ago
;; Version: 20150301.2131
;; X-Original-Version: 1.6.2

But this might be something wrong with the config on my end. When calling M-x evil-snipe-override-mode it works.

hlissner commented 9 years ago

Is evil-snipe-override-evil set to t?

hlissner commented 9 years ago

Also: you seem to be one version behind (the latest was 1.6.3, pushed ~15 minutes ago). I just bumped it to 1.6.4 a second ago. I'm not sure how often MELPA checks for changes though.

halbtuerke commented 9 years ago

I'm not sure how often MELPA checks for changes though.

In my experience MELPA updates every 10-30 minutes.

ghost commented 9 years ago

This works for me now with the new version. Thanks.