Skip to content

Transpiles, evaluates and prints code. Provides immediate feedback for code execution within Sublime Text.

License

Notifications You must be signed in to change notification settings

evandroforks/EvalPrinter

 
 

Repository files navigation

Sublime-EvalPrinter Build Status

EvalPrinter is a Sublime Text 2/3 Plugin which transpiles, evaluates and prints code. This allows rapid testing of code snippets without leaving your code editor. To see which languages are supported, see the appropriate section.

Installation

By Package Control

  1. Download & Install Sublime Text 3 (https://www.sublimetext.com/3)
  2. Go to the menu Tools -> Install Package Control, then, wait few seconds until the installation finishes up
  3. Now, Go to the menu Preferences -> Package Control
  4. Type Add Channel on the opened quick panel and press Enter
  5. Then, input the following address and press Enter
    https://raw.githubusercontent.com/evandrocoan/StudioChannel/master/channel.json
    
  6. Go to the menu Tools -> Command Palette... (Ctrl+Shift+P)
  7. Type Preferences: Package Control Settings – User on the opened quick panel and press Enter
  8. Then, find the following setting on your Package Control.sublime-settings file:
    "channels":
    [
        "https://packagecontrol.io/channel_v3.json",
        "https://raw.githubusercontent.com/evandrocoan/StudioChannel/master/channel.json",
    ],
  9. And, change it to the following, i.e., put the https://raw.githubusercontent... line as first:
    "channels":
    [
        "https://raw.githubusercontent.com/evandrocoan/StudioChannel/master/channel.json",
        "https://packagecontrol.io/channel_v3.json",
    ],
    • The https://raw.githubusercontent... line must to be added before the https://packagecontrol.io... one, otherwise, you will not install this forked version of the package, but the original available on the Package Control default channel https://packagecontrol.io...
  10. Now, go to the menu Preferences -> Package Control
  11. Type Install Package on the opened quick panel and press Enter
  12. Then, search for EvaluatePrinter and press Enter

See also:

  1. ITE - Integrated Toolset Environment
  2. Package control docs for details.

Motivation

You are writing some code and you are unsure if it does what you want? Is JavaScript's second parameter for String.prototype.slice the index of the last character? Or is it the amount of characters to slice? Does Python's reverse-method for lists return a reversed copy or does it modify the instance? Do you need these braces in your CoffeeScript code or are they optional?

Don't look this up in the documention! Don't open a shell, in which you replicate the code you already wrote! Stay in Sublime and just evaluate/transpile your code. With EvalPrinter.

Unlike a REPL, EvalPrinter does not only work with simple expressions but with entire blocks of code. Because you don't have to switch to another program, context switches are reduced und Sublime's usual text editing capabilities can be used, as well.

Additionally, the live session mode provides true immediate feedback which is completely missing in a REPL. The same applies for showing the results of transpilation processes.

Features

You can trigger the eval_print command to transpile/evaluate the current selection (or the current line if nothing is selected). The default keybinding is Shift + Alt + Enter. By default, the output will yield the result of the last expression. Additional output can be achieved via the standard logging methods of the current programming language (e.g. console.log in JavaScript and print in Python).

Another possibility is to enter a "live session", in which the code will be transpiled/evaluated after each keystroke. The immediate feedback makes it especially useful for tweaking code until it's perfect. The command is called eval_print_enter_live_session and the default keybinding is Ctrl/Cmd + Shift + Alt + Enter. Invoke it again to exit the mode.

For languages which will be transpiled (e.g. CoffeeScript), the output will also include the result of the transpilation process:

Supported languages

Currently, the following languages are supported:

  • JavaScript
  • CoffeeScript
  • Python

Feel free to open issues or submit pull requests to add support for other languages.

License

MIT © Philipp Otto 2014