Skip to content

Commit 8aa42c3

Browse files
Don't reevaluate session if not modified
1 parent 64d875e commit 8aa42c3

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

bpython/curtsiesfrontend/repl.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,10 @@
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")
8791
MAX_EVENTS_POSSIBLY_NOT_PASTE = 20 # more than this many events will be assumed to
8892
# be a true paste event, i.e. control characters
8993
# like '<Ctrl-a>' will be stripped
@@ -837,22 +841,26 @@ def send_current_block_to_external_editor(self, filename=None):
837841
self.cursor_offset = len(self.current_line)
838842

839843
def send_session_to_external_editor(self, filename=None):
840-
for_editor = ("### current bpython session - file will be "
841-
"reevaluated, ### lines will not be run\n")
844+
for_editor = EDIT_SESSION_HEADER
842845
for_editor += '\n'.join(line[len(self.ps1):]
843846
if line.startswith(self.ps1) else
844847
line[len(self.ps2):]
845848
if line.startswith(self.ps2) else
846849
'### '+line
847850
for line in self.getstdout().split('\n'))
848851
text = self.send_to_external_editor(for_editor)
852+
if text == for_editor:
853+
self.status_bar.message(
854+
_('Session not reevaluated because it was not edited'))
855+
return
849856
lines = text.split('\n')
850-
from_editor = [line for line in lines if line[:4] != '### ']
857+
from_editor = [line for line in lines if line[:3] != '###']
851858
source = preprocess('\n'.join(from_editor), self.interp.compile)
852859
self.history = source.split('\n')
853860
self.reevaluate(insert_into_history=True)
854861
self.current_line = lines[-1][4:]
855862
self.cursor_offset = len(self.current_line)
863+
self.status_bar.message(_('Session edited and reevaluated'))
856864

857865
def clear_modules_and_reevaluate(self):
858866
if self.watcher:

0 commit comments

Comments
 (0)