Sublime Forum

PHP.tmLanguage text.html.basic scope

#1

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:

	<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:

	<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?

0 Likes

#2

The PHP grammar is included into the html grammar, much the same way it includes the javascript/css grammars.

0 Likes

#3

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?

0 Likes

#4

Good question.

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

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:

>>> view.settings().get('syntax') 'Packages/PHP/PHP.tmLanguage'

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

0 Likes

#5

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: sublime-text-unofficial-documen … xdefs.html

Back in the day, the TextMate wiki was useful: manual.macromates.com/en/language_grammars

0 Likes

#6

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.

0 Likes