@@ -267,7 +267,7 @@ def smarter_request_reload(desc):
267
267
self .interact = self .status_bar # overwriting what bpython.Repl put there
268
268
# interact is called to interact with the status bar,
269
269
# so we're just using the same object
270
- self .current_line = '' # line currently being edited, without '>>> '
270
+ self ._current_line = '' # line currently being edited, without '>>> '
271
271
self .current_stdouterr_line = '' # current line of output - stdout and stdin go here
272
272
self .display_lines = [] # lines separated whenever logical line
273
273
# length goes over what the terminal width
@@ -280,7 +280,7 @@ def smarter_request_reload(desc):
280
280
# bpython.Repl
281
281
self .scroll_offset = 0 # how many times display has been scrolled down
282
282
# because there wasn't room to display everything
283
- self .cursor_offset = 0 # from the left, 0 means first char
283
+ self ._cursor_offset = 0 # from the left, 0 means first char
284
284
self .orig_tcattrs = orig_tcattrs # useful for shelling out with normal terminal
285
285
286
286
self .coderunner = CodeRunner (self .interp , self .request_refresh )
@@ -407,21 +407,18 @@ def proccess_control_event(self, e):
407
407
self .stdin .process_event (ee )
408
408
else :
409
409
self .process_simple_keypress (ee )
410
- self .update_completion ()
411
410
412
411
elif self .stdin .has_focus :
413
412
return self .stdin .process_event (e )
414
413
415
414
elif isinstance (e , events .SigIntEvent ):
416
415
logger .debug ('received sigint event' )
417
416
self .keyboard_interrupt ()
418
- self .update_completion ()
419
417
return
420
418
421
419
elif isinstance (e , events .ReloadEvent ):
422
420
if self .watching_files :
423
421
self .clear_modules_and_reevaluate ()
424
- self .update_completion ()
425
422
self .status_bar .message ('Reloaded at ' + time .strftime ('%H:%M:%S' ) + ' because ' + ' & ' .join (e .files_modified ) + ' modified' )
426
423
427
424
else :
@@ -451,18 +448,15 @@ def process_key_event(self, e):
451
448
452
449
elif e in key_dispatch [self .config .reimport_key ]:
453
450
self .clear_modules_and_reevaluate ()
454
- self .update_completion ()
455
451
self .status_bar .message ('Reloaded at ' + time .strftime ('%H:%M:%S' ) + ' by user' )
456
452
457
453
elif (e in ("<RIGHT>" , '<Ctrl-f>' ) and self .config .curtsies_right_arrow_completion
458
454
and self .cursor_offset == len (self .current_line )):
459
455
self .current_line += self .current_suggestion
460
456
self .cursor_offset = len (self .current_line )
461
- self .update_completion ()
462
457
463
458
elif e in self .rl_char_sequences :
464
459
self .cursor_offset , self .current_line = self .rl_char_sequences [e ](self .cursor_offset , self .current_line )
465
- self .update_completion ()
466
460
self .rl_history .reset ()
467
461
468
462
# readline history commands
@@ -510,7 +504,6 @@ def process_key_event(self, e):
510
504
raise SystemExit ()
511
505
else :
512
506
self .current_line = self .current_line [:self .cursor_offset ] + self .current_line [self .cursor_offset + 1 :]
513
- self .update_completion ()
514
507
self .rl_history .reset ()
515
508
elif e in key_dispatch [self .config .exit_key ]:
516
509
raise SystemExit ()
@@ -524,7 +517,6 @@ def process_key_event(self, e):
524
517
self .rl_history .reset ()
525
518
elif e in key_dispatch [self .config .undo_key ]: #ctrl-r for undo
526
519
self .undo ()
527
- self .update_completion ()
528
520
elif e in key_dispatch [self .config .save_key ]: # ctrl-s for save
529
521
g = greenlet .greenlet (self .write2file )
530
522
g .switch ()
@@ -541,11 +533,9 @@ def process_key_event(self, e):
541
533
pass
542
534
elif e in ["<SPACE>" ]:
543
535
self .add_normal_character (' ' )
544
- self .update_completion ()
545
536
else :
546
537
self .add_normal_character (e )
547
538
self .rl_history .reset ()
548
- self .update_completion ()
549
539
550
540
def on_enter (self , insert_into_history = True ):
551
541
self .cursor_offset = - 1 # so the cursor isn't touching a paren
@@ -587,14 +577,16 @@ def only_whitespace_left_of_cursor():
587
577
588
578
# 3. check to see if we can expand the current word
589
579
if self .matches_iter .is_cseq ():
590
- self .cursor_offset , self .current_line = self .matches_iter .substitute_cseq ()
580
+ self ._cursor_offset , self ._current_line = self .matches_iter .substitute_cseq ()
581
+ # using _current_line so we don't trigger a completion reset
591
582
if not self .matches_iter :
592
583
self .list_win_visible = self .complete ()
593
584
594
585
elif self .matches_iter .matches :
595
586
self .current_match = back and self .matches_iter .previous () \
596
587
or self .matches_iter .next ()
597
- self .cursor_offset , self .current_line = self .matches_iter .cur_line ()
588
+ self ._cursor_offset , self ._current_line = self .matches_iter .cur_line ()
589
+ # using _current_line so we don't trigger a completion reset
598
590
599
591
def process_simple_keypress (self , e ):
600
592
if e in (u"<Ctrl-j>" , u"<Ctrl-m>" , u"<PADENTER>" ):
@@ -661,6 +653,7 @@ def update_completion(self, tab=False):
661
653
# * when current line changes, unless via selecting a match
662
654
# * when cursor position changes
663
655
# *
656
+ self .current_match = None
664
657
self .list_win_visible = BpythonRepl .complete (self , tab )
665
658
#look for history stuff
666
659
@@ -733,7 +726,6 @@ def run_code_and_maybe_finish(self, for_code=None):
733
726
734
727
self .current_line = ' ' * indent
735
728
self .cursor_offset = len (self .current_line )
736
- self .update_completion ()
737
729
738
730
def keyboard_interrupt (self ):
739
731
#TODO factor out the common cleanup from running a line
@@ -1052,6 +1044,20 @@ def __repr__(self):
1052
1044
s += '>'
1053
1045
return s
1054
1046
1047
+ def _get_current_line (self ):
1048
+ return self ._current_line
1049
+ def _set_current_line (self , line ):
1050
+ self ._current_line = line
1051
+ self .update_completion ()
1052
+ current_line = property (_get_current_line , _set_current_line , None ,
1053
+ "The current line" )
1054
+ def _get_cursor_offset (self ):
1055
+ return self ._cursor_offset
1056
+ def _set_cursor_offset (self , line ):
1057
+ self ._cursor_offset = line
1058
+ self .update_completion ()
1059
+ cursor_offset = property (_get_cursor_offset , _set_cursor_offset , None ,
1060
+ "The current cursor offset from the front of the line" )
1055
1061
def echo (self , msg , redraw = True ):
1056
1062
"""
1057
1063
Notification that redrawing the current line is necessary (we don't
0 commit comments