Giter Site home page Giter Site logo

hafen / sendtextplus Goto Github PK

View Code? Open in Web Editor NEW

This project forked from randy3k/sendtextplus

0.0 2.0 0.0 2.34 MB

An improved SendText plugin for Sublime Text. Send text to various programs. Works with R, Python and Julia

License: MIT License

JavaScript 22.96% AutoHotkey 5.79% Python 71.26%

sendtextplus's Introduction

SendTextPlus for Sublime Text

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

  • Mac: Terminal, iTerm, 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 a strange behavior of RStudio, it doesn't accept the ctrl-enter key when there is no source file, so make sure there is at least one (possibly untitled) source file opened.
  • SublimeREPL for R and python syntaxes (it works better with R)

Terminal is the default for Mac, Cmder for Windows and tmux for Linux. Use the command SendText+: Choose Program in command palette to quickly change the active program.

Installation

Via Package Control.

Usage

  • 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

An example:

{
    "defaults" : [
        {
            "platform": "osx",
            "scopes": ["source.r"],
            "prog": "RStudio"
        },
        {
            "platform": "osx",
            "scopes": ["source.python", "source.julia"],
            "prog": "Chrome-Jupyter"
        },
        {
            "platform": "osx",
            "prog": "Terminal"
        },
        {
            "platform": "windows",
            "prog": "Cmder"
        },
        {
            "platform": "linux",
            "prog": "tmux"
        }
    ]
}

Make sure [Defaults] 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.

sendtextplus's People

Contributors

randy3k avatar devjit avatar fdm1 avatar leakymirror avatar yueatwork avatar

Watchers

Ryan Hafen avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.