8000 bpo-30723: Enhancement to IDLE parenmatch extension by wohlganger · Pull Request #2306 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

bpo-30723: Enhancement to IDLE parenmatch extension #2306

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

Merged
merged 8 commits into from
Jun 28, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
trivial - made FLASH_DELAY configure for all styles.
added highlight both parens option.
  • Loading branch information
Charles Wohlganger committed Jun 20, 2017
commit 1700630f1535b1557530568fd818a18aa539c615
31 changes: 25 additions & 6 deletions Lib/idlelib/parenmatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,26 @@
class ParenMatch:
"""Highlight matching parentheses

There are three supported style of paren matching, based loosely
There are three supported styles of paren matching, based loosely
on the Emacs options. The style is select based on the
HILITE_STYLE attribute; it can be changed used the set_style
HILITE_STYLE attribute; it can be changed using the set_style
method.

The supported styles are:

default -- When a right paren is typed, highlight the matching
left paren for 1/2 sec.
left paren.

expression -- When a right paren is typed, highlight the entire
expression from the left paren to the right paren.

parens -- When a right paren is typed, highlight the left and
right parens.


flash-delay option determines how long (milliseconds) the highlighting
remains. If set to 0, it does not timeout.

TODO:
- extend IDLE with configuration dialog to change options
- implement rest of Emacs highlight styles (see below)
Expand Down Expand Up @@ -84,9 +91,13 @@ def set_style(self, style):
self.STYLE = style
if style == "default":
self.create_tag = self.create_tag_default
self.set_timeout = self.set_timeout_last
elif style == "expression":
self.create_tag = self.create_tag_expression
elif style == "parens":
self.create_tag = self.create_tag_parens
if self.FLASH_DELAY:
self.set_timeout = self.set_timeout_last
else:
self.set_timeout = self.set_timeout_none

def flash_paren_event(self, event):
Expand All @@ -97,7 +108,7 @@ def flash_paren_event(self, event):
return
self.activate_restore()
self.create_tag(indices)
self.set_timeout_last()
self.set_timeout()

def paren_closed_event(self, event):
# If it was a shortcut and not really a closing paren, quit.
Expand Down Expand Up @@ -141,6 +152,14 @@ def create_tag_expression(self, indices):
self.text.tag_add("paren", indices[0], rightindex)
self.text.tag_config("paren", self.HILITE_CONFIG)

def create_tag_parens(self, indices):
"""Highlight the left and right parens"""
if self.text.get(indices[1]) in (')', ']', '}'):
rightindex = indices[1]+"+1c"
else:
rightindex = indices[1]
self.text.tag_add("paren", indices[0], indices[0]+"+1c", rightindex+"-1c", rightindex)
self.text.tag_config("paren", self.HILITE_CONFIG)
# any one of the set_timeout_XXX methods can be used depending on
# the style

Expand All @@ -160,7 +179,7 @@ def callme(callme, self=self, c=self.counter,
self.editwin.text_frame.after(CHECK_DELAY, callme, callme)

def set_timeout_last(self):
"""The last highlight created will be removed after .5 sec"""
"""The last highlight created will be removed after FLASH_DELAY millisecs"""
# associate a counter with an event; only disable the "paren"
# tag if the event is for the most recent timer.
self.counter += 1
Expand Down
1 change: 1 addition & 0 deletions Misc/ACKS
Original file line number Diff line number Diff line change
Expand Up @@ -1710,6 +1710,7 @@ John Wiseman
Chris Withers
Stefan Witzel
Irek Wlizlo
Charles Wohlganger
David Wolever
Klaus-Juergen Wolf
Dan Wolfe
Expand Down
0