-
-
Notifications
You must be signed in to change notification settings - Fork 246
Brackets completion #934
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Brackets completion #934
Conversation
Codecov Report
@@ Coverage Diff @@
## main #934 +/- ##
==========================================
+ Coverage 67.98% 68.69% +0.71%
==========================================
Files 61 62 +1
Lines 9174 9437 +263
==========================================
+ Hits 6237 6483 +246
- Misses 2937 2954 +17
Continue to review full report at Codecov.
|
I just played with this a bit. Since this would be an optional feature, these things wouldn't be required from my perspective (maybe none of them are worth the complexity!) but might be nice. Overwriting closing charactersThis already works for ) and ], but I'm missing it for strings too.
To avoid the case above, a closing character could overwrite an existing one in some cases. This might be tricky to implement but it is behavior that makes autoclosing pairs in IDEs manageable for me, because I can still type what I normally would. Always overwriting any closing characters, ignoring whether they were automatically added, sounds easier. Don't autoclose when cursor is followed by non-whitespaceI often forget that a socket.socket's connect method takes a single argument, a tuple:
To avoid this, autoclosing could take place only when the the cursor is at the end of a line? I notice VSCode uses a fancier heuristic than this, but it seems based on what is to the right of the cursor. If it's a space or nothing, it seems to auto-close. Remove autoclose when open is deleted (by method other than backspace)This already works for backspace, but not some other ways of clearing the line:
VSCode has the same behavior as this PR, so I can hardly complain — but there are series of keystrokes I make similar to backspace that delete the opening character without deleting the matching close character. Matching history entriesA closing paren causes history entries to no longer match.
Not a big issue, but the the closing paren can cause lines from history to no longer match. Maybe it could be removed when searching through history. |
@thomasballinger i will read through this and get back to you |
The problem is that opening and closing characters are the same and are difficult to distinguish. i will look into it and come up with a solution. BTW, tabbing still works even with quotes. Don't autoclose when cursor is followed by non-whitespace
Remove autoclose when open is deleted (by method other than backspace)
Matching history entries
These changes shouldnt take a lot of time. |
great, that's good
Sounds fine to me, I'm not sure how I'd go about this either.
Sounds good, but if it's very complicated feel free to skip this one — it's something that I noticed, but I'm not sure it's worth fixing. |
i just realized, when testing the solution for this problem, that it breaks another good behaviour. if you write multiple nested open parens |
Hm, maybe the behavior I think I want is too complex to be worth implementing. What I see in VSCode (which I think does what I want, but I'm not even sure about that — it does work for this one socket case) is:
|
@thomasballinger thats exactly what i meant by previous comment! (pseudocode):
this way, the case with the socket works. basically it will autocomplete very similarly to VS Code |
i looked into the missing history hints, and basically the problem seems to be that the |
@thomasballinger |
Whatever is convenient for you! A new file sounds fine to me. If not a new file, bpython/test/test_curtsies_repl.py might be the right file. |
@thomasballinger i wrote test for scenarios we talked about, including quotes and all brackets with TAB, BACKSPACE and others. i just cant figure out how to write a test which would include the search history. any advice, pointer? thanks! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm, I'll take a look at the history thing.
I think you can check the value of |
Oh if you're checking for the grayed out text completion you might need to set |
thank you! any other ideas to add to this feature? |
Seems good to me! I'm looking forward to it. option-r reverse history search is the only thing that I think is left to change. |
This looks good to me! I'll wait for CI to run then merge it. |
great! hopefuly it will serve the users good |
hey I am the one who opened this enhancement thanks for merging this edit:I am new to python and english |
@yogeshdcool I didn't merge this feature in in time for the release that came out a few days ago, so you'll either need to wait for the next release or install bpython from source. Here's how to do that with pip: python -m pip install git+https://github.com/bpython/bpython.git@main |
Thanks for helping me out |
Solution for #905
As requested, posted here for feedback (still needs polishing, more docs and tests).
Changes include traditional IDEs behavior on completing brackets ( [ { and quotes " '.
This works in writing, as well as with callable autocomplete matches.
Example:
If you type in
def foo(
, the line will printdef foo()
and put the cursor between the brackets. This also works with nested brackets and quotes. So if you dox = 5*(some_list[5])
, the brackets will close upon writing the starting paren/quote, and put your cursor inside them.I also implemented behavior on BACKSPACE key and TAB key.
If your cursor is currently positioned right on the character, which is a closing bracket or a quote and you hit TAB, your cursor will move behind that symbol.
If you hit BACKSPACE and the first character to be deleted is an opening bracket, and your cursor is on a closing bracket, this will delete both brackets/quotes.
This behavior also works in nested brackets environment.
Feature can be enabled in config file by setting the brackets_completion flag to True.
Thank you for the feedback.
Still needs tests. Guidance or advice appreciated.