]> code.delx.au - gnu-emacs/blobdiff - lisp/dired.el
(dired-do-create-files): On DOS/Windows, allow to
[gnu-emacs] / lisp / dired.el
index e9426d402880c05fae79fec3c95b4f7757ee4122..393635452a171c2c01d842fbadd009314d6ed298 100644 (file)
@@ -1,6 +1,6 @@
 ;;; dired.el --- directory-browsing commands
 
-;; Copyright (C) 1985, 86, 92, 93, 94, 95, 96, 1997 Free Software Foundation, Inc.
+;; Copyright (C) 1985, 86, 92, 93, 94, 95, 96, 1997, 2000 Free Software Foundation, Inc.
 
 ;; Author: Sebastian Kremer <sk@thp.uni-koeln.de>
 ;; Maintainer: FSF
@@ -561,6 +561,12 @@ If DIRNAME is already in a dired buffer, that buffer is used without refresh."
     (set-buffer old-buf)
     buffer))
 
+(defvar dired-buffers nil
+  ;; Enlarged by dired-advertise
+  ;; Queried by function dired-buffers-for-dir. When this detects a
+  ;; killed buffer, it is removed from this list.
+  "Alist of expanded directories and their associated dired buffers.")
+
 (defun dired-find-buffer-nocreate (dirname &optional mode)
   ;; This differs from dired-buffers-for-dir in that it does not consider
   ;; subdirs of default-directory and searches for the first match only.
@@ -867,7 +873,7 @@ If DIRNAME is already in a dired buffer, that buffer is used without refresh."
     (define-key map "M" 'dired-do-chmod)
     (define-key map "O" 'dired-do-chown)
     (define-key map "P" 'dired-do-print)
-    (define-key map "Q" 'dired-do-query-replace)
+    (define-key map "Q" 'dired-do-query-replace-regexp)
     (define-key map "R" 'dired-do-rename)
     (define-key map "S" 'dired-do-symlink)
     (define-key map "X" 'dired-do-shell-command)
@@ -917,9 +923,11 @@ If DIRNAME is already in a dired buffer, that buffer is used without refresh."
     (define-key map "*\C-p" 'dired-prev-marked-file)
     (define-key map "*t" 'dired-do-toggle)
     ;; Lower keys for commands not operating on all the marked files
+    (define-key map "a" 'dired-find-alternate-file)
     (define-key map "d" 'dired-flag-file-deletion)
     (define-key map "e" 'dired-find-file)
     (define-key map "f" 'dired-find-file)
+    (define-key map "w" 'dired-show-file-type)
     (define-key map "\C-m" 'dired-advertised-find-file)
     (define-key map "g" 'revert-buffer)
     (define-key map "h" 'describe-mode)
@@ -1119,7 +1127,7 @@ If DIRNAME is already in a dired buffer, that buffer is used without refresh."
       (cons "Operate" (make-sparse-keymap "Operate")))
 
     (define-key map [menu-bar operate query-replace]
-      '(menu-item "Query Replace in Files..." dired-do-query-replace
+      '(menu-item "Query Replace in Files..." dired-do-query-replace-regexp
                  :help "Replace regexp in marked files"))
     (define-key map [menu-bar operate search]
       '(menu-item "Search Files..." dired-do-search
@@ -1343,6 +1351,12 @@ Creates a buffer if necessary."
          (error "File is a symlink to a nonexistent target")
        (error "File no longer exists; type `g' to update Dired buffer")))))
 
+(defun dired-find-alternate-file ()
+  "In dired, visit this file or directory instead of the dired buffer."
+  (interactive)
+  (set-buffer-modified-p nil)
+  (find-alternate-file (dired-get-filename)))
+
 (defun dired-mouse-find-file-other-window (event)
   "In dired, visit the file or directory name you click on."
   (interactive "e")
@@ -1486,8 +1500,10 @@ DIR must be a directory name, not a file name."
         (western (concat "\\(" month s dd "\\|" dd s month "\\)"
          ;; weiand: changed: year potentially unaligned
 ;;old                    s "\\(" HH:MM "\\|" s yyyy "\\|" yyyy s "\\)"))
-                         s "\\(" HH:MM "\\|" s "?" yyyy "\\|" yyyy s
-"\\)"))
+                         s "\\(" HH:MM 
+                                 "\\|" yyyy s s "?"
+                                 "\\|" s "?" yyyy
+                            "\\)"))
         (japanese (concat mm k s dd k s "\\(" s HH:MM "\\|" yyyy k "\\)")))
         ;; The "[0-9]" below requires the previous column to end in a digit.
         ;; This avoids recognizing `1 may 1997' as a date in the line:
@@ -1583,12 +1599,6 @@ regardless of the language.")
 \f
 ;; Keeping Dired buffers in sync with the filesystem and with each other
 
-(defvar dired-buffers nil
-  ;; Enlarged by dired-advertise
-  ;; Queried by function dired-buffers-for-dir. When this detects a
-  ;; killed buffer, it is removed from this list.
-  "Alist of expanded directories and their associated dired buffers.")
-
 (defun dired-buffers-for-dir (dir &optional file)
 ;; Return a list of buffers that dired DIR (top level or in-situ subdir).
 ;; If FILE is non-nil, include only those whose wildcard pattern (if any)
@@ -1754,7 +1764,13 @@ Returns the new value of the alist."
   (save-excursion
     (let ((count 0)
          (buffer-read-only nil)
-         new-dir-name)
+         new-dir-name
+         (R-ftp-base-dir-regex
+          ;; Used to expand subdirectory names correctly in recursive
+          ;; ange-ftp listings.
+          (and (string-match "R" dired-actual-switches)
+               (string-match "\\`/.*:\\(/.*\\)" default-directory)
+               (concat "\\`" (match-string 1 default-directory)))))
       (goto-char (point-min))
       (setq dired-subdir-alist nil)
       (while (and (re-search-forward dired-subdir-regexp nil t)
@@ -1768,7 +1784,15 @@ Returns the new value of the alist."
        (save-excursion
          (goto-char (match-beginning 1))
          (setq new-dir-name
-               (expand-file-name (buffer-substring (point) (match-end 1))))
+               (buffer-substring-no-properties (point) (match-end 1))
+               new-dir-name
+               (save-match-data
+                 (if (and R-ftp-base-dir-regex
+                          (not (string= new-dir-name default-directory))
+                          (string-match R-ftp-base-dir-regex new-dir-name))
+                     (concat default-directory
+                             (substring new-dir-name (match-end 0)))
+                   (expand-file-name new-dir-name))))
          (delete-region (point) (match-end 1))
          (insert new-dir-name))
        (setq count (1+ count))
@@ -2176,7 +2200,7 @@ Command symbols are `byte-compile', `chgrp', `chmod', `chown', `compress',
   ;; Point must be at beginning of line
   ;; Should be equivalent to (save-excursion (not (dired-move-to-filename)))
   ;; but is about 1.5..2.0 times as fast. (Actually that's not worth it)
-  (or (looking-at "^$\\|^. *$\\|^. total\\|^. wildcard")
+  (or (looking-at "^$\\|^. *$\\|^. total\\|^. wildcard\\|^. used")
       (and (looking-at dired-subdir-regexp)
           (save-excursion (not (dired-move-to-filename))))))
 
@@ -2622,9 +2646,45 @@ With a prefix argument you can edit the current listing switches instead."
   ;; `dired-sort-by-date-regexp' or `dired-sort-by-name-regexp' set the
   ;; minor mode accordingly, others appear literally in the mode line.
   ;; With optional second arg NO-REVERT, don't refresh the listing afterwards.
+  (dired-sort-R-check switches)
   (setq dired-actual-switches switches)
   (if (eq major-mode 'dired-mode) (dired-sort-set-modeline))
   (or no-revert (revert-buffer)))
+
+(make-variable-buffer-local
+ (defvar dired-subdir-alist-pre-R nil
+   "Value of `dired-subdir-alist' before -R switch added."))
+
+(defun dired-sort-R-check (switches)
+  "Additional processing of -R in ls option string SWITCHES.
+Saves `dired-subdir-alist' when R is set and restores saved value
+minus any directories explicitly deleted when R is cleared.
+To be called first in body of `dired-sort-other', etc."
+  (cond
+   ((and (string-match "R" switches)
+        (not (string-match "R" dired-actual-switches)))
+    ;; Adding -R to ls switches -- save `dired-subdir-alist':
+    (setq dired-subdir-alist-pre-R dired-subdir-alist))
+   ((and (string-match "R" dired-actual-switches)
+        (not (string-match "R" switches)))
+    ;; Deleting -R from ls switches -- revert to pre-R subdirs
+    ;; that are still present:
+    (setq dired-subdir-alist
+         (if dired-subdir-alist-pre-R
+             (let (subdirs)
+               (while dired-subdir-alist-pre-R
+                 (if (assoc (caar dired-subdir-alist-pre-R)
+                            dired-subdir-alist)
+                     ;; subdir still present...
+                     (setq subdirs
+                           (cons (car dired-subdir-alist-pre-R)
+                                 subdirs)))
+                 (setq dired-subdir-alist-pre-R
+                       (cdr dired-subdir-alist-pre-R)))
+               (reverse subdirs))
+           ;; No pre-R subdir alist, so revert to main directory
+           ;; listing:
+           (list (car (reverse dired-subdir-alist))))))))
 \f
 ;; To make this file smaller, the less common commands
 ;; go in a separate file.  But autoload them here
@@ -2834,6 +2894,12 @@ Use \\[dired-hide-all] to (un)hide all directories."
 If there is already something hidden, make everything visible again.
 Use \\[dired-hide-subdir] to (un)hide a particular subdirectory."
   t)
+
+(autoload 'dired-show-file-type "dired-aux"
+  "Print the type of FILE, according to the `file' command.
+If FILE is a symbolic link and the optional argument DEREF-SYMLINKS is
+true then the type of the file linked to by FILE is printed instead." 
+  t)
 \f
 (if (eq system-type 'vax-vms)
     (load "dired-vms"))