我的php代码无法正确缩进...
我希望我的代码看起来像这样
if (foo)
{
print "i am indented";
}
但它总是这样:
if (foo)
{
print "i am not indented correctly";
}
我厌倦了谷歌搜索类似的东西,并尝试将以下内容添加到我的.emacs,但它根本不起作用。
有什么想法吗?
(add-hook 'php-mode-hook
(function (lambda ()
;; GNU style
(setq php-indent-level 4
php-continued-statement-offset 4
php-continued-brace-offset 0
php-brace-offset 0
php-brace-imaginary-offset 0
php-label-offset -4))))
答案 0 :(得分:12)
自定义c-default-style变量。将其添加到.emacs文件中:
(setq c-default-style "bsd"
c-basic-offset 4)
答案 1 :(得分:1)
自定义变量c-default-style。您要么将“其他”模式(或“php”,如果可用)设置为“bsd”,要么将所有模式中的hte样式设置为bsd。
据我所知,PHP模式建立在c模式之上,因此它继承了自定义。
答案 2 :(得分:1)
试试这个:
(defun my-build-tab-stop-list (width)
(let ((num-tab-stops (/ 80 width))
(counter 1)
(ls nil))
(while (<= counter num-tab-stops)
(setq ls (cons (* width counter) ls))
(setq counter (1+ counter)))
(nreverse ls)))
(add-hook 'c-mode-common-hook
#'(lambda ()
;; You an remove this, if you don't want fixed tab-stop-widths
(set (make-local-variable 'tab-stop-list)
(my-build-tab-stop-list tab-width))
(setq c-basic-offset tab-width)
(c-set-offset 'defun-block-intro tab-width)
(c-set-offset 'arglist-intro tab-width)
(c-set-offset 'arglist-close 0)
(c-set-offset 'defun-close 0)
(setq abbrev-mode nil)))