Skip to main content

A convenient DSL for generating SublimeText configs.

Project description

Build Status Coverage Status Code Climate version downloads documentation

The configuration of Sublime Text uses verbose JSON files, XML files, and also horrible PList/XML files (TextMate legacy). When used in plugins, some of them (e.g. keymaps) may contain even hundreds of lines with huge ratio of duplications. Sooner or later, it’ll become quite hard to maintain such a mess.

The aim of this module is to provide simple pythonic DSL for generating particular configuration files. Currently only Key Bindings are supported, but other configs may come later.

You’re more than welcome to add DSL for other Sublime Text’s configs!

Usage

Examples

#!/usr/bin/env python3
from sublimedsl.keymap import *

Keymap(
    bind('backspace')
        .to('run_macro_file', file='res://Packages/Default/Delete Left Right.sublime-macro')
        .when('setting.auto_match_enabled').any().true()
        .also('preceding_text').regex_contains(r'_$')
        .also('following_text').regex_contains(r'^_'),

    bind('super+k', 'super+shift+up')
        .to('new_pane', move=False),

    common_context=[
        context('selector').equal('text.asciidoc')
    ],
    default_match_all=True

).dump()

The above code generates:

[
  {
    "keys": [ "backspace" ],
    "command": "run_macro_file",
    "args": { "file": "res://Packages/Default/Delete Left Right.sublime-macro" },
    "context": [
      { "key": "setting.auto_match_enabled", "operator": "equal", "operand": true, "match_all": false },
      { "key": "preceding_text", "operator": "regex_contains", "operand": "_$", "match_all": true },
      { "key": "following_text", "operator": "regex_contains", "operand": "^_", "match_all": true },
      { "key": "selector", "operator": "equal", "operand": "text.asciidoc", "match_all": true }
    ]
  },
  {
    "keys": [ "super+k", "super+shift+up" ],
    "command": "new_pane",
    "args": { "move": false },
    "context": [
      { "key": "selector", "operator": "equal", "operand": "text.asciidoc", "match_all": true }
    ]
  }
]

You can also look at real-world example in the Asciidoctor plugin: Keymap DSL and generated JSON.

Installation

System-wide

Install from PyPI system-wide:

sudo pip install sublimedsl

…or manually:

git clone git@github.com:jirutka/sublimedsl.git
cd sublimedsl
sudo ./setup.py install

Locally

If you don’t have a root access to the system, or just don’t want to install sublimedsl system-wide, then you can tell pip or setup.py to install it into your home directory (namely ~/.local):

pip install --user sublimedsl

…or manually:

git clone git@github.com:jirutka/sublimedsl.git
cd sublimedsl
./setup.py --user install

License

This project is licensed under MIT license.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sublimedsl-0.3.2.tar.gz (6.6 kB view details)

Uploaded Source

File details

Details for the file sublimedsl-0.3.2.tar.gz.

File metadata

  • Download URL: sublimedsl-0.3.2.tar.gz
  • Upload date:
  • Size: 6.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for sublimedsl-0.3.2.tar.gz
Algorithm Hash digest
SHA256 672f97ffaf4f93de73efc935459f15fd926ec65c44b020c39ce28669452d62bf
MD5 539440cf27e097e1f1d1aefa910462fa
BLAKE2b-256 8a1b1a70a36634988d61eaeb0544a1f869f780076f30d4ec402d1b496f77d4f5

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page