@@ -35,7 +35,7 @@ def loadini(struct, configfile):
35
35
config_path = os .path .expanduser (configfile )
36
36
37
37
config = ConfigParser ()
38
- fill_config_with_default_values ( config , {
38
+ defaults = {
39
39
'general' : {
40
40
'arg_spec' : True ,
41
41
'auto_display_list' : True ,
@@ -61,8 +61,15 @@ def loadini(struct, configfile):
61
61
'editor' : os .environ .get ('VISUAL' , os .environ .get ('EDITOR' , 'vi' ))
62
62
},
63
63
'keyboard' : {
64
+ 'backspace' : 'C-h' ,
65
+ 'left' : 'C-b' ,
66
+ 'right' : 'C-f' ,
67
+ 'beginning_of_line' : 'C-a' ,
68
+ 'end_of_line' : 'C-e' ,
69
+ 'transpose_chars' : 'C-t' ,
64
70
'clear_line' : 'C-u' ,
65
71
'clear_screen' : 'C-l' ,
72
+ 'kill_line' : 'C-k' ,
66
73
'clear_word' : 'C-w' ,
67
74
'cut_to_buffer' : 'C-k' ,
68
75
'delete' : 'C-d' ,
@@ -90,7 +97,8 @@ def loadini(struct, configfile):
90
97
'curtsies' : {
91
98
'list_above' : False ,
92
99
'right_arrow_completion' : True ,
93
- }})
100
+ }}
101
+ fill_config_with_default_values (config , defaults )
94
102
if not config .read (config_path ):
95
103
# No config file. If the user has it in the old place then complain
96
104
if os .path .isfile (os .path .expanduser ('~/.bpython.ini' )):
@@ -99,6 +107,18 @@ def loadini(struct, configfile):
99
107
"%s\n " % default_config_path ())
100
108
sys .exit (1 )
101
109
110
+ def get_key_no_doublebind (attr , already_used = {}):
111
+ """Clears any other configured keybindings using this key"""
112
+ key = config .get ('keyboard' , attr )
113
+ if key in already_used :
114
+ default = defaults ['keyboard' ][already_used [key ]]
115
+ if default in already_used :
116
+ setattr (struct , '%s_key' % already_used [key ], '' )
117
+ else :
118
+ setattr (struct , '%s_key' % already_used [key ], default )
119
+ already_used [key ] = attr
120
+ return key
121
+
102
122
struct .config_path = config_path
103
123
104
124
struct .dedent_after = config .getint ('general' , 'dedent_after' )
@@ -115,28 +135,39 @@ def loadini(struct, configfile):
115
135
struct .hist_length = config .getint ('general' , 'hist_length' )
116
136
struct .hist_duplicates = config .getboolean ('general' , 'hist_duplicates' )
117
137
struct .flush_output = config .getboolean ('general' , 'flush_output' )
118
- struct .pastebin_key = config .get ('keyboard' , 'pastebin' )
119
- struct .save_key = config .get ('keyboard' , 'save' )
120
- struct .search_key = config .get ('keyboard' , 'search' )
121
- struct .show_source_key = config .get ('keyboard' , 'show_source' )
122
- struct .suspend_key = config .get ('keyboard' , 'suspend' )
123
- struct .toggle_file_watch_key = config .get ('keyboard' , 'toggle_file_watch' )
124
- struct .undo_key = config .get ('keyboard' , 'undo' )
125
- struct .reimport_key = config .get ('keyboard' , 'reimport' )
126
- struct .up_one_line_key = config .get ('keyboard' , 'up_one_line' )
127
- struct .down_one_line_key = config .get ('keyboard' , 'down_one_line' )
128
- struct .cut_to_buffer_key = config .get ('keyboard' , 'cut_to_buffer' )
129
- struct .yank_from_buffer_key = config .get ('keyboard' , 'yank_from_buffer' )
130
- struct .clear_word_key = config .get ('keyboard' , 'clear_word' )
131
- struct .clear_line_key = config .get ('keyboard' , 'clear_line' )
132
- struct .clear_screen_key = config .get ('keyboard' , 'clear_screen' )
133
- struct .delete_key = config .get ('keyboard' , 'delete' )
134
- struct .exit_key = config .get ('keyboard' , 'exit' )
135
- struct .last_output_key = config .get ('keyboard' , 'last_output' )
136
- struct .edit_config_key = config .get ('keyboard' , 'edit_config' )
137
- struct .edit_current_block_key = config .get ('keyboard' , 'edit_current_block' )
138
- struct .external_editor_key = config .get ('keyboard' , 'external_editor' )
139
- struct .help_key = config .get ('keyboard' , 'help' )
138
+
139
+ struct .pastebin_key = get_key_no_doublebind ('pastebin' )
140
+ struct .save_key = get_key_no_doublebind ('save' )
141
+ struct .search_key = get_key_no_doublebind ('search' )
142
+ struct .show_source_key = get_key_no_doublebind ('show_source' )
143
+ struct .suspend_key = get_key_no_doublebind ('suspend' )
144
+ struct .toggle_file_watch_key = get_key_no_doublebind ('toggle_file_watch' )
145
+ struct .undo_key = get_key_no_doublebind ('undo' )
146
+ struct .reimport_key = get_key_no_doublebind ('reimport' )
147
+ struct .up_one_line_key = get_key_no_doublebind ('up_one_line' )
148
+ struct .down_one_line_key = get_key_no_doublebind ('down_one_line' )
149
+ struct .cut_to_buffer_key = get_key_no_doublebind ('cut_to_buffer' )
150
+ struct .yank_from_buffer_key = get_key_no_doublebind ('yank_from_buffer' )
151
+ struct .clear_word_key = get_key_no_doublebind ('clear_word' )
152
+ struct .backspace_key = get_key_no_doublebind ('backspace' )
153
+ struct .clear_line_key = get_key_no_doublebind ('clear_line' )
154
+ struct .clear_screen_key = get_key_no_doublebind ('clear_screen' )
155
+ struct .delete_key = get_key_no_doublebind ('delete' )
156
+
157
+ struct .left_key = get_key_no_doublebind ('left' )
158
+ struct .right_key = get_key_no_doublebind ('right' )
159
+ struct .end_of_line_key = get_key_no_doublebind ('end_of_line' )
160
+ struct .beginning_of_line_key = get_key_no_doublebind ('beginning_of_line' )
161
+ struct .transpose_chars_key = get_key_no_doublebind ('transpose_chars' )
162
+ struct .clear_line_key = get_key_no_doublebind ('clear_line' )
163
+ struct .clear_screen_key = get_key_no_doublebind ('clear_screen' )
164
+ struct .kill_line_key = get_key_no_doublebind ('kill_line' )
165
+ struct .exit_key = get_key_no_doublebind ('exit' )
166
+ struct .last_output_key = get_key_no_doublebind ('last_output' )
167
+ struct .edit_config_key = get_key_no_doublebind ('edit_config' )
168
+ struct .edit_current_block_key = get_key_no_doublebind ('edit_current_block' )
169
+ struct .external_editor_key = get_key_no_doublebind ('external_editor' )
170
+ struct .help_key = get_key_no_doublebind ('help' )
140
171
141
172
struct .pastebin_confirm = config .getboolean ('general' , 'pastebin_confirm' )
142
173
struct .pastebin_url = config .get ('general' , 'pastebin_url' )
0 commit comments