]> code.delx.au - gnu-emacs/blobdiff - lisp/files.el
*** empty log message ***
[gnu-emacs] / lisp / files.el
index c18cc2e20acb4d0e65a4d45cfd521056ccf6c41a..6a406b6fbf01f7629672088b9ae99617756160b6 100644 (file)
@@ -1,6 +1,6 @@
 ;;; files.el --- file input and output commands for Emacs
 
-;; Copyright (C) 1985, 86, 87, 92, 93, 94, 95, 96, 97, 98, 99, 2000, 2001, 2002
+;; Copyright (C) 1985,86,87,92,93,94,95,96,97,98,99,2000,01,02,03,2004
 ;;;   Free Software Foundation, Inc.
 
 ;; Maintainer: FSF
@@ -42,7 +42,7 @@
 (defcustom delete-auto-save-files t
   "*Non-nil means delete auto-save file when a buffer is saved or killed.
 
-Note that auto-save file will not be deleted if the buffer is killed
+Note that the auto-save file will not be deleted if the buffer is killed
 when it has unsaved changes."
   :type 'boolean
   :group 'auto-save)
@@ -355,10 +355,14 @@ The functions are called in the order given until one of them returns non-nil.")
 
 ;;;It is not useful to make this a local variable.
 ;;;(put 'find-file-hooks 'permanent-local t)
-(defvar find-file-hook nil
+(defcustom find-file-hook nil
   "List of functions to be called after a buffer is loaded from a file.
 The buffer's local variables (if any) will have been processed before the
-functions are called.")
+functions are called."
+  :group 'find-file
+  :type 'hook
+  :options '(auto-insert)
+  :version "21.4")
 (defvaralias 'find-file-hooks 'find-file-hook)
 (make-obsolete-variable 'find-file-hooks 'find-file-hook "21.4")
 
@@ -371,7 +375,12 @@ So any buffer-local binding of this variable is discarded if you change
 the visited file name with \\[set-visited-file-name], but not when you
 change the major mode.
 
-See also `write-contents-functions'.")
+This hook is not run if any of the functions in
+`write-contents-functions' returns non-nil.  Both hooks pertain
+to how to save a buffer to file, for instance, choosing a suitable
+coding system and setting mode bits.  (See Info
+node `(elisp)Saving Buffers'.)  To perform various checks or
+updates before the buffer is saved, use `before-save-hook' .")
 (put 'write-file-functions 'permanent-local t)
 (defvaralias 'write-file-hooks 'write-file-functions)
 (make-obsolete-variable 'write-file-hooks 'write-file-functions "21.4")
@@ -391,7 +400,11 @@ buffer's contents, not to the particular visited file; thus,
 `set-visited-file-name' does not clear this variable; but changing the
 major mode does clear it.
 
-See also `write-file-functions'.")
+For hooks that _do_ pertain to the particular visited file, use
+`write-file-functions'.  Both this variable and
+`write-file-functions' relate to how a buffer is saved to file.
+To perform various checks or updates before the buffer is saved,
+use `before-save-hook'.")
 (make-variable-buffer-local 'write-contents-functions)
 (defvaralias 'write-contents-hooks 'write-contents-functions)
 (make-obsolete-variable 'write-contents-hooks 'write-contents-functions "21.4")
@@ -477,13 +490,18 @@ patterns and to guarantee valid names."
 (defun read-directory-name (prompt &optional dir default-dirname mustmatch initial)
   "Read directory name, prompting with PROMPT and completing in directory DIR.
 Value is not expanded---you must call `expand-file-name' yourself.
-Default name to DEFAULT-DIRNAME if user enters a null string.
+Default name to DEFAULT-DIRNAME if user exits with the same
+non-empty string that was inserted by this function.
  (If DEFAULT-DIRNAME is omitted, the current buffer's directory is used,
   except that if INITIAL is specified, that combined with DIR is used.)
+If the user exits with an empty minibuffer, this function returns
+an empty string.  (This can only happen if the user erased the
+pre-inserted contents or if `insert-default-directory' is nil.)
 Fourth arg MUSTMATCH non-nil means require existing directory's name.
  Non-nil and non-t means also require confirmation after completion.
 Fifth arg INITIAL specifies text to start with.
-DIR defaults to current buffer's directory default."
+DIR should be an absolute directory name.  It defaults to
+the value of `default-directory'."
   (unless dir
     (setq dir default-directory))
   (unless default-dirname
@@ -598,6 +616,8 @@ PATH-AND-SUFFIXES is a pair of lists (DIRECTORIES . SUFFIXES)."
          (suffix (concat (regexp-opt (cdr path-and-suffixes) t) "\\'"))
          (string-dir (file-name-directory string)))
       (dolist (dir (car path-and-suffixes))
+       (unless dir
+         (setq dir default-directory))
        (if string-dir (setq dir (expand-file-name string-dir dir)))
        (when (file-directory-p dir)
          (dolist (file (file-name-all-completions
@@ -650,14 +670,17 @@ Do not specify them in other calls."
   ;; PREV-DIRS can be a cons cell whose car is an alist
   ;; of truenames we've just recently computed.
 
-  ;; The last test looks dubious, maybe `+' is meant here?  --simon.
-  (if (or (string= filename "") (string= filename "~")
-         (and (string= (substring filename 0 1) "~")
-              (string-match "~[^/]*" filename)))
-      (progn
-       (setq filename (expand-file-name filename))
-       (if (string= filename "")
-           (setq filename "/"))))
+  (cond ((or (string= filename "") (string= filename "~"))
+        (setq filename (expand-file-name filename))
+        (if (string= filename "")
+            (setq filename "/")))
+       ((and (string= (substring filename 0 1) "~")
+             (string-match "~[^/]*/?" filename))
+        (let ((first-part
+               (substring filename 0 (match-end 0)))
+              (rest (substring filename (match-end 0))))
+          (setq filename (concat (expand-file-name first-part) rest)))))
+
   (or counter (setq counter (list 100)))
   (let (done
        ;; For speed, remove the ange-ftp completion handler from the list.
@@ -803,7 +826,7 @@ use with M-x."
                            default-coding))
        (setq from-coding (read-coding-system
                          (format "Recode filename %s from: " filename))))
-     
+
      ;; We provide the default coding only when a user is going to
      ;; change the encoding not from the default coding.
      (if (eq from-coding default-coding)
@@ -837,7 +860,9 @@ do not put this buffer at the front of the list of recently selected ones.
 This uses the function `display-buffer' as a subroutine; see its
 documentation for additional customization information."
   (interactive "BSwitch to buffer in other window: ")
-  (let ((pop-up-windows t))
+  (let ((pop-up-windows t)
+       ;; Don't let these interfere.
+       same-window-buffer-names same-window-regexps)
     (pop-to-buffer buffer t norecord)))
 
 (defun switch-to-buffer-other-frame (buffer &optional norecord)
@@ -848,7 +873,8 @@ do not put this buffer at the front of the list of recently selected ones.
 This uses the function `display-buffer' as a subroutine; see its
 documentation for additional customization information."
   (interactive "BSwitch to buffer in other frame: ")
-  (let ((pop-up-frames t))
+  (let ((pop-up-frames t)
+       same-window-buffer-names same-window-regexps)
     (pop-to-buffer buffer t norecord)
     (raise-frame (window-frame (selected-window)))))
 
@@ -1173,8 +1199,11 @@ suppresses this warning."
   :type 'boolean)
 
 (defcustom large-file-warning-threshold 10000000
-  "Maximum size of file above which a confirmation is requested."
-  :type 'integer)
+  "Maximum size of file above which a confirmation is requested.
+When nil, never request confirmation."
+  :group 'files
+  :group 'find-file
+  :type '(choice integer (const :tag "Never request confirmation" nil)))
 
 (defun find-file-noselect (filename &optional nowarn rawfile wildcards)
   "Read file FILENAME into a buffer and return the buffer.
@@ -1412,15 +1441,17 @@ This function ensures that none of these modifications will take place."
        (coding-system-for-read 'no-conversion)
        (coding-system-for-write 'no-conversion)
        (find-buffer-file-type-function
-        (if (fboundp 'find-buffer-file-type)
-            (symbol-function 'find-buffer-file-type)
-          nil))
-       (inhibit-file-name-handlers '(jka-compr-handler image-file-handler))
-       (inhibit-file-name-operation 'insert-file-contents))
+         (if (fboundp 'find-buffer-file-type)
+             (symbol-function 'find-buffer-file-type)
+           nil))
+        (inhibit-file-name-handlers
+         (append '(jka-compr-handler image-file-handler)
+                 inhibit-file-name-handlers))
+        (inhibit-file-name-operation 'insert-file-contents))
     (unwind-protect
-       (progn
-         (fset 'find-buffer-file-type (lambda (filename) t))
-         (insert-file-contents filename visit beg end replace))
+         (progn
+           (fset 'find-buffer-file-type (lambda (filename) t))
+           (insert-file-contents filename visit beg end replace))
       (if find-buffer-file-type-function
          (fset 'find-buffer-file-type find-buffer-file-type-function)
        (fmakunbound 'find-buffer-file-type)))))
@@ -1519,12 +1550,10 @@ unless NOMODES is non-nil."
              (setq buffer-read-only nil))
             (t
              (setq buffer-read-only nil)
-             (if (file-exists-p (file-name-directory (directory-file-name (file-name-directory buffer-file-name))))
-                 "Use M-x make-directory RET RET to create the directory"
-               "Use C-u M-x make-directory RET RET to create directory and its parents")))))
+             "Use M-x make-directory RET RET to create the directory and its parents"))))
       (when msg
        (message "%s" msg)
-       (or not-serious (sit-for 1 nil t))))
+       (or not-serious (sit-for 1 t))))
     (when (and auto-save-default (not noauto))
       (auto-save-mode t)))
   ;; Make people do a little extra work (C-x C-q)
@@ -1585,18 +1614,20 @@ in that case, this function acts as if `enable-local-variables' were t."
       (ucs-set-table-for-input)))
 
 (defvar auto-mode-alist
+  ;; Note: The entries for the modes defined in cc-mode.el (c-mode,
+  ;; c++-mode, java-mode and more) are added through autoload
+  ;; directives in that file.  That way is discouraged since it
+  ;; spreads out the definition of the initial value.
   (mapc
    (lambda (elt)
      (cons (purecopy (car elt)) (cdr elt)))
    '(("\\.te?xt\\'" . text-mode)
-     ("\\.c\\'" . c-mode)
-     ("\\.h\\'" . c-mode)
      ("\\.tex\\'" . tex-mode)
      ("\\.ins\\'" . tex-mode)          ;Installation files for TeX packages.
      ("\\.ltx\\'" . latex-mode)
      ("\\.dtx\\'" . doctex-mode)
      ("\\.el\\'" . emacs-lisp-mode)
-     ("\\.scm\\'" . scheme-mode)
+     ("\\.\\(scm\\|stk\\|ss\\|sch\\)\\'" . scheme-mode)
      ("\\.l\\'" . lisp-mode)
      ("\\.lisp\\'" . lisp-mode)
      ("\\.f\\'" . fortran-mode)
@@ -1608,18 +1639,6 @@ in that case, this function acts as if `enable-local-variables' were t."
      ("\\.ad[bs].dg\\'" . ada-mode)
      ("\\.\\([pP]\\([Llm]\\|erl\\)\\|al\\)\\'" . perl-mode)
      ("\\.s?html?\\'" . html-mode)
-     ("\\.cc\\'" . c++-mode)
-     ("\\.hh\\'" . c++-mode)
-     ("\\.hpp\\'" . c++-mode)
-     ("\\.C\\'" . c++-mode)
-     ("\\.H\\'" . c++-mode)
-     ("\\.cpp\\'" . c++-mode)
-     ("\\.cxx\\'" . c++-mode)
-     ("\\.hxx\\'" . c++-mode)
-     ("\\.c\\+\\+\\'" . c++-mode)
-     ("\\.h\\+\\+\\'" . c++-mode)
-     ("\\.m\\'" . objc-mode)
-     ("\\.java\\'" . java-mode)
      ("\\.mk\\'" . makefile-mode)
      ("\\(M\\|m\\|GNUm\\)akefile\\'" . makefile-mode)
      ("\\.am\\'" . makefile-mode)      ;For Automake.
@@ -1649,7 +1668,6 @@ in that case, this function acts as if `enable-local-variables' were t."
      ("\\.me\\'" . nroff-mode)
      ("\\.ms\\'" . nroff-mode)
      ("\\.man\\'" . nroff-mode)
-     ("\\.\\(u?lpc\\|pike\\|pmod\\)\\'" . pike-mode)
      ("\\.TeX\\'" . tex-mode)
      ("\\.sty\\'" . latex-mode)
      ("\\.cls\\'" . latex-mode)                ;LaTeX 2e class
@@ -1676,7 +1694,6 @@ in that case, this function acts as if `enable-local-variables' were t."
      ("\\.indent\\.pro\\'" . fundamental-mode) ; to avoid idlwave-mode
      ("\\.pro\\'" . idlwave-mode)
      ("\\.lsp\\'" . lisp-mode)
-     ("\\.awk\\'" . awk-mode)
      ("\\.prolog\\'" . prolog-mode)
      ("\\.tar\\'" . tar-mode)
      ("\\.\\(arc\\|zip\\|lzh\\|zoo\\|ear\\|jar\\|war\\)\\'" . archive-mode)
@@ -1690,15 +1707,12 @@ in that case, this function acts as if `enable-local-variables' were t."
      ("\\.zone\\'" . zone-mode)
      ;; some news reader is reported to use this
      ("\\`/tmp/fol/" . text-mode)
-     ("\\.y\\'" . c-mode)
-     ("\\.lex\\'" . c-mode)
      ("\\.oak\\'" . scheme-mode)
      ("\\.sgml?\\'" . sgml-mode)
      ("\\.xml\\'" . sgml-mode)
      ("\\.xsl\\'" . sgml-mode)
      ("\\.dtd\\'" . sgml-mode)
      ("\\.ds\\(ss\\)?l\\'" . dsssl-mode)
-     ("\\.idl\\'" . idl-mode)
      ;; .emacs or .gnus or .viper following a directory delimiter in
      ;; Unix, MSDOG or VMS syntax.
      ("[]>:/\\]\\..*\\(emacs\\|gnus\\|viper\\)\\'" . emacs-lisp-mode)
@@ -1729,6 +1743,7 @@ in that case, this function acts as if `enable-local-variables' were t."
      ("\\.[1-9]\\'" . nroff-mode)
      ("\\.g\\'" . antlr-mode)
      ("\\.ses\\'" . ses-mode)
+     ("\\.orig\\'" nil t)              ; from patch
      ("\\.in\\'" nil t)))
   "Alist of filename patterns vs corresponding major mode functions.
 Each element looks like (REGEXP . FUNCTION) or (REGEXP FUNCTION NON-NIL).
@@ -1742,6 +1757,10 @@ REGEXP and search the list again for another match.")
 
 
 (defvar interpreter-mode-alist
+  ;; Note: The entries for the modes defined in cc-mode.el (awk-mode
+  ;; and pike-mode) are added through autoload directives in that
+  ;; file.  That way is discouraged since it spreads out the
+  ;; definition of the initial value.
   (mapc
    (lambda (l)
      (cons (purecopy (car l)) (cdr l)))
@@ -1752,10 +1771,6 @@ REGEXP and search the list again for another match.")
      ("wishx" . tcl-mode)
      ("tcl" . tcl-mode)
      ("tclsh" . tcl-mode)
-     ("awk" . awk-mode)
-     ("mawk" . awk-mode)
-     ("nawk" . awk-mode)
-     ("gawk" . awk-mode)
      ("scm" . scheme-mode)
      ("ash" . sh-mode)
      ("bash" . sh-mode)
@@ -2166,7 +2181,7 @@ is specified, returning t if it is specified."
 (put 'format-alist 'risky-local-variable t)
 (put 'vc-mode 'risky-local-variable t)
 (put 'imenu-generic-expression 'risky-local-variable t)
-(put 'imenu-index-alist 'risky-local-variable t)
+(put 'imenu--index-alist 'risky-local-variable t)
 (put 'standard-input 'risky-local-variable t)
 (put 'standard-output 'risky-local-variable t)
 (put 'unread-command-events 'risky-local-variable t)
@@ -2186,9 +2201,10 @@ is specified, returning t if it is specified."
 ;; This case is safe because the user gets to check it before it is used.
 (put 'compile-command 'safe-local-variable 'stringp)
 
-(defun risky-local-variable-p (sym val)
+(defun risky-local-variable-p (sym &optional val)
   "Non-nil if SYM could be dangerous as a file-local variable with value VAL.
-If VAL is nil, the question is whether any value might be dangerous."
+If VAL is nil or omitted, the question is whether any value might be
+dangerous."
   (let ((safep (get sym 'safe-local-variable)))
     (or (memq sym ignored-local-variables)
        (get sym 'risky-local-variable)
@@ -2355,6 +2371,8 @@ the old visited file has been renamed to the new name FILENAME."
          (if (eq system-type 'vax-vms)
              (setq new-name (downcase new-name)))
          (setq default-directory (file-name-directory buffer-file-name))
+         ;; If new-name == old-name, renaming would add a spurious <2>
+         ;; and it's considered as a feature in rename-buffer.
          (or (string= new-name (buffer-name))
              (rename-buffer new-name t))))
     (setq buffer-backed-up nil)
@@ -2365,7 +2383,7 @@ the old visited file has been renamed to the new name FILENAME."
        (progn
          (setq buffer-file-truename (abbreviate-file-name truename))
          (if find-file-visit-truename
-             (setq buffer-file-name buffer-file-truename))))
+             (setq buffer-file-name truename))))
     (setq buffer-file-number
          (if filename
              (nthcdr 10 (file-attributes buffer-file-name))
@@ -2424,7 +2442,7 @@ This makes the buffer visit that file, and marks it as not modified.
 
 If you specify just a directory name as FILENAME, that means to use
 the default file name but in that directory.  You can also yank
-the default file name into the minibuffer to edit it, using M-n.
+the default file name into the minibuffer to edit it, using \\<minibuffer-local-map>\\[next-history-element].
 
 If the buffer is not already visiting a file, the default file name
 for the output file is the buffer name.
@@ -2556,7 +2574,8 @@ BACKUPNAME is the backup file name, which is the old file renamed."
              (not (file-writable-p to-name)))
         (delete-file to-name))
      (copy-file from-name to-name t t)))
-  (set-file-modes to-name (logand modes #o1777)))
+  (and modes
+       (set-file-modes to-name (logand modes #o1777))))
 
 (defun file-name-sans-versions (name &optional keep-backup-version)
   "Return file NAME sans backup versions or strings.
@@ -2891,9 +2910,9 @@ on a DOS/Windows machine, it returns FILENAME on expanded form."
          (or
           ;; Test for different drives on DOS/Windows
           (and
+           ;; Should `cygwin' really be included here?  --stef
            (memq system-type '(ms-dos cygwin windows-nt))
-           (not (string-equal (substring filename  0 2)
-                              (substring directory 0 2))))
+           (not (eq t (compare-strings filename 0 2 directory 0 2))))
           ;; Test for different remote file handlers
           (not (eq hf hd))
           ;; Test for different remote file system identification
@@ -2909,27 +2928,24 @@ on a DOS/Windows machine, it returns FILENAME on expanded form."
                 (string-match re directory)
                 (substring directory 0 (match-end 0))))))))
          filename
-        (unless (eq (aref filename 0) ?/)
-         (setq filename (concat "/" filename)))
-        (unless (eq (aref directory 0) ?/)
-         (setq directory (concat "/" directory)))
         (let ((ancestor ".")
              (filename-dir (file-name-as-directory filename)))
-          (while
-             (and
-              (not (string-match (concat "^" (regexp-quote directory))
-                                 filename-dir))
-              (not (string-match (concat "^" (regexp-quote directory))
-                                 filename)))
+          (while (not
+                 (or
+                  (eq t (compare-strings filename-dir nil (length directory)
+                                         directory nil nil case-fold-search))
+                  (eq t (compare-strings filename nil (length directory)
+                                         directory nil nil case-fold-search))))
             (setq directory (file-name-directory (substring directory 0 -1))
                  ancestor (if (equal ancestor ".")
                               ".."
                             (concat "../" ancestor))))
           ;; Now ancestor is empty, or .., or ../.., etc.
-          (if (string-match (concat "^" (regexp-quote directory)) filename)
+          (if (eq t (compare-strings filename nil (length directory)
+                                    directory nil nil case-fold-search))
              ;; We matched within FILENAME's directory part.
              ;; Add the rest of FILENAME onto ANCESTOR.
-             (let ((rest (substring filename (match-end 0))))
+             (let ((rest (substring filename (length directory))))
                (if (and (equal ancestor ".") (not (equal rest "")))
                    ;; But don't bother with ANCESTOR if it would give us `./'.
                    rest
@@ -2997,6 +3013,12 @@ the last real save, but optional arg FORCE non-nil means delete anyway."
 (defvar auto-save-hook nil
   "Normal hook run just before auto-saving.")
 
+(defcustom before-save-hook nil
+  "Normal hook that is run before a buffer is saved to its file."
+  :options '(copyright-update)
+  :type 'hook
+  :group 'files)
+
 (defcustom after-save-hook nil
   "Normal hook that is run after a buffer is saved to its file."
   :options '(executable-make-buffer-file-executable-if-script-p)
@@ -3019,7 +3041,8 @@ in such cases.")
 The hooks `write-contents-functions' and `write-file-functions' get a chance
 to do the job of saving; if they do not, then the buffer is saved in
 the visited file file in the usual way.
-After saving the buffer, this function runs `after-save-hook'."
+Before and after saving the buffer, this function runs
+`before-save-hook' and `after-save-hook', respectively."
   (interactive)
   (save-current-buffer
     ;; In an indirect buffer, save its base buffer instead.
@@ -3075,6 +3098,7 @@ After saving the buffer, this function runs `after-save-hook'."
                     (insert ?\n))))
            ;; Support VC version backups.
            (vc-before-save)
+           (run-hooks 'before-save-hook)
            (or (run-hook-with-args-until-success 'write-contents-functions)
                (run-hook-with-args-until-success 'local-write-file-hooks)
                (run-hook-with-args-until-success 'write-file-functions)
@@ -3357,7 +3381,7 @@ saying what text to write."
   ;; ordinary or numeric backups.  It might create a directory for
   ;; backups as a side-effect, according to `backup-directory-alist'.
   (let* ((filename (file-name-sans-versions
-                   (make-backup-file-name filename)))
+                   (make-backup-file-name (expand-file-name filename))))
         (file (file-name-nondirectory filename))
         (dir  (file-name-directory    filename))
         (comp (file-name-all-completions file dir))
@@ -3398,7 +3422,8 @@ is the current default directory for file names.
 That is useful when you have visited a file in a nonexistent directory.
 
 Noninteractively, the second (optional) argument PARENTS says whether
-to create parent directories if they don't exist."
+to create parent directories if they don't exist.  Interactively,
+this happens by default."
   (interactive
    (list (read-file-name "Make directory: " default-directory default-directory
                         nil nil)
@@ -3434,6 +3459,20 @@ and second, t if reading the auto-save file.
 
 The function you specify is responsible for updating (or preserving) point.")
 
+(defvar buffer-stale-function nil
+  "Function to check whether a non-file buffer needs reverting.
+This should be a function with one optional argument NOCONFIRM.
+Auto Revert Mode sets NOCONFIRM to t.  The function should return
+non-nil if the buffer should be reverted.  A return value of
+`fast' means that the need for reverting was not checked, but
+that reverting the buffer is fast.  The buffer is current when
+this function is called.
+
+The idea behind the NOCONFIRM argument is that it should be
+non-nil if the buffer is going to be reverted without asking the
+user.  In such situations, one has to be careful with potentially
+time consuming operations.")
+
 (defvar before-revert-hook nil
   "Normal hook for `revert-buffer' to run before reverting.
 If `revert-buffer-function' is used to override the normal revert
@@ -3549,8 +3588,7 @@ non-nil, it is called instead of rereading visited file contents."
                          (if auto-save-p 'emacs-mule-unix
                            (or coding-system-for-read
                                buffer-file-coding-system))))
-                    ;; This force
-                    ;; after-insert-file-set-buffer-file-coding-system
+                    ;; This force after-insert-file-set-coding
                     ;; (called from insert-file-contents) to set
                     ;; buffer-file-coding-system to a proper value.
                     (kill-local-variable 'buffer-file-coding-system)
@@ -3618,8 +3656,8 @@ non-nil, it is called instead of rereading visited file contents."
           (let ((buffer-read-only nil)
                 ;; Keep the current buffer-file-coding-system.
                 (coding-system buffer-file-coding-system)
-                ;; Auto-saved file shoule be read without any code conversion.
-                (coding-system-for-read 'emacs-mule-unix))
+                ;; Auto-saved file shoule be read with special coding.
+                (coding-system-for-read 'auto-save-coding))
             (erase-buffer)
             (insert-file-contents file-name nil)
             (set-buffer-file-coding-system coding-system))
@@ -3687,18 +3725,21 @@ This command is used in the special Dired buffer created by
                  ;; a "visited file name" from that.
                  (progn
                    (forward-line 1)
-                   (setq autofile
-                         (buffer-substring-no-properties
-                          (point)
-                          (save-excursion
-                            (end-of-line)
-                            (point))))
-                   (setq thisfile
-                         (expand-file-name
-                          (substring
-                           (file-name-nondirectory autofile)
-                           1 -1)
-                          (file-name-directory autofile)))
+                   ;; If there is no auto-save file name, the
+                   ;; auto-save-list file is probably corrupted.
+                   (unless (eolp)
+                     (setq autofile
+                           (buffer-substring-no-properties
+                            (point)
+                            (save-excursion
+                              (end-of-line)
+                              (point))))
+                     (setq thisfile
+                           (expand-file-name
+                            (substring
+                             (file-name-nondirectory autofile)
+                             1 -1)
+                            (file-name-directory autofile))))
                    (forward-line 1))
                ;; This pair of lines is a file-visiting
                ;; buffer.  Use the visited file name.
@@ -3712,7 +3753,7 @@ This command is used in the special Dired buffer created by
                         (point) (progn (end-of-line) (point))))
                  (forward-line 1)))
              ;; Ignore a file if its auto-save file does not exist now.
-             (if (file-exists-p autofile)
+             (if (and autofile (file-exists-p autofile))
                  (setq files (cons thisfile files)))))
          (setq files (nreverse files))
          ;; The file contains a pair of line for each auto-saved buffer.
@@ -3732,8 +3773,9 @@ This command is used in the special Dired buffer created by
       (kill-buffer buffer))))
 
 (defun kill-some-buffers (&optional list)
-  "For each buffer in LIST, ask whether to kill it.
-LIST defaults to all existing live buffers."
+  "Kill some buffers.  Asks the user whether to kill each one of them.
+Non-interactively, if optional argument LIST is non-`nil', it
+specifies the list of buffers to kill, asking for approval for each one."
   (interactive)
   (if (null list)
       (setq list (buffer-list)))
@@ -4140,10 +4182,10 @@ program specified by `directory-free-space-program' if that is non-nil."
     (save-match-data
       (with-temp-buffer
        (when (and directory-free-space-program
-                  (zerop (call-process directory-free-space-program
-                                       nil t nil
-                                       directory-free-space-args
-                                       dir)))
+                  (eq 0 (call-process directory-free-space-program
+                                      nil t nil
+                                      directory-free-space-args
+                                      dir)))
          ;; Usual format is a header line followed by a line of
          ;; numbers.
          (goto-char (point-min))
@@ -4183,14 +4225,20 @@ program specified by `directory-free-space-program' if that is non-nil."
 (defun insert-directory (file switches &optional wildcard full-directory-p)
   "Insert directory listing for FILE, formatted according to SWITCHES.
 Leaves point after the inserted text.
-SWITCHES may be a string of options, or a list of strings.
+SWITCHES may be a string of options, or a list of strings
+representing individual options.
 Optional third arg WILDCARD means treat FILE as shell wildcard.
 Optional fourth arg FULL-DIRECTORY-P means file is a directory and
 switches do not contain `d', so that a full listing is expected.
 
 This works by running a directory listing program
 whose name is in the variable `insert-directory-program'.
-If WILDCARD, it also runs the shell specified by `shell-file-name'."
+If WILDCARD, it also runs the shell specified by `shell-file-name'.
+
+When SWITCHES contains the long `--dired' option, this function
+treats it specially, for the sake of dired.  However, the
+normally equivalent short `-D' option is just passed on to
+`insert-directory-program', as any other option."
   ;; We need the directory in order to find the right handler.
   (let ((handler (find-file-name-handler (expand-file-name file)
                                         'insert-directory)))
@@ -4263,23 +4311,27 @@ If WILDCARD, it also runs the shell specified by `shell-file-name'."
                                 file))))))))
 
          ;; If `insert-directory-program' failed, signal an error.
-         (if (/= result 0)
-             ;; On non-Posix systems, we cannot open a directory, so
-             ;; don't even try, because that will always result in
-             ;; the ubiquitous "Access denied".  Instead, show the
-             ;; command line so the user can try to guess what went wrong.
-             (if (and (file-directory-p file)
-                      (memq system-type '(ms-dos windows-nt)))
-                 (error
-                  "Reading directory: \"%s %s -- %s\" exited with status %s"
-                  insert-directory-program
-                  (if (listp switches) (concat switches) switches)
-                  file result)
-               ;; Unix.  Access the file to get a suitable error.
-               (access-file file "Reading directory")
-               (error "Listing directory failed but `access-file' worked")))
-
-         (when (string-match "--dired\\>" switches)
+         (unless (eq 0 result)
+           ;; Delete the error message it may have output.
+           (delete-region beg (point))
+           ;; On non-Posix systems, we cannot open a directory, so
+           ;; don't even try, because that will always result in
+           ;; the ubiquitous "Access denied".  Instead, show the
+           ;; command line so the user can try to guess what went wrong.
+           (if (and (file-directory-p file)
+                    (memq system-type '(ms-dos windows-nt)))
+               (error
+                "Reading directory: \"%s %s -- %s\" exited with status %s"
+                insert-directory-program
+                (if (listp switches) (concat switches) switches)
+                file result)
+             ;; Unix.  Access the file to get a suitable error.
+             (access-file file "Reading directory")
+             (error "Listing directory failed but `access-file' worked")))
+
+         (when (if (stringp switches)
+                   (string-match "--dired\\>" switches)
+                 (member "--dired" switches))
            (forward-line -2)
             (when (looking-at "//SUBDIRED//")
               (delete-region (point) (progn (forward-line 1) (point)))
@@ -4305,6 +4357,7 @@ If WILDCARD, it also runs the shell specified by `shell-file-name'."
                            file-name-coding-system
                            default-file-name-coding-system
                            'undecided))
+               coding-no-eol
                val pos)
            (when (and enable-multibyte-characters
                       (not (memq (coding-system-base coding)
@@ -4315,6 +4368,8 @@ If WILDCARD, it also runs the shell specified by `shell-file-name'."
                  (setq coding (detect-coding-region beg (point) t)))
              (if (not (eq (coding-system-base coding) 'undecided))
                  (save-restriction
+                   (setq coding-no-eol
+                         (coding-system-change-eol-conversion coding 'unix))
                    (narrow-to-region beg (point))
                    (goto-char (point-min))
                    (while (not (eobp))
@@ -4322,7 +4377,10 @@ If WILDCARD, it also runs the shell specified by `shell-file-name'."
                            val (get-text-property (point) 'dired-filename))
                      (goto-char (next-single-property-change
                                  (point) 'dired-filename nil (point-max)))
-                     (decode-coding-region pos (point) coding)
+                     ;; Force no eol conversion on a file name, so
+                     ;; that CR is preserved.
+                     (decode-coding-region pos (point)
+                                           (if val coding-no-eol coding))
                      (if val
                          (put-text-property pos (point)
                                             'dired-filename t)))))))
@@ -4480,4 +4538,5 @@ With prefix arg, silently save all file-visiting buffers, then kill."
 (define-key ctl-x-5-map "\C-f" 'find-file-other-frame)
 (define-key ctl-x-5-map "r" 'find-file-read-only-other-frame)
 
+;;; arch-tag: bc68d3ea-19ca-468b-aac6-3a4a7766101f
 ;;; files.el ends here