Skip to content

Commit afde916

Browse files
implement ^W, ^D, option-d, option-delete
--HG-- branch : scroll-frontend
1 parent e057d6d commit afde916

File tree

1 file changed

+21
-5
lines changed

1 file changed

+21
-5
lines changed

bpython/scrollfrontend/manual_readline.py

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ def forward_word(cursor_offset, line):
5454

5555
@on('b')
5656
@on('\x1bOD')
57+
@on('\x1bB')
5758
def back_word(cursor_offset, line):
5859
return (last_word_pos(line[:cursor_offset]), line)
5960

@@ -91,21 +92,30 @@ def delete_from_cursor_back(cursor_offset, line):
9192
def delete_from_cursor_forward(cursor_offset, line):
9293
return cursor_offset, line[:cursor_offset]
9394

94-
@on('d')
95+
@on('d') # option-d
9596
def delete_rest_of_word(cursor_offset, line):
96-
raise NotImplementedError()
97+
m = re.search(r'\w\b', line[cursor_offset:])
98+
if not m:
99+
return cursor_offset, line
100+
return cursor_offset, line[:cursor_offset] + line[m.start()+cursor_offset+1:]
97101

98102
@on('')
99103
def delete_word_to_cursor(cursor_offset, line):
100-
raise NotImplementedError()
104+
matches = list(re.finditer(r'\s\S', line[:cursor_offset]))
105+
start = matches[-1].start()+1 if matches else 0
106+
return start, line[:start] + line[cursor_offset:]
101107

102108
@on('y')
103109
def yank_prev_prev_killed_text(cursor_offset, line):
104110
raise NotImplementedError()
105111

106112
@on('')
107113
def transpose_character_before_cursor(cursor_offset, line):
108-
raise NotImplementedError()
114+
return (min(len(line), cursor_offset + 1),
115+
line[:cursor_offset-1] +
116+
(line[cursor_offset] if len(line) > cursor_offset else '') +
117+
line[cursor_offset - 1] +
118+
line[cursor_offset+1:])
109119

110120
@on('t')
111121
def transpose_word_before_cursor(cursor_offset, line):
@@ -116,7 +126,13 @@ def transpose_word_before_cursor(cursor_offset, line):
116126
@on('\x1b\x7f')
117127
@on('\xff')
118128
def delete_word_from_cursor_back(cursor_offset, line):
119-
raise NotImplementedError()
129+
"""Whatever my option-delete does in bash on my mac"""
130+
if not line:
131+
return cursor_offset, line
132+
starts = [m.start() for m in list(re.finditer(r'\b\w', line)) if m.start() < cursor_offset]
133+
if starts:
134+
return starts[-1], line[:starts[-1]] + line[cursor_offset:]
135+
return cursor_offset, line
120136

121137
def get_updated_char_sequences(key_dispatch, config):
122138
updated_char_sequences = dict(char_sequences)

0 commit comments

Comments
 (0)