Home Download Buy Blog Forum Support

Scope problem and syntax highlighting

Scope problem and syntax highlighting

Postby Pixelshaped on Tue Feb 18, 2014 3:49 pm

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 :
Image
Edit: Here is the plain text code you can copypaste to reproduce the issue http://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 !
Last edited by Pixelshaped on Wed Feb 26, 2014 11:45 am, edited 2 times in total.
Pixelshaped
 
Posts: 7
Joined: Tue Feb 18, 2014 3:38 pm

Re: Scope problem and syntax highlighting

Postby tito on Thu Feb 20, 2014 3:59 pm

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.
Give APIs, let the community build the rest!
https://github.com/titoBouzout
tito
 
Posts: 846
Joined: Thu Sep 29, 2011 2:27 pm
Location: Montevideo, Uruguay

Re: Scope problem and syntax highlighting

Postby Pixelshaped on Wed Feb 26, 2014 11:44 am

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 :
Image
Here is the code to copypaste : http://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 !
Pixelshaped
 
Posts: 7
Joined: Tue Feb 18, 2014 3:38 pm

Re: Scope problem and syntax highlighting

Postby Pixelshaped on Sun Mar 02, 2014 5:46 pm

Anyone please ? ;)
Pixelshaped
 
Posts: 7
Joined: Tue Feb 18, 2014 3:38 pm

Re: Scope problem and syntax highlighting

Postby Pixelshaped on Wed Mar 05, 2014 6:49 pm

Can't believe people have never crossed this issue before. There must be a simple solution ! :|
Pixelshaped
 
Posts: 7
Joined: Tue Feb 18, 2014 3:38 pm

Re: Scope problem and syntax highlighting

Postby Orlmente on Wed Mar 05, 2014 10:45 pm

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:
Code: Select all
<?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 ;)
Orlmente
 
Posts: 95
Joined: Mon Mar 18, 2013 12:37 pm

Re: Scope problem and syntax highlighting

Postby Pixelshaped on Mon Mar 10, 2014 3:29 pm

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

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).
Pixelshaped
 
Posts: 7
Joined: Tue Feb 18, 2014 3:38 pm

Re: Scope problem and syntax highlighting

Postby FichteFoll on Tue Mar 11, 2014 3:03 am

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, http://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.
FichteFoll
 
Posts: 376
Joined: Fri Mar 16, 2012 11:49 pm
Location: Germany

Re: Scope problem and syntax highlighting

Postby Pixelshaped on Tue Mar 11, 2014 10:08 am

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.

:idea: Hasn't somebody created a package for this ?
Pixelshaped
 
Posts: 7
Joined: Tue Feb 18, 2014 3:38 pm

Re: Scope problem and syntax highlighting

Postby FichteFoll on Tue Mar 11, 2014 3:43 pm

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

The package for editing archived package files is: https://sublime.wbond.net/packages/Pack ... urceViewer It also works for ST2 but is incredibly useful for ST3 because it automatically extracts the files.
FichteFoll
 
Posts: 376
Joined: Fri Mar 16, 2012 11:49 pm
Location: Germany

Next

Return to Technical Support

Who is online

Users browsing this forum: Google [Bot] and 29 guests