X

An Oracle blog about NetBeans for PHP

Custom code folding in PHP editor improved

Last week I wrote article about code folding in PHP editor. Yesterday I have improved a little the custom fold. Now it allows to define, whether the fold will be by default collapsed and also the description of the fold.

From the picture should be clear that the custom fold is defined via element <editor-fold>, which can have two optional attributes. The attribute defaultstate with the value collapsed, says that the fold is collapsed when the file is opened. If you don't use this attribute, then the fold will not be collapsed after opening file by default. The second attribute is desc, where you can define a description of the fold. This description is displayed, when the fold is collapsed.

Because writing the open element can take time, you can create a code template for this.

  • Go to the Tools -> Options and in Editor category select Code Templates tab.
  • Select PHP in  Language combobox.
  • Press New button and enter an abbreviation for the code template. I have choosen cusf.
  • In the Expanded Text tex area write:

    <editor-fold defaultstate="collapsed" desc="${cursor}">

  • Close the Option dialog

The exresion ${cursor} marks the position, where cursor in editor is placed after expanding the code template.

Now when you write cusf and press TAB, then the text cusf is replaced with the defined template.

Join the discussion

Comments ( 11 )
  • Azrael Valedhel Thursday, July 24, 2008

    Now this is getting some colors, looks really nice with the code template used to even ease the pain of writing kinda long element.

    Code folding getting on a higher level of usability. I got to try it at home, for some time I can't do it at work, but seeing all of this - I think I'm going to use NetBeans a lot on a new pc here ;)


  • Petr Thursday, July 24, 2008

    The functionality is available in dev build and sure it will be a part of the M2/Beta build.

    Thanks,

    Petr


  • ci Friday, July 25, 2008

    thanks.


  • raymond Friday, July 25, 2008

    Hi,

    Where can we go to submit feature requests?


  • alex_mayorga Friday, July 25, 2008
  • Alexius Saturday, July 26, 2008

    Why in last versions diff sidebar doesn't work? In version 200805291203 it's work normally.

    Thanks.


  • Petr Monday, July 28, 2008

    Hi Alexius,

    I haven't notice this. Do yo have the option View -> Show Diff Sidebar enabled?

    Thanks,

    Petr


  • fortruth Thursday, August 28, 2008

    hi Petr:

    Thanks your tutor about custom folding on php.!

    i am using 6.5 beta. is there a setting to custom the html fold

    like this:: i want to the fold

    <div id="fold">the fold div's content is here</div> .

    I want to get the effect is like this

    <div id="fold">[..folding..]

    thanks.


  • Brett Zamir Saturday, October 18, 2008

    This is a very nice feature. I'd love to see this for JavaScript too (though even better would be to see objects--which can be quite long--be made collapsible).


  • Petr Sunday, October 19, 2008

    I want to go through all languages (html, css, javascript and php) and synchronize functionality more. Folding should be one of them.

    Thanks,

    Petr


  • Ben Thursday, August 12, 2010

    Hi there,

    thanks a lot for this artikel and the tipps in it.

    I am quiet new to development with netbeans. (I use german language pack on it)

    I have a problem with code folding.

    It folds the code, but when i place the mouse over the hidden field (where code is hidden) it only shows me a empty box, just with the line numbers in of the part of the hidden code. It looks like the first picture on this side, but it looks like you have only the first 30 pixels from the left side.

    Hope i described my problem clear enough. It would be nice if you have any tipps for me.

    Best regards

    Ben


Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.