apommel / vscode-matlab-interactive-terminal

VS Code extension allowing for an interactive Matlab terminal and launching of scripts through Matlab Engine for Python
MIT License
46 stars 10 forks source link

Recognize and run code blocks #13

Open ngharrison opened 4 years ago

ngharrison commented 4 years ago

Just a feature suggestion. The ability to run blocks of code delimited by %% would be very useful. Thanks for the great extension!

apommel commented 4 years ago

Thanks for your feedback! You mean that this feature would be able to run blocks one after the other, a bit like Jupyter?

ngharrison commented 4 years ago

Yes, similar to that. The idea of code blocks or code cells. The Matlab IDE does this itself using %%. There is similar functionality in Python IDEs (Jupyter, Spyder, VSCode Python extension) with some delimiter such as #%%.

One more thing I'd add on is to have the focus stay in the editor when code (selection, line, block, etc.) is run. Currently it always takes me to the terminal and I have to click back into the editor to run the next line.

These would be nice features. I'm not sure how complicated they would be.

aidedinertial commented 4 years ago

Here is my workaround for cell evaluation:

This solution requires the Vim extension.

  1. Press Escape to enter Vim Command Mode
  2. Type /%% to search for the beginning of a cell
  3. Type N to find the top of the current cell (or g to jump to beginning of file)
  4. Type Shift+V to select the current line
  5. Type n to jump to beginning of next cell (or G to jump to end of file)
  6. Use mapped keybinding to run command "extension.runMatlabSelection"

I have also mapped <Ctrl+A> to toggle focus between the editor and terminal.

weihongliang233 commented 4 years ago

Yes, similar to that. The idea of code blocks or code cells. The Matlab IDE does this itself using %%. There is similar functionality in Python IDEs (Jupyter, Spyder, VSCode Python extension) with some delimiter such as #%%.

One more thing I'd add on is to have the focus stay in the editor when code (selection, line, block, etc.) is run. Currently it always takes me to the terminal and I have to click back into the editor to run the next line.

These would be nice features. I'm not sure how complicated they would be.

Check out this issue/pullrequest Adding "Cursor Back to Editor" function for "Run Current Selection". It solves your second problem.

weihongliang233 commented 4 years ago

I think "splitting code into blocks" should be an independent functionality. I'm working on it. Here is a demo. I'll integrate it into this extension soon and hope can implement the "run code blocks" functionality.

weihongliang233 commented 4 years ago

Almost done (if there is no unexpected bugs).