ctrl+shift+p filters: :st2 :st3 :win :osx :linux
Browse

Send​Code

by randy3k ST3

Send code and text to macOS and Linux Terminals, iTerm, ConEmu, Cmder, Tmux, TerminalView; R (RStudio), Julia, IPython.

Details

Installs

  • Total 8K
  • Win 3K
  • OS X 4K
  • Linux 1K
Aug 20 Aug 19 Aug 18 Aug 17 Aug 16 Aug 15 Aug 14 Aug 13 Aug 12 Aug 11 Aug 10 Aug 9 Aug 8 Aug 7 Aug 6 Aug 5 Aug 4 Aug 3 Aug 2 Aug 1 Jul 31 Jul 30 Jul 29 Jul 28 Jul 27 Jul 26 Jul 25 Jul 24 Jul 23 Jul 22 Jul 21 Jul 20 Jul 19 Jul 18 Jul 17 Jul 16 Jul 15 Jul 14 Jul 13 Jul 12 Jul 11 Jul 10 Jul 9 Jul 8 Jul 7 Jul 6
Windows 0 1 8 9 4 4 7 4 2 5 15 11 14 9 4 6 6 3 3 3 3 6 7 10 4 8 6 9 1 1 4 3 6 7 9 2 2 3 13 7 1 9 1 4 6 2
OS X 0 4 4 8 8 5 7 4 1 8 10 10 5 6 1 1 4 6 10 0 3 4 0 1 3 4 5 2 5 2 4 7 3 6 6 0 2 4 5 3 1 6 8 8 3 8
Linux 0 4 2 1 3 3 1 0 3 4 5 5 3 0 0 4 3 2 8 2 3 2 0 1 2 1 1 1 2 1 2 3 1 3 0 3 3 2 5 4 3 2 0 3 4 3

Readme

Source
raw.​githubusercontent.​com

SendCode for Sublime Text


SendCode v0.3.x

SendCode no longer defines the keybinds for change working directory. User should define their own keybinds in the user settings.


Send code and text to macOS and Linux Terminals, iTerm, ConEmu, Cmder, Tmux, TerminalView; R (RStudio), Julia, IPython.

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, Gnome-Terminal, Pantheon-Terminal, Mate-Terminal, Konsole, RStudio Desktop
  • Others: TerminalView (requires v0.5.0 or above), SublimeREPL (deprecating)

Installation

You could install SendCode via Package Control. If you are using Linux, the respective platform dependency xdotool will also be installed automatically.

Usage

Select a program using the command SendCode: Choose Program in command palette. The default program on macOS, windows and linux are Terminal, Cmder and tmux respectively.

  • 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+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

  1. Python console

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.

  1. RStudio on Windows

If the code is pasted on the console but it is not being executed, you need to open an empty RScript file from the menu File -> New File -> R Script. This is a quick fix to a RStudio issue on Windows.

  1. R Gui on Windows

Make sure the corresponding R program is opened when you are sending the text.

  1. Cmder/ Conemu on Windows

You might need to set the path to ConEmuC.exe in SendCode settings. For Cmder, the file is located at <path to cmder folder>\\vendor\\conemu-maximus5\\ConEmu\\ConEmuC.exe.

  1. Safari-Jupyter on macOS

Most likely you haven't enabled JavaScript for AppleScript. Check the option “Allow JavaScript from Apple Events” in the Develop menu (the develope menu needs to be enabled in the preferences).

Custom Keybinds

It is fairly easy to create your own keybinds for commands which you frequently use. For example, the following keybinds execute changing working directory commands for R, Python and Julia.

[
    {
        "keys": ["ctrl+shift+h"], "command": "send_code",
        "args": {"cmd": "setwd(\"$file_path\")"},
        "context": [
            { "key": "selector", "operator": "equal", "operand": "source.r" }
        ]
    },
    {
        "keys": ["ctrl+shift+h"], "command": "send_code",
        "args": {"cmd": "%cd \"$file_path\""},
        "context": [
            { "key": "selector", "operator": "equal", "operand": "source.python" }
        ]
    },
    {
        "keys": ["ctrl+shift+h"], "command": "send_code",
        "args": {"cmd": "cd(\"$file_path\")"},
        "context": [
            { "key": "selector", "operator": "equal", "operand": "source.julia" }
        ]
    }
]

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

A couple of settings can be found Preferences: SendCode Settings

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 blocks of Markdown Extended and R Markdown are also supported.