Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion bpython/curtsiesfrontend/repl.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@

#TODO other autocomplete modes (also fix in other bpython implementations)


from curtsies.configfile_keynames import keymap as key_dispatch

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -87,6 +88,7 @@ def __init__(self, coderunner, repl, configured_edit_keys=None):

def process_event(self, e):
assert self.has_focus

logger.debug('fake input processing event %r', e)
if isinstance(e, events.PasteEvent):
for ee in e.events:
Expand All @@ -100,6 +102,9 @@ def process_event(self, e):
self.current_line = ''
self.cursor_offset = 0
self.repl.run_code_and_maybe_finish()
elif e in ("<Esc+.>",):
self.get_last_word()

elif e in ["<ESC>"]:
pass
elif e in ['<Ctrl-d>']:
Expand Down Expand Up @@ -469,6 +474,8 @@ def process_key_event(self, e):
self.down_one_line()
elif e in ("<Ctrl-d>",):
self.on_control_d()
elif e in ("<Esc+.>",):
self.get_last_word()
elif e in ("<Esc+r>",):
self.incremental_search(reverse=True)
elif e in ("<Esc+s>",):
Expand Down Expand Up @@ -524,6 +531,21 @@ def process_key_event(self, e):
else:
self.add_normal_character(e)

def get_last_word(self):

def last_word(line):
if not line:
return ''
return line.split().pop()

previous_word = last_word(self.rl_history.entry)
word = last_word(self.rl_history.back())
line=self.current_line
self._set_current_line(line[:len(line)-len(previous_word)]+word, reset_rl_history=False)

self._set_cursor_offset(self.cursor_offset-len(previous_word)+len(word), reset_rl_history=False)


def incremental_search(self, reverse=False, include_current=False):
if self.special_mode == None:
self.rl_history.enter(self.current_line)
Expand Down Expand Up @@ -808,7 +830,8 @@ def run_code_and_maybe_finish(self, for_code=None):
if err:
indent = 0

#TODO This should be printed ABOVE the error that just happened instead

#TODO This should be printed ABOVE the error that just happened instead
# or maybe just thrown away and not shown
if self.current_stdouterr_line:
self.display_lines.extend(paint.display_linize(self.current_stdouterr_line, self.width))
Expand Down
9 changes: 9 additions & 0 deletions bpython/test/test_curtsies_repl.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,15 @@ def test_external_communication(self):
self.repl.send_current_block_to_external_editor()
self.repl.send_session_to_external_editor()

def test_get_last_word(self):
self.repl.rl_history.entries=['1','2 3','4 5 6']
self.repl._set_current_line('abcde')
self.repl.get_last_word()
self.assertEqual(self.repl.current_line,'abcde6')
self.repl.get_last_word()
self.assertEqual(self.repl.current_line,'abcde3')


@contextmanager # from http://stackoverflow.com/a/17981937/398212 - thanks @rkennedy
def captured_output():
new_out, new_err = StringIO(), StringIO()
Expand Down