Skip to content

Commit 08c5017

Browse files
Fix currentline in reevaluate session
1 parent 8aa42c3 commit 08c5017

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

bpython/curtsiesfrontend/repl.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,11 @@
8484
Press {config.edit_config_key} to edit this config file.
8585
"""
8686
EXAMPLE_CONFIG_URL = 'https://raw.githubusercontent.com/bpython/bpython/master/bpython/sample-config'
87-
EDIT_SESSION_HEADER = ("### current bpython session - file will be "
88-
"reevaluated, ### lines will not be run\n"
89-
"### To return to bpython without reevaluating, "
90-
"exit without making changes.\n")
87+
EDIT_SESSION_HEADER = """### current bpython session - make changes and save to reevaluate session.
88+
### lines beginning with ### will be ignored.
89+
### To return to bpython without reevaluating make no changes to this file
90+
### or save an empty file.
91+
"""
9192
MAX_EVENTS_POSSIBLY_NOT_PASTE = 20 # more than this many events will be assumed to
9293
# be a true paste event, i.e. control characters
9394
# like '<Ctrl-a>' will be stripped
@@ -854,11 +855,19 @@ def send_session_to_external_editor(self, filename=None):
854855
_('Session not reevaluated because it was not edited'))
855856
return
856857
lines = text.split('\n')
858+
if not lines[-1].strip():
859+
lines.pop() # strip last line if empty
860+
if lines[-1].startswith('### '):
861+
current_line = lines[-1][4:]
862+
else:
863+
current_line = ''
857864
from_editor = [line for line in lines if line[:3] != '###']
865+
858866
source = preprocess('\n'.join(from_editor), self.interp.compile)
859-
self.history = source.split('\n')
867+
lines = source.split('\n')
868+
self.history = lines
860869
self.reevaluate(insert_into_history=True)
861-
self.current_line = lines[-1][4:]
870+
self.current_line = current_line
862871
self.cursor_offset = len(self.current_line)
863872
self.status_bar.message(_('Session edited and reevaluated'))
864873

0 commit comments

Comments
 (0)