Sends entire bpython session to external editor to be edited. Usually bound to F7.
(self, filename=None)
| 1100 | self.cursor_offset = len(self.current_line) |
| 1101 | |
| 1102 | def send_session_to_external_editor(self, filename=None): |
| 1103 | """ |
| 1104 | Sends entire bpython session to external editor to be edited. Usually bound to F7. |
| 1105 | """ |
| 1106 | for_editor = EDIT_SESSION_HEADER |
| 1107 | for_editor += self.get_session_formatted_for_file() |
| 1108 | |
| 1109 | text = self.send_to_external_editor(for_editor) |
| 1110 | if text == for_editor: |
| 1111 | self.status_bar.message( |
| 1112 | _("Session not reevaluated because it was not edited") |
| 1113 | ) |
| 1114 | return |
| 1115 | lines = text.split("\n") |
| 1116 | if len(lines) and not lines[-1].strip(): |
| 1117 | lines.pop() # strip last line if empty |
| 1118 | if len(lines) and lines[-1].startswith("### "): |
| 1119 | current_line = lines[-1][4:] |
| 1120 | else: |
| 1121 | current_line = "" |
| 1122 | from_editor = [ |
| 1123 | line for line in lines if line[:6] != "# OUT:" and line[:3] != "###" |
| 1124 | ] |
| 1125 | if all(not line.strip() for line in from_editor): |
| 1126 | self.status_bar.message( |
| 1127 | _("Session not reevaluated because saved file was blank") |
| 1128 | ) |
| 1129 | return |
| 1130 | |
| 1131 | source = preprocess("\n".join(from_editor), self.interp.compile) |
| 1132 | lines = source.split("\n") |
| 1133 | self.history = lines |
| 1134 | self.reevaluate(new_code=True) |
| 1135 | self.current_line = current_line |
| 1136 | self.cursor_offset = len(self.current_line) |
| 1137 | self.status_bar.message(_("Session edited and reevaluated")) |
| 1138 | |
| 1139 | def clear_modules_and_reevaluate(self): |
| 1140 | if self.watcher: |