Skip to content

Commit

Permalink
Small changes
Browse files Browse the repository at this point in the history
- Add show edit panel command
- Update docs
- Set selection in edit panel to (0, 0) on open.
- Update messages
  • Loading branch information
facelessuser committed Jun 17, 2016
1 parent 5a2e892 commit f8fb627
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 2 deletions.
6 changes: 6 additions & 0 deletions Default.sublime-commands
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@
"command": "reg_replace_delete_regex"
},

// Show the regular expression rule edit panel.
{
"caption": "RegReplace: Show Edit Panel",
"command": "reg_replace_show_edit_panel"
},

// Example commands.
// {
// "caption": "Reg Replace: HTML5 Remove Deprecated Type Attr",
Expand Down
25 changes: 25 additions & 0 deletions docs/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,8 @@ You can also bind a replacement command to a shortcut.
## A Better Way To Create Regex Rules
Recently a new feature was added that allows the editing of the regex rules to be done in a Python syntax highlighted panel. This allows for a less cumbersome editing experience. Users can even split their regex on multiple lines and add comments which will all be preserved for the next time the rule is viewed.
While in the edit panel, you can press <kbd>ctrl</kbd> + <kbd>s</kbd> on Windows/Linux (or <kbd>super</kbd> + <kbd>s</kbd> on OSX) and the rule will be saved back to the settings file. On save, the regex is compiled to test if it is valid; if it fails, you should be alerted and the save will be canceled.
To edit, insert, or delete rules, you can use the following command palette commands:
- RegReplace: Edit Regular Expression Rule
Expand All @@ -151,6 +153,29 @@ To edit, insert, or delete rules, you can use the following command palette comm
![edit panel](https://dl.dropboxusercontent.com/u/342698/RegReplace/edit_panel.png)
You can also test the regex from the edit panel. At the bottom of the panel, you should see the `test` variable which will allow you to configure a sequence to run from the panel. Once configured, you can press <kbd>ctrl</kbd> + <kbd>f</kbd> on Windows/Linux (or <kbd>super</kbd> + <kbd>f</kbd> on OSX) to execute. Keep in mind, you can run the current rule sequenced together with others in the test configuration to test how it plays with other rules. `test` is not saved with the other settings, but is only good for the current session.
```python
# ----------------------------------------------------------------------------------------
# test: Here you can setup a test command. This is not saved and is just used for this session.
# - replacements ([str]): A list of regex rules to sequence together.
# - find_only (bool): Highlight current find results and prompt for action.
# - action (str): Apply the given action (fold|unfold|mark|unmark|select).
# This overrides the default replace action.
# - options (dict): optional parameters for actions (see documentation for more info).
# - key (str): Unique name for highlighted region.
# - scope (str - default="invalid"): Scope name to use as teh color.
# - style (str - default="outline"): Highlight style (solid|underline|outline).
# - multi_pass (bool): Repeatedly sweep with sequence to find all instances.
# - no_selection (bool): Overrides the "selection_only" setting and forces no selections.
# - regex_full_file_with_selections (bool): Apply regex search to full file then apply
# action to results under selections.
```
![test variable](https://dl.dropboxusercontent.com/u/342698/RegReplace/test.png)
Depending on how the test command was configured, it may cause the panel to close, or you might accidentally close it by pressing <kbd>esc</kbd> or running some other command. When closed, the currently opened rule is not lost and can be brought back by running the command palette command `RegReplace: Show Edit Panel` (the command will only work if the panel has been opened at least once). You can also use the panel icon in the bottom left hand corner of the Sublime Text window (only on later versions of Sublime Text 3).
## View Without Replacing
If you would simply like to view what the sequence would find without replacing, you can construct a command to highlight targets without replacing them (each pass could affect the end result, but this just shows all passes without predicting the replacements).
Expand Down
4 changes: 2 additions & 2 deletions messages/3.0.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ CHANGES HAVE BEEN MADE TO THE REGEX RULE FORMAT. ALSO, RULES HAVE BEEN MOVED TO

## New

- Users can now edit regex (and other settings) in a python syntax highlighted panel. You can even do multi-line regex with comments using Python re's `(?x)` flag. All this will be converted properly into the JSON setting. This makes it easier to edit regex as editing regex in JSON is cumbersome. New command palette commands have been added to edit, add, or delete regex, but you can still edit it in the traditional way. Read http://facelessuser.github.io/RegReplace/usage/#a-better-way-to-create-regex-rules to learn more.
- Users can now edit regex (and other settings) in a python syntax highlighted panel. You can even do multi-line regex with comments using Python re's `(?x)` flag. All this will be converted properly into the JSON setting. This makes it easier to edit regex as editing regex in JSON is cumbersome. New command palette commands have been added to edit, add, or delete regex, but you can still edit it in the traditional way. You can also run tests from the the new regex edit panel. Read http://facelessuser.github.io/RegReplace/usage/#a-better-way-to-create-regex-rules to learn more.

- Replacement rules have been changed slightly and should be moved to a separate file: `reg_replace_rules.sublime-settings`. This is to allows RegReplace to update the rules with out destroying all the comments in a User's settings. A command found in `Preferences->Package Settings->RegReplace->Convert Rules to 3.0` will convert existing rules to the new format and copy them to the new location.
- Replacement rules have been changed slightly and have been moved to a separate file: `reg_replace_rules.sublime-settings`. This is to allows RegReplace to update the rules with out destroying all the comments in a User's settings. A command found in `Preferences->Package Settings->RegReplace->Convert Rules to 3.0` will convert existing rules to the new format and copy them to the new location.

- `on_save_sequences`'s option `dotall` has been deprecated (this option specifically affected the `file_regex` option). This shouldn't affect anyone as there is no reason to use `dotall` in a file pattern, but if this is needed, you can `(?s)` to the regex. Legacy support still works but will be removed in the next non-bugfix release.

Expand Down
11 changes: 11 additions & 0 deletions rr_edit.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,15 @@ def convert(self, text):
return obj, test


class RegReplaceShowEditPanel(sublime_plugin.WindowCommand):
"""Show the existing regex panel."""

def run(self):
"""Execute the command to show the panel."""

self.window.run_command("show_panel", {"panel": "output.reg_replace"})


class RegReplacePanelTestCommand(sublime_plugin.TextCommand):
"""Handle the panel find shortcut."""

Expand Down Expand Up @@ -635,6 +644,8 @@ def edit_rule(self, value, new=False):
replace_view.settings().set('bracket_highlighter.widget_okay', True)
replace_view.settings().set('bracket_highlighter.bracket_string_escape_mode', 'regex')
replace_view.settings().set('regreplace.name', name)
replace_view.sel().clear()
replace_view.sel().add(sublime.Region(0, 0))
self.window.run_command("show_panel", {"panel": "output.reg_replace"})
sublime.set_timeout(lambda w=self.window, v=replace_view: w.focus_view(v), 100)

Expand Down

0 comments on commit f8fb627

Please sign in to comment.