Backport commit fbce475 from Emacs