Hi,
After a lot of reading the documentation on textmate language bundles, grammar and scopes and regular expressions, I (just|finally) began making my own bundle for the cheetah templating language. My first post on this list is the following question: How can I name the scope from when I include an other language in my language bundle?
To explain this a bit: My quest comes forth out of an esthetic desire to color the background of embedded html in the cheetah template, just like the "Embedded source" scope 'text source, string.unquoted' can colorize the embedded javascript or css in a html document.
In my cheetah language grammar I have a pattern: { name = 'source.embedded.html'; include = 'text.html.basic'; }, But in the document, the scope (ctrl shft P) just says "source.cheetah", or "source.cheetah meta.tag.structure.any.html" when my caret is within a html tag. I don't see anything of that name 'source.embedded.html' reflected in the scope.
Is it possible to give an embedded (or included) language an extra scope layer name, so I can use that in a theme? I tried 'source.cheetah source.embedded.html' but that didn't do anything. For now I use 'source.cheetah meta', but that means I am missing a lot of non-cheetah-html stuff, like html comments, or (in html) embedded css or javascript.
I hope that my question is somewhat clear. thnx dirk
----------------------------- Dirk van Oosterbosch de Wittenstraat 225 1052 AT Amsterdam the Netherlands
http://labs.ixopusada.com -----------------------------
On 9/4/2006, at 15:22, Dirk van Oosterbosch, IR labs wrote:
[...] Is it possible to give an embedded (or included) language an extra scope layer name, so I can use that in a theme?
Not really. When you include another grammar, that rule (which performs the include) does not match anything itself, and so, there is nothing to assign a name to.
Normally an embedded language rule would look something like this:
{ name = 'source.embedded.php.html'; begin = '<?php'; end = '?>'; patterns = ( … ); }
Here the scope is clearly marked by having to start with <?php and end with ?>. In your case, there does not seem to be such clear markers, but instead, everything not matched by the cheetah grammar is “embedded.”
There are however ways in which you can likely achieve the desired effect. But I am not sure exactly how much you want to show as “embedded.” I.e. if you were able to add this extra scope name layer, then a line like: “that’s nice” would have the entity shown as embedded code, as it is matched by a rule included from the HTML grammar.
On 9-apr-2006, at 16:34, Allan Odgaard wrote:
On 9/4/2006, at 15:22, Dirk van Oosterbosch, IR labs wrote:
[...] Is it possible to give an embedded (or included) language an extra scope layer name, so I can use that in a theme?
Not really. [...] In your case, there does not seem to be such clear markers, but instead, everything not matched by the cheetah grammar is “embedded.”
Right. Maybe then what I am looking for is a scope selector which selects all the most specific (rightmost) scope names. I mean where 'source' selects all source.html, source.py source.whatever.comes.after etc, I would like to select all whatever.scopenames.that.ends.specific (e.g. 'variables.other.specific', 'keyword.control.specific' etc) by just something like '.specific'. That would allow me to select all the individually parsed cheetah stuff for instance, leaving the rest “embedded.” But I guess there isn't a '.specific-name-ending' -like selector, so I give up on this endeavor.
However, now I encountered an other problem: I have my bundle recognize cheetah placeholders (or 'variables'), which look like this: $placeholder or $placeholder.argument. But when I also have { include = 'text.html.basic'; } in my patterns the placeholders which are inside html tags (e.g. as arguments or values), are no longer recognized and become just 'string.quotes.double.html'. The text outside html tags stays unaffected, and thus placeholder.
As an example: <title>$currentPage.title</title> is perfectly parsed. The scope of '<title>' and '</title>' is "source.cheetah meta.tag.inline.any.html entity.name.tag.inline.any.html" and the scope of '$currentPage.title' is "source.cheetah variable.other.cheetah" However in: <meta name="author" content="$currentPage.author" /> the scope of '$currentPage.author' is "source.cheetah meta.tag.inline.any.html string.quotes.double.html", while I would like it to be "source.cheetah variable.other.cheetah" too. Only if I disable the include pattern it is recognized correctly. How can I make this variables.other.cheetah pattern take precedence over the { include = 'text.html.basic'; } pattern?
best, dirk
Sorry if this actually IS a new thread and I just made the universe collapse. oops. ----------------------------- Dirk van Oosterbosch de Wittenstraat 225 1052 AT Amsterdam the Netherlands
http://labs.ixopusada.com -----------------------------
On 10/4/2006, at 1:02, Dirk van Oosterbosch, IR labs wrote:
[...] I have my bundle recognize cheetah placeholders (or 'variables'), which look like this: $placeholder or $placeholder.argument. But when I also have { include = 'text.html.basic'; } in my patterns the placeholders which are inside html tags (e.g. as arguments or values), are no longer recognized and become just 'string.quotes.double.html'. The text outside html tags stays unaffected, and thus placeholder.
Yes -- the rules you declare are at the root level. So when the (included) HTML grammar starts a sub-context, your rules will not be applied.
A better approach would be to duplicate the existing HTML grammar and locate the “ embedded-code” rule. Here add another rule to include cheetah. The HTML grammar re-uses this “embedded-code” rule in most of the contexts where embedded code makes sense.
You will then have to select this (duplicated and modified) HTML grammar for your cheetah files, instead of selecting cheetah.
Long term I plan to do something akin to activate the scope selector text field for language grammars (and allow UTI’s/file types to be targeted by scope selectors). Then one would be able to set a scope selector for a language grammar, which would basically be where this grammar should be “injected” (which could be in multiple places/for different file types.) But this is post 2.0, so for now one is stuck with just editing the language grammar in which the injection should take place.
Allan,
A better approach would be to duplicate the existing HTML grammar and locate the “ embedded-code” rule. Here add another rule to include cheetah. The HTML grammar re-uses this “embedded-code” rule in most of the contexts where embedded code makes sense.
You will then have to select this (duplicated and modified) HTML grammar for your cheetah files, instead of selecting cheetah.
Would it not be better to create a “subclass” of the HTML language grammar and just add the “embedded-code” rule as well as an include of the original HTML grammar?
(But then I guess the HTML grammar will not change that much so it is not necessary to maintain easy updatability?)
Dan
On 10/4/2006, at 12:09, Daniel Käsmayr wrote:
You will then have to select this (duplicated and modified) HTML grammar for your cheetah files, instead of selecting cheetah.
Would it not be better to create a “subclass” of the HTML language grammar and just add the “embedded-code” rule as well as an include of the original HTML grammar? [...]
If it was possible, yes.
But the embedded-code rule is a “repository” rule which is included by a lot of other HTML rules, e.g. to allow embedded code in tag attribute values (strings), and similar.
So presently there is no way to override it, other than actually edit the grammar.