From e8a5fe3ed8b0feec2609d70c2ea156a4b06d68b6 Mon Sep 17 00:00:00 2001 From: Stefan Monnier Date: Wed, 23 Apr 2008 18:37:50 +0000 Subject: [PATCH] (read-file-name): Don't let-bind default-directory. Only abbreviate default-filename if it's a file. --- lisp/ChangeLog | 3 +++ lisp/minibuffer.el | 21 +++++++++++++++------ 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/lisp/ChangeLog b/lisp/ChangeLog index a50ef0cf512..9f4da1f394a 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,5 +1,8 @@ 2008-04-23 Stefan Monnier + * minibuffer.el (read-file-name): Don't let-bind default-directory. + Only abbreviate default-filename if it's a file. + * minibuffer.el (read-file-name-function, read-file-name-predicate) (read-file-name-completion-ignore-case, insert-default-directory): New vars, moved from fileio.c. diff --git a/lisp/minibuffer.el b/lisp/minibuffer.el index 3651aa439bd..6cef906475e 100644 --- a/lisp/minibuffer.el +++ b/lisp/minibuffer.el @@ -834,7 +834,8 @@ and `read-file-name-function'." ;; If dir starts with user's homedir, change that to ~. (setq dir (abbreviate-file-name dir)) ;; Likewise for default-filename. - (setq default-filename (abbreviate-file-name default-filename)) + (if default-filename + (setq default-filename (abbreviate-file-name default-filename))) (let ((insdef (cond ((and insert-default-directory (stringp dir)) (if initial @@ -846,17 +847,25 @@ and `read-file-name-function'." (if read-file-name-function (funcall read-file-name-function prompt dir default-filename mustmatch initial predicate) - (let ((default-directory (file-name-as-directory (expand-file-name dir))) - (completion-ignore-case read-file-name-completion-ignore-case) + (let ((completion-ignore-case read-file-name-completion-ignore-case) (minibuffer-completing-file-name t) (read-file-name-predicate (or predicate 'file-exists-p)) (add-to-history nil)) (let* ((val (if (not (next-read-file-uses-dialog-p)) - (completing-read prompt 'read-file-name-internal - nil mustmatch insdef 'file-name-history - default-filename) + ;; We used to pass `dir' to `read-file-name-internal' by + ;; abusing the `predicate' argument. It's better to + ;; just use `default-directory', but in order to avoid + ;; changing `default-directory' in the current buffer, + ;; we don't let-bind it. + (lexical-let ((dir (file-name-as-directory + (expand-file-name dir)))) + (minibuffer-with-setup-hook + (lambda () (setq default-directory dir)) + (completing-read prompt 'read-file-name-internal + nil mustmatch insdef 'file-name-history + default-filename))) ;; If DIR contains a file name, split it. (let ((file (file-name-nondirectory dir))) (when (and default-filename (not (zerop (length file)))) -- 2.39.2