No, there isn’t. You are absolute right, using -comment works as expected.
Thanks a lot for your help.
–
Highend
No, there isn’t. You are absolute right, using -comment works as expected.
Thanks a lot for your help.
–
Highend
I tried to use RegReplace to create a simple sequence to swap quotes of all double quoted strings, or all single quoted strings. I wanted to ensure it woud work in all languages regardless of whether they used “double quoted” or “single quoted” scope types. It was really hard, so I figured there had to be a better way. This lead me to add a new feature.
This allowed me to use a scope search with regex qualifiers, and identify all string regions. I then used regex to determine if they were single or double quoted and find all internal quotes that needed to be escaped and unescaped within the string.
Regex defines for swapping from double to single quotes
"swap_quotes_to_single": {
"scope": "string",
"find" : "^\"(.*?)\"$",
"replace": "'\\1'",
"greedy_replace": false
},
"escape_single_quotes": {
"scope": "string",
"find" : "^(\".*?(?<!\\\\))((?:\\\\]{2})*)'(.*?\")$",
"replace": "\\1\\2\\'\\3",
"greedy_replace": false,
"multi_pass_regex": true
},
"unescape_quotes_double": {
"scope": "string",
"find" : "^('.*?(?<!\\\\))((?:\\\\]{2})*)\\\\\"(.*?')$",
"replace": "\\1\\2\"\\3",
"greedy_replace": false,
"multi_pass_regex": true
},
Regex defines for swapping for single to double quotes
"swap_quotes_to_double": {
"scope": "string",
"find" : "^'(.*?)'$",
"replace": "\"\\1\"",
"greedy_replace": false
},
"escape_double_quotes": {
"scope": "string",
"find" : "^('.*?(?<!\\\\))((?:\\\\]{2})*)\"(.*?')$",
"replace": "\\1\\2\\\"\\3",
"greedy_replace": false,
"multi_pass_regex": true
},
"unescape_single_quotes": {
"scope": "string",
"find" : "^(\".*?(?<!\\\\))((?:\\\\]{2})*)\\\\'(.*?\")$",
"replace": "\\1\\2'\\3",
"greedy_replace": false,
"multi_pass_regex": true
}
The commands
// Swap Quotes
{
"caption": "Replace: Swap Quotes to Single",
"command": "reg_replace",
"args": {"replacements": "escape_single_quotes", "swap_quotes_to_single", "unescape_double_quotes"], "find_only": true}
},
{
"caption": "Replace: Swap Quotes to Double",
"command": "reg_replace",
"args": {"replacements": "escape_double_quotes", "swap_quotes_to_double", "unescape_single_quotes"], "find_only": true}
}
Now it is easy .
Version 1.0
That finishes off everything I had planned (now I can stop tinkering with this). Scope searches with literal search qualifiers cannot use “multi_pass_regex” param (it will just be ignored). There is really no need for it since literals have no trouble finding all instances. If in the future people find a scenario where there is useful, I will add it, but until then, I think this plugin is feature complete.
I am open to improvements or new feature ideas; just drop a post here explaining what it is you want, and I will evaluate the request and decide.
If you find any bugs, let me know.
Didn’t realize that view.folded_regions() was not included in the latest official beta (not dev builds). So I added the old unfold method again with a threshold for those who are still using the latest official beta. A message will pop up when the threshold is reached alerting the user of what has happened and will explain that upgrading to the latest beta build will fix this. So now this will work on anybodies install as long as they are not grossly outdated.
Old methods of unfold will be deprecated on the next official beta.
Version 1.2.1
Version 1.3
Just add the on save sequences to reg_replace.sublime-settings
You can create as many on save sequences as you want, and they can all target different files. If a file matches multiple sequences, then the sequences will be strung together as one sequence.
Included example. **on_save ** is turned off by default.
// If on_save is true, RegReplace will search through the file patterns listed below right before a file is saved,
// if the file name matches a file pattern, the sequence will be applied before the file is saved.
// RegReplace will apply all sequences that apply to a given file in the order they appear below.
"on_save": true,
"on_save_sequences":
// An example on_save_sequence that targets all files and trims trailing spaces
// - file_pattern: an array of file patterns that must match for the sequence to be applied
// - sequence: an array of replacement definitions to be applied on saving the file
{"file_pattern": "*"], "sequence": "remove_trailing_spaces"]}
],
One more small update
Version 1.4
Decided to allow “on_save_sequences” to use unix file name pattern matching and/or regex (you can use either or both).
Example:
"on_save_sequences":
// An example on_save event that removes dangling commas from json files
// - file_regex: an array of regex strings that must match the file for the sequence to be applied
// - case: regex case sensitivity (true|false) false is default (this setting is optional)
// - file_pattern: an array of file patterns that must match for the sequence to be applied
// - sequence: an array of replacement definitions to be applied on saving the file
{
"file_regex": ".*\\.sublime-(settings|commands|menu|keymap|mousemap|theme|build|project|completions|commands)"],
"file_pattern": "*.json"],
"sequence": "remove_json_dangling_commas"]
},
Version 1.5.1
Now allows you to specify sequences to that only highlight instead of replace on save. Also added the ability to have the on save replacement sequences use multipass if desired. Highlight on save sequences and replace on save sequences can coexist; replacements are run first, and then highlights are performed. The read me gives more details.
id like to excuse myself for not reading the instructions word by word and ask if there is an option to apply RegReplace commands to selection(s).
Should have regex under selection out fairly soon day or so. The code is pretty much done (it was pretty simple). I think I will just have a setting that you can enable, and then after that, if you a something selected, it will default to search selection only. If you have no selections (cursors are fine), then it will search the whole document.
It is pretty straight forward. If you are doing the special replacements that first target a scope and then apply the regex to that scope, you will have to ensure the entire scope is under the selection (I might change this in the future).
I might have it out by tomorrow if I am not feeling too lazy.
Finally finished this.
Version 1.6
Replace Only Under Selection(s)
Sometimes you only want to search under selections. This can be done by enabling the selection_only setting in the settings file. By enabling this setting, regex targets will be limited to the current selection if and only if a selection exists. Auto replace/highlight on save events ignore this setting. If you have a command that you wish to ignore this setting, just set the no_selection argument to true. Highlight style will be forced to underline under selections if find_only is set to ensure they will show up.
Though RegReplace does support fold, unfold, mark, unmark, I am not sure it is all supported via “on_save”. A matter of fact, I am pretty sure it isn’t…but I could add it. RegReplace is a plugin that I plan on spending some more time on some time soon. It was thrown together pretty quick to fulfill my basic needs, and while it works well for what I use it for, it has some gaps in features etc. and has some areas that could use better polish.
If you hop on github and create an issue for allowing for fold on save, I will try and add it sometime soon.
I added an issue to github. Totally no rush.
I was very surprised to find RegReplace supported folding matches.
[quote=“quodlibet”]I added an issue to github. Totally no rush.
I was very surprised to find RegReplace supported folding matches.[/quote]
I probably use terms like “soon” too freely…it is in my queue though .
I wanted to be able to fold all comments, so I added the fold/unfold a while ago…
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.)
[quote=“facelessuser”]
I wanted to be able to fold all comments, so I added the fold/unfold a while ago…[/quote]
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.
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?