-
-
Notifications
You must be signed in to change notification settings - Fork 29.1k
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
bpo-21756: fix IDLE's "show surrounding parens" for multi-line statements #20753
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,7 +23,7 @@ | |
|
||
|
||
class HyperParser: | ||
def __init__(self, editwin, index): | ||
def __init__(self, editwin, index, end_at_eol=True): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you think There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, the name "end_at_eol" isn't great. I'm not sure "wrap" is clear enough though. Perhaps "stop_at_line_end" or "multiline"? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I prefer one word or at most two (which don't necessarily need '_') rather than a phrase. The docstring can explain the word. In any case, the audience is only IDLE maintainers and there may never be more than one or two calls that change the current default. 'endline=True' is a possibility. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So "multiline"? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
"To initialize, analyze the surroundings of the given index." | ||
|
||
self.editwin = editwin | ||
|
@@ -39,7 +39,7 @@ def index2line(index): | |
for context in editwin.num_context_lines: | ||
startat = max(lno - context, 1) | ||
startatindex = repr(startat) + ".0" | ||
stopatindex = "%d.end" % lno | ||
stopatindex = "%d.end" % lno if end_at_eol else "end-1c" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since you're changing this line, an f-string would make this more readable. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Definitely. |
||
# We add the newline because PyParse requires a newline | ||
# at end. We add a space so that index won't be at end | ||
# of line, so that its status will be the same as the | ||
|
@@ -56,7 +56,14 @@ def index2line(index): | |
startatindex = r[1] | ||
else: | ||
startatindex = "1.0" | ||
stopatindex = "%d.end" % lno | ||
if end_at_eol: | ||
stopatindex = "%d.end" % lno | ||
else: | ||
r = text.tag_nextrange("console", index) | ||
if r: | ||
stopatindex = text.index(r[0] + "-1c") | ||
else: | ||
stopatindex = "end-1c" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This
|
||
# We add the newline because PyParse requires it. We add a | ||
# space so that index won't be at end of line, so that its | ||
# status will be the same as the char before it, if should. | ||
|
@@ -119,10 +126,11 @@ def get_surrounding_brackets(self, openers='([{', mustclose=False): | |
If the index given to the HyperParser is surrounded by a | ||
bracket defined in openers (or at least has one before it), | ||
return the indices of the opening bracket and the closing | ||
bracket (or the end of line, whichever comes first). | ||
bracket (or the end of line/file, whichever comes first). | ||
|
||
If it is not surrounded by brackets, or the end of line comes | ||
before the closing bracket and mustclose is True, returns None. | ||
If it is not surrounded by brackets, or the end of line/file | ||
comes before the closing bracket and mustclose is True, returns | ||
None. | ||
""" | ||
|
||
bracketinglevel = self.bracketing[self.indexbracket][1] | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Fixed IDLE's "show surrounding parens" for multi-line statements. |
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.
Just a nit, but I prefer
for something like this.
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.
Great suggestion!
I'm still slowly chipping away at the deeply-ingrained "IDLE supports very old Python versions" rule in my mind...
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.
One 3.7.8 is out, we can consider using new-in-3.8 features such as '/' in signatures and ':='.