emacs

Gent Krasniqi 2025-09-26T06:44:34.215399Z

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.

hkjels 2025-09-26T07:04:34.323369Z

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

hkjels 2025-09-26T07:04:47.239439Z

apparently it is not set up by default

hkjels 2025-09-26T07:05:31.085439Z

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

hkjels 2025-09-26T07:06:23.069169Z

but it looks legit

hkjels 2025-09-26T07:10:24.728249Z

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

Gent Krasniqi 2025-09-26T07:13:21.797029Z

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

Gent Krasniqi 2025-09-26T10:57:40.724469Z

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

hkjels 2025-09-26T11:59:32.809279Z

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

hkjels 2025-09-26T12:00:20.621879Z

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

hkjels 2025-09-26T12:01:07.367299Z

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

hkjels 2025-09-26T12:02:03.384779Z

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

Gent Krasniqi 2025-09-26T13:36:23.622049Z

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.

hkjels 2025-09-26T06:51:23.904379Z

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

Gent Krasniqi 2025-09-26T06:57:28.698429Z

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.

Gent Krasniqi 2025-09-26T06:59:31.108419Z

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