It turns out my patch doesn't fully fix the issue, when doing completion at the end of a file path. For example: 1. C-x C-f ~/src/emacs/emacs-29/lisp/.el 2. TAB to trigger completion, moving point to before .el 3. M- 4. The filenames are inserted before the .el, so one gets for example ~/src/emacs/emacs-29/lisp/abbrev.el.el The attached patch for the Emacs 29 branch fixes this remaining case.