emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: Indentation contest nxml vs xml-mode


From: Drew Adams
Subject: RE: Indentation contest nxml vs xml-mode
Date: Thu, 6 Mar 2008 14:21:28 -0800

> ***** xml-mode
> <outermost>
>    <inner1><inner2>
>        <inner3>Duh</inner3>
>      </inner2>
>    </inner1>
> </outermost>
> 
> ***** nxml-mode
> <outermost>
>    <inner1><inner2>
>      <inner3>Duh</inner3>
>    </inner2>
>    </inner1>
> </outermost>

IMO, neither is great (both are ugly and confusing). I've never seen XML
indented like either of those (except when it wasn't formatted at all).
FWIW, I use this:

<outermost>
  <inner1><inner2>
            <inner3>Duh</inner3>
          </inner2>
  </inner1>
</outermost>

IOW: 1. Align opening and closing tags. 2. Indent just enough so that nested
tags start after the </ of their parent.

Why? Because (1) you need to be able to easily find corresponding tags and
(2) XML is verbose, so the less indentation the better. You could indent
only one space, but I think it's more readable with two.

Another possibility is what we (most of us) use in Lisp - avoid starting
lines with closing tags:

<outermost>
  <inner1><inner2>
            <inner3>Duh</inner3></inner2></inner1>
  <inner1>some more</inner1></outermost>

That can also work well in some contexts.

I present lots of XML in doc everyday. I haven't found anything more
readable than just indenting two spaces and aligning the corresponding
element tags. I also align attributes. But I never, ever introduce or change
significant whitespace, such as that within a text() node, if I can avoid
it. For example, I never indent the text here:

       <foo>some text that is too
long for a printed line</foo>

That should never be changed by automatic indentation to, say, this:

       <foo>some text that is too
       long for a printed line</foo>

or this:

       <foo>some text that is too
            long for a printed line
       </foo>

or anything else - it should not be changed at all. If the representation
(e.g. HTML or PDF doc) can't reasonably let it wrap naturally (without,
e.g., introducing a scroll bar), then a single newline is best, with no
indentation. Readers will get the idea that it represents wrapped text and
it really isn't split at all.

I mention this because there was some question here a while back about it.
Indentation (e.g. pretty-printing) should avoid changing significant
whitespace.

HTH.





reply via email to

[Prev in Thread] Current Thread [Next in Thread]