Folding tags in emacs nxml-mode

5.5k Views Asked by At

The interwebs are full of ancient doctrines for folding code in the Glorious Emacs Editor. Among them are folding.el, outline-minor-mode, and fold-dwim.el. Alas, my poor unenlightened mind cannot write the necessary elisp configuration.

Please help a mortal fold tags in nxml-mode, preferably with TAB. If relevant, I use viper and vimpulse.

3

There are 3 best solutions below

3
hpavc On

Its called outlining in nxml-mode, its in section 5 of the nxml-mode documentation. Which begins ...

5 Outlining


nXML mode allows you to display all or part of a buffer as an outline, in a similar way to Emacs' outline mode. An outline in nXML mode is based on recognizing two kinds of element: sections and headings. There is one heading for every section and one section for every heading. A section contains its heading as or within its first child element. A section also contains its subordinate sections (its subsections). The text content of a section consists of anything in a section that is neither a subsection nor a heading.

https://www.gnu.org/software/emacs/manual/html_mono/nxml-mode.html#Outlining

0
quazgar On

There finally is an answer at https://emacs.stackexchange.com/questions/2884/the-old-how-to-fold-xml-question, using hideshow.

If and when the emacs.stackexchange gets out of its beta stage, this question might become obsolete.

0
Shon On

If you only need to edit unspecified xml, I suggest using web-mode instead of nxml-mode. It supports node folding.

Emacs seems to open .xml files in nxml-mode by default. I guess nxml-mode is useful for working with xml validated against a schema. However, if you just want to edit some un-specified xml with convenient tools, it seems that web-mode may be a better choice.

I found this question searching for a way to do the latter, so I thought I'd share.