1

I come from an Eclipse/Vim background, and I've just started using Emacs for the first time for editing my PHP files.

I've recently taken over a chunk of PHP files, and the existing code formatting is inconsistent and *very* poor.

if (condition   &&      condition)      {    
    }

if (condition   &&      condition)      
{

$var            =   "val"        // comment

    }
$var2      =           "val2"       // comment
//...

In Eclipse and Vim, I can format source files(Java and C/C++ respectively), and the IDE will take care of indentation, code style, and code cleanup. This means removing unnecessary white space, bracing properly, inserting/removing newlines where appropriate, etc.

How do I do this in Emacs with PHP files? I'm using PHP-mode in nxhtml, and I've figured out the indentation portion, so all my PHP is indented(tabbed) properly, but the rest of the code is still out of whack.

For example, in the above code, how do I specify brace style and spacing rules?

4
  • That's computer generated code ... right? A human didn't actually write that. Commented Dec 28, 2010 at 8:35
  • No, a human wrote that. The previous developer was in a rush and hand formatted alot of code in another IDE(notepad++ or wordpad I think). Commented Dec 28, 2010 at 8:39
  • They're not IDEs :) Don't know Emacs but the feature is called auto-indentation: emacswiki.org/emacs/AutoIndentation Commented Dec 28, 2010 at 9:08
  • That solves indentation issues, but doesn't remove unnecessary white space nor fix brace style. Commented Dec 28, 2010 at 9:16

2 Answers 2

2

Maybe PHP Beautifier PEAR package would do what you need? E.g. just use the command line tool on the files and make them proper.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, looks like the tool I need.
1

Emacs' php modes can only do indentation for you. You need to run it through some external tool to fix that formatting.

1 Comment

Thanks, I was searching forever in Emacs if that was possible.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.