drws65968272 2012-09-03 23:16
浏览 99
已采纳

Emacs PHP缩进

I am using Emacs with php-mode.el: http://php-mode.sourceforge.net/php-mode.el.html

I have the following lines in my .emacs file:

(load-file "~/.emacs.d/php-mode.el")
(require 'php-mode)
(setq c-default-style "linux" c-basic-offset 4)

It is working really nicely for the most part. The issue is that for certain bits of code Emacs displays the code differently to other editors. For example, I have the following code in Emacs:

public function showStuff($items, $Stuff) {
    $restrict = true;
    $stuff  = false;
    $moreStuff = true;

    if (($restrict && $stuff >= $moreStuff) 
        || ( $moreStuff > 10)) {
        return true;
    }           
    return false;
}

But viewing the same file in Eclipse/Sublime Text/Text Wrangler looks like:

public function showStuff($items, $Stuff) {
    $restrict = true;
    $stuff  = false;
    $moreStuff = true;

    if (($restrict && $stuff >= $moreStuff) 
    || ( $moreStuff > 10)) {
    return true;
    }           
    return false;
}

Can anyone comment on why I am seeing these results and a possible solution?

Thanks.

  • 写回答

2条回答 默认 最新

  • dongshenyu4638 2012-09-05 00:11
    关注

    As it seems you want to use spaces rather than tabs, I think this is basically a duplicate of:

    I can't find this: How do I use 4 SPACES instead of a TAB in EMACS?

    Or if you wanted this only for PHP files, then you would use:

    (add-hook 'php-mode-hook 'my-php-mode-hook)
    (defun my-php-mode-hook ()
      "My PHP mode configuration."
      (setq indent-tabs-mode nil
            tab-width 4
            c-basic-offset 4))
    

    Before that, with the code looking correct in Emacs, convert the tabs to spaces with:

    • <kbd>C-x</kbd><kbd>h</kbd>
    • <kbd>M-x</kbd> untabify <kbd>RET</kbd>

    I would also take a look at:
    http://www.emacswiki.org/emacs/CategoryIndentation

    (or take note of it, at least -- indentation can be trickier than expected in Emacs, and there's lots of good information there.)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 用ns3仿真出5G核心网网元
  • ¥15 matlab答疑 关于海上风电的爬坡事件检测
  • ¥88 python部署量化回测异常问题
  • ¥30 酬劳2w元求合作写文章
  • ¥15 在现有系统基础上增加功能
  • ¥15 远程桌面文档内容复制粘贴,格式会变化
  • ¥15 关于#java#的问题:找一份能快速看完mooc视频的代码
  • ¥15 这种微信登录授权 谁可以做啊
  • ¥15 请问我该如何添加自己的数据去运行蚁群算法代码
  • ¥20 用HslCommunication 连接欧姆龙 plc有时会连接失败。报异常为“未知错误”