Repository: spyder-ide/spyder

Issue:
Automatically advance to the next line after pressing F9
There's already a [question on stackoverflow](http://stackoverflow.com/questions/35611033/how-to-automatically-advance-to-the-next-line-after-f9-in-spyder-ide) that perfectly describes my question:

> Coming from RStudio, I'm familiar with the behavior of the cursor automatically moving to the next line after running the current line. I think this makes sense for data analysis. Does Spyder have something similar?
> 
> I'm familiar with the concept of cell and auto-advancing cell in Spyder. However, I want to maintain a pure Python script (that can be run with python file.py) for portability, and don't want to use something that only makes sense on Spyder.

I know some people in my working group and other institutions that would already like to have such a shortcut for procedural data analysis scripts, plotting, ...

Is there a way to realize that behaviour (without using code cells)?



Discussion:
I can easily make F9 to advance to the next line, but I think it's much nicer to use cells.

Please remember that cells are _comments_ (so there's nothing special about them) of the form

``` python
#%% One cell

#%% Another cell
```

They are just interpreted by Spyder to break a file in regions that can be evaluated independently of the rest :-) But there's no problem in running `python myscript.py` with that kind of comments :-)

However, @ckaldemeyer please let me know if this is a really important feature for you and/or your team or colleagues, and I'll add it to the next Spyder release :-)

Hi Carlos,

thanks for your answer!

I know the concept of cells and already make use of it in certain scripts to group semantical connected blocks of code.

But I think a shortcut "run current line and advance" would be a nice addition to go through procedural scripts line by line without having to define cells. I think this would be a valuable feature for many users that use Python for data analysis and statistics coming from languages like R. And I know various people from my institution who would appreciate it.

My opinion on the implementation: A definable keyboard shortcut under "Preferences > Keyboard shortcuts" would also be o.k.

Thanks a lot!

Cheers
Cord

@ckaldemeyer, I think making F9 to move to the next line is the thing to do (instead of introducing a new shortcut that does something slightly different :-).

@goanpeca, what do you think?

Agree on F9 move to the next line :+1:

@ccordoba12 and @goanpeca : That's great, thanks! Will it be in the next version? And what are your plans on the releases? Do your have a fix cycle or release as time allows you?

Best!

We have bugfix releases for the 2.3 branch, but they are limited to really critical bugs (like freezes and crashes).

That's why I tagged this issue for Spyder 3.0. We hope to release it next month :-)

Thanks a lot!

Very much needed..looking forward to it..!


Resolving patch:
diff --git a/spyderlib/widgets/editor.py b/spyderlib/widgets/editor.py
--- a/spyderlib/widgets/editor.py
+++ b/spyderlib/widgets/editor.py
@@ -1773,12 +1773,21 @@ def fix_indentation(self, index=None):
 
     #------ Run
     def run_selection(self):
-        """Run selected text or current line in console"""
+        """
+        Run selected text or current line in console. If no text is selected, 
+        then advance cursor to next line.
+        """
         text = self.get_current_editor().get_selection_as_executable_code()
-        if not text:
-            line = self.get_current_editor().get_current_line()
+        if text:
+            move_next_line = False
+        else:
+            editor = self.get_current_editor()
+            line = editor.get_current_line()
             text = line.lstrip()
+            move_next_line = True
         self.exec_in_extconsole.emit(text, self.focus_to_editor)
+        if move_next_line:
+            editor.move_cursor_to_next('line', 'down')
 
     def run_cell(self):
         """Run current cell"""


Test patch: