Home Download Buy Blog Forum Support

"text" in context doesn't work

"text" in context doesn't work

Postby demon386 on Wed Jun 27, 2012 4:39 pm

Let's say I want the "tab" to act as "set mark" when "#" is contained in the text of the current line.

I set the following key bindings:
{ "keys": ["tab"], "command": "set_mark", "context":
[
{ "key": "text", "operator": "regex_contains", "operand": "#" }
]
}

It doesn't work. Yet if I change "text" to "following_text" and put the caret before the "#", it works.

What's the problem?

In addition, anyone can dell me the difference between "regex_match" and "regex_contains"?
demon386
 
Posts: 13
Joined: Sun Jun 10, 2012 1:52 pm

Re: "text" in context doesn't work

Postby agibsonsw on Wed Jun 27, 2012 7:57 pm

I don't know the answer unfortunately, but it might be worth escaping the "\\#". Alternatively, I would explore "regex_match" with "match_all": false; e.g.

Code: Select all
{ "key": "following_text", "operator": "regex_match", "operand": "^$", "match_all": true }

I'm only guessing :?: but I assume "regex_contains" is equivalent to a global modifier/global search of the line; whereas a match requires a precise, consecutive, match.

I apologise if this info is unhelpful. Andy.
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
agibsonsw
 
Posts: 901
Joined: Fri Jan 27, 2012 9:11 pm

Re: "text" in context doesn't work

Postby demon386 on Thu Jun 28, 2012 2:24 am

Thanks. But match_all is false by default. And following_text works anyway. It's "text" that doesn't work.

As the documentation (http://docs.sublimetext.info/en/latest/reference/key_bindings.html) said, "text" means "Restricts the test to the line the caret is in.".

But in my case it doesn't work as intended and I don't know why.

agibsonsw wrote:I don't know the answer unfortunately, but it might be worth escaping the "\\#". Alternatively, I would explore "regex_match" with "match_all": false; e.g.

Code: Select all
{ "key": "following_text", "operator": "regex_match", "operand": "^$", "match_all": true }

I'm only guessing :?: but I assume "regex_contains" is equivalent to a global modifier/global search of the line; whereas a match requires a precise, consecutive, match.

I apologise if this info is unhelpful. Andy.
demon386
 
Posts: 13
Joined: Sun Jun 10, 2012 1:52 pm

Re: "text" in context doesn't work

Postby demon386 on Thu Jun 28, 2012 3:33 pm

I guess I've figured out the difference between regex_contains and regex_match.

regex_match has to be matched against exactly the whole line.

So if the line is "aabb", and the regex_match is "aab", this won't be a match.

Yet regex_contains would match in this case.

Another example, "\\d+" won't "regex_match" "11a",

yet "regex_contains" would match.



I haven't figured out the problem of "text", I guess the problem has something related to precedence of keybinding context rules.
demon386
 
Posts: 13
Joined: Sun Jun 10, 2012 1:52 pm

Re: "text" in context doesn't work

Postby jps on Sat Jun 30, 2012 7:36 am

The "text" context refers to the selected text, rather than the current line
jps
Site Admin
 
Posts: 3077
Joined: Wed Mar 19, 2008 12:33 pm


Return to Plugin Development

Who is online

Users browsing this forum: No registered users and 3 guests