Skip to content

Conversation

foobarbyte
Copy link
Contributor

Since the vi keybinding (v) and emacs mode keybinding (c-x c-e) are handled by prompt_toolkit directly, and the tempfile_suffix argument was not provided to prompt_toolkit, the tempfile created when the editor was opened via these keybindings was a .txt file, breaking syntax highlighting in some editors.

By passing the tempfile_suffix=".py" argument to the PromptSession constructor, this ensures that when the open_in_editor() method of the current buffer is called, the tempfile opened in the editor will always have a .py extension.

The open_input_in_editor(event) function associated with the f2 keybinding manually set the tempfile_suffix property of the current buffer before calling the buffer's open_in_editor() method. Passing the tempfile_suffix argument to the PromptSession constructor ensures that .py extension is always used, so setting the attribute manually is no longer required.

With these small changes, vi and emacs open_in_editor shortcuts produce a tempfile with the correct extension, and F2 continues to work correctly.

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.
Since tempfile_suffix is set in the PromptSession constructor, it does not need to be set when calling the open_input_in_editor function.
@Carreau Carreau added this to the 7.14 milestone Mar 3, 2020
@Carreau
Copy link
Member

Carreau commented Mar 3, 2020

Looks reasonable. Thanks

@Carreau Carreau merged commit b7beef6 into ipython:master Mar 3, 2020
meeseeksmachine pushed a commit to meeseeksmachine/ipython that referenced this pull request Mar 3, 2020
Carreau added a commit that referenced this pull request Mar 4, 2020
…167-on-7.x

Backport PR #12167 on branch 7.x (Set .py tempfile suffix when using vi/emacs editor shortcuts.)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants