quarto-dev / quarto

Quarto open-source scientific and technical publishing system
https://quarto.org
GNU Affero General Public License v3.0
332 stars 29 forks source link

Run single line interactively #299

Closed m-pauper closed 1 year ago

m-pauper commented 1 year ago

Hello,

In my VS Code keybindings.json I had included the following:

{
        "key": "alt+enter",
        "command": "quarto.runSelection",
        "when": "editorTextFocus && !findInputFocussed && !replaceInputFocussed && editorLangId == 'quarto'"
    },
    {
        "key": "ctrl+enter",
        "command": "-quarto.runSelection",
        "when": "editorTextFocus && !findInputFocussed && !replaceInputFocussed && editorLangId == 'quarto'"
    },
    {
        "key": "alt+enter",
        "command": "quarto.runSelection",
        "when": "activeCustomEditorId == 'quarto.visualEditor'"
    },
    {
        "key": "ctrl+enter",
        "command": "-quarto.runSelection",
        "when": "activeCustomEditorId == 'quarto.visualEditor'"
    },

which allowed me to send and execute the current line in the editor to the interactive session by pressing alt+enter. It used to work fine.

Today I noticed that when I tried it, VS Code says the command does not exist anymore:

image

Was it deprecated?

Thanks for any help!

jjallaire commented 1 year ago

It's been renamed quarto.runCurrent

m-pauper commented 1 year ago

I thought so and renamed the runSelection in those lines to runCurrent but now pressing alt+enter runs the entire cell, not only the current line.

jjallaire commented 1 year ago

Okay, I'll take a closer look too see what the problem might be!

jjallaire commented 1 year ago

I think I see the issue. In the last release we wanted to make our keyboard shortcuts better align with Jupyter notebooks (as many of our users will be switching between notebooks and qmds). In notebooks, there isn't a default command/keyboard shortcut to run a single line (you always run the whole cell). So we changed the behavior of Cmd+Enter to run the cell rather than the line. We also added Shift+Enter which does the same and advanced to the next cell (same as Jupyter).

That said, I do think that a line at a time is still potentially valuable so we should have a way to do it. We could bind Alt+Enter to run line (as you did). The only downside of this is that is the Jupyter Notebook shortcut for "run cell and insert a new cell below"). So we'd fail to be compatible in that way but gain line-by-line execution.

Note that for Knitr we will execute line by line (as unlike Jupyter that is the default behavior in RStudio).

jjallaire commented 1 year ago

New command added here: https://github.com/quarto-dev/quarto/commit/292eab14438252e397a4c0d9881138c9a09aca9d

m-pauper commented 1 year ago

Thank you so much!

benjaminmoritz commented 1 year ago

Hello. May you please bring back the old functionality "runSelection"? I was not only running single lines while developing but also running single code parts. e.g. a variable name. So the variable was displayed.

benjaminmoritz commented 1 year ago

I also select multiple lines and let them run. this is not possible anymore unfortunately

m-pauper commented 1 year ago

Indeed, the new runLine works great but cannot run a selection of x lines, only single lines. This is problematic especially when you split long lines of code to multiple lines. Submitting only one often results in an error in the interactive interpreter.

jjallaire commented 1 year ago

Okay, in version 1.105.0 of the extension we have now brought back the original "quarto.runSelection" command (bound to Alt+Enter).

Cmd+Enter will execute the entire cell (if in Jupyter, to match notebook UIs) or line/selection (if in Knitr, to match RStudio UI)