Sublime Forum

Plugin Idea: Would This Be Useful?

#23

Thanks so much! I have no idea either. It must really want to be released :smiley:

0 Likes

#24

I want to say I disagree forks (to sublimetext organization) of packages without the authorization of the package “owner”

edit: I also sent to you an invitation to “collaborate” there.

0 Likes

#25

my bad … I forked it to my account the other day … and accidentally pressed the ST organisation first but didn’t think the request completed …

0 Likes

#26

[quote=“tito”]I want to say I disagree forks (to sublimetext organization) of packages without the authorization of the package “owner”

edit: I also sent to you an invitation to “collaborate” there.[/quote]

I agree, and thanks for the invite.

No worries. It happens. It just surprised me.

0 Likes

#27

I wanted to see if anyone has an opinion on this. I added scope filtering locally on my machine the other day, but I am trying to figure out the best way to represent the functionality.

Basically I have positive and negative filtering (must include and must exclude scope respectively), but on top of that, I have further defined the difference: include at least one instance of scope vs entire match must be of scope type; alternately on the negative side: one instance of scope disqualifies match, and only the entire match of a scope disqualifies match.

My questions is the best way to represent this to be the most intuitive. Currently I have:

  • Any instance of scope qualifies match: scope.name
  • Entire match of scope qualifies match: !scope.name
  • Any instance of scope disqualifies match: -scope.name
  • Entire match of scope disqualifies match: -!scope.name

Thoughts, opinions?

0 Likes

#28

Also looking for good useful regex tasks to include by default. If you have any suggestions, post them here. I may not include all of them, but I will evaluate them and include the ones I feel would be the most useful.

0 Likes

#29

I just downloaded Sublime yesterday and I am loving it. I’ve been playing with the plugin stuff off and on today and I think I’m missing something. I think I understand how the plugins work but for the life of me I can’t find how to pass arguments to the view.run_command function. In other words, what’s the command prompt syntax to run regreplace? When I run it the script always dies at “if len(replacements) > 0:” because I’m, apparently, not passing anything in.

Any help would be appriciated.

0 Likes

#30

[quote=“brentdooley999”]I just downloaded Sublime yesterday and I am loving it. I’ve been playing with the plugin stuff off and on today and I think I’m missing something. I think I understand how the plugins work but for the life of me I can’t find how to pass arguments to the view.run_command function. In other words, what’s the command prompt syntax to run regreplace? When I run it the script always dies at “if len(replacements) > 0:” because I’m, apparently, not passing anything in.

Any help would be appriciated.[/quote]

First off, you must have the replacement(s) you want defined in the settings file(reg_replace.sublime-settings). If you are adding your own, I recommend to copy the settings file to the User folder under the Packages folder and modify it there so your settings will persist when you upgrade the plugin.

For example:

{ "replacements": { "remove_html_comments": { "find": "<!--\\s\\S]+?-->", "replace": "", "scope_filter": "!comment"], "greedy": true, "case": true }, "trailing_spaces": { "find": " \\t]+$", "replace": "", "greedy": true, "case": true } } }

You can then define a command in the Defaults.sublime-commands file. Do the same as your settings file if you are going to make changes that you wish to persist.

Follow the same convention as your command file.

So, if I have a replacement defined in my settings file called “trailing_spaces”, I would call it via the command line in the console like this (you can also call this from other plugins as well similarly; you just need a valid view to call it):

sublime.active_window().active_view().run_command("reg_replace", {"replacements" : "trailing_spaces"]})

or define it in the command file like this (this will make the command accessible via the command pallet):

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

Notice the arguments for the command are contained inside a dict, and the “replacements” argument is always in an array (you can add other regex tasks to the array to perform multiple regex in a sequence).

I hope this makes it a little more clear.

Note this is still in development, so please note there may be some bugs. I have a fairly big commit comming tonight that should complete most of the currently planned features…assuming there are no bugs :smile:.

0 Likes

#31

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

Thanks for the great example and plugin!

0 Likes

#32

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.

github.com/facelessuser/RegReplace

0 Likes

#33

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.

0 Likes

#34

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.

0 Likes

#35

[quote=“brentdooley999”]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?[/quote]

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?

"args": {"replacements": "trailing_spaces","another_task","yet_another_task"]}

[quote=“brentdooley999”]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.[/quote]

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.

0 Likes

#36

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.

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.

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!

0 Likes

#37

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.

"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.

0 Likes

#38

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

Thanks for all for your help! I really appreciate it.

0 Likes

#39

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.

0 Likes

#40

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.

0 Likes

#41

Probably will have an official release tomorrow (if I get all of my testing and documentation done), and then I will start the process for getting it on Package Control.

It has already proved useful to me, so I am glad I picked this project up. Thanks, to all the great ideas and feedback; I was mainly the implementer on this one, and everyone else supplied the ideas.

0 Likes

#42

The official thread for RegReplace is now here viewtopic.php?f=5&t=4594&start=0

Please post all questions, comments, etc. in the official thread.

0 Likes