;;; files.el --- file input and output commands for Emacs
-;; Copyright (C) 1985, 1986, 1987, 1992, 1993, 1994, 1995, 1996,
-;; 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
-;; 2006, 2007, 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
+;; Copyright (C) 1985-1987, 1992-2011 Free Software Foundation, Inc.
;; Maintainer: FSF
;; Package: emacs
A list of elements of the form (FROM . TO), each meaning to replace
FROM with TO when it appears in a directory name. This replacement is
done when setting up the default directory of a newly visited file.
-*Every* FROM string ought to start with \"\\\\`\".
+
+FROM is matched against directory names anchored at the first
+character, so it should start with a \"\\\\`\", or, if directory
+names cannot have embedded newlines, with a \"^\".
FROM and TO should be equivalent names, which refer to the
same directory. Do not use `~' in the TO strings;
(unless (run-hook-with-args-until-failure 'kill-buffer-query-functions)
(error "Aborted"))
(when (and (buffer-modified-p) buffer-file-name)
- (if (yes-or-no-p "Buffer %s is modified; save it first? "
- (buffer-name))
+ (if (yes-or-no-p (format "Buffer %s is modified; save it first? "
+ (buffer-name)))
(save-buffer)
(unless (yes-or-no-p "Kill and replace the buffer without saving it? ")
(error "Aborted"))))
OP-TYPE specifies the file operation being performed (for message to user)."
(when (and large-file-warning-threshold size
(> size large-file-warning-threshold)
- (not (y-or-n-p "File %s is large (%dMB), really %s? "
- (file-name-nondirectory filename)
- (/ size 1048576) op-type)))
+ (not (y-or-n-p (format "File %s is large (%dMB), really %s? "
+ (file-name-nondirectory filename)
+ (/ size 1048576) op-type))))
(error "Aborted")))
(defun find-file-noselect (filename &optional nowarn rawfile wildcards)
(let ((buffer (and filename (find-buffer-visiting filename))))
(and buffer (not (eq buffer (current-buffer)))
(not no-query)
- (not (y-or-n-p "A buffer is visiting %s; proceed? "
- filename))
+ (not (y-or-n-p (format "A buffer is visiting %s; proceed? "
+ filename)))
(error "Aborted")))
(or (equal filename buffer-file-name)
(progn
(or buffer-file-name (buffer-name))))))
(and confirm
(file-exists-p filename)
- (or (y-or-n-p "File `%s' exists; overwrite? " filename)
+ (or (y-or-n-p (format "File `%s' exists; overwrite? " filename))
(error "Canceled")))
(set-visited-file-name filename (not confirm))))
(set-buffer-modified-p t)
(and targets
(or (eq delete-old-versions t) (eq delete-old-versions nil))
(or delete-old-versions
- (y-or-n-p "Delete excess backup versions of %s? "
- real-file-name))))
+ (y-or-n-p (format "Delete excess backup versions of %s? "
+ real-file-name)))))
(modes (file-modes buffer-file-name))
(context (file-selinux-context buffer-file-name)))
;; Actually write the back up file.
(rename-file real-file-name backupname t)
(setq setmodes (list modes context backupname)))
(file-error
- ;; If trouble writing the backup, write it in ~.
- (setq backupname (expand-file-name
- (convert-standard-filename
- "~/%backup%~")))
+ ;; If trouble writing the backup, write it in
+ ;; .emacs.d/%backup%.
+ (setq backupname (locate-user-emacs-file "%backup%~"))
(message "Cannot write backup file; backing up in %s"
backupname)
(sleep-for 1)
;; Signal an error if the user specified the name of an
;; existing directory.
(error "%s is a directory" filename)
- (unless (y-or-n-p "File `%s' exists; overwrite? "
- filename)
+ (unless (y-or-n-p (format "File `%s' exists; overwrite? "
+ filename))
(error "Canceled")))
;; Signal an error if the specified name refers to a
;; non-existing directory.
(or (verify-visited-file-modtime (current-buffer))
(not (file-exists-p buffer-file-name))
(yes-or-no-p
- "%s has changed since visited or saved. Save anyway? "
- (file-name-nondirectory buffer-file-name))
+ (format
+ "%s has changed since visited or saved. Save anyway? "
+ (file-name-nondirectory buffer-file-name)))
(error "Save not confirmed"))
(save-restriction
(widen)
(eq require-final-newline 'visit-save)
(and require-final-newline
(y-or-n-p
- "Buffer %s does not end in newline. Add one? "
- (buffer-name))))
+ (format "Buffer %s does not end in newline. Add one? "
+ (buffer-name)))))
(save-excursion
(goto-char (point-max))
(insert ?\n))))
(if (not (file-exists-p buffer-file-name))
(error "Directory %s write-protected" dir)
(if (yes-or-no-p
- "File %s is write-protected; try to save anyway? "
- (file-name-nondirectory
- buffer-file-name))
+ (format
+ "File %s is write-protected; try to save anyway? "
+ (file-name-nondirectory
+ buffer-file-name)))
(setq tempsetmodes t)
(error "Attempt to save to a file which you aren't allowed to write"))))))
(or buffer-backed-up
(progn
(if (or arg
(eq save-abbrevs 'silently)
- (y-or-n-p "Save abbrevs in %s? " abbrev-file-name))
+ (y-or-n-p (format "Save abbrevs in %s? " abbrev-file-name)))
(write-abbrev-file nil))
;; Don't keep bothering user if he says no.
(setq abbrevs-changed nil)
(list dir
(if (directory-files dir nil directory-files-no-dot-files-regexp)
(y-or-n-p
- "Directory `%s' is not empty, really %s? "
- dir (if trashing "trash" "delete"))
+ (format "Directory `%s' is not empty, really %s? "
+ dir (if trashing "trash" "delete")))
nil)
(null current-prefix-arg))))
;; If default-directory is a remote directory, make sure we find its
(dolist (regexp revert-without-query)
(when (string-match regexp file-name)
(throw 'found t)))))
- (yes-or-no-p "Revert buffer from file %s? "
- file-name))
+ (yes-or-no-p (format "Revert buffer from file %s? "
+ file-name)))
(run-hooks 'before-revert-hook)
;; If file was backed up but has changed since,
;; we should make another backup.
;; to emulate what `ls' did in that case.
(insert-directory-safely file switches)
(insert-directory-safely file-name switches))))
- (yes-or-no-p "Recover auto save file %s? " file-name))
+ (yes-or-no-p (format "Recover auto save file %s? " file-name)))
(switch-to-buffer (find-file-noselect file t))
(let ((inhibit-read-only t)
;; Keep the current buffer-file-coding-system.
(defun kill-buffer-ask (buffer)
"Kill BUFFER if confirmed."
- (when (yes-or-no-p
- "Buffer %s %s. Kill? " (buffer-name buffer)
- (if (buffer-modified-p buffer)
- "HAS BEEN EDITED" "is unmodified"))
+ (when (yes-or-no-p (format "Buffer %s %s. Kill? "
+ (buffer-name buffer)
+ (if (buffer-modified-p buffer)
+ "HAS BEEN EDITED" "is unmodified")))
(kill-buffer buffer)))
(defun kill-some-buffers (&optional list)
(substitute-in-file-name identity)
;; `add' means add "/:" to the result.
(file-truename add 0)
- ;; `quote' means add "/:" to buffer-file-name.
- (insert-file-contents quote 0)
+ (insert-file-contents insert-file-contents 0)
;; `unquote-then-quote' means set buffer-file-name
;; temporarily to unquoted filename.
(verify-visited-file-modtime unquote-then-quote)
"/"
(substring (car pair) 2)))))
(setq file-arg-indices (cdr file-arg-indices))))
- (cond ((eq method 'identity)
- (car arguments))
- ((eq method 'add)
- (concat "/:" (apply operation arguments)))
- ((eq method 'quote)
- (unwind-protect
+ (case method
+ (identity (car arguments))
+ (add (concat "/:" (apply operation arguments)))
+ (insert-file-contents
+ (let ((visit (nth 1 arguments)))
+ (prog1
(apply operation arguments)
- (setq buffer-file-name (concat "/:" buffer-file-name))))
- ((eq method 'unquote-then-quote)
- (let (res)
- (setq buffer-file-name (substring buffer-file-name 2))
- (setq res (apply operation arguments))
- (setq buffer-file-name (concat "/:" buffer-file-name))
- res))
+ (when (and visit buffer-file-name)
+ (setq buffer-file-name (concat "/:" buffer-file-name))))))
+ (unquote-then-quote
+ (let ((buffer-file-name (substring buffer-file-name 2)))
+ (apply operation arguments)))
(t
(apply operation arguments)))))
\f