3

I'm using Eclipse Helios with PHPEclipse, which works great, but I can't seem to get the formatter (Ctrl-Shift-F) to work with highlighted code. It doesn't really seem to do anything. Does anyone know if there is a way to edit the settings (i.e. import/export formatter settings, like in Eclipse Java) for PHPEclipse?

Basically, my problem is that it doesn't even do anything reasonable. If I have:

   class SomeClass {
     function myFunc() {
     if (isEnabled()
     ) 
   {
   // do something
   }
     }
   }

It won't move the brackets to the correct indentation. If it could even do that, I would be happy. :)

jwir3
  • 6,019
  • 5
  • 47
  • 92

2 Answers2

4

Select your code and hit Ctrl + I this will format the above code as follows:

class SomeClass {
    public function myFunc() {
        if (isEnabled()
        )
        {
            // do something
        }
    }
}

As far as I can find the only thing you can actually set relating to format is weather or not to use spaces or tabs for indentation.

Windows -> Preferences

Then:

PHP -> Code Style -> Formatter
James
  • 2,609
  • 3
  • 20
  • 27
  • Ah, ok. Well, this helps! I didn't have any way of fixing the indentation. Thanks a lot. – jwir3 Feb 07 '11 at 15:07
0

This is for Eclipse PDT!

From the top menu go to Window > Preferences

From the left side click on PHP to expand all of the settings for PHP.

Click Code Style to edit the code templates for PHP

In my eclipse installation, the result of formating your code

class SomeClass {
    function myFunc() {
        if (isEnabled()
        )
        {
            // do something
        }
    }
}

Hope this helps

satrun77
  • 3,202
  • 17
  • 20
  • Well, since I'm using PHPEclipse, I don't have a PHP menu item in the tree. I have a PHPEclipse option, and understand I have a PHP item, but underneath this, I do not have a Code Style option. The Formatter option has very few configurable settings, so this didn't really help... thanks, though. – jwir3 Feb 03 '11 at 15:29
  • I thought PHPEclipse == Eclipse PDT. I have installed PHPEclipse and it does not seem to be working! There is an option for code templates (PHPEclipse > PHP > Code Templates). Exporting the template xml file and modifying it then importing the new one does not do anything! – satrun77 Feb 03 '11 at 21:46
  • Yes, that is the crux of my question. – jwir3 Feb 04 '11 at 17:52