benma / visual-regexp.el

A regexp/replace command for Emacs with interactive visual feedback
400 stars 29 forks source link

Continue to show highlighted regions with invalid regexp #47

Closed raxod502 closed 7 years ago

raxod502 commented 7 years ago

One thing that annoys me with visual-regexp is that when I type the beginning of a group \(, all the highlighted matches disappear until I close the group \), because the regexp is invalid.

It makes sense that when the group delimiters are mismatched, an error message is displayed. But it would be much nicer if the old highlights did not go away. Even better, since this is such a common use case, visual-regexp could try adding closing delimiters when it encountered an invalid regexp, and see if that fixed the error. That way, you could continue to have instant feedback for the entire process of typing a regexp, even one with groups.

benma commented 7 years ago

Thanks.

I am afraid I don't agree. If the regexp is invalid but matches are still shown, it is confusing. It would imply that hitting enter and entering a replacement will work, but it wouldn't.

About autocorrecting invalid regexpes: It would deviate too much from stock Emacs regexp search/replace, which visual-regexp is trying to mirror as closely as possible.

You could build an extension that auto-inserts the closing \) immediately after entering a \( though, which should largely mitigate your annoyance. Maybe electric-pair could be used for that (it already can auto-close normal parens, maybe it can be modified to close \( too).

raxod502 commented 7 years ago

I agree that auto-inserting paired delimiters would solve the problem, but it doesn't quite get there because all of your matches disappear when you type the backslash.

That being said, I totally understand your perspective and am happy to keep this in my own advice. (Or perhaps I could add a configuration variable which would be off by default?)

benma commented 7 years ago

Thanks for understanding. I'd prefer it if you kept this in your local config. Did you already code it?

raxod502 commented 7 years ago

I didn't, but it's on my long, long list of to-do items https://github.com/raxod502/radian/issues, see https://github.com/raxod502/radian/issues/264.