NuSphere Forums Forum Index
NuSphere Forums
Reply to topic
Reindenting code


Joined: 28 Sep 2012
Posts: 3
Reply with quote
Hi,
when reindenting code - is there any way to tell PhpEd how to indent?

Lets say i have this code:

Code:

public function TestFunc() {
  ob_start();
  ?>
  <div>
    <div>Div text</div>
  </div>
  <?php
  echo ob_get_clean();
}


When i reindent the code it looks like this:

Code:

public function TestFunc() {
  ob_start();
?>
<div>
  <div>Div text</div>
</div>
<?php
  echo ob_get_clean();
}


Thats not what i want so i am searching for a way to change how phped indent my code.
View user's profileFind all posts by SveinlaSend private message
Site Admin

Joined: 13 Jul 2003
Posts: 8334
Reply with quote
php tags (<?, <?php, ?>) are indented according to their level. Not sure what you think is wrong with the results

_________________
The PHP IDE team
View user's profileFind all posts by dmitriSend private messageVisit poster's website


Joined: 28 Sep 2012
Posts: 3
Reply with quote
Hi,
i dont say that the result is "wrong", but i want the reindented code to be as the "original" in this case.

I think the php-tags and div-tags in this case should be indented relative to the containing function.
View user's profileFind all posts by SveinlaSend private message
Guru master

Joined: 24 Jul 2009
Posts: 737
Reply with quote
Others might not agree, but I find breaking out of PHP into HTML halfway through a function very messy. This is possibly even the first time I've seen that done; it certainly doesn't get done in any of the web apps and frameworks that I deal with.

This is easier to read (despite lacking HTML syntax highlighting) and re-indents better as well:

Code:
function TestFunc() {
   ob_start();
   echo '
   <div>
   <div>Div text</div>
   </div>';
   echo ob_get_clean();
}


For anything but the most simple function I would probably be inclined to use a simple template mechanism so that the function does not have any HTML in it.
View user's profileFind all posts by plugnplaySend private message


Joined: 28 Sep 2012
Posts: 3
Reply with quote
I see your point, but in some projects i have to use that syntax and combine php and html.

Its actually not a big deal, but i just wanted to know if there are some settings i could edit in PhpEd to change the way it do the indenting - or if the rules are hardcoded into the program.
View user's profileFind all posts by SveinlaSend private message
individual settings would be nice


Joined: 01 Apr 2008
Posts: 5
Reply with quote
I agree with Sveinla that it would be nice to modify the way PhpED reindents the code. It doesn't matter how someone writes code - the editor should follow the habit of the user not vice versa.

I'm also using Visual C# for windows- and .aspx-projects and this editor gives me the complete freedom how it formats code (while writing!). This is exactly how things should work and PhpEd doesn't reach this level by far - so far.

Btw: imho mixing php and html in one function is not usual - but it may happen, especially in small or quick-and-dirty-projects and in this cases the way Sveinla formats code is much more clearer.
View user's profileFind all posts by khinkelmannSend private message


Joined: 04 Oct 2012
Posts: 8
Reply with quote
I would like to add my voice to the concept of indenting being user configurable. I am not a new programmer and have evolved a certain style over the years and it should be possible for me to tailor something as simple as indentation to my own preference.

I tried to buy polystyle but it seems they are simply accepting money and not delivering product keys now. RegNow or PayPal will fix it, so no big deal. It does raise the question of whether NuSphere should continue to include a trial of the indenter when it only leads to the end user having troubles. I would clearly like to get polystyle or have the ability to configure indentation in phpEd.

It has been a lot of learning to move from Netbeans, but I am now getting pretty comfortable with it. Still only scratched the surface but the speed is surely nice to have and what I have managed to learn is nearly enough to work very productively. Still waiting for a rainy day to try out remote debugging, which was one of the key reasons to consider the move.

So, the key point here is --> have a close look at how Netbeans allows the end user to change all aspects of indentation and use it during editing. It means I only have to reformat someone else's code and never my own because it already meets my spec.
View user's profileFind all posts by lonnienSend private message
Site Admin

Joined: 13 Jul 2003
Posts: 8334
Reply with quote
lonnien wrote:
I would clearly like to get polystyle or have the ability to configure indentation in phpEd.

I'm sorry to hear that you encountered problems with their product. We'll try to reach the author and in case of failure, we'll definitely remove the package.
As of phped's own re-indent feature -- it's already there, available since ~ v5.6
It is not a re-formatting function like what polystyle does (did), phped only re-indents the code.

_________________
The PHP IDE team
View user's profileFind all posts by dmitriSend private messageVisit poster's website


Joined: 04 Oct 2012
Posts: 8
Reply with quote
Hi dmitri. Yes I am aware of the re-indent and that is why I tried to buy Polystyle. The re-indentation that phpEd does is maybe fine for you guys who write phpEd since it is your style but it is not the way I indent, and apparently I am not the only one with a style of their own.

It seems that it is too difficult to make the indentation tweakable by the user, so I will be looking at some other reformatters. I know it is a small matter but after many years of a certain style it breaks my stride to look at other code. The first thing I do with "alien" code is reformat it and right now it means I open it up with Netbeans, reformat and save. Then phpEd comes back onto the scene.

It gets the job done, just like my mis-using Todo lists for Bookmarks.
View user's profileFind all posts by lonnienSend private message
Veteran

Joined: 15 Nov 2003
Posts: 118
Reply with quote
re-indent did what i expected it to do. I deleted all the tabs from some code, selected it, then re-indent'ed it. It looks just right.

What coding standards are you guys using?

Nothing in the manual referring to what "re-indent" actually does, so guessing it just formats the selection?
View user's profileFind all posts by joebSend private message


Joined: 09 Aug 2012
Posts: 9
Reply with quote
Although this thread is several months old, I want to cast a vote for having configuration options regarding PhpEd's indentation rules.

For example, PhpEd indents all the lines between opening and closing PHP-Tags. This clashes with the coding style used in all the projects I'm working on (I'm the only one using PhpEd in my team).
So whenever I use the auto-indent feature and commit my code to the repository, every line is marked as "changed". This renders this otherwise helpful feature pretty useless.

Thanks!
View user's profileFind all posts by EstigySend private message
Reindenting code
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