简体   繁体   English

在Emacs中设置PHP的初始缩进级别?

[英]Setting initial indent level for PHP in Emacs?

I typically code my PHP with one level of indentation after the initial <?php , but I'm having trouble finding a setting for this in Emacs with php-mode . 我通常在初始<?php之后用一级缩进来编写我的PHP代码,但是我在使用php-mode在Emacs中找到这个设置时遇到了麻烦。

To be clear, here's what Emacs is doing: 要清楚,这就是Emacs正在做的事情:

<?php
echo "Hello.";

if (something)
    do_something();

And here's how I usually code: 以下是我通常编码的方式:

<?php
    echo "Hello.";

    if (something)
        do_something();

Emacs version 23 (straight from CVS), php-mode 1.5.0. Emacs版本23(直接来自CVS),php-mode 1.5.0。

Found a solution, I think: 找到一个解决方案,我想:

(c-set-offset 'topmost-intro 4)
(c-set-offset 'cpp-macro -4)

Seems to be working. 似乎工作。 topmost-intro sets everything, and as far as I can tell cpp-macro only sets the <?php tags. topmost-intro设置一切,据我所知cpp-macro只设置<?php标签。

Thanks to Cheeso for the hint which led me to the answer. 感谢Cheeso的暗示,这让我得到了答案。

I don't have a php-mode, but in c-modes, Mx c-set-offset can help. 我没有php模式,但在c模式下,Mx c-set-offset可以提供帮助。 - it'll allow you to customize the offset for a syntactic element, and it shows you what element was used for the current line. - 它允许您自定义语法元素的偏移量,并显示当前行使用的元素。

php-mode derives from c-mode , so I think all you need is: php-mode派生于c-mode ,所以我认为你需要的只是:

(setq-default indent-tabs-mode nil)
(setq standard-indent 2)
(setq default-tab-width 2)
(add-hook 'c-mode-common-hook
  #'(lambda ()
    (setq c-basic-offset tab-width)))

If that's not what you meant, maybe you are looking for tab-stop-list ? 如果这不是你的意思,也许你正在寻找tab-stop-list

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM