;;; dired.el --- directory-browsing commands -*- lexical-binding: t -*-
-;; Copyright (C) 1985-1986, 1992-1997, 2000-2011
+;; Copyright (C) 1985-1986, 1992-1997, 2000-2012
;; Free Software Foundation, Inc.
;; Author: Sebastian Kremer <sk@thp.uni-koeln.de>
(defun dired-file-name-at-point ()
"Try to get a file name at point in the current dired buffer.
-This hook is inteneded to be put in `file-name-at-point-functions'."
+This hook is intended to be put in `file-name-at-point-functions'."
(let ((filename (dired-get-filename nil t)))
(when filename
(if (file-directory-p filename)
;; spaces there (and within the filename as well, of course).
(save-excursion
(let (file file-col other other-col)
- ;; Check that there is indeed a file, and that there is anoter adjacent
+ ;; Check that there is indeed a file, and that there is another adjacent
;; file with which to align, and that additional spaces are needed to
;; align the filenames.
(when (and (setq file (progn (goto-char beg)
(defvar ls-lisp-use-insert-directory-program)
+(defun dired-switches-escape-p (switches)
+ "Return non-nil if the string SWITCHES contains -b or --escape."
+ ;; Do not match things like "--block-size" that happen to contain "b".
+ (string-match "\\(\\`\\| \\)-[[:alnum:]]*b\\|--escape\\>" switches))
+
(defun dired-insert-directory (dir switches &optional file-list wildcard hdr)
"Insert a directory listing of DIR, Dired style.
Use SWITCHES to make the listings.
(dired-align-file beg (point))))
(insert-directory dir switches wildcard (not wildcard)))
;; Quote certain characters, unless ls quoted them for us.
- (if (not (string-match "b" dired-actual-switches))
+ (if (not (dired-switches-escape-p dired-actual-switches))
(save-excursion
(setq end (point-marker))
(goto-char opoint)
"\\015"
(text-properties-at (match-beginning 0)))
nil t))
- (set-marker end nil)))
+ (set-marker end nil))
+ ;; Replace any newlines in DIR with literal "\n"s, for the sake
+ ;; of the header line. To disambiguate a literal "\n" in the
+ ;; actual dirname, we also replace "\" with "\\".
+ ;; Personally, I think this should always be done, irrespective
+ ;; of the value of dired-actual-switches, because:
+ ;; i) Dired simply does not work with an unescaped newline in
+ ;; the directory name used in the header (bug=10469#28), and
+ ;; ii) "\" is always replaced with "\\" in the listing, so doing
+ ;; it in the header as well makes things consistent.
+ ;; But at present it is only done if "-b" is in ls-switches,
+ ;; because newlines in dirnames are uncommon, and people may
+ ;; have gotten used to seeing unescaped "\" in the headers.
+ ;; Note: adjust dired-build-subdir-alist if you change this.
+ (setq dir (replace-regexp-in-string "\\\\" "\\\\" dir nil t)
+ dir (replace-regexp-in-string "\n" "\\n" dir nil t)))
(dired-insert-set-properties opoint (point))
;; If we used --dired and it worked, the lines are already indented.
;; Otherwise, indent them.
[menu-bar immediate image-dired-dired-display-image]
'(menu-item "Display Image" image-dired-dired-display-image
:help "Display sized image in a separate window"))
+ (define-key map
+ [menu-bar immediate image-dired-dired-toggle-marked-thumbs]
+ '(menu-item "Toggle Image Thumbnails in This Buffer" image-dired-dired-toggle-marked-thumbs
+ :help "Add or remove image thumbnails in front of marked file names"))
(define-key map [menu-bar immediate revert-buffer]
'(menu-item "Refresh" revert-buffer
:help "Add image comment to current or marked files"))
(define-key map
[menu-bar operate image-dired-display-thumbs]
- '(menu-item "Display image thumbnails" image-dired-display-thumbs
+ '(menu-item "Display Image Thumbnails" image-dired-display-thumbs
:help "Display image thumbnails for current or marked image files"))
(define-key map [menu-bar operate dashes-4]
;; with quotation marks in their names.
(while (string-match "\\(?:[^\\]\\|\\`\\)\\(\"\\)" file)
(setq file (replace-match "\\\"" nil t file 1)))
-
+ ;; Unescape any spaces escaped by ls -b (bug#10469).
+ ;; Other -b quotes, eg \t, \n, work transparently.
+ (if (dired-switches-escape-p dired-actual-switches)
+ (let ((start 0)
+ (rep "")
+ (shift -1))
+ (if (eq localp 'verbatim)
+ (setq rep "\\\\"
+ shift +1))
+ (while (string-match "\\(\\\\\\) " file start)
+ (setq file (replace-match rep nil t file 1)
+ start (+ shift (match-end 0))))))
(when (eq system-type 'windows-nt)
(save-match-data
(let ((start 0))
(aset file (match-beginning 0) ?/)
(setq start (match-end 0))))))
+ ;; Hence we don't need to worry about converting `\\' back to `\'.
(setq file (read (concat "\"" file "\"")))
;; The above `read' will return a unibyte string if FILE
;; contains eight-bit-control/graphic characters.
(delete-region (point) (match-end 1))
(insert new-dir-name))
(setq count (1+ count))
+ ;; Undo any escaping of newlines and \ by dired-insert-directory.
+ ;; Convert "n" preceded by odd number of \ to newline, and \\ to \.
+ (when (and (dired-switches-escape-p switches)
+ (string-match-p "\\\\" new-dir-name))
+ (let (temp res)
+ (mapc (lambda (char)
+ (cond ((equal char ?\\)
+ (if temp
+ (setq res (concat res "\\")
+ temp nil)
+ (setq temp "\\")))
+ ((and temp (equal char ?n))
+ (setq res (concat res "\n")
+ temp nil))
+ (t
+ (setq res (concat res temp (char-to-string char))
+ temp nil))))
+ new-dir-name)
+ (setq new-dir-name res)))
(dired-alist-add-1 new-dir-name
- ;; Place a sub directory boundary between lines.
- (save-excursion
- (goto-char (match-beginning 0))
- (beginning-of-line)
- (point-marker)))))
+ ;; Place a sub directory boundary between lines.
+ (save-excursion
+ (goto-char (match-beginning 0))
+ (beginning-of-line)
+ (point-marker)))))
(if (and (> count 1) (called-interactively-p 'interactive))
(message "Buffer includes %d directories" count)))
;; We don't need to sort it because it is in buffer order per
(replace-regexp-in-string "\^m" "\\^m" base nil t))
(setq search-string
(replace-regexp-in-string "\\\\" "\\\\" search-string nil t))
+ (and (dired-switches-escape-p dired-actual-switches)
+ (string-match "[ \t\n]" search-string)
+ ;; FIXME to fix this for all possible file names
+ ;; (embedded control characters etc), we need to
+ ;; escape everything that `ls -b' does.
+ (setq search-string
+ (replace-regexp-in-string " " "\\ "
+ search-string nil t)
+ search-string
+ (replace-regexp-in-string "\t" "\\t"
+ search-string nil t)
+ search-string
+ (replace-regexp-in-string "\n" "\\n"
+ search-string nil t)))
(while (and (not found)
;; filenames are preceded by SPC, this makes
;; the search faster (e.g. for the filename "-"!).
(defvar dired-re-no-dot "^\\([^.]\\|\\.\\([^.]\\|\\..\\)\\).*")
;; Delete file, possibly delete a directory and all its files.
-;; This function is usefull outside of dired. One could change it's name
+;; This function is useful outside of dired. One could change its name
;; to e.g. recursive-delete-file and put it somewhere else.
(defun dired-delete-file (file &optional recursive trash) "\
Delete FILE or directory (possibly recursively if optional RECURSIVE is true.)
(window-splittable-p (selected-window)))
;; Try to split the selected window vertically if
;; that's possible. (Bug#1806)
- (split-window-vertically))
+ (split-window-below))
;; Otherwise, try to split WINDOW sensibly.
(split-window-sensibly window))))
pop-up-frames)
(dired-mark-if
(and (not (looking-at dired-re-dot))
(not (eolp)) ; empty line
- (let ((fn (dired-get-filename nil t)))
- (and fn (string-match regexp (file-name-nondirectory fn)))))
+ (let ((fn (dired-get-filename t t)))
+ (and fn (string-match regexp fn))))
"matching file")))
(defun dired-mark-files-containing-regexp (regexp &optional marker-char)
;;;;;; dired-run-shell-command dired-do-shell-command dired-do-async-shell-command
;;;;;; dired-clean-directory dired-do-print dired-do-touch dired-do-chown
;;;;;; dired-do-chgrp dired-do-chmod dired-compare-directories dired-backup-diff
-;;;;;; dired-diff) "dired-aux" "dired-aux.el" "bbb53a5b6bf56c413fe0f898559bef8d")
+;;;;;; dired-diff) "dired-aux" "dired-aux.el" "e77c506a0dd793230c5856a67e408fc6")
;;; Generated autoloads from dired-aux.el
(autoload 'dired-diff "dired-aux" "\
`*' and `?' when not surrounded by whitespace have no special
significance for `dired-do-shell-command', and are passed through
-normally to the shell, but you must confirm first. To pass `*' by
-itself to the shell as a wildcard, type `*\"\"'.
+normally to the shell, but you must confirm first.
+
+If you want to use `*' as a shell wildcard with whitespace around
+it, write `*\"\"' in place of just `*'. This is equivalent to just
+`*' in the shell, but avoids Dired's special handling.
If COMMAND produces output, it goes to a separate buffer.
;;;***
\f
;;;### (autoloads (dired-do-relsymlink dired-jump-other-window dired-jump)
-;;;;;; "dired-x" "dired-x.el" "219648338c42c7912fa336680b434db0")
+;;;;;; "dired-x" "dired-x.el" "bc516591d881911d72b58eeed8816576")
;;; Generated autoloads from dired-x.el
(autoload 'dired-jump "dired-x" "\