drws65968272 2012-09-03 15: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-04 16: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 某东JD算法逆向算法
  • ¥15 求GCMS辅导数据分析
  • ¥30 SD中的一段Unet下采样代码其中的resnet是谁跟谁进行残差连接
  • ¥15 Unet采样阶段的res_samples问题
  • ¥60 Python+pygame坦克大战游戏开发实验报告
  • ¥15 R语言regionNames()和demomap()无法选中中文地区的问题
  • ¥15 Open GL ES 的使用
  • ¥15 我如果只想表示节点的结构信息,使用GCN方法不进行训练可以吗
  • ¥15 QT6将音频采样数据转PCM
  • ¥15 下面三个文件分别是OFDM波形的数据,我的思路公式和我写的成像算法代码,有没有人能帮我改一改,如何解决?
手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部