From c4fca257f16f06b1170c2854ae8b5cea5e514ca9 Mon Sep 17 00:00:00 2001 From: Charles Wohlganger Date: Tue, 20 Jun 2017 09:26:15 -0500 Subject: [PATCH 1/3] IDLE extension parenmatch improvements: flash-delay now independant of style. added 'parens' style - highlights left and right parens. --- Lib/idlelib/parenmatch.py | 35 +++++++++++++++++++++++++++-------- 1 file changed, 27 insertions(+), 8 deletions(-) diff --git a/Lib/idlelib/parenmatch.py b/Lib/idlelib/parenmatch.py index ccec708f31f436..ece068a92f8c58 100644 --- a/Lib/idlelib/parenmatch.py +++ b/Lib/idlelib/parenmatch.py @@ -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) @@ -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): @@ -140,7 +151,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 @@ -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 From 110ddc84cf1d96eeaaf35b678ce51c429bd04c3d Mon Sep 17 00:00:00 2001 From: Charles Wohlganger Date: Tue, 20 Jun 2017 14:31:45 -0500 Subject: [PATCH 2/3] fixed for ctrl-0 highlighting --- Lib/idlelib/parenmatch.py | 38 +++++++++++++++++++++++++++++--------- 1 file changed, 29 insertions(+), 9 deletions(-) diff --git a/Lib/idlelib/parenmatch.py b/Lib/idlelib/parenmatch.py index ccec708f31f436..15803a58e8e51e 100644 --- a/Lib/idlelib/parenmatch.py +++ b/Lib/idlelib/parenmatch.py @@ -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) @@ -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): @@ -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. @@ -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 @@ -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 From c3c21481e9a51241aa630db8a17ca4cd182001b4 Mon Sep 17 00:00:00 2001 From: Charles Wohlganger Date: Tue, 20 Jun 2017 15:46:10 -0500 Subject: [PATCH 3/3] added name to acks --- Misc/ACKS | 1 + 1 file changed, 1 insertion(+) diff --git a/Misc/ACKS b/Misc/ACKS index 4f98e980bd971f..170a2de81a634a 100644 --- a/Misc/ACKS +++ b/Misc/ACKS @@ -1710,6 +1710,7 @@ John Wiseman Chris Withers Stefan Witzel Irek Wlizlo +Charles Wohlganger David Wolever Klaus-Juergen Wolf Dan Wolfe