jskinner / DefaultPackages

Old bug tracker for Sublime Text's "Default Packages", e.g. bad syntax highlighting
http://web.archive.org/web/20150524043750/https://www.sublimetext.com/forum/viewtopic.php?f=2&t=12095
26 stars 2 forks source link

HTML includes PHP in such a way that toggle_comment chooses the wrong comment marker #94

Closed FichteFoll closed 8 years ago

FichteFoll commented 9 years ago

Example file:

<html>
    <?php while (have_posts()) : the_post(); ?>
</html>

If you run toggle_comment anywhere in the php line, it will prepend // to the line, even though it should be choosing HTML comments (or with the current implementations of the toggle_comment command, do nothing at all).

The reason for this is that php source is detected in the HTML syntax using look-aheads and the PHP syntax then matches the entire <?php block, including the block markers, and assigns source.php.embedded.block to it. That results in toggle_comments finding the source.php scope both at the location of the caret and at the beginning of the (whitespace-stripped) line.

It is debatable if the <?php and ?> markers should be matched as source.php, but if they should, this is hardly fixable for the toggle_commends command when it occurs at the beginning of the line without leading whitespace.

Original report: http://www.sublimetext.com/forum/viewtopic.php?f=3&t=8230

jhebb commented 9 years ago

I would expect the toggle_comment command to prepend the // to the php line, within the <?php ?> tags, as if I'm inside a php block I'm probably looking to comment that out and not the html.

FichteFoll commented 9 years ago

The issue is that the comment might result in the ?> not being recognized. I'm actually not sure if HTML will find that (and if the current PHP syntax definition respects that case and does not consume it) or if it needs a non-commented ?> to close the block.

Also, the normal behavior is to comment the entire line in all other files (not considering embedded right now).

And finally, even if this worked with HTML&PHP it might not with all other language combinations. Going the save way would definitely be the more desireable option here.

jhebb commented 9 years ago

There doesn't seem to be any issues if you manually add the comment to the beginning of the php block, I end up doing that all the time - wouldn't that be the same thing?

FichteFoll commented 8 years ago

Because this is, in its core, the same issue as https://github.com/SublimeTextIssues/Core/issues/43 and we decided to list issues with the Default package in the other repo (since it's considered to be "core"), I'm closing this as duplicate.