Sublime Forum

RegReplace Plugin

#65

First of all let me say that i love this package, makes my life incredibly easier. :smiley:
A few days ago all my “reg_replace” commands disappeared from the command palette and key bindings stopped working as well.
I did some troubleshooting but nothing seemed to help, eventually i installed a fresh copy of Sublime Text and the RegReplace package in a different machine only to find that not even the examples in the Default.sublime-commands seem to be working anymore.
On a fresh install, tried adding this command to the list

{
    "caption": "Reg Replace: Remove Trailing Spaces",
    "command": "reg_replace",
    "args": {"replacements": "remove_trailing_spaces"]}
},

but is does not show up in the command palette.
"open_file " commands seem to work fine, only the “reg_replace” ones are giving me problems.
Is anyone having the same problem ? Is there anything else i should check ?

0 Likes

#66
  1. Github repo’s issue section is probably more appropriate for getting help as it actually notifies me and keeps a record in a place people can more easily find if they have similar issues.
  2. ST2 or ST3?
  3. Are you getting console errors? If you see no commands, usually it is because sublime failed to load the plugin. So search your console for errors you can share here.

RegReplace is working for me on ST3 OSX and Windows.

0 Likes

#67
  1. Done, moved to github. github.com/facelessuser/RegReplace/issues/29
  2. ST2
  3. Now that you mention the console, i do see an error on load there

Reloading plugin C:\Users\ricardosz\AppData\Roaming\Sublime Text 2\Packages\RegReplace\rr_extended.py
Reloading plugin C:\Users\ricardosz\AppData\Roaming\Sublime Text 2\Packages\RegReplace\rr_notify.py
Reloading plugin C:\Users\ricardosz\AppData\Roaming\Sublime Text 2\Packages\RegReplace\rr_plugin.py
Reloading plugin C:\Users\ricardosz\AppData\Roaming\Sublime Text 2\Packages\RegReplace\rr_replacer.py
Traceback (most recent call last):
File “.\sublime_plugin.py”, line 62, in reload_plugin
File “.\rr_replacer.py”, line 3, in
from RegReplace.rr_plugin import Plugin
ImportError: No module named RegReplace.rr_plugin
Reloading plugin C:\Users\ricardosz\AppData\Roaming\Sublime Text 2\Packages\RegReplace\rr_sequencer.py
Traceback (most recent call last):
File “.\sublime_plugin.py”, line 62, in reload_plugin
File “.\rr_sequencer.py”, line 11, in
from RegReplace.rr_replacer import FindReplace
ImportError: No module named RegReplace.rr_replacer

0 Likes

#68

There was an ST3 fix backported to ST2, but I mistakenly released the ST2 release from the wrong branch. Release 1.10.1 for ST2 should fix this issue when available in Package Control.

0 Likes

#69

I’m trying to replace few characters in my text, for example “š” with “\v{s}” but it doesn’t work :confused:

  • for replace with “\v{s}” i get error: Error trying to parse settings: Invalid escape in Packages/RegReplace/reg_replace.sublime-settings:87:24
  • for replace with “\v{s}” it just changes to: ‘vertical tab sign’{s}

can someone please explain how to keep \v?

0 Likes

#70

\v is not a recognized back reference. Since you are suing Python’s re regex module, you need to use something that works with that, so here is a simple example:

"unicode_test": { "find": "replace me", "replace": "<verttab>\u000B<verttab>" }

Good luck!

0 Likes

#71

2.2.0 is out.

  • Adds a number of improvements to handling upper case and lower case back references in replace patterns.
  • It also adds support for escaping characters with \Q…\E in search patterns.
  • Adds upper\lower case character classes via \l and \c in search or the inverse via \L and \C (if re.Unicode flag is enabled, they will act as unicode character classes).
  • Also adds support for unicode properties via \p{Letter_Number} or \p{Nl} or the inverse form \P{Letter_Number} or \P{Nl} etc. It is just limited to the general property classes.

Anyways, read more here facelessuser.github.io/RegReplac … references.

0 Likes

#72

2.2.1 update

  • Added some fixes for the extended backrefs where some situations it would not be able to detect inline (?x) or (?u) flags to alter the parsing logic. I doubt anyone ran into the issue as you would have to bury the flags in a non usual way, but anyways, it should be fine now.
0 Likes

#73

Hello,
I’m having problem with Reg Replace. I’ve received a lot of poems lyrics in .txt format (I’m not programist). Problem is they all have been saved with wrong encoding which resulted with replacing all national characters (I’m from Poland) to their equivalent in Unicode. I was looking for a tool which would allow me to batch all files at once and I bumped to Reg Replace for STE. I have installed Reg Replace using Package Controll and decided to do one file at the time. Fallowing this instructions:

see here

I’ve put in reg_replace.sublime-settings fallowing code:

`{
  "replacements": {
    "pl1": {
      "find": "ê",
      "replace": "ę",
      "greedy": true,
      "case": false,
      "literal": true
    },
    "pl2": {
      "find": "¿",
      "replace": "ż",
      "greedy": true,
      "case": false,
      "literal": true
    },
    "pl3": {
      "find": "³",
      "replace": "ł",
      "greedy": true,
      "case": false,
      "literal": true
    },
    "pl4": {
      "find": "¹",
      "replace": "ą",
      "greedy": true,
      "case": false,
      "literal": true
    },
    "pl5": {
      "find": "Ÿ",
      "replace": "ź",
      "greedy": true,
      "case": false,
      "literal": true
    },
    "pl6": {
      "find": "œ",
      "replace": "ś",
      "greedy": true,
      "case": false,
      "literal": true
    },
    "pl7": {
      "find": "æ",
      "replace": "ć",
      "greedy": true,
      "case": false,
      "literal": true
    }
  }
}`

