From: Eli Zaretskii Date: Thu, 21 Dec 2000 14:44:35 +0000 (+0000) Subject: (insert-directory-safely): New function. X-Git-Tag: emacs-pretest-21.0.95~350 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=bc22fd184ade431c75d015c74315462c8430d36b;p=emacs.git (insert-directory-safely): New function. (recover-file): Use it instead of insert-directory. --- diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 710aca56141..7f61a1a3dfa 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,8 @@ +2000-12-21 Eli Zaretskii + + * files.el (insert-directory-safely): New function. + (recover-file): Use it instead of insert-directory. + 2000-12-21 Kenichi Handa * international/mule-cmds.el (select-safe-coding-system): Check diff --git a/lisp/files.el b/lisp/files.el index 57387b1e70e..bd808ddae7b 100644 --- a/lisp/files.el +++ b/lisp/files.el @@ -3058,8 +3058,14 @@ non-nil, it is called instead of rereading visited file contents." (if (file-symlink-p file) (setq switches (concat switches "L"))) (set-buffer standard-output) - (insert-directory file switches) - (insert-directory file-name switches)))) + ;; Use insert-directory-safely, not insert-directory, + ;; because these files might not exist. In particular, + ;; FILE might not exist if the auto-save file was for + ;; a buffer that didn't visit a file, such as "*mail*". + ;; The code in v20.x called `ls' directly, so we need + ;; to emulate what `ls' did in that case. + (insert-directory-safely file switches) + (insert-directory-safely file-name switches)))) (yes-or-no-p (format "Recover auto save file %s? " file-name))) (switch-to-buffer (find-file-noselect file t)) (let ((buffer-read-only nil) @@ -3620,6 +3626,17 @@ If WILDCARD, it also runs the shell specified by `shell-file-name'." (setq available (buffer-substring (point) end)))) (insert " available " available)))))))))) +(defun insert-directory-safely (file switches + &optional wildcard full-directory-p) + "Insert directory listing for FILE, formatted according to SWITCHES. + +Like `insert-directory', but if FILE does not exist, it inserts a +message to that effect instead of signaling an error." + (if (file-exists-p file) + (insert-directory file switches wildcard full-directory-p) + ;; Simulate the message printed by `ls'. + (insert (format "%s: No such file or directory\n" file)))) + (defvar kill-emacs-query-functions nil "Functions to call with no arguments to query about killing Emacs. If any of these functions returns nil, killing Emacs is cancelled.