Spyder: Provide a "Run current line" feature

Created on 17 Feb 2015  ·  33Comments  ·  Source: spyder-ide/spyder

_From [email protected] on 2013-12-07T07:32:28Z_

Hello Spyder Devs

I often want to simply run the current line (i.e. the line under my cursor), and its a little cumbersome to first highlight it and then execute "Run Selection"
Thanks for your hardwork.

_Original issue: http://code.google.com/p/spyderlib/issues/detail?id=1670_

6–10 stars Editor Enhancement

Most helpful comment

We'll try to improve the line-by-line evaluation model in Spyder 4.

All 33 comments

_From ccordoba12 on 2013-12-11T17:37:05Z_

I also need this sometimes. Maybe we could make F9 to do this by default.

Status: Accepted
Labels: Cat-Editor MS-v2.3.1

_From [email protected] on 2014-01-30T09:41:51Z_

agreed it would be very useful
thks

_From [email protected] on 2014-03-11T06:26:44Z_

I couldn't concur more. Simple things like this really improve UX.

_From [email protected] on 2014-03-11T21:34:28Z_

It might be easy... Spyder already has a method to get the current line.
See: https://bitbucket.org/spyder-ide/spyderlib/pull-request/28/issue-1670-run-current-line-if-no/diff

_From [email protected] on 2014-03-12T09:16:35Z_

Hmm after some sleep, I realized that I'm just not completely comfortable with modifying get_selection_as_executable_code to let it return code that's not actually from a selection.

What would you suggest?

_From contrebasse on 2014-03-13T17:33:56Z_

Blind suggestion: have the function select the line before execution.

_From [email protected] on 2014-03-20T03:37:44Z_

Definitely +1. To avoid being a totally useless comment, I'd vote not to change the behavior for F9 (run selection), but rather add a new hotkey (F10 or whatever) for the functionality. Or F9 handler could check if a global option was set to change F9 from default behavior i.e. :

If no selection, get the text at the line where the text cursor is

if (OPTIONS.F9_RUN_CURRENT_LINE):
text = self.get_current_line()
else:
# do whatever you currently do

_From [email protected] on 2014-04-20T04:57:32Z_

Hi there,

The amended source code works good. Thank you so much. May I suggest something ?
When we press F9, the cursor place changes and go in the console window, which forces us to click again in the editor to use F9 again.

Maybe it would be good if the cursor stay in the editor and go in the next line, after the one executed.

Thank you

_From [email protected] on 2014-08-06T08:13:42Z_

Hi all,

Is the feature already built in Spyder? How can I get the run-line-without-selection to work?

Totally agree with the #9 comment. Please implement it in such a way that after completion the cursor remains in the editor.

Alternative suggestion- Ctrl+Enter can be used to run a line when nothing is selected. And this wouldn't interfere with the current behavior of F9. Ctrl+Enter is the hotkey in most editors that have this feature.

Thanks.

_From ccordoba12 on 2014-08-06T11:00:06Z_

There are two things here:

  1. Ctrl+Enter is used to evaluate cells (similar Matlab cells; they are created with comments of the form #%%), so this won't work.
  2. We can extend F9 behavior to evaluate the current line (when nothing is selected) _but_ only that. Before Spyder 2.2 F9 evaluated all lines above and below the current cursor, until a blank line was found. That behavior is not going to come back (because for that we introduced cells).

I'll try to solve this for 2.3.1

_From ccordoba12 on 2014-08-06T11:02:33Z_

I forgot to mention that staying in the Editor is part of a pull request I hope to merge soon.

_From ccordoba12 on 2014-08-17T09:44:26Z_

This issue was closed by revision 5f4e47ead5cc .

Status: Fixed

_From ccordoba12 on 2014-08-17T09:46:55Z_

Ok, now F9 runs the current line if nothing is selected. Besides, focus remains on the Editor when running lines, selections or cells.

Why can I not associate CTRL + ENTER for this feature? (I mean I can in preferences, but it doesn't work.)

Ctrl+Enter is reserved to run cells, as in the Jupyter notebook.

That is hard coded? Why not allow it to be bound to other things if it is not a cell. Seems to me this would make ctrl+enter more consistent, no? Like this:

  • highest priority: if selection, then execute selection
  • mid priority: if no selection, execute cell around cursor
  • low priority: if no selection and no cell, execute line.

For consistency with similar platforms, F9 must skip to the next line if no text is selected.

An option to overload the ctrl+enter would be nice too. That way Jupyter users keep their consistency and RStudio users get their way.

F9 will move to the next line in our next release (Spyder 3.0). About Ctrl+Enter, please open a new issue about it, this one is closed :-)

ctrl+Enter shortcut wouldbe better for this.

ctrl+Enter is better for this .. much much better than F9.

It's better for Rstudio people because they are accustomed to it :-)

But we're going to provide an Rstudio shortcut set in Spyder 3.1.

Where can I find the Rstudio shortcut set in Spyder 3.2.4?

Sorry, we haven't had time to implement it. That's going to be available in Spyder 4, to be released next year.

Ok, I look forward to it 👍

Hi,

If you guys could go beyond F9 for current line and have it more like RStudio's ctrl+enter which runs the next command I would be very grateful.

Running 1 line at a time means any commands or functions that go over one line need to be highlighted and selected manually to run (unless you wrote the code with sufficient number of cells).

Thanks so much!
Kirk

@kgeier, that is what cells are for. You can create a cell (which is a block of code that can be evaluated independently) by adding a comment of the form #%% in your code file. Then, after pressing Ctrl+Enter (run cell and stay in the current cell) or Shift+Enter (run cell and advance), that block will be sent to the console.

Hi Carlos,
Yes thank you. Cells is definitely better than nothing but if trying to run someone else's code that hasn't been written with cells it's a little less clear and more work. However I understand if you guys have other priorities.

Thanks!

We'll try to improve the line-by-line evaluation model in Spyder 4.

I'm not sure if I've missed this, but is there a date for deployment of Spyder 4 in Anaconda?

January of 2019. We can't be more specific right now, sorry.

Is the run-current line function available in the Spyder 4 beta?

No, not yet.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

goanpeca picture goanpeca  ·  3Comments

dalthviz picture dalthviz  ·  3Comments

spyder-bot picture spyder-bot  ·  3Comments

danieltomasz picture danieltomasz  ·  3Comments

gabrielclow picture gabrielclow  ·  3Comments