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