diff --git a/CHANGES.md b/CHANGES.md index f5990c6..8cf0387 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,5 +1,9 @@ # RegReplace +## 3.10.0 + +- **NEW**: Add `reg_replace_chain` command. + ## 3.9.0 - **NEW**: Changes to support Python 3.13 on ST 4201+. diff --git a/docs/src/markdown/usage.md b/docs/src/markdown/usage.md index 9d69199..3e1fa01 100644 --- a/docs/src/markdown/usage.md +++ b/docs/src/markdown/usage.md @@ -166,6 +166,25 @@ You can also bind a replacement command to a keyboard shortcut: } ``` +As noted in the arguments above, `multi_pass` applies to a chain of replacements, but each replacement in a chain +cannot be controlled individually. In some cases, it may be desired that some patterns are applied multiple times, while +others are not. If this is the case, you can chain multiple replace commands together using the `reg_replace_chain` +command. Then each command can can be configured separately. + + +```js + { + "caption": "Reg Replace: Chained Command" + "command": "reg_replace_chain", + "args": { + "commands": [ + {"command": "reg_replace", "replacements": ["replace_command_1"]}, + {"command": "reg_replace", "replacements": ["replace_command_2"], "multi_pass": true} + ] + } + } +``` + ## Selection Inputs /// warning | Experimental diff --git a/rr_sequencer.py b/rr_sequencer.py index 60a20d8..b5d9db3 100644 --- a/rr_sequencer.py +++ b/rr_sequencer.py @@ -168,6 +168,17 @@ def on_pre_save(self, view): self.apply(view, self.unfolds, action="unfold") +class RegReplaceChain(sublime_plugin.TextCommand): + """RegReplace chain command.""" + + def run(self, edit, commands): + """Chain multiple commands.""" + + for command in commands: + cmd = command.pop('command') + self.view.run_command(cmd, command) + + class RegReplaceCommand(sublime_plugin.TextCommand): """RegReplace command."""