i desperately try to make my emacs xml (sgml?) mode indent with tabs instead of spaces. What i tried so far:
(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)))
Nothing works though, indentation will still happen with 2 spaces (emacs23 and emacs24) when editing *.xml files.
Note that i also have
(setq indent-tabs-mode nil)
in my .emacs file, but the hook should be called afterwards so this should be overridden.
How can i force emacs to indent with tabs in *.xml files? Why are my hooks not working?
To insert an indented line before the current line, do C-a C-o TAB . To make an indented line after the current line, use C-e C-j . If you just want to insert a tab character in the buffer, you can type C-q TAB .
To manually insert a tab in Emacs, use ctrl-Q TAB. control-Q causes the next key to be inserted rather than interpreted as a possible command.
nXML mode is an Emacs major-mode for editing XML documents. It supports editing well-formed XML documents, and provides schema-sensitive editing using RELAX NG Compact Syntax. To get started, visit a file containing an XML document, and, if necessary, use M-x nxml-mode to switch to nXML mode.
This is because standard tabs are set to eight spaces. Tabs are special characters.
(c-)tab-always-indent
controls what hitting the TAB key does, not what is inserted.
Setting indent-line-function
to insert-tab
will make you lose the smart indentation of the mode.
If you are using a modern emacs, chances are you are using nxml-mode instead of xml-mode. In that case nxml-mode-hook
should be the one where you should do (setq indent-tabs-mode t)
.
If you are using default sgml mode, sgml-mode-hook
should be the one where you should do (setq indent-tabs-mode t)
should be done (in your snippet you are using psgml-mode-hook
)
(and tab-always-indent and indent-line-function could be leave in their default states)
EDIT
To summarize conversation below: variable nxml-child-indent
should not be less than tab-width
.
(and since default emacs values for those variables are 2 and 8, imho configuring emacs to indent XML using tabs in emacs is harder than it should be)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With