Home Download Buy Blog Forum Support

PHP highlight mess

PHP highlight mess

Postby yann.tersen on Sat Jun 23, 2012 12:37 pm

Image

How to fix this? And ST2 doesn't know where is PHP and where is HTML ?
yann.tersen
 
Posts: 4
Joined: Sat Jun 23, 2012 12:15 pm

Re: PHP highlight mess

Postby agibsonsw on Sat Jun 23, 2012 7:35 pm

If you install ScopeHunter via PackageControl it will help you discover the scope for the various parts of your code. Then you can add some of these scopes, and your chosen colours, to your theme-file.

But first I would test a few different themes - this will help to confirm that it is your theme that is letting you down. That is, that your theme isn't defining colours for the variety of scopes that you would like.

When you are checking the scopes for the various parts of your PHP code, if you believe that some are incorrectly scoped, then it becomes a bit trickier. This would mean that the syntax (PHP.tmLanguage) file is not working correctly - or is not exacting enough. Modifying this file to correct it can be a challenge :(

But perhaps someone, somewhere, has already modified/corrected the PHP syntax file and might offer it to you ;)

Personally, I added a couple of PHP-specific colours to my theme, but I'm trying to ignore the formatting of PHP/HTML/JS combinations - because I suspect it would prove quite messy to fix.
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
agibsonsw
 
Posts: 901
Joined: Fri Jan 27, 2012 9:11 pm

Re: PHP highlight mess

Postby agibsonsw on Sat Jun 23, 2012 7:48 pm

This might be a mess but I'm happy that I can spot the PHP.
Attachments
phpcolour1.png
phpcolour1.png (20.91 KiB) Viewed 1885 times
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
agibsonsw
 
Posts: 901
Joined: Fri Jan 27, 2012 9:11 pm

Re: PHP highlight mess

Postby yann.tersen on Sat Jun 23, 2012 9:50 pm

Thanks a lot for the plugin.
I cannot believe, it is so buggy. And nobody cares, as if I am the only one who comes across to these issues in highlighting.

As for php in html attribute. How do you do that? can you share tmLanguage file? :roll:
yann.tersen
 
Posts: 4
Joined: Sat Jun 23, 2012 12:15 pm

Re: PHP highlight mess

Postby agibsonsw on Sat Jun 23, 2012 10:43 pm

I don't think I've touched the PHP syntax file at all, as I recall. But I inserted the following into my theme file:

Code: Select all
      <dict>
         <key>name</key>
         <string>Embedded begin (PHP)</string>
         <key>scope</key>
         <string>text.html.basic source.php.embedded.block.html punctuation.section.embedded.begin.php</string>
         <key>settings</key>
         <dict>
            <key>fontStyle</key>
            <string></string>
            <key>foreground</key>
            <string>#FF0000</string>
         </dict>
      </dict>
      <dict>
         <key>name</key>
         <string>Embedded end (PHP)</string>
         <key>scope</key>
         <string>text.html.basic source.php.embedded.block.html punctuation.section.embedded.end.php</string>
         <key>settings</key>
         <dict>
            <key>fontStyle</key>
            <string></string>
            <key>foreground</key>
            <string>#FF0000</string>
         </dict>
      </dict>
      <dict>
         <key>name</key>
         <string>Embedded PHP in HTML double</string>
         <key>scope</key>
         <string>text.html.basic meta.tag.inline.any.html string.quoted.double.html source.php.embedded.line.html</string>
         <key>settings</key>
         <dict>
            <key>fontStyle</key>
            <string></string>
            <key>foreground</key>
            <string>#FF0000</string>
         </dict>
      </dict>
      <dict>
         <key>name</key>
         <string>Embedded PHP in HTML single</string>
         <key>scope</key>
         <string>text.html.basic meta.tag.inline.any.html string.quoted.single.html source.php.embedded.line.html</string>
         <key>settings</key>
         <dict>
            <key>fontStyle</key>
            <string></string>
            <key>foreground</key>
            <string>#FF0000</string>
         </dict>
      </dict>

The first two sections - embedded begin and end - refer to the <?php and ?> tags.

Open your theme file (having taken a copy..) and insert the above. I inserted this between scopes 'support.constant' and 'meta.processor.c', although your theme is unlikely to follow the same order: just insert it carefully after all the 'comment', 'keyword', etc., scopes. Of course, you don't have to use red :)
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
agibsonsw
 
Posts: 901
Joined: Fri Jan 27, 2012 9:11 pm

Re: PHP highlight mess

Postby agibsonsw on Sat Jun 23, 2012 10:50 pm

it is so buggy. And nobody cares..


I suspect someone, somewhere, has managed to fix it. I'm trying not to look at it too closely :roll: as, although I'm sure it can be fixed, I suspect it's the sort of challenge whereby, if you fix it in one place, it will be broken elsewhere :o
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
agibsonsw
 
Posts: 901
Joined: Fri Jan 27, 2012 9:11 pm

Re: PHP highlight mess

Postby agibsonsw on Sun Jun 24, 2012 7:26 pm

On reflection, I don't think the php-syntax file is necessarily broken; it's just that themes don't target embedded PHP specifically enough.

Some themes do target specific languages, so it might be worth searching for a more-php centric theme. In the meantime, the following addition to my theme file allows me to target php-functions, but not if they're embedded within quotes:

Code: Select all
        <dict>
            <key>name</key>
            <string>Embedded PHP in HTML(functions)</string>
            <key>scope</key>
            <string>text.html.basic source.php.embedded.block.html support.function</string>
            <key>settings</key>
            <dict>
                <key>fontStyle</key>
                <string></string>
                <key>foreground</key>
                <string>#FFFF00</string>
            </dict>
        </dict>
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
agibsonsw
 
Posts: 901
Joined: Fri Jan 27, 2012 9:11 pm


Return to Technical Support

Who is online

Users browsing this forum: Google [Bot], Yahoo [Bot] and 21 guests