Backport commit f994c20 from Emacs