GNU bug report logs - #28513
25.1; ido insists on guessing the wrong directory

Previous Next

Package: emacs;

Reported by: Guillaume Salagnac <guillaume.salagnac <at> gmail.com>

Date: Tue, 19 Sep 2017 15:29:01 UTC

Severity: minor

Tags: fixed

Found in version 25.1

Fixed in version 28.1

Done: Lars Ingebrigtsen <larsi <at> gnus.org>

Bug is archived. No further changes may be made.

Full log


Message #26 received at 28513 <at> debbugs.gnu.org (full text, mbox):

From: Lars Ingebrigtsen <larsi <at> gnus.org>
To: Dmitry Gutov <dgutov <at> yandex.ru>
Cc: Guillaume Salagnac <guillaume.salagnac <at> gmail.com>, 28513 <at> debbugs.gnu.org
Subject: Re: bug#28513: 25.1; ido insists on guessing the wrong directory
Date: Tue, 15 Dec 2020 07:42:10 +0100
Dmitry Gutov <dgutov <at> yandex.ru> writes:

>> So this isn't an ido problem at all -- it's a bug in `write-file'?
>> Or
>> rather...
>> (let ((default-directory "/tmp/")) (read-file-name "Foo: "))
>> If you just hit RET there, it'll return `buffer-file-name'.
>
> But there is a difference between having default-directory set to
> /tmp/ and typing /tmp/ yourself.

There is.  However, I don't think the way

(let ((default-directory "/tmp/")) (read-file-name "Foo: "))

works is logical.  We're clearly presenting the user with an interface
that seems like we're doing something in /tmp/, but RET returns
buffer-file-name.

The following would be more logical, in my opinion.  But it's a very
low-level change, so it's...  ticklish.  It should give the same results
99% of the time (because binding default-directory and then calling
read-file-name isn't the usual pattern, I think?), but would fix this
issue.

Opinions?

diff --git a/lisp/minibuffer.el b/lisp/minibuffer.el
index 456193d52e..d1f1bf3758 100644
--- a/lisp/minibuffer.el
+++ b/lisp/minibuffer.el
@@ -2814,7 +2814,9 @@ read-file-name-default
   (unless default-filename
     (setq default-filename
           (cond
-           ((null initial) buffer-file-name)
+           ((null initial)
+            (expand-file-name (file-name-nondirectory buffer-file-name)
+                              default-directory))
            ;; Special-case "" because (expand-file-name "" "/tmp/") returns
            ;; "/tmp" rather than "/tmp/" (bug#39057).
            ((equal "" initial) dir)

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no




This bug report was last modified 4 years and 193 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.