The old “how to fold XML” question

From http://emacs.stackexchange.com/questions/2884/the-old-how-to-fold-xml-question

I found this SO post: http://stackoverflow.com/questions/944614/emacs-does-hideshow-work-with-xml-mode-sgml-mode

(require 'hideshow)
(require 'sgml-mode)
(require 'nxml-mode)

(add-to-list 'hs-special-modes-alist
             '(nxml-mode
               "<!--\\|<[^/>]*[^/]>"
               "-->\\|</[^/>]*[^/]>"

               "<!--"
               sgml-skip-tag-forward
               nil))



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

;; optional key bindings, easier than hs defaults
(define-key nxml-mode-map (kbd "C-c h") 'hs-toggle-hiding)

You can use the code from there, slightly modified, for nxml-mode easily.

This will allow you to toggle hiding/unhiding of xml elements with C-ch and will support underscores in the names.

enter image description here

shareimprove this answer
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s