]> code.delx.au - gnu-emacs/blobdiff - lisp/dired.el
* net/tramp.el (tramp-replace-environment-variables): New defun.
[gnu-emacs] / lisp / dired.el
index 942a6e4c9052d207545b3c2d4bb267fff39d5aec..375894ca8c195d27caa266e64069d8526fb71e52 100644 (file)
@@ -70,7 +70,7 @@ If nil, `dired-listing-switches' is used.")
 
 ;;;###autoload
 (defvar dired-chown-program
-  (if (memq system-type '(hpux dgux usg-unix-v irix linux gnu/linux cygwin))
+  (if (memq system-type '(hpux usg-unix-v irix linux gnu/linux cygwin))
       "chown"
     (if (file-exists-p "/usr/sbin/chown")
        "/usr/sbin/chown"
@@ -344,13 +344,15 @@ Subexpression 2 must end right before the \\n or \\r.")
 (defvar dired-warning-face 'dired-warning
   "Face name used for a part of a buffer that needs user attention.")
 
-(defface dired-warn-writable
+(defface dired-perm-write
   '((((type w32 pc)) :inherit default)  ;; These default to rw-rw-rw.
-    (t (:inherit font-lock-warning-face)))
+    ;; Inherit from font-lock-comment-delimiter-face since with min-colors 8
+    ;; font-lock-comment-face is not colored any more.
+    (t (:inherit font-lock-comment-delimiter-face)))
   "Face used to highlight permissions of group- and world-writable files."
   :group 'dired-faces
   :version "22.2")
-(defvar dired-warn-writable-face 'dired-warn-writable
+(defvar dired-perm-write-face 'dired-perm-write
   "Face name used for permissions of group- and world-writable files.")
 
 (defface dired-directory
@@ -414,10 +416,10 @@ Subexpression 2 must end right before the \\n or \\r.")
    ;; fields with keymaps to frob the permissions, somewhat a la XEmacs.
    (list (concat dired-re-maybe-mark dired-re-inode-size
                 "[-d]....\\(w\\)....") ; group writable
-        '(1 dired-warn-writable-face))
+        '(1 dired-perm-write-face))
    (list (concat dired-re-maybe-mark dired-re-inode-size
                 "[-d].......\\(w\\).") ; world writable
-        '(1 dired-warn-writable-face))
+        '(1 dired-perm-write-face))
    ;;
    ;; Subdirectories.
    (list dired-re-dir
@@ -592,11 +594,12 @@ Don't use that together with FILTER."
            ;; If a dialog is about to be used, call read-directory-name so
            ;; the dialog code knows we want directories.  Some dialogs can
            ;; only select directories or files when popped up, not both.
-           (if (next-read-file-uses-dialog-p)
+           (let ((default (and buffer-file-name
+                               (abbreviate-file-name buffer-file-name))))
+             (minibuffer-with-setup-hook
+                 (lambda () (setq minibuffer-default default))
                (read-directory-name (format "Dired %s(directory): " str)
-                                    nil default-directory nil)
-             (read-file-name (format "Dired %s(directory): " str)
-                             nil default-directory nil)))))
+                                    nil default-directory nil))))))
 
 ;;;###autoload (define-key ctl-x-map "d" 'dired)
 ;;;###autoload
@@ -1258,6 +1261,7 @@ Do so according to the former subdir alist OLD-SUBDIR-ALIST."
     (define-key map "$" 'dired-hide-subdir)
     (define-key map "\M-$" 'dired-hide-all)
     ;; misc
+    (define-key map "\C-x\C-q" 'dired-toggle-read-only)
     (define-key map "?" 'dired-summary)
     (define-key map "\177" 'dired-unmark-backward)
     (define-key map [remap undo] 'dired-undo)
@@ -1363,7 +1367,8 @@ Do so according to the former subdir alist OLD-SUBDIR-ALIST."
     (define-key map [menu-bar immediate create-directory]
       '(menu-item "Create Directory..." dired-create-directory))
     (define-key map [menu-bar immediate wdired-mode]
-      '(menu-item "Edit File Names" wdired-change-to-wdired-mode))
+      '(menu-item "Edit File Names" wdired-change-to-wdired-mode
+                 :filter (lambda (x) (if (eq major-mode 'dired-mode) x))))
 
     (define-key map [menu-bar regexp]
       (cons "Regexp" (make-sparse-keymap "Regexp")))
@@ -1462,6 +1467,7 @@ Do so according to the former subdir alist OLD-SUBDIR-ALIST."
 
     (define-key map [menu-bar operate]
       (cons "Operate" (make-sparse-keymap "Operate")))
+
     (define-key map
       [menu-bar operate image-dired-delete-tag]
       '(menu-item "Delete Image Tag..." image-dired-delete-tag
@@ -1665,18 +1671,28 @@ You can use it to recover marks, killed lines or subdirs."
   (message "Change in dired buffer undone.
 Actual changes in files cannot be undone by Emacs."))
 
+(defun dired-toggle-read-only ()
+  "Edit dired buffer with Wdired, or set it read-only.
+Call `wdired-change-to-wdired-mode' in dired buffers whose editing is
+supported by Wdired (the major mode of the dired buffer is `dired-mode').
+Otherwise, for buffers inheriting from dired-mode, call `toggle-read-only'."
+  (interactive)
+  (if (eq major-mode 'dired-mode)
+      (wdired-change-to-wdired-mode)
+    (toggle-read-only)))
+
 (defun dired-next-line (arg)
   "Move down lines then position at filename.
 Optional prefix ARG says how many lines to move; default is one line."
   (interactive "p")
-  (next-line arg)
+  (forward-line arg)
   (dired-move-to-filename))
 
 (defun dired-previous-line (arg)
   "Move up lines then position at filename.
 Optional prefix ARG says how many lines to move; default is one line."
   (interactive "p")
-  (previous-line arg)
+  (forward-line (- arg))
   (dired-move-to-filename))
 
 (defun dired-next-dirline (arg &optional opoint)
@@ -1992,7 +2008,7 @@ Return the position of the beginning of the filename, or nil if none found."
               (forward-char -1))))
       (or no-error
          (not (eq opoint (point)))
-         (error (if hidden
+         (error "%s" (if hidden
                     (substitute-command-keys
                      "File line is hidden, type \\[dired-hide-subdir] to unhide")
                   "No file on this line")))
@@ -2418,8 +2434,8 @@ Anything else, ask for each sub-directory."
   "In Dired, delete the files flagged for deletion.
 If NOMESSAGE is non-nil, we don't display any message
 if there are no flagged files.
-`dired-recursive-deletes' controls whether 
-deletion of non-empty directories is allowed."
+`dired-recursive-deletes' controls whether deletion of
+non-empty directories is allowed."
   (interactive)
   (let* ((dired-marker-char dired-del-marker)
         (regexp (dired-marker-regexp))
@@ -2436,8 +2452,8 @@ deletion of non-empty directories is allowed."
 
 (defun dired-do-delete (&optional arg)
   "Delete all marked (or next ARG) files.
-`dired-recursive-deletes' controls whether 
-deletion of non-empty directories is allowed."
+`dired-recursive-deletes' controls whether deletion of
+non-empty directories is allowed."
   ;; This is more consistent with the file marking feature than
   ;; dired-do-flagged-delete.
   (interactive "P")
@@ -3234,7 +3250,7 @@ Anything else means ask for each directory."
 
 (defun dired-dnd-popup-notice ()
   (message-box
-   "Recursive copies not enabled.\nSee variable dired-recursive-copies."))
+   "Dired recursive copies are currently disabled.\nSee the variable `dired-recursive-copies'."))
 
 
 (defun dired-dnd-do-ask-action (uri)
@@ -3253,43 +3269,55 @@ Anything else means ask for each directory."
        (dired-dnd-handle-local-file uri action)
       nil)))
 
+(declare-function dired-relist-entry "dired-aux" (file))
+(declare-function make-symbolic-link "fileio.c")
+
 (defun dired-dnd-handle-local-file (uri action)
   "Copy, move or link a file to the dired directory.
 URI is the file to handle, ACTION is one of copy, move, link or ask.
 Ask means pop up a menu for the user to select one of copy, move or link."
   (require 'dired-aux)
   (let* ((from (dnd-get-local-file-name uri t))
-        (to (if from (concat (dired-current-directory)
-                          (file-name-nondirectory from))
-              nil)))
-    (if from
-       (cond ((or (eq action 'copy)
-                  (eq action 'private))        ; Treat private as copy.
-
-              ;; If copying a directory and dired-recursive-copies is nil,
-              ;; dired-copy-file silently fails.  Pop up a notice.
-              (if (and (file-directory-p from)
-                       (not dired-recursive-copies))
-                  (dired-dnd-popup-notice)
-                (progn
-                  (dired-copy-file from to 1)
-                  (dired-relist-entry to)
-                  action)))
-
-              ((eq action 'move)
-               (dired-rename-file from to 1)
-               (dired-relist-entry to)
-               action)
-
-              ((eq action 'link)
-               (make-symbolic-link from to 1)
-               (dired-relist-entry to)
-               action)
-
-              ((eq action 'ask)
-               (dired-dnd-do-ask-action uri))
-
-              (t nil)))))
+        (to (when from
+              (concat (dired-current-directory)
+                      (file-name-nondirectory from)))))
+    (when from
+      (cond ((eq action 'ask)
+            (dired-dnd-do-ask-action uri))
+           ;; If copying a directory and dired-recursive-copies is
+           ;; nil, dired-copy-file fails.  Pop up a notice.
+           ((and (memq action '(copy private))
+                 (file-directory-p from)
+                 (not dired-recursive-copies))
+            (dired-dnd-popup-notice))
+           ((memq action '(copy private move link))
+            (let ((overwrite (and (file-exists-p to)
+                                  (y-or-n-p
+                                   (format "Overwrite existing file `%s'? " to))))
+                  ;; Binding dired-overwrite-confirmed to nil makes
+                  ;; dired-handle-overwrite a no-op.  We instead use
+                  ;; y-or-n-p, which pops a graphical menu.
+                  dired-overwrite-confirmed backup-file)
+              (when (and overwrite
+                         ;; d-b-o is defined in dired-aux.
+                         (boundp 'dired-backup-overwrite)
+                         dired-backup-overwrite
+                         (setq backup-file
+                               (car (find-backup-file-name to)))
+                         (or (eq dired-backup-overwrite 'always)
+                             (y-or-n-p
+                              (format
+                               "Make backup for existing file `%s'? " to))))
+                (rename-file to backup-file 0)
+                (dired-relist-entry backup-file))
+              (cond ((memq action '(copy private))
+                     (dired-copy-file from to overwrite))
+                    ((eq action 'move)
+                     (dired-rename-file from to overwrite))
+                    ((eq action 'link)
+                     (make-symbolic-link from to overwrite)))
+              (dired-relist-entry to)
+              action))))))
 
 (defun dired-dnd-handle-file (uri action)
   "Copy, move or link a file to the dired directory if it is a local file.
@@ -3336,7 +3364,7 @@ Ask means pop up a menu for the user to select one of copy, move or link."
           (dired dired-dir)
           ;; The following elements of `desktop-buffer-misc' are the keys
           ;; from `dired-subdir-alist'.
-          (mapcar 'dired-maybe-insert-subdir (cdr desktop-buffer-misc))
+          (mapc 'dired-maybe-insert-subdir (cdr desktop-buffer-misc))
           (current-buffer))
       (message "Desktop: Directory %s no longer exists." dir)
       (when desktop-missing-file-warning (sit-for 1))