X

An Oracle blog about NetBeans for PHP

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.

Join the discussion

Comments ( 25 )
  • Petr Pisl Thursday, May 19, 2011
    Just one little note. I have to moderate every comment, so please be patient:)
    I usually go through the comments morning.
  • Chris Thursday, May 19, 2011
    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?
  • guest Thursday, May 19, 2011
    very cool and helpful! Thanks for that!
    could you more often report what have been done in nightly builds? Just brief summuries
  • zegenie Friday, May 20, 2011
    Very nice! That's one of the things that have annoyed me a bit as well - good to see it is being fixed / added.
  • guest Friday, May 20, 2011
    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
  • Mike Friday, May 20, 2011
    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!
  • guest Friday, May 20, 2011
    Thanks for this, it will be very useful
  • James Friday, May 20, 2011
    Greatly appreciated !
  • Layne Obserdia Sunday, May 22, 2011
    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.
  • Martijn Wednesday, May 25, 2011
    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.
  • Petr Pisl Wednesday, May 25, 2011
    To Martijn: I don't understand fully what you mean. Could you describe the usecase more?
  • guest Thursday, May 26, 2011
    Thanks, I use this syntax all the time and really appreciate this. I hope auto-formatting for alternative syntax comes next!
  • Simon Holywell Thursday, May 26, 2011
    This patch should then close my bug report: https://netbeans.org/bugzilla/show_bug.cgi?id=167988
    Thanks for the patch Petr.
  • Petr Pisl Thursday, May 26, 2011
    To Simon: Thanks, I have just close it.
  • Permana Jayanta Friday, May 27, 2011
    This is a very helpful improvement. I user alternate syntax a lot for creating WordPress theme.
  • Martijn Saturday, May 28, 2011
    @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?
  • Lucas Souza Monday, May 30, 2011
    Great advice, very helpful!!!
  • Jeremy Clarke Wednesday, June 1, 2011
    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!
  • Petr Pisl Thursday, June 2, 2011
    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?
  • Petr Pisl Thursday, June 2, 2011
    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.
  • Jeremy Clarke Friday, June 3, 2011
    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!
  • Petr Pisl Friday, June 3, 2011
    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.
  • Jeremy Clarke Friday, June 3, 2011
    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
  • Petr Pisl Tuesday, June 7, 2011
    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. :)
  • Petr Pisl Tuesday, June 7, 2011
    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.
Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.Captcha
Oracle

Integrated Cloud Applications & Platform Services