Skip to content

Commit

Permalink
Feature/selection inputs and update docs and tests (#73)
Browse files Browse the repository at this point in the history
* Add selection input feature

ref #71

* Update docs and test environment

* Fix spelling

* Document selection input feature

* Fix changelog version and autolink issues
  • Loading branch information
facelessuser authored Nov 20, 2017
1 parent e2a24c6 commit 07f6fdf
Show file tree
Hide file tree
Showing 19 changed files with 295 additions and 90 deletions.
56 changes: 34 additions & 22 deletions .dictionary
Original file line number Diff line number Diff line change
@@ -1,50 +1,62 @@
Backrefs
Control's
EmojiOne
GitHub
JSON
JSON's
MERCHANTABILITY
MkDocs
Multi
NONINFRINGEMENT
OSX
OSX
Plugin
Plugins
Posix
Re
Re's
RegReplace
Regex
Regex's
Sublime's
Unmark
YYYYMMDD
backrefs
bregex
builtins
cmd
Control's
ctrl
ctrl
dev
docstrings
dotall
ebeweber
emoji
EmojiOne
esc
GitHub
facelessuser
facelessuser
gforcada
installable
jinja
JSON
JSON's
markupsafe
mdpopups
MERCHANTABILITY
MkDocs
mkdocs
Multi
multi
NONINFRINGEMENT
OSX
OSX
Plugin
packagecontrol
plugin
Plugins
plugins
Posix
popups
pre
pycqa
pygments
pymdown
pytest
Re
Re's
regex
Regex
Regex's
RegReplace
requesters
squidfunk
sublicense
Sublime's
tox
un
unhighlight
unmark
Unmark
url
YYYYMMDD
30 changes: 24 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,24 +1,41 @@
sudo: false

language: python
python:
- "3.3"

# Limit git depth to speed up build
git:
depth: 5

matrix:
include:
- python: 3.6
env: TESTENV=unittest
- python: 3.6
env: TESTENV=documents

install:
- pip install flake8
- pip install flake8-docstrings
- pip install pep8-naming
- pip install flake8-mutable
- pip install flake8-builtins
- pip install pytest
- pip install mkdocs-material
- pip install pymdown-extensions
- pip install pygments

addons:
apt:
packages:
- aspell
- aspell-en

script:
- py.test .
- flake8 .
- python tests/spellcheck.py
- mkdocs build --clean --verbose --strict
- if [ $TESTENV = unittest ]; then py.test .; fi
- if [ $TESTENV = unittest ]; then flake8 .; fi
- if [ $TESTENV = documents ]; then python tests/spellcheck.py; fi
- if [ $TESTENV = documents ]; then mkdocs build --clean --verbose --strict; fi

deploy:
- provider: pages
github_token: $GITHUB_TOKEN
Expand All @@ -29,3 +46,4 @@ deploy:
on:
tags: true
repo: facelessuser/RegReplace
condition: "$TESTENV = documents"
12 changes: 9 additions & 3 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# RegReplace 3.7.0

Nov 19, 2017

- **NEW**: New experimental support for selection inputs for find patterns (#71).

# RegReplace 3.6.0

Sep 30, 2017
Expand All @@ -18,9 +24,9 @@ Aug 13, 2017
Jun 4, 2017

- **NEW**: Scope searches will now apply highlights and actions directly to the regex find regions opposed to the whole
scope [#58](https://github.com/facelessuser/RegReplace/issues/58).
scope (#58).
- **NEW**: Use new Sublime settings API for opening settings file.
- **NEW**: Show error message when rule not found [#60](https://github.com/facelessuser/RegReplace/issues/60).
- **NEW**: Show error message when rule not found (#60).

# RegReplace 3.3.0

Expand All @@ -39,7 +45,7 @@ Mar 5, 2017

Dec 28, 2016

- **NEW**: Add support for regex regular expression module [#52](https://github.com/facelessuser/RegReplace/pull/52)
- **NEW**: Add support for regex regular expression module (!52).

# RegReplace 3.1.0

Expand Down
4 changes: 3 additions & 1 deletion dependencies.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
"python-jinja2",
"markupsafe",
"backrefs",
"regex"
"regex",
"pyyaml",
"pymdownx"
]
}
}
26 changes: 18 additions & 8 deletions docs/src/markdown/contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

## Overview

Sublime Versions | Description
-----------------|------------
ST2\ <=\ version\ <\ ST3 | Supported on a separate branch, but not actively. Any further fixes or enhancements must come from the community. Issues for versions less than ST3 will not be addressed moving forward by me. Pull requests are welcome for back-porting features, enhancements, or fixes to the old branch, but the content of the pull **must** already exist on the main, actively developed branch. I will not allow an older branch to exceed the main branch in regards to functionality. |
ST3 | Fully supported and actively maintained.
Sublime\ Versions | Description
----------------- |------------
ST2 | Supported on a separate branch, but not actively. Any further fixes or enhancements must come from the community. Issues for versions less than ST3 will not be addressed moving forward by me. Pull requests are welcome for back-porting features, enhancements, or fixes to the old branch, but the content of the pull **must** already exist on the main, actively developed branch. I will not allow an older branch to exceed the main branch in regards to functionality. |
ST3 | Fully supported and actively maintained.

Contributions from the community are encouraged and can be done in a variety of ways:

Expand Down Expand Up @@ -55,9 +55,9 @@ Feel free to use a virtual environment if you are concerned about installing any

There are a couple of dependencies that must be present before running the tests.

1. As ST3 is the only current, actively supported version, Python 3.3 must be used to validate the tests.
1. As ST3 is the only current, actively supported version, Python 3 must be used to validate the tests.

2. Unit tests are run with `pytest`. You can install [pytest][pytest] via:
2. Unit tests are run with `pytest` (@pytest-dev/pytest). You can install pytest via:

```
pip install pytest
Expand All @@ -69,11 +69,21 @@ There are a couple of dependencies that must be present before running the tests
py.test .
```
3. Linting is performed on the entire project with `flake8`, `flake8-docstrings`, and `pep8-naming`. These can be installed via:
3. Linting is performed on the entire project with the following modules:
- @gitlab:pycqa/flake8
- @gitlab:pycqa/flake8-docstrings
- @ebeweber/flake8-mutable
- @gforcada/flake8-builtins
- @gitlab:pycqa/pep8-naming
These can be installed via:
```
pip install flake8
pip install flake8-docstrings
pip install flake8-mutable
pip install flake8-builtins
pip install pep8-naming
```
Expand All @@ -87,6 +97,6 @@ There are a couple of dependencies that must be present before running the tests
A huge amount of time has been spent not only creating and supporting this plugin, but also writing this documentation. If you feel it's still lacking, show your appreciation for the plugin by helping to improve the documentation. Help with documentation is always appreciated and can be done via pull requests. There shouldn't be any need to run validation tests when updating just the documentation.
You don't have to render the docs locally before pull requesting, but if you wish to, I currently use a combination of [mkdocs][mkdocs] with my own custom Python Markdown [extensions][pymdown-extensions] to render the docs. You can preview the docs if you install these two packages. The command for previewing the docs is `mkdocs serve` from the root directory.
You don't have to render the docs locally before pull requesting, but if you wish to, I currently use a combination of @mkdocs/mkdocs, the @squidfunk/mkdocs-material, and @facelessuser/pymdown-extensions to render the docs. You can preview the docs if you install these two packages. The command for previewing the docs is `mkdocs serve` from the root directory. You can then view the documents at `localhost:8000`.
--8<-- "refs.md"
16 changes: 8 additions & 8 deletions docs/src/markdown/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,17 @@ For those who want to install RegReplace without package control, here are the s

1. Download the latest releases of the following dependencies and unpack or git clone them in the `Packages` folder as shown below:

- https://bitbucket.org/teddy_beer_maniac/sublime-text-dependency-markupsafe -> markupsafe
- https://bitbucket.org/teddy_beer_maniac/sublime-text-dependency-jinja2 -> python-jinja2
- https://github.com/packagecontrol/pygments -> pygments
- https://github.com/facelessuser/sublime-markdown-popups -> mdpopups
- https://github.com/facelessuser/sublime-markdown -> python-markdown
- https://github.com/facelessuser/sublime-backrefs -> backrefs
- https://github.com/facelessuser/sublime-regex -> regex
- @bitbucket:teddy_beer_maniac/sublime-text-dependency-markupsafe -> markupsafe
- @bitbucket:teddy_beer_maniac/sublime-text-dependency-jinja2 -> python-jinja2
- @packagecontrol/pygments -> pygments
- @facelessuser/sublime-markdown-popups -> mdpopups
- @facelessuser/sublime-markdown -> python-markdown
- @facelessuser/sublime-backrefs -> backrefs
- @facelessuser/sublime-regex -> regex

2. Download and unpack or git clone the latest RegReplace release and unpack it as `RegReplace`:

- https://github.com/facelessuser/RegReplace -> RegReplace
- @facelessuser/RegReplace -> RegReplace

3. Create a folder under `Packages` called `00-dependencies` and under that folder create a file called `00-dependencies.py`:

Expand Down
30 changes: 30 additions & 0 deletions docs/src/markdown/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ There are two types of rules that can be created: scope rules (with optional sco
- greedy
- scope_filter
- format_replace
- selection_inputs
- plugin
- args
*/
Expand Down Expand Up @@ -52,6 +53,7 @@ The second kind of rule is the **scope regex** which allows you to search for a
- greedy_scope
- format_replace
- multi_pass
- selection_inputs
- plugin
- args
*/
Expand Down Expand Up @@ -103,6 +105,9 @@ A description of all the options is found below:
Works only for Regex (with and without Backrefs) and Re (with Backrefs).
See http://facelessuser.github.io/backrefs/#format-replacements for more info.

selection_inputs (bool -default=False): Use selection for inputs into find pattern.
Global setting "selection_only" must be disabled for this to work.

multi_pass: (bool - default=False): Perform multiple sweeps on the scope region to find
and replace all instances of the regex when regex cannot be formatted to find
all instances. Since a replace can change a scope, this can be useful.
Expand Down Expand Up @@ -146,6 +151,31 @@ You can also bind a replacement command to a keyboard shortcut:
}
```
## Selection Inputs
!!! warning "Experimental"
This feature is experimental and is subject to change.
If `selection_inputs` is set to `True`, selections will be inserted into your pattern via format string logic.
So to specify to implicit variables, the following format string logic can be used: `r'Some value {} some [\w]+ {}'`. In this example, the first two selections will be inserted in `{}`: `r'Some value selection0 some [\w]+ selection1'`.
To control which selection goes where, you can explicitly set the index: `r'Some value {1} some [\w]+ {0}'` ->. `r'Some value selection1 some [\w]+ selection0'`. Or alternatively: `r'Some value {sel[1]} some [\w]+ {sel[0]}'` (`sel` is the selection list).
By default, the selection is just inserted into the pattern raw. This is fine for literal searches, but for regex this is bad if your selection is something like: `something(else)`. This example would be interpreted as adding group containing `else`. So if this is not intended, the text would need to be escaped. So a new conversion type has been added: `!e`. This new conversion type will insert the selection into the pattern after first escaping it. So you could use it like so: `r'Some value {1!e} some [\w]+ {0!e}'`, and the selection inputs would be escaped.
For the sake of avoiding bad situations, RegReplace will limit the length of selections to the arbitrary value of 256, but you can configure this with the global setting `selection_input_max_size` in `reg_replace.sublime-settings`. Also, the number of allowed inputs will be limited to 10, but this can be tweaked via the setting `selection_input_max_count`.
```js
// Limit size of selections for inputs.
"selection_input_max_size": 256,

// Limit number of selections for inputs.
"selection_input_max_count": 10,
```
This should go without saying, but this is incompatible if you have the global option `selection_only` set which will search in selection content. Though you can ignore it per command via the command parameter `no_selection`. So if you are constructing a chain that uses selection inputs, you can temporarily disable it with `selection_only`.
## A Better Way to Create Regex Rules
A new feature was recently added that allows editing regular expression rules in a panel with Python syntax highlighting, providing a friendlier editing experience. Users can even split their regular expressions on multiple lines and add comments which will be preserved the next time the rule is viewed.
Expand Down
1 change: 0 additions & 1 deletion docs/theme/extra-00833721db.css

This file was deleted.

Loading

0 comments on commit 07f6fdf

Please sign in to comment.