Highlighting of Alternative Syntax

Although NetBeans 7.0 is out, I'm still in fixing mode and I work mainly on fixes into NetBeans 7.0.1 release. I have noticed that there were a few complains that NetBeans doesn't support highlighting for alternative syntax in PHP. Last week I committed a patch that solve this.

Similarly as open and close brackets are matched, now also begin of a control structure ":" is matched with the end of the structure. For structures while, for, foreach and switch it's simple. It just match ":" with endwhile, endfor, endforeach or endswitch.

For if statement it's little different. There is always matched the true or false branch as is shown on the picture.

The highlighting matching is not good only for the better visual orientation through the code, but also you can quickly navigate between the matching bracket, parenthesis, the begin and end of alternative syntax etc. When there is matched a begin and end, then you can through the shortcut CTRL+[ jump at the matching end or begin. When there is added the key SHIFT (CTRL+SHIFT+[) to the mentioned shortcut , then the content between matching begin and end is selected.

Hope that this small improvement will helpful for someone.


Just one little note. I have to moderate every comment, so please be patient:) I usually go through the comments morning.

Posted by Petr Pisl on May 19, 2011 at 10:03 AM CEST #

Hi Petr, Thanks for updating us on the new PHP features in Netbeans. I really appreciate it and the cumulation of blog articles that talk about new features is better than the information on the what's new page (http://netbeans.org/community/releases/70/). I thought I saw in the Hg logs something about auto completion for elements inside of an array using phpdoc. So if you have a method that returns an array of Foo objects, you can put something like '@return Foo[]' for the phpdoc for the method and Netbeans would do auto completion on whatever variable stored the return value. I tried this in a recent Hudson build but it didn't work. Can you talk more about this? Did I see a feature that doesn't exists?

Posted by Chris on May 19, 2011 at 10:19 AM CEST #

very cool and helpful! Thanks for that! could you more often report what have been done in nightly builds? Just brief summuries

Posted by guest on May 19, 2011 at 12:55 PM CEST #

Very nice! That's one of the things that have annoyed me a bit as well - good to see it is being fixed / added.

Posted by zegenie on May 20, 2011 at 02:49 AM CEST #

HI, thanks a lot for this. Do you mind it would be possible to support the flexy template syntax too? See: http://pear.php.net/package/HTML_Template_Flexy Its a quite simple and nice engine which does the job for even big projects. Thanks Anton

Posted by guest on May 20, 2011 at 02:56 AM CEST #

This is great, I've been having to work on some legacy code that uses this syntax and it's a real pain. This will make it much more bearable!

Posted by Mike on May 20, 2011 at 03:40 AM CEST #

Thanks for this, it will be very useful

Posted by guest on May 20, 2011 at 04:46 AM CEST #

Greatly appreciated !

Posted by James on May 20, 2011 at 09:21 AM CEST #

Perhaps you can fix the auto format with a mix of php and html? I never get the right format result if I use the auto format in a file with php and html.

Posted by Layne Obserdia on May 22, 2011 at 09:56 AM CEST #

Very nice! In addition to the post about adding the flexy template... is it possible to create/add support for a templating system/framework ourselves? Perhaps through some sort of config file? Currently I put the framework I work with in the global include path which mostly works but not quite.

Posted by Martijn on May 25, 2011 at 04:19 AM CEST #

To Martijn: I don't understand fully what you mean. Could you describe the usecase more?

Posted by Petr Pisl on May 25, 2011 at 04:31 AM CEST #

Thanks, I use this syntax all the time and really appreciate this. I hope auto-formatting for alternative syntax comes next!

Posted by guest on May 26, 2011 at 03:21 AM CEST #

This patch should then close my bug report: https://netbeans.org/bugzilla/show_bug.cgi?id=167988 Thanks for the patch Petr.

Posted by Simon Holywell on May 26, 2011 at 05:25 AM CEST #

To Simon: Thanks, I have just close it.

Posted by Petr Pisl on May 26, 2011 at 09:19 AM CEST #

This is a very helpful improvement. I user alternate syntax a lot for creating WordPress theme.

Posted by Permana Jayanta on May 27, 2011 at 08:45 PM CEST #

@Petr - What I mean is... you've been adding support for stuff like Symphony to NetBeans PHP right? Is there a way we can add that support ourselves? That would save you guys a lot of time and it would allow us to add support for lesser known stuff. Am I making sense?

Posted by Martijn on May 28, 2011 at 03:59 AM CEST #

Great advice, very helpful!!!

Posted by Lucas Souza on May 30, 2011 at 03:30 PM CEST #

Awesome! Thanks for adding this! Even though it is officially an 'old legacy format' a LOT of people prefer the end* versions of PHP control structures for their readability, this highlighting will make NetBeans seem a lot smarter when navigating my code :) Like a previous commenter I'd love to also see autocomplete support for the alternate syntax, so that when you type "if ($x) :" and hit enter, it completes the structure and gives you: if ($x) : | endif; where "|" is the flashing cursor. This would make it behave the same as "if ($x) {" and would speed up my coding significantly. Thanks for all your great work!

