Convert consecutive FSF copyright years to ranges.
[bpt/emacs.git] / lisp / files.el
index 1e03ba1..7abf536 100644 (file)
@@ -1,8 +1,6 @@
 ;;; 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
@@ -57,7 +55,10 @@ when it has unsaved changes."
 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;
@@ -1555,8 +1556,8 @@ killed."
   (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"))))
@@ -1759,9 +1760,9 @@ When nil, never request confirmation."
 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)
@@ -3581,8 +3582,8 @@ the old visited file has been renamed to the new name FILENAME."
     (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
@@ -3693,7 +3694,7 @@ Interactively, confirmation is required unless you supply a prefix argument."
                                    (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)
@@ -3747,8 +3748,8 @@ BACKUPNAME is the backup file name, which is the old file renamed."
                       (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.
@@ -3775,10 +3776,9 @@ BACKUPNAME is the backup file name, which is the old file renamed."
                        (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)
@@ -4322,8 +4322,8 @@ Before and after saving the buffer, this function runs
                        ;; 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.
@@ -4336,8 +4336,9 @@ Before and after saving the buffer, this function runs
          (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)
@@ -4351,8 +4352,8 @@ Before and after saving the buffer, this function runs
                       (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))))
@@ -4414,9 +4415,10 @@ Before and after saving the buffer, this function runs
            (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
@@ -4607,7 +4609,7 @@ change the additional actions you can take on files."
           (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)
@@ -4782,8 +4784,8 @@ given.  With a prefix argument, TRASH is 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
@@ -4982,8 +4984,8 @@ non-nil, it is called instead of rereading visited file contents."
                          (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.
@@ -5103,7 +5105,7 @@ non-nil, it is called instead of rereading visited file contents."
                   ;; 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.
@@ -5223,10 +5225,10 @@ This command is used in the special Dired buffer created by
 
 (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)
@@ -6114,8 +6116,7 @@ only these files will be asked to be saved."
                          (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)
@@ -6146,20 +6147,18 @@ only these files will be asked to be saved."
                           "/"
                         (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