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 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分
  • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题