Home Download Buy Blog Forum Support

PHP.tmLanguage text.html.basic scope

PHP.tmLanguage text.html.basic scope

Postby atomi on Thu Feb 14, 2013 11:30 pm

Does anyone know how exactly php files are scoped text.html.basic?

I believed that you would need to include the text.html.basic scope in the PHP.tmLanguage file like so:
Code: Select all
   <dict>
      <key>include</key>
      <string>text.html.basic</string>
   </dict>


But I don't see that anywhere in the base of the PHP.tmLanguage file.
I also see this bit in the comments:
Code: Select all
   <array>
      <!-- .php files are actually opened with HTML.tmLanguage, this is just a bit of trickery to make it look like PHP.tmLanguage is used to open them -->
      <string>php</string>
   </array>


So are .php files actually opened by HTML.tmLanguage and if so, how does this "trickery" work?
atomi
 
Posts: 342
Joined: Thu Jan 20, 2011 5:06 pm
Location: Los Angeles CA US

Re: PHP.tmLanguage text.html.basic scope

Postby sublimator on Fri Feb 15, 2013 2:02 am

The PHP grammar is included into the html grammar, much the same way it includes the javascript/css grammars.
It is better to remain silent and be thought a fool, than to speak out and remove all doubt
sublimator
 
Posts: 648
Joined: Thu Mar 20, 2008 5:41 am

Re: PHP.tmLanguage text.html.basic scope

Postby atomi on Fri Feb 15, 2013 7:23 am

Thanks.
I'm just confused as to how it's done exactly.

If you notice the bottom right of the status bar the syntax indicates it's "PHP".
When you take a look at the HTML.tmLanguage file it doesn't include PHP in the filetypes array element so it must be using the PHP.tmLanguage since the PHP.tmLanguage file contains php file type in filetypes array.How does Sublime know to use the HTML.tmLanguage instead?
atomi
 
Posts: 342
Joined: Thu Jan 20, 2011 5:06 pm
Location: Los Angeles CA US

Re: PHP.tmLanguage text.html.basic scope

Postby sublimator on Fri Feb 15, 2013 8:56 am

Good question.

Back in the old days of ST1, if you selected PHP it would actually show HTML, to the confusion of many.

atomi wrote:If you notice the bottom right of the status bar the syntax indicates it's "PHP".


It seems ST3 has restored this behaviour of showing HTML in the status bar rather than PHP.

Maybe the status bar is looking at the root scope? I know the context menu definitely has a `✔` next to PHP

And the following confirms it:
Code: Select all
>>> view.settings().get('syntax')
'Packages/PHP/PHP.tmLanguage'


atomi wrote:How does Sublime know to use the HTML.tmLanguage instead?


Not quite sure, but they both seem to include each other. I just took a look.

I guess `text.html.basic` is the root scope for either grammar the way it's set up
It is better to remain silent and be thought a fool, than to speak out and remove all doubt
sublimator
 
Posts: 648
Joined: Thu Mar 20, 2008 5:41 am

Re: PHP.tmLanguage text.html.basic scope

Postby sublimator on Fri Feb 15, 2013 9:00 am

BTW, the `fileTypes` array is not how a sub grammar is included.

G' probably has a nice intro that'll save you reading an unclarification from me: https://sublime-text-unofficial-documen ... xdefs.html

Back in the day, the TextMate wiki was useful: http://manual.macromates.com/en/language_grammars
It is better to remain silent and be thought a fool, than to speak out and remove all doubt
sublimator
 
Posts: 648
Joined: Thu Mar 20, 2008 5:41 am

Re: PHP.tmLanguage text.html.basic scope

Postby atomi on Fri Feb 15, 2013 9:43 am

Okay yea, the only conclusion I can come up with is that this behavior is special for PHP and probably hard coded somewhere in Sublime proper itself.

I don't mind so much not being able to do this for my own language files but I would like to be able to at least hide tmLanguage files from showing up in the status bar syntax context menu and command palette. I wasn't able to find any information on whether this was possible.
atomi
 
Posts: 342
Joined: Thu Jan 20, 2011 5:06 pm
Location: Los Angeles CA US


Return to Plugin Development

Who is online

Users browsing this forum: No registered users and 4 guests

cron