+
+(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)))))