;;; files.el --- file input and output commands for Emacs
-;; Copyright (C) 1985, 86, 87, 92, 93,
-;; 94, 95, 96, 97, 98, 99, 2000 Free Software Foundation, Inc.
+;; Copyright (C) 1985, 86, 87, 92, 93, 94, 95, 96, 97, 98, 99, 2000, 2001
+;;; Free Software Foundation, Inc.
;; Maintainer: FSF
"Load the Lisp file named FILE."
;; This is a case where .elc makes a lot of sense.
(interactive (list (let ((completion-ignored-extensions
- (delete ".elc" completion-ignored-extensions)))
+ (remove ".elc" completion-ignored-extensions)))
(read-file-name "Load file: "))))
(load (expand-file-name file) nil nil t))
(make-backup-files (or (and make-backup-files (not (eq args 0)))
(memq args '(16 64)))))
(and modp (memq args '(16 64)) (setq buffer-backed-up nil))
- (if (and modp large) (message "Saving file %s..." (buffer-file-name)))
+ (if (and modp large (buffer-file-name))
+ (message "Saving file %s..." (buffer-file-name)))
(basic-save-buffer)
(and modp (memq args '(4 64)) (setq buffer-backed-up nil))))
(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)
(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.
but `kill-emacs', the low level primitive, does not.
See also `kill-emacs-hook'.")
+(defcustom confirm-kill-emacs nil
+ "How to ask for confirmation when leaving Emacs.
+If nil, the default, don't ask at all. If the value is non-nil, it should
+be a predicate function such as `yes-or-no-p'."
+ :type '(choice (const :tag "Ask with yes-or-no-p" yes-or-no-p)
+ (const :tag "Ask with y-or-n-p" y-or-n-p)
+ (const :tag "Don't confirm" nil))
+ :group 'emacs
+ :version "21.1")
+
(defun save-buffers-kill-emacs (&optional arg)
"Offer to save each buffer, then kill this Emacs process.
With prefix arg, silently save all file-visiting buffers, then kill."
(yes-or-no-p "Active processes exist; kill them and exit anyway? "))))
;; Query the user for other things, perhaps.
(run-hook-with-args-until-failure 'kill-emacs-query-functions)
+ (or (null confirm-kill-emacs)
+ (funcall confirm-kill-emacs "Really exit Emacs? "))
(kill-emacs)))
\f
;; We use /: as a prefix to "quote" a file name