Fix some completion code that broke in Emacs recently.

This includes a test for Emacs' completion code, which seems to
break every few months.