在emacs中自动格式化一个PHP文件 [英] Auto formatting a PHP file in emacs

查看:170
本文介绍了在emacs中自动格式化一个PHP文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我来自Eclipse / Vim背景,我刚刚开始使用Emacs来编辑我的PHP文件。



我最近采取在一大堆PHP文件中,现有的代码格式不一致,* 非常 *差。

  if(condition&& condition){
}

if(condition&& condition)
{

$ var = val//注释

}
$ var2 =val2//注释
// ...

在Eclipse和Vim中,我可以格式化源文件(分别为Java和C / C ++),IDE将处理缩进,代码样式和代码清理。这意味着删除不必要的空格,正确支撑,适当插入/删除换行符等。



如何在Emacs中使用PHP文件?我在nxhtml中使用PHP模式,我已经弄清了缩进部分,所以我的所有PHP都正确缩进(标签),但是其余的代码仍然没有。



例如,在上面的代码中,如何指定大括号风格和间距规则?

解决方案

也许 PHP Beautifier PEAR包将会做你所需要的?例如。只需使用文件上的命令行工具,使其正确。


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?

解决方案

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文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