"Run current line or selection" functionality? #13226
Unanswered
adam-milton-morgan
asked this question in
Feedback
Replies: 2 comments 1 reply
|
Interesting! Positron has a code execution API that can do this, but it's not possible to do via a keybinding AFAIK. positron/src/positron-dts/positron.d.ts Lines 2158 to 2161 in ccda249 Can you say more about why you want to send partial statements to the console? |
0 replies
|
Interesting, thanks! I wonder if I can somehow leverage that... will play
around with it.
As for why, I just find it so much faster to find errors and troubleshoot
when I can move line by line through my script, skip some lines, send
others in different orders. It's not really about sending partial
statements -- that's not helpful in itself. It's probably not the best
coding practice, but I often comment out the "for(loop in variables){" line
and leave "loop = variables[1]" uncommented right beneath it when coding so
that I can move line-by-line and execute as I go, making sure every line
works and does what I expect it to. Then at the very end I'll go back and
uncomment the loops etc.
Thanks again!
…On Mon, Apr 27, 2026 at 10:42 PM Jonathan ***@***.***> wrote:
Interesting! Positron has a code execution API that can do this, but it's
not possible to do via a keybinding AFAIK.
https://github.com/posit-dev/positron/blob/ccda249178398602c859a8f8bcf8bb5a3ae79409/src/positron-dts/positron.d.ts#L2158-L2161
Can you say more about why you want to send partial statements to the
console?
—
Reply to this email directly, view it on GitHub
<#13226 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ACZMDIPJSQUVDKMZ6MFV7ML4YAEA5AVCNFSM6AAAAACYIPCUO6VHI2DSMVQWIX3LMV43URDJONRXK43TNFXW4Q3PNVWWK3TUHMYTMNZTGYZTIMA>
.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
My favorite thing about RStudio is that I can send single lines to the console with one keyboard shortcut (I have it set to Cmd+Enter). I've been trying to replicate that behavior in Positron through various keybindings.json configurations, but can't quite seem to get it to work. Specifically, I want Cmd+Enter to behave like RStudio's "Run Current Line or Selection," which executes the selection if there's selected code (any number of lines), or if not, it executes just the current line, and moves the cursor to the beginning of the next line down. The closest I've come is this:
(NOTE: I didn't realize tabs wouldn't align the code properly below, so the code looks awful. Adding this a screenshot, which shows one of the keybindings I've tried (left) and the problem in console (right), where the first entry comes from hitting Cmd+Enter with the keybinding below and the second, which works the way I want, occurs when I type "if(TRUE){" directly into the console and hit "Enter".)

[
{
"key": "cmd+enter",
"command": "workbench.action.positronConsole.executeCode",
"when": "editorTextFocus && editorLangId == 'r' && editorHasSelection"
},
{
"key": "cmd+enter",
"command": "runCommands",
"when": "editorTextFocus && editorLangId == 'r' && !editorHasSelection",
"args": {
"commands": [
"cursorHome",
"cursorEndSelect",
"workbench.action.positronConsole.executeCode",
"workbench.action.positronConsole.enter",
"cancelSelection",
"cursorDown",
"cursorHome"
]
}
}
]
The first entry executes highlighted code (if any) in console. The second is for when there's no highlighted code — this is when I want it to just send one line, not a block or the rest of the script. I couldn't find a way to directly execute the line, so I had it highlight the line by moving the cursor to the beginning of the line ("cursorHome"), selecting the rest of the line (cursorEndSelect), sending that to the console, then moving the cursor to the beginning of the next line. The problem is, the line of code appears in the console input line, but isn't executed. I have also tried the following, which is similar except that the second command leverages the executeCode command.
[ { "key": "cmd+enter", "command": "workbench.action.positronConsole.executeCode", "when": "editorTextFocus && editorLangId == 'r' && editorHasSelection" }, { "key": "cmd+enter", "command": "runCommands", "when": "editorTextFocus && editorLangId == 'r' && !editorHasSelection", "args": { "commands": [ "cursorHome", "cursorEndSelect", { "command": "workbench.action.positronConsole.executeCode", "args": { "languageId": "r", "advance": false, "allowIncomplete": true } }, "cancelSelection", "cursorDown", "cursorHome" ] } } ]This works for a single line of code (e.g., "x = 10"), but it rejects incomplete input rather than sending it to the R console continuation prompt. For instance, if you try to run the following R code line-by-line by repeatedly pressing Cmd+Enter:
if(x){ print("hey!") }it breaks on the first line: the console prints: "Error: Can't parse incomplete input" rather than "+" (indicating that the console is waiting for the rest of the as-yet incomplete code). The "+" is what RStudio does automatically, and, notably, what the console does when you just type
if(TRUE){directly into the console in Positron and hit "Enter".
I would love a feature like one of these:
Does anyone know if something like that exists? Any other ideas? Thanks!!
All reactions