;;; dired.el --- directory-browsing commands -*- lexical-binding: t -*-
-;; Copyright (C) 1985-1986, 1992-1997, 2000-2012
-;; Free Software Foundation, Inc.
+;; Copyright (C) 1985-1986, 1992-1997, 2000-2013 Free Software
+;; Foundation, Inc.
;; Author: Sebastian Kremer <sk@thp.uni-koeln.de>
;; Maintainer: FSF
"Controls marking of renamed files.
If t, files keep their previous marks when they are renamed.
If a character, renamed files (whether previously marked or not)
-are afterward marked with that character."
+are afterward marked with that character.
+This option affects only files renamed by `dired-do-rename' and
+`dired-do-rename-regexp'. See `wdired-keep-marker-rename'
+if you want to do the same for files renamed in WDired mode."
:type '(choice (const :tag "Keep" t)
- (character :tag "Mark"))
+ (character :tag "Mark" :value ?R))
:group 'dired-mark)
(defcustom dired-keep-marker-copy ?C
:version "22.1"
:group 'dired)
+(defcustom dired-hide-details-hide-symlink-targets t
+ "If non-nil, `dired-hide-details-mode' hides symbolic link targets."
+ :type 'boolean
+ :version "24.4"
+ :group 'dired)
+
+(defcustom dired-hide-details-hide-information-lines t
+ "Non-nil means hide lines other than header and file/dir lines."
+ :type 'boolean
+ :version "24.4"
+ :group 'dired)
+
;; Internal variables
(defvar dired-marker-char ?* ; the answer is 42
;; I see no reason ever to make this nil -- rms.
;; (> baud-rate search-slow-speed)
"Non-nil means Dired shrinks the display buffer to fit the marked files.")
+(make-obsolete-variable 'dired-shrink-to-fit
+ "use the Customization interface to add a new rule
+to `display-buffer-alist' where condition regexp is \"^ \\*Marked Files\\*$\",
+action argument symbol is `window-height' and its value is nil." "24.3")
(defvar dired-file-version-alist)
If DISTINGUISH-ONE-MARKED is non-nil, then if we find just one marked file,
return (t FILENAME) instead of (FILENAME).
Don't use that together with FILTER."
- (let* ((all-of-them
- (save-excursion
- (dired-map-over-marks
- (dired-get-filename localp)
- arg nil distinguish-one-marked)))
- result)
+ (let ((all-of-them
+ (save-excursion
+ (delq nil (dired-map-over-marks
+ (dired-get-filename localp 'no-error-if-not-filep)
+ arg nil distinguish-one-marked))))
+ result)
+ (when (equal all-of-them '(t))
+ (setq all-of-them nil))
(if (not filter)
(if (and distinguish-one-marked (eq (car all-of-them) t))
all-of-them
;; 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.
(unless (save-excursion
(let ((indent-tabs-mode nil))
(indent-rigidly opoint (point) 2)))
;; Insert text at the beginning to standardize things.
- (save-excursion
- (goto-char opoint)
- (if (and (or hdr wildcard)
- (not (and (looking-at "^ \\(.*\\):$")
- (file-name-absolute-p (match-string 1)))))
+ (let ((content-point opoint))
+ (save-excursion
+ (goto-char opoint)
+ (when (and (or hdr wildcard)
+ (not (and (looking-at "^ \\(.*\\):$")
+ (file-name-absolute-p (match-string 1)))))
;; Note that dired-build-subdir-alist will replace the name
;; by its expansion, so it does not matter whether what we insert
;; here is fully expanded, but it should be absolute.
- (insert " " (directory-file-name (file-name-directory dir)) ":\n"))
- (when wildcard
- ;; Insert "wildcard" line where "total" line would be for a full dir.
- (insert " wildcard " (file-name-nondirectory dir) "\n")))))
+ (insert " " (directory-file-name (file-name-directory dir)) ":\n")
+ (setq content-point (point)))
+ (when wildcard
+ ;; Insert "wildcard" line where "total" line would be for a full dir.
+ (insert " wildcard " (file-name-nondirectory dir) "\n")))
+ (dired-insert-set-properties content-point (point)))))
(defun dired-insert-set-properties (beg end)
"Add various text properties to the lines in the region."
(goto-char beg)
(while (< (point) end)
(condition-case nil
- (if (dired-move-to-filename)
- (add-text-properties
- (point)
- (save-excursion
- (dired-move-to-end-of-filename)
- (point))
- '(mouse-face highlight
- dired-filename t
- help-echo "mouse-2: visit this file in other window")))
+ (if (not (dired-move-to-filename))
+ (put-text-property (line-beginning-position)
+ (1+ (line-end-position))
+ 'invisible 'dired-hide-details-information)
+ (put-text-property (+ (line-beginning-position) 1) (1- (point))
+ 'invisible 'dired-hide-details-detail)
+ (add-text-properties
+ (point)
+ (progn
+ (dired-move-to-end-of-filename)
+ (point))
+ '(mouse-face
+ highlight
+ dired-filename t
+ help-echo "mouse-2: visit this file in other window"))
+ (when (< (+ (point) 4) (line-end-position))
+ (put-text-property (+ (point) 4) (line-end-position)
+ 'invisible 'dired-hide-details-link)))
(error nil))
(forward-line 1))))
\f
(define-key map "&" 'dired-do-async-shell-command)
;; Comparison commands
(define-key map "=" 'dired-diff)
- (define-key map "\M-=" 'dired-backup-diff)
;; Tree Dired commands
(define-key map "\M-\C-?" 'dired-unmark-all-files)
(define-key map "\M-\C-d" 'dired-tree-down)
;; hiding
(define-key map "$" 'dired-hide-subdir)
(define-key map "\M-$" 'dired-hide-all)
+ (define-key map "(" 'dired-hide-details-mode)
;; isearch
(define-key map (kbd "M-s a C-s") 'dired-do-isearch)
(define-key map (kbd "M-s a M-C-s") 'dired-do-isearch-regexp)
(define-key map (kbd "M-s f C-s") 'dired-isearch-filenames)
(define-key map (kbd "M-s f M-C-s") 'dired-isearch-filenames-regexp)
;; misc
+ (define-key map [remap read-only-mode] 'dired-toggle-read-only)
+ ;; `toggle-read-only' is an obsolete alias for `read-only-mode'
(define-key map [remap toggle-read-only] 'dired-toggle-read-only)
(define-key map "?" 'dired-summary)
(define-key map "\177" 'dired-unmark-backward)
'(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 hide-details]
+ '(menu-item "Hide Details" dired-hide-details-mode
+ :help "Hide details in buffer"
+ :button (:toggle . dired-hide-details-mode)))
(define-key map [menu-bar immediate revert-buffer]
'(menu-item "Refresh" revert-buffer
:help "Update contents of shown directories"))
(define-key map
[menu-bar operate epa-dired-do-decrypt]
- '(menu-item "Decrypt" epa-dired-do-decrypt
+ '(menu-item "Decrypt..." epa-dired-do-decrypt
:help "Decrypt file at cursor"))
(define-key map
(define-key map
[menu-bar operate epa-dired-do-sign]
- '(menu-item "Sign" epa-dired-do-sign
+ '(menu-item "Sign..." epa-dired-do-sign
:help "Create digital signature of file at cursor"))
(define-key map
[menu-bar operate epa-dired-do-encrypt]
- '(menu-item "Encrypt" epa-dired-do-encrypt
+ '(menu-item "Encrypt..." epa-dired-do-encrypt
:help "Encrypt file at cursor"))
(define-key map [menu-bar operate dashes-3]
`dired-listing-switches'
`dired-trivial-filenames'
- `dired-shrink-to-fit'
`dired-marker-char'
`dired-del-marker'
`dired-keep-marker-rename'
selective-display t ; for subdirectory hiding
mode-line-buffer-identification
(propertized-buffer-identification "%17b"))
+ ;; Ignore dired-hide-details-* value of invisible text property by default.
+ (when (eq buffer-invisibility-spec t)
+ (setq buffer-invisibility-spec (list t)))
(set (make-local-variable 'revert-buffer-function)
(function dired-revert))
(set (make-local-variable 'buffer-stale-function)
(interactive)
(if (derived-mode-p 'dired-mode)
(wdired-change-to-wdired-mode)
- (call-interactively 'toggle-read-only)))
+ (read-only-mode 'toggle)))
(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")
- (forward-line arg)
+ (let ((line-move-visual)
+ (goal-column))
+ (line-move arg t))
+ ;; We never want to move point into an invisible line.
+ (while (and (invisible-p (point))
+ (not (if (and arg (< arg 0)) (bobp) (eobp))))
+ (forward-char (if (and arg (< arg 0)) -1 1)))
(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")
- (forward-line (- arg))
- (dired-move-to-filename))
+ (dired-next-line (- (or arg 1))))
(defun dired-next-dirline (arg &optional opoint)
"Goto ARG'th next directory file line."
(substring file (match-end 0))
file))
\f
+;;; Minor mode for hiding details
+;;;###autoload
+(define-minor-mode dired-hide-details-mode
+ "Hide details in `dired-mode'."
+ :group 'dired
+ (unless (derived-mode-p 'dired-mode)
+ (error "Not a Dired buffer"))
+ (dired-hide-details-update-invisibility-spec)
+ (if dired-hide-details-mode
+ (add-hook 'wdired-mode-hook
+ 'dired-hide-details-update-invisibility-spec
+ nil
+ t)
+ (remove-hook 'wdired-mode-hook
+ 'dired-hide-details-update-invisibility-spec
+ t)))
+
+(defun dired-hide-details-update-invisibility-spec ()
+ (funcall (if dired-hide-details-mode
+ 'add-to-invisibility-spec
+ 'remove-from-invisibility-spec)
+ 'dired-hide-details-detail)
+ (funcall (if (and dired-hide-details-mode
+ dired-hide-details-hide-information-lines)
+ 'add-to-invisibility-spec
+ 'remove-from-invisibility-spec)
+ 'dired-hide-details-information)
+ (funcall (if (and dired-hide-details-mode
+ dired-hide-details-hide-symlink-targets
+ (not (derived-mode-p 'wdired-mode)))
+ 'add-to-invisibility-spec
+ 'remove-from-invisibility-spec)
+ 'dired-hide-details-link))
+\f
;;; Functions for finding the file name in a dired buffer line.
(defvar dired-permission-flags-regexp
(defun dired-pop-to-buffer (buf)
"Pop up buffer BUF in a way suitable for Dired."
+ (declare (obsolete dired-mark-pop-up "24.3"))
(let ((split-window-preferred-function
(lambda (window)
(or (and (let ((split-height-threshold 0))
(const shell) (const symlink) (const touch)
(const uncompress))))
-(defun dired-mark-pop-up (bufname op-symbol files function &rest args)
+(defun dired-mark-pop-up (buffer-or-name op-symbol files function &rest args)
"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'.
+Displays the file names in a window showing a buffer named
+BUFFER-OR-NAME; the default name being \" *Marked Files*\". The
+window is not shown if there is just one file, `dired-no-confirm'
+is t, or OP-SYMBOL is a member of the list in `dired-no-confirm'.
+
+By default, Dired shrinks the display buffer to fit the marked files.
+To disable this, use the Customization interface to add a new rule
+to `display-buffer-alist' where condition regexp is \"^ \\*Marked Files\\*$\",
+action argument symbol is `window-height' and its value is nil.
+
FILES is the list of marked files. It can also be (t FILENAME)
in the case of one marked file, to distinguish that from using
-just the current file."
- (or bufname (setq bufname " *Marked Files*"))
+just the current file.
+
+FUNCTION should not manipulate files, just read input \(an
+argument or confirmation)."
(if (or (eq dired-no-confirm t)
(memq op-symbol dired-no-confirm)
;; If FILES defaulted to the current line's file.
(= (length files) 1))
(apply function args)
- (with-current-buffer (get-buffer-create bufname)
- (erase-buffer)
- ;; Handle (t FILE) just like (FILE), here.
- ;; That value is used (only in some cases), to mean
- ;; just one file that was marked, rather than the current line file.
- (dired-format-columns-of-files (if (eq (car files) t) (cdr files) files))
- (remove-text-properties (point-min) (point-max)
- '(mouse-face nil help-echo nil)))
- (save-window-excursion
- (dired-pop-to-buffer bufname)
- (apply function args))))
+ (let ((buffer (get-buffer-create (or buffer-or-name " *Marked Files*"))))
+ (with-current-buffer buffer
+ (let ((split-height-threshold 0))
+ (with-temp-buffer-window
+ buffer
+ (cons 'display-buffer-below-selected
+ '((window-height . fit-window-to-buffer)))
+ #'(lambda (window _value)
+ (with-selected-window window
+ (unwind-protect
+ (apply function args)
+ (when (window-live-p window)
+ (quit-restore-window window 'kill)))))
+ ;; Handle (t FILE) just like (FILE), here. That value is
+ ;; used (only in some cases), to mean just one file that was
+ ;; marked, rather than the current line file.
+ (dired-format-columns-of-files
+ (if (eq (car files) t) (cdr files) files))
+ (remove-text-properties (point-min) (point-max)
+ '(mouse-face nil help-echo nil))))))))
(defun dired-format-columns-of-files (files)
(let ((beg (point)))
(insert dired-marker-char)))
(forward-line 1))))
-(defun dired-mark (arg)
- "Mark the current (or next ARG) files.
+(defun dired-mark (arg &optional interactive)
+ "Mark the file at point in the Dired buffer.
+If the region is active, mark all files in the region.
+Otherwise, with a prefix arg, mark files on the next ARG lines.
+
If on a subdir headerline, mark all its files except `.' and `..'.
Use \\[dired-unmark-all-files] to remove all marks
and \\[dired-unmark] on a subdir to remove the marks in
this subdir."
- (interactive "P")
- (if (dired-get-subdir)
- (save-excursion (dired-mark-subdir-files))
+ (interactive (list current-prefix-arg t))
+ (cond
+ ;; Mark files in the active region.
+ ((and interactive (use-region-p))
+ (save-excursion
+ (let ((beg (region-beginning))
+ (end (region-end)))
+ (dired-mark-files-in-region
+ (progn (goto-char beg) (line-beginning-position))
+ (progn (goto-char end) (line-beginning-position))))))
+ ;; Mark subdir files from the subdir headerline.
+ ((dired-get-subdir)
+ (save-excursion (dired-mark-subdir-files)))
+ ;; Mark the current (or next ARG) files.
+ (t
(let ((inhibit-read-only t))
(dired-repeat-over-lines
(prefix-numeric-value arg)
- (function (lambda () (delete-char 1) (insert dired-marker-char)))))))
+ (function (lambda () (delete-char 1) (insert dired-marker-char))))))))
-(defun dired-unmark (arg)
- "Unmark the current (or next ARG) files.
-If looking at a subdir, unmark all its files except `.' and `..'."
- (interactive "P")
+(defun dired-unmark (arg &optional interactive)
+ "Unmark the file at point in the Dired buffer.
+If the region is active, unmark all files in the region.
+Otherwise, with a prefix arg, unmark files on the next ARG lines.
+
+If looking at a subdir, unmark all its files except `.' and `..'.
+If the region is active in Transient Mark mode, unmark all files
+in the active region."
+ (interactive (list current-prefix-arg t))
(let ((dired-marker-char ?\040))
- (dired-mark arg)))
+ (dired-mark arg interactive)))
-(defun dired-flag-file-deletion (arg)
+(defun dired-flag-file-deletion (arg &optional interactive)
"In Dired, flag the current line's file for deletion.
-With prefix arg, repeat over several lines.
+If the region is active, flag all files in the region.
+Otherwise, with a prefix arg, flag files on the next ARG lines.
-If on a subdir headerline, mark all its files except `.' and `..'."
- (interactive "P")
+If on a subdir headerline, flag all its files except `.' and `..'.
+If the region is active in Transient Mark mode, flag all files
+in the active region."
+ (interactive (list current-prefix-arg t))
(let ((dired-marker-char dired-del-marker))
- (dired-mark arg)))
+ (dired-mark arg interactive)))
(defun dired-unmark-backward (arg)
"In Dired, move up lines and remove marks or deletion flags there.
Optional prefix ARG says how many lines to unmark/unflag; default
-is one line."
+is one line.
+If the region is active in Transient Mark mode, unmark all files
+in the active region."
(interactive "p")
(dired-unmark (- arg)))
(defvar dired-regexp-history nil
"History list of regular expressions used in Dired commands.")
-(defun dired-read-regexp (prompt)
- (read-from-minibuffer prompt nil nil nil 'dired-regexp-history))
+(defun dired-read-regexp (prompt &optional default history)
+ (read-regexp prompt default (or history 'dired-regexp-history)))
(defun dired-mark-files-regexp (regexp &optional marker-char)
"Mark all files matching REGEXP for use in later commands.
(setq dired-actual-switches
(replace-match "" t t dired-actual-switches 3))))
;; Now, if we weren't sorting by date before, add the -t switch.
+ ;; Some simple-minded ls implementations (eg ftp servers) only
+ ;; allow a single option string, so try not to add " -t" if possible.
(unless sorting-by-date
- (setq dired-actual-switches (concat dired-actual-switches " -t"))))
+ (setq dired-actual-switches
+ (concat dired-actual-switches
+ (if (string-match-p "\\`-[[:alnum:]]+\\'"
+ dired-actual-switches)
+ "t"
+ " -t")))))
(dired-sort-set-mode-line)
(revert-buffer))
;;;; Desktop support
(eval-when-compile (require 'desktop))
+(declare-function desktop-file-name "desktop" (filename dirname))
(defun dired-desktop-buffer-misc-data (dirname)
"Auxiliary information to be saved in desktop file."
;;;;;; 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" "9499f79f5853da0aa93d26465c7bf3a1")
+;;;;;; dired-diff) "dired-aux" "dired-aux.el" "d6a694b6d13fa948465fde52a9ffb3ba")
;;; Generated autoloads from dired-aux.el
(autoload 'dired-diff "dired-aux" "\
Compare file at point with file FILE using `diff'.
-FILE defaults to the file at the mark. (That's the mark set by
-\\[set-mark-command], not by Dired's \\[dired-mark] command.)
-The prompted-for FILE is the first file given to `diff'.
-With prefix arg, prompt for second argument SWITCHES,
-which is the string of command switches for `diff'.
+If called interactively, prompt for FILE. If the file at point
+has a backup file, use that as the default. If the file at point
+is a backup file, use its original. If the mark is active
+in Transient Mark mode, use the file at the mark as the default.
+\(That's the mark set by \\[set-mark-command], not by Dired's
+\\[dired-mark] command.)
+
+FILE is the first file given to `diff'. The file at point
+is the second file given to `diff'.
+
+With prefix arg, prompt for second argument SWITCHES, which is
+the string of command switches for the third argument of `diff'.
\(fn FILE &optional SWITCHES)" t nil)
(autoload 'dired-do-chmod "dired-aux" "\
Change the mode of the marked (or next ARG) files.
Symbolic modes like `g+w' are allowed.
+Type M-n to pull the file attributes of the file at point
+into the minibuffer.
\(fn &optional ARG)" t nil)
(autoload 'dired-do-chgrp "dired-aux" "\
Change the group of the marked (or next ARG) files.
+Type M-n to pull the file attributes of the file at point
+into the minibuffer.
\(fn &optional ARG)" t nil)
(autoload 'dired-do-chown "dired-aux" "\
Change the owner of the marked (or next ARG) files.
+Type M-n to pull the file attributes of the file at point
+into the minibuffer.
\(fn &optional ARG)" t nil)
(autoload 'dired-do-touch "dired-aux" "\
Change the timestamp of the marked (or next ARG) files.
This calls touch.
+Type M-n to pull the file attributes of the file at point
+into the minibuffer.
\(fn &optional ARG)" t nil)
;;;***
\f
;;;### (autoloads (dired-do-relsymlink dired-jump-other-window dired-jump)
-;;;;;; "dired-x" "dired-x.el" "d2461aa6efb8c1d7de8f245728ab448e")
+;;;;;; "dired-x" "dired-x.el" "90ba5245f6f5df3bdbda6303c725ef45")
;;; Generated autoloads from dired-x.el
(autoload 'dired-jump "dired-x" "\