emacs: fix #259

and factor some completion code.