(dired-show-file-type): Format filename with "%s" to escape any format-like
[bpt/emacs.git] / lisp / dired.el
index 43941bc..5fe4e4a 100644 (file)
@@ -192,7 +192,7 @@ with the buffer narrowed to the listing."
 ;; Note this can't simply be run inside function `dired-ls' as the hook
 ;; functions probably depend on the dired-subdir-alist to be OK.
 
-;;; Internal variables
+;; Internal variables
 
 (defvar dired-marker-char ?*           ; the answer is 42
   ;; so that you can write things like
@@ -304,11 +304,10 @@ Subexpression 2 must end right before the \\n or \\r.")
    ;;
    ;; Files suffixed with `completion-ignored-extensions'.
    '(eval .
-     (let ((extensions (mapcar 'regexp-quote completion-ignored-extensions)))
-       ;; It is quicker to first find just an extension, then go back to the
-       ;; start of that file name.  So we do this complex MATCH-ANCHORED form.
-       (list (concat "\\(" (mapconcat 'identity extensions "\\|") "\\|#\\)$")
-            '(".+" (dired-move-to-filename) nil (0 font-lock-string-face))))))
+     ;; It is quicker to first find just an extension, then go back to the
+     ;; start of that file name.  So we do this complex MATCH-ANCHORED form.
+     (list (concat "\\(" (regexp-opt completion-ignored-extensions) "\\|#\\)$")
+          '(".+" (dired-move-to-filename) nil (0 font-lock-string-face)))))
   "Additional expressions to highlight in Dired mode.")
 \f
 ;;; Macros must be defined before they are used, for the byte compiler.
@@ -655,6 +654,7 @@ If DIRNAME is already in a dired buffer, that buffer is used without refresh."
              file-list (cdr dired-directory))
       (setq dir dired-directory
            file-list nil))
+    (setq dir (expand-file-name dir))
     (if (and (equal "" (file-name-nondirectory dir))
             (not file-list))
        ;; If we are reading a whole single directory...
@@ -678,7 +678,7 @@ If HDR is non-nil, insert a header line with the directory name."
   (let ((opoint (point))
        (process-environment (copy-sequence process-environment))
        end)
-    (if dired-use-ls-dired
+    (if (or dired-use-ls-dired (file-remote-p dir))
        (setq switches (concat "--dired " switches)))
     ;; We used to specify the C locale here, to force English month names;
     ;; but this should not be necessary any more,
@@ -702,7 +702,7 @@ If HDR is non-nil, insert a header line with the directory name."
     ;; If we used --dired and it worked, the lines are already indented.
     ;; Otherwise, indent them.
     (unless (save-excursion
-             (forward-line -1)
+             (goto-char opoint)
              (looking-at "  "))
       (let ((indent-tabs-mode nil))
        (indent-rigidly opoint (point) 2)))
@@ -1449,7 +1449,7 @@ Optional arg NO-ERROR-IF-NOT-FILEP means return nil if no filename on
          (setq file
                (read
                 (concat "\""
-                        ;; some ls -b don't escape quotes, argh!
+                        ;; Some ls -b don't escape quotes, argh!
                         ;; This is not needed for GNU ls, though.
                         (or (dired-string-replace-match
                              "\\([^\\]\\|\\`\\)\"" file "\\1\\\\\"" nil t)
@@ -1584,17 +1584,21 @@ regardless of the language.")
 ;; Returns position (point) or nil if no filename on this line."
 (defun dired-move-to-filename (&optional raise-error eol)
   ;; This is the UNIX version.
-  (or eol (setq eol (progn (end-of-line) (point))))
+  (or eol (setq eol (line-end-position)))
   (beginning-of-line)
   ;; First try assuming `ls --dired' was used.
-  (let ((change (next-single-property-change (point) 'dired-filename
-                                            nil eol)))
-    (if (and change (< change eol))
-       (goto-char change)
-      (if (re-search-forward dired-move-to-filename-regexp eol t)
-         (goto-char (match-end 0))
-       (if raise-error
-           (error "No file on this line"))))))
+  (let ((change (next-single-property-change (point) 'dired-filename nil eol)))
+    (cond
+     ((and change (< change eol))
+      (goto-char change))
+     ((re-search-forward dired-move-to-filename-regexp eol t)
+      (goto-char (match-end 0)))
+     ((re-search-forward dired-permission-flags-regexp eol t)
+      ;; Ha!  There *is* a file.  Our regexp-from-hell just failed to find it.
+      (funcall (if raise-error 'error 'message)
+              "Unrecognized line!  Check dired-move-to-filename-regexp"))
+     (raise-error
+      (error "No file on this line")))))
 
 (defun dired-move-to-end-of-filename (&optional no-error)
   ;; Assumes point is at beginning of filename,
@@ -2244,12 +2248,13 @@ Command symbols are `byte-compile', `chgrp', `chmod', `chown', `compress',
 `uncompress'.")
 
 (defun dired-mark-pop-up (bufname op-symbol files function &rest args)
-  "Args BUFNAME OP-SYMBOL FILES FUNCTION &rest ARGS.
-Return FUNCTION's result on ARGS after popping up a window (in a buffer
-named BUFNAME, nil gives \" *Marked Files*\") showing the marked
-files.  Uses function `dired-pop-to-buffer' to do that.
- FUNCTION should not manipulate files.
- It should only read input (an argument or confirmation).
+  "Return FUNCTION's result on ARGS after showing which files are marked.
+Displays the file names in a buffer named BUFNAME;
+ nil gives \" *Marked Files*\".
+This uses function `dired-pop-to-buffer' to do that.
+
+FUNCTION should not manipulate files, just read input
+ (an argument or confirmation).
 The window is not shown if there is just one file or
  OP-SYMBOL is a member of the list in `dired-no-confirm'.
 FILES is the list of marked files."
@@ -2749,7 +2754,7 @@ With a prefix argument you can edit the current listing switches instead."
          (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)
+                 (substring dired-actual-switches 0 (match-beginning 0))
                (concat dired-actual-switches " -t"))
            ;; old toggle scheme: look for some 't' switch and add/remove it
            (concat