Sublime Forum

Scope problem and syntax highlighting

#1

Hi guys,

I work a lot with ST3 that I discovered not too long ago. I spent some time making my own Monokai PHP theme, using Scope Hunter, and which you can donwload here : http://pixelshaped.com/vrac/MonokaiPHP.tmTheme if you want to.

I still have some issues with detecting PHP inside HTML, and Scope Hunter is not helping me for that one :


Edit: Here is the plain text code you can copypaste to reproduce the issue pastebin.com/xmTnyjDj (in a .php file)

As you can see, PHP tags are nested into a CDATA tag in a XML file. Sublime can’t seem to see that I happen to open my PHP brackets in the middle. Can it be fixed ?

Thank you !

0 Likes

#2

If people reporting this type of problems, don’t post their code, the person testing or trying to fix this, should type everything, and disencourage trying to investigate the problem. So, post the code, for an easy copy and paste.

0 Likes

#3

Hi !

You’re right ! I’ve edited my message to let people copypaste easily this small snippet of code !

In the meantime, I’ve had another issue with syntax highlighting :


Here is the code to copypaste : pastebin.com/WrwtQvrS (in a .php file)

We can see that in a php file containing HTML and JS, PHP tags put inside a JS string are not detected. Can this issue be fixed ? The scope hunter when I put my cursor between <?php and ?> gives “text.html.basic meta.tag.script.html source.js.embedded.html string.quoted.single.js” which seems to indicate that Sublime Text has no idea that php tags are present.

Thank you !

0 Likes

#4

Anyone please ? :wink:

0 Likes

#5

Can’t believe people have never crossed this issue before. There must be a simple solution ! :neutral_face:

0 Likes

#6

Quotes and other scopes like Cdata seems to have higher importance over all the others, you get the same result if you try something like:

<?php
$foo = '<div class="baz">bar</bar>';
?>

the html tags wont be highlighted as such, 'coz actually it’s a quoted text string.

In your examples you are actually inside a quoted text in a javascript function or inside a CDATA in a piece of xml/xhtml.

To me the highlight is working “as expected”, i’ll be surprised to see a quoted string with some part highlighted in different colors, doing so will lower the readability a lot imho…

hope it helps :wink:

0 Likes

#7

I really don’t think the fact PHP tags remain undetected in some HTML strings should be considered “a feature”.

Here is what the same snippet looks like in NPP (for example, but same behavior happens in other editors like Webstorm) :


Line 6, in ST3, the line is barely readable : single-quotes from PHP close a string that has been opened outside that language and it doesn’t make any sense.

I think PHP tags detection should happen in everything (because, well, that is just the way the PHP interpretor works).

0 Likes

#8

You can manually do this by editing the PHP.tmLanguage (or HTML.tmLanguage - they are tightly linked afaik) syntax definition files. You should probably rename them as well and put them into the User package.

For syntax definitions, docs.sublimetext.info/en/sublime … xdefs.html is a very good entry point and should also explain how to dig into the languag definitions. What you should aim to do is adding some - include: source.php lines where strings and cdata are defined.

0 Likes

#9

Thanks for your valuable input !

Although I can find tmLanguage files in my ST2 directory, I can’t find any in my ST3 directory (user/Sublime Text 3/packages), except files apparently brought back here by the SublimeLinter package (HTML and HTML (rails)).

I tried copy pasting the PHP folder from ST2 to ST3 with no success whatsoever.

:bulb: Hasn’t somebody created a package for this ?

0 Likes

#10

You’re lucky, someone actually did. Package handling changed a bit in ST3, you can read most of that here: sublimetext.com/docs/3/packages.html

The package for editing archived package files is: sublime.wbond.net/packages/Pack … urceViewer It also works for ST2 but is incredibly useful for ST3 because it automatically extracts the files.

0 Likes

#11

Thank you very much !

Has somebody already done this kind of job before ? Because I’m not too keen on reinventing the wheel. :wink:

The easiest thing I found for now is installing the extension PHPModern, and switching Syntax Definition from PHP to PHP5 when I want to highlight PHP only. But this is not optimal because the PHP5 Syntax Definition colors only PHP, where it is the HTML.tmLanguage file that is used for PHP files by default (as seen in the PHP.tmLanguage).

0 Likes