<commit_before># ★ SublimeMagic

A magic command for sublime. Create a spellbook, cast spells on your code, make magic happen.

## What?

SublimeMagic provides a `sublime_magic` command, which looks through user-defined actions and performs the first matching one.

## Set your spell hotkey!

The plugin comes without default key bindings. To use the plugin, you have to bind the `sublime_magic` command.

Regular example:

```json
{
  "keys": ["ctrl+,"],
  "command": "sublime_magic"
}
```

Vintageous example:

```json
{
  "keys": [" ", " "],
  "command": "sublime_magic",
  "context": [{ "key": "vi_command_mode_aware" }]
}
```


## Create your spellbook!

The spellbook (your sublime-settings file) consists of a single `spells` array containing the user-defined spells:

```json
{
  "spells": []
}
```

The spells are iterated one-by-one and the first one matching the `context` conditions is casted. When there's no spell matching, nothing happens. When there are multiple matching spells, only the top-most one is performed.

## Spell

Each spell consists of the following required fields:

- `name` is the human readable name of your spell
- `spell` is the spell code, see ["Available spells" for a list of spells](#available-spells)
- `args` specific to the selected spell

Spells can be limited by settings a `context` (similar to key bindings, though not using the same syntax). Known context keys:

- `scope` - an array of required scope names (using regexp) - all patterns must match 
- `line_matches` - an array of patterns that the current line must match
- more to come - make a PR :)

### Spell example

```json
{
  "name": "Replace single quoted content with clipboard",
  "context": {
    "scope": ["string\\.quoted\\.single"]
  },
  "spell": "replace_text",
  "args": {
    "where": "inside",
    "delimiter": "'",
    "replacement": "$clipboard"
  }
}
```

## Available spells

- [replace_text](docs/spells/replace_text.md)
- [perform_line_regex](docs/spells/perform_line_regex.md)
- [toggle_values](docs/spells/toggle_values.md)
- more to come - make a PR :)

## Example spellbook

```json
{
  "spells": [
    {
      "name": "Replace single quoted content with clipboard",
      "context": {
        "scope": ["string\\.quoted\\.single"]
      },
      "spell": "replace_text",
      "args": {
        "where": "inside",
        "delimiter": "'",
        "replacement": "$clipboard"
      }<commit_msg>add example spellbook link<commit_after># ★ SublimeMagic

A magic command for sublime. Create a spellbook, cast spells on your code, make magic happen.

## What?

SublimeMagic provides a `sublime_magic` command, which looks through user-defined actions and performs the first matching one.

## Set your spell hotkey!

The plugin comes without default key bindings. To use the plugin, you have to bind the `sublime_magic` command.

Regular example:

```json
{
  "keys": ["ctrl+,"],
  "command": "sublime_magic"
}
```

Vintageous example:

```json
{
  "keys": [" ", " "],
  "command": "sublime_magic",
  "context": [{ "key": "vi_command_mode_aware" }]
}
```


## Create your spellbook!

The spellbook (your sublime-settings file) consists of a single `spells` array containing the user-defined spells:

```json
{
  "spells": []
}
```

The spells are iterated one-by-one and the first one matching the `context` conditions is casted. When there's no spell matching, nothing happens. When there are multiple matching spells, only the top-most one is performed.

## Spell

Each spell consists of the following required fields:

- `name` is the human readable name of your spell
- `spell` is the spell code, see ["Available spells" for a list of spells](#available-spells)
- `args` specific to the selected spell

Spells can be limited by settings a `context` (similar to key bindings, though not using the same syntax). Known context keys:

- `scope` - an array of required scope names (using regexp) - all patterns must match 
- `line_matches` - an array of patterns that the current line must match
- more to come - make a PR :)

### Spell example

```json
{
  "name": "Replace single quoted content with clipboard",
  "context": {
    "scope": ["string\\.quoted\\.single"]
  },
  "spell": "replace_text",
  "args": {
    "where": "inside",
    "delimiter": "'",
    "replacement": "$clipboard"
  }
}
```

## Available spells

- [replace_text](docs/spells/replace_text.md)
- [perform_line_regex](docs/spells/perform_line_regex.md)
- [toggle_values](docs/spells/toggle_values.md)
- more to come - make a PR :)

## Example spellbook

Have a nice spellbook? Create a pull request and let me add a link here!

Spellbooks:
+ [mreq](https://github.com/mreq/dotfiles/blob/master/subl/Packages/User/SublimeMagic.sublime-settings)

A simple example:

```json
{
  "spells": [
    {
      "name": "Replace single quoted content with clipboard",
      "context": {
        "scope": ["string\\.quoted\\.single"]
      },
      "spell": "replace_text",
      "args": {
        "where": "inside",
        "delimiter": "'",
        "replacement": "$clipboard"
      }
{'fraction_non_alphanumeric': 0.13305736250739209, 'fraction_numerical': 0.0, 'mean_word_length': 3.72, 'pattern_counts': {'":': 48, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2029635', 'n_tokens_mistral': 1630, 'n_tokens_neox': 1566, 'n_words': 563}