This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 186731 - No code folding for IF and FOREACH statements
Summary: No code folding for IF and FOREACH statements
Status: RESOLVED FIXED
Alias: None
Product: php
Classification: Unclassified
Component: Editor (show other bugs)
Version: 6.x
Hardware: PC All
: P1 normal with 24 votes (vote)
Assignee: Ondrej Brejla
URL:
Keywords: PLAN
: 188971 195925 205926 208940 (view as bug list)
Depends on:
Blocks:
 
Reported: 2010-05-26 12:08 UTC by noldsel
Modified: 2012-09-04 15:39 UTC (History)
11 users (show)

See Also:
Issue Type: ENHANCEMENT
Exception Reporter:


Attachments
New folding... (26.87 KB, image/png)
2012-02-15 14:55 UTC, Ondrej Brejla
Details
Unfolding (3.58 KB, image/png)
2012-02-20 15:45 UTC, jdbevan
Details

Note You need to log in before you can comment on or make changes to this bug.
Description noldsel 2010-05-26 12:08:45 UTC
I notice in netbeans 6.9 beta that there are no code foldings for IF and FOREACH statements.

Function, classes and comments have code foldings though..
Comment 1 Vitezslav Stejskal 2010-05-26 14:35:17 UTC
What programming language are you referring to?
Comment 2 AIML_Engr 2010-07-19 15:30:40 UTC
This happens at least in PHP. Code folding is missing for switch statements, conditionals(if/else), and loop constructs (for and foreach). It does exist as the OP stated for functions, classes, and comments(C-style, o'course). I'd sure like to see it re-implemented in 6.9, as it worked in 6.8. I've downgraded to 6.8 to keep this functionality, even though I get many nullPointerExceptions daily with it.

I'd also like to request that when code folding, leave the first line (or condition in if/else conditionals) visible, and fold the rest. This is done with functions, can we have it with the rest (conditionals, loops, switches)? In addition, the ability to fold individual portions of a condition tree would be supremely handy. I don't want to expand the entire tree if I just want to look at the last condition. Seems as though folding on braces should be fairly orthogonal? Should I do a feature request?
Comment 3 PazsitZ 2010-08-05 11:23:30 UTC
I use for PHP the NetBeans and I miss the statement collapsing too from the 6.9, after 6.8 had this functionality.
It would be very helpful to allow collapse every single curly brackets.
Comment 4 AIML_Engr 2010-08-16 14:02:12 UTC
*** Bug 188971 has been marked as a duplicate of this bug. ***
Comment 5 zvk77 2010-10-08 18:20:07 UTC
"It would be very helpful to allow collapse every single curly brackets."

It's true!

Additionaly, this bug is not only on Linux, but on Windows too!

It's amazing that NetBeans cannot fold all "{ ... }" blocks in code, like the way Notepad++ do it.

This is ONLY bug in NetBeans for me.
Comment 6 sclewin7 2010-10-18 14:28:58 UTC
+1 here.  Can anyone verify if this problem persist for PHP in 9.10?
Comment 7 AIML_Engr 2010-10-20 15:08:06 UTC
(In reply to comment #6)
> +1 here.  Can anyone verify if this problem persist for PHP in 9.10?

Yes, it it still broken. It only folds (for me) on classes, methods (functions), or C-style /**/ comments. Sometimes it breaks if I have a regular // comment right above a method declaration. It never works on if/then, switch or in for/foreach/while loops.

Other than the occasional slowness, which I can live with (argh!), this code folding problem is the biggest issue for me, and others who use proprietary IDEs.
Comment 8 zvk77 2010-10-26 11:03:45 UTC
same ploblem in 7.0M2 :(
Comment 9 achapman 2010-11-22 08:57:10 UTC
I really don't understand why code folding for LOOPS and IF statements in the PHP module has become such a big deal. It's been a source of frustration ever since I moved to Netbeans.

I am almost sure there is some kind of policy not to implement it. Using custom code folding is tedious and laborious.
Comment 10 AIML_Engr 2010-11-26 16:34:36 UTC
I have been considering implementing this for PHP myself, as it's such a useful and unsupported feature. Why it was taken out after 6.8, I don't understand. Maybe for orthogonality between the language implementations? It really wouldn't take much to implement, probably a day of sitting down and brushing off my rusty Java skills. Though I'm not on the development team, I suppose I could submit a patch, if I get some time.
Comment 11 zvk77 2010-11-26 20:13:02 UTC
AIML_Engr - if you do this, you'll get 1 beer from me. ;)

Seriously, I myself would like to make this feature, but I'm not a Java programmer (although I already begun to teach it, and even tried to fix some bug in NB).

I do not understand why this feature is still absent. I have the code with very complex logic in computing, where one method or function can take hundreds of lines. It is very difficult to work in such cases in Netbeans...

The first message for this bug was sent 2010-05-26. Today is 2010-11-26.
No changes for six months and Target Milestone is still TBD. It is very sad.

Can we expect this feature in 7.0 release? Please!!!
Comment 12 DizzyC 2011-01-27 13:29:36 UTC
This is one of the things about Netbeans that baffles me.
This feature was implemented in earlier versions and was taken out?
Why on earth would somebody do that?! If there really is a reason at least give me a choice. Put it in the options dialog with a checkbox, disabled by default.

I can not wrap my head around this problem. These little details really make a difference and I'm sure it's a matter of minutes for a JAVA developer to fix this.

So... 
AIML_Engr +1 beer from me if you do it :)
Or maybe a nebeans developer will get interest in this issue.

Cheers
Comment 13 Marian Mirilovic 2011-02-23 09:54:51 UTC
> 10 votes means P2
Comment 14 Petr Pisl 2011-03-09 13:19:21 UTC
This is not a bug, it's not implemented. Java does not support this as well. I threated this as enhancements. I'm going to implement this for the next version.
Comment 15 Marian Mirilovic 2011-03-09 13:20:53 UTC
Ok, keep it on the list for Next
Comment 16 jdbevan 2011-05-12 11:08:54 UTC
@Petr Pisl - any luck?

I too am going to have a look at getting this implemented... it's the only incredibly frustrating non-feature in Netbeans for PHP dev.
Comment 17 rangerek 2011-11-15 16:01:16 UTC
I'm using version 7.0.1 and {} folding is still missing - such a pity, especially as someone noted that simple Notepad++ has this functionality
Comment 18 zvk77 2011-11-15 16:14:11 UTC
I see that "Target Milestone" is "7.1". I can't believe.
Can you say - this feature is implemented already in 7.1 Beta?
Comment 19 allanNB 2011-11-16 07:51:16 UTC
Im using NetBeans IDE 7.1 Beta (Build 201109252201) and this feature is still missing!
Comment 20 allanNB 2011-11-16 08:45:25 UTC
Just tested it in NetBeans IDE Dev (Build 201111150600) and no change there too.
Comment 21 amrana83 2011-11-28 07:22:21 UTC
Missing code folding( In php at least for if statement ) really sad. Hope this will be solved soon.
Comment 22 jdbevan 2011-11-30 16:35:56 UTC
I think I found where to add this functionality in, but subsequently got lost in a web of inherited and extended classes.

As far as I understand, this feature would need implementing for each language, and in the case of PHP, the parser doesn't tag control structure tokens as separate token types, so when processing the PHP document there's only a trigger for code folding the case that the current scope is a function or method definition: http://hg.netbeans.org/main/file/eae7afaf7beb/php.editor/src/org/netbeans/modules/php/editor/parser/PhpStructureScanner.java#l228
Comment 23 zvk77 2011-12-01 15:58:34 UTC
jdbevan, it's like that! 
Based on this code, other "scopes" should to be added (for "if", "for", "foreach", "switch" and other blocks). These "scopes" must not change "real" scopes (like functions, methods etc.), but must add folding. But how to do this?
Comment 24 Ondrej Brejla 2011-12-05 12:47:26 UTC
*** Bug 205926 has been marked as a duplicate of this bug. ***
Comment 25 zvk77 2011-12-07 19:39:26 UTC
Hmm, I was right when I wrote earlier : 
//////////
I see that "Target Milestone" is "7.1". I can't believe.
//////////

Now, I see that "Target Milestone" changed from "7.1" to "7.2". 
It's very sad... :(((

NetBeans Release Roadmap says:
7.0 Released April 19, 2011
7.1 (planned) 14 Dec 2011 ( + 8 months after 7.0 release)

So, 7.2 release can be expected at (14 Dec 2011 + 8 months) ~ August 2012? :-/
Comment 26 wnjordan 2011-12-07 19:56:16 UTC
This is such an important feature when working with files that are hundreds to thousands of lines long and while I'm glad that it's still on the roadmap, it's very disappointing that it's been pushed to the 7.2 release.  It's the one and only feature (I'm aware of) that's available in nearly every other IDE that's not available in Netbeans and it's obvious from the comments below how important the feature is to the Netbeans user base.  Having said that, it's open source software so that doesn't give me much right to complain. :)  Besides, Netbeans on the whole is amazing and a pleasure to work in everyday.

Another PHP IDE I've used in the past that has incredible support for code folding is NuShpere PHPed.  That IDE takes code folding a step further by remembering your folds after the page is closed.  Since we have to wait another 8+ months for the feature maybe you could take the time to add the memory feature to it as well???
Comment 27 eflat 2011-12-07 20:03:18 UTC
(In reply to comment #25)
> Hmm, I was right when I wrote earlier : 
> //////////
> I see that "Target Milestone" is "7.1". I can't believe.
> //////////
> 
> Now, I see that "Target Milestone" changed from "7.1" to "7.2". 
> It's very sad... :(((
> 
> NetBeans Release Roadmap says:
> 7.0 Released April 19, 2011
> 7.1 (planned) 14 Dec 2011 ( + 8 months after 7.0 release)
> 
> So, 7.2 release can be expected at (14 Dec 2011 + 8 months) ~ August 2012? :-/

I think I saw that 7.2 was going to have support for the newer svn format. Hopefully that'll be out way before August.
Comment 28 zvk77 2012-01-16 15:57:08 UTC
7.2 release can be expected at 29 Jun 2012 (see http://netbeans.org/community/releases/roadmap.html)

:(((
Comment 29 Ondrej Brejla 2012-02-10 12:22:42 UTC
Fixed in web-main: http://hg.netbeans.org/web-main/rev/5d54999ddb46
Comment 30 jdbevan 2012-02-10 12:35:40 UTC
Wooo! Party :) thanks obrejla@netbeans.org!
Comment 31 seengee 2012-02-10 12:37:10 UTC
(In reply to comment #30)
> Wooo! Party :) thanks obrejla@netbeans.org!

Amen to that, brother!

Any chance we will see this before 7.2 release?
Comment 32 Ondrej Brejla 2012-02-10 12:38:34 UTC
It will be in the dev build in 3 days I think.
Comment 33 zvk77 2012-02-10 13:11:56 UTC
obrejla, thanks!
:D
Comment 34 wnjordan 2012-02-10 15:53:42 UTC
(In reply to comment #32)
> It will be in the dev build in 3 days I think.

Thank You! Thank You! Thank You! Thank You! Thank You!  WooHoo :D
Comment 35 Vladimir Riha 2012-02-15 11:38:58 UTC
verified

Product Version: NetBeans IDE Dev (Build 201202150400)
Java: 1.7.0_02; Java HotSpot(TM) Client VM 22.0-b10
System: Linux version 3.0.0-16-generic-pae running on i386; UTF-8; en_US (nb)
Comment 36 jdbevan 2012-02-15 11:41:32 UTC
verified +1

Product Version: NetBeans IDE Dev (Build 201202130400)
Java: 1.6.0_25; Java HotSpot(TM) Client VM 20.0-b11
System: Windows 7 version 6.1 running on x86; Cp1252; en_GB (nb)
Comment 37 seengee 2012-02-15 12:35:25 UTC
Not sure the implementation is correct (as of dev 201202140400)

If you're folding an if statement it should only fold the content between the braces, not the actual if statement itself. This seems to be the problem on all control structures i checked. 

Just so i'm clear, if you have this code:

<?php
if($something == true)
{
    $myobj->coolThingsHappen();
}
?>

then folding it should leave:

<?php
if($something == true)
{...}
?>

Currently it leaves only:

<?php
{...}
?>
Comment 38 Ondrej Brejla 2012-02-15 12:41:00 UTC
It's the expected behaviour. If you would like to have folded just its "blocks", please, file a new enhancement PHP/Editor. Thanks.
Comment 39 seengee 2012-02-15 12:46:55 UTC
I appreciate it may work as intended but i would assume that most people that have voted for this are expecting it to work the way it works in pretty much every other editor around which is the way that i've described it.  Its not really useful in its current form, sorry!
Comment 40 Ondrej Brejla 2012-02-15 13:36:03 UTC
Ok, so I made some improvements for you: http://hg.netbeans.org/web-main/rev/dfaa7345d4b8
Comment 41 zvk77 2012-02-15 14:34:20 UTC
I agree with seengee on this:
"it should only fold the content between the braces, not the actual if statement itself".

For me, even current version of folding is useful (in comparison with previous state). Thanks a lot, obrejla! 

But I think that folding should be "braces-based", not "statement-based". It is necessary to see what is folded. When you see "{...}" only, you can't guess what is folded in this place, and you must use mouse to see the contents of the block.

In my opinion, code folding should work like this:

============================================
Example 1 (if - else)

Unfolded code:
if (condition) {
  // something
} else {
  // something
}

---
Folded "if":
if (condition) {...}
else {
  // something
}

Folded "if" - current version: not applicable.

---
Folded "else":
if (condition) {
  // something
} else {...}

Folded "else" - current version: not applicable.

---
Folded "if" and "else":
if (condition) {...} else {...}

Folded "if" and "else" - current version (not good):
{...}

============================================
Example 2 (for)

Unfolded code:
for ($i=0; $i<10; ++$i) {
  // something
}

Folded code:
for ($i=0; $i<10; ++$i) {...}

Folded code - current version (not good):
{...}

============================================
Example 3 (while)

Unfolded code:
while (condition) {
  // something
}

Folded code:
while (condition) {...}

Folded code - current version (not good):
{...}

============================================
Example 4 (do - while)

Unfolded code:
do {
  // something
} while (condition);

Folded code:
do {...} while (condition); 

Folded code - current version (not good):
{...}

============================================
Example 5 (foreach)

Unfolded code:
foreach ($array as $key=>$value) {
  // something
}

Folded code:
foreach ($array as $key=>$value) {...}

Folded code - current version (not good):
{...}

============================================

...and so on!

That is, folding should work like actual folding for functions, when code
 function abc($a, $b, $c) {
   // something
 }
folded as:
 function abc($a, $b, $c) {...} // good!
not
 {...} // bad!
!

Is it possible to make folding of "if-for-while etc." statements according to this scheme?

obrejla, thanks again for your efforts!
Comment 42 jdbevan 2012-02-15 14:37:38 UTC
Thanks for sorting out those improvements obrejla! This bug fix is very much appreciated!

I second zvk77's folding proposals.
Comment 43 seengee 2012-02-15 14:40:57 UTC
Totally agree with all zvk77 has said. 

Not sure what improvements obrejla has made but hopefully this is the direction we're moving in. Sorry if i seemed unappreciative though, totally not the case. Great to see this *finally* getting worked on and i just want it to work the right way!
Comment 44 Ondrej Brejla 2012-02-15 14:55:34 UTC
Created attachment 115764 [details]
New folding...

Now it folds as you wished...and please, don't reopen verified status if everything is ok. Thanks.
Comment 45 zvk77 2012-02-15 15:12:51 UTC
Wow, looks great!!! :^D This is exactly what I wanted!

I can't wait for nightly build! Now, the main disadvantage of Netbeans (for me) was gone! I'm happy. :)

Thanks!!!
Comment 46 wnjordan 2012-02-15 16:53:06 UTC
(In reply to comment #44)
> Created attachment 115764 [details]
> New folding...
> 
> Now it folds as you wished...and please, don't reopen verified status if
> everything is ok. Thanks.

Thanks Obrejla!  The attachment looks great and I'm excited to start using it.
Comment 47 jdbevan 2012-02-20 15:45:11 UTC
Created attachment 115956 [details]
Unfolding

See attachment for small bug when trying to re-open a folded "if () else if () else" statement.

The [+] button for opening the folds just toggles the last fold, so the first and second folds can't be opened once closed.

Product Version: NetBeans IDE Dev (Build 201202190400)
Java: 1.6.0_25; Java HotSpot(TM) Client VM 20.0-b11
System: Windows 7 version 6.1 running on x86; Cp1252; en_GB (nb)
Comment 48 Ondrej Brejla 2012-02-20 15:49:08 UTC
I know about that but I can't do anything with that. You can onem them by double-click on {...}.
Comment 49 jdbevan 2012-02-20 15:52:11 UTC
Ah, great, didn't know about the double-click!

Thanks very much, I vote this is set to VERIFIED.
Comment 50 mathewfer 2012-02-29 00:00:28 UTC
Hi 

I downloaded the latest dev ver.

Product Version: NetBeans IDE Dev (Build 201202280400)
Java: 1.6.0_20; Java HotSpot(TM) Client VM 16.3-b01

Code folding works in PHP but t does not work with C++ plugin.

How can one request to add this into C++ module?

Mathew
Comment 51 Ondrej Brejla 2012-02-29 07:32:46 UTC
It's jus a PHP feature. File a new enhancement to CND/Editor - http://netbeans.org/bugzilla/enter_bug.cgi?product=cnd
Comment 52 Marian Mirilovic 2012-02-29 09:31:30 UTC
*** Bug 208940 has been marked as a duplicate of this bug. ***
Comment 53 wnjordan 2012-02-29 18:59:12 UTC
Feature Feedback: (based on build 201202280400)

1. All of the looping structures are collapsed by default when opening a file.  In Options [Editor/General] I only have "Use Code Folding" and "Methods" checked, and unless I'm misunderstanding the options, wouldn't "Tags and Other Code Blocks" need to be checked in order for the looping structures to be automatically collapsed?

2. One thing that seems like a bug to me is that when collapsing looping structures the system is auto-collapsing ones that occur on a single line.  

For example:
foreach ($arr as $k=>$v) echo "$k: $v<br />";

The current implementation collapses everything after the closing paren and it doesn't need to since the code spans a single line.

I would expect this example to automatically collapse:
foreach ($arr as $k=>$v) 
{
  echo "$k: $v<br />";
}

3. It would be extremely helpful to collapse/expand Code Blocks, Comments and Functions/Methods in addition to:
[View|Right Click]->Code Folds->Expand|Collapse All
-new options-
[View|Right Click]->Code Folds->Expand|Collapse Code Blocks
[View|Right Click]->Code Folds->Expand|Collapse Comments
[View|Right Click]->Code Folds->Expand|Collapse Functions

4. When a take the time to collapse and expand a file so that I'm seeing it exactly the way I want, I would expect the system to remember my choices so that when the file is re-opened later it's collapsed and expanded exactly the way it was the last time I looked at it.  The "Collapse by Default" option should only apply the first time a file is opened.
Comment 54 mathewfer 2012-02-29 22:45:46 UTC
Hi wnjordan@netbeans.org,

In Options [Editor/General], I ticked "Tags and Other
Code Blocks" to see it works for the looping structures but it did not work.

It seems to me it is only added to PHP module in 7.2 dev. Please look at these below 3 links.

1. https://blogs.oracle.com/netbeansphp/entry/improved_code_folding
2. http://netbeans.org/bugzilla/show_bug.cgi?id=186731
3. http://hg.netbeans.org/web-main/rev/5d54999ddb46

I will request/file a new enhancement to CND/Editor

Mathew
Comment 55 mpalasis 2012-05-31 10:39:40 UTC
Improvement request for php code folding:

Would it be possible for elseif/else parts of the folding to go to the next line?

e.g.
instead of this:
[+] if (true) {...} elseif (true) {...} else {...}

this:
[+] if (true) {...}
[+] elseif (true) {...}
[+] else {...}


this would allow displaying the [+]/[-] signs for each separate block specifically; and it's more intuitive in my opinion. (also negates the problem of having to use double click the green {...} blocks to expand those cases.)
Comment 56 maxmanus 2012-07-31 13:24:12 UTC
How do I turn it off? I do not need this feature (folding for IF and FOREACH statements) . Please give us a setting possibility to switch this new "if, else etc." Code Folding on or off (in global Settings please).
Comment 57 Ondrej Brejla 2012-09-04 15:39:16 UTC
*** Bug 195925 has been marked as a duplicate of this bug. ***