jas-ho / SendCode

Send code and text to Terminal, iTerm, ConEmu, Cmder, tmux; R (RStudio), Julia, IPython/ptpython REPL

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

SendCode for Sublime Text

Send code and text to Terminal, ITerm, ConEmu, Cmder, Tmux; R (RStudio), Julia, IPython/ptpython REPL.

Following Programs are supported

  • Mac: Terminal, iTerm (>=2.9), R GUI, RStudio Desktop, RStudio and Jupyter running on Chrome and Safari
  • Windows: Cmder, ConEmu, R GUI, RStudio Desktop
  • Linux: Tmux, Screen, RStudio Desktop
  • Others: SublimeREPL

Installation

You could install SendCode via Package Control. If you are using Linux (Windows), the corresponding platform dependency xdotool (pywin32) will also be installed automatically.

Usage

Select a program using the command SendCode: Choose REPL Program in command palette. The default program is Terminal for Mac, Cmder for Windows and tmux for Linux.

  • cmd+enter (Mac) or ctrl+enter (Windows/Linux)

    If text is selected, it sends the text to the program selected. If no text is selected, then it sends the current block (if found). Finally, it moves the cursor to the next line.

  • cmd+\ (Mac) or ctrl+\ (Windows/Linux): change working directory (R, Julia and Python (IPython) only)

  • cmd+b (Mac) or ctrl+b (Windows/Linux): source current file (R, Julia and Python (IPython) only)

    SendCode uses Sublime build system to source files, you might have to choose the Source File option in a pop up window.

Troubleshooting

Important: For Python, IPython 5.0 or ptpython (or any repls which support bracketed paste mode) are assumed to be used. IPython 4.0 is still supported, but users need to disable bracketed_paste_mode in the settings.

Custom Keybind

It is fairly easy to create your own keybinds for commands which you frequently use. For example, the following keybind run the R command source("<the current file>") in the active program.

{
    "keys": ["super+shift+e"], "command": "send_repl",
    "args": {"cmd": "source(\"$file\")"},
    "context": [
        { "key": "selector", "operator": "equal", "operand": "source.r" }
    ]
}

SendCode understands the following variables in the cmd field:

  • $file, the full path to the file
  • $file_path, the directory contains the file
  • $file_name, the file name
  • $file_basename, the file name without extension
  • $file_extension, the file extension
  • $project_path, the active folder, if not found, use the directory of current file
  • $selection, the text selected, or the word under cursor
  • $line, the current line number

User settings

User settings should go into the user key in the SendCode.sublime-settings. For example

{
    "user":{
        "python" : {
            "prog": "terminal",
            "bracketed_paste_mode": true
        }
    }
}

Some details about block expansion

SendCode uses the following logic to expand cursor when sending text.

  • R blocks are detected by {,} pairs or knitr-spin #+ decorators.
  • Julia blocks are detected by begin, end pairs and indentations.
  • Python blocks are detected by indentations or by # %%/# In[] decorators.
  • Markdown fenced code of Markdown Extended and R Markdown is also supported.

About

Send code and text to Terminal, iTerm, ConEmu, Cmder, tmux; R (RStudio), Julia, IPython/ptpython REPL


Languages

Language:Python 86.4%Language:AppleScript 13.6%