emacs 2025-09-26

Can anyone recommend a good package/mode for xml (and html I guess)? So basically, things like making it work with hideshow, having an equivalent of electric-pair-mode, etc.

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

apparently it is not set up by default

html would be the same I guess, just use html-mode instead

but it looks legit

I don't use hs myself. Instead I have found imenu and narrowing to be more convenient, but it's just a matter taste.

Yep I will try that later, thanks, found a similar recommendation in stackexchange.

@hkjels should imenu work with nxml-mode by default btw? doesn't seem to be the case.

you'll want to do something similar as with hs, but with the var imenu-generic-expression

Something like (setq imenu-generic-expression '((nil "<\\(\\w+\\)>" 1))) should suffice I guess

You could also group by supplying something other than nil and different patterns

(setq imenu-generic-expression
        '(("IDs"    "^.*id=\"\\([^\"]+\\)\"" 1)
          ("Names"  "^.*name=\"\\([^\"]+\\)\"" 1)
          ("Tags"   "^ *<\\([a-zA-Z0-9:_-]+\\)" 1)))

Thanks for your effort! I'll try these out when I have the chance to check out how they work. There goes my longest stint without 'ricing' my emacs config.

Emacs comes bundled with both html-mode and nxml-mode I believe. Those should work just fine, but if you want to write html more easily, I could recommend looking into emmet-mode. I can also recommend web-mode. It requires a bit of configuration, but you will be able to mix javascript, css and html in the same file amongst other things

I don't know if it's the document I'm on, but with nXML mode for example "Show Outline Only" and "Show Everything" don't seem to do anything.

and it's a bit disapointing that it's not really integrated with hideshow but has another set of keybindings/commands to learn