Mercurial > emacs
comparison lisp/minibuffer.el @ 94301:9060af7294b9
(read-file-name): Don't let-bind default-directory.
Only abbreviate default-filename if it's a file.
author | Stefan Monnier <monnier@iro.umontreal.ca> |
---|---|
date | Wed, 23 Apr 2008 18:37:50 +0000 |
parents | b47239d57d36 |
children | bc48ced5cf89 |
comparison
equal
deleted
inserted
replaced
94300:b47239d57d36 | 94301:9060af7294b9 |
---|---|
832 (setq default-filename (if initial (expand-file-name initial dir) | 832 (setq default-filename (if initial (expand-file-name initial dir) |
833 buffer-file-name))) | 833 buffer-file-name))) |
834 ;; If dir starts with user's homedir, change that to ~. | 834 ;; If dir starts with user's homedir, change that to ~. |
835 (setq dir (abbreviate-file-name dir)) | 835 (setq dir (abbreviate-file-name dir)) |
836 ;; Likewise for default-filename. | 836 ;; Likewise for default-filename. |
837 (setq default-filename (abbreviate-file-name default-filename)) | 837 (if default-filename |
838 (setq default-filename (abbreviate-file-name default-filename))) | |
838 (let ((insdef (cond | 839 (let ((insdef (cond |
839 ((and insert-default-directory (stringp dir)) | 840 ((and insert-default-directory (stringp dir)) |
840 (if initial | 841 (if initial |
841 (cons (minibuffer--double-dollars (concat dir initial)) | 842 (cons (minibuffer--double-dollars (concat dir initial)) |
842 (length (minibuffer--double-dollars dir))) | 843 (length (minibuffer--double-dollars dir))) |
844 (initial (cons (minibuffer--double-dollars initial) 0))))) | 845 (initial (cons (minibuffer--double-dollars initial) 0))))) |
845 | 846 |
846 (if read-file-name-function | 847 (if read-file-name-function |
847 (funcall read-file-name-function | 848 (funcall read-file-name-function |
848 prompt dir default-filename mustmatch initial predicate) | 849 prompt dir default-filename mustmatch initial predicate) |
849 (let ((default-directory (file-name-as-directory (expand-file-name dir))) | 850 (let ((completion-ignore-case read-file-name-completion-ignore-case) |
850 (completion-ignore-case read-file-name-completion-ignore-case) | |
851 (minibuffer-completing-file-name t) | 851 (minibuffer-completing-file-name t) |
852 (read-file-name-predicate (or predicate 'file-exists-p)) | 852 (read-file-name-predicate (or predicate 'file-exists-p)) |
853 (add-to-history nil)) | 853 (add-to-history nil)) |
854 | 854 |
855 (let* ((val | 855 (let* ((val |
856 (if (not (next-read-file-uses-dialog-p)) | 856 (if (not (next-read-file-uses-dialog-p)) |
857 (completing-read prompt 'read-file-name-internal | 857 ;; We used to pass `dir' to `read-file-name-internal' by |
858 nil mustmatch insdef 'file-name-history | 858 ;; abusing the `predicate' argument. It's better to |
859 default-filename) | 859 ;; just use `default-directory', but in order to avoid |
860 ;; changing `default-directory' in the current buffer, | |
861 ;; we don't let-bind it. | |
862 (lexical-let ((dir (file-name-as-directory | |
863 (expand-file-name dir)))) | |
864 (minibuffer-with-setup-hook | |
865 (lambda () (setq default-directory dir)) | |
866 (completing-read prompt 'read-file-name-internal | |
867 nil mustmatch insdef 'file-name-history | |
868 default-filename))) | |
860 ;; If DIR contains a file name, split it. | 869 ;; If DIR contains a file name, split it. |
861 (let ((file (file-name-nondirectory dir))) | 870 (let ((file (file-name-nondirectory dir))) |
862 (when (and default-filename (not (zerop (length file)))) | 871 (when (and default-filename (not (zerop (length file)))) |
863 (setq default-filename file) | 872 (setq default-filename file) |
864 (setq dir (file-name-directory dir))) | 873 (setq dir (file-name-directory dir))) |