Add encapsulate with parentheses (quotes, brackets, braces) function
See original GitHub issueEncapsulating parentheses and others
I want to be able to highlight code and press the button for some beginning character like the opening parenthesis, so that the whole highlighted text is surrounded by an opening parenthesis on the left and a closing parenthesis on the right, as an example. Many editors support this kind of behavior and I have gotten used to being able to do this.
What steps will reproduce the problem?
- highlight some code
- press opening parenthesis key
What is the expected output? What do you see instead?
- The text should be surrounded by parenthesis.
- The text was replaced.
Versions and main components
- Spyder Version: 2.3.9 (in an Anaconda env for Python 3.5)
- Python Version: Python 3.5
- Operating system: Fedora 22
Dependencies
Please go to the menu entry Help > Optional Dependencies
(or
Help > Dependencies
), press the button Copy to clipboard
and paste the contents below:
IPython >=1.0 : 5.1.0 (OK) jedi >=0.8.1;<0.9.0: 0.9.0 (NOK) matplotlib >=1.0 : 1.5.1 (OK) pandas >=0.13.1 : 0.18.1 (OK) pep8 >=0.6 : 1.7.0 (OK) psutil >=0.3 : 4.3.1 (OK) pyflakes >=0.6.0 : 1.3.0 (OK) pygments >=1.6 : 2.1.3 (OK) pylint >=0.25 : None (NOK) qtconsole >=4.0 : 4.2.1 (OK) rope >=0.9.2 : 0.9.4-1 (OK) sphinx >=0.6.6 : 1.4.1 (OK) sympy >=0.7.3 : None (NOK) zmq >=2.1.11 : 15.4.0 (OK)
Issue Analytics
- State:
- Created 7 years ago
- Reactions:9
- Comments:7 (5 by maintainers)
Top GitHub Comments
@h4gen Spyder already has quote insertion for selected text in master. If you select text and press the
'
or"
key the selection will get quoted.This functionality is now implemented as the first example of an editor extension:
https://github.com/spyder-ide/spyder/blob/master/spyder/widgets/sourcecode/extensions/closequotes.py
This section does the part you want to do with brackets:
https://github.com/spyder-ide/spyder/blob/da167e4e088373bcb3028112027c3eddab34c14f/spyder/widgets/sourcecode/extensions/closequotes.py#L71-L78
I think you will want to write an editor extension similar to closequotes extension. See this PR for more info.
https://github.com/spyder-ide/spyder/pull/5002
Sounds like a fun project!
If I may add something to this request, also enclose selection with brackets, curlies, and quotes, when the corresponding key is pressed.