unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Indentation contest nxml vs xml-mode
@ 2008-03-06 18:41 Lennart Borgman (gmail)
  2008-03-06 18:50 ` Drew Adams
  2008-03-07  0:28 ` Miles Bader
  0 siblings, 2 replies; 10+ messages in thread
From: Lennart Borgman (gmail) @ 2008-03-06 18:41 UTC (permalink / raw)
  To: Emacs Devel

Try indenting the following in nxml-mode and xml-mode:

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

I think xml-mode wins here. If I remember correctly there are also some 
bugs in nxml-mode indentattion code. Is there any reason to have both 
ways of indenting, ie should not nxml-mode indentation use the xml-mode 
indentation code?




^ permalink raw reply	[flat|nested] 10+ messages in thread

* RE: Indentation contest nxml vs xml-mode
  2008-03-06 18:41 Indentation contest nxml vs xml-mode Lennart Borgman (gmail)
@ 2008-03-06 18:50 ` Drew Adams
  2008-03-06 21:52   ` Lennart Borgman (gmail)
  2008-03-06 22:18   ` Jason Rumney
  2008-03-07  0:28 ` Miles Bader
  1 sibling, 2 replies; 10+ messages in thread
From: Drew Adams @ 2008-03-06 18:50 UTC (permalink / raw)
  To: 'Lennart Borgman (gmail)', 'Emacs Devel'

> Try indenting the following in nxml-mode and xml-mode:
> 
> <outermost>
>    <inner1><inner2>
>        <inner3>Duh</inner3>
>      </inner2>
>    </inner1>
> </outermost>
> 
> I think xml-mode wins here. If I remember correctly there are 
> also some 
> bugs in nxml-mode indentattion code. Is there any reason to have both 
> ways of indenting, ie should not nxml-mode indentation use 
> the xml-mode indentation code?

Can you please just present the two alternatives here, so we don't have to
go through the exercise? Thx.





^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Indentation contest nxml vs xml-mode
  2008-03-06 18:50 ` Drew Adams
@ 2008-03-06 21:52   ` Lennart Borgman (gmail)
  2008-03-06 22:21     ` Drew Adams
  2008-03-06 22:18   ` Jason Rumney
  1 sibling, 1 reply; 10+ messages in thread
From: Lennart Borgman (gmail) @ 2008-03-06 21:52 UTC (permalink / raw)
  To: Drew Adams; +Cc: 'Emacs Devel'

Drew Adams wrote:
>> Try indenting the following in nxml-mode and xml-mode:
>>
>> <outermost>
>>    <inner1><inner2>
>>        <inner3>Duh</inner3>
>>      </inner2>
>>    </inner1>
>> </outermost>
>>
>> I think xml-mode wins here. If I remember correctly there are 
>> also some 
>> bugs in nxml-mode indentattion code. Is there any reason to have both 
>> ways of indenting, ie should not nxml-mode indentation use 
>> the xml-mode indentation code?
> 
> Can you please just present the two alternatives here, so we don't have to
> go through the exercise? Thx.

My main point was of course to have only one code to do the indentation 
(I think there might be bugs in both versions today), but here is the 
output:

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

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

BTW, I just noted that the person that sent me the bug report long ago 
put a "duh" in the text. ;-)




^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Indentation contest nxml vs xml-mode
  2008-03-06 18:50 ` Drew Adams
  2008-03-06 21:52   ` Lennart Borgman (gmail)
