Skip to content

Commit 07c1ffc

Browse files
committed
Change C-d from quit key to delete key (by default).
Also bind forward to C-f and backward to C-b. This adresses issue #92. Thanks to Jeff Bauer for the initial patch.
1 parent 8410722 commit 07c1ffc

File tree

3 files changed

+15
-5
lines changed

3 files changed

+15
-5
lines changed

bpython/cli.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -722,7 +722,12 @@ def p_key(self, key):
722722
self.complete()
723723
return ''
724724

725-
elif key == 'KEY_DC': # Del
725+
elif key in key_dispatch[config.delete_key] and not self.s:
726+
# Delete on empty line exits
727+
self.do_exit = True
728+
return None
729+
730+
elif key in ('KEY_DC', ) + key_dispatch[config.delete_key]:
726731
self.delete()
727732
self.complete()
728733
# Redraw (as there might have been highlighted parens)
@@ -743,12 +748,12 @@ def p_key(self, key):
743748
self.fwd()
744749
return ''
745750

746-
elif key == 'KEY_LEFT': # Cursor Left
751+
elif key in ("KEY_LEFT",' ^B', chr(2)): # Cursor Left or ^B
747752
self.mvc(1)
748753
# Redraw (as there might have been highlighted parens)
749754
self.print_line(self.s)
750755

751-
elif key == 'KEY_RIGHT': # Cursor Right
756+
elif key in ("KEY_RIGHT", '^F', chr(6)): # Cursor Right or ^F
752757
self.mvc(-1)
753758
# Redraw (as there might have been highlighted parens)
754759
self.print_line(self.s)

bpython/config.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,9 @@ def loadini(struct, configfile):
5353
'clear_screen': 'C-l',
5454
'clear_word': 'C-w',
5555
'cut_to_buffer': 'C-k',
56+
'delete': 'C-d',
5657
'down_one_line': 'C-n',
57-
'exit': 'C-d',
58+
'exit': '',
5859
'last_output': 'F9',
5960
'pastebin': 'F8',
6061
'save': 'C-s',
@@ -87,6 +88,7 @@ def loadini(struct, configfile):
8788
struct.clear_word_key = config.get('keyboard', 'clear_word')
8889
struct.clear_line_key = config.get('keyboard', 'clear_line')
8990
struct.clear_screen_key = config.get('keyboard', 'clear_screen')
91+
struct.delete_key = config.get('keyboard', 'delete')
9092
struct.exit_key = config.get('keyboard', 'exit')
9193
struct.last_output_key = config.get('keyboard', 'last_output')
9294

bpython/keys.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,10 @@ def __init__(self):
3232
self.map = {}
3333

3434
def __getitem__(self, key):
35-
if key in self.map:
35+
if not key:
36+
# Unbound key
37+
return str()
38+
elif key in self.map:
3639
return self.map[key]
3740
else:
3841
raise Exception('Configured keymap (%s)\

0 commit comments

Comments
 (0)