Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request: Run block and move down in Python text file without selecting block manually #12176

Closed
kylebarron opened this issue Nov 26, 2022 · 7 comments
Assignees
Labels
feature-request Request for new features or functionality

Comments

@kylebarron
Copy link

(I have tried to search through issues and have not found any relevant results)

Here's the behavior I'm used to in Atom's Hydrogen (with the added hydrogen-python extension). The only thing I'm pressing is Shift + Enter

Screen.Recording.2022-11-26.at.12.15.00.PM.mov
  1. Shift + Enter first starts the jupyter kernel
  2. Each call to Shift + Enter:
    1. Infers a "block" of code to run in Jupyter, including the current line plus any additional lines that are indented more than the current line
    2. Sends that block of code to Jupyter
    3. Moves cursor down past the block that was run + past any additional whitespace to the next line of Python code

Key points

  • This is not in a notebook with cells, but rather a normal Python text file.
  • I don't have to select the block manually to determine what to run.
  • Moving the cursor down automatically means that I can use a series of only Shift + Enter to run through as much of my file as I'd like
  • This is Python-specific, and so maybe is out of scope for this extension? Is there a Python-specific Jupyter add on somewhere?
@kylebarron kylebarron added the feature-request Request for new features or functionality label Nov 26, 2022
@kylebarron kylebarron changed the title Feature Request: Run block and move down in Python text file without selecting block Feature Request: Run block and move down in Python text file without selecting block manually Nov 26, 2022
@DonJayamanne DonJayamanne assigned amunger and unassigned DonJayamanne Nov 26, 2022
@amunger
Copy link
Contributor

amunger commented Nov 28, 2022

We currently have the Interactive Window for running sections of python files against a running kernel, and the "cells" are marked with # %%. You can set "jupyter.sendSelectionToInteractiveWindow": true to make shift+enter work that way.

One big difference with your video is that the output is sent to a separate editor rather than inline, and we don't currently attempt to find implicit code blocks.

Could you give that a try and let us know what you think?

@kylebarron
Copy link
Author

we don't currently attempt to find implicit code blocks.

That is what this feature request is for 🙂.

and the "cells" are marked with # %%

This is the big difference between Atom + Hydrogen and vscode + Jupyter IMO. My point is I don't want to have to use cells. For me as a Python library author and not a data scientist wanting the notebook experience, Hydrogen provides an amazing, seamless development experience because it's so easy to interactively debug a normal Python script (while still getting rich data output by relying on IPython).

Inferring code blocks automatically is a big factor in Hydrogen's expressiveness, because I don't have to manually select each region of text every time I run shift + enter.

You can set "jupyter.sendSelectionToInteractiveWindow": true to make shift+enter work that way

I do have this set.

@amunger
Copy link
Contributor

amunger commented Nov 28, 2022

alright, thanks for the feedback - I just wanted to make sure you knew about the functionality since it was related to what you were describing

@kylebarron
Copy link
Author

kylebarron commented Nov 29, 2022

I got frustrated enough that I just wrote my own extension (I also figured you likely wouldn't accept/implement python-specific functionality in this repo). I.e. here's a screencast of it in vscode

Screen.Recording.2022-11-28.at.10.27.28.PM.mov

The code for that extension is super hacky and not tested, but helps me keep my sanity and usual dev workflow now that Atom is mostly dead.

@andycraig
Copy link
Contributor

@kylebarron Wow, this is fantastic! I started using it today. Thank you very much for making it!

You may want to share this at this similar issue: #1471. I had just started working on something similar but I will be very happily using yours instead!

@kylebarron
Copy link
Author

@kylebarron Wow, this is fantastic! I started using it today. Thank you very much for making it!

Welcome! With the caveat that it was a quick hack and I can't promise there are no bugs and that I'll spend a lot of time maintaining it going forward 😄

You may want to share this at this similar issue: #1471

Ah I assumed there had to be an existing issue for this, but couldn't find one after a few minutes of searching.

@kylebarron
Copy link
Author

I figure I'll close this in favor of #1471

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 21, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feature-request Request for new features or functionality
Projects
None yet
Development

No branches or pull requests

4 participants