Run automatically-inferred Python code blocks in Jupyter.
In this example, the only keyboard shortcut used is Shift+Enter:
This is inspired by the Hydrogen and hydrogen-python
extensions for Atom.
Install from the Visual Studio Marketplace or search kylebarron.vscode-jupyter-python
in the vscode extensions search bar.
Infer a logical "block" of code to be run at once, without needing to manually mark cell boundaries with # %%
.
In general a "block" is the current line plus any following lines with a greater initial indentation.
Additionally there's a list of keywords where the "block" of code should be expanded, even when that code appears at the same indentation level. For example:
# cursor
# ↓
if x > 0:
foo()
else:
bar()
in this case a naive "include only code with greater indentation" would exclude the else
clause, so else
is included in the list of keywords where the code should be extended despite being at the initial indentation. See "extension settings" below for how to modify this list.
By default there are two shortcuts defined:
This depends on the upstream vscode-jupyter
extension, where this extension simply infers what text to send to jupyter.execSelectionInteractive
.
vscode-jupyter-python.expandCodeList
: This list is used to determine when code that is part of the same indentation level as the starting text should be included in the inferred block. You may define your own custom elements to modify the code to your preferred behaviour. In the default setting, else
, elif
, except
, finally
, as well as all closing braces are expanded on.This is an early package so there are probably bugs.