This project has moved and is read-only. For the latest updates, please go here.

Improvement in REPL flexibility


REPL feature request following a chat with Dino Viehland

I believe the flexibility and userfriendliness of the REPL could be improved to match other REPL. For instance, Spiderlib's.

I would like simple keyboard shortcuts to :
  1. send and eval the active line of code (the line where the cursor is) to the interactive console and move the cursor to the end of the next line of code (not in the console, so I can immediately repeat the action easily with the next line)
  2. same thing with the active block of code
  3. same thing with a selection of code
Currently, the REPL feature is limited to using Ctrl+E, CTRL+E (a simpler default combinaison would be better) and I cannot easily execute code line by line without having to move the cursor manually.

file attachments


Zooba wrote Jul 4, 2014 at 5:13 PM

I like it! Pretty sure the current shortcut doesn't work without a selection, so we could auto select the current block and advance the cursor if there's nothing selected.

What behaviour would be expected within a class/function? Send the whole block? Dedent and send each statement?

lorifan wrote Jul 4, 2014 at 6:39 PM

Very relevant question for the first case: 'send and eval the active line of code'.

I would recomment to handle two different subcases:
  1. if the active line is the first one of a class/function/loop
    Only send the active line to the console with no eval. The user can then send addition lines and the eval will only occur when a whole block has been sent.
  2. if the active line is within a class/function/loop
    Dedent, send the active line and eval
This is Rstudio REPL behavior and I quite like it.
I have attached a screen capture to illustrate the first subcase: the function is 14 lines long and I sent the first 5 lines to the console. No eval has occured so far. Cursor is now on line 6. For instance, I can then decide to send lines 11 to 14. A whole block will then be detected and an eval will occur.

Zooba wrote Jul 4, 2014 at 7:12 PM

Python has no way to detect the end of a block, unfortunately. Most repls use an empty line as a marker, but that doesn't apply in a script - the next line can be code but be one less indent.

Both of those cases are covered by "copy the current statement without indentation and paste into the repl at its natural indent then press enter", which is convenient. The only downside is that you'd have to manually switch to the repl to end a block. I think it's worth experimenting with this to figure out how to make it work best, which means it won't get into 2.1, but I'm sure we'll do something along these lines.

Ptools wrote Jul 4, 2014 at 9:39 PM

there's a whole LOT of stuff that can be done w the repl. i think we have a couple of features open. take a look at matlab's as well. next release we'll definitely focus more on the repl. personally, i'd like to see:
  • smart search in history (instead of just up/down)
  • repl commands history that allows selecting & executing subsections
  • ipython repl connected to a remote engine
  • ipython repl connected to debugger

lorifan wrote Jul 4, 2014 at 10:20 PM

Zooba, you are right, what I described in the first comment can't be done in Python.

I am not sure I correctly understand your second paragraph, especially why having to 'press enter' and 'manually switch to repl' This adds a lot of drag but maybe I did not get it correctly.

However, the idea of the feature request is simply:
  • one shortcut to "send active line of code to console then eval then switch back to text editor and move cursor to next line"
  • one shortcut to "send active block/selection to console then eval then switch back to text editor and move cursor to line following sent block/selection' (this exact feature available in Spiderlib as "run selection or current block F9")
I am really looking forward to see how it goes.