Can't change Emacs's default indentation between HTML tags

扶醉桌前 提交于 2019-12-03 12:03:11

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/2076783/cant-change-emacss-default-indentation-between-html-tags

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!