Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

emacs: Does HideShow work with xml-mode (sgml-mode)?

Tags:

emacs

xml

I use hideshow.el in my cc-mode buffers to collapse sections of the file I'm not looking at.

It would be nice to be able to do that in an XML doc. I use emacs 22.2.1 and the built-in sgml-mode for xml editing. I haven't gotten hideshow to work with the XML. I mean, I turn on the minor mode but the keystrokes have no effect. Ooh, except, I did get an XML comment to collapse. But no elements.

Has anyone done this successfully?
Recommendations?


EDIT: I'll bet it would work if I added an sgml-mode element to hs-special-modes-alist. I'd need a regexp for start-block. Has anyone done this?


I haven't moved to nxml-mode. Should I? does it do "folding" or hiding?

like image 735
Cheeso Avatar asked Jun 03 '09 13:06

Cheeso


1 Answers

Answering my own question... I am using something like this. Seems to work.

;; Fix XML folding
(add-to-list 'hs-special-modes-alist
             (list 'nxml-mode
                   "<!--\\|<[^/>]*[^/]>"
                   "-->\\|</[^/>]*[^/]>"
                   "<!--"
                   'nxml-forward-element
                   nil))

;; Fix HTML folding
(dolist (mode '(sgml-mode
                html-mode
                html-erb-mode))
  (add-to-list 'hs-special-modes-alist
               (list mode
                     "<!--\\|<[^/>]*[^/]>"
                     "-->\\|</[^/>]*[^/]>"
                     "<!--"
                     'sgml-skip-tag-forward
                     nil)))
like image 147
Cheeso Avatar answered Nov 03 '22 14:11

Cheeso