Skip to content

Instantly share code, notes, and snippets.

@scheakur
Created September 7, 2011 16:05
Show Gist options
  • Save scheakur/1200976 to your computer and use it in GitHub Desktop.
Save scheakur/1200976 to your computer and use it in GitHub Desktop.
XML folding
setlocal foldtext=MakeXMLFoldingLabelByConcatenatingNextLine()
function! MakeXMLFoldingLabelByConcatenatingNextLine()
if getline(v:foldstart) !~# '^\s*<propert\(y\|ies\)\s\+name="[^"]\+"'
return foldtext()
endif
let l:line = s:shorten(getline(v:foldstart) . getline(v:foldstart + 1))
return l:line
endfunction
function! s:shorten(line)
let l:rv = substitute(a:line, '<propert\(y\|ies\)\s\+name="\([^"]\+\)"', '<\2', 'g')
let l:rv = substitute(l:rv, '\s*value=', '=', 'g')
let l:rv = substitute(l:rv, '\(<[a-zA-Z0-9\-]*\)>\s*<', '\1 ', 'g')
return l:rv
endfunction
setlocal foldmethod=syntax
let g:xml_syntax_folding = 1
<property name="foo">
<property name="bar">
<property name="id" value="aaa" />
</property>
<property name="bar">
<property name="id" value="bbb" />
</property>
<property name="bar">
<property name="id" value="ccc" />
</property>
</property>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment