NuSphere Forums Forum Index
NuSphere Forums
Reply to topic
Region Code Folding


Joined: 07 Sep 2009
Posts: 12
Location: Knoxville, TN
Reply with quote
Many IDEs support the ability to fold "regions" of code. Regions can be denoted by three opening (left) curly braces ( {{{ ), followed by a label, and then closed with three closing (right) curly braces ( }}} ). Example:
Code:
/* {{{ myFunction */
function myFunction ($param1, $param2) {
    print $param1;
    return $param2;
}
/* }}} */


The area in the example above between the {{{ and the }}} would be considered a region and, when collapsed, the "myFunction" area just after the {{{ would serve as the collapsed region's label (which would be the visible text inside the collapsed code box. Another idea to implement this behavior (considering PHP's language syntax for comments) would be:
Code:
//region This function does nothing, really
function myFunction ($param1) {
    return $param1;
}
//endregion

In that case, the region is denoted by //region and //endregion with "This function does nothing, really" serving as the label. The idea stems from VisualStudio, in which this:
Code:
#region Private Properties
private DictionaryEntry[] _wamDictItems;
private Int32 _itemsInUse = 0;
private bool _isFixedSize = false;
private bool _isReadOnly = false;
private bool _isSynchronized = false;
#endregion

would be a collapsible region.

Using collapsible regions, it allows developers even more options for folding large areas of (related) code to save space in the code window. Consider this:
Code:
<?php
//region Functions
function func1 () {
    print 'I am func1.';
}

function func2 () {
    print 'I am func2.';
}
//endregion

//region Variables
$var1 = 'I am var 1';
$var2 = array(
    'Value 1',
    'Value 2',
    'Value 3',
    100 => 'Value 100'
);
$var3 = print_r($var2, true);
//endregion

//region Logic
if ($var1 == 'I am var 4') {
    print '$var1 is var 4';
}
elseif ($var1 == 'I am var 1') {
    print '$var1 is var 1';
}
//endregion
?>

With all default collapsible areas collapsed, the user still sees 21 distinct lines of code. However, if you had regions in the list of collapsibles, the user would only see 7 lines of code. That's one-third the lines![/i]
View user's profileFind all posts by hyponiqSend private messageVisit poster's websiteYahoo MessengerMSN Messenger
While I'm at it ...


Joined: 07 Sep 2009
Posts: 12
Location: Knoxville, TN
Reply with quote
... I'd also like to reiterate the need for array declarations to be collapsible, as well, like multiline strings.
View user's profileFind all posts by hyponiqSend private messageVisit poster's websiteYahoo MessengerMSN Messenger
Code Region folding


Joined: 12 Feb 2014
Posts: 1
Reply with quote
Hi there,

Any news with this feature?

I would also appreciate a Visual Studio like #region #endregion folding option to be able to define my own code regions.


Thx.
View user's profileFind all posts by csegyudSend private message


Joined: 02 Mar 2011
Posts: 8
Location: Poland
Reply with quote
I agree, i would love to see that feature: #region [<name>], #endregion ...
View user's profileFind all posts by SetiSend private message


Joined: 26 Jun 2014
Posts: 14
Reply with quote
Confirm.
Regions can really simplify navigation in "Code navigator" window. This feature is very useful in Visual Studio (#region name; #endregion).

Regions feature specs:
- Regions can be collapsed in editor window;
- Functions can be grouped by regions in "Code navigator" window;
- Regions must have names and "begin" an "end" (opt) definitions (such as #regionand #endregion).
View user's profileFind all posts by vekurmanovaSend private message
regions already exist in php and they are foldable in PhpED


Joined: 02 Dec 2015
Posts: 9
Reply with quote
From documentation on php.net:
http://www.php.net/manual/en/control-structures.intro.php

Quote:
Any PHP script is built out of a series of statements. A statement can be an assignment, a function call, a loop, a conditional statement or even a statement that does nothing (an empty statement). Statements usually end with a semicolon. In addition, statements can be grouped into a statement-group by encapsulating a group of statements with curly braces. A statement-group is a statement by itself as well. The various statement types are described in this chapter.


In other words, the following code is valid PHP code:

Code:

echo 'Hello World';
{ //polite stuff
    echo ", it's nice to meet you.\n";
    echo "May I be of service?\n";
}


The curly braces define a statement group similar to when used with if, else, foreach, etc. It does not create a new variable scope, but can be used to format/organize code in some arbitrary way. Statement groups can contain almost anything (assuming nest conventions are followed). Some things that can't be used inside statement blocks are: namespace, use, (global) const, and __halt_compiler().

Anything in curly braces will have a fold mark in PhpED. That includes statement groups which then function just as one would hope/expect. One feature that would be nice is if PhpED showed the comment immediately after the starting brace while the group is folded. One can even make a shortcut to create a foldable statement group using code snippets in PhpED. For example, the following template could be created and assigned to the keyboard combination Ctrl+Alt+B
Code:
{// my_custom_code_block
|}

Thereafter one could highlight a block of code then hit Ctrl+Alt+B to wrap the highlighted statements in curly braces, creating a statement group.
View user's profileFind all posts by pantsmannSend private message
And still more on Regions


Joined: 22 Feb 2017
Posts: 7
Reply with quote
I've just changed from using phpEdit for about 10yrs. The developer has gone out of business.

However, the latest version had some very nice features, one is

//region******** foobar ********

code or anything

//endregion

Everything between /region and endregion is folded, only the //region******** foobar ******** and //endregion render
View user's profileFind all posts by riderForumSend private message
Region Code Folding
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
All times are GMT - 5 Hours  
Page 1 of 1  

  
  
 Reply to topic