(archive-tmpdir): Make the prefix of the temporary
[bpt/emacs.git] / lisp / dired.el
index 82e5c2d..348fda3 100644 (file)
@@ -67,10 +67,8 @@ may contain even `F', `b', `i' and `s'.  See also the variable
       "/etc/chown"))
   "Name of chown command (usually `chown' or `/etc/chown').")
 
-(defvar dired-chmod-program
-  (if (eq system-type 'windows-nt)
-      "chmode" "chmod")
-  "Name of chmod command (usually `chmod' or `chmode').")
+(defvar dired-chmod-program "chmod"
+  "Name of chmod command (usually `chmod').")
 
 ;;;###autoload
 (defcustom dired-ls-F-marks-symlinks nil
@@ -876,6 +874,7 @@ If DIRNAME is already in a dired buffer, that buffer is used without refresh."
     (define-key map "*\177" 'dired-unmark-backward)
     (define-key map "*\C-n" 'dired-next-marked-file)
     (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 "d" 'dired-flag-file-deletion)
     (define-key map "e" 'dired-find-file)
@@ -891,8 +890,9 @@ If DIRNAME is already in a dired buffer, that buffer is used without refresh."
     (define-key map "o" 'dired-find-file-other-window)
     (define-key map "\C-o" 'dired-display-file)
     (define-key map "p" 'dired-previous-line)
-    (define-key map "q" 'dired-quit)
+    (define-key map "q" 'quit-window)
     (define-key map "s" 'dired-sort-toggle-or-edit)
+    (define-key map "t" 'dired-do-toggle)
     (define-key map "u" 'dired-unmark)
     (define-key map "v" 'dired-view-file)
     (define-key map "x" 'dired-do-flagged-delete)
@@ -1019,6 +1019,8 @@ If DIRNAME is already in a dired buffer, that buffer is used without refresh."
       '("Unmark" . dired-unmark))
     (define-key map [menu-bar mark mark]
       '("Mark" . dired-mark))
+    (define-key map [menu-bar mark toggle-marks]
+      '("Toggle Marks" . dired-do-toggle))
 
     (define-key map [menu-bar operate]
       (cons "Operate" (make-sparse-keymap "Operate")))
@@ -1151,11 +1153,6 @@ Keybindings:
 \f
 ;; Idiosyncratic dired commands that don't deal with marks.
 
-(defun dired-quit ()
-  "Bury the current dired buffer."
-  (interactive)
-  (bury-buffer))
-
 (defun dired-summary ()
   "Summarize basic Dired commands and show recent Dired errors."
   (interactive)
@@ -1301,6 +1298,7 @@ Optional arg NO-ERROR-IF-NOT-FILEP means return nil if no filename on
                         "\"")))))
     (and file buffer-file-coding-system
         (not file-name-coding-system)
+        (not default-file-name-coding-system)
         (setq file (encode-coding-string file buffer-file-coding-system)))
     (if (eq localp 'no-dir)
        file
@@ -1365,7 +1363,7 @@ DIR must be a directory name, not a file name."
         (dd "[ 0-3][0-9]")
         (HH:MM "[ 0-2][0-9]:[0-5][0-9]")
         (western (concat "\\(" month s dd "\\|" dd s month "\\)"
-                         s "\\(" HH:MM "\\|" s yyyy "\\)"))
+                         s "\\(" HH:MM "\\|" s yyyy "\\|" yyyy s "\\)"))
         (japanese (concat mm k s dd k s "\\(" s HH:MM "\\|" yyyy k "\\)")))
         ;; Require the previous column to end in a digit.
         ;; This avoids recognizing `1 may 1997' as a date in the line:
@@ -2099,6 +2097,29 @@ If on a subdir headerline, mark all its files except `.' and `..'."
 Optional prefix ARG says how many lines to unflag; default is one line."
   (interactive "p")
   (dired-unmark (- arg)))
+
+(defun dired-do-toggle ()
+  "Toggle marks.
+That is, currently marked files become unmarked and vice versa.
+Files marked with other flags (such as `D') are not affected.
+`.' and `..' are never toggled.
+As always, hidden subdirs are not affected."
+  (interactive)
+  (save-excursion
+    (goto-char (point-min))
+    (let (buffer-read-only)
+      (while (not (eobp))
+        (or (dired-between-files)
+            (looking-at dired-re-dot)
+            ;; use subst instead of insdel because it does not move
+            ;; the gap and thus should be faster and because
+            ;; other characters are left alone automatically
+            (apply 'subst-char-in-region
+                   (point) (1+ (point))
+                   (if (eq ?\040 (following-char)) ; SPC
+                       (list ?\040 dired-marker-char)
+                     (list dired-marker-char ?\040))))
+        (forward-line 1)))))
 \f
 ;;; Commands to mark or flag files based on their characteristics or names.
 
@@ -2369,16 +2390,22 @@ With a prefix argument you can edit the current listing switches instead."
   ;; Toggle between sort by date/name.  Reverts the buffer.
   (setq dired-actual-switches
        (let (case-fold-search)
-         (concat
-          "-l"
-          (dired-replace-in-string (concat "[-lt"
-                                           dired-ls-sorting-switches "]")
-                                   ""
-                                   dired-actual-switches)
-          (if (string-match (concat "[t" dired-ls-sorting-switches "]")
-                            dired-actual-switches)
-              ""
-            "t"))))
+         (if (string-match " " dired-actual-switches)
+             ;; New toggle scheme: add/remove a trailing " -t"
+             (if (string-match " -t\\'" dired-actual-switches)
+                 (dired-replace-in-string " -t\\'" "" dired-actual-switches)
+               (concat dired-actual-switches " -t"))
+           ;; old toggle scheme: look for some 't' switch and add/remove it
+           (concat
+            "-l"
+            (dired-replace-in-string (concat "[-lt"
+                                             dired-ls-sorting-switches "]")
+                                     ""
+                                     dired-actual-switches)
+            (if (string-match (concat "[t" dired-ls-sorting-switches "]")
+                              dired-actual-switches)
+                ""
+              "t")))))
   (dired-sort-set-modeline)
   (revert-buffer))