|
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 | 91 | MAX_EVENTS_POSSIBLY_NOT_PASTE = 20 # more than this many events will be assumed to
|
88 | 92 | # be a true paste event, i.e. control characters
|
89 | 93 | # like '<Ctrl-a>' will be stripped
|
@@ -837,22 +841,26 @@ def send_current_block_to_external_editor(self, filename=None):
|
837 | 841 | self.cursor_offset = len(self.current_line)
|
838 | 842 |
|
839 | 843 | 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 |
842 | 845 | for_editor += '\n'.join(line[len(self.ps1):]
|
843 | 846 | if line.startswith(self.ps1) else
|
844 | 847 | line[len(self.ps2):]
|
845 | 848 | if line.startswith(self.ps2) else
|
846 | 849 | '### '+line
|
847 | 850 | for line in self.getstdout().split('\n'))
|
848 | 851 | 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 |
849 | 856 | 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] != '###'] |
851 | 858 | source = preprocess('\n'.join(from_editor), self.interp.compile)
|
852 | 859 | self.history = source.split('\n')
|
853 | 860 | self.reevaluate(insert_into_history=True)
|
854 | 861 | self.current_line = lines[-1][4:]
|
855 | 862 | self.cursor_offset = len(self.current_line)
|
| 863 | + self.status_bar.message(_('Session edited and reevaluated')) |
856 | 864 |
|
857 | 865 | def clear_modules_and_reevaluate(self):
|
858 | 866 | if self.watcher:
|
|
0 commit comments