Subject: working recover-file function

From: [email-masked] (Douglas Gray Stephens)
Date: Fri, 11 Oct 96 17:57:45 CDT

Hi,

The standard recover-file function in file.el gets the file details by
expecting the system to have a command called "ls", which is normally
available on Unix boxes.  It fails gracefully on VMS boxes, but
creates an error on NT boxes.

I've modified this function, so that it will work on NT, by processing
the file attributes.  This should work on all platforms, and may be a
better way for the distributed platform independent version of emacs
to work.

The modifed recover-file function, and a emacs-ls-function that
recover-file calls are appended to this message.

Douglas.

================================
Dr. Douglas GRAY STEPHENS        
Schlubmerger Austin Product Centre,
8311 North FM 620,
AUSTIN,
TX 78726

Phone +1 512 331 3717
Fax   +1 512 331 3760
Email [email-masked]
================================

;;  Modified to work with windows as NT does not have native ls
(defun recover-file (file)
  "Visit file FILE, but get contents from its last auto-save file."
  ;; Actually putting the file name in the minibuffer should be used
  ;; only rarely.
  ;; Not just because users often use the default.
  (interactive "FRecover file: ")
  (setq file (expand-file-name file))
  (if (auto-save-file-name-p (file-name-nondirectory file))
      (error "%s is an auto-save file" file))
  (let ((file-name (let ((buffer-file-name file))
		     (make-auto-save-file-name))))
    (cond ((if (file-exists-p file)
	       (not (file-newer-than-file-p file-name file))
	     (not (file-exists-p file-name)))
	   (error "Auto-save file %s not current" file-name))
	  ((save-window-excursion
	     ;; Fri 11-Oct-1996; Douglas Gray Stephens 
	     ;; added this test for NT 
             ;; (I guess that it be used on all platforms)
	     (if (eq system-type 'windows-nt)
		 (progn
		   (get-buffer-create "*Directory*")
		   (switch-to-buffer-other-window "*Directory*")
		   (erase-buffer)
		   (insert (emacs-ls-function file))
		   (insert (emacs-ls-function file-name))
		   )
	       (if (not (eq system-type 'vax-vms))
		   (with-output-to-temp-buffer "*Directory*"
		     (buffer-disable-undo standard-output)
		     (call-process "ls" nil standard-output nil
				   (if (file-symlink-p file) "-lL" "-l")
				   file file-name))))
	   (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))
	     (erase-buffer)
	     (insert-file-contents file-name nil))
	   (after-find-file nil nil t))
	  (t (error "Recover-file cancelled.")))))

;; Function for use with modified recover file.
(defun emacs-ls-function (file)
  "Return similar information to Unix \"ls -l\" command"
  (format "%s  %8s  %10.0d  %s  %s\n"
	  (nth 8 (file-attributes
		  file)
	       )
	  (user-login-name
	   (nth 3 (file-attributes
		   file)
		)
	   )
	  (nth 7 (file-attributes 
		  file))
	  (current-time-string 
	   (nth 5 (file-attributes
		   file)))
	  file
	  )
  )