NuSphere Forums Forum Index
NuSphere Forums
Reply to topic
Auto re-indent versus arrays and multi-line strings...


Joined: 24 Jan 2008
Posts: 26
Reply with quote
It is quite common to indent the content of arrays in PHP or Javascript this way:

Code:
$myArray = array(
    1 => "Value 1",
    2 => "Value 2",
    3 => "Value 3",
    4 => "Value 4"
);


I do that quite a lot myself as it keeps my code easier to read. However if I use the automatic re-indent code feature, it won't stay aligned the way I want it to and becomes:

Code:
$myArray = array(
1 => "Value 1",
2 => "Value 2",
3 => "Value 3",
4 => "Value 4"
);


I also often put very long strings on multiple lines using a concatenation character, and indent all lines at the same level as such:

Code:
$mystring = "Lorem ipsum dolor sit amet, consectetur adipisicing elit, ".
            "sed do eiusmod tempor incididunt ut labore et dolore magna ".
            "aliqua. Ut enim ad minim veniam, quis nostrud exercitation ".
            "ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis".
            " aute irure dolor in reprehenderit in voluptate velit esse".
            " cillum dolore eu fugiat nulla pariatur. Excepteur sint";


This is especially useful when combined with MySQL queries. This way to can keep the indents in the query and keep it very readable.

Unfortunately, the re-indent engine realigns it this way:

Code:
$mystring = "Lorem ipsum dolor sit amet, consectetur adipisicing elit, ".
"sed do eiusmod tempor incididunt ut labore et dolore magna ".
"aliqua. Ut enim ad minim veniam, quis nostrud exercitation ".
"ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis".
" aute irure dolor in reprehenderit in voluptate velit esse".
" cillum dolore eu fugiat nulla pariatur. Excepteur sint";


So all this comes down to 2 feature requests:

1. Array declarations that are broken on multiple lines (where the brackets are in compact style), should be indented the same way a function declaration is.

2. If a string is broken on several lines using a concatenation character, then all subsequent lines should be aligned with the beginning of the first quote after the assignment operator (=, .=, etc..) just like in my example. Since this is perhaps not a behavior that everyone would like, it could be an additional checkbox in the general settings (something like "auto-indent multi-line strings together")[/list][/quote][/code]
View user's profileFind all posts by ygirouardSend private message


Joined: 24 Jan 2008
Posts: 26
Reply with quote
Am I really the only one who sees a need for this?
View user's profileFind all posts by ygirouardSend private message
Auto re-indent versus arrays and multi-line strings...
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