]> code.delx.au - gnu-emacs/blobdiff - lisp/files.el
*** empty log message ***
[gnu-emacs] / lisp / files.el
index b6bee3b09d44dc816e21b1111a3698877ff50cc1..acfea07992f5c46d5351a23e9308776bbbca2972 100644 (file)
@@ -215,7 +215,7 @@ have fast storage with limited space, such as a RAM disk."
                 "[\000-\031]\\|"                 ; control characters
                 "\\(/\\.\\.?[^/]\\)\\|"          ; leading dots
                 "\\(/[^/.]+\\.[^/.]*\\.\\)"))    ; more than a single dot
-       ((memq system-type '(ms-dos windows-nt))
+       ((memq system-type '(ms-dos windows-nt cygwin))
         (concat "^\\([^A-Z[-`a-z]\\|..+\\)?:\\|" ; colon except after drive
                 "[|<>\"?*\000-\031]"))           ; invalid characters
        (t "[\000]"))
@@ -682,10 +682,8 @@ Do not specify them in other calls."
            (setq filename (funcall handler 'file-truename filename))
          ;; If filename contains a wildcard, newname will be the old name.
          (unless (string-match "[[*?]" filename)
-           ;; If filename exists, use the long name, otherwise
-           ;; canonicalize the name, to handle case differences.
-           (setq filename (or (w32-long-file-name filename)
-                              (untranslated-canonical-name filename)))))
+           ;; If filename exists, use the long name
+           (setq filename (or (w32-long-file-name filename) filename))))
        (setq done t)))
 
     ;; If this file directly leads to a link, process that iteratively