@ 2008-03-06 22:18   ` Jason Rumney
  2008-03-06 22:34     ` Lennart Borgman (gmail)
  2008-03-07  3:31     ` Drew Adams
  1 sibling, 2 replies; 10+ messages in thread
From: Jason Rumney @ 2008-03-06 22:18 UTC (permalink / raw)
  To: Drew Adams; +Cc: 'Lennart Borgman (gmail)', 'Emacs Devel'

Drew Adams wrote:
>> Try indenting the following in nxml-mode and xml-mode:
>>
>> <outermost>
>>    <inner1><inner2>
>>        <inner3>Duh</inner3>
>>      </inner2>
>>    </inner1>
>> </outermost>
>>
>> I think xml-mode wins here.

This has been discussed here before. Try it with some real elements...

<html>
  <body><b>
    <i>Duh</i>
    </b>
  </body>
</html>

Which indentation looks more correct now?

nxml's indentation is based on the fact that you are using <inner2> in a 
way that suggests that it has inline, not block semantics.





^ permalink raw reply	[flat|nested] 10+ messages in thread

* RE: Indentation contest nxml vs xml-mode
  2008-03-06 21:52   ` Lennart Borgman (gmail)
@ 2008-03-06 22:21     ` Drew Adams
  2008-03-06 22:38       ` Lennart Borgman (gmail)
  0 siblings, 1 reply; 10+ messages in thread
From: Drew Adams @ 2008-03-06 22:21 UTC (permalink / raw)
  To: 'Lennart Borgman (gmail)'; +Cc: 'Emacs Devel'

> ***** 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.





^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Indentation contest nxml vs xml-mode
  2008-03-06 22:18   ` Jason Rumney
@ 2008-03-06 22:34     ` Lennart Borgman (gmail)
  2008-03-07  3:31     ` Drew Adams
  1 sibling, 0 replies; 10+ messages in thread
From: Lennart Borgman (gmail) @ 2008-03-06 22:34 UTC (permalink / raw)
  To: Jason Rumney; +Cc: Drew Adams, 'Emacs Devel'

Jason Rumney wrote:
> Drew Adams wrote:
>>> Try indenting the following in nxml-mode and xml-mode:
>>>
>>> <outermost>
>>>    <inner1><inner2>
>>>        <inner3>Duh</inner3>
>>>      </inner2>
>>>    </inner1>
>>> </outermost>
>>>
>>> I think xml-mode wins here.
> 
> This has been discussed here before. Try it with some real elements...
> 
> <html>
>  <body><b>
>    <i>Duh</i>
>    </b>
>  </body>
> </html>
> 
> Which indentation looks more correct now?

I am not sure, but the main thing is if we can get rid of one of those 
(and I suggest to get rid of nxml-mode's variant because I think there 
is a bug there).

> nxml's indentation is based on the fact that you are using <inner2> in a 
> way that suggests that it has inline, not block semantics.





^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Indentation contest nxml vs xml-mode
  2008-03-06 22:21     ` Drew Adams
@ 2008-03-06 22:38       ` Lennart Borgman (gmail)
  2008-03-07  3:31         ` Drew Adams
  0 siblings, 1 reply; 10+ messages in thread
From: Lennart Borgman (gmail) @ 2008-03-06 22:38 UTC (permalink / raw)
  To: Drew Adams; +Cc: Jason Rumney, 'Emacs Devel'

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?




^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Indentation contest nxml vs xml-mode
  2008-03-06 18:41 Indentation contest nxml vs xml-mode Lennart Borgman (gmail)
  2008-03-06 18:50 ` Drew Adams
@ 2008-03-07  0:28 ` Miles Bader
  1 sibling, 0 replies; 10+ messages in thread
From: Miles Bader @ 2008-03-07  0:28 UTC (permalink / raw)
  To: Lennart Borgman (gmail); +Cc: Emacs Devel

"Lennart Borgman (gmail)" <lennart.borgman@gmail.com> writes:
> I think xml-mode wins here.

Both packages seem to do a good job of attempting to make some sense out
of a rather weird example.

-Miles

-- 
In New York, most people don't have cars, so if you want to kill a person, you
have to take the subway to their house.  And sometimes on the way, the train
is delayed and you get impatient, so you have to kill someone on the subway.
  [George Carlin]




^ permalink raw reply	[flat|nested] 10+ messages in thread

