This question already has an answer here:

I am using spacemacs nXML mode to edit build.xml (java ant configuration file), the file is very long, how to fold and unfold it?

marked as duplicate by Dan Apr 15 '15 at 15:21

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • Here is a related link to some code folding for nXML-mode that I wrote up some time ago -- perhaps you could modify it to suit your needs. The title of the thread is How can I fold arbitrary tags with nxml-mode?: superuser.com/a/787030/206164 – lawlist Apr 15 '15 at 1:36
  • 1
    Not really what you're looking for but set-selective-display function can help you hide/un-hide some part of your file based on the indention. Also, occur is probably the best way to go when editing a large file, IMHO. – Nsukami _ Apr 15 '15 at 1:42

You need to add this hook:

(add-hook 'nxml-mode-hook 'hs-minor-mode)

After that put this in your init.el file or somewhere it'll be loaded.

(define-key nxml-mode-map (kbd "C-c h") 'hs-toggle-hiding)

If you now press C-c h it will fold the xml at the element where your cursor is.

  • 1
    I guess you need to have hs-minor-mode enabled too? Should perhaps be part of the answer. – Meaningful Username Apr 15 '15 at 9:45
  • This actually does nothing in my Emacs 24.3.1. Do I need a specific Emacs version? Or hide-show mode version? – wvxvw Apr 15 '15 at 12:32
  • I'm using emacs 24.5.1 with nothing special. You of course need to be in an xml. I'll have a look at what may be missing.. – cb0 Apr 15 '15 at 18:37

Not the answer you're looking for? Browse other questions tagged or ask your own question.