From 33f2b7b2577ce0c9247c2eac0a29ce8212cdf829 Mon Sep 17 00:00:00 2001 From: Guido van Rossum Date: Sun, 3 Jan 1999 00:47:35 +0000 Subject: [PATCH] Added something like Tim Peters' backspace patch. --- Tools/idle/AutoIndent.py | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/Tools/idle/AutoIndent.py b/Tools/idle/AutoIndent.py index 329f49215fe..3f1dfe1991c 100644 --- a/Tools/idle/AutoIndent.py +++ b/Tools/idle/AutoIndent.py @@ -47,8 +47,12 @@ class AutoIndent: ]), ] - windows_keydefs = { + keydefs = { + '<>': [''], '<>': ['', ''], + } + + windows_keydefs = { '<>': [''], '<>': [''], '<>': [''], @@ -58,7 +62,6 @@ class AutoIndent: } unix_keydefs = { - '<>': ['', ''], '<>': ['', '', ''], @@ -86,6 +89,29 @@ class AutoIndent: else: raise KeyError, "bad option name: %s" % `key` + def smart_backspace_event(self, event): + text = self.text + try: + first = text.index("sel.first") + last = text.index("sel.last") + except TclError: + first = last = None + if first and last: + text.delete(first, last) + text.mark_set("insert", first) + return "break" + # After Tim Peters + ndelete = 1 + chars = text.get("insert linestart", "insert") + i = 0 + n = len(chars) + while i < n and chars[i] in " \t": + i = i+1 + if i == n and chars[-4:] == " ": + ndelete = 4 + text.delete("insert - %d chars" % ndelete, "insert") + return "break" + def newline_and_indent_event(self, event): text = self.text try: