File tree 3 files changed +32
-7
lines changed
prompt_toolkit/key_binding/bindings
3 files changed +32
-7
lines changed Original file line number Diff line number Diff line change @@ -58,8 +58,8 @@ def _(event):
58
58
handle (Keys .Escape , 'l' , filter = insert_mode )(get_by_name ('downcase-word' ))
59
59
handle (Keys .Escape , 'u' , filter = insert_mode )(get_by_name ('uppercase-word' ))
60
60
handle (Keys .Escape , 'y' , filter = insert_mode )(get_by_name ('yank-pop' ))
61
- handle (Keys .Escape , Keys .ControlH , filter = insert_mode )(get_by_name ('unix-word-rubout ' ))
62
- handle (Keys .Escape , Keys .Backspace , filter = insert_mode )(get_by_name ('unix-word-rubout ' ))
61
+ handle (Keys .Escape , Keys .ControlH , filter = insert_mode )(get_by_name ('backward-kill-word ' ))
62
+ handle (Keys .Escape , Keys .Backspace , filter = insert_mode )(get_by_name ('backward-kill-word ' ))
63
63
handle (Keys .Escape , '\\ ' , filter = insert_mode )(get_by_name ('delete-horizontal-space' ))
64
64
65
65
handle (Keys .ControlUnderscore , save_before = (lambda e : False ), filter = insert_mode )(
Original file line number Diff line number Diff line change @@ -302,13 +302,13 @@ def kill_word(event):
302
302
303
303
304
304
@register ('unix-word-rubout' )
305
- @register ('backward-kill-word' ) # XXX: backward-kill-word is actually slightly different.
306
- def unix_word_rubout (event ):
305
+ def unix_word_rubout (event , WORD = True ):
307
306
"""
308
- Kill the word behind point. Word boundaries are the same as backward-word.
307
+ Kill the word behind point, using whitespace as a word boundary.
308
+ Usually bound to ControlW.
309
309
"""
310
310
buff = event .current_buffer
311
- pos = buff .document .find_start_of_previous_word (count = event .arg )
311
+ pos = buff .document .find_start_of_previous_word (count = event .arg , WORD = WORD )
312
312
313
313
if pos is None :
314
314
# Nothing found? delete until the start of the document. (The
@@ -330,6 +330,15 @@ def unix_word_rubout(event):
330
330
event .cli .output .bell ()
331
331
332
332
333
+ @register ('backward-kill-word' )
334
+ def backward_kill_word (event ):
335
+ """
336
+ Kills the word before point, using “not a letter nor a digit” as a word boundary.
337
+ Usually bound to M-Del or M-Backspace.
338
+ """
339
+ unix_word_rubout (event , WORD = False )
340
+
341
+
333
342
@register ('delete-horizontal-space' )
334
343
def delete_horizontal_space (event ):
335
344
" Delete all spaces and tabs around point. "
Original file line number Diff line number Diff line change @@ -252,14 +252,30 @@ def test_emacs_other_bindings():
252
252
result , cli = _feed_cli_with_input ('hello\x1b [D\x1b [D\x15 X\n ' )
253
253
assert result .text == 'Xlo'
254
254
255
- # Delete word before the cursor.
255
+ # unix-word-rubout: delete word before the cursor.
256
+ # (ControlW).
256
257
result , cli = _feed_cli_with_input ('hello world test\x17 X\n ' )
257
258
assert result .text == 'hello world X'
258
259
260
+ result , cli = _feed_cli_with_input ('hello world /some/very/long/path\x17 X\n ' )
261
+ assert result .text == 'hello world X'
262
+
259
263
# (with argument.)
260
264
result , cli = _feed_cli_with_input ('hello world test\x1b 2\x17 X\n ' )
261
265
assert result .text == 'hello X'
262
266
267
+ result , cli = _feed_cli_with_input ('hello world /some/very/long/path\x1b 2\x17 X\n ' )
268
+ assert result .text == 'hello X'
269
+
270
+ # backward-kill-word: delete word before the cursor.
271
+ # (Esc-ControlH).
272
+ result , cli = _feed_cli_with_input ('hello world /some/very/long/path\x1b \x08 X\n ' )
273
+ assert result .text == 'hello world /some/very/long/X'
274
+
275
+ # (with arguments.)
276
+ result , cli = _feed_cli_with_input ('hello world /some/very/long/path\x1b 3\x1b \x08 X\n ' )
277
+ assert result .text == 'hello world /some/very/X'
278
+
263
279
264
280
def test_controlx_controlx ():
265
281
# At the end: go to the start of the line.
You can’t perform that action at this time.
0 commit comments