@@ -940,6 +938,7 @@ If the current buffer now contains an empty file that you just visited
   (let ((obuf (current-buffer))
        (ofile buffer-file-name)
        (onum buffer-file-number)
+       (odir dired-directory)
        (otrue buffer-file-truename)
        (oname (buffer-name)))
     (if (get-buffer " **lose**")
@@ -948,9 +947,13 @@ If the current buffer now contains an empty file that you just visited
     (unwind-protect
        (progn
          (unlock-buffer)
+         ;; This prevents us from finding the same buffer
+         ;; if we specified the same file again.
          (setq buffer-file-name nil)
          (setq buffer-file-number nil)
          (setq buffer-file-truename nil)
+         ;; Likewise for dired buffers.
+         (setq dired-directory nil)
          (find-file filename))
       (when (eq obuf (current-buffer))
        ;; This executes if find-file gets an error
@@ -960,6 +963,7 @@ If the current buffer now contains an empty file that you just visited
        (setq buffer-file-name ofile)
        (setq buffer-file-number onum)
        (setq buffer-file-truename otrue)
+       (setq dired-directory odir)
        (lock-buffer)
        (rename-buffer oname)))
     (unless (eq (current-buffer) obuf)
@@ -992,8 +996,8 @@ Choose the buffer's name using `generate-new-buffer-name'."
 
 (defun abbreviate-file-name (filename)
   "Return a version of FILENAME shortened using `directory-abbrev-alist'.
-This also substitutes \"~\" for the user's home directory.
-Type \\[describe-variable] directory-abbrev-alist RET for more information."
+This also substitutes \"~\" for the user's home directory and
+removes automounter prefixes (see the variable `automount-dir-prefix')."
   ;; Get rid of the prefixes added by the automounter.
   (if (and automount-dir-prefix
           (string-match automount-dir-prefix filename)
@@ -1028,6 +1032,7 @@ Type \\[describe-variable] directory-abbrev-alist RET for more information."
             ;; MS-DOS root directories can come with a drive letter;
             ;; Novell Netware allows drive letters beyond `Z:'.
             (not (and (or (eq system-type 'ms-dos)
+                          (eq system-type 'cygwin)
                           (eq system-type 'windows-nt))
                       (save-match-data
                         (string-match "^[a-zA-`]:/$" filename)))))
@@ -1250,6 +1255,7 @@ that are visiting the various files."
       ;; Needed in case we are re-visiting the file with a different
       ;; text representation.
       (kill-local-variable 'buffer-file-coding-system)
+      (kill-local-variable 'cursor-type)
       (erase-buffer)
       (and (default-value 'enable-multibyte-characters)
           (not rawfile)
@@ -1598,6 +1604,7 @@ in that case, this function acts as if `enable-local-variables' were t."
      ("\\.oak\\'" . scheme-mode)
      ("\\.sgml?\\'" . sgml-mode)
      ("\\.xml\\'" . sgml-mode)
+     ("\\.xsl\\'" . sgml-mode)
      ("\\.dtd\\'" . sgml-mode)
      ("\\.ds\\(ss\\)?l\\'" . dsssl-mode)
      ("\\.idl\\'" . idl-mode)
@@ -1773,7 +1780,7 @@ and we don't even do that unless it would come from the file name."
                  (mode nil))
              ;; Find first matching alist entry.
              (let ((case-fold-search
-                    (memq system-type '(vax-vms windows-nt))))
+                    (memq system-type '(vax-vms windows-nt cygwin))))
                (while (and (not mode) alist)
                  (if (string-match (car (car alist)) name)
                      (if (and (consp (cdr (car alist)))
@@ -2068,6 +2075,7 @@ is specified, returning t if it is specified."
 (put 'mode-line-buffer-identification 'risky-local-variable t)
 (put 'mode-line-modes 'risky-local-variable t)
 (put 'mode-line-position 'risky-local-variable t)
+(put 'mode-line-process 'risky-local-variable t)
 (put 'mode-name 'risky-local-variable t)
 (put 'display-time-string 'risky-local-variable t)
 (put 'parse-time-rules 'risky-local-variable t)
@@ -2399,7 +2407,7 @@ BACKUPNAME is the backup file name, which is the old file renamed."
     ;                        (file-symlink-p buffer-file-name)
                              backup-by-copying
                              ;; Don't rename a suid or sgid file.
-                             (< 0 (logand modes #o6000))
+                             (and modes (< 0 (logand modes #o6000)))
                              (and backup-by-copying-when-linked
                                   (> (file-nlinks real-file-name) 1))
                              (and (or backup-by-copying-when-mismatch
@@ -2613,7 +2621,7 @@ doesn't exist, it is created."
        file
       (if (file-name-absolute-p backup-directory)
          (progn
-           (when (memq system-type '(windows-nt ms-dos))
+           (when (memq system-type '(windows-nt ms-dos cygwin))
              ;; Normalize DOSish file names: downcase the drive
              ;; letter, if any, and replace the leading "x:" with
              ;; "/drive_x".
@@ -2735,6 +2743,7 @@ then it returns FILENAME."
       ;; 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 'cygwin)
                   (eq system-type 'windows-nt))
               (not (string-equal (substring fname  0 2)
                                  (substring directory 0 2))))
@@ -3134,7 +3143,7 @@ prints a message in the minibuffer.  Instead, use `set-buffer-modified-p'."
 With arg, set read-only iff arg is positive.
 If visiting file read-only and `view-read-only' is non-nil, enter view mode."
   (interactive "P")
-  (if (and arg 
+  (if (and arg
            (if (> (prefix-numeric-value arg) 0) buffer-read-only
              (not buffer-read-only)))  ; If buffer-read-only is set correctly,
       nil                             ; do nothing.
@@ -3354,7 +3363,10 @@ non-nil, it is called instead of rereading visited file contents."
                     (funcall revert-buffer-insert-file-contents-function
                              file-name auto-save-p)
                   (if (not (file-exists-p file-name))
-                      (error "File %s no longer exists!" file-name))
+                      (error (if buffer-file-number
+                                 "File %s no longer exists!"
+                               "Cannot revert nonexistent file %s")
+                             file-name))
                   ;; Bind buffer-file-name to nil
                   ;; so that we don't try to lock the file.
                   (let ((buffer-file-name nil))
@@ -3455,7 +3467,13 @@ Then you'll be asked about a number of files to recover."
       (error "You set `auto-save-list-file-prefix' to disable making session files"))
   (let ((dir (file-name-directory auto-save-list-file-prefix)))
     (unless (file-directory-p dir)
-      (make-directory dir t)))
+      (make-directory dir t))
+    (unless (directory-files dir nil
+                            (concat "\\`" (regexp-quote
+                                           (file-name-nondirectory
+                                            auto-save-list-file-prefix)))
+                            t)
+      (error "No previous sessions to recover")))
   (let ((ls-lisp-support-shell-wildcards t))
     (dired (concat auto-save-list-file-prefix "*")
           (concat dired-listing-switches "t")))
@@ -3879,7 +3897,7 @@ Existing quote characters in PATTERN are left alone, so you can pass
 PATTERN that already quotes some of the special characters."
   (save-match-data
     (cond
-     ((memq system-type '(ms-dos windows-nt))
+     ((memq system-type '(ms-dos windows-nt cygwin))
       ;; DOS/Windows don't allow `"' in file names.  So if the
       ;; argument has quotes, we can safely assume it is already
       ;; quoted by the caller.
@@ -4015,12 +4033,15 @@ If WILDCARD, it also runs the shell specified by `shell-file-name'."
 
          ;; Read the actual directory using `insert-directory-program'.
          ;; RESULT gets the status code.
-         (let* ((coding-system-for-read
+         (let* (;; We at first read by no-conversion, then after
+                ;; putting text property `dired-filename, decode one
+                ;; bunch by one to preserve that property.
+                (coding-system-for-read 'no-conversion)
+                ;; This is to control encoding the arguments in call-process.
+                (coding-system-for-write
                  (and enable-multibyte-characters
                       (or file-name-coding-system
-                          default-file-name-coding-system)))
-                ;; This is to control encoding the arguments in call-process.
-                (coding-system-for-write coding-system-for-read))
+                          default-file-name-coding-system))))
            (setq result
                  (if wildcard
                      ;; Run ls in the directory part of the file pattern
@@ -4099,22 +4120,55 @@ If WILDCARD, it also runs the shell specified by `shell-file-name'."
              (while (< (point) end)
                (let ((start (+ beg (read (current-buffer))))
                      (end (+ beg (read (current-buffer)))))
-                 (put-text-property start end 'dired-filename t)))
+                 (if (= (char-after end) ?\n)
+                     (put-text-property start end 'dired-filename t)
+                   ;; It seems that we can't trust ls's output as to
+                   ;; byte positions of filenames.
+                   (put-text-property beg (point) 'dired-filename nil)
+                   (end-of-line))))
              (goto-char end)
              (beginning-of-line)
              (delete-region (point) (progn (forward-line 2) (point)))))
 
-         ;; Try to insert the amount of free space.
-         (save-excursion
-           (goto-char beg)
-           ;; First find the line to put it on.
-           (when (re-search-forward "^ *\\(total\\)" nil t)
-             (let ((available (get-free-disk-space ".")))
-               (when available
-                 ;; Replace "total" with "used", to avoid confusion.
-                 (replace-match "total used in directory" nil nil nil 1)
-                 (end-of-line)
-                 (insert " available " available))))))))))
+         ;; Now decode what read if necessary.
+         (let ((coding (or coding-system-for-read
+                           file-name-coding-system
+                           default-file-name-coding-system
+                           'undecided))
+               val pos)
+           (when (and enable-multibyte-characters
+                      (not (memq (coding-system-base coding)
+                                 '(raw-text no-conversion))))
+             ;; If no coding system is specified or detection is
+             ;; requested, detect the coding.
+             (if (eq (coding-system-base coding) 'undecided)
+                 (setq coding (detect-coding-region beg (point) t)))
+             (if (not (eq (coding-system-base coding) 'undecided))
+                 (save-restriction
+                   (narrow-to-region beg (point))
+                   (goto-char (point-min))
+                   (while (not (eobp))
+                     (setq pos (point)
+                           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)
+                     (if val
+                         (put-text-property pos (point)
+                                            'dired-filename t)))))))
+
+         (if full-directory-p
+             ;; Try to insert the amount of free space.
+             (save-excursion
+               (goto-char beg)
+               ;; First find the line to put it on.
+               (when (re-search-forward "^ *\\(total\\)" nil t)
+                 (let ((available (get-free-disk-space ".")))
+                   (when available
+                     ;; Replace "total" with "used", to avoid confusion.
+                     (replace-match "total used in directory" nil nil nil 1)
+                     (end-of-line)
+                     (insert " available " available)))))))))))
 
 (defun insert-directory-safely (file switches
                                     &optional wildcard full-directory-p)