* RE: Indentation contest nxml vs xml-mode
  2008-03-06 22:18   ` Jason Rumney
  2008-03-06 22:34     ` Lennart Borgman (gmail)
@ 2008-03-07  3:31     ` Drew Adams
  1 sibling, 0 replies; 10+ messages in thread
From: Drew Adams @ 2008-03-07  3:31 UTC (permalink / raw)
  To: 'Jason Rumney'
  Cc: 'Lennart Borgman (gmail)', 'Emacs Devel'

> Drew Adams wrote:
> >> Try indenting the following in nxml-mode and xml-mode:
> >>
> >> <outermost>
> >>    <inner1><inner2>
> >>        <inner3>Duh</inner3>
> >>      </inner2>
> >>    </inner1>
> >> </outermost>
> >>
> >> I think xml-mode wins here.

(For the record, I did not write that; Lennart did. I wrote that both
indentation styles shown are poor.)

> This has been discussed here before. Try it with some real elements...
> 
> <html>
>   <body><b>
>     <i>Duh</i>
>     </b>
>   </body>
> </html>
> 
> Which indentation looks more correct now?

Again, neither is great, IMO. It is not obvious with your indentation that
<i> is a child of <b>. I would always indent a child inside its parent,
unless there is no choice. Try reading a 10-page XML schema whose
indentation doesn't help you see the hierarchy. Indentation is important to
human readers, even when it is insignificant in terms of XML semantics.

> nxml's indentation is based on the fact that you are using 
> <inner2> in a way that suggests that it has inline, not block semantics.

What are "inline" and "block" semantics? There are no semantics implied by
XML indentation, unless indenting changes significant whitespace (which it
should not).

Of course, anyone or any program is free to add additional semantics (their
own interpretation) to code, but there is no such difference in the XML
standards.






^ permalink raw reply	[flat|nested] 10+ messages in thread

* RE: Indentation contest nxml vs xml-mode
  2008-03-06 22:38       ` Lennart Borgman (gmail)
@ 2008-03-07  3:31         ` Drew Adams
  0 siblings, 0 replies; 10+ messages in thread
From: Drew Adams @ 2008-03-07  3:31 UTC (permalink / raw)
  To: 'Lennart Borgman (gmail)'
  Cc: 'Jason Rumney', 'Emacs Devel'

> 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?

The significance or not of whitespace is not something up for a vote or a
beauty contest. It is well-defined for XML. And XHTML is XML.

What you might be trying to say is that many programs that use XHTML code do
not, themselves, detect or make use of whitespace that is, technically
speaking, significant (in terms of XML). That is another matter entirely.

Whether you or a Web browser does or does not actually distinguish between
two documents that differ in significant XML whitespace is not the point. 

There is a big difference between XML documents or fragments being
indistinguishable in terms of significant whitespace and their being
distinguishable. XML tools and databases go to great pains to preserve and
restore significant whitespace, even when they sacrifice insignificant
whitespace.

It's fine to have tools that also let you preserve insignificant whitespace
(that's sometimes important), or that also let you sacrifice whitespace that
is significant in terms of its XML meaning but might not be significant to
you. But tools should at a minimum have a mode that lets you preserve
significant whitespace. And indentation should not gratuitously alter
significant whitespace. Doing that would be akin to TAB indenting text in
the middle of a Lisp string.





^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2008-03-07  3:31 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-03-06 18:41 Indentation contest nxml vs xml-mode Lennart Borgman (gmail)
2008-03-06 18:50 ` Drew Adams
2008-03-06 21:52   ` Lennart Borgman (gmail)
2008-03-06 22:21     ` Drew Adams
2008-03-06 22:38       ` Lennart Borgman (gmail)
2008-03-07  3:31         ` Drew Adams
2008-03-06 22:18   ` Jason Rumney
2008-03-06 22:34     ` Lennart Borgman (gmail)
2008-03-07  3:31     ` Drew Adams
2008-03-07  0:28 ` Miles Bader

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).