This is a Sublime Text plugin for Mac OS X and Linux which passes the contents of a buffer line-by-line to a REPL and displays the results inline.
It works in Sublime Text 2 and 3.
It's great for trying things out directly in Sublime Text.
Windows support Thanks to @timonwong v0.8.0 introduces experimental Windows support. Please report any issues you discover.
Package Control is "a full-featured package manager that helps discovering, installing, updating and removing packages for SublimeText 2." It's the preferred way to manage your SublimeText 2 Packages directory.
Follow these instructions to install Sublime-worksheet with Package Control.
Go to your SublimeText 2 Packages
directory and clone the repository using the command below:
$ git clone https://github.com/jcartledge/sublime-worksheet.git
Download the files using the .zip download option.
Unzip the files.
Copy the folder to your SublimeText 2 Packages directory.
Sublime Worksheet provides two commands which you can access from the command palette (CMD-SHIFT-P / CTRL-SHIFT-P):
Worksheet: Evaluate worksheet
Passes the contents of the current document line by line to the interpreter which matches its syntax setting.
Results are inserted as comments directly below the statement, as they would appear if you were entering them in the REPL.
This automatically clears the results of previous evaluations first.
You don't need to save the document before running Evaluate worksheet
, but if it has been saved then you can write imports/requires/includes relative to the file and they should work.
Any errors or timeouts will cause evaluation to stop and the error to be written to the document. A timeout occurs if the REPL hasn't returned a result for an evaluated line after 10 seconds.
Worksheet: Clear worksheet results
Removes comments inserted by evaluating the worksheet.
You also can override Sublime Worksheet settings per-project so you can use your virtual environnement. For example, to add your virtualenv, just append this to your .sublime-project
file:
"settings": {
"worksheet_languages": {
"Python": {
"cmd": "/home/adrien/.pyenvs/web2/bin/python -i",
"prompt": [">>> ", "\\.\\.+ "],
"prefix": "# > ",
"error": ["Traceback ", " File \"<stdin>\","]
},
}
}
Please see the worksheet.sublime-settings
for more configuration examples.
Sublime worksheet uses the interpreters you have installed on your system. Generally speaking if you can run an interpreter from the command line it should work in Sublime Text. The following languages are supported:
Uses the iex
interpreter running on the Erlang VM.
Uses the interactive mode of the NodeJS command line interpreter.
Uses re.pl
which is provided by the Devel::REPL
package.
# You may need to run these as root
cpan -i Devel::REPL
# You also need to install a readline implemetation:
cpan -i Term::ReadLine::Perl
apt-get install libdevel-repl-perl
Uses the PHP CLI executable in interactive mode (php -a
).
See your OS package manager documentation or the PHP website for help setting this up.
Uses the interactive mode of the Python binary (python -i
).
See your OS package manager documentation or the Python website for help setting this up.
Uses irb
.
See your OS package manager documentation or the Ruby website for help setting this up.
Uses the Scala REPL.
See your OS package manager documentation or the Scala website for help setting this up.
Uses Guile.
See your OS package manager documentation or the Guile website for help setting this up.
There is an issue where code which is interpreted correctly by non-interactive Python causes an indentation error in interactive Python.
This arises when indented lines are separated by one or more unindented blank lines. The simple workaround is to indent the blank lines to the level of the surrounding indentation.
For more information see this issue or this StackOverflow thread.
Please feel free. More REPLs would be great - take a look at worksheet.sublime-settings (and this pull request) for details of how these are implemented.