NuSphere Forums Forum Index
NuSphere Forums
Reply to topic
reindent code
Veteran

Joined: 28 Nov 2005
Posts: 144
Reply with quote
I'd like to have a function that reindents the source code selected in a file (like Eclipse does)

I don't like very much how polistyle works
View user's profileFind all posts by blackSend private message
Veteran

Joined: 28 Nov 2005
Posts: 144
Reply with quote
no comments?
View user's profileFind all posts by blackSend private message
Site Admin

Joined: 13 Jul 2003
Posts: 8335
Reply with quote
Could you please tell me what's wrong with PolyStyle?
View user's profileFind all posts by dmitriSend private messageVisit poster's website
Veteran

Joined: 28 Nov 2005
Posts: 144
Reply with quote
This is wrong for me:

1) It's a very heavy application
2) I can't reindent just some lines of my script
3) I can't undo the reindent
4) I don't like the way it reindent the code (eg I like to have { at the end of the line, not so lonely Smile on the next line of the construct (if, while...)

eg. 2:

I like the more compact:

if ($x>2) {
bla bla bla
}

and not like polystile does:

if ($x>2)
{
bla bla bla
}



I like very much how Eclipse works to reindent the code
View user's profileFind all posts by blackSend private message
Site Admin

Joined: 13 Jul 2003
Posts: 8335
Reply with quote
I got it. Thanks.
View user's profileFind all posts by dmitriSend private messageVisit poster's website


Joined: 03 Mar 2004
Posts: 40
Reply with quote
black wrote:
This is wrong for me:

1) It's a very heavy application
2) I can't reindent just some lines of my script
3) I can't undo the reindent

I like very much how Eclipse works to reindent the code

I'd like to second this.
Especially the ability to simply and quickly reindent a few selected lines of code (renesting 'if's and classes/functions in particular). This is something I miss that I use a lot in ZDE.
With a local, incremental reindent available, I almost never feel the need to do a wholesale reformat my code in the way that PolyStyle does and have a lot more confidence that a major reformat hasn't done something obscure that I wish it hadn't.
View user's profileFind all posts by jonphippsSend private message
Site Admin

Joined: 13 Jul 2003
Posts: 8335
Reply with quote
I got it, thanks.
So we're talking about a lightweight feature that just takes the lestmost spaces on every line and adjust them according to the nesting level. Latter one increments with each { and decrements with }. No other reformatting is needed. Right?
View user's profileFind all posts by dmitriSend private messageVisit poster's website


Joined: 03 Mar 2004
Posts: 40
Reply with quote
ddmitrie wrote:
I got it, thanks.
So we're talking about a lightweight feature that just takes the leftmost spaces on every line and adjust them according to the nesting level. Latter one increments with each { and decrements with }. No other reformatting is needed. Right?

Right, mostly... Comments or comment blocks that are not indented at all are left on the left margin. Comments or comment blocks that are indented are aligned with the first line of code following the comment or comment block. Also, if no text selected, indenting is applied to the whole file. And a single undo returns all re-indented text to the way it was before the indenting was applied.

So...
Code:
class questionActions extends sfActions {
//this is a comment
private function getQuestionOrCreate ($id = 'id')
{
  //this is another comment
  if (!$this->getRequestParameter($id, 0)) {
$question = new Question();
}
else {
$question = QuestionPeer::retrieveByPk($this->getRequestParameter($id));
}
return $question;
}
}

becomes...
Code:
class questionActions extends sfActions {
//this is a cooment
   private function getQuestionOrCreate ($id = 'id')
   {
      //this is another comment
      if (!$this->getRequestParameter($id, 0)) {
         $question = new Question();
      }
      else {
         $question = QuestionPeer::retrieveByPk($this->getRequestParameter($id));
      }
      return $question;
   }
}

The only possible exception to the {} rule that I'm aware of is switch:

Code:
switch (key) {
case value:
$foo='bar';
break;

default:
break;
}

becomes...
Code:
switch (key) {
   case value:
      $foo='bar';
      break;

   default:
      break;
}


Hope that still looks lightweight Smile
View user's profileFind all posts by jonphippsSend private message
Site Admin

Joined: 13 Jul 2003
Posts: 8335
Reply with quote
looks good with one notice Smile

if
Quote:
//this is another comment
went with
Quote:
if (!$this->getRequestParameter($id, 0)) {
, why
Quote:
//this is a comment
didn't go with
Quote:
private function getQuestionOrCreate ($id = 'id')
?

to me the resulting code should look like:

Code:
class questionActions extends sfActions {
   //this is a cooment
   private function getQuestionOrCreate ($id = 'id')
   {
      //this is another comment
      if (!$this->getRequestParameter($id, 0)) {
         $question = new Question();
      }
      else {
         $question = QuestionPeer::retrieveByPk($this->getRequestParameter($id));
      }
      return $question;
   }
}

or did I miss a point?
View user's profileFind all posts by dmitriSend private messageVisit poster's website


Joined: 03 Mar 2004
Posts: 40
Reply with quote
ddmitrie wrote:
or did I miss a point?

No. You're quite right. I was trying to sneak in a personal thing and you caught me Wink

Sometimes, when I'm commenting code in order to test alternatives, I'll deliberately put the comment slashes on the left margin so that I can easily find disabled code, as opposed to real comments:
Code:
//        if (!$this->getRequestParameter($id, 0)) {
        if (!$this->getRequestParameter($id, 0)) {

Most automatic indenting routines do just as you say and align the comment:
Code:
        //        if (!$this->getRequestParameter($id, 0)) {
        if (!$this->getRequestParameter($id, 0)) {

And then I have to manually move them back over to the margin, or delete the commented code, or wait to adjust the indents. This is actually not a very big deal, but it would be a nice thing, for me at least. But I'll bet it would result in a support question or two. Smile
View user's profileFind all posts by jonphippsSend private message
Site Admin

Joined: 13 Jul 2003
Posts: 8335
Reply with quote
so the lines with comments one the leftmost positions should not be re-indented Smile
View user's profileFind all posts by dmitriSend private messageVisit poster's website


Joined: 03 Mar 2004
Posts: 40
Reply with quote
Yes. That would be great.
View user's profileFind all posts by jonphippsSend private message
reindent 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