Home Download Buy Blog Forum Support

Selector on a keybind

Selector on a keybind

Postby spadgos on Thu Jan 12, 2012 10:37 am

I'm trying to write a keybinding that will only happen if the current context is a string, but this doesn't work:

Code: Select all
{ "keys": ["ctrl+'"], "command": "toggle_quotes", "context":
        [
            { "key": "selector", "operator": "regex_contains", "operand": "string"}
        ]
    }


Even stranger is that a "match everything" regex doesn't even work:

Code: Select all
{ "keys": ["ctrl+'"], "command": "toggle_quotes", "context":
        [
            { "key": "selector", "operator": "regex_contains", "operand": ".*"}
        ]
    }


What am I doing wrong here?
spadgos
 
Posts: 121
Joined: Thu Oct 06, 2011 12:49 am

Re: Selector on a keybind

Postby sublimator on Thu Jan 12, 2012 4:32 pm

something like this:
Code: Select all
"context": [
{
  "operand": "string",
  "operator": "equal",
  "match_all": true,
  "key": "selector"
}]


`selector == string`
It is better to remain silent and be thought a fool, than to speak out and remove all doubt
sublimator
 
Posts: 649
Joined: Thu Mar 20, 2008 5:41 am

Re: Selector on a keybind

Postby spadgos on Sun Jan 15, 2012 2:58 pm

Ah okay that worked, thanks!

I guess I don't really understand how that scope thing works then...
spadgos
 
Posts: 121
Joined: Thu Oct 06, 2011 12:49 am

Re: Selector on a keybind

Postby C0D312 on Sun Jan 15, 2012 3:46 pm

I think I can help explain...

Selector: refers to the name of the scope as defined by the tmLanguage. The tmLanguage assigns names to different regular expressions. The tmTheme then uses these selectors to assign colors to particular scopes. You can see the selector at the cursor using the command: show_scope_name.

Therefore, saying "selector contains .*" is backwards since "selector" is returning the name of the scope itself.
Alternatively, you could say "Preceding Text regex contains .*" because preceding_text is returning the text before the cursor.

In the context field:

- selector can be equal or not_equal.
- Preceding_text/following_text/text can be regex_match, regex_contains, not_regex_contains

I feel like a list of all the available options needs to be spelled out somewhere. It may be in AAAPackageDev, or maybe sublimetext.info, if it's not it should be.
C0D312
 
Posts: 1063
Joined: Sun Jul 10, 2011 3:23 am


Return to Plugin Development

Who is online

Users browsing this forum: No registered users and 7 guests

cron