Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit df80ea1

Browse filesBrowse files
susinmotionthomasballinger
authored andcommitted
pressing <Esc+.> prints the last word of the last command to the command line
Added test for get last word
1 parent 0513f1a commit df80ea1
Copy full SHA for df80ea1

2 files changed

+33-1Lines changed: 33 additions & 1 deletion

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎bpython/curtsiesfrontend/repl.py‎

Copy file name to clipboardExpand all lines: bpython/curtsiesfrontend/repl.py
+24-1Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646

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

49+
4950
from curtsies.configfile_keynames import keymap as key_dispatch
5051

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

8889
def process_event(self, e):
8990
assert self.has_focus
91+
9092
logger.debug('fake input processing event %r', e)
9193
if isinstance(e, events.PasteEvent):
9294
for ee in e.events:
@@ -100,6 +102,9 @@ def process_event(self, e):
100102
self.current_line = ''
101103
self.cursor_offset = 0
102104
self.repl.run_code_and_maybe_finish()
105+
elif e in ("<Esc+.>",):
106+
self.get_last_word()
107+
103108
elif e in ["<ESC>"]:
104109
pass
105110
elif e in ['<Ctrl-d>']:
@@ -469,6 +474,8 @@ def process_key_event(self, e):
469474
self.down_one_line()
470475
elif e in ("<Ctrl-d>",):
471476
self.on_control_d()
477+
elif e in ("<Esc+.>",):
478+
self.get_last_word()
472479
elif e in ("<Esc+r>",):
473480
self.incremental_search(reverse=True)
474481
elif e in ("<Esc+s>",):
@@ -524,6 +531,21 @@ def process_key_event(self, e):
524531
else:
525532
self.add_normal_character(e)
526533

534+
def get_last_word(self):
535+
536+
def last_word(line):
537+
if not line:
538+
return ''
539+
return line.split().pop()
540+
541+
previous_word = last_word(self.rl_history.entry)
542+
word = last_word(self.rl_history.back())
543+
line=self.current_line
544+
self._set_current_line(line[:len(line)-len(previous_word)]+word, reset_rl_history=False)
545+
546+
self._set_cursor_offset(self.cursor_offset-len(previous_word)+len(word), reset_rl_history=False)
547+
548+
527549
def incremental_search(self, reverse=False, include_current=False):
528550
if self.special_mode == None:
529551
self.rl_history.enter(self.current_line)
@@ -808,7 +830,8 @@ def run_code_and_maybe_finish(self, for_code=None):
808830
if err:
809831
indent = 0
810832

811-
#TODO This should be printed ABOVE the error that just happened instead
833+
834+
#TODO This should be printed ABOVE the error that just happened instead
812835
# or maybe just thrown away and not shown
813836
if self.current_stdouterr_line:
814837
self.display_lines.extend(paint.display_linize(self.current_stdouterr_line, self.width))
Collapse file

‎bpython/test/test_curtsies_repl.py‎

Copy file name to clipboardExpand all lines: bpython/test/test_curtsies_repl.py
+9Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,15 @@ def test_external_communication(self):
5151
self.repl.send_current_block_to_external_editor()
5252
self.repl.send_session_to_external_editor()
5353

54+
def test_get_last_word(self):
55+
self.repl.rl_history.entries=['1','2 3','4 5 6']
56+
self.repl._set_current_line('abcde')
57+
self.repl.get_last_word()
58+
self.assertEqual(self.repl.current_line,'abcde6')
59+
self.repl.get_last_word()
60+
self.assertEqual(self.repl.current_line,'abcde3')
61+
62+
5463
@contextmanager # from http://stackoverflow.com/a/17981937/398212 - thanks @rkennedy
5564
def captured_output():
5665
new_out, new_err = StringIO(), StringIO()

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.