Backport commit 284c470 from Emacs master branch