Sublime Forum

RegReplace Plugin

#81

Short answer is that this is due to the way replace is done internally with scope replace. RegReplace will actually replace the entire scope with all your matches replaced proper, which is why it highlights the entire scope. It doesn’t return individual regions for each replace of a scope find. So I am actually getting a region returned for the entire scope instead of individual regions. I would have to refactor the code to possibly preform a different kind of search on the scope buffer that gives me individual regions and replace buffers. While this isn’t a bug per se, I understand that individual regions would be the preferred result.

On a side note, I did find an unrelated bug. If I disable literal, the command fails. Looks like I was trying to recompile an already compiled pattern when doing non-literal scope replacements :confused:. I’ll at least have that bug fixed in the next version.

As for the highlight resolution of scope searches, I’ll have to look into a different way of parsing scope buffers to return regions for each individual replace. I don’t know when I’ll have this work completed, but I will probably rush a bug fix to get the more critical bug listed above.

0 Likes

#82

For anyone else that sees the recent posts and is confused. RegReplace has two kinds of searches.

  1. Regex searches with scope qualifiers: a regex search that then applies a scope filter on the result to determine if it is valid.

  2. Scope search with regex qualifiers: a search for specific scopes that then applies a regex to it to determine if the scope is a valid result.

So RegReplace when highlighting scope replacements treats the whole scope as a valid result if it contains a regular expression match. It is the opposite of “regex searches with scope qualifiers” which is doing individual regex searches and then applying a scope check to it.

The request by @Carpenter is to have finer resolution and show the regex matches within the scope search. Highlighting the whole scope in a scope rule is not a bug, just the current behavior.

In the future I plan on looking into giving scope search results in finer resolution, but this is low priority. Instead of just sending a scope through subn, we would now have to treat each scope as a separate buffer and iterate over the matches within the scope treating each match individually. This will add more complexity and require a refactoring of the current approach. Hopefully that makes this a bit more clear.

0 Likes

#83

RegReplace 3.2.1

Released Mar 5, 2017

  • FIX: Fix issue where scope search pattern could fail due to recompiling a compiled pattern.

This should fix issue where RegReplace attempts to recompile a compiled pattern in certain scope replacements.

0 Likes

#84

Though a new release is out, there is nothing notable about it, but I did package the latest 3rd party regular expression module regex and released it. So run Satisfy Dependencies to get it if you use it or have a passing interest in using it. If you are using re and that’s your favorite, then you can ignore this.

This time I built both the 32 and 64 bit linux binaries on Docker images with a super old CentOS 5, so if it didn’t run on some Linux systems, hopefully now it will. Windows is directly from the wheel, so it should run on all windows systems. Lastly OSX was built on my current mac, so hopefully it works with most macs, who knows.

0 Likes

#85

3.4.0 is out. Notable change is that scope searches now highlights the find results proper instead of highlighting the whole parent scope. The same goes for other actions like fold, mark, select, etc.

I know this has bugged people for a long time, but I finally got around to making the change.

As always, let me know if I broke something along the way.

0 Likes

#86

I don’t normally announce every time I update dependencies, but this should be the last time. Regex has been updated to: Update to regex-2017.06.07 (2.4.124). I only mention it because now I build the OSX binaries on a Snow Leopard VM. Since it is so old, it should maximize compatibility on most OSX systems.

0 Likes

#87

3.6.0 is out.

This adds support for the Regex library’s format replace template (particularly useful for indexing captures in a group as the Regex library actually retains multiple captures in groups):

>>> regex.subf(r"(\w)+ (\w+)", "{0} => {2} {1[0]}", "foo bar")
'foo bar => bar f'

This can also be used with Backrefs (which requires version 2.1, so ensure dependencies are the latest). Also backrefs includes bug fixes and such, so it is good to pick it up regardless of whether you wish to use the new format feature.

This functionality is also available for Re, but is obviously limited to only one capture as Re only retains the last capture of a group. But if you like the syntax, it is available.

Anyways, you can read more and see more examples about the format replace in Backrefs docs: http://facelessuser.github.io/backrefs/#format-replacements. I’d link to Regex’s documentation, but format replace is only covered in passing.

Big thing to note, as always, read the documentation and links to the various libraries you are using. Recognized syntax, or handling of escaped characters can differ slightly depending on which regular expression engine you are using and whether you have extended_back_references (Backrefs) enabled. For instance, Regex’s format style (without Backrefs) will not translate \\n to a newline like normal replace templates do, it requires a literal new line \n. Format templates with Backrefs will handle \\n like they are in normal replace templates.

Remember to report bugs if you find them. I’ll probably be updating the Regex dependencies to the latest sometime soon to pick up any recent bug fixes.

2 Likes