Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/math2001/package_setting_context
A Sublime Text plugin to be able to use plugin settings in key bindings' context.
https://github.com/math2001/package_setting_context
dependency package-control sublime-text
Last synced: 22 days ago
JSON representation
A Sublime Text plugin to be able to use plugin settings in key bindings' context.
- Host: GitHub
- URL: https://github.com/math2001/package_setting_context
- Owner: math2001
- License: mit
- Created: 2017-02-15T08:08:28.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2019-10-27T23:09:53.000Z (over 5 years ago)
- Last Synced: 2024-11-10T07:41:22.690Z (3 months ago)
- Topics: dependency, package-control, sublime-text
- Language: Python
- Size: 11.7 KB
- Stars: 0
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# package_setting_context
This "package" is a dependency for *your* package(s). It allows your users to enable/disable a key
binding by simply changing your package's settings. And all it requires you to do is to add:```json
"context": [
{ "key": "package_setting.SettingsFileName.setting_to_enable_this_key_binding" }
]
```That's it!
To make things clearer, here's when it's decomposed:
1. `package_setting.`: this prefix is needed and the exact same in every cases.
2. `SettingsFileName`: this part might be a bit more confusing. It the name of the setting file *without the extension* in which you write custom settings for the package. It usually is the same as the package name. It also usually have the extension `.sublime-settings`.
3. `setting_to_enable_this_key_binding`: simply the setting's name. It can be a bit more than that though, keep reading to get more :wink:## Overview
A `YourPackage.sublime-settings` file:
```json
{
"enabled_shortcut_my_super_command": true
}
``````json
[
{
"keys": ["ctrl+l"],
"command": "my_super_command",
"context": [
{ "key": "package_setting.YourPackage.enabled_shortcut_my_super_command" }
]
}
]
```And this shortcut will work. But if you set `YourPackage.sublime-settings`'s content to:
```json
{
"enabled_shortcut_my_super_command": false
}
```You guessed it: this key binding wouldn't work any more. Pretty handy, right?
## Further infos
In the overview's example, the `operator: equal` and `operand: true` is implicit, but you can of
course change it:```json
[
{
"keys": ["ctrl+l"],
"command": "my_super_command",
"context": [
{ "key": "package_setting.YourPackage.enabled_shortcut_my_super_command",
"operand": "not_equal",
"operator": "a string for example!"}
]
}
]
```The `key` is quiet clever too. Have a look:
In `Hello.sublime-settings`:
```json
{
"my_setting": {
"my_key": ["my", "list", {
"and": "it goes on and",
"on": true
}]
}
}
```And your key binding:
```json
[
{
"keys": ["ctrl+l"],
"command": "my_super_command",
"context": [
{ "key": "package_setting.SettingsFileName.my_setting.my_key.2.on"}
]
}
]
```And it works!
## How to use it
### If you want to use this in your package
If you want to use this feature in your *package*, just [add it as a dependency][]. So, for example
In your `dependencies.json`
```json
{
"*": {
"*": [
"package_setting_context"
]
}
}
```### If you want to use this in your regular keymap
What you can do is actually set this as a dependency to your `User` package. Create the file
`Packages/User/dependencies.json`, and set the same content as above[add it as a dependency]: https://packagecontrol.io/docs/dependencies