unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: "Ryan C. Thompson" <rct@thompsonclan.org>
To: 19412@debbugs.gnu.org
Subject: bug#19412: 24.3; ido-write-file sometimes writes to a different directory than, it says it will
Date: Mon, 4 Nov 2019 06:52:19 -0800	[thread overview]
Message-ID: <0a0e748b-e809-d1e9-e52a-a3d846635fe6@thompsonclan.org> (raw)
In-Reply-To: <abbcae10-8b42-f94f-82a9-a700547c7a84@thompsonclan.org>

[-- Attachment #1: Type: text/plain, Size: 578 bytes --]

I think I have found a fix for this issue. A patch for ido.el is 
attached. The solution is essentially to simulate re-typing the current 
ido input into the fallback command's prompt rather than modifying 
dynamic variables to trick the fallback command into starting in the 
right place.

Note that this is NOT thoroughly tested yet. It seems to work for the 
specific case described in this bug (ido-write-file), but I need to test 
it for some time to make sure it isn't breaking other cases at the same 
time. I will use this fix in my Emacs for some time and report back.

[-- Attachment #2: 0001-Ensure-correct-behavior-in-ido-file-fallback-complet.patch --]
[-- Type: text/plain, Size: 2165 bytes --]

From 11f7ce6952550cbcec35492f41baa14025911cfa Mon Sep 17 00:00:00 2001
From: "Ryan C. Thompson" <rct@thompsonclan.org>
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


  reply	other threads:[~2019-11-04 14:52 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-12-19 20:21 bug#19412: 24.3; ido-write-file sometimes writes to a different directory than it says it will Don Morrison
2019-11-03 22:48 ` bug#19412: 24.3; ido-write-file sometimes writes to a different directory than, " Ryan C. Thompson
2019-11-04 14:52   ` Ryan C. Thompson [this message]
2019-11-04 15:55     ` Ryan C. Thompson
2020-03-11 16:46       ` Ryan C. Thompson
2020-08-12 16:44         ` Stefan Kangas
2021-01-10 23:12           ` Ryan C. Thompson
2021-01-11 14:14             ` Lars Ingebrigtsen
2021-01-11 14:28               ` Ryan C. Thompson
2021-01-11 18:43                 ` Lars Ingebrigtsen
2021-01-11 18:50                   ` Ryan C. Thompson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=0a0e748b-e809-d1e9-e52a-a3d846635fe6@thompsonclan.org \
    --to=rct@thompsonclan.org \
    --cc=19412@debbugs.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).