Emacs xml模式缩进,带有选项卡

eci*_*eci 4 xml emacs sgml indentation

我拼命尝试使用制表符而不是空格来制作我的emacs xml(sgml?)模式缩进.到目前为止我尝试了什么:

(defun my-xml-hook ()
  (setq c-tab-always-indent t
        tab-width 4
        indent-tabs-mode t) ; use tabs for indentation
  (setq indent-line-function 'insert-tab)
)
(add-hook 'xml-mode-hook 'my-xml-hook)
(defun local-sgml-mode-hook
  (setq fill-column 70
        indent-tabs-mode t
        next-line-add-newlines nil
        sgml-indent-data t)
  (auto-fill-mode t)
  (setq indent-line-function 'insert-tab)
  )
(add-hook 'psgml-mode-hook '(lambda () (local-psgml-mode-hook)))
Run Code Online (Sandbox Code Playgroud)

没有什么可行,编辑*.xml文件时,仍会在2个空格(emacs23和emacs24)中出现缩进.

请注意,我也有

(setq indent-tabs-mode nil)
Run Code Online (Sandbox Code Playgroud)

在我的.emacs文件中,但是之后应该调用钩子,所以应该重写它.

如何强制emacs缩进*.xml文件中的选项卡?为什么我的钩子不起作用?

jua*_*eon 7

(c-)tab-always-indent 控制击中TAB键的内容,而不是插入的内容.

设置indent-line-functioninsert-tab将使您失去模式的智能缩进.

如果您使用的是现代emacs,则可能使用的是nxml-mode而不是xml-mode.在那种情况下nxml-mode-hook应该是你应该做的事情(setq indent-tabs-mode t).

如果你使用的是默认的sgml模式,sgml-mode-hook应该是(setq indent-tabs-mode t)应该完成的那个(在你正在使用的代码片段中psgml-mode-hook)

(并且tab-always-indent和indent-line-function可以保持默认状态)

编辑

总结下面的对话:变量nxml-child-indent不应小于tab-width.

(并且因为这些变量的默认emacs值是2和8,所以imho配置emacs以使用emacs中的选项卡缩进XML比应该更难)

  • 还尝试增加“nxml-child-indent” (2认同)