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

Skip to content

bpo-30723: Enhancement to IDLE parenmatch extension #2299

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

Closed
wants to merge 7 commits into from
Closed
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
Prev Previous commit
Next Next commit
fixed for ctrl-0 highlighting
  • Loading branch information
Charles Wohlganger committed Jun 20, 2017
commit 110ddc84cf1d96eeaaf35b678ce51c429bd04c3d
38 changes: 29 additions & 9 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 @@ -83,10 +90,14 @@ def deactivate_restore(self):
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
self.create_tag = self.create_tag_default
elif style == "expression":
self.create_tag = self.create_tag_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,8 @@ def flash_paren_event(self, event):
return
self.activate_restore()
self.create_tag(indices)
self.set_timeout_last()
self.set_timeout()
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 @@ -140,7 +152,15 @@ def create_tag_expression(self, indices):
rightindex = indices[1]
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 +180,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
0