Backport commit ac16149 from Emacs