Than I’ve put this code into Default.sublime-commands:

[
  {
    "caption": "Reg Replace: Polish characters",
    "command": "reg_replace",
    "args": {
      "replacements": [
        "pl1",
        "pl2",
        "pl3",
        "pl4",
        "pl5",
        "pl6",
        "pl7"
      ]
    },
    "find_only": true
  }
]

In the end I hit Ctrl + Shift + P and by typing “Polish characters” (name of my command), I find it, hit Enter and nothing happens. No error, no changes to opened document. Normally I would attempt some kind of trouble shooting, but I know only basis of Java Script and PHP. What I should check, where to read?

I’m using latest version of Sublime and running Windows 7 x64 Pro.

0 Likes

#74

@mateuszfryc, as tempting as it is to follow someone’s guide on the internet, there is no guarantee it is up to date – in this case, the guide you followed is very outdated.

  1. The official user guide is here: http://facelessuser.github.io/RegReplace/usage/#create-find-and-replace-sequences.

  2. Documentation states that replacement rules are now defined in reg_replace_rules.sublime-settings.

  3. You can’t use the argument case anymore as it is no longer valid. Case sensitivity is true by default as it is in the regular expression engine. If you need to do a non literal replacement sequence, you use Python’s regular expression case insensitive flag of (?i). If doing a literal example as you are doing, you use the flag literal_ignorecase option as the find rule will now be parsed literally not accounting the flag.

    Examp

    /* For literal: */
    "pl1": {
      "find": "ê",
      "replace": "ę",
      "greedy": true,
      "literal_ignorecase": true,
      "literal": true
    },
    /* non-literal */
    "pl1": {
      "find": "(?i)ê",
      "replace": "ę",
      "greedy": true
    },
    
  4. You made a mistake with your command, the find_only argument should have been under args.


In the next version to be released, I have a quick start guide available in Preferences -> Package Settings -> RegReplace -> Quick Start Guide but unfortunately it is taking a while for a new regex module dependency to get merged on Package Control. I can’t make a new release until that gets merged:

You can read the quick start guide here:


Anyways, this is what I did to get your example to work:

  1. Edit reg_relace_rules.sublime_settings and add this:

    {
        "format": "3.0",
        "replacements":
        {
            "pl1": {
              "find": "ê",
              "replace": "ę",
              "greedy": true,
              "literal_ignorecase": true,
              "literal": true
            },
            "pl2": {
              "find": "¿",
              "replace": "ż",
              "greedy": true,
              "literal_ignorecase": true,
              "literal": true
            },
            "pl3": {
              "find": "³",
              "replace": "ł",
              "greedy": true,
              "literal_ignorecase": true,
              "literal": true
            },
            "pl4": {
              "find": "¹",
              "replace": "ą",
              "greedy": true,
              "literal_ignorecase": true,
              "literal": true
            },
            "pl5": {
              "find": "Ÿ",
              "replace": "ź",
              "greedy": true,
              "literal_ignorecase": true,
              "literal": true
            },
            "pl6": {
              "find": "œ",
              "replace": "ś",
              "greedy": true,
              "literal_ignorecase": true,
              "literal": true
            },
            "pl7": {
              "find": "æ",
              "replace": "ć",
              "greedy": true,
              "literal_ignorecase": true,
              "literal": true
            }
        }
    }
    
  2. Place this command in Default.sublime-commands:

        {
            "caption": "Reg Replace: Polish characters",
            "command": "reg_replace",
            "args": {
                "replacements": [
                    "pl1",
                    "pl2",
                    "pl3",
                    "pl4",
                    "pl5",
                    "pl6",
                    "pl7"
                ],
                "find_only": true
            }
        }
    
  3. And with the following text in a file 꿳¹Ÿœæ, you can run the command and replace and get ężłąźść.

1 Like

#75

@facelessuser thank you! I’ve fixed what you said and now it works perfectly :smiley:

0 Likes

#76

You’re welcome :).

0 Likes

#77

Thank you for your plugin, it looks promising.

I need to find all “GetSheHe” in a scope defined in my syntax file.
meta.block.french.csv is the scope (all characters between the second and the third semicolon
in each line)

  • In Default.sublime-commands:
{
    "caption": "Reg Replace: Highlight GetSheHe",
    "command": "reg_replace",
    "args": {
        "replacements": ["highlight_getshehe"],
        "action": "mark",
        "options": {"key": "name", "scope": "invalid", "style": "underline"}
    }
}
  • In reg_relace_rules.sublime_settings:
    "highlight_getshehe":
    {
        "scope": "meta.block.french.csv",
        "literal": true,
        "find": "GetSheHe",
        "greedy": true,
        "replace": ""
    }

My issue is with scope parameter. If i add it, it highlights all the scope when GetSheHe exists. If i remove it, it highlights any GetSheHe in the file. How can I do for highlighting all GetSheHe only in this scope ?
I don’t understand how scope_filter works, maybe it is the solution…

And, is there a parameter for having the mark symbol (a white circle) at the beginning of the line when finding a match ? I tested mark, but no avail. Apparently, it works exactly like underline.

0 Likes

#78

@Carpenter, unfortunately, you haven’t provided me with enough info. Please provide example text, and the syntax package you are using to highlight your file.

0 Likes

#79

@facelessuser

4 files:

  • syntax
  • setting
  • theme
  • example: there are 10 GetSheHe in this line. I would like highlight with your plugin #3 #4 #5 #6 because they are in French column (between the second and the third semicolon).

Thank you

0 Likes

#80

I will take a look later today. In the future, please create issues in the repo’s issue tracker. I prefer to answer issues there as I then have a issue to reference when people have similar issues.

0 Likes

#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