Posted by Jeremy Clarke on June 01, 2011 at 10:31 AM CEST #

To Jeremy CLarke: The example that you mentioned should work. At least it works for me in development builds. In which build doesn't work for you?

Posted by Petr Pisl on June 02, 2011 at 09:48 AM CEST #

To Martijn: Yes you can, but you have to know Java and some NetBeans API to write plugin that will create a support for a framework.

Posted by Petr Pisl on June 02, 2011 at 09:50 AM CEST #

You're right Petr! Sorry I was still using 6.9 when I did testing before writing my comment, just upgraded to 7.0 and it's working exactly like I described, sorry for creating noise and thanks for the wonderful new PHP features all the time!

Posted by Jeremy Clarke on June 03, 2011 at 09:02 AM CEST #

It's OK. There are still many issues in the formatter ind indentation engine. I have fixed some on them in NetBeans 7.0, but I'm sure not all of them:). If you find any problem, please report it. Thanks.

Posted by Petr Pisl on June 03, 2011 at 10:35 AM CEST #

Actually, now that I'm using it it's actually annoying me a lot of the time :P It works great if you are writing your code in order (one thing after another), but I find it way too aggressive about adding the closing 'endif' if you are editing code inside an existing if/endif pair. This is especially problematic when the next thing in the code is another 'endif'. Have you noticed this? If the cursor is between an "if () :" and an "endif;" then hitting enter continuously adds new "endif;"s below the cursor. You can end up with dozens! I think what's needed is to have it only add the "endif/endforeach" below if the current structure is incomplete. If the most recent "if" already has a matching "endif" then it should be left alone. That might be hard because it requires checking the whole document structure (though i imageine this is already being done?). If you can't do it that way then a more hacky but still helpful fix would be to just never add an 'endif' when the next line is an 'endif'. Thanks for your work, sorry to give you more bugs after discovering a feature ;) Like if I have " if ($x) :" above the

Posted by Jeremy Clarke on June 03, 2011 at 01:27 PM CEST #

Jeremy, it's ok. One purpose why I'm writing about new features is that a few people work with daily builds and they can test the usability and find issues before the release gets to final state. There are many cases that has to be tested and it's not possible to test all cases for me. Please file a new bug, I'm glad that you are using development builds and in this way help me to increase the quality. I always saying that many bugs doesn't mean poor quality, it mainly means that many people are using it. :)

Posted by Petr Pisl on June 07, 2011 at 05:02 AM CEST #

To Jeremy: I have just tried the case as you describe in your comment above. But I can not reproduce it. Probably I have tried only simple cases. Could you enter new issue in our Bugzila (http://netbeans.org/community/issues.html), with a reproducible case. Thanks a lot.

Posted by Petr Pisl on June 07, 2011 at 05:07 AM CEST #

Post a Comment:
  • HTML Syntax: NOT allowed

This blogs is written by NetBeans developers who contribute to the PHP support mainly.


« July 2016