Skip to content

Commit e457d07

Browse files
committed
Merge pull request #451 from keyanp/bug447
Refactor and fix keybinding issue (fixes #447)
2 parents 94e8999 + fb46b60 commit e457d07

File tree

2 files changed

+16
-14
lines changed

2 files changed

+16
-14
lines changed

bpython/config.py

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ def loadini(struct, configfile):
7474
'transpose_chars': 'C-t',
7575
'clear_line': 'C-u',
7676
'clear_screen': 'C-l',
77-
'kill_line': 'C-k',
7877
'clear_word': 'C-w',
7978
'cut_to_buffer': 'C-k',
8079
'delete': 'C-d',
@@ -104,6 +103,10 @@ def loadini(struct, configfile):
104103
'list_above' : False,
105104
'right_arrow_completion' : True,
106105
}}
106+
107+
default_keys_to_commands = dict((value, key) for (key, value)
108+
in defaults['keyboard'].iteritems())
109+
107110
fill_config_with_default_values(config, defaults)
108111
if not config.read(config_path):
109112
# No config file. If the user has it in the old place then complain
@@ -113,17 +116,17 @@ def loadini(struct, configfile):
113116
"%s\n" % default_config_path())
114117
sys.exit(1)
115118

116-
def get_key_no_doublebind(attr, already_used={}):
117-
"""Clears any other configured keybindings using this key"""
118-
key = config.get('keyboard', attr)
119-
if key in already_used:
120-
default = defaults['keyboard'][already_used[key]]
121-
if default in already_used:
122-
setattr(struct, '%s_key' % already_used[key], '')
123-
else:
124-
setattr(struct, '%s_key' % already_used[key], default)
125-
already_used[key] = attr
126-
return key
119+
120+
def get_key_no_doublebind(command):
121+
default_commands_to_keys = defaults['keyboard']
122+
requested_key = config.get('keyboard', command)
123+
default_command = default_keys_to_commands[requested_key]
124+
125+
if default_commands_to_keys[default_command] == \
126+
config.get('keyboard', default_command):
127+
setattr(struct, '%s_key' % default_command, '')
128+
129+
return requested_key
127130

128131
struct.config_path = config_path
129132

@@ -168,7 +171,6 @@ def get_key_no_doublebind(attr, already_used={}):
168171
struct.transpose_chars_key = get_key_no_doublebind('transpose_chars')
169172
struct.clear_line_key = get_key_no_doublebind('clear_line')
170173
struct.clear_screen_key = get_key_no_doublebind('clear_screen')
171-
struct.kill_line_key = get_key_no_doublebind('kill_line')
172174
struct.exit_key = get_key_no_doublebind('exit')
173175
struct.last_output_key = get_key_no_doublebind('last_output')
174176
struct.edit_config_key = get_key_no_doublebind('edit_config')

bpython/curtsiesfrontend/manual_readline.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ def delete_line(cursor_offset, line):
250250
def uppercase_next_word(cursor_offset, line):
251251
return cursor_offset, line #TODO Not implemented
252252

253-
@edit_keys.on(config='kill_line_key')
253+
@edit_keys.on(config='cut_to_buffer_key')
254254
@kills_ahead
255255
def delete_from_cursor_forward(cursor_offset, line):
256256
return cursor_offset, line[:cursor_offset], line[cursor_offset:]

0 commit comments

Comments
 (0)