@@ -248,6 +248,8 @@ def smarter_request_refresh():
248248 self .current_match = None
249249 self .list_win_visible = False
250250
251+ self .original_modules = sys .modules .keys ()
252+
251253 self .width = None # will both be set by a window resize event
252254 self .height = None
253255
@@ -404,6 +406,9 @@ def process_event(self, e):
404406 self .on_tab ()
405407 elif e in ("KEY_BTAB" ,): # shift-tab
406408 self .on_tab (back = True )
409+ elif e in ("KEY_F(6)" ,):
410+ self .clear_modules_and_reevaluate ()
411+ self .update_completion ()
407412 elif e in key_dispatch [self .config .undo_key ]: #ctrl-r for undo
408413 self .undo ()
409414 self .update_completion ()
@@ -509,6 +514,14 @@ def send_session_to_external_editor(self, filename=None):
509514 self .current_line = lines [- 1 ][4 :]
510515 self .cursor_offset = len (self .current_line )
511516
517+ def clear_modules_and_reevaluate (self ):
518+ cursor , line = self .cursor_offset , self .current_line
519+ for modname in sys .modules .keys ():
520+ if modname not in self .original_modules :
521+ del sys .modules [modname ]
522+ self .reevaluate (insert_into_history = True )
523+ self .cursor_offset , self .current_line = cursor , line
524+
512525 ## Handler Helpers
513526 def add_normal_character (self , char ):
514527 if len (char ) > 1 or is_nop (char ):
0 commit comments