Actually, while we were talking about the issue, Stefan solved it.
See:
  https://git.savannah.gnu.org/cgit/emacs.git/commit/?id=dde33727b2ace3ce417d97475d074f0a82b7c2b8

This is a better solution than any of the ones proposed by either of
us, and is completely satisfactory to me.

Best,
Radon