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: Lennart Borgman (gmail)
Subject: Re: Indentation contest nxml vs xml-mode
Date: Thu, 06 Mar 2008 23:38:12 +0100
User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.9) Gecko/20071031 Thunderbird/2.0.0.9 Mnenhy/0.7.5.666

Drew Adams wrote:
***** 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>

Both your suggestions looks good IMO.

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>


Though as Jason (I believe) pointed out when we discussed it last time whitespace is not significant (most of the time ...) in XHTML, only in XML. But it is sometimes -- and those times are really hard to detect since they might depend on the style sheet, or?




reply via email to

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