Hi,
In JavaScript I would like every instance of the word "self" and "parent" to be orange except when they appear as "window.self" or "window.parent". How can I specify these. What I have so far is...
{ name = 'window.js'; match = '\bwindow.self\b'; },
(Which is wrong, of course.)
Thanks for any help!
Peter
On 1. Mar 2007, at 21:32, Peter Michaux wrote:
In JavaScript I would like every instance of the word "self" and "parent" to be orange except when they appear as "window.self" or "window.parent". How can I specify these. What I have so far is...
Instead of one rule, make two:
{ match = '\b(window).(this|parent)\b'; captures = { 1 = { name = 'support.class.js'; }; 2 = { name = 'variable.language.this-or-parent.js'; }; }; }, { name = 'variable.language.js'; match = '\b(super|this|parent)\b'; }
The first one explicitly matches window.this and window.parent. This and parent is still marked up as variable.language, so with no theme modifications, it will show the same.
But you can now style all but window.(this|parent) using a scope selector of:
variable.language - variable.language.this-or-parent
Likewise you can style just window.(this|parent) with:
variable.language.this-or-parent
Hi Allan,
Thanks very much for the response. I tried it and fiddled with it a lot but I couldn't get this working.
On 3/1/07, Allan Odgaard throw-away-1@macromates.com wrote:
On 1. Mar 2007, at 21:32, Peter Michaux wrote:
In JavaScript I would like every instance of the word "self" and "parent" to be orange except when they appear as "window.self" or "window.parent". How can I specify these. What I have so far is...
Instead of one rule, make two:
{ match = '\b(window)\.(this|parent)\b'; captures = { 1 = { name = 'support.class.js'; }; 2 = { name = 'variable.language.this-or-parent.js'; }; }; },
If I try the above rule alone (no other matches in the whole language file) it doesn't seem to work as a way to capture the "this" and "parent" words. I can't style them with the following in the preferences scope selector.
"variable.language.this-or-parent.js".
Did the above work for you?
{ name = 'variable.language.js'; match = '\b(super|this|parent)\b'; }
The first one explicitly matches window.this and window.parent. This and parent is still marked up as variable.language, so with no theme modifications, it will show the same.
But you can now style all but window.(this|parent) using a scope selector of:
variable.language - variable.language.this-or-parent
WOW! it is possible to subtract scopes? That is very cool!
Likewise you can style just window.(this|parent) with:
variable.language.this-or-parent
By the way, I just spent two days trying to learn VIM for a work situation. What a waste of my time. I think it would take me a year of plugin programming to get VIM to a state of productivity not quite matching Textmate. Textmate is a far better solution.
Thanks, Peter
On 2. Mar 2007, at 09:39, Peter Michaux wrote:
Instead of one rule, make two:
{ match = '\b(window)\.(this|parent)\b'; captures = { 1 = { name = 'support.class.js'; }; 2 = { name = 'variable.language.this-or-parent.js'; }; }; },
If I try the above rule alone (no other matches in the whole language file) it doesn't seem to work as a way to capture the "this" and "parent" words.
You mean it does not match them stand-alone (cause it shouldn’t, i.e. not the rule above), or it doesn’t match them when part of ‘window.this’ or ‘window.parent’?
[...] Did the above work for you?
I just pasted the above rule into the current JavaScript grammar (as the first rule) and if I press ⌃⇧P on ‘this’ or ‘parent’, when used after ‘window.’ it does show that they get correctly matched. So yes, it works for me.
Be sure to close the bundle editor after making a change to a grammar, to ensure it updates the various buffers.
Hi Allan,
Thanks. It all works now. I didn't know about ⌃⇧P and that made it much faster to debug my problems.
Thanks again, Peter
On 3/2/07, Allan Odgaard throw-away-1@macromates.com wrote:
On 2. Mar 2007, at 09:39, Peter Michaux wrote:
Instead of one rule, make two:
{ match = '\b(window)\.(this|parent)\b'; captures = { 1 = { name = 'support.class.js'; }; 2 = { name = 'variable.language.this-or-parent.js'; }; }; },
If I try the above rule alone (no other matches in the whole language file) it doesn't seem to work as a way to capture the "this" and "parent" words.
You mean it does not match them stand-alone (cause it shouldn't, i.e. not the rule above), or it doesn't match them when part of 'window.this' or 'window.parent'?
[...] Did the above work for you?
I just pasted the above rule into the current JavaScript grammar (as the first rule) and if I press ⌃⇧P on 'this' or 'parent', when used after 'window.' it does show that they get correctly matched. So yes, it works for me.
Be sure to close the bundle editor after making a change to a grammar, to ensure it updates the various buffers.