繁体   English   中英

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

[英]Emacs xml mode indent with tabs

我拼命尝试使用制表符而不是空格来制作我的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)))

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

请注意,我也有

(setq indent-tabs-mode nil)

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

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

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

indent-line-function设置为insert-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-mode才得到nxml-mode来使用标签。 我最终使用了smart-tabs-mode ,它提供了一个简洁的解决方案。 对于它的价值,这里是我最终确定的配置:

;; indentation using smart-tabs-mode
(setq-default tab-width 4)
(smart-tabs-insinuate 'c 'c++ 'java 'javascript 'cperl 'python 'ruby 'nxml)

;; nxml-mode
(setq 
    nxml-child-indent 4
    nxml-attribute-indent 4
    nxml-slash-auto-complete-flag t)

您实际上不需要设置nxml-slash-auto-complete-flag ,但它会让您自动完成标记,这非常好。

暂无
暂无

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

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