spyder-ide / spyder

Official repository for Spyder - The Scientific Python Development Environment
https://www.spyder-ide.org
MIT License
8.33k stars 1.61k forks source link

Provide a "Run current line" feature #1670

Closed spyder-bot closed 9 years ago

spyder-bot commented 9 years ago

From giz...@gmail.com 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

spyder-bot commented 9 years ago

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

spyder-bot commented 9 years ago

From bl83...@gmail.com on 2014-01-30T09:41:51Z

agreed it would be very useful thks

spyder-bot commented 9 years ago

From geotheo...@gmail.com on 2014-03-11T06:26:44Z

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

spyder-bot commented 9 years ago

From robro...@gmail.com 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

spyder-bot commented 9 years ago

From robro...@gmail.com 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?

spyder-bot commented 9 years ago

From contrebasse on 2014-03-13T17:33:56Z

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

spyder-bot commented 9 years ago

From nin...@gmail.com 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

spyder-bot commented 9 years ago

From mayou...@gmail.com 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

spyder-bot commented 9 years ago

From heshr...@gmail.com 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.

spyder-bot commented 9 years ago

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

spyder-bot commented 9 years ago

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.

spyder-bot commented 9 years ago

From ccordoba12 on 2014-08-17T09:44:26Z

This issue was closed by revision 5f4e47ead5cc .

Status: Fixed

spyder-bot commented 9 years ago

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.

DavorJ commented 8 years ago

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

ccordoba12 commented 8 years ago

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

DavorJ commented 8 years ago

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:

lgallindo commented 8 years ago

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.

ccordoba12 commented 8 years ago

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 :-)

DavorJ commented 8 years ago

New issue is thus made: https://github.com/spyder-ide/spyder/issues/3395

kanihal commented 8 years ago

ctrl+Enter shortcut wouldbe better for this.

kjmobile commented 7 years ago

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

ccordoba12 commented 7 years ago

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.

markusdumke commented 7 years ago

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

ccordoba12 commented 7 years ago

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

markusdumke commented 7 years ago

Ok, I look forward to it 👍

kgeier commented 6 years ago

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

ccordoba12 commented 6 years ago

@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.

kgeier commented 6 years ago

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!

ccordoba12 commented 6 years ago

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

vultronn commented 6 years ago

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

ccordoba12 commented 6 years ago

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

vultronn commented 6 years ago

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

ccordoba12 commented 6 years ago

No, not yet.