|
84 | 84 | Press {config.edit_config_key} to edit this config file. |
85 | 85 | """ |
86 | 86 | 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 | +""" |
91 | 92 | MAX_EVENTS_POSSIBLY_NOT_PASTE = 20 # more than this many events will be assumed to |
92 | 93 | # be a true paste event, i.e. control characters |
93 | 94 | # like '<Ctrl-a>' will be stripped |
@@ -854,11 +855,19 @@ def send_session_to_external_editor(self, filename=None): |
854 | 855 | _('Session not reevaluated because it was not edited')) |
855 | 856 | return |
856 | 857 | 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 = '' |
857 | 864 | from_editor = [line for line in lines if line[:3] != '###'] |
| 865 | + |
858 | 866 | source = preprocess('\n'.join(from_editor), self.interp.compile) |
859 | | - self.history = source.split('\n') |
| 867 | + lines = source.split('\n') |
| 868 | + self.history = lines |
860 | 869 | self.reevaluate(insert_into_history=True) |
861 | | - self.current_line = lines[-1][4:] |
| 870 | + self.current_line = current_line |
862 | 871 | self.cursor_offset = len(self.current_line) |
863 | 872 | self.status_bar.message(_('Session edited and reevaluated')) |
864 | 873 |
|
|
0 commit comments