Home Download Buy Blog Forum Support

Plugin Idea: Would This Be Useful?

Re: Plugin Idea: Would This Be Useful?

Postby brentdooley999 on Tue Jan 10, 2012 10:52 pm

Very nice. Worked on the first try. I didn't put my replacement in brackets.

Thanks for the great example and plugin!
brentdooley999
 
Posts: 5
Joined: Tue Jan 10, 2012 10:11 pm

Re: Plugin Idea: Would This Be Useful?

Postby facelessuser on Wed Jan 11, 2012 4:12 am

A lot of additions:

-Add ability to filter results by scope
-Add regex feedback in status bar (or optionally a panel)
-Add setting to enable panel feedback
-Add non-greedy replace relative to cursor (allow wrapping)
-Add a input panel for quickly creating and running a sequence
-Add trailing space removal "replacement"
-Change default regex sequence commands

I have done some general testing, but do let me know if you find some bugs. I am going to do some heavier testing in the next couple to shake out any bugs and probably do an initial release, so if you have any requests, suggestions, or issues let me know.

https://github.com/facelessuser/RegReplace
facelessuser
 
Posts: 1575
Joined: Tue Apr 05, 2011 7:38 pm

Re: Plugin Idea: Would This Be Useful?

Postby facelessuser on Wed Jan 11, 2012 4:20 am

By the way, the input sequencer command simply allows you to create a regex sequence on the fly via an input panel.

So if you have a couple of replacements defined in the settings file, you can just enter the names separated by commas and run the sequence of replacements.

Was using it during testing, but then I figured why not leave it in.
facelessuser
 
Posts: 1575
Joined: Tue Apr 05, 2011 7:38 pm

Re: Plugin Idea: Would This Be Useful?

Postby brentdooley999 on Wed Jan 11, 2012 3:44 pm

I downloaded and ran a few tests and everything seems to work well. I have two more question for you and any help would be appreciated. I'm editing large XHR responses with lots of "\n" and "\t" control characters. I need to replace the "\n"s with a sublime line breaks and the "\t"s with either tabs or a few spaces.

1) Is it possible to string together multiple replaces into one command or do I need to use 2 commands?

2) Do you know how to get the replace to pick up "\n" and "\t" strings? I've tried everything I can think of and it's a hard thing to search for.

I'll keep working with it and I will run some more test cases. Thanks in advance to any help.
brentdooley999
 
Posts: 5
Joined: Tue Jan 10, 2012 10:11 pm

Re: Plugin Idea: Would This Be Useful?

Postby facelessuser on Wed Jan 11, 2012 4:18 pm

brentdooley999 wrote:I downloaded and ran a few tests and everything seems to work well. I have two more question for you and any help would be appreciated. I'm editing large XHR responses with lots of "\n" and "\t" control characters. I need to replace the "\n"s with a sublime line breaks and the "\t"s with either tabs or a few spaces.

1) Is it possible to string together multiple replaces into one command or do I need to use 2 commands?


Do you mean once a specific region is targeted for replace, you want to run multiple regex on just that region, or just chain multiple regex in one command? I am not sure I understand; could you elaborate?

This is perfectly allowable; is this not what you are looking for?
Code: Select all
"args": {"replacements": ["trailing_spaces","another_task","yet_another_task"]}


brentdooley999 wrote:2) Do you know how to get the replace to pick up "\n" and "\t" strings? I've tried everything I can think of and it's a hard thing to search for.

I'll keep working with it and I will run some more test cases. Thanks in advance to any help.


What kind of file line endings are you dealing with? Windows? or Unix/Linux?

Windows you may need to do something like /n/r for line endings.

If you can post an example file here and explain what exactly you are trying to target, I may be able to help you.
facelessuser
 
Posts: 1575
Joined: Tue Apr 05, 2011 7:38 pm

Re: Plugin Idea: Would This Be Useful?

Postby brentdooley999 on Wed Jan 11, 2012 5:48 pm

What kind of file line endings are you dealing with? Windows? or Unix/Linux?

