@@ -735,6 +735,18 @@ def update_completion(self, tab=False):
735
735
self .current_match = None
736
736
self .list_win_visible = BpythonRepl .complete (self , tab )
737
737
738
+ def predicted_indent (self , line ):
739
+ logger .debug ('line is %r' , line )
740
+ indent = len (re .match (r'[ ]*' , line ).group ())
741
+ if line .endswith (':' ):
742
+ indent = max (0 , indent + self .config .tab_length )
743
+ elif line and line .count (' ' ) == len (line ):
744
+ indent = max (0 , indent - self .config .tab_length )
745
+ elif line and ':' not in line and line .strip ().startswith (('return' , 'pass' , 'raise' , 'yield' )):
746
+ indent = max (0 , indent - self .config .tab_length )
747
+ logger .debug ('indent we found was %s' , indent )
748
+ return indent
749
+
738
750
def push (self , line , insert_into_history = True ):
739
751
"""Push a line of code onto the buffer, start running the buffer
740
752
@@ -743,14 +755,7 @@ def push(self, line, insert_into_history=True):
743
755
if self .paste_mode :
744
756
self .saved_indent = 0
745
757
else :
746
- indent = len (re .match (r'[ ]*' , line ).group ())
747
- if line .endswith (':' ):
748
- indent = max (0 , indent + self .config .tab_length )
749
- elif line and line .count (' ' ) == len (line ):
750
- indent = max (0 , indent - self .config .tab_length )
751
- elif line and ':' not in line and line .strip ().startswith (('return' , 'pass' , 'raise' , 'yield' )):
752
- indent = max (0 , indent - self .config .tab_length )
753
- self .saved_indent = indent
758
+ self .saved_indent = self .predicted_indent (line )
754
759
755
760
#current line not added to display buffer if quitting #TODO I don't understand this comment
756
761
if self .config .syntax :
@@ -1197,8 +1202,15 @@ def reprint_line(self, lineno, tokens):
1197
1202
def take_back_buffer_line (self ):
1198
1203
self .display_buffer .pop ()
1199
1204
self .buffer .pop ()
1200
- self .cursor_offset = 0
1201
- self .current_line = ''
1205
+
1206
+ if not self .buffer :
1207
+ self .current_line = ''
1208
+ self .cursor_offset = 0
1209
+ else :
1210
+ line = self .buffer [- 1 ]
1211
+ indent = self .predicted_indent (line )
1212
+ self .current_line = indent * ' '
1213
+ self .cursor_offset = len (self .current_line )
1202
1214
1203
1215
def reevaluate (self , insert_into_history = False ):
1204
1216
"""bpython.Repl.undo calls this"""
0 commit comments