From f8c37e843e89503d4dd858140d1ba846d94c20a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B8rgen=20P=2E=20Tjern=C3=B8?= Date: Thu, 21 Aug 2008 13:21:55 +0200 Subject: [PATCH] Added C-w to delete a word to the left of the cursor. --- bpython.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/bpython.py b/bpython.py index f809dab..0806f66 100644 --- a/bpython.py +++ b/bpython.py @@ -937,6 +937,17 @@ class Repl( object ): for _ in range(n): self.scr.delch( y, x - n ) + return n + + def bs_word(self): + pos = len(self.s) - self.cpos - 1 + # First we delete any space to the left of the cursor. + while pos >= 0 and self.s[pos] == ' ': + pos -= self.bs() + # Then we delete a full word. + while pos >= 0 and self.s[pos] != ' ': + pos -= self.bs() + def delete( self ): """Process a del""" if not len(self.s): @@ -1004,6 +1015,11 @@ class Repl( object ): elif self.c == "KEY_END": self.mvc(-self.cpos) + elif self.c in ('^W', chr(23)): # C-w + self.bs_word() + self.complete() + return '' + elif self.c in ('^U', chr(21) ): # C-u self.clrtobol() return ''