A style guide for DocBook XML that I must adhere to states "Content within elements should be indented by two spaces if the content runs over more than one line." They give this example.

<para>See the <link
  section if there are problems booting.  Powering down and
  disconnecting the original <filename>ada0</filename> disk
  will allow it to be kept as an offline backup.</para>

<para>It is also possible to journal the boot disk of a &os;
  system.  Refer to the article <link
    xlink:href="&url.articles.gjournal-desktop;">Implementing UFS
    Journaling on a Desktop PC</link> for detailed

They also state that,

Tags containing long attributes follow the same rules. See the linkend element of the link tag.

None of the customizable nxml-mode variables seem to help. In fact, some of the docstrings describe the opposite behaviour.


This only applies when the line or lines containing the start-tag contains nothing else other than that start-tag.


Indentation for the attributes of an element relative to the start-tag.

I think I prefer keeping opening an closing tags on separate lines like nxml-mode promotes. Unfortunately the guide specifically prohibits some "straggling" tags (tags on their own line).

Am I out of luck conforming to this style guide with nxml-mode?

1 Answer 1


I believe you're indeed partly out of luck. nxml-mode is good at parsing the file and providing on the fly validation, but indentation was a secondary goal. You would probably be better served by sgml-mode's indentation.

This said, you could try

(add-hook 'nxml-mode-hook
          (lambda ()
            (require 'sgml-mode)
            (setq-local indent-line-function #'sgml-indent-line)))

It's quite possible that it will misbehave in various cases (e.g. because the syntax-tables are setup very differently), but if you're interested, I'd be happy to try and help you get it working well and integrate that change into Emacs.

  • I had considered something similar after noticing sgml-mode indents in way that (nearly) matches the style guide. Unfortunately, locally setting indent-line-function to sgml-indent-line seems to completely break indenting in nxml-mode. Thanks for your offer to help. I will have a look at the code and depending on what I find, I may take you up on your offer.
    – jrm
    Jul 15, 2016 at 14:33
  • A partial solution may be to create a variable nxml-continuation-offset. I think this could be used in nxml-compute-indent-from-matching-start-tag. If the default for nxml-continuation-offset were 0, then the default behaviour would not change. What do you think? Do you have any specific tips on how to do this?
    – jrm
    Jul 15, 2016 at 15:22
  • Also, would you prefer to move the discussion to emacs.devel?
    – jrm
    Jul 15, 2016 at 15:29
  • I think I spoke too soon when I said "locally setting indent-line-function to sgml-indent-line seems to completely break indenting in nxml-mode". It does improve some things, but a problem is the DocBook file I'm working on starts with a chapter tag. After setting the variable all indentation reports the chapter tag isn't closed and so the indentation for the rest of the file is borked.
    – jrm
    Jul 15, 2016 at 18:11
  • This problem with an unclosed tag seems like something that shouldn't be too hard to fix.
    – Stefan
    Jul 17, 2016 at 1:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.