Windows you may need to do something like /n/r for line endings.

If you can post an example file here and explain what exactly you are trying to target, I may be able to help you.


I'm on a Mac. I'm still a little new to developing on a Mac so line feeds and whatnot still throw me a bit. I'm doing web development and sometimes I have to execute Javascript embedded in a JSON reply. Here's an example of the returned code. I have the ability to turn on a debug mode to leave the line feeds and tabs.

Code: Select all
if(Ext.getCmp('report_toolbar'))\n{\n\tvar btn = new Ext.Button({\n\t\tid:'btn_0', \n\t\ttext: 'Labor Expense GL', \n\t\tenableToggle: true, \n\t\tpressed: true,\n\t\ttoggleGroup: 'btn_grp',\n\t\tlisteners:{\n\t\t\tclick:function(){\n\t\t\t\tExt.getCmp('win_0').show();\n\t\t\t}\n\t\t}\n\t});\n\tExt.getCmp('report_toolbar').add(btn);\t\n\tExt.getCmp('report_toolbar').doLayout();\n\tvar ismaximizable = true;\n\tvar isminimizable = true;\n}


To debug it I need it in a more readable format like this.

Code: Select all
if(Ext.getCmp('report_toolbar'))
{
   var btn = new Ext.Button({
      id:'btn_0',
      text: 'Labor Expense GL',
      enableToggle: true,
      pressed: true,
      toggleGroup: 'btn_grp',
      listeners:{
         click:function(){
            Ext.getCmp('win_0').show();
         }
      }
   });
   Ext.getCmp('report_toolbar').add(btn);   
   Ext.getCmp('report_toolbar').doLayout();
   var ismaximizable = true;
   var isminimizable = true;
}


Also, I will try that other thing once I get this going. Thanks!
brentdooley999
 
Posts: 5
Joined: Tue Jan 10, 2012 10:11 pm

Re: Plugin Idea: Would This Be Useful?

Postby facelessuser on Wed Jan 11, 2012 6:01 pm

Ahh, you are converting the the symbol "\n" to a literal newline, etc.

You have to escape your escapes so the slash will be literal. I am also telling it here that none of the target can be part of a string; "\n" inside a string is probably what you really want it to be. Hope that helps you.

Code: Select all
      "convert_symbol_newline_to_literal": {
         "find": "\\\\n",
         "replace": "\n",
         "scope_filter": ["-!string"],
         "greedy": true,
         "case": true
      },
      "convert_symbol_tab_to_literal": {
         "find": "\\\\t",
         "replace": "\t",
         "scope_filter": ["-!string"],
         "greedy": true,
         "case": true
      }


Then you can chain these two together in a command.
facelessuser
 
Posts: 1575
Joined: Tue Apr 05, 2011 7:38 pm

Re: Plugin Idea: Would This Be Useful?

Postby brentdooley999 on Wed Jan 11, 2012 6:17 pm

That worked great. All of the escaping was throwing me.

Thanks for all for your help! I really appreciate it.
brentdooley999
 
Posts: 5
Joined: Tue Jan 10, 2012 10:11 pm

Re: Plugin Idea: Would This Be Useful?

Postby facelessuser on Wed Jan 11, 2012 6:22 pm

brentdooley999 wrote:That worked great. All of the escaping was throwing me.


Yeah, it is because you are trying to represent regex inside a string, so you have escape things for regex, but you also have escape them because you are in string. As soon as I realized what you were doing, I knew that had to be your problem. It can trip me up some times too.
facelessuser
 
Posts: 1575
Joined: Tue Apr 05, 2011 7:38 pm

Re: Plugin Idea: Would This Be Useful?

Postby facelessuser on Thu Jan 12, 2012 2:00 am

Small update on non-greedy logic. Also, I removed the portion of the code that moves the cursor to the beginning of the non-greedy replace.
facelessuser
 
Posts: 1575
Joined: Tue Apr 05, 2011 7:38 pm

PreviousNext

Return to Plugin Development

Who is online

Users browsing this forum: No registered users and 4 guests