Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide a "Run current line" feature #1670

Closed
spyder-bot opened this issue Feb 17, 2015 · 33 comments
Closed

Provide a "Run current line" feature #1670

spyder-bot opened this issue Feb 17, 2015 · 33 comments

Comments

@spyder-bot
Copy link
Collaborator

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
Copy link
Collaborator Author

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
Copy link
Collaborator Author

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

agreed it would be very useful
thks

@spyder-bot
Copy link
Collaborator Author

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

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

@spyder-bot
Copy link
Collaborator Author

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
Copy link
Collaborator Author

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
Copy link
Collaborator Author

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

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

@spyder-bot
Copy link
Collaborator Author

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
Copy link
Collaborator Author

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
Copy link
Collaborator Author

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
Copy link
Collaborator Author

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
Copy link
Collaborator Author

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
Copy link
Collaborator Author

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

This issue was closed by revision 5f4e47ead5cc .

Status: Fixed

@spyder-bot
Copy link
Collaborator Author

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
Copy link

DavorJ commented Aug 4, 2016

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

@ccordoba12
Copy link
Member

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

@DavorJ
Copy link

DavorJ commented Aug 4, 2016

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.

@lgallindo
Copy link

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
Copy link
Member

ccordoba12 commented Sep 2, 2016

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
Copy link

DavorJ commented Sep 2, 2016

New issue is thus made: #3395

@kanihal
Copy link

kanihal commented Oct 9, 2016

ctrl+Enter shortcut wouldbe better for this.

@kjmobile
Copy link

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

@ccordoba12
Copy link
Member

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
Copy link

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

@ccordoba12
Copy link
Member

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

@markusdumke
Copy link

Ok, I look forward to it 👍

@kgeier
Copy link

kgeier commented May 7, 2018

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
Copy link
Member

ccordoba12 commented May 7, 2018

@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
Copy link

kgeier commented May 9, 2018

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
Copy link
Member

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

@vultronn
Copy link

vultronn commented Aug 9, 2018

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

@ccordoba12
Copy link
Member

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

@vultronn
Copy link

vultronn commented Aug 23, 2018

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

@ccordoba12
Copy link
Member

No, not yet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

9 participants