4646
4747#TODO other autocomplete modes (also fix in other bpython implementations)
4848
49+
4950from curtsies .configfile_keynames import keymap as key_dispatch
5051
5152logger = 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 ))
0 commit comments