From 5d39b579262dda44b321fe5b6f4a3dd42fd29f0c 2020-03-01 10:45:52 From: foobarbyte <61650320+foobarbyte@users.noreply.github.com> Date: 2020-03-01 10:45:52 Subject: [PATCH] Pass tempfile_suffix argument to PromptSession. This ensures that when the open_in_editor() method of the current buffer (a prompt_toolkit.buffer.Buffer) is called, the tempfile opened in the editor will always have a .py extension, to support editor syntax highlighting. The open_input_in_editor(event) function associated with the f2 keybinding manually sets the tempfile_suffix property of the current buffer before calling its open_in_editor() method. The vi keybinding (v) and emacs mode keybinding (c-x c-e) are handled by prompt_toolkit directly, bypassing this function, so the tempfile created when they are used is a .txt file. Passing the tempfile_suffix argument to the PrompSession constructor ensures that .py extension is always used. --- diff --git a/IPython/terminal/interactiveshell.py b/IPython/terminal/interactiveshell.py index 9f7d335..7f18ac2 100644 --- a/IPython/terminal/interactiveshell.py +++ b/IPython/terminal/interactiveshell.py @@ -322,6 +322,7 @@ class TerminalInteractiveShell(InteractiveShell): mouse_support=self.mouse_support, enable_open_in_editor=self.extra_open_editor_shortcuts, color_depth=self.color_depth, + tempfile_suffix=".py", **self._extra_prompt_options()) def _make_style_from_name_or_cls(self, name_or_cls):