I am using Sublime Text 3 and running OSX Mavericks. I am using the Sublime REPL package and I have adjusted the settings for that package such that I have "show_transferred_text" : true
When a Python REPL window is opened, I have the nice option to send a chunk of code from the editor to it using Ctrl + , , s . But, doing so doesn't display any of the output of my commands, unless I include a print command. E.g. If I write the following
x = 2.5
type(x)
and use the Ctrl +
, , s to send it to be evaluated, then I do get a display of these commands, but I don't get a display of the output from type(x) as I would if I copy/pasted the commands into the Python interpreter in the Mac Terminal.
Is there any way to get this functionality within Sublime Text?
[UPDATE]
The code below is now deprecated. For the newest, better working version, please visit the gist for this plugin at https://gist.github.com/dantonnoriega/46c40275a93bab74cff6.
Feel free to fork and star. I will add any changes to the gist as the code evolves. However, to stay the most up-to-date, please following the following repo: https://github.com/dantonnoriega/sublime_text_plugins/blob/master/python_blocks_for_repl.py
***************
I wanted the same functionality. What I came up with works and is a hodgepodge of the following posts:
https://stackoverflow.com/a/14091739/3987905
Is it possible to chain key binding commands in sublime text 2?
How to pass a line to the console in sublime text 2 editor
Creating the Plugin
The following plugin requires that you open repl in the same window as your code but as a separate group. I learned how to do this using the 1st link above. In order to send the text you want and then execute the text, I used the idea from the 2nd link above and wrote the following plugin (Tools -> New Plugin...)
The code above sends the selected line(s) to REPL, focuses the group where REPL is contained, executes REPL (i.e. hits 'enter') then focuses back to the code window.
The plugin now moves the cursor to the next line automatically so you can evaluate lines quickly. Also, if the next line happens to be empty, the plugin keeps hitting 'enter' for you automatically until it encounters a non-empty line. This, for me, was key, since if I selected a function block in python, I would still have to switch over to REPL and hit enter for the function to complete. The while loop part fixes that.
Using the Plugin
To run the following plugin, I put the following in my user key bindings (which I learned from the 3rd link above)...
And that should work!
Summary
Remember, you need to
pydev
plugin).'repl_view_and_execute'
plugin then bind it.If anyone knows how to make a more elegant version that can switch between the active window and wherever the REPL view is contained (like another window), I welcome the advice. I worked through
sublimerepl.py
but could not figure out how to use all theactive_window()
etc. commands.