无法更改Emacs在HTML标签之间的默认缩进 [英] Can't change Emacs's default indentation between HTML tags

查看:154
本文介绍了无法更改Emacs在HTML标签之间的默认缩进的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对Emacs缩进范例感到困惑。



我在我的 .emacs 文件中有这个:

 (setq-default tab-width 4)

如果在以下情况下按TAB

 < ul> 
(caret)
< / ul>

最终如此

 < ul> 
(caret)
< / ul>

(HTML标签之间有2个空格缩进。)



应该这样结束:

 < ul> 
(caret)
< / ul>

我尝试过一切:

 (setq-default tab-width 4)
(setq-default indent-tabs-mode t)
(setq tab-stop-list'(4 8 12 16))

我已经将所有可能的Emacs设置缩进为4,但是还有2个空格缩进。



任何建议?

解决方案

设置标签宽度不是在这种情况下适用,但我明白你的困惑; Emacs提供了几个与Tab相关的变量,并且为特定场景确定正确的变量可能会令人困惑。



这个EmacsWiki文章提供了关于设置HTML的缩进级别的更多细节;一般来说, EmacsWiki 是Emacs提示的一个很好的资源。



在这种特定情况下,由于您使用Emacs的标准HTML模式( html-mode ,由 sgml-mode ),您要设置的变量是 sgml-basic-offset 。该变量默认为2,但是您可以将其更改为4,如下所示:

 (setq sgml-basic-offset 4)

要使此更改仅对 html-mode ,可以使用以下代码:

 (add-hook'html-mode-hook 
(lambda )
;;默认缩进通常为2个空格,更改为4.
(set(make-local-variable'sgml-basic-offset)4)))

这一切都假定您正在使用Emacs 22或更高版本;如果不是这样,我链接的EmacsWiki页面包含早期版本的Emacs的解决方法。


I'm confused about the Emacs indentation paradigm.

I have this in my .emacs file:

(setq-default tab-width 4)

If I press TAB in the following situation

                    <ul>
(caret)
                    </ul>

it end up like this

                   <ul>
                     (caret)
                   </ul>

(with 2 spaces indentation between the HTML tags.)

It should end up like this:

                   <ul>
                       (caret)
                   </ul>

I tried everything:

(setq-default tab-width 4)
(setq-default indent-tabs-mode t)
(setq tab-stop-list '(4 8 12 16))

I've set every possible Emacs setting about indentation to 4 but that 2 space indentation is still there.

Any suggestions?

解决方案

Setting the tab width isn't applicable in this scenario, but I understand your confusion; Emacs provides several tab-related variables and determining the correct one for a particular scenario can be confusing.

This EmacsWiki article provides more details about setting the indentation level for HTML; in general, EmacsWiki is a great resource for Emacs tips.

In this specific case, since you're using Emacs' standard HTML mode (html-mode, as defined by sgml-mode), the variable that you want to set is sgml-basic-offset. That variable defaults to 2, but you can change it to 4 as follows:

(setq sgml-basic-offset 4)

To make this change specific only to html-mode, you can use the following code:

(add-hook 'html-mode-hook
  (lambda ()
    ;; Default indentation is usually 2 spaces, changing to 4.
    (set (make-local-variable 'sgml-basic-offset) 4)))

This all assumes that you're using Emacs 22 or later; if that's not the case, the EmacsWiki page that I linked to contains a workaround for earlier versions of Emacs.

这篇关于无法更改Emacs在HTML标签之间的默认缩进的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