Highlight matching openers and closers, (), [], and {}. There are three supported styles of paren matching. When a right paren (opener) is typed: opener -- highlight the matching left paren (closer); parens -- highlight the left and right parens (opener and closer); expression
| 11 | CHECK_DELAY = 100 # milliseconds |
| 12 | |
| 13 | class ParenMatch: |
| 14 | """Highlight matching openers and closers, (), [], and {}. |
| 15 | |
| 16 | There are three supported styles of paren matching. When a right |
| 17 | paren (opener) is typed: |
| 18 | |
| 19 | opener -- highlight the matching left paren (closer); |
| 20 | parens -- highlight the left and right parens (opener and closer); |
| 21 | expression -- highlight the entire expression from opener to closer. |
| 22 | (For back compatibility, 'default' is a synonym for 'opener'). |
| 23 | |
| 24 | Flash-delay is the maximum milliseconds the highlighting remains. |
| 25 | Any cursor movement (key press or click) before that removes the |
| 26 | highlight. If flash-delay is 0, there is no maximum. |
| 27 | |
| 28 | TODO: |
| 29 | - Augment bell() with mismatch warning in status window. |
| 30 | - Highlight when cursor is moved to the right of a closer. |
| 31 | This might be too expensive to check. |
| 32 | """ |
| 33 | |
| 34 | RESTORE_VIRTUAL_EVENT_NAME = "<<parenmatch-check-restore>>" |
| 35 | # We want the restore event be called before the usual return and |
| 36 | # backspace events. |
| 37 | RESTORE_SEQUENCES = ("<KeyPress>", "<ButtonPress>", |
| 38 | "<Key-Return>", "<Key-BackSpace>") |
| 39 | |
| 40 | def __init__(self, editwin): |
| 41 | self.editwin = editwin |
| 42 | self.text = editwin.text |
| 43 | # Bind the check-restore event to the function restore_event, |
| 44 | # so that we can then use activate_restore (which calls event_add) |
| 45 | # and deactivate_restore (which calls event_delete). |
| 46 | editwin.text.bind(self.RESTORE_VIRTUAL_EVENT_NAME, |
| 47 | self.restore_event) |
| 48 | self.counter = 0 |
| 49 | self.is_restore_active = 0 |
| 50 | |
| 51 | @classmethod |
| 52 | def reload(cls): |
| 53 | cls.STYLE = idleConf.GetOption( |
| 54 | 'extensions','ParenMatch','style', default='opener') |
| 55 | cls.FLASH_DELAY = idleConf.GetOption( |
| 56 | 'extensions','ParenMatch','flash-delay', type='int',default=500) |
| 57 | cls.BELL = idleConf.GetOption( |
| 58 | 'extensions','ParenMatch','bell', type='bool', default=1) |
| 59 | cls.HILITE_CONFIG = idleConf.GetHighlight(idleConf.CurrentTheme(), |
| 60 | 'hilite') |
| 61 | |
| 62 | def activate_restore(self): |
| 63 | "Activate mechanism to restore text from highlighting." |
| 64 | if not self.is_restore_active: |
| 65 | for seq in self.RESTORE_SEQUENCES: |
| 66 | self.text.event_add(self.RESTORE_VIRTUAL_EVENT_NAME, seq) |
| 67 | self.is_restore_active = True |
| 68 | |
| 69 | def deactivate_restore(self): |
| 70 | "Remove restore event bindings." |
no outgoing calls
searching dependent graphs…