From: "Ryan C. Thompson" <rct@thompsonclan.org>
To: 28513@debbugs.gnu.org
Subject: bug#28513:
Date: Fri, 1 Jan 2021 16:51:56 -0500 [thread overview]
Message-ID: <430c52f7-7962-4e65-874f-f4a572951314@thompsonclan.org> (raw)
In-Reply-To: <3526ABC6-2389-492A-83D7-A26195A6FC37@gmail.com>
[-- Attachment #1: Type: text/plain, Size: 713 bytes --]
Hello,
I believe this bug (#28513) is a duplicate of #19412. In the discussion
for #19412 I have investigated the problem and proposed a fix that
doesn't require special-casing anything. However, due to being quite
busy since then I have not had the time to properly test my fix.
Briefly, the fix is to pass all the original args to the fallback
function unchanged and then use "minibuffer-with-setup-hook" to simulate
deleting the initial input and then typing whatever the user currently
had typed into ido before they triggered the fallback.
I have rebased the patch from that thread onto the current master and
attached it. To reiterate, this patch should be tested before merging.
Regards,
Ryan
[-- Attachment #2: 0001-Fix-default-directory-handling-in-ido-file-fallback-.patch --]
[-- Type: text/plain, Size: 6173 bytes --]
From 41feb86c67390ce6c17fd59ddfc6e7288aa47d64 Mon Sep 17 00:00:00 2001
From: "Ryan C. Thompson" <rct@thompsonclan.org>
Date: Wed, 11 Mar 2020 12:24:24 -0400
Subject: [PATCH] Fix default directory handling in ido file fallback (bug
#19412)
Briefly, when falling back from ido file completion to normal file
completion, previously the current directory at the time of falling
back was treated as the default directory, which was wrong and caused
unintuitive edge cases. Now, when falling back for file completion,
ido uses the original default directory that ido was called with and
then uses `minibuffer-with-setup-hook' to "simulate" typing in the
currently entered directory, so that it is not treated as the
default. See the bug description for more information.
Note: This also reverts commit 526abadd07, which is intended to be a fix
for bug #28513 which I believe is a duplicate of bug #19412. I believe
the fix in this patch is better because it should fix every case
without the need to special-case specific functions.
---
lisp/ido.el | 63 +++++++++++++++++++++++++++++++++++++++--------------
1 file changed, 47 insertions(+), 16 deletions(-)
diff --git a/lisp/ido.el b/lisp/ido.el
index 89b6a62f5a..2d0a9e69e2 100644
--- a/lisp/ido.el
+++ b/lisp/ido.el
@@ -2363,20 +2363,23 @@ ido-file-internal
((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)
- (if (eq this-command 'write-file)
- (write-file (read-file-name
- "Write file: "
- default-directory
- (and buffer-file-name
- (expand-file-name
- (file-name-nondirectory buffer-file-name)
- default-directory)))
- t)
- (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 (abbreviate-file-name ido-current-directory))))
+ (call-interactively this-command))))
((eq ido-exit 'switch-to-buffer)
(ido-buffer-internal
@@ -4871,7 +4874,8 @@ ido-read-file-name
"Ido replacement for the built-in `read-file-name'.
Read file name, prompting with PROMPT and completing in directory DIR.
See `read-file-name' for additional parameters."
- (let (filename)
+ (let (filename
+ (orig-dir dir))
(cond
((and (not (memq this-command ido-read-file-name-non-ido))
(or (eq predicate 'file-directory-p)
@@ -4925,7 +4929,21 @@ ido-read-file-name
(if (eq filename 'fallback)
(let ((read-file-name-function nil))
(run-hook-with-args 'ido-before-fallback-functions 'read-file-name)
- (read-file-name prompt dir default-filename mustmatch initial predicate))
+ ;; Bug#19412: need to pass original DIR to `read-file-name'
+ ;; but start with current value of DIR entered in
+ ;; minibuffer, so that it correctly handles a default that
+ ;; is not in the current directory. See also bug#1516.
+ ;; (ido-trace "read-file-name fallback" (list prompt orig-dir default-filename mustmatch initial predicate))
+ ;; (ido-trace "read-file-name fallback initial" dir)
+ (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 (abbreviate-file-name dir))))
+ (read-file-name prompt orig-dir default-filename mustmatch initial predicate)))
filename)))
;;;###autoload
@@ -4934,6 +4952,7 @@ ido-read-directory-name
Read directory name, prompting with PROMPT and completing in directory DIR.
See `read-directory-name' for additional parameters."
(let* (filename
+ (orig-dir dir)
(minibuffer-completing-file-name t)
(ido-context-switch-command 'ignore)
ido-saved-vc-hb
@@ -4950,12 +4969,24 @@ ido-read-directory-name
(expand-file-name initial ido-current-directory)
ido-current-directory))
mustmatch initial))
+ (setq dir ido-current-directory)
(cond
((eq ido-exit 'fallback)
(let ((read-file-name-function nil))
(run-hook-with-args 'ido-before-fallback-functions 'read-directory-name)
- (read-directory-name prompt ido-current-directory
- default-dirname mustmatch initial)))
+ ;; Bug#19412: need to pass original DIR to `read-file-name'
+ ;; but start with current value of DIR entered in minibuffer,
+ ;; so that it correctly handles a default that is not in the
+ ;; current 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 (abbreviate-file-name dir))))
+ (read-directory-name prompt orig-dir default-dirname mustmatch initial))))
((equal filename ".") ido-current-directory)
(t (concat ido-current-directory filename)))))
--
2.29.2
next prev parent reply other threads:[~2021-01-01 21:51 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-09-19 15:03 bug#28513: 25.1; ido insists on guessing the wrong directory Guillaume Salagnac
2020-12-12 12:10 ` Lars Ingebrigtsen
2020-12-13 1:11 ` Dmitry Gutov
2020-12-13 13:12 ` Lars Ingebrigtsen
2020-12-14 2:24 ` Dmitry Gutov
2020-12-14 16:42 ` Lars Ingebrigtsen
2020-12-15 2:23 ` Dmitry Gutov
2020-12-15 6:42 ` Lars Ingebrigtsen
2020-12-17 11:33 ` Lars Ingebrigtsen
2020-12-17 11:54 ` Dmitry Gutov
2021-01-01 21:51 ` Ryan C. Thompson [this message]
2021-01-10 23:07 ` bug#19412: bug#28513 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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=430c52f7-7962-4e65-874f-f4a572951314@thompsonclan.org \
--to=rct@thompsonclan.org \
--cc=28513@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 external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.