Backport commit 20e9a00fb from Emacs