Skip to content
This repository was archived by the owner on Mar 30, 2019. It is now read-only.

Files

Latest commit

e9ef3c0 · Jul 19, 2016

History

History
113 lines (79 loc) · 4.86 KB

README.old.md

File metadata and controls

113 lines (79 loc) · 4.86 KB

SendTextPlus for Sublime Text


Note

SendTestPlus will be deprecated soon in favour of SendREPL.


This package improves SendText, particularly for r, python and julia syntaxes (Note: IPython is assumed for python codes.). It supports

  • Mac: Terminal, iTerm (>=2.9), RStudio, R GUI, and Jupyter running on Chrome and Safari
  • Linux: gnome-terminal, screen, tmux and RStudio. xdotool is required for gnome-terminal and RStudio, it can be installed via apt-get install xdotool. As gnome-terminal doesn't accept keystrokes while it is not in focus, we need to switch focus temporarily to gnome-terminal in order to send the code.
  • Windows: Cmder (see below to configure Cmder), Cygwin, R32, R64 and RStudio. Due to an issue of RStudio (see RStudio and this), it doesn't accept the ctrl-enter key when there is no file opened, so make sure there is at least one (possibly untitled) source file opened.

Installation

Via Package Control.

Usage

Use the command SendText+: Choose Program in command palette to quickly change the active program. Terminal is the default 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 only)

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

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

Platform and syntax specific settings.

You can use different settings for different platforms and syntaxes by editing the default settings at Preferences -> Package Settings -> SendTextPlus. It understands platform and syntax specifications. The list of supported programs are

  • Mac: Terminal, iTerm, R, RStudio, Chrome-RStudio, Chrome-Jupyter, Safari-RStudio, Safari-Jupyter
  • Liniux: gnome-terminal, tmux, screen, RStudio
  • Windows: Cmder, Cygwin, R64, R32, RStudio
  • or SublimeREPL

Order matters, SendTextPlus will pick the first match out of the list.

For example:

{
    "user" : [
        {
            "platform": "osx",
            "scopes": ["source.r"],
            "prog": "RStudio",
        },
        {
            "platform": "osx",
            "scopes": ["source.python"],
            "prog": "Chrome-Jupyter",
            "remove_line_indentation": false
        },
        {
            "platform": "osx",
            "scopes": ["source.julia"],
            "prog": "Terminal",
            "bracketed_paste_mode": false
        }
    ]
}

Make sure [User] is selected in SendText+: Choose Program.

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. SendTextPlus 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

An example

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

Cmder settings

  • Go to Paste in the settings, uncheck, "Confirm keypress" and "Confirm pasting more than..."
  • Change the default paste all lines command from shift+insert to ctrl+shift+v. I actually posted an issue at Cmder about the default keybind.

Some details about block detection

  • R blocks are detected by {,} pairs.
  • 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.