Home Download Buy Blog Forum Support

RegReplace Plugin

Re: RegReplace Plugin

Postby quodlibet on Tue Dec 04, 2012 11:08 pm

facelessuser wrote:I probably use terms like "soon" too freely...

I'm always hesitant to ask you for new features -- it feels like enabling an addict :)

(I am referring to the insane speed with which you respond to both messages and bugs & suggestions.)

facelessuser wrote:I wanted to be able to fold all comments, so I added the fold/unfold a while ago...

I'm tinkering with a todo list (of all things!) and I want to fold some meta-data, but the gist is the same. Because I have a "nervous" Ctrl+S, it seemed reasonable (?) to use "on_save" as a trigger for this. This is such a niche thing.
quodlibet
 
Posts: 499
Joined: Sat Jun 18, 2011 5:53 pm

Re: RegReplace Plugin

Postby montrealDesigner724 on Wed Mar 20, 2013 3:24 pm

I've created the following, but nothing happens.

In the "reg_replace.sublime-settings":

// CONVERT TO LESS - STEPH
"lessrewrite_width": {
"find": "(\t*)[^-]\bwidth\b: (-?[0-9]*%|-?[0-9]*px|auto|-?[0-9]*);",
"replace": "$1.w($2);"
}

in the "Default.sublime-commands":

// Convert rewrite CSS to LESS - Steph
{
"caption": "Reg Replace: CSS to LESS",
"command": "reg_replace",
"args": {"replacements": ["lessrewrite_width"]}
},

I thought I did it correctly, but what am I missing?
montrealDesigner724
 
Posts: 3
Joined: Wed Mar 20, 2013 3:20 pm

Re: RegReplace Plugin

Postby facelessuser on Wed Mar 20, 2013 3:32 pm

Please give me a snippet of example code and the description of what you want to happen.
facelessuser
 
Posts: 1547
Joined: Tue Apr 05, 2011 7:38 pm

Re: RegReplace Plugin

Postby montrealDesigner724 on Wed Mar 20, 2013 4:23 pm

I want to use the RegEx in the replace to change this:

Code: Select all
width: 250px;


to this:

Code: Select all
.w(250px);


Once I get one working, my goal is to chain a number of them together so that I can convert a whole document instead of spending time inputing all the RegEx piece by piece.
I'm attaching the LESS document I'm trying to run this on, and the RegReplace files I modified.
Attachments
RegReplace.zip
(8.15 KiB) Downloaded 143 times
montrealDesigner724
 
Posts: 3
Joined: Wed Mar 20, 2013 3:20 pm

Re: RegReplace Plugin

Postby facelessuser on Wed Mar 20, 2013 4:44 pm

Two things. Python uses \\1 instead of $1. And your regex is in a string so escape literal backslashes.

        // CONVERT TO LESS - STEPH
"lessrewrite_width": {
"find": "(\\t*)[^-]\\bwidth\\b: (-?[0-9]*%|-?[0-9]*px|auto|-?[0-9]*);",
"replace": "\\1.w(\\2);"
}
facelessuser
 
Posts: 1547
Joined: Tue Apr 05, 2011 7:38 pm

Re: RegReplace Plugin

Postby montrealDesigner724 on Wed Mar 20, 2013 5:39 pm

Thanks for the info about the RegEx, I didn't realize it was Python.

So I updated my code with your suggestion, but nothing happens when I run it from the Command Palette, or am I supposed to run it from somewhere else?
montrealDesigner724
 
Posts: 3
Joined: Wed Mar 20, 2013 3:20 pm

Re: RegReplace Plugin

Postby facelessuser on Wed Mar 20, 2013 5:46 pm

I verified the code before I posted; that is why I asked for an example.

I did not run it on the ads_ca-fr_home.less you provided because there are no width attributes that need to be converted in it; therefore, it would do nothing. So if that is the file you are testing on, you are wasting your time because width is already converted in every instance in that file.
facelessuser
 
Posts: 1547
Joined: Tue Apr 05, 2011 7:38 pm

Re: RegReplace Plugin

Postby facelessuser on Wed Mar 20, 2013 6:22 pm

Also, if you are still having issues, I may need some more info. It should work fine from command palette. But if it isn't, you may be doing something odd, so I would need to know how you installed the package, are you editing the default version of the settings file, or did you copy it to user and edit that one. I may need to see your settings file to verify what you have done. Based on what you gave me, it should work, and did for me. If it isn't working for you, then something else isn't right on your end.
facelessuser
 
Posts: 1547
Joined: Tue Apr 05, 2011 7:38 pm

Re: RegReplace Plugin

Postby geerlingguy on Thu May 23, 2013 3:57 am

I just found your plugin, and it looks really helpful!

For my needs, I'm trying to simply get a command mapped to a key binding, and have it fold all functions (and only functions) in PHP files, which are structured like:

Code: Select all
/**
* Docblock for function.
*/
function example_function($param) {
  return $param;
}


The built-in code folding folds all comments, too, which is annoying in my workflow. Therefore I'm trying to add the command "fold_functions", and I think I'm getting hung up somewhere; it's not clear if I need to define the 'fold' action in the command itself, and then how to run the "fold_functions" command without the key binding (which I might also have set up incorrectly).

Here's my customizations:

Inside Default.sublime-commands (which Sublime opened when I chose Sublime > Preferences > Package Settings > Reg Replace > Commands - User):
Code: Select all
{
    {
        "caption": "Code Folding: Fold All Functions",
        "command": "fold_functions",
        "keys": ["shift+super+0"],
        "args": {"replacements": ["fold_functions"], "action": "fold"}
    },
}


Inside reg_replace.sublime-settings (which Sublime opened when I chose Sublime > Preferences > Package Settings > Reg Replace > Commands - User):
Code: Select all
{
    // Fold all functions.
    "fold_functions": {
        "find": "^function\\b(.*?(\\n))+.*?\\}",
        "greedy": false,
        "case": false
    }
}


It's a little confusing to me, but I've also only started using Sublime a few weeks ago, so I'm trying to understand the system.
geerlingguy
 
Posts: 2
Joined: Wed Jun 27, 2012 10:11 pm

Re: RegReplace Plugin

Postby vitaLee on Mon Aug 19, 2013 3:51 pm

I have the following usecase:
find hex colors with uppercase letters: #([A-F\d]+)
replace uppercase letters with lower ones: #\L$1\E
I expect to find #FF00AA and replace it with #ff00aa, which works as expected when i test it from sublime's Find and replace dialog.
Given the following settings I get a literal replace with #\L$1\E
Code: Select all
"css_lowercase_hex_colors": {
  "find"    : "#([A-F\\d]+)",
  "replace" : "#\\L$1\\E",
  "greedy"  : true,
  "case"    : true,
  "literal" : false
}

Is this Oniguruma feature supposed to be working with RegReplace?
vitaLee
 
Posts: 150
Joined: Tue Dec 27, 2011 11:10 pm

PreviousNext

Return to Plugin Announcements

Who is online

Users browsing this forum: No registered users and 7 guests