2026-09-12

Emacs hang for long CSS selector list

I can't get Emacs (29.3) to open this file:

@charset "UTF-8";

body.javadoc span.wbr::before {
    content: "\200b";
}

body.javadoc strong.error {
    color: #f00;
    font-size: 150%;
}

body.javadoc .javadoc-members > tbody > .item > .name-purpose > .sig {
    display: flex;
}

body.javadoc .javadoc-type-params > * > tr > .name,
body.javadoc .javadoc-members > * > tr > .return-type,
body.javadoc .javadoc-class-list > * > tr > .kind,
body.javadoc .javadoc-package-list > * > tr > .kind,
body.javadoc .javadoc-qualities > tbody > tr > .name,
body.javadoc .javadoc-hierarchy > tbody > tr > .pad {
    text-align: right;
}

body.javadoc .javadoc-qualities > tbody > tr > .name {
    white-space: nowrap;
}

body.javadoc .javadoc-type-params > * > tr > .purpose,
body.javadoc .javadoc-terminals > * > tr.heading > *,
body.javadoc .javadoc-terminals > * > tr.item > .type,
body.javadoc .javadoc-terminals > * > tr.item > .name,
body.javadoc .javadoc-terminals > * > tr.item > .descr,
body.javadoc .javadoc-members > * > tr > .modifiers,
body.javadoc .javadoc-members > * > tr.heading > *,
body.javadoc .javadoc-members > * > tr > .name-purpose,
body.javadoc .javadoc-package-list > caption,
body.javadoc .javadoc-package-list > * > tr.heading > *,
body.javadoc .javadoc-package-list > * > tr > .name,
body.javadoc .javadoc-package-list > * > tr > .purpose,
body.javadoc .javadoc-class-list > * > tr > .name,
body.javadoc .javadoc-class-list > * > tr > .purpose,
body.javadoc .javadoc-qualities > tbody > tr > .value,
body.javadoc .javadoc-hierarchy > tbody > tr > .link,
body {
    text-align: left;
}

It just sits there and spins, and I have to kill it. It also spins if I paste it into an empty buffer with css-mode enabled.

Sending SIGUSR2 breaks the spin, and yields the following:

Debugger entered--entering a function:
* #f(compiled-function () #<bytecode -0x46307a0762b616a>)()
  font-lock-default-fontify-region(1 1501 nil)
  css--fontify-region(1 1501 nil)
  font-lock-fontify-region(1 1501)
  #f(compiled-function (fun) #<bytecode -0x156b402ed9bf57c3>)(font-lock-fontify-region)
  jit-lock--run-functions(1 1501)
  jit-lock-fontify-now(1 1501)
  jit-lock-function(1)
  redisplay_internal\ \(C\ function\)()

Note how the last selector, a plain body, is on a line by itself. Now replace the newline before it with a space, so it looks like this at the end:

body.javadoc .javadoc-hierarchy > tbody > tr > .link, body {
    text-align: left;
}

Emacs opens this fine. It's also seems okay if you skip the @charset and the first selector and declaration (commenting them out isn't enough), or if you skip the first two selector-declarations, or if you split the final list of selectors into two, and repeat the declaration. The problem seems to be with the long selector list split over multiple lines, in combination with its position in the file.

Hope that helps, if you encounter it. Yes, I should probably file a bug report, but, you know, the species is on its way out and all that. I might eventually get a round tuit.