[TxMt] Re: Re -indenting XML with tag on multiple lines

Alessandro Vernet avernet at scdi.org
Fri Oct 9 18:41:01 UTC 2009


Daniel,


Daniel Stockman wrote:
> 
> The reason this doesn't work, sadly, is due to a limitation of the  
> folding engine. In a nutshell, the "closing" fold needs to be at the  
> same tab stop as the "opening". In my experience the indenting  
> behaviour maps fairly consistently with the folding behaviour.
> 
> A workaround to make the example fold, and perhaps re-indent properly:
> 
> <gaga>
>      <bar at1="" at2="" at3="" at4="" at5=""
>          at6="" at7="" at8="" at9="" at10=""
>      />
>      gaga
> </gaga>
> 
> Less than ideal, I'll grant, but you get used to it.
> 

The issue is that I often use the re-indent command on code that I haven't
written myself, to make it more readable. (It is amazing to me how some
people manage to get any work done on totally badly indented XML files!) So
I don't have the option of putting the /> on a new line.

As a workaround, I changed decreaseIndentPattern to kick in when it finds a
/> on a line where there is no corresponding <. So you would get the
following:

<foo>
    <bar
        a1="v1"
        a2="v2"
    a3="v3"/>
    <bar/>
</foo>

The a3="v3" is not properly aligned with the a2="v2", but at least the
remainder of the code around is properly indented. With this updated
decreaseIndentPattern, if you put the /> on a new line, as you suggested,
you also get the correct indentation:

<foo>
    <bar
        a1="v1"
        a2="v2"
        a3="v3"
    />
    <bar/>
</foo>

Not ideal, but I think an improvement over the default pattern. Here is the
updated pattern:

decreaseIndentPattern = '^\s*(</[^>]+>|-->|--%>|[^<]*/>)';

Alex

-----
Orbeon Forms - Web 2.0 Forms, open-source, for the Enterprise
Orbeon's Blog: http://www.orbeon.com/blog/
Personal Blog: http://avernet.blogspot.com/
Twitter - http://twitter.com/avernet
-- 
View this message in context: http://www.nabble.com/Re-indenting-XML-with-tag-on-multiple-lines-tp25672686p25826004.html
Sent from the textmate users mailing list archive at Nabble.com.




More information about the textmate mailing list