benma / visual-regexp.el

A regexp/replace command for Emacs with interactive visual feedback
392 stars 28 forks source link

Display artifacts when deleting pattern #69

Open codecoll opened 2 years ago

codecoll commented 2 years ago
  1. Start vr/query-replace
  2. type one character which matches current buffer contents, e.g: a
  3. delete the character, so the pattern is empty
  4. instead of showing the unchanged buffer, many | characters are shown
benma commented 2 years ago

It's not an artefact really, it is all the locations that match. If you hit enter and start typing the replacement, you will see the replacement appear in all those locations.

I disabled rendering these with the initial empty pattern as that would be a bit too distracting imho, as most of the time you want to actually search for a non-empty string.

codecoll commented 2 years ago

Highlighting the empty pattern seems unecessary, since if one wants to replace the empty string then one knows it matches after every character, so it does not give any useful information.

Shouldn't it work like the initial empty pattern, so it's consistent? I thought it was a bug, because it added | characters when I deleted the pattern which I didn't understand, since the user expects that by deleting the pattern one gets back to the inital state.

benma commented 2 years ago

since if one wants to replace the empty string then one knows it matches after every character

Same could be said for any other pattern, but this package is here to give visual feedback on your pattern. Explicit is better than implicit.

Shouldn't it work like the initial empty pattern, so it's consistent?

It could, but this is why I wrote:

I disabled rendering these with the initial empty pattern as that would be a bit too distracting imho, as most of the time you want to actually search for a non-empty string.

It is inconsistent though for sure.

I don't have a very strong opinion. Feel free to open a PR if you think it's worth it (but only for the empty pattern, there can be other zero-width patterns that should still be rendered).