Emacs: check for valid buffer-file-name
Emacs: fix handling of completion prefix (less caching)