开发者

Auto formatting a PHP file in emacs

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 unnece开发者_开发百科ssary 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?


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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