evil-mode and xml folding

October 21, 2015

Recently I went back to Maven's pom.xml editing and still can't get that nice warm feeling with Eclipse. Yet.

So, I was thinking, why not fire up Emacs (with evil-mode of course) and reuse all that folding goodness we get out of the box.

The thing is, Emacs does not support xml folding out of the box, but thanks to this awesome tip from Jordon Biondo, you can easily add it. Here is a little bit improved version:

(require 'sgml-mode)

(add-to-list 'hs-special-modes-alist
              '(nxml-mode
                "<!--\\|<[^/>]*[^/]>"
                "-->\\|</[^/>]*[^/]>"
                "<!--"
                sgml-skip-tag-forward
                nil))
    			
(add-hook 'nxml-mode-hook 'hs-minor-mode)

I just removed loading of hideshow and nxml-mode modes as they will be loaded by evil-mode as soon as you use one of the standard vim folding shortcuts.

To recap: drop above snippet in your Emacs init file and add some sanity in xml editing.