From 11f7ce6952550cbcec35492f41baa14025911cfa Mon Sep 17 00:00:00 2001 From: "Ryan C. Thompson" Date: Sun, 3 Nov 2019 23:40:13 -0800 Subject: [PATCH] Ensure correct behavior in ido file fallback completion Fixes bug #19412. Previously, when falling back, ido would let-bind default-directory to ido-current-directory so that read-file-name would start in the right location. However, this has an unexpected side effect (see the bug report). Instead, ido now leaves default-directory alone and instead uses minibuffer-with-setup-hook to simulate the user deleting the initial input and typing ido-current-directory instead. --- lisp/ido.el | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/lisp/ido.el b/lisp/ido.el index 2a660e6b0c..c17972c1cc 100644 --- a/lisp/ido.el +++ b/lisp/ido.el @@ -2428,11 +2428,23 @@ If cursor is not at the end of the user input, move to end of input." ((eq ido-exit 'fallback) ;; Need to guard setting of default-directory here, since ;; we don't want to change directory of current buffer. - (let ((default-directory ido-current-directory) - (read-file-name-function nil)) + (let ((default-directory default-directory) + (read-file-name-function nil)) (setq this-command (or ido-fallback fallback 'find-file)) (run-hook-with-args 'ido-before-fallback-functions this-command) - (call-interactively this-command))) + ;; Workaround for bug #19412: ensure that pressing RET + ;; immediately after falling back with C-f will select the + ;; input rather than use the default (which is + ;; `default-directory'). + (minibuffer-with-setup-hook + (:append + (lambda () + ;; Clear out whatever started in the minibuffer and + ;; replace it with what the user had already entered + ;; into ido. + (delete-minibuffer-contents) + (insert ido-current-directory))) + (call-interactively this-command)))) ((eq ido-exit 'switch-to-buffer) (ido-buffer-internal -- 2.23.0