]> code.delx.au - gnu-emacs/blobdiff - lisp/files.el
(recover-file): Fix error message.
[gnu-emacs] / lisp / files.el
index d554005b8fa1620ee213a5d9220eaee005a2c518..15f9c3af56470b8e724b3691a7eb6f9aad666b31 100644 (file)
@@ -1063,6 +1063,7 @@ run `normal-mode' explicitly."
     ("\\.oak\\'" . scheme-mode)
     ("\\.sgml?\\'" . sgml-mode)
     ("\\.dtd\\'" . sgml-mode)
+    ("\\.ds\\(ss\\)?l\\'" . dsssl-mode)
     ("\\.s?html?\\'" . html-mode)
     ;; .emacs following a directory delimiter
     ;; in either Unix or VMS syntax.
@@ -1864,16 +1865,28 @@ If the value is nil, don't make a backup."
   (car (cdr (file-attributes filename))))
 
 (defun file-relative-name (filename &optional directory)
-  "Convert FILENAME to be relative to DIRECTORY (default: default-directory)."
+  "Convert FILENAME to be relative to DIRECTORY (default: default-directory).
+This function returns a relative file name which is equivalent to FILENAME
+when used with that default directory as the default.
+If this is impossible (which can happen on MSDOS and Windows
+when the file name and directory use different drive names)
+then it returns FILENAME."
   (save-match-data
-   (setq filename (expand-file-name filename)
-        directory (file-name-as-directory
-                   (expand-file-name (or directory default-directory))))
-   (let ((ancestor ""))
-     (while (not (string-match (concat "^" (regexp-quote directory)) filename))
-       (setq directory (file-name-directory (substring directory 0 -1))
-            ancestor (concat "../" ancestor)))
-     (concat ancestor (substring filename (match-end 0))))))
+    (setq fname (expand-file-name filename)
+         directory (file-name-as-directory
+                    (expand-file-name (or directory default-directory))))
+    ;; On Microsoft OSes, if FILENAME and DIRECTORY have different
+    ;; drive names, they can't be relative, so return the absolute name.
+    (if (and (or (eq system-type 'ms-dos)
+                (eq system-type 'windows-nt))
+            (not (string-equal (substring fname  0 2)
+                               (substring directory 0 2))))
+       filename
+      (let ((ancestor ""))
+       (while (not (string-match (concat "^" (regexp-quote directory)) fname))
+         (setq directory (file-name-directory (substring directory 0 -1))
+               ancestor (concat "../" ancestor)))
+       (concat ancestor (substring fname (match-end 0)))))))
 \f
 (defun save-buffer (&optional args)
   "Save current buffer in visited file if modified.  Versions described below.
@@ -2405,7 +2418,7 @@ non-nil, it is called instead of rereading visited file contents."
             (erase-buffer)
             (insert-file-contents file-name nil))
           (after-find-file nil nil t))
-         (t (error "Recover-file cancelled.")))))
+         (t (error "Recover-file cancelled")))))
 
 (defun recover-session ()
   "Recover auto save files from a previous Emacs session.
@@ -2417,7 +2430,8 @@ Then you'll be asked about a number of files to recover."
   (if (null auto-save-list-file-prefix)
       (error "You set `auto-save-list-file-prefix' to disable making session files"))
   (let ((ls-lisp-support-shell-wildcards t))
-    (dired (concat auto-save-list-file-prefix "*")))
+    (dired (concat auto-save-list-file-prefix "*")
+          (concat dired-listing-switches "t")))
   (goto-char (point-min))
   (or (looking-at "Move to the session you want to recover,")
       (let ((inhibit-read-only t))
@@ -2577,20 +2591,17 @@ See also `auto-save-file-name-p'."
 
     (let ((buffer-name (buffer-name))
          (limit 0))
-      ;; Use technique from Sebastian Kremer's auto-save
-      ;; package to turn slashes into \\!.  This ensures that
-      ;; the auto-save buffer name is unique.
-
-      (while (string-match "[/\\]" buffer-name limit)
-       (setq buffer-name (concat (substring buffer-name 0 (match-beginning 0))
-                       (if (string= (substring buffer-name
-                                               (match-beginning 0)
-                                               (match-end 0))
-                                    "/")
-                           "\\!"
-                         "\\\\")
-                       (substring buffer-name (match-end 0))))
-       (setq limit (1+ (match-end 0))))
+      ;; Eliminate all slashes and backslashes by
+      ;; replacing them with sequences that start with %.
+      ;; Quote % also, to keep distinct names distinct.
+      (while (string-match "[/\\%]" buffer-name limit)
+       (let* ((character (aref buffer-name (match-beginning 0)))
+              (replacement
+               (cond ((eq character ?%) "%%")
+                     ((eq character ?/) "%+")
+                     ((eq character ?\\) "%-"))))
+         (setq buffer-name (replace-match replacement t t buffer-name))
+         (setq limit (1+ (match-end 0)))))
       ;; Generate the file name.
       (expand-file-name
        (format "#%s#%s#" buffer-name (make-temp-name ""))