Skip to content

nafeu/TextTransmute

master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.

TextTransmute

An experimental Sublime Text plugin that allows you to mutate selected text in a style inspired by VIM, Emacs macros and unix shell programming tools.

Build Status

How It Works

  1. Select some text
  2. Select the transmutation(s) you want to perform
  3. Watch the text magically change
  4. Realize some transmutations don't even need inputs at all
  5. Channel your inner alchemist

Features

  • Use a collection of customizable sublime commands to mutate and contextually modify text. Some notable things include:
    • Performing HTTP GET/POST requests right inside your text editor (useful for testing REST APIs)
    • Converting selected text from markdown to html
    • Quick multi line formatting with swap, dupl, expand, compress, filter, and strip
  • Piping using the | character is supported and inspired by stdin/stdout mechanics of a unix shell
  • Use knowledge of python to quickly write a command that helps simplify repetitive coding tasks
  • Create aliases that run a common/useful sequence of piped commands

Requirements

Sublime Text 3, Python 3.3 and above

Installation

Clone this repository into your Sublime Text Packages folder under the directory name TextTransmute

cd Sublime\ Text\ 3/Packages
git clone https://github.com/nafeu/TextTransmute.git TextTransmute

Usage

Default Key Bindings:

Command OSX Linux/Windows
Perform Transmutation ctrl + shift + j ctrl + k, j
Use Alias ctrl + shift + h ctrl + k, h

All available Sublime Commands:

Perform Transmutation
Use Alias
History
Edit/Add Aliases
Edit Key Bindings
Edit/Add Custom Commands

Currently Available Transmutation Commands (more to come)

[] - Mandatory, () - Optional

Name / Synopsis Description
http [method] (url) (key_1) (val_1) ... (key_n) (val_n) Perform http requests
markdown (indentation amount) Parse markdown into html
swap [old string] [new string] Swap matched strings with a new string
expr Evaluate simple expressions
mklist [#/a-z] [#/a-z] (--close) (--place=[string including {$}]) Generate alphabetized or numeric lists
dupl (n) (--close) Duplicate selection n times
strip [string] Strip a matched string out of a selection
expand (n) Add an empty whitespace between lines n times
compress Compress multiple lines into one line
filter [string] Filter for lines that contain a specific string
map (file extension) Convert whitespace seperated words into language specific map (hashmap, dict, json, etc)

Creating Custom Transmutation Commands

Lets say we want to make a command called Foo

  1. Open command palette (cmd + shift + p on OSX, ctrl + shift + p on Linux/Windows) and run TextTransmute: Edit/Add Custom Commands

  2. Create a new class inheriting from Transmutation like so:

class Foo(Transmutation):
    """Convert selected text to 'bar'"""
    ...
  1. Foo or foo is how your command will be invoked, it must be ONE WORD for the plugin to add it to the command library

  2. Add the transmute(self, body=None, params=None) method to your class like so:

class Foo(Transmutation):
    """Convert selected text to 'bar'"""

    def transmute(self, body=None, params=None, meta=None):
        ...

The transmute method will be called on the body of text you have selected. To learn about the params argument, observe the base Transmutation class found inside Packages/TextTransmute/commands.py

  1. Return a string in your transmute method, this is what you'll be mutating your selected text into
class Foo(Transmutation):
    """Convert selected text to 'bar'"""

    def transmute(self, body=None, params=None, meta=None):
        return "bar"
  1. Define a test for your command (definitely a more comprehensive one than the following example)
class TestFoo(unittest.TestCase):
    """Unit test for Foo command"""

    def setUp(self):
        self.t = Foo()

    def test_default(self):
        self.assertEqual(self.t.transmute(), "bar")
        self.assertEqual(self.t.transmute("Foo"), "bar")
  1. Run tests using python runtests.py

Editing Aliases

  1. Open command palette (cmd + shift + p on OSX, ctrl + shift + p on Linux/Windows) and run TextTransmute: Edit/Add Aliases

  2. Insert or update an alias in the specified format with Description and Command sequence

ALIASES = [

  ["Generate a list from 1 to 10", "gen -s {$}. 1 10"],
  ["Evaluate this expression", "expr"],
  # ["Description", "Command sequence"],

]

Running the tests

Manually:

If system is running Python 3 use:

python runtests.py

Otherwise use:

python3 runtests.py

Autorun tests on file change:

Use the included gulpfile to autorun tests anytime a .py file is changed:

npm install
gulp test-py

Use gulp test-py3 to enforce Python 3

Development

OSX/Linux:

cd Sublime\ Text\ 3/Packages\TextTransmute
pip3 install -r requirements.txt

TODO: Add Windows dev instructions...

License

MIT

About

An experimental Sublime Text 3 plugin that allows you to mutate selected text in a style inspired by VIM, Emacs and unix shell programming tools.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published