* display.texi (Face Attributes): Add an index.
[bpt/emacs.git] / lisp / dired.el
CommitLineData
295fb2ac 1;;; dired.el --- directory-browsing commands -*- lexical-binding: t -*-
52041219 2
ba318903 3;; Copyright (C) 1985-1986, 1992-1997, 2000-2014 Free Software
ab422c4d 4;; Foundation, Inc.
ab67260b 5
b36b40ae
RS
6;; Author: Sebastian Kremer <sk@thp.uni-koeln.de>
7;; Maintainer: FSF
565132a3 8;; Keywords: files
bd78fa1d 9;; Package: emacs
84fc2cfa
ER
10
11;; This file is part of GNU Emacs.
12
eb3fa2cf 13;; GNU Emacs is free software: you can redistribute it and/or modify
84fc2cfa 14;; it under the terms of the GNU General Public License as published by
eb3fa2cf
GM
15;; the Free Software Foundation, either version 3 of the License, or
16;; (at your option) any later version.
84fc2cfa
ER
17
18;; GNU Emacs is distributed in the hope that it will be useful,
19;; but WITHOUT ANY WARRANTY; without even the implied warranty of
20;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21;; GNU General Public License for more details.
22
23;; You should have received a copy of the GNU General Public License
eb3fa2cf 24;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
84fc2cfa 25
52041219
RS
26;;; Commentary:
27
bff7c1ad
GM
28;; This is a major mode for directory browsing and editing.
29;; It is documented in the Emacs manual.
e41b2db1 30
492d2437
RS
31;; Rewritten in 1990/1991 to add tree features, file marking and
32;; sorting by Sebastian Kremer <sk@thp.uni-koeln.de>.
33;; Finished up by rms in 1992.
34
52041219 35;;; Code:
492d2437 36
45fdb482
JB
37(declare-function dired-buffer-more-recently-used-p
38 "dired-x" (buffer1 buffer2))
39
492d2437
RS
40;;; Customizable variables
41
286c247d
RS
42(defgroup dired nil
43 "Directory editing."
d7aed37c 44 :link '(custom-manual "(emacs)Dired")
ca66efd1 45 :group 'files)
286c247d
RS
46
47(defgroup dired-mark nil
68d2f12f 48 "Handling marks in Dired."
286c247d
RS
49 :prefix "dired-"
50 :group 'dired)
51
52
84fc2cfa 53;;;###autoload
6bdad9ae 54(defcustom dired-listing-switches (purecopy "-al")
9201cc28 55 "Switches passed to `ls' for Dired. MUST contain the `l' option.
492d2437 56May contain all other options that don't contradict `-l';
b36b40ae 57may contain even `F', `b', `i' and `s'. See also the variable
48404d5a
EZ
58`dired-ls-F-marks-symlinks' concerning the `F' switch.
59On systems such as MS-DOS and MS-Windows, which use `ls' emulation in Lisp,
60some of the `ls' switches are not supported; see the doc string of
a6d231bb 61`insert-directory' in `ls-lisp.el' for more details."
286c247d
RS
62 :type 'string
63 :group 'dired)
84fc2cfa 64
bff7c1ad 65(defcustom dired-subdir-switches nil
5553077c 66 "If non-nil, switches passed to `ls' for inserting subdirectories.
bff7c1ad
GM
67If nil, `dired-listing-switches' is used."
68 :group 'dired
69 :type '(choice (const :tag "Use dired-listing-switches" nil)
70 (string :tag "Switches")))
492d2437 71
bff7c1ad
GM
72(defcustom dired-chown-program
73 (purecopy (cond ((executable-find "chown") "chown")
74 ((file-executable-p "/usr/sbin/chown") "/usr/sbin/chown")
75 ((file-executable-p "/etc/chown") "/etc/chown")
76 (t "chown")))
77 "Name of chown command (usually `chown')."
78 :group 'dired
79 :type 'file)
80
81(defcustom dired-use-ls-dired 'unspecified
6240145a 82 "Non-nil means Dired should pass the \"--dired\" option to \"ls\".
8c44f097
CY
83The special value of `unspecified' means to check explicitly, and
84save the result in this variable. This is performed the first
6240145a
GM
85time `dired-insert-directory' is called.
86
87Note that if you set this option to nil, either through choice or
88because your \"ls\" program does not support \"--dired\", Dired
89will fail to parse some \"unusual\" file names, e.g. those with leading
90spaces. You might want to install ls from GNU Coreutils, which does
91support this option. Alternatively, you might want to use Emacs's
92own emulation of \"ls\", by using:
cedf5c9d
JB
93 (setq ls-lisp-use-insert-directory-program nil)
94 (require 'ls-lisp)
6240145a
GM
95This is used by default on MS Windows, which does not have an \"ls\" program.
96Note that `ls-lisp' does not support as many options as GNU ls, though.
97For more details, see Info node `(emacs)ls in Lisp'."
bff7c1ad
GM
98 :group 'dired
99 :type '(choice (const :tag "Check for --dired support" unspecified)
100 (const :tag "Do not use --dired" nil)
101 (other :tag "Use --dired" t)))
102
103(defcustom dired-chmod-program "chmod"
104 "Name of chmod command (usually `chmod')."
105 :group 'dired
106 :type 'file)
107
108(defcustom dired-touch-program "touch"
109 "Name of touch command (usually `touch')."
110 :group 'dired
111 :type 'file)
57654b8c 112
286c247d 113(defcustom dired-ls-F-marks-symlinks nil
9201cc28 114 "Informs Dired about how `ls -lF' marks symbolic links.
fc83abf7
RS
115Set this to t if `ls' (or whatever program is specified by
116`insert-directory-program') with `-lF' marks the symbolic link
492d2437 117itself with a trailing @ (usually the case under Ultrix).
84fc2cfa 118
492d2437
RS
119Example: if `ln -s foo bar; ls -F bar' gives `bar -> foo', set it to
120nil (the default), if it gives `bar@ -> foo', set it to t.
121
122Dired checks if there is really a @ appended. Thus, if you have a
123marking `ls' program on one host and a non-marking on another host, and
124don't care about symbolic links which really end in a @, you can
286c247d
RS
125always set this variable to t."
126 :type 'boolean
127 :group 'dired-mark)
492d2437 128
aaa448c9 129(defcustom dired-trivial-filenames (purecopy "^\\.\\.?$\\|^#")
9201cc28 130 "Regexp of files to skip when finding first file of a directory.
492d2437 131A value of nil means move to the subdir line.
286c247d
RS
132A value of t means move to first file."
133 :type '(choice (const :tag "Move to subdir" nil)
134 (const :tag "Move to first" t)
135 regexp)
136 :group 'dired)
492d2437 137
286c247d 138(defcustom dired-keep-marker-rename t
492d2437 139 ;; Use t as default so that moved files "take their markers with them".
9201cc28 140 "Controls marking of renamed files.
492d2437
RS
141If t, files keep their previous marks when they are renamed.
142If a character, renamed files (whether previously marked or not)
e2f022a3
JL
143are afterward marked with that character.
144This option affects only files renamed by `dired-do-rename' and
145`dired-do-rename-regexp'. See `wdired-keep-marker-rename'
146if you want to do the same for files renamed in WDired mode."
286c247d 147 :type '(choice (const :tag "Keep" t)
e2f022a3 148 (character :tag "Mark" :value ?R))
286c247d 149 :group 'dired-mark)
492d2437 150
286c247d 151(defcustom dired-keep-marker-copy ?C
9201cc28 152 "Controls marking of copied files.
492d2437 153If t, copied files are marked if and as the corresponding original files were.
286c247d
RS
154If a character, copied files are unconditionally marked with that character."
155 :type '(choice (const :tag "Keep" t)
156 (character :tag "Mark"))
157 :group 'dired-mark)
492d2437 158
286c247d 159(defcustom dired-keep-marker-hardlink ?H
9201cc28 160 "Controls marking of newly made hard links.
492d2437 161If t, they are marked if and as the files linked to were marked.
286c247d
RS
162If a character, new links are unconditionally marked with that character."
163 :type '(choice (const :tag "Keep" t)
164 (character :tag "Mark"))
165 :group 'dired-mark)
492d2437 166
286c247d 167(defcustom dired-keep-marker-symlink ?Y
9201cc28 168 "Controls marking of newly made symbolic links.
492d2437 169If t, they are marked if and as the files linked to were marked.
286c247d
RS
170If a character, new links are unconditionally marked with that character."
171 :type '(choice (const :tag "Keep" t)
172 (character :tag "Mark"))
173 :group 'dired-mark)
492d2437 174
286c247d 175(defcustom dired-dwim-target nil
9201cc28 176 "If non-nil, Dired tries to guess a default target directory.
c5695d1d
CY
177This means: if there is a Dired buffer displayed in the next
178window, use its current directory, instead of this Dired buffer's
179current directory.
492d2437 180
286c247d
RS
181The target is used in the prompt for file copy, rename etc."
182 :type 'boolean
183 :group 'dired)
492d2437 184
286c247d 185(defcustom dired-copy-preserve-time t
9201cc28 186 "If non-nil, Dired preserves the last-modified time in a file copy.
286c247d
RS
187\(This works on only some systems.)"
188 :type 'boolean
189 :group 'dired)
492d2437 190
05b855f5
EZ
191; These variables were deleted and the replacements are on files.el.
192; We leave aliases behind for back-compatibility.
193(defvaralias 'dired-free-space-program 'directory-free-space-program)
194(defvaralias 'dired-free-space-args 'directory-free-space-args)
195
492d2437
RS
196;;; Hook variables
197
c2792945 198(defcustom dired-load-hook nil
ee680b2b 199 "Run after loading Dired.
c2792945
EZ
200You can customize key bindings or load extensions with this."
201 :group 'dired
202 :type 'hook)
492d2437 203
c2792945 204(defcustom dired-mode-hook nil
ee680b2b 205 "Run at the very end of `dired-mode'."
c2792945
EZ
206 :group 'dired
207 :type 'hook)
492d2437 208
c2792945 209(defcustom dired-before-readin-hook nil
cedf5c9d 210 "This hook is run before a Dired buffer is read in (created or reverted)."
c2792945
EZ
211 :group 'dired
212 :type 'hook)
492d2437 213
c2792945 214(defcustom dired-after-readin-hook nil
492d2437
RS
215 "Hook run after each time a file or directory is read by Dired.
216After each listing of a file or directory, this hook is run
c2792945
EZ
217with the buffer narrowed to the listing."
218 :group 'dired
219 :type 'hook)
492d2437
RS
220;; Note this can't simply be run inside function `dired-ls' as the hook
221;; functions probably depend on the dired-subdir-alist to be OK.
222
1d42e5b6 223(defcustom dired-initial-position-hook nil
d4466a91
IK
224 "This hook is used to position the point.
225It is run the function `dired-initial-position'."
226 :group 'dired
227 :type 'hook
228 :version "24.4")
229
1ed8284d
RS
230(defcustom dired-dnd-protocol-alist
231 '(("^file:///" . dired-dnd-handle-local-file)
232 ("^file://" . dired-dnd-handle-file)
233 ("^file:" . dired-dnd-handle-local-file))
234 "The functions to call when a drop in `dired-mode' is made.
235See `dnd-protocol-alist' for more information. When nil, behave
3db7bf54 236as in other buffers. Changing this option is effective only for
cedf5c9d 237new Dired buffers."
1ed8284d
RS
238 :type '(choice (repeat (cons (regexp) (function)))
239 (const :tag "Behave as in other buffers" nil))
240 :version "22.1"
241 :group 'dired)
242
a2a538b1 243(defcustom dired-hide-details-hide-symlink-targets t
52695556 244 "Non-nil means `dired-hide-details-mode' hides symbolic link targets."
a2a538b1
CS
245 :type 'boolean
246 :version "24.4"
247 :group 'dired)
248
249(defcustom dired-hide-details-hide-information-lines t
52695556 250 "Non-nil means `dired-hide-details-mode' hides all but header and file lines."
a2a538b1
CS
251 :type 'boolean
252 :version "24.4"
253 :group 'dired)
254
2b2059d8 255;; Internal variables
492d2437
RS
256
257(defvar dired-marker-char ?* ; the answer is 42
258 ;; so that you can write things like
259 ;; (let ((dired-marker-char ?X))
260 ;; ;; great code using X markers ...
261 ;; )
262 ;; For example, commands operating on two sets of files, A and B.
263 ;; Or marking files with digits 0-9. This could implicate
264 ;; concentric sets or an order for the marked files.
265 ;; The code depends on dynamic scoping on the marker char.
266 "In Dired, the current mark character.
884b7f9d 267This is what the do-commands look for, and what the mark-commands store.")
492d2437
RS
268
269(defvar dired-del-marker ?D
270 "Character used to flag files for deletion.")
271
ee680b2b 272(defvar dired-shrink-to-fit t
ab67260b
RS
273;; I see no reason ever to make this nil -- rms.
274;; (> baud-rate search-slow-speed)
492d2437 275 "Non-nil means Dired shrinks the display buffer to fit the marked files.")
93cacb6d
JL
276(make-obsolete-variable 'dired-shrink-to-fit
277 "use the Customization interface to add a new rule
278to `display-buffer-alist' where condition regexp is \"^ \\*Marked Files\\*$\",
279action argument symbol is `window-height' and its value is nil." "24.3")
492d2437 280
ab67260b
RS
281(defvar dired-file-version-alist)
282
e956c609 283;;;###autoload
492d2437 284(defvar dired-directory nil
cedf5c9d
JB
285 "The directory name or wildcard spec that this Dired directory lists.
286Local to each Dired buffer. May be a list, in which case the car is the
0b7bc76f
RS
287directory name and the cdr is the list of files to mention.
288The directory name must be absolute, but need not be fully expanded.")
492d2437 289
9903d828 290;; Beware of "-l;reboot" etc. See bug#3230.
75da6eb9 291(defun dired-safe-switches-p (switches)
cedf5c9d 292 "Return non-nil if string SWITCHES does not look risky for Dired."
9903d828
GM
293 (or (not switches)
294 (and (stringp switches)
295 (< (length switches) 100) ; arbitrary
cedf5c9d 296 (string-match-p "\\` *-[- [:alnum:]]+\\'" switches))))
75da6eb9 297
492d2437
RS
298(defvar dired-actual-switches nil
299 "The value of `dired-listing-switches' used to make this buffer's text.")
300
9903d828
GM
301(put 'dired-actual-switches 'safe-local-variable 'dired-safe-switches-p)
302
492d2437
RS
303(defvar dired-re-inode-size "[0-9 \t]*"
304 "Regexp for optional initial inode and file size as made by `ls -i -s'.")
305
306;; These regexps must be tested at beginning-of-line, but are also
307;; used to search for next matches, so neither omitting "^" nor
308;; replacing "^" by "\n" (to make it slightly faster) will work.
309
310(defvar dired-re-mark "^[^ \n]")
311;; "Regexp matching a marked line.
312;; Important: the match ends just after the marker."
313(defvar dired-re-maybe-mark "^. ")
312a9e03
EZ
314;; The [^:] part after "d" and "l" is to avoid confusion with the
315;; DOS/Windows-style drive letters in directory names, like in "d:/foo".
316(defvar dired-re-dir (concat dired-re-maybe-mark dired-re-inode-size "d[^:]"))
317(defvar dired-re-sym (concat dired-re-maybe-mark dired-re-inode-size "l[^:]"))
492d2437
RS
318(defvar dired-re-exe;; match ls permission string of an executable file
319 (mapconcat (function
320 (lambda (x)
321 (concat dired-re-maybe-mark dired-re-inode-size x)))
322 '("-[-r][-w][xs][-r][-w].[-r][-w]."
323 "-[-r][-w].[-r][-w][xs][-r][-w]."
324 "-[-r][-w].[-r][-w].[-r][-w][xst]")
325 "\\|"))
e6cecd2b 326(defvar dired-re-perms "[-bcdlps][-r][-w].[-r][-w].[-r][-w].")
147e214c 327(defvar dired-re-dot "^.* \\.\\.?/?$")
492d2437 328
5553077c 329;; The subdirectory names in the next two lists are expanded.
492d2437
RS
330(defvar dired-subdir-alist nil
331 "Association list of subdirectories and their buffer positions.
332Each subdirectory has an element: (DIRNAME . STARTMARKER).
7b2469ae
RS
333The order of elements is the reverse of the order in the buffer.
334In simple cases, this list contains one element.")
492d2437 335
cedf5c9d 336(defvar-local dired-switches-alist nil
5553077c
LT
337 "Keeps track of which switches to use for inserted subdirectories.
338This is an alist of the form (SUBDIR . SWITCHES).")
5553077c 339
5afea280
RS
340(defvaralias 'dired-move-to-filename-regexp
341 'directory-listing-before-filename-regexp)
342
cdf156a9 343(defvar dired-subdir-regexp "^. \\([^\n\r]+\\)\\(:\\)[\n\r]"
492d2437
RS
344 "Regexp matching a maybe hidden subdirectory line in `ls -lR' output.
345Subexpression 1 is the subdirectory proper, no trailing colon.
346The match starts at the beginning of the line and ends after the end
347of the line (\\n or \\r).
348Subexpression 2 must end right before the \\n or \\r.")
349
0b0e6651 350(defgroup dired-faces nil
ee680b2b 351 "Faces used by Dired."
0b0e6651
JL
352 :group 'dired
353 :group 'faces)
354
355(defface dired-header
356 '((t (:inherit font-lock-type-face)))
357 "Face used for directory headers."
358 :group 'dired-faces
bf247b6e 359 :version "22.1")
0b0e6651
JL
360(defvar dired-header-face 'dired-header
361 "Face name used for directory headers.")
362
363(defface dired-mark
364 '((t (:inherit font-lock-constant-face)))
cedf5c9d 365 "Face used for Dired marks."
0b0e6651 366 :group 'dired-faces
bf247b6e 367 :version "22.1")
0b0e6651 368(defvar dired-mark-face 'dired-mark
cedf5c9d 369 "Face name used for Dired marks.")
0b0e6651
JL
370
371(defface dired-marked
bc987f8b 372 '((t (:inherit warning)))
0b0e6651
JL
373 "Face used for marked files."
374 :group 'dired-faces
bf247b6e 375 :version "22.1")
0b0e6651
JL
376(defvar dired-marked-face 'dired-marked
377 "Face name used for marked files.")
378
379(defface dired-flagged
bc987f8b 380 '((t (:inherit error)))
58274504 381 "Face used for files flagged for deletion."
0b0e6651 382 :group 'dired-faces
bf247b6e 383 :version "22.1")
0b0e6651 384(defvar dired-flagged-face 'dired-flagged
58274504 385 "Face name used for files flagged for deletion.")
0b0e6651
JL
386
387(defface dired-warning
0f0c86fc
MR
388 ;; Inherit from font-lock-warning-face since with min-colors 8
389 ;; font-lock-comment-face is not colored any more.
390 '((t (:inherit font-lock-warning-face)))
0b0e6651
JL
391 "Face used to highlight a part of a buffer that needs user attention."
392 :group 'dired-faces
bf247b6e 393 :version "22.1")
0b0e6651
JL
394(defvar dired-warning-face 'dired-warning
395 "Face name used for a part of a buffer that needs user attention.")
396
0199e765 397(defface dired-perm-write
38838c80 398 '((((type w32 pc)) :inherit default) ;; These default to rw-rw-rw.
e1dab605
JL
399 ;; Inherit from font-lock-comment-delimiter-face since with min-colors 8
400 ;; font-lock-comment-face is not colored any more.
0199e765 401 (t (:inherit font-lock-comment-delimiter-face)))
38838c80
EZ
402 "Face used to highlight permissions of group- and world-writable files."
403 :group 'dired-faces
404 :version "22.2")
0199e765 405(defvar dired-perm-write-face 'dired-perm-write
38838c80
EZ
406 "Face name used for permissions of group- and world-writable files.")
407
0b0e6651
JL
408(defface dired-directory
409 '((t (:inherit font-lock-function-name-face)))
410 "Face used for subdirectories."
411 :group 'dired-faces
bf247b6e 412 :version "22.1")
0b0e6651
JL
413(defvar dired-directory-face 'dired-directory
414 "Face name used for subdirectories.")
415
416(defface dired-symlink
417 '((t (:inherit font-lock-keyword-face)))
418 "Face used for symbolic links."
419 :group 'dired-faces
bf247b6e 420 :version "22.1")
0b0e6651
JL
421(defvar dired-symlink-face 'dired-symlink
422 "Face name used for symbolic links.")
423
424(defface dired-ignored
cf78a467 425 '((t (:inherit shadow)))
0b0e6651
JL
426 "Face used for files suffixed with `completion-ignored-extensions'."
427 :group 'dired-faces
bf247b6e 428 :version "22.1")
0b0e6651
JL
429(defvar dired-ignored-face 'dired-ignored
430 "Face name used for files suffixed with `completion-ignored-extensions'.")
431
2439570d
SM
432(defvar dired-font-lock-keywords
433 (list
0b0e6651
JL
434 ;;
435 ;; Dired marks.
436 (list dired-re-mark '(0 dired-mark-face))
2439570d
SM
437 ;;
438 ;; We make heavy use of MATCH-ANCHORED, since the regexps don't identify the
439 ;; file name itself. We search for Dired defined regexps, and then use the
440 ;; Dired defined function `dired-move-to-filename' before searching for the
441 ;; simple regexp ".+". It is that regexp which matches the file name.
442 ;;
0b0e6651
JL
443 ;; Marked files.
444 (list (concat "^[" (char-to-string dired-marker-char) "]")
445 '(".+" (dired-move-to-filename) nil (0 dired-marked-face)))
446 ;;
447 ;; Flagged files.
448 (list (concat "^[" (char-to-string dired-del-marker) "]")
449 '(".+" (dired-move-to-filename) nil (0 dired-flagged-face)))
4fdf389a
RS
450 ;; People who are paranoid about security would consider this more
451 ;; important than other things such as whether it is a directory.
452 ;; But we don't want to encourage paranoia, so our default
453 ;; should be what's most useful for non-paranoids. -- rms.
454;;; ;;
455;;; ;; Files that are group or world writable.
456;;; (list (concat dired-re-maybe-mark dired-re-inode-size
457;;; "\\([-d]\\(....w....\\|.......w.\\)\\)")
0b0e6651
JL
458;;; '(1 dired-warning-face)
459;;; '(".+" (dired-move-to-filename) nil (0 dired-warning-face)))
d7aed37c
SM
460 ;; However, we don't need to highlight the file name, only the
461 ;; permissions, to win generally. -- fx.
462 ;; Fixme: we could also put text properties on the permission
463 ;; fields with keymaps to frob the permissions, somewhat a la XEmacs.
464 (list (concat dired-re-maybe-mark dired-re-inode-size
f16bcc9a 465 "[-d]....\\(w\\)....") ; group writable
0199e765 466 '(1 dired-perm-write-face))
d7aed37c 467 (list (concat dired-re-maybe-mark dired-re-inode-size
f16bcc9a 468 "[-d].......\\(w\\).") ; world writable
0199e765 469 '(1 dired-perm-write-face))
2439570d
SM
470 ;;
471 ;; Subdirectories.
472 (list dired-re-dir
0b0e6651 473 '(".+" (dired-move-to-filename) nil (0 dired-directory-face)))
2439570d
SM
474 ;;
475 ;; Symbolic links.
c60ee5e7 476 (list dired-re-sym
0b0e6651 477 '(".+" (dired-move-to-filename) nil (0 dired-symlink-face)))
2439570d
SM
478 ;;
479 ;; Files suffixed with `completion-ignored-extensions'.
480 '(eval .
2b2059d8
SM
481 ;; It is quicker to first find just an extension, then go back to the
482 ;; start of that file name. So we do this complex MATCH-ANCHORED form.
483 (list (concat "\\(" (regexp-opt completion-ignored-extensions) "\\|#\\)$")
2225a196
RS
484 '(".+" (dired-move-to-filename) nil (0 dired-ignored-face))))
485 ;;
486 ;; Files suffixed with `completion-ignored-extensions'
487 ;; plus a character put in by -F.
488 '(eval .
489 (list (concat "\\(" (regexp-opt completion-ignored-extensions)
490 "\\|#\\)[*=|]$")
491 '(".+" (progn
492 (end-of-line)
493 ;; If the last character is not part of the filename,
494 ;; move back to the start of the filename
495 ;; so it can be fontified.
496 ;; Otherwise, leave point at the end of the line;
497 ;; that way, nothing is fontified.
498 (unless (get-text-property (1- (point)) 'mouse-face)
499 (dired-move-to-filename)))
500 nil (0 dired-ignored-face))))
a5dad58a
AS
501 ;;
502 ;; Explicitly put the default face on file names ending in a colon to
503 ;; avoid fontifying them as directory header.
504 (list (concat dired-re-maybe-mark dired-re-inode-size dired-re-perms ".*:$")
fc7da30b 505 '(".+" (dired-move-to-filename) nil (0 'default)))
a5dad58a
AS
506 ;;
507 ;; Directory headers.
508 (list dired-subdir-regexp '(1 dired-header-face))
2225a196 509)
2439570d 510 "Additional expressions to highlight in Dired mode.")
65536d1d
RS
511
512(defvar dnd-protocol-alist)
83fadedf 513\f
492d2437
RS
514;;; Macros must be defined before they are used, for the byte compiler.
515
492d2437 516(defmacro dired-mark-if (predicate msg)
d7aed37c
SM
517 "Mark all files for which PREDICATE evals to non-nil.
518PREDICATE is evaluated on each line, with point at beginning of line.
519MSG is a noun phrase for the type of files being marked.
520It should end with a noun that can be pluralized by adding `s'.
521Return value is the number of files marked, or nil if none were marked."
f836b98e 522 `(let ((inhibit-read-only t) count)
8a946354
SS
523 (save-excursion
524 (setq count 0)
e17d05e2
LMI
525 (when ,msg
526 (message "%s %ss%s..."
527 (cond ((eq dired-marker-char ?\040) "Unmarking")
528 ((eq dired-del-marker dired-marker-char)
529 "Flagging")
530 (t "Marking"))
531 ,msg
532 (if (eq dired-del-marker dired-marker-char)
533 " for deletion"
534 "")))
8a946354
SS
535 (goto-char (point-min))
536 (while (not (eobp))
537 (if ,predicate
538 (progn
539 (delete-char 1)
540 (insert dired-marker-char)
541 (setq count (1+ count))))
542 (forward-line 1))
543 (if ,msg (message "%s %s%s %s%s."
544 count
545 ,msg
546 (dired-plural-s count)
547 (if (eq dired-marker-char ?\040) "un" "")
548 (if (eq dired-marker-char dired-del-marker)
549 "flagged" "marked"))))
550 (and (> count 0) count)))
492d2437 551
09b092ad
RS
552(defmacro dired-map-over-marks (body arg &optional show-progress
553 distinguish-one-marked)
91947235 554 "Eval BODY with point on each marked line. Return a list of BODY's results.
1ca0da0e
LMI
555If no marked file could be found, execute BODY on the current
556line. ARG, if non-nil, specifies the files to use instead of the
557marked files.
558
559If ARG is an integer, use the next ARG (or previous -ARG, if
560ARG<0) files. In that case, point is dragged along. This is so
561that commands on the next ARG (instead of the marked) files can
562be chained easily.
563For any other non-nil value of ARG, use the current file.
564
91947235 565If optional third arg SHOW-PROGRESS evaluates to non-nil,
1ca0da0e
LMI
566redisplay the dired buffer after each file is processed.
567
cedf5c9d
JB
568No guarantee is made about the position on the marked line.
569BODY must ensure this itself if it depends on this.
1ca0da0e
LMI
570
571Search starts at the beginning of the buffer, thus the car of the
572list corresponds to the line nearest to the buffer's bottom.
573This is also true for (positive and negative) integer values of
574ARG.
575
09b092ad
RS
576BODY should not be too long as it is expanded four times.
577
1ca0da0e
LMI
578If DISTINGUISH-ONE-MARKED is non-nil, then if we find just one
579marked file, return (t FILENAME) instead of (FILENAME)."
91947235
SM
580 ;;
581 ;;Warning: BODY must not add new lines before point - this may cause an
582 ;;endless loop.
583 ;;This warning should not apply any longer, sk 2-Sep-1991 14:10.
584 `(prog1
f836b98e 585 (let ((inhibit-read-only t) case-fold-search found results)
91947235
SM
586 (if ,arg
587 (if (integerp ,arg)
588 (progn ;; no save-excursion, want to move point.
589 (dired-repeat-over-lines
590 ,arg
591 (function (lambda ()
592 (if ,show-progress (sit-for 0))
593 (setq results (cons ,body results)))))
594 (if (< ,arg 0)
595 (nreverse results)
596 results))
597 ;; non-nil, non-integer ARG means use current file:
598 (list ,body))
599 (let ((regexp (dired-marker-regexp)) next-position)
600 (save-excursion
601 (goto-char (point-min))
602 ;; remember position of next marked file before BODY
603 ;; can insert lines before the just found file,
604 ;; confusing us by finding the same marked file again
605 ;; and again and...
606 (setq next-position (and (re-search-forward regexp nil t)
607 (point-marker))
608 found (not (null next-position)))
609 (while next-position
610 (goto-char next-position)
611 (if ,show-progress (sit-for 0))
612 (setq results (cons ,body results))
613 ;; move after last match
614 (goto-char next-position)
615 (forward-line 1)
616 (set-marker next-position nil)
492d2437 617 (setq next-position (and (re-search-forward regexp nil t)
91947235 618 (point-marker)))))
09b092ad
RS
619 (if (and ,distinguish-one-marked (= (length results) 1))
620 (setq results (cons t results)))
91947235
SM
621 (if found
622 results
623 (list ,body)))))
624 ;; save-excursion loses, again
625 (dired-move-to-filename)))
492d2437 626
09b092ad 627(defun dired-get-marked-files (&optional localp arg filter distinguish-one-marked)
492d2437
RS
628 "Return the marked files' names as list of strings.
629The list is in the same order as the buffer, that is, the car is the
630 first marked file.
1312bfc6 631Values returned are normally absolute file names.
492d2437 632Optional arg LOCALP as in `dired-get-filename'.
7ada496c
CY
633Optional second argument ARG, if non-nil, specifies files near
634 point instead of marked files. It usually comes from the prefix
635 argument.
636 If ARG is an integer, use the next ARG files.
637 Any other non-nil value means to use the current file instead.
1312bfc6 638Optional third argument FILTER, if non-nil, is a function to select
09b092ad
RS
639 some of the files--those for which (funcall FILTER FILENAME) is non-nil.
640
641If DISTINGUISH-ONE-MARKED is non-nil, then if we find just one marked file,
642return (t FILENAME) instead of (FILENAME).
643Don't use that together with FILTER."
2fc71e3c
LL
644 (let ((all-of-them
645 (save-excursion
646 (delq nil (dired-map-over-marks
647 (dired-get-filename localp 'no-error-if-not-filep)
648 arg nil distinguish-one-marked))))
649 result)
650 (when (equal all-of-them '(t))
651 (setq all-of-them nil))
1312bfc6 652 (if (not filter)
09b092ad
RS
653 (if (and distinguish-one-marked (eq (car all-of-them) t))
654 all-of-them
655 (nreverse all-of-them))
1312bfc6
RS
656 (dolist (file all-of-them)
657 (if (funcall filter file)
658 (push file result)))
659 result)))
83fadedf 660\f
492d2437
RS
661;; The dired command
662
663(defun dired-read-dir-and-switches (str)
664 ;; For use in interactive.
6f6c43ff
CY
665 (reverse (list
666 (if current-prefix-arg
667 (read-string "Dired listing switches: "
668 dired-listing-switches))
7e27ce9c
AL
669 ;; If a dialog is used, call `read-directory-name' so the
670 ;; dialog code knows we want directories. Some dialogs
671 ;; can only select directories or files when popped up,
672 ;; not both. If no dialog is used, call `read-file-name'
673 ;; because the user may want completion of file names for
674 ;; use in a wildcard pattern.
6f6c43ff
CY
675 (if (next-read-file-uses-dialog-p)
676 (read-directory-name (format "Dired %s(directory): " str)
677 nil default-directory nil)
7d371eac
JL
678 (read-file-name (format "Dired %s(directory): " str)
679 nil default-directory nil)))))
6f6c43ff
CY
680
681;; We want to switch to a more sophisticated version of
682;; dired-read-dir-and-switches like the following, if there is a way
683;; to make it more intuitive. See bug#1285.
684
685;; (defun dired-read-dir-and-switches (str)
686;; ;; For use in interactive.
687;; (reverse
688;; (list
689;; (if current-prefix-arg
690;; (read-string "Dired listing switches: "
691;; dired-listing-switches))
692;; ;; If a dialog is about to be used, call read-directory-name so
693;; ;; the dialog code knows we want directories. Some dialogs can
694;; ;; only select directories or files when popped up, not both.
695;; (if (next-read-file-uses-dialog-p)
696;; (read-directory-name (format "Dired %s(directory): " str)
697;; nil default-directory nil)
698;; (let ((cie ()))
699;; (dolist (ext completion-ignored-extensions)
700;; (if (eq ?/ (aref ext (1- (length ext)))) (push ext cie)))
701;; (setq cie (concat (regexp-opt cie "\\(?:") "\\'"))
e95a67dc
SM
702;; (let* ((default (and buffer-file-name
703;; (abbreviate-file-name buffer-file-name)))
704;; (cie cie)
705;; (completion-table
706;; ;; We need a mix of read-file-name and
707;; ;; read-directory-name so that completion to directories
708;; ;; is preferred, but if the user wants to enter a global
709;; ;; pattern, he can still use completion on filenames to
710;; ;; help him write the pattern.
711;; ;; Essentially, we want to use
712;; ;; (completion-table-with-predicate
713;; ;; 'read-file-name-internal 'file-directory-p nil)
714;; ;; but that doesn't work because read-file-name-internal
715;; ;; does not obey its `predicate' argument.
716;; (completion-table-in-turn
717;; (lambda (str pred action)
718;; (let ((read-file-name-predicate
719;; (lambda (f)
720;; (and (not (member f '("./" "../")))
721;; ;; Hack! Faster than file-directory-p!
722;; (eq (aref f (1- (length f))) ?/)
723;; (not (string-match cie f))))))
724;; (complete-with-action
725;; action 'read-file-name-internal str nil)))
726;; 'read-file-name-internal)))
6f6c43ff
CY
727;; (minibuffer-with-setup-hook
728;; (lambda ()
729;; (setq minibuffer-default default)
730;; (setq minibuffer-completion-table completion-table))
731;; (read-file-name (format "Dired %s(directory): " str)
732;; nil default-directory nil))))))))
84fc2cfa 733
7d371eac
JL
734(defun dired-file-name-at-point ()
735 "Try to get a file name at point in the current dired buffer.
1d42e5b6
JL
736This hook is intended to be put in `file-name-at-point-functions'.
737Note that it returns an abbreviated name that can't be used
738as an argument to `dired-goto-file'."
7d371eac
JL
739 (let ((filename (dired-get-filename nil t)))
740 (when filename
741 (if (file-directory-p filename)
742 (file-name-as-directory (abbreviate-file-name filename))
743 (abbreviate-file-name filename)))))
744
492d2437 745;;;###autoload (define-key ctl-x-map "d" 'dired)
84fc2cfa 746;;;###autoload
492d2437 747(defun dired (dirname &optional switches)
84fc2cfa 748 "\"Edit\" directory DIRNAME--delete, rename, print, etc. some files in it.
492d2437
RS
749Optional second argument SWITCHES specifies the `ls' options used.
750\(Interactively, use a prefix argument to be able to specify SWITCHES.)
751Dired displays a list of files in DIRNAME (which may also have
8d23c16b 752shell wildcards appended to select certain files). If DIRNAME is a cons,
1015daba 753its first element is taken as the directory name and the rest as an explicit
8d23c16b 754list of files to make directory entries for.
52041219 755\\<dired-mode-map>\
8d23c16b
ER
756You can flag files for deletion with \\[dired-flag-file-deletion] and then
757delete them by typing \\[dired-do-flagged-delete].
ee680b2b 758Type \\[describe-mode] after entering Dired for more info.
84fc2cfa 759
cedf5c9d 760If DIRNAME is already in a Dired buffer, that buffer is used without refresh."
492d2437
RS
761 ;; Cannot use (interactive "D") because of wildcards.
762 (interactive (dired-read-dir-and-switches ""))
763 (switch-to-buffer (dired-noselect dirname switches)))
764
765;;;###autoload (define-key ctl-x-4-map "d" 'dired-other-window)
84fc2cfa 766;;;###autoload
492d2437 767(defun dired-other-window (dirname &optional switches)
84fc2cfa 768 "\"Edit\" directory DIRNAME. Like `dired' but selects in another window."
492d2437
RS
769 (interactive (dired-read-dir-and-switches "in other window "))
770 (switch-to-buffer-other-window (dired-noselect dirname switches)))
84fc2cfa 771
ec03e49c
RS
772;;;###autoload (define-key ctl-x-5-map "d" 'dired-other-frame)
773;;;###autoload
774(defun dired-other-frame (dirname &optional switches)
775 "\"Edit\" directory DIRNAME. Like `dired' but makes a new frame."
776 (interactive (dired-read-dir-and-switches "in other frame "))
777 (switch-to-buffer-other-frame (dired-noselect dirname switches)))
778
84fc2cfa 779;;;###autoload
8d23c16b 780(defun dired-noselect (dir-or-list &optional switches)
cedf5c9d 781 "Like `dired' but returns the Dired buffer as value, does not select it."
8d23c16b 782 (or dir-or-list (setq dir-or-list default-directory))
492d2437
RS
783 ;; This loses the distinction between "/foo/*/" and "/foo/*" that
784 ;; some shells make:
54df7d9a 785 (let (dirname initially-was-dirname)
8d23c16b
ER
786 (if (consp dir-or-list)
787 (setq dirname (car dir-or-list))
788 (setq dirname dir-or-list))
54df7d9a
RS
789 (setq initially-was-dirname
790 (string= (file-name-as-directory dirname) dirname))
370b6149
RS
791 (setq dirname (abbreviate-file-name
792 (expand-file-name (directory-file-name dirname))))
cb2e51f8
RS
793 (if find-file-visit-truename
794 (setq dirname (file-truename dirname)))
54df7d9a
RS
795 ;; If the argument was syntactically a directory name not a file name,
796 ;; or if it happens to name a file that is a directory,
797 ;; convert it syntactically to a directory name.
798 ;; The reason for checking initially-was-dirname
799 ;; and not just file-directory-p
800 ;; is that file-directory-p is slow over ftp.
801 (if (or initially-was-dirname (file-directory-p dirname))
802 (setq dirname (file-name-as-directory dirname)))
8d23c16b
ER
803 (if (consp dir-or-list)
804 (setq dir-or-list (cons dirname (cdr dir-or-list)))
805 (setq dir-or-list dirname))
806 (dired-internal-noselect dir-or-list switches)))
492d2437 807
573e4d2d
LT
808;; The following is an internal dired function. It returns non-nil if
809;; the directory visited by the current dired buffer has changed on
810;; disk. DIRNAME should be the directory name of that directory.
811(defun dired-directory-changed-p (dirname)
812 (not (let ((attributes (file-attributes dirname))
e09cd94f
LT
813 (modtime (visited-file-modtime)))
814 (or (eq modtime 0)
815 (not (eq (car attributes) t))
ca02a726 816 (equal (nth 5 attributes) modtime)))))
573e4d2d
LT
817
818(defun dired-buffer-stale-p (&optional noconfirm)
cedf5c9d 819 "Return non-nil if current Dired buffer needs updating.
573e4d2d 820If NOCONFIRM is non-nil, then this function always returns nil
cedf5c9d 821for a remote directory. This feature is used by Auto Revert mode."
573e4d2d
LT
822 (let ((dirname
823 (if (consp dired-directory) (car dired-directory) dired-directory)))
824 (and (stringp dirname)
825 (not (when noconfirm (file-remote-p dirname)))
826 (file-readable-p dirname)
85a3be15
MR
827 ;; Do not auto-revert when the dired buffer can be currently
828 ;; written by the user as in `wdired-mode'.
829 buffer-read-only
573e4d2d
LT
830 (dired-directory-changed-p dirname))))
831
2b3489a7 832(defcustom dired-auto-revert-buffer nil
cedf5c9d
JB
833 "Automatically revert Dired buffer on revisiting.
834If t, revisiting an existing Dired buffer automatically reverts it.
2b3489a7
JL
835If its value is a function, call this function with the directory
836name as single argument and revert the buffer if it returns non-nil.
837Otherwise, a message offering to revert the changed dired buffer
838is displayed.
839Note that this is not the same as `auto-revert-mode' that
840periodically reverts at specified time intervals."
841 :type '(choice
842 (const :tag "Don't revert" nil)
cedf5c9d
JB
843 (const :tag "Always revert visited Dired buffer" t)
844 (const :tag "Revert changed Dired buffer" dired-directory-changed-p)
2b3489a7
JL
845 (function :tag "Predicate function"))
846 :group 'dired
847 :version "23.2")
848
6a4cd605 849(defun dired-internal-noselect (dir-or-list &optional switches mode)
492d2437
RS
850 ;; If there is an existing dired buffer for DIRNAME, just leave
851 ;; buffer as it is (don't even call dired-revert).
852 ;; This saves time especially for deep trees or with ange-ftp.
573e4d2d 853 ;; The user can type `g' easily, and it is more consistent with find-file.
492d2437
RS
854 ;; But if SWITCHES are given they are probably different from the
855 ;; buffer's old value, so call dired-sort-other, which does
856 ;; revert the buffer.
857 ;; A pity we can't possibly do "Directory has changed - refresh? "
858 ;; like find-file does.
6a4cd605
RS
859 ;; Optional argument MODE is passed to dired-find-buffer-nocreate,
860 ;; see there.
72f16325
SM
861 (let* ((old-buf (current-buffer))
862 (dirname (if (consp dir-or-list) (car dir-or-list) dir-or-list))
863 ;; Look for an existing buffer.
864 (buffer (dired-find-buffer-nocreate dirname mode))
865 ;; Note that buffer already is in dired-mode, if found.
866 (new-buffer-p (null buffer)))
492d2437 867 (or buffer
72f16325 868 (setq buffer (create-file-buffer (directory-file-name dirname))))
492d2437 869 (set-buffer buffer)
573e4d2d
LT
870 (if (not new-buffer-p) ; existing buffer ...
871 (cond (switches ; ... but new switches
6cfd24f9 872 ;; file list may have changed
0b7bc76f 873 (setq dired-directory dir-or-list)
6cfd24f9 874 ;; this calls dired-revert
c60ee5e7 875 (dired-sort-other switches))
2b3489a7
JL
876 ;; Always revert regardless of whether it has changed or not.
877 ((eq dired-auto-revert-buffer t)
878 (revert-buffer))
879 ;; Revert when predicate function returns non-nil.
880 ((functionp dired-auto-revert-buffer)
881 (when (funcall dired-auto-revert-buffer dirname)
882 (revert-buffer)
883 (message "Changed directory automatically updated")))
6cfd24f9 884 ;; If directory has changed on disk, offer to revert.
573e4d2d 885 ((when (dired-directory-changed-p dirname)
952e8cb5 886 (message "%s"
212b2266
KH
887 (substitute-command-keys
888 "Directory has changed on disk; type \\[revert-buffer] to update Dired")))))
492d2437 889 ;; Else a new buffer
847aabce 890 (setq default-directory
e3cd4b53
RS
891 ;; We can do this unconditionally
892 ;; because dired-noselect ensures that the name
893 ;; is passed in directory name syntax
894 ;; if it was the name of a directory at all.
895 (file-name-directory dirname))
492d2437 896 (or switches (setq switches dired-listing-switches))
6e5d9ec5 897 (if mode (funcall mode)
0b7bc76f 898 (dired-mode dir-or-list switches))
492d2437
RS
899 ;; default-directory and dired-actual-switches are set now
900 ;; (buffer-local), so we can call dired-readin:
901 (let ((failed t))
902 (unwind-protect
0b7bc76f 903 (progn (dired-readin)
492d2437
RS
904 (setq failed nil))
905 ;; dired-readin can fail if parent directories are inaccessible.
906 ;; Don't leave an empty buffer around in that case.
907 (if failed (kill-buffer buffer))))
492d2437
RS
908 (goto-char (point-min))
909 (dired-initial-position dirname))
910 (set-buffer old-buf)
84fc2cfa
ER
911 buffer))
912
c5753a5d
GM
913(defvar dired-buffers nil
914 ;; Enlarged by dired-advertise
915 ;; Queried by function dired-buffers-for-dir. When this detects a
916 ;; killed buffer, it is removed from this list.
cedf5c9d 917 "Alist of expanded directories and their associated Dired buffers.")
c5753a5d 918
bea584fa
GM
919(defvar dired-find-subdir)
920
921;; FIXME add a doc-string, and document dired-x extensions.
6a4cd605
RS
922(defun dired-find-buffer-nocreate (dirname &optional mode)
923 ;; This differs from dired-buffers-for-dir in that it does not consider
924 ;; subdirs of default-directory and searches for the first match only.
925 ;; Also, the major mode must be MODE.
bea584fa
GM
926 (if (and (featurep 'dired-x)
927 dired-find-subdir
928 ;; Don't try to find a wildcard as a subdirectory.
929 (string-equal dirname (file-name-directory dirname)))
930 (let* ((cur-buf (current-buffer))
931 (buffers (nreverse
932 (dired-buffers-for-dir (expand-file-name dirname))))
933 (cur-buf-matches (and (memq cur-buf buffers)
934 ;; Wildcards must match, too:
935 (equal dired-directory dirname))))
936 ;; We don't want to switch to the same buffer---
937 (setq buffers (delq cur-buf buffers))
938 (or (car (sort buffers #'dired-buffer-more-recently-used-p))
939 ;; ---unless it's the only possibility:
940 (and cur-buf-matches cur-buf)))
941 ;; No dired-x, or dired-find-subdir nil.
942 (setq dirname (expand-file-name dirname))
943 (let (found (blist dired-buffers)) ; was (buffer-list)
944 (or mode (setq mode 'dired-mode))
945 (while blist
946 (if (null (buffer-name (cdr (car blist))))
947 (setq blist (cdr blist))
948 (with-current-buffer (cdr (car blist))
949 (if (and (eq major-mode mode)
950 dired-directory ;; nil during find-alternate-file
951 (equal dirname
952 (expand-file-name
953 (if (consp dired-directory)
954 (car dired-directory)
955 dired-directory))))
956 (setq found (cdr (car blist))
957 blist nil)
958 (setq blist (cdr blist))))))
959 found)))
492d2437 960
83fadedf 961\f
492d2437
RS
962;; Read in a new dired buffer
963
0b7bc76f 964(defun dired-readin ()
cedf5c9d 965 "Read in a new Dired buffer.
87ae59e3 966Differs from `dired-insert-subdir' in that it accepts
d7aed37c
SM
967wildcards, erases the buffer, and builds the subdir-alist anew
968\(including making it buffer-local and clearing it first)."
969
492d2437
RS
970 ;; default-directory and dired-actual-switches must be buffer-local
971 ;; and initialized by now.
a1037423
RS
972 (let (dirname
973 ;; This makes readin much much faster.
974 ;; In particular, it prevents the font lock hook from running
975 ;; until the directory is all read in.
976 (inhibit-modification-hooks t))
0b7bc76f
RS
977 (if (consp dired-directory)
978 (setq dirname (car dired-directory))
979 (setq dirname dired-directory))
8d23c16b 980 (setq dirname (expand-file-name dirname))
8d23c16b 981 (save-excursion
0b7bc76f
RS
982 ;; This hook which may want to modify dired-actual-switches
983 ;; based on dired-directory, e.g. with ange-ftp to a SysV host
984 ;; where ls won't understand -Al switches.
985 (run-hooks 'dired-before-readin-hook)
0b7bc76f
RS
986 (if (consp buffer-undo-list)
987 (setq buffer-undo-list nil))
cedf5c9d
JB
988 (setq-local file-name-coding-system
989 (or coding-system-for-read file-name-coding-system))
f836b98e 990 (let ((inhibit-read-only t)
0b7bc76f
RS
991 ;; Don't make undo entries for readin.
992 (buffer-undo-list t))
8d23c16b
ER
993 (widen)
994 (erase-buffer)
0b7bc76f 995 (dired-readin-insert))
0b7bc76f 996 (goto-char (point-min))
8d23c16b
ER
997 ;; Must first make alist buffer local and set it to nil because
998 ;; dired-build-subdir-alist will call dired-clear-alist first
cedf5c9d 999 (setq-local dired-subdir-alist nil)
8197b8bf 1000 (dired-build-subdir-alist)
fa562dd5
RS
1001 (let ((attributes (file-attributes dirname)))
1002 (if (eq (car attributes) t)
1003 (set-visited-file-modtime (nth 5 attributes))))
0b7bc76f
RS
1004 (set-buffer-modified-p nil)
1005 ;; No need to narrow since the whole buffer contains just
1006 ;; dired-readin's output, nothing else. The hook can
1007 ;; successfully use dired functions (e.g. dired-get-filename)
1008 ;; as the subdir-alist has been built in dired-readin.
1009 (run-hooks 'dired-after-readin-hook))))
492d2437
RS
1010
1011;; Subroutines of dired-readin
1012
0b7bc76f
RS
1013(defun dired-readin-insert ()
1014 ;; Insert listing for the specified dir (and maybe file list)
1015 ;; already in dired-directory, assuming a clean buffer.
1016 (let (dir file-list)
1017 (if (consp dired-directory)
1018 (setq dir (car dired-directory)
1019 file-list (cdr dired-directory))
1020 (setq dir dired-directory
1021 file-list nil))
34cd7b3c 1022 (setq dir (expand-file-name dir))
0b7bc76f
RS
1023 (if (and (equal "" (file-name-nondirectory dir))
1024 (not file-list))
cf39fa9b 1025 ;; If we are reading a whole single directory...
0b7bc76f 1026 (dired-insert-directory dir dired-actual-switches nil nil t)
8d23c16b 1027 (if (not (file-readable-p
0b7bc76f
RS
1028 (directory-file-name (file-name-directory dir))))
1029 (error "Directory %s inaccessible or nonexistent" dir)
1030 ;; Else treat it as a wildcard spec
1031 ;; unless we have an explicit list of files.
1032 (dired-insert-directory dir dired-actual-switches
1033 file-list (not file-list) t)))))
1034
a12c6dca
SM
1035(defun dired-align-file (beg end)
1036 "Align the fields of a file to the ones of surrounding lines.
1037BEG..END is the line where the file info is located."
1038 ;; Some versions of ls try to adjust the size of each field so as to just
1039 ;; hold the largest element ("largest" in the current invocation, of
1040 ;; course). So when a single line is output, the size of each field is
1041 ;; just big enough for that one output. Thus when dired refreshes one
1042 ;; line, the alignment if this line w.r.t the rest is messed up because
1043 ;; the fields of that one line will generally be smaller.
1044 ;;
9bc260cf
MA
1045 ;; To work around this problem, we here add spaces to try and
1046 ;; re-align the fields as needed. Since this is purely aesthetic,
1047 ;; it is of utmost importance that it doesn't mess up anything like
1048 ;; `dired-move-to-filename'. To this end, we limit ourselves to
1049 ;; adding spaces only, and to only add them at places where there
1050 ;; was already at least one space. This way, as long as
1051 ;; `directory-listing-before-filename-regexp' always matches spaces
1052 ;; with "*" or "+", we know we haven't made anything worse. There
1053 ;; is one spot where the exact number of spaces is important, which
1054 ;; is just before the actual filename, so we refrain from adding
1055 ;; spaces there (and within the filename as well, of course).
a12c6dca
SM
1056 (save-excursion
1057 (let (file file-col other other-col)
91af3942 1058 ;; Check that there is indeed a file, and that there is another adjacent
a12c6dca
SM
1059 ;; file with which to align, and that additional spaces are needed to
1060 ;; align the filenames.
1061 (when (and (setq file (progn (goto-char beg)
1062 (dired-move-to-filename nil end)))
1063 (setq file-col (current-column))
1064 (setq other
1065 (or (and (goto-char beg)
1066 (zerop (forward-line -1))
1067 (dired-move-to-filename))
1068 (and (goto-char beg)
1069 (zerop (forward-line 1))
1070 (dired-move-to-filename))))
1071 (setq other-col (current-column))
1072 (/= file other)
1073 ;; Make sure there is some work left to do.
1074 (> other-col file-col))
1075 ;; If we've only looked at the line above, check to see if the line
1076 ;; below exists as well and if so, align with the shorter one.
1077 (when (and (< other file)
1078 (goto-char beg)
1079 (zerop (forward-line 1))
1080 (dired-move-to-filename))
1081 (let ((alt-col (current-column)))
1082 (when (< alt-col other-col)
1083 (setq other-col alt-col)
1084 (setq other (point)))))
1085 ;; Keep positions uptodate when we insert stuff.
1086 (if (> other file) (setq other (copy-marker other)))
1087 (setq file (copy-marker file))
1088 ;; Main loop.
1089 (goto-char beg)
87ae59e3 1090 (skip-chars-forward " ") ;Skip to the first field.
a12c6dca 1091 (while (and (> other-col file-col)
a12c6dca
SM
1092 ;; Don't touch anything just before (and after) the
1093 ;; beginning of the filename.
1094 (> file (point)))
1095 ;; We're now just in front of a field, with a space behind us.
1096 (let* ((curcol (current-column))
1097 ;; Nums are right-aligned.
cedf5c9d 1098 (num-align (looking-at-p "[0-9]"))
a12c6dca
SM
1099 ;; Let's look at the other line, in the same column: we
1100 ;; should be either near the end of the previous field, or
1101 ;; in the space between that field and the next.
1102 ;; [ Of course, it's also possible that we're already within
1103 ;; the next field or even past it, but that's unlikely since
1104 ;; other-col > file-col. ]
1105 ;; Let's find the distance to the alignment-point (either
1106 ;; the beginning or the end of the next field, depending on
1107 ;; whether this field is left or right aligned).
1108 (align-pt-offset
1109 (save-excursion
1110 (goto-char other)
1111 (move-to-column curcol)
1112 (when (looking-at
1113 (concat
ee680b2b 1114 (if (eq (char-before) ?\s) " *" "[^ ]* *")
a12c6dca
SM
1115 (if num-align "[0-9][^ ]*")))
1116 (- (match-end 0) (match-beginning 0)))))
1117 ;; Now, the number of spaces to insert is align-pt-offset
1118 ;; minus the distance to the equivalent point on the
1119 ;; current line.
1120 (spaces
1121 (if (not num-align)
1122 align-pt-offset
1123 (and align-pt-offset
1124 (save-excursion
1125 (skip-chars-forward "^ ")
1126 (- align-pt-offset (- (current-column) curcol)))))))
1127 (when (and spaces (> spaces 0))
1128 (setq file-col (+ spaces file-col))
1129 (if (> file-col other-col)
1130 (setq spaces (- spaces (- file-col other-col))))
1131 (insert-char ?\s spaces)
1132 ;; Let's just make really sure we did not mess up.
1133 (unless (save-excursion
87ae59e3 1134 (eq (dired-move-to-filename) (marker-position file)))
a12c6dca 1135 ;; Damn! We messed up: let's revert the change.
87ae59e3
SM
1136 (delete-char (- spaces)))))
1137 ;; Now skip to next field.
1138 (skip-chars-forward "^ ") (skip-chars-forward " "))
a12c6dca 1139 (set-marker file nil)))))
87ae59e3 1140
a12c6dca 1141
bc35ff32
EZ
1142(defvar ls-lisp-use-insert-directory-program)
1143
1498536e
GM
1144(defun dired-switches-escape-p (switches)
1145 "Return non-nil if the string SWITCHES contains -b or --escape."
1146 ;; Do not match things like "--block-size" that happen to contain "b".
cedf5c9d 1147 (string-match-p "\\(\\`\\| \\)-[[:alnum:]]*b\\|--escape\\>" switches))
1498536e 1148
0b7bc76f
RS
1149(defun dired-insert-directory (dir switches &optional file-list wildcard hdr)
1150 "Insert a directory listing of DIR, Dired style.
1151Use SWITCHES to make the listings.
1152If FILE-LIST is non-nil, list only those files.
1153Otherwise, if WILDCARD is non-nil, expand wildcards;
1154 in that case, DIR should be a file name that uses wildcards.
1155In other cases, DIR should be a directory name or a directory filename.
1156If HDR is non-nil, insert a header line with the directory name."
9888aa65 1157 (let ((opoint (point))
02b5d79c 1158 (process-environment (copy-sequence process-environment))
9888aa65 1159 end)
bc35ff32
EZ
1160 (if (and
1161 ;; Don't try to invoke `ls' if we are on DOS/Windows where
1162 ;; ls-lisp emulation is used, except if they want to use `ls'
1163 ;; as indicated by `ls-lisp-use-insert-directory-program'.
1164 (not (and (featurep 'ls-lisp)
1165 (null ls-lisp-use-insert-directory-program)))
1166 (or (if (eq dired-use-ls-dired 'unspecified)
1167 ;; Check whether "ls --dired" gives exit code 0, and
1168 ;; save the answer in `dired-use-ls-dired'.
6240145a
GM
1169 (or (setq dired-use-ls-dired
1170 (eq 0 (call-process insert-directory-program
1171 nil nil nil "--dired")))
1172 (progn
1173 (message "ls does not support --dired; \
1174see `dired-use-ls-dired' for more details.")
1175 nil))
bc35ff32
EZ
1176 dired-use-ls-dired)
1177 (file-remote-p dir)))
0b7bc76f 1178 (setq switches (concat "--dired " switches)))
6492483f
RS
1179 ;; We used to specify the C locale here, to force English month names;
1180 ;; but this should not be necessary any more,
9bc260cf 1181 ;; with the new value of `directory-listing-before-filename-regexp'.
0b7bc76f
RS
1182 (if file-list
1183 (dolist (f file-list)
a12c6dca
SM
1184 (let ((beg (point)))
1185 (insert-directory f switches nil nil)
1186 ;; Re-align fields, if necessary.
1187 (dired-align-file beg (point))))
0b7bc76f 1188 (insert-directory dir switches wildcard (not wildcard)))
9888aa65 1189 ;; Quote certain characters, unless ls quoted them for us.
1498536e 1190 (if (not (dired-switches-escape-p dired-actual-switches))
ad632492
SM
1191 (save-excursion
1192 (setq end (point-marker))
1193 (goto-char opoint)
1194 (while (search-forward "\\" end t)
2bb27597
AS
1195 (replace-match (apply #'propertize
1196 "\\\\"
1197 (text-properties-at (match-beginning 0)))
1198 nil t))
ad632492
SM
1199 (goto-char opoint)
1200 (while (search-forward "\^m" end t)
2bb27597
AS
1201 (replace-match (apply #'propertize
1202 "\\015"
1203 (text-properties-at (match-beginning 0)))
1204 nil t))
1db03b16
GM
1205 (set-marker end nil))
1206 ;; Replace any newlines in DIR with literal "\n"s, for the sake
1207 ;; of the header line. To disambiguate a literal "\n" in the
1208 ;; actual dirname, we also replace "\" with "\\".
1209 ;; Personally, I think this should always be done, irrespective
1210 ;; of the value of dired-actual-switches, because:
1211 ;; i) Dired simply does not work with an unescaped newline in
1212 ;; the directory name used in the header (bug=10469#28), and
1213 ;; ii) "\" is always replaced with "\\" in the listing, so doing
1214 ;; it in the header as well makes things consistent.
1215 ;; But at present it is only done if "-b" is in ls-switches,
1216 ;; because newlines in dirnames are uncommon, and people may
1217 ;; have gotten used to seeing unescaped "\" in the headers.
1218 ;; Note: adjust dired-build-subdir-alist if you change this.
1219 (setq dir (replace-regexp-in-string "\\\\" "\\\\" dir nil t)
1220 dir (replace-regexp-in-string "\n" "\\n" dir nil t)))
0b7bc76f
RS
1221 ;; If we used --dired and it worked, the lines are already indented.
1222 ;; Otherwise, indent them.
1223 (unless (save-excursion
1ba6c0f2 1224 (goto-char opoint)
cedf5c9d 1225 (looking-at-p " "))
0b7bc76f
RS
1226 (let ((indent-tabs-mode nil))
1227 (indent-rigidly opoint (point) 2)))
1228 ;; Insert text at the beginning to standardize things.
a2a538b1
CS
1229 (let ((content-point opoint))
1230 (save-excursion
1231 (goto-char opoint)
1232 (when (and (or hdr wildcard)
1d237bba 1233 (not (and (looking-at "^ \\(.*\\):$")
a2a538b1 1234 (file-name-absolute-p (match-string 1)))))
0b7bc76f
RS
1235 ;; Note that dired-build-subdir-alist will replace the name
1236 ;; by its expansion, so it does not matter whether what we insert
1237 ;; here is fully expanded, but it should be absolute.
a2a538b1
CS
1238 (insert " " (directory-file-name (file-name-directory dir)) ":\n")
1239 (setq content-point (point)))
1240 (when wildcard
1241 ;; Insert "wildcard" line where "total" line would be for a full dir.
1242 (insert " wildcard " (file-name-nondirectory dir) "\n")))
1243 (dired-insert-set-properties content-point (point)))))
492d2437 1244
cb88a3db 1245(defun dired-insert-set-properties (beg end)
7e9505c5 1246 "Add various text properties to the lines in the region."
cb88a3db
RS
1247 (save-excursion
1248 (goto-char beg)
1249 (while (< (point) end)
45fdb482
JB
1250 (ignore-errors
1251 (if (not (dired-move-to-filename))
1252 (put-text-property (line-beginning-position)
1253 (1+ (line-end-position))
1254 'invisible 'dired-hide-details-information)
1255 (put-text-property (+ (line-beginning-position) 1) (1- (point))
1256 'invisible 'dired-hide-details-detail)
1257 (add-text-properties
1258 (point)
1259 (progn
1260 (dired-move-to-end-of-filename)
1261 (point))
1262 '(mouse-face
1263 highlight
1264 dired-filename t
1265 help-echo "mouse-2: visit this file in other window"))
1266 (when (< (+ (point) 4) (line-end-position))
1267 (put-text-property (+ (point) 4) (line-end-position)
1268 'invisible 'dired-hide-details-link))))
cb88a3db 1269 (forward-line 1))))
83fadedf 1270\f
492d2437
RS
1271;; Reverting a dired buffer
1272
d032d5e7 1273(defun dired-revert (&optional _arg _noconfirm)
cedf5c9d 1274 "Reread the Dired buffer.
ee680b2b 1275Must also be called after `dired-actual-switches' have changed.
d7aed37c 1276Should not fail even on completely garbaged buffers.
b14f16ad
CY
1277Preserves old cursor, marks/flags, hidden-p.
1278
1279Dired sets `revert-buffer-function' to this function. The args
1280ARG and NOCONFIRM, passed from `revert-buffer', are ignored."
492d2437 1281 (widen) ; just in case user narrowed
7805cdbd 1282 (let ((modflag (buffer-modified-p))
05404988 1283 (positions (dired-save-positions))
492d2437
RS
1284 (mark-alist nil) ; save marked files
1285 (hidden-subdirs (dired-remember-hidden))
1286 (old-subdir-alist (cdr (reverse dired-subdir-alist))) ; except pwd
1287 (case-fold-search nil) ; we check for upper case ls flags
f836b98e 1288 (inhibit-read-only t))
492d2437
RS
1289 (goto-char (point-min))
1290 (setq mark-alist;; only after dired-remember-hidden since this unhides:
1291 (dired-remember-marks (point-min) (point-max)))
1292 ;; treat top level dir extra (it may contain wildcards)
d5b3979c
MA
1293 (if (not (consp dired-directory))
1294 (dired-uncache dired-directory)
1295 (dired-uncache (car dired-directory))
1296 (dolist (dir (cdr dired-directory))
1297 (if (file-name-absolute-p dir)
1298 (dired-uncache dir))))
6a80f50e 1299 ;; Run dired-after-readin-hook just once, below.
492d2437 1300 (let ((dired-after-readin-hook nil))
6a80f50e 1301 (dired-readin)
492d2437
RS
1302 (dired-insert-old-subdirs old-subdir-alist))
1303 (dired-mark-remembered mark-alist) ; mark files that were marked
1304 ;; ... run the hook for the whole buffer, and only after markers
1305 ;; have been reinserted (else omitting in dired-x would omit marked files)
1306 (run-hooks 'dired-after-readin-hook) ; no need to narrow
05404988 1307 (dired-restore-positions positions)
492d2437 1308 (save-excursion ; hide subdirs that were hidden
d7aed37c
SM
1309 (dolist (dir hidden-subdirs)
1310 (if (dired-goto-subdir dir)
7805cdbd
LT
1311 (dired-hide-subdir 1))))
1312 (unless modflag (restore-buffer-modified-p nil)))
492d2437 1313 ;; outside of the let scope
7805cdbd 1314;;; Might as well not override the user if the user changed this.
492d2437
RS
1315;;; (setq buffer-read-only t)
1316 )
1317
1318;; Subroutines of dired-revert
1319;; Some of these are also used when inserting subdirs.
1320
05404988 1321(defun dired-save-positions ()
065543e7
JL
1322 "Return current positions in the buffer and all windows with this directory.
1323The positions have the form (BUFFER-POSITION WINDOW-POSITIONS).
1324
cedf5c9d 1325BUFFER-POSITION is the point position in the current Dired buffer.
53ad04fc 1326It has the form (BUFFER DIRED-FILENAME BUFFER-POINT).
065543e7
JL
1327
1328WINDOW-POSITIONS are current positions in all windows displaying
1329this dired buffer. The window positions have the form (WINDOW
1330DIRED-FILENAME WINDOW-POINT)."
1331 (list
1332 (list (current-buffer) (dired-get-filename nil t) (point))
1333 (mapcar (lambda (w)
1334 (list w
1335 (with-selected-window w
1336 (dired-get-filename nil t))
1337 (window-point w)))
1338 (get-buffer-window-list nil 0 t))))
05404988
SM
1339
1340(defun dired-restore-positions (positions)
1341 "Restore POSITIONS saved with `dired-save-positions'."
065543e7
JL
1342 (let* ((buf-file-pos (nth 0 positions))
1343 (buffer (nth 0 buf-file-pos)))
1344 (unless (and (nth 1 buf-file-pos)
1345 (dired-goto-file (nth 1 buf-file-pos)))
1346 (goto-char (nth 2 buf-file-pos))
1347 (dired-move-to-filename))
1348 (dolist (win-file-pos (nth 1 positions))
1349 ;; Ensure that window still displays the original buffer.
1350 (when (eq (window-buffer (nth 0 win-file-pos)) buffer)
1351 (with-selected-window (nth 0 win-file-pos)
1352 (unless (and (nth 1 win-file-pos)
1353 (dired-goto-file (nth 1 win-file-pos)))
1354 (goto-char (nth 2 win-file-pos))
1355 (dired-move-to-filename)))))))
05404988 1356
492d2437 1357(defun dired-remember-marks (beg end)
d7aed37c 1358 "Return alist of files and their marks, from BEG to END."
492d2437 1359 (if selective-display ; must unhide to make this work.
f836b98e 1360 (let ((inhibit-read-only t))
492d2437
RS
1361 (subst-char-in-region beg end ?\r ?\n)))
1362 (let (fil chr alist)
1363 (save-excursion
1364 (goto-char beg)
1365 (while (re-search-forward dired-re-mark end t)
1366 (if (setq fil (dired-get-filename nil t))
1367 (setq chr (preceding-char)
1368 alist (cons (cons fil chr) alist)))))
1369 alist))
1370
492d2437 1371(defun dired-mark-remembered (alist)
d7aed37c
SM
1372 "Mark all files remembered in ALIST.
1373Each element of ALIST looks like (FILE . MARKERCHAR)."
492d2437 1374 (let (elt fil chr)
fbb6300b
MR
1375 (save-excursion
1376 (while alist
1377 (setq elt (car alist)
1378 alist (cdr alist)
1379 fil (car elt)
1380 chr (cdr elt))
1381 (when (dired-goto-file fil)
1382 (beginning-of-line)
1383 (delete-char 1)
1384 (insert chr))))))
492d2437 1385
492d2437 1386(defun dired-remember-hidden ()
d7aed37c 1387 "Return a list of names of subdirs currently hidden."
492d2437
RS
1388 (let ((l dired-subdir-alist) dir pos result)
1389 (while l
1390 (setq dir (car (car l))
1391 pos (cdr (car l))
1392 l (cdr l))
1393 (goto-char pos)
1394 (skip-chars-forward "^\r\n")
52041219 1395 (if (eq (following-char) ?\r)
492d2437
RS
1396 (setq result (cons dir result))))
1397 result))
1398
492d2437 1399(defun dired-insert-old-subdirs (old-subdir-alist)
d7aed37c
SM
1400 "Try to insert all subdirs that were displayed before.
1401Do so according to the former subdir alist OLD-SUBDIR-ALIST."
cedf5c9d 1402 (or (string-match-p "R" dired-actual-switches)
492d2437
RS
1403 (let (elt dir)
1404 (while old-subdir-alist
1405 (setq elt (car old-subdir-alist)
1406 old-subdir-alist (cdr old-subdir-alist)
1407 dir (car elt))
45fdb482
JB
1408 (ignore-errors
1409 (dired-uncache dir)
1410 (dired-insert-subdir dir))))))
715984d3 1411
715984d3 1412(defun dired-uncache (dir)
d7aed37c 1413 "Remove directory DIR from any directory cache."
6eaebaa2 1414 (let ((handler (find-file-name-handler dir 'dired-uncache)))
715984d3
RS
1415 (if handler
1416 (funcall handler 'dired-uncache dir))))
83fadedf 1417\f
492d2437 1418;; dired mode key bindings and initialization
84fc2cfa 1419
d7aed37c 1420(defvar dired-mode-map
492d2437
RS
1421 ;; This looks ugly when substitute-command-keys uses C-d instead d:
1422 ;; (define-key dired-mode-map "\C-d" 'dired-flag-file-deletion)
3e1fb00f 1423 (let ((map (make-keymap)))
abef340a 1424 (set-keymap-parent map special-mode-map)
3e1fb00f 1425 (define-key map [mouse-2] 'dired-mouse-find-file-other-window)
bb87fbc3 1426 (define-key map [follow-link] 'mouse-face)
3e1fb00f
RS
1427 ;; Commands to mark or flag certain categories of files
1428 (define-key map "#" 'dired-flag-auto-save-files)
3e1fb00f 1429 (define-key map "." 'dired-clean-directory)
3e1fb00f
RS
1430 (define-key map "~" 'dired-flag-backup-files)
1431 ;; Upper case keys (except !) for operating on the marked files
1432 (define-key map "A" 'dired-do-search)
1433 (define-key map "C" 'dired-do-copy)
1434 (define-key map "B" 'dired-do-byte-compile)
1435 (define-key map "D" 'dired-do-delete)
1436 (define-key map "G" 'dired-do-chgrp)
1437 (define-key map "H" 'dired-do-hardlink)
1438 (define-key map "L" 'dired-do-load)
1439 (define-key map "M" 'dired-do-chmod)
1440 (define-key map "O" 'dired-do-chown)
1441 (define-key map "P" 'dired-do-print)
ee93b692 1442 (define-key map "Q" 'dired-do-query-replace-regexp)
3e1fb00f
RS
1443 (define-key map "R" 'dired-do-rename)
1444 (define-key map "S" 'dired-do-symlink)
57654b8c 1445 (define-key map "T" 'dired-do-touch)
3e1fb00f
RS
1446 (define-key map "X" 'dired-do-shell-command)
1447 (define-key map "Z" 'dired-do-compress)
1448 (define-key map "!" 'dired-do-shell-command)
48e740bf 1449 (define-key map "&" 'dired-do-async-shell-command)
3e1fb00f
RS
1450 ;; Comparison commands
1451 (define-key map "=" 'dired-diff)
3e1fb00f
RS
1452 ;; Tree Dired commands
1453 (define-key map "\M-\C-?" 'dired-unmark-all-files)
1454 (define-key map "\M-\C-d" 'dired-tree-down)
1455 (define-key map "\M-\C-u" 'dired-tree-up)
1456 (define-key map "\M-\C-n" 'dired-next-subdir)
1457 (define-key map "\M-\C-p" 'dired-prev-subdir)
1458 ;; move to marked files
1459 (define-key map "\M-{" 'dired-prev-marked-file)
1460 (define-key map "\M-}" 'dired-next-marked-file)
1461 ;; Make all regexp commands share a `%' prefix:
1462 ;; We used to get to the submap via a symbol dired-regexp-prefix,
1463 ;; but that seems to serve little purpose, and copy-keymap
1464 ;; does a better job without it.
1465 (define-key map "%" nil)
1466 (define-key map "%u" 'dired-upcase)
1467 (define-key map "%l" 'dired-downcase)
1468 (define-key map "%d" 'dired-flag-files-regexp)
e9b8e22d 1469 (define-key map "%g" 'dired-mark-files-containing-regexp)
3e1fb00f
RS
1470 (define-key map "%m" 'dired-mark-files-regexp)
1471 (define-key map "%r" 'dired-do-rename-regexp)
1472 (define-key map "%C" 'dired-do-copy-regexp)
1473 (define-key map "%H" 'dired-do-hardlink-regexp)
1474 (define-key map "%R" 'dired-do-rename-regexp)
1475 (define-key map "%S" 'dired-do-symlink-regexp)
48e740bf 1476 (define-key map "%&" 'dired-flag-garbage-files)
4a3ca6ed
RS
1477 ;; Commands for marking and unmarking.
1478 (define-key map "*" nil)
1479 (define-key map "**" 'dired-mark-executables)
1480 (define-key map "*/" 'dired-mark-directories)
1481 (define-key map "*@" 'dired-mark-symlinks)
1482 (define-key map "*%" 'dired-mark-files-regexp)
1483 (define-key map "*c" 'dired-change-marks)
0609c998 1484 (define-key map "*s" 'dired-mark-subdir-files)
4a3ca6ed
RS
1485 (define-key map "*m" 'dired-mark)
1486 (define-key map "*u" 'dired-unmark)
1487 (define-key map "*?" 'dired-unmark-all-files)
534a6edf 1488 (define-key map "*!" 'dired-unmark-all-marks)
d7aed37c 1489 (define-key map "U" 'dired-unmark-all-marks)
4a3ca6ed
RS
1490 (define-key map "*\177" 'dired-unmark-backward)
1491 (define-key map "*\C-n" 'dired-next-marked-file)
1492 (define-key map "*\C-p" 'dired-prev-marked-file)
d588eb90 1493 (define-key map "*t" 'dired-toggle-marks)
3e1fb00f 1494 ;; Lower keys for commands not operating on all the marked files
c5753a5d 1495 (define-key map "a" 'dired-find-alternate-file)
3e1fb00f
RS
1496 (define-key map "d" 'dired-flag-file-deletion)
1497 (define-key map "e" 'dired-find-file)
1498 (define-key map "f" 'dired-find-file)
8cb95edf
SM
1499 (define-key map "\C-m" 'dired-find-file)
1500 (put 'dired-find-file :advertised-binding "\C-m")
3e1fb00f 1501 (define-key map "g" 'revert-buffer)
3e1fb00f 1502 (define-key map "i" 'dired-maybe-insert-subdir)
e19d2d64 1503 (define-key map "j" 'dired-goto-file)
3e1fb00f
RS
1504 (define-key map "k" 'dired-do-kill-lines)
1505 (define-key map "l" 'dired-do-redisplay)
1506 (define-key map "m" 'dired-mark)
1507 (define-key map "n" 'dired-next-line)
1508 (define-key map "o" 'dired-find-file-other-window)
1509 (define-key map "\C-o" 'dired-display-file)
1510 (define-key map "p" 'dired-previous-line)
3e1fb00f 1511 (define-key map "s" 'dired-sort-toggle-or-edit)
d588eb90 1512 (define-key map "t" 'dired-toggle-marks)
3e1fb00f
RS
1513 (define-key map "u" 'dired-unmark)
1514 (define-key map "v" 'dired-view-file)
a3f4a3ef 1515 (define-key map "w" 'dired-copy-filename-as-kill)
3e1fb00f 1516 (define-key map "x" 'dired-do-flagged-delete)
d1e99fa5 1517 (define-key map "y" 'dired-show-file-type)
3e1fb00f
RS
1518 (define-key map "+" 'dired-create-directory)
1519 ;; moving
1520 (define-key map "<" 'dired-prev-dirline)
1521 (define-key map ">" 'dired-next-dirline)
1522 (define-key map "^" 'dired-up-directory)
1523 (define-key map " " 'dired-next-line)
aac818a8
TL
1524 (define-key map [remap next-line] 'dired-next-line)
1525 (define-key map [remap previous-line] 'dired-previous-line)
3e1fb00f
RS
1526 ;; hiding
1527 (define-key map "$" 'dired-hide-subdir)
1528 (define-key map "\M-$" 'dired-hide-all)
a2a538b1 1529 (define-key map "(" 'dired-hide-details-mode)
b89b46cf
JL
1530 ;; isearch
1531 (define-key map (kbd "M-s a C-s") 'dired-do-isearch)
1532 (define-key map (kbd "M-s a M-C-s") 'dired-do-isearch-regexp)
eae2c85e
JL
1533 (define-key map (kbd "M-s f C-s") 'dired-isearch-filenames)
1534 (define-key map (kbd "M-s f M-C-s") 'dired-isearch-filenames-regexp)
3e1fb00f 1535 ;; misc
51c4474e
JL
1536 (define-key map [remap read-only-mode] 'dired-toggle-read-only)
1537 ;; `toggle-read-only' is an obsolete alias for `read-only-mode'
aac818a8 1538 (define-key map [remap toggle-read-only] 'dired-toggle-read-only)
3e1fb00f
RS
1539 (define-key map "?" 'dired-summary)
1540 (define-key map "\177" 'dired-unmark-backward)
5e5a3412
RS
1541 (define-key map [remap undo] 'dired-undo)
1542 (define-key map [remap advertised-undo] 'dired-undo)
aa1a7612
CY
1543 ;; thumbnail manipulation (image-dired)
1544 (define-key map "\C-td" 'image-dired-display-thumbs)
1545 (define-key map "\C-tt" 'image-dired-tag-files)
1546 (define-key map "\C-tr" 'image-dired-delete-tag)
1547 (define-key map "\C-tj" 'image-dired-jump-thumbnail-buffer)
1548 (define-key map "\C-ti" 'image-dired-dired-display-image)
1549 (define-key map "\C-tx" 'image-dired-dired-display-external)
1550 (define-key map "\C-ta" 'image-dired-display-thumbs-append)
1551 (define-key map "\C-t." 'image-dired-display-thumb)
1552 (define-key map "\C-tc" 'image-dired-dired-comment-files)
1553 (define-key map "\C-tf" 'image-dired-mark-tagged-files)
84fb0956 1554 (define-key map "\C-t\C-t" 'image-dired-dired-toggle-marked-thumbs)
aa1a7612 1555 (define-key map "\C-te" 'image-dired-dired-edit-comment-and-tags)
bfeee9d1
DN
1556 ;; encryption and decryption (epa-dired)
1557 (define-key map ":d" 'epa-dired-do-decrypt)
1558 (define-key map ":v" 'epa-dired-do-verify)
1559 (define-key map ":s" 'epa-dired-do-sign)
1560 (define-key map ":e" 'epa-dired-do-encrypt)
3e1fb00f
RS
1561
1562 ;; Make menu bar items.
1563
d066de8e
EZ
1564 ;; No need to fo this, now that top-level items are fewer.
1565 ;;;;
3e1fb00f 1566 ;; Get rid of the Edit menu bar item to save space.
d066de8e 1567 ;(define-key map [menu-bar edit] 'undefined)
3e1fb00f
RS
1568
1569 (define-key map [menu-bar subdir]
1570 (cons "Subdir" (make-sparse-keymap "Subdir")))
1571
1572 (define-key map [menu-bar subdir hide-all]
d066de8e
EZ
1573 '(menu-item "Hide All" dired-hide-all
1574 :help "Hide all subdirectories, leave only header lines"))
3e1fb00f 1575 (define-key map [menu-bar subdir hide-subdir]
d066de8e
EZ
1576 '(menu-item "Hide/UnHide Subdir" dired-hide-subdir
1577 :help "Hide or unhide current directory listing"))
3e1fb00f 1578 (define-key map [menu-bar subdir tree-down]
d066de8e
EZ
1579 '(menu-item "Tree Down" dired-tree-down
1580 :help "Go to first subdirectory header down the tree"))
3e1fb00f 1581 (define-key map [menu-bar subdir tree-up]
d066de8e
EZ
1582 '(menu-item "Tree Up" dired-tree-up
1583 :help "Go to first subdirectory header up the tree"))
3e1fb00f 1584 (define-key map [menu-bar subdir up]
d066de8e
EZ
1585 '(menu-item "Up Directory" dired-up-directory
1586 :help "Edit the parent directory"))
3e1fb00f 1587 (define-key map [menu-bar subdir prev-subdir]
d066de8e
EZ
1588 '(menu-item "Prev Subdir" dired-prev-subdir
1589 :help "Go to previous subdirectory header line"))
3e1fb00f 1590 (define-key map [menu-bar subdir next-subdir]
d066de8e
EZ
1591 '(menu-item "Next Subdir" dired-next-subdir
1592 :help "Go to next subdirectory header line"))
3e1fb00f 1593 (define-key map [menu-bar subdir prev-dirline]
d066de8e
EZ
1594 '(menu-item "Prev Dirline" dired-prev-dirline
1595 :help "Move to next directory-file line"))
3e1fb00f 1596 (define-key map [menu-bar subdir next-dirline]
d066de8e
EZ
1597 '(menu-item "Next Dirline" dired-next-dirline
1598 :help "Move to previous directory-file line"))
3e1fb00f 1599 (define-key map [menu-bar subdir insert]
d066de8e 1600 '(menu-item "Insert This Subdir" dired-maybe-insert-subdir
bedd8a58
CY
1601 :help "Insert contents of subdirectory"
1602 :enable (let ((f (dired-get-filename nil t)))
1603 (and f (file-directory-p f)))))
3e1fb00f
RS
1604 (define-key map [menu-bar immediate]
1605 (cons "Immediate" (make-sparse-keymap "Immediate")))
1606
635abd82 1607 (define-key map
aa1a7612
CY
1608 [menu-bar immediate image-dired-dired-display-external]
1609 '(menu-item "Display Image Externally" image-dired-dired-display-external
bc4dbed5 1610 :help "Display image in external viewer"))
635abd82 1611 (define-key map
aa1a7612
CY
1612 [menu-bar immediate image-dired-dired-display-image]
1613 '(menu-item "Display Image" image-dired-dired-display-image
bc4dbed5 1614 :help "Display sized image in a separate window"))
7cc6e154
JL
1615 (define-key map
1616 [menu-bar immediate image-dired-dired-toggle-marked-thumbs]
1617 '(menu-item "Toggle Image Thumbnails in This Buffer" image-dired-dired-toggle-marked-thumbs
1618 :help "Add or remove image thumbnails in front of marked file names"))
36938994 1619
a2a538b1
CS
1620 (define-key map [menu-bar immediate hide-details]
1621 '(menu-item "Hide Details" dired-hide-details-mode
1622 :help "Hide details in buffer"
1623 :button (:toggle . dired-hide-details-mode)))
836788c9
MD
1624 (define-key map [menu-bar immediate revert-buffer]
1625 '(menu-item "Refresh" revert-buffer
1626 :help "Update contents of shown directories"))
1627
1628 (define-key map [menu-bar immediate dashes]
1629 '("--"))
635abd82 1630
eae2c85e
JL
1631 (define-key map [menu-bar immediate isearch-filenames-regexp]
1632 '(menu-item "Isearch Regexp in File Names..." dired-isearch-filenames-regexp
1633 :help "Incrementally search for regexp in file names only"))
1634 (define-key map [menu-bar immediate isearch-filenames]
1635 '(menu-item "Isearch in File Names..." dired-isearch-filenames
1636 :help "Incrementally search for string in file names only."))
0e2aaf98 1637 (define-key map [menu-bar immediate compare-directories]
27af5d58 1638 '(menu-item "Compare Directories..." dired-compare-directories
cedf5c9d 1639 :help "Mark files with different attributes in two Dired buffers"))
3e1fb00f 1640 (define-key map [menu-bar immediate backup-diff]
d066de8e
EZ
1641 '(menu-item "Compare with Backup" dired-backup-diff
1642 :help "Diff file at cursor with its latest backup"))
3e1fb00f 1643 (define-key map [menu-bar immediate diff]
d066de8e
EZ
1644 '(menu-item "Diff..." dired-diff
1645 :help "Compare file at cursor with another file"))
3e1fb00f 1646 (define-key map [menu-bar immediate view]
d066de8e
EZ
1647 '(menu-item "View This File" dired-view-file
1648 :help "Examine file at cursor in read-only mode"))
3e1fb00f 1649 (define-key map [menu-bar immediate display]
d066de8e
EZ
1650 '(menu-item "Display in Other Window" dired-display-file
1651 :help "Display file at cursor in other window"))
3e1fb00f 1652 (define-key map [menu-bar immediate find-file-other-window]
d066de8e
EZ
1653 '(menu-item "Find in Other Window" dired-find-file-other-window
1654 :help "Edit file at cursor in other window"))
3e1fb00f 1655 (define-key map [menu-bar immediate find-file]
d066de8e
EZ
1656 '(menu-item "Find This File" dired-find-file
1657 :help "Edit file at cursor"))
3e1fb00f 1658 (define-key map [menu-bar immediate create-directory]
4b33a64a
DN
1659 '(menu-item "Create Directory..." dired-create-directory
1660 :help "Create a directory"))
2ecab840 1661 (define-key map [menu-bar immediate wdired-mode]
40aa8257 1662 '(menu-item "Edit File Names" wdired-change-to-wdired-mode
cedf5c9d 1663 :help "Put a Dired buffer in a mode in which filenames are editable"
89e87059 1664 :keys "C-x C-q"
40aa8257 1665 :filter (lambda (x) (if (eq major-mode 'dired-mode) x))))
3e1fb00f
RS
1666
1667 (define-key map [menu-bar regexp]
1668 (cons "Regexp" (make-sparse-keymap "Regexp")))
1669
836788c9 1670 (define-key map
aa1a7612
CY
1671 [menu-bar regexp image-dired-mark-tagged-files]
1672 '(menu-item "Mark From Image Tag..." image-dired-mark-tagged-files
098bab71
JB
1673 :help "Mark files whose image tags matches regexp"))
1674
836788c9 1675 (define-key map [menu-bar regexp dashes-1]
098bab71 1676 '("--"))
836788c9 1677
3e1fb00f 1678 (define-key map [menu-bar regexp downcase]
d066de8e
EZ
1679 '(menu-item "Downcase" dired-downcase
1680 ;; When running on plain MS-DOS, there's only one
1681 ;; letter-case for file names.
1682 :enable (or (not (fboundp 'msdos-long-file-names))
1683 (msdos-long-file-names))
1684 :help "Rename marked files to lower-case name"))
3e1fb00f 1685 (define-key map [menu-bar regexp upcase]
d066de8e
EZ
1686 '(menu-item "Upcase" dired-upcase
1687 :enable (or (not (fboundp 'msdos-long-file-names))
1688 (msdos-long-file-names))
1689 :help "Rename marked files to upper-case name"))
3e1fb00f 1690 (define-key map [menu-bar regexp hardlink]
d066de8e
EZ
1691 '(menu-item "Hardlink..." dired-do-hardlink-regexp
1692 :help "Make hard links for files matching regexp"))
3e1fb00f 1693 (define-key map [menu-bar regexp symlink]
d066de8e
EZ
1694 '(menu-item "Symlink..." dired-do-symlink-regexp
1695 :visible (fboundp 'make-symbolic-link)
1696 :help "Make symbolic links for files matching regexp"))
3e1fb00f 1697 (define-key map [menu-bar regexp rename]
d066de8e
EZ
1698 '(menu-item "Rename..." dired-do-rename-regexp
1699 :help "Rename marked files matching regexp"))
3e1fb00f 1700 (define-key map [menu-bar regexp copy]
d066de8e
EZ
1701 '(menu-item "Copy..." dired-do-copy-regexp
1702 :help "Copy marked files matching regexp"))
3e1fb00f 1703 (define-key map [menu-bar regexp flag]
d066de8e
EZ
1704 '(menu-item "Flag..." dired-flag-files-regexp
1705 :help "Flag files matching regexp for deletion"))
3e1fb00f 1706 (define-key map [menu-bar regexp mark]
d066de8e
EZ
1707 '(menu-item "Mark..." dired-mark-files-regexp
1708 :help "Mark files matching regexp for future operations"))
aa924deb 1709 (define-key map [menu-bar regexp mark-cont]
d066de8e
EZ
1710 '(menu-item "Mark Containing..." dired-mark-files-containing-regexp
1711 :help "Mark files whose contents matches regexp"))
3e1fb00f
RS
1712
1713 (define-key map [menu-bar mark]
1714 (cons "Mark" (make-sparse-keymap "Mark")))
1715
1716 (define-key map [menu-bar mark prev]
d066de8e
EZ
1717 '(menu-item "Previous Marked" dired-prev-marked-file
1718 :help "Move to previous marked file"))
3e1fb00f 1719 (define-key map [menu-bar mark next]
d066de8e
EZ
1720 '(menu-item "Next Marked" dired-next-marked-file
1721 :help "Move to next marked file"))
3e1fb00f 1722 (define-key map [menu-bar mark marks]
d066de8e
EZ
1723 '(menu-item "Change Marks..." dired-change-marks
1724 :help "Replace marker with another character"))
3e1fb00f 1725 (define-key map [menu-bar mark unmark-all]
d066de8e 1726 '(menu-item "Unmark All" dired-unmark-all-marks))
3e1fb00f 1727 (define-key map [menu-bar mark symlinks]
d066de8e
EZ
1728 '(menu-item "Mark Symlinks" dired-mark-symlinks
1729 :visible (fboundp 'make-symbolic-link)
1730 :help "Mark all symbolic links"))
3e1fb00f 1731 (define-key map [menu-bar mark directories]
d066de8e
EZ
1732 '(menu-item "Mark Directories" dired-mark-directories
1733 :help "Mark all directories except `.' and `..'"))
3e1fb00f 1734 (define-key map [menu-bar mark directory]
d066de8e
EZ
1735 '(menu-item "Mark Old Backups" dired-clean-directory
1736 :help "Flag old numbered backups for deletion"))
3e1fb00f 1737 (define-key map [menu-bar mark executables]
d066de8e
EZ
1738 '(menu-item "Mark Executables" dired-mark-executables
1739 :help "Mark all executable files"))
84d3f6e8 1740 (define-key map [menu-bar mark garbage-files]
d066de8e
EZ
1741 '(menu-item "Flag Garbage Files" dired-flag-garbage-files
1742 :help "Flag unneeded files for deletion"))
3e1fb00f 1743 (define-key map [menu-bar mark backup-files]
d066de8e
EZ
1744 '(menu-item "Flag Backup Files" dired-flag-backup-files
1745 :help "Flag all backup files for deletion"))
3e1fb00f 1746 (define-key map [menu-bar mark auto-save-files]
d066de8e
EZ
1747 '(menu-item "Flag Auto-save Files" dired-flag-auto-save-files
1748 :help "Flag auto-save files for deletion"))
3e1fb00f 1749 (define-key map [menu-bar mark deletion]
d066de8e
EZ
1750 '(menu-item "Flag" dired-flag-file-deletion
1751 :help "Flag current line's file for deletion"))
3e1fb00f 1752 (define-key map [menu-bar mark unmark]
d066de8e
EZ
1753 '(menu-item "Unmark" dired-unmark
1754 :help "Unmark or unflag current line's file"))
3e1fb00f 1755 (define-key map [menu-bar mark mark]
d066de8e
EZ
1756 '(menu-item "Mark" dired-mark
1757 :help "Mark current line's file for future operations"))
e5f0841e 1758 (define-key map [menu-bar mark toggle-marks]
d588eb90 1759 '(menu-item "Toggle Marks" dired-toggle-marks
d066de8e 1760 :help "Mark unmarked files, unmark marked ones"))
3e1fb00f
RS
1761
1762 (define-key map [menu-bar operate]
1763 (cons "Operate" (make-sparse-keymap "Operate")))
1764
836788c9 1765 (define-key map
aa1a7612
CY
1766 [menu-bar operate image-dired-delete-tag]
1767 '(menu-item "Delete Image Tag..." image-dired-delete-tag
b305952d 1768 :help "Delete image tag from current or marked files"))
836788c9 1769 (define-key map
aa1a7612
CY
1770 [menu-bar operate image-dired-tag-files]
1771 '(menu-item "Add Image Tags..." image-dired-tag-files
836788c9
MD
1772 :help "Add image tags to current or marked files"))
1773 (define-key map
aa1a7612
CY
1774 [menu-bar operate image-dired-dired-comment-files]
1775 '(menu-item "Add Image Comment..." image-dired-dired-comment-files
836788c9
MD
1776 :help "Add image comment to current or marked files"))
1777 (define-key map
aa1a7612 1778 [menu-bar operate image-dired-display-thumbs]
7cc6e154 1779 '(menu-item "Display Image Thumbnails" image-dired-display-thumbs
a41925a2 1780 :help "Display image thumbnails for current or marked image files"))
098bab71 1781
7cce3c91
CY
1782 (define-key map [menu-bar operate dashes-4]
1783 '("--"))
1784
1785 (define-key map
1786 [menu-bar operate epa-dired-do-decrypt]
af7dda05 1787 '(menu-item "Decrypt..." epa-dired-do-decrypt
7cce3c91
CY
1788 :help "Decrypt file at cursor"))
1789
1790 (define-key map
1791 [menu-bar operate epa-dired-do-verify]
1792 '(menu-item "Verify" epa-dired-do-verify
1793 :help "Verify digital signature of file at cursor"))
1794
1795 (define-key map
1796 [menu-bar operate epa-dired-do-sign]
af7dda05 1797 '(menu-item "Sign..." epa-dired-do-sign
7cce3c91
CY
1798 :help "Create digital signature of file at cursor"))
1799
1800 (define-key map
1801 [menu-bar operate epa-dired-do-encrypt]
af7dda05 1802 '(menu-item "Encrypt..." epa-dired-do-encrypt
7cce3c91
CY
1803 :help "Encrypt file at cursor"))
1804
836788c9 1805 (define-key map [menu-bar operate dashes-3]
098bab71 1806 '("--"))
836788c9 1807
3e1fb00f 1808 (define-key map [menu-bar operate query-replace]
ee93b692 1809 '(menu-item "Query Replace in Files..." dired-do-query-replace-regexp
d066de8e 1810 :help "Replace regexp in marked files"))
3e1fb00f 1811 (define-key map [menu-bar operate search]
d066de8e
EZ
1812 '(menu-item "Search Files..." dired-do-search
1813 :help "Search marked files for regexp"))
b89b46cf
JL
1814 (define-key map [menu-bar operate isearch-regexp]
1815 '(menu-item "Isearch Regexp Files..." dired-do-isearch-regexp
1816 :help "Incrementally search marked files for regexp"))
1817 (define-key map [menu-bar operate isearch]
1818 '(menu-item "Isearch Files..." dired-do-isearch
1819 :help "Incrementally search marked files for string"))
3e1fb00f 1820 (define-key map [menu-bar operate chown]
d066de8e
EZ
1821 '(menu-item "Change Owner..." dired-do-chown
1822 :visible (not (memq system-type '(ms-dos windows-nt)))
1823 :help "Change the owner of marked files"))
3e1fb00f 1824 (define-key map [menu-bar operate chgrp]
d066de8e
EZ
1825 '(menu-item "Change Group..." dired-do-chgrp
1826 :visible (not (memq system-type '(ms-dos windows-nt)))
1827 :help "Change the group of marked files"))
3e1fb00f 1828 (define-key map [menu-bar operate chmod]
d066de8e
EZ
1829 '(menu-item "Change Mode..." dired-do-chmod
1830 :help "Change mode (attributes) of marked files"))
57654b8c
JL
1831 (define-key map [menu-bar operate touch]
1832 '(menu-item "Change Timestamp..." dired-do-touch
1833 :help "Change timestamp of marked files"))
3e1fb00f 1834 (define-key map [menu-bar operate load]
d066de8e
EZ
1835 '(menu-item "Load" dired-do-load
1836 :help "Load marked Emacs Lisp files"))
3e1fb00f 1837 (define-key map [menu-bar operate compile]
d066de8e
EZ
1838 '(menu-item "Byte-compile" dired-do-byte-compile
1839 :help "Byte-compile marked Emacs Lisp files"))
3e1fb00f 1840 (define-key map [menu-bar operate compress]
d066de8e
EZ
1841 '(menu-item "Compress" dired-do-compress
1842 :help "Compress/uncompress marked files"))
3e1fb00f 1843 (define-key map [menu-bar operate print]
d066de8e
EZ
1844 '(menu-item "Print..." dired-do-print
1845 :help "Ask for print command and print marked files"))
3e1fb00f 1846 (define-key map [menu-bar operate hardlink]
d066de8e
EZ
1847 '(menu-item "Hardlink to..." dired-do-hardlink
1848 :help "Make hard links for current or marked files"))
3e1fb00f 1849 (define-key map [menu-bar operate symlink]
d066de8e
EZ
1850 '(menu-item "Symlink to..." dired-do-symlink
1851 :visible (fboundp 'make-symbolic-link)
1852 :help "Make symbolic links for current or marked files"))
077bf69b
GM
1853 (define-key map [menu-bar operate async-command]
1854 '(menu-item "Asynchronous Shell Command..." dired-do-async-shell-command
1855 :help "Run a shell command asynchronously on current or marked files"))
3e1fb00f 1856 (define-key map [menu-bar operate command]
d066de8e 1857 '(menu-item "Shell Command..." dired-do-shell-command
077bf69b 1858 :help "Run a shell command on current or marked files"))
3e1fb00f 1859 (define-key map [menu-bar operate delete]
d066de8e
EZ
1860 '(menu-item "Delete" dired-do-delete
1861 :help "Delete current file or all marked files"))
3e1fb00f 1862 (define-key map [menu-bar operate rename]
d066de8e
EZ
1863 '(menu-item "Rename to..." dired-do-rename
1864 :help "Rename current file or move marked files"))
3e1fb00f 1865 (define-key map [menu-bar operate copy]
d066de8e
EZ
1866 '(menu-item "Copy to..." dired-do-copy
1867 :help "Copy current file or all marked files"))
3e1fb00f 1868
d7aed37c 1869 map)
cedf5c9d 1870 "Local keymap for Dired mode buffers.")
83fadedf 1871\f
84fc2cfa
ER
1872;; Dired mode is suitable only for specially formatted data.
1873(put 'dired-mode 'mode-class 'special)
1874
a515788d
LH
1875;; Autoload cookie needed by desktop.el
1876;;;###autoload
492d2437
RS
1877(defun dired-mode (&optional dirname switches)
1878 "\
1879Mode for \"editing\" directory listings.
68d2f12f 1880In Dired, you are \"editing\" a list of the files in a directory and
cedf5c9d 1881 (optionally) its subdirectories, in the format of `ls -lR'.
492d2437
RS
1882 Each directory is a page: use \\[backward-page] and \\[forward-page] to move pagewise.
1883\"Editing\" means that you can run shell commands on files, visit,
1884 compress, load or byte-compile them, change their file attributes
1885 and insert subdirectories into the same buffer. You can \"mark\"
1886 files for later commands or \"flag\" them for deletion, either file
1887 by file or all files matching certain criteria.
1888You can move using the usual cursor motion commands.\\<dired-mode-map>
191e2bed
LMI
1889The buffer is read-only. Digits are prefix arguments.
1890Type \\[dired-flag-file-deletion] to flag a file `D' for deletion.
492d2437
RS
1891Type \\[dired-mark] to Mark a file or subdirectory for later commands.
1892 Most commands operate on the marked files and use the current file
1893 if no files are marked. Use a numeric prefix argument to operate on
1894 the next ARG (or previous -ARG if ARG<0) files, or just `1'
1895 to operate on the current file only. Prefix arguments override marks.
1896 Mark-using commands display a list of failures afterwards. Type \\[dired-summary]
1897 to see why something went wrong.
191e2bed 1898Type \\[dired-unmark] to Unmark a file or all files of an inserted subdirectory.
a48868a7 1899Type \\[dired-unmark-backward] to back up one line and unmark or unflag.
191e2bed 1900Type \\[dired-do-flagged-delete] to delete (eXecute) the files flagged `D'.
8cb95edf 1901Type \\[dired-find-file] to Find the current line's file
492d2437 1902 (or dired it in another buffer, if it is a directory).
cedf5c9d 1903Type \\[dired-find-file-other-window] to find file or Dired directory in Other window.
492d2437
RS
1904Type \\[dired-maybe-insert-subdir] to Insert a subdirectory in this buffer.
1905Type \\[dired-do-rename] to Rename a file or move the marked files to another directory.
1906Type \\[dired-do-copy] to Copy files.
ee680b2b
JB
1907Type \\[dired-sort-toggle-or-edit] to toggle Sorting by name/date or change the `ls' switches.
1908Type \\[revert-buffer] to read all currently expanded directories aGain.
492d2437 1909 This retains all marks and hides subdirs again that were hidden before.
191e2bed 1910Use `SPC' and `DEL' to move down and up by lines.
492d2437 1911
ee680b2b 1912If Dired ever gets confused, you can either type \\[revert-buffer] \
492d2437
RS
1913to read the
1914directories again, type \\[dired-do-redisplay] \
191e2bed 1915to relist the file at point or the marked files or a
492d2437
RS
1916subdirectory, or type \\[dired-build-subdir-alist] to parse the buffer
1917again for the directory tree.
1918
1919Customization variables (rename this buffer and type \\[describe-variable] on each line
1920for more info):
1921
87ae59e3
SM
1922 `dired-listing-switches'
1923 `dired-trivial-filenames'
87ae59e3
SM
1924 `dired-marker-char'
1925 `dired-del-marker'
1926 `dired-keep-marker-rename'
1927 `dired-keep-marker-copy'
1928 `dired-keep-marker-hardlink'
1929 `dired-keep-marker-symlink'
492d2437
RS
1930
1931Hooks (use \\[describe-variable] to see their documentation):
1932
87ae59e3
SM
1933 `dired-before-readin-hook'
1934 `dired-after-readin-hook'
1935 `dired-mode-hook'
1936 `dired-load-hook'
492d2437
RS
1937
1938Keybindings:
84fc2cfa 1939\\{dired-mode-map}"
492d2437
RS
1940 ;; Not to be called interactively (e.g. dired-directory will be set
1941 ;; to default-directory, which is wrong with wildcards).
84fc2cfa 1942 (kill-all-local-variables)
84fc2cfa 1943 (use-local-map dired-mode-map)
492d2437
RS
1944 (dired-advertise) ; default-directory is already set
1945 (setq major-mode 'dired-mode
1946 mode-name "Dired"
87ae59e3 1947 ;; case-fold-search nil
492d2437
RS
1948 buffer-read-only t
1949 selective-display t ; for subdirectory hiding
0acdf642
GM
1950 mode-line-buffer-identification
1951 (propertized-buffer-identification "%17b"))
a2a538b1
CS
1952 ;; Ignore dired-hide-details-* value of invisible text property by default.
1953 (when (eq buffer-invisibility-spec t)
1954 (setq buffer-invisibility-spec (list t)))
cedf5c9d
JB
1955 (setq-local revert-buffer-function (function dired-revert))
1956 (setq-local buffer-stale-function (function dired-buffer-stale-p))
1957 (setq-local page-delimiter "\n\n")
1958 (setq-local dired-directory (or dirname default-directory))
492d2437 1959 ;; list-buffers uses this to display the dir being edited in this buffer.
11ee8d90
JB
1960 (setq list-buffers-directory
1961 (expand-file-name (if (listp dired-directory)
1962 (car dired-directory)
1963 dired-directory)))
cedf5c9d
JB
1964 (setq-local dired-actual-switches (or switches dired-listing-switches))
1965 (setq-local font-lock-defaults
1966 '(dired-font-lock-keywords t nil nil beginning-of-line))
1967 (setq-local desktop-save-buffer 'dired-desktop-buffer-misc-data)
5553077c 1968 (setq dired-switches-alist nil)
817b48a7 1969 (hack-dir-local-variables-non-file-buffer) ; before sorting
492d2437 1970 (dired-sort-other dired-actual-switches t)
361eee8f 1971 (when (featurep 'dnd)
cedf5c9d
JB
1972 (setq-local dnd-protocol-alist
1973 (append dired-dnd-protocol-alist dnd-protocol-alist)))
7d371eac 1974 (add-hook 'file-name-at-point-functions 'dired-file-name-at-point nil t)
eae2c85e 1975 (add-hook 'isearch-mode-hook 'dired-isearch-filenames-setup nil t)
1ed8284d 1976 (run-mode-hooks 'dired-mode-hook))
83fadedf 1977\f
eb8c3be9 1978;; Idiosyncratic dired commands that don't deal with marks.
84fc2cfa 1979
84fc2cfa 1980(defun dired-summary ()
cedf5c9d 1981 "Summarize basic Dired commands and show recent Dired errors."
84fc2cfa 1982 (interactive)
492d2437 1983 (dired-why)
84fc2cfa
ER
1984 ;>> this should check the key-bindings and use substitute-command-keys if non-standard
1985 (message
50f74744 1986 "d-elete, u-ndelete, x-punge, f-ind, o-ther window, R-ename, C-opy, h-elp"))
84fc2cfa 1987
492d2437 1988(defun dired-undo ()
cedf5c9d 1989 "Undo in a Dired buffer.
492d2437 1990This doesn't recover lost files, it just undoes changes in the buffer itself.
487327a9 1991You can use it to recover marks, killed lines or subdirs."
492d2437 1992 (interactive)
f836b98e 1993 (let ((inhibit-read-only t))
487327a9
LT
1994 (undo))
1995 (dired-build-subdir-alist)
cedf5c9d 1996 (message "Change in Dired buffer undone.
487327a9 1997Actual changes in files cannot be undone by Emacs."))
84fc2cfa 1998
40aa8257 1999(defun dired-toggle-read-only ()
b68b3337
CY
2000 "Edit Dired buffer with Wdired, or make it read-only.
2001If the current buffer can be edited with Wdired, (i.e. the major
2002mode is `dired-mode'), call `wdired-change-to-wdired-mode'.
2003Otherwise, call `toggle-read-only'."
40aa8257 2004 (interactive)
ba10c48c 2005 (if (derived-mode-p 'dired-mode)
40aa8257 2006 (wdired-change-to-wdired-mode)
9a930676 2007 (read-only-mode 'toggle)))
40aa8257 2008
84fc2cfa
ER
2009(defun dired-next-line (arg)
2010 "Move down lines then position at filename.
2011Optional prefix ARG says how many lines to move; default is one line."
2012 (interactive "p")
a2a538b1
CS
2013 (let ((line-move-visual)
2014 (goal-column))
2015 (line-move arg t))
2016 ;; We never want to move point into an invisible line.
2017 (while (and (invisible-p (point))
2018 (not (if (and arg (< arg 0)) (bobp) (eobp))))
2019 (forward-char (if (and arg (< arg 0)) -1 1)))
84fc2cfa
ER
2020 (dired-move-to-filename))
2021
2022(defun dired-previous-line (arg)
2023 "Move up lines then position at filename.
2024Optional prefix ARG says how many lines to move; default is one line."
2025 (interactive "p")
a2a538b1 2026 (dired-next-line (- (or arg 1))))
84fc2cfa 2027
492d2437 2028(defun dired-next-dirline (arg &optional opoint)
cedf5c9d 2029 "Goto ARGth next directory file line."
492d2437
RS
2030 (interactive "p")
2031 (or opoint (setq opoint (point)))
2032 (if (if (> arg 0)
2033 (re-search-forward dired-re-dir nil t arg)
2034 (beginning-of-line)
2035 (re-search-backward dired-re-dir nil t (- arg)))
2036 (dired-move-to-filename) ; user may type `i' or `f'
2037 (goto-char opoint)
2038 (error "No more subdirectories")))
2039
2040(defun dired-prev-dirline (arg)
cedf5c9d 2041 "Goto ARGth previous directory file line."
492d2437
RS
2042 (interactive "p")
2043 (dired-next-dirline (- arg)))
2044
ac1ce341 2045(defun dired-up-directory (&optional other-window)
68d2f12f 2046 "Run Dired on parent directory of current directory.
492d2437
RS
2047Find the parent directory either in this buffer or another buffer.
2048Creates a buffer if necessary."
ac1ce341 2049 (interactive "P")
492d2437
RS
2050 (let* ((dir (dired-current-directory))
2051 (up (file-name-directory (directory-file-name dir))))
2052 (or (dired-goto-file (directory-file-name dir))
7b2469ae
RS
2053 ;; Only try dired-goto-subdir if buffer has more than one dir.
2054 (and (cdr dired-subdir-alist)
492d2437
RS
2055 (dired-goto-subdir up))
2056 (progn
ac1ce341
EN
2057 (if other-window
2058 (dired-other-window up)
2059 (dired up))
492d2437 2060 (dired-goto-file dir)))))
84fc2cfa 2061
68d2f12f
RS
2062(defun dired-get-file-for-visit ()
2063 "Get the current line's file name, with an error if file does not exist."
53fd9d05 2064 (interactive)
e9407052
RS
2065 ;; We pass t for second arg so that we don't get error for `.' and `..'.
2066 (let ((raw (dired-get-filename nil t))
2067 file-name)
2068 (if (null raw)
2069 (error "No file on this line"))
2070 (setq file-name (file-name-sans-versions raw t))
c439687b 2071 (if (file-exists-p file-name)
68d2f12f 2072 file-name
55642aa4
RS
2073 (if (file-symlink-p file-name)
2074 (error "File is a symlink to a nonexistent target")
cedf5c9d 2075 (error "File no longer exists; type `g' to update Dired buffer")))))
84fc2cfa 2076
f143d380 2077;; Force C-m keybinding rather than `f' or `e' in the mode doc:
8cb95edf 2078(define-obsolete-function-alias 'dired-advertised-find-file 'dired-find-file "23.2")
68d2f12f
RS
2079(defun dired-find-file ()
2080 "In Dired, visit the file or directory named on this line."
2081 (interactive)
1d5ad120 2082 ;; Bind `find-file-run-dired' so that the command works on directories
59d18288
RS
2083 ;; too, independent of the user's setting.
2084 (let ((find-file-run-dired t))
2085 (find-file (dired-get-file-for-visit))))
68d2f12f 2086
c5753a5d 2087(defun dired-find-alternate-file ()
cedf5c9d 2088 "In Dired, visit this file or directory instead of the Dired buffer."
c5753a5d
GM
2089 (interactive)
2090 (set-buffer-modified-p nil)
68d2f12f 2091 (find-alternate-file (dired-get-file-for-visit)))
336cd99d 2092;; Don't override the setting from .emacs.
c21993d0 2093;;;###autoload (put 'dired-find-alternate-file 'disabled t)
c5753a5d 2094
dbcb9389 2095(defun dired-mouse-find-file-other-window (event)
68d2f12f 2096 "In Dired, visit the file or directory name you click on."
dbcb9389 2097 (interactive "e")
2aaa7f0a 2098 (let (window pos file)
dbcb9389 2099 (save-excursion
2aaa7f0a
RS
2100 (setq window (posn-window (event-end event))
2101 pos (posn-point (event-end event)))
2102 (if (not (windowp window))
2103 (error "No file chosen"))
2104 (set-buffer (window-buffer window))
2105 (goto-char pos)
2106 (setq file (dired-get-file-for-visit)))
55a87770
RS
2107 (if (file-directory-p file)
2108 (or (and (cdr dired-subdir-alist)
2109 (dired-goto-subdir file))
2110 (progn
2111 (select-window window)
2112 (dired-other-window file)))
3f68d7c8
RS
2113 (select-window window)
2114 (find-file-other-window (file-name-sans-versions file t)))))
b70ebe37 2115
84fc2cfa 2116(defun dired-view-file ()
ee680b2b 2117 "In Dired, examine a file in view mode, returning to Dired when done.
b70ebe37 2118When file is a directory, show it in this buffer if it is inserted.
3f68d7c8 2119Otherwise, display it in another buffer."
84fc2cfa 2120 (interactive)
68d2f12f
RS
2121 (let ((file (dired-get-file-for-visit)))
2122 (if (file-directory-p file)
2123 (or (and (cdr dired-subdir-alist)
2124 (dired-goto-subdir file))
2125 (dired file))
3f68d7c8 2126 (view-file file))))
84fc2cfa
ER
2127
2128(defun dired-find-file-other-window ()
68d2f12f 2129 "In Dired, visit this file or directory in another window."
84fc2cfa 2130 (interactive)
68d2f12f 2131 (find-file-other-window (dired-get-file-for-visit)))
ab67260b
RS
2132
2133(defun dired-display-file ()
68d2f12f 2134 "In Dired, display this file or directory in another window."
ab67260b 2135 (interactive)
68d2f12f 2136 (display-buffer (find-file-noselect (dired-get-file-for-visit))))
83fadedf 2137\f
68d2f12f 2138;;; Functions for extracting and manipulating file names in Dired buffers.
84fc2cfa
ER
2139
2140(defun dired-get-filename (&optional localp no-error-if-not-filep)
68d2f12f 2141 "In Dired, return name of file mentioned on this line.
84fc2cfa 2142Value returned normally includes the directory name.
492d2437 2143Optional arg LOCALP with value `no-dir' means don't include directory
147e214c
LT
2144name in result. A value of `verbatim' means to return the name exactly as
2145it occurs in the buffer, and a value of t means construct name relative to
2146`default-directory', which still may contain slashes if in a subdirectory.
2147Optional arg NO-ERROR-IF-NOT-FILEP means treat `.' and `..' as
2148regular filenames and return nil if no filename on this line.
2149Otherwise, an error occurs in these cases."
a5e0e1a8 2150 (let (case-fold-search file p1 p2 already-absolute)
84fc2cfa 2151 (save-excursion
492d2437
RS
2152 (if (setq p1 (dired-move-to-filename (not no-error-if-not-filep)))
2153 (setq p2 (dired-move-to-end-of-filename no-error-if-not-filep))))
2154 ;; nil if no file on this line, but no-error-if-not-filep is t:
9888aa65
RS
2155 (if (setq file (and p1 p2 (buffer-substring p1 p2)))
2156 (progn
2157 ;; Get rid of the mouse-face property that file names have.
2158 (set-text-properties 0 (length file) nil file)
2159 ;; Unquote names quoted by ls or by dired-insert-directory.
1be9bd1e
CY
2160 ;; This code was written using `read' to unquote, because
2161 ;; it's faster than substituting \007 (4 chars) -> ^G (1
2162 ;; char) etc. in a lisp loop. Unfortunately, this decision
2163 ;; has necessitated hacks such as dealing with filenames
2164 ;; with quotation marks in their names.
2165 (while (string-match "\\(?:[^\\]\\|\\`\\)\\(\"\\)" file)
2166 (setq file (replace-match "\\\"" nil t file 1)))
1498536e
GM
2167 ;; Unescape any spaces escaped by ls -b (bug#10469).
2168 ;; Other -b quotes, eg \t, \n, work transparently.
2169 (if (dired-switches-escape-p dired-actual-switches)
3cdb7f5a
GM
2170 (let ((start 0)
2171 (rep "")
2172 (shift -1))
2173 (if (eq localp 'verbatim)
2174 (setq rep "\\\\"
2175 shift +1))
1498536e 2176 (while (string-match "\\(\\\\\\) " file start)
3cdb7f5a
GM
2177 (setq file (replace-match rep nil t file 1)
2178 start (+ shift (match-end 0))))))
d1882ac7
EW
2179 (when (eq system-type 'windows-nt)
2180 (save-match-data
2181 (let ((start 0))
2182 (while (string-match "\\\\" file start)
2183 (aset file (match-beginning 0) ?/)
2184 (setq start (match-end 0))))))
2185
1498536e 2186 ;; Hence we don't need to worry about converting `\\' back to `\'.
1be9bd1e 2187 (setq file (read (concat "\"" file "\"")))
038b5501
KH
2188 ;; The above `read' will return a unibyte string if FILE
2189 ;; contains eight-bit-control/graphic characters.
2190 (if (and enable-multibyte-characters
2191 (not (multibyte-string-p file)))
2192 (setq file (string-to-multibyte file)))))
f6e2cbe3 2193 (and file (file-name-absolute-p file)
7994d91a
RS
2194 ;; A relative file name can start with ~.
2195 ;; Don't treat it as absolute in this context.
2196 (not (eq (aref file 0) ?~))
a5e0e1a8 2197 (setq already-absolute t))
a5e0e1a8 2198 (cond
b95ddab3
RS
2199 ((null file)
2200 nil)
1d5ad120
JB
2201 ((eq localp 'verbatim)
2202 file)
e9407052 2203 ((and (not no-error-if-not-filep)
5709c1a0 2204 (member file '("." "..")))
e9407052 2205 (error "Cannot operate on `.' or `..'"))
a5e0e1a8
EZ
2206 ((and (eq localp 'no-dir) already-absolute)
2207 (file-name-nondirectory file))
b95ddab3 2208 (already-absolute
ca66efd1
RS
2209 (let ((handler (find-file-name-handler file nil)))
2210 ;; check for safe-magic property so that we won't
2211 ;; put /: for names that don't really need them.
0b7bc76f 2212 ;; For instance, .gz files when auto-compression-mode is on.
ca66efd1
RS
2213 (if (and handler (not (get handler 'safe-magic)))
2214 (concat "/:" file)
2215 file)))
b95ddab3 2216 ((eq localp 'no-dir)
a5e0e1a8 2217 file)
b95ddab3
RS
2218 ((equal (dired-current-directory) "/")
2219 (setq file (concat (dired-current-directory localp) file))
ca66efd1
RS
2220 (let ((handler (find-file-name-handler file nil)))
2221 ;; check for safe-magic property so that we won't
2222 ;; put /: for names that don't really need them.
2223 ;; For instance, .gz files when auto-compression-mode is on.
2224 (if (and handler (not (get handler 'safe-magic)))
2225 (concat "/:" file)
2226 file)))
a5e0e1a8 2227 (t
b95ddab3 2228 (concat (dired-current-directory localp) file)))))
492d2437 2229
437fe5ae 2230(defun dired-string-replace-match (regexp string newtext
1d5ad120 2231 &optional literal global)
437fe5ae
RS
2232 "Replace first match of REGEXP in STRING with NEWTEXT.
2233If it does not match, nil is returned instead of the new string.
2234Optional arg LITERAL means to take NEWTEXT literally.
2235Optional arg GLOBAL means to replace all matches."
2236 (if global
b976e099 2237 (let ((start 0) ret)
856321e2
RS
2238 (while (string-match regexp string start)
2239 (let ((from-end (- (length string) (match-end 0))))
b976e099 2240 (setq ret (setq string (replace-match newtext t literal string)))
856321e2 2241 (setq start (- (length string) from-end))))
b976e099 2242 ret)
437fe5ae
RS
2243 (if (not (string-match regexp string 0))
2244 nil
856321e2 2245 (replace-match newtext t literal string))))
437fe5ae 2246
492d2437 2247(defun dired-make-absolute (file &optional dir)
470fa6d1 2248 ;;"Convert FILE (a file name relative to DIR) to an absolute file name."
492d2437
RS
2249 ;; We can't always use expand-file-name as this would get rid of `.'
2250 ;; or expand in / instead default-directory if DIR=="".
7c2fb837 2251 ;; This should be good enough for ange-ftp.
492d2437
RS
2252 ;; It should be reasonably fast, though, as it is called in
2253 ;; dired-get-filename.
2254 (concat (or dir default-directory) file))
2255
c5695d1d 2256(defun dired-make-relative (file &optional dir)
827dc60d 2257 "Convert FILE (an absolute file name) to a name relative to DIR.
c5695d1d
CY
2258If DIR is omitted or nil, it defaults to `default-directory'.
2259If FILE is not in the directory tree of DIR, return FILE
2260unchanged."
492d2437 2261 (or dir (setq dir default-directory))
7425bbff
RS
2262 ;; This case comes into play if default-directory is set to
2263 ;; use ~.
2264 (if (and (> (length dir) 0) (= (aref dir 0) ?~))
2265 (setq dir (expand-file-name dir)))
492d2437
RS
2266 (if (string-match (concat "^" (regexp-quote dir)) file)
2267 (substring file (match-end 0))
827dc60d 2268 file))
83fadedf 2269\f
a2a538b1 2270(define-minor-mode dired-hide-details-mode
52695556
GM
2271 "Toggle visibility of detailed information in current Dired buffer.
2272When this minor mode is enabled, details such as file ownership and
2273permissions are hidden from view.
2274
2275See options: `dired-hide-details-hide-symlink-targets' and
2276`dired-hide-details-hide-information-lines'."
a2a538b1
CS
2277 :group 'dired
2278 (unless (derived-mode-p 'dired-mode)
2279 (error "Not a Dired buffer"))
2280 (dired-hide-details-update-invisibility-spec)
2281 (if dired-hide-details-mode
2282 (add-hook 'wdired-mode-hook
2283 'dired-hide-details-update-invisibility-spec
2284 nil
2285 t)
2286 (remove-hook 'wdired-mode-hook
2287 'dired-hide-details-update-invisibility-spec
2288 t)))
2289
2290(defun dired-hide-details-update-invisibility-spec ()
2291 (funcall (if dired-hide-details-mode
2292 'add-to-invisibility-spec
2293 'remove-from-invisibility-spec)
2294 'dired-hide-details-detail)
2295 (funcall (if (and dired-hide-details-mode
2296 dired-hide-details-hide-information-lines)
2297 'add-to-invisibility-spec
2298 'remove-from-invisibility-spec)
2299 'dired-hide-details-information)
2300 (funcall (if (and dired-hide-details-mode
2301 dired-hide-details-hide-symlink-targets
2302 (not (derived-mode-p 'wdired-mode)))
2303 'add-to-invisibility-spec
2304 'remove-from-invisibility-spec)
2305 'dired-hide-details-link))
2306\f
492d2437
RS
2307;;; Functions for finding the file name in a dired buffer line.
2308
23e217f6
RS
2309(defvar dired-permission-flags-regexp
2310 "\\([^ ]\\)[-r][-w]\\([^ ]\\)[-r][-w]\\([^ ]\\)[-r][-w]\\([^ ]\\)"
2311 "Regular expression to match the permission flags in `ls -l'.")
2312
492d2437
RS
2313;; Move to first char of filename on this line.
2314;; Returns position (point) or nil if no filename on this line."
2315(defun dired-move-to-filename (&optional raise-error eol)
a12c6dca
SM
2316 "Move to the beginning of the filename on the current line.
2317Return the position of the beginning of the filename, or nil if none found."
492d2437 2318 ;; This is the UNIX version.
2b2059d8 2319 (or eol (setq eol (line-end-position)))
492d2437 2320 (beginning-of-line)
0b7bc76f 2321 ;; First try assuming `ls --dired' was used.
2b2059d8
SM
2322 (let ((change (next-single-property-change (point) 'dired-filename nil eol)))
2323 (cond
2324 ((and change (< change eol))
2325 (goto-char change))
9bc260cf 2326 ((re-search-forward directory-listing-before-filename-regexp eol t)
2b2059d8
SM
2327 (goto-char (match-end 0)))
2328 ((re-search-forward dired-permission-flags-regexp eol t)
2329 ;; Ha! There *is* a file. Our regexp-from-hell just failed to find it.
1f3b4d04 2330 (if raise-error
9bc260cf 2331 (error "Unrecognized line! Check directory-listing-before-filename-regexp"))
1f3b4d04
SM
2332 (beginning-of-line)
2333 nil)
2b2059d8
SM
2334 (raise-error
2335 (error "No file on this line")))))
492d2437
RS
2336
2337(defun dired-move-to-end-of-filename (&optional no-error)
2338 ;; Assumes point is at beginning of filename,
2339 ;; thus the rwx bit re-search-backward below will succeed in *this*
2340 ;; line if at all. So, it should be called only after
2341 ;; (dired-move-to-filename t).
2342 ;; On failure, signals an error (with non-nil NO-ERROR just returns nil).
2343 ;; This is the UNIX version.
0b7bc76f
RS
2344 (if (get-text-property (point) 'dired-filename)
2345 (goto-char (next-single-property-change (point) 'dired-filename))
2346 (let (opoint file-type executable symlink hidden case-fold-search used-F eol)
2347 ;; case-fold-search is nil now, so we can test for capital F:
cedf5c9d 2348 (setq used-F (string-match-p "F" dired-actual-switches)
0b7bc76f 2349 opoint (point)
5ed619e0 2350 eol (line-end-position)
0b7bc76f
RS
2351 hidden (and selective-display
2352 (save-excursion (search-forward "\r" eol t))))
2353 (if hidden
2354 nil
2355 (save-excursion ;; Find out what kind of file this is:
2356 ;; Restrict perm bits to be non-blank,
2357 ;; otherwise this matches one char to early (looking backward):
2358 ;; "l---------" (some systems make symlinks that way)
2359 ;; "----------" (plain file with zero perms)
2360 (if (re-search-backward
2361 dired-permission-flags-regexp nil t)
2362 (setq file-type (char-after (match-beginning 1))
2363 symlink (eq file-type ?l)
2364 ;; Only with -F we need to know whether it's an executable
2365 executable (and
2366 used-F
2367 (string-match
2368 "[xst]" ;; execute bit set anywhere?
2369 (concat
ff3d76aa
SM
2370 (match-string 2)
2371 (match-string 3)
2372 (match-string 4)))))
0b7bc76f
RS
2373 (or no-error (error "No file on this line"))))
2374 ;; Move point to end of name:
2375 (if symlink
a12c6dca 2376 (if (search-forward " -> " eol t)
0b7bc76f 2377 (progn
a12c6dca 2378 (forward-char -4)
0b7bc76f
RS
2379 (and used-F
2380 dired-ls-F-marks-symlinks
2381 (eq (preceding-char) ?@) ;; did ls really mark the link?
2382 (forward-char -1))))
2383 (goto-char eol) ;; else not a symbolic link
dd52fff6
TTN
2384 ;; ls -lF marks dirs, sockets, fifos and executables with exactly
2385 ;; one trailing character. (Executable bits on symlinks ain't mean
0b7bc76f
RS
2386 ;; a thing, even to ls, but we know it's not a symlink.)
2387 (and used-F
dd52fff6 2388 (or (memq file-type '(?d ?s ?p))
0b7bc76f
RS
2389 executable)
2390 (forward-char -1))))
2391 (or no-error
2392 (not (eq opoint (point)))
8c16bd8c 2393 (error "%s" (if hidden
0b7bc76f
RS
2394 (substitute-command-keys
2395 "File line is hidden, type \\[dired-hide-subdir] to unhide")
2396 "No file on this line")))
2397 (if (eq opoint (point))
2398 nil
2399 (point)))))
492d2437 2400
83fadedf 2401\f
a3f4a3ef
RS
2402;;; COPY NAMES OF MARKED FILES INTO KILL-RING.
2403
2404(defun dired-copy-filename-as-kill (&optional arg)
2405 "Copy names of marked (or next ARG) files into the kill ring.
2406The names are separated by a space.
470fa6d1 2407With a zero prefix arg, use the absolute file name of each marked file.
cedf5c9d 2408With \\[universal-argument], use the file name relative to the Dired buffer's
afda9919 2409`default-directory'. (This still may contain slashes if in a subdirectory.)
a3f4a3ef 2410
afda9919
LT
2411If on a subdir headerline, use absolute subdirname instead;
2412prefix arg and marked files are ignored in this case.
a3f4a3ef
RS
2413
2414You can then feed the file name(s) to other commands with \\[yank]."
2415 (interactive "P")
2416 (let ((string
2417 (or (dired-get-subdir)
2418 (mapconcat (function identity)
2419 (if arg
2420 (cond ((zerop (prefix-numeric-value arg))
2421 (dired-get-marked-files))
afda9919
LT
2422 ((consp arg)
2423 (dired-get-marked-files t))
2424 (t
2425 (dired-get-marked-files
2426 'no-dir (prefix-numeric-value arg))))
a3f4a3ef
RS
2427 (dired-get-marked-files 'no-dir))
2428 " "))))
4de547e4
RS
2429 (if (eq last-command 'kill-region)
2430 (kill-append string nil)
2431 (kill-new string))
a3f4a3ef
RS
2432 (message "%s" string)))
2433
2434\f
492d2437
RS
2435;; Keeping Dired buffers in sync with the filesystem and with each other
2436
ef746164 2437(defun dired-buffers-for-dir (dir &optional file)
dad7c716 2438;; Return a list of buffers for DIR (top level or in-situ subdir).
ef746164
RS
2439;; If FILE is non-nil, include only those whose wildcard pattern (if any)
2440;; matches FILE.
492d2437
RS
2441;; The list is in reverse order of buffer creation, most recent last.
2442;; As a side effect, killed dired buffers for DIR are removed from
2443;; dired-buffers.
2444 (setq dir (file-name-as-directory dir))
dad7c716
CY
2445 (let (result buf)
2446 (dolist (elt dired-buffers)
2447 (setq buf (cdr elt))
2448 (cond
2449 ((null (buffer-name buf))
2450 ;; Buffer is killed - clean up:
38819778 2451 (setq dired-buffers (delq elt dired-buffers)))
dad7c716
CY
2452 ((dired-in-this-tree dir (car elt))
2453 (with-current-buffer buf
2454 (and (assoc dir dired-subdir-alist)
2455 (or (null file)
2456 (if (stringp dired-directory)
2457 (let ((wildcards (file-name-nondirectory
2458 dired-directory)))
cedf5c9d
JB
2459 (or (zerop (length wildcards))
2460 (string-match-p (dired-glob-regexp wildcards)
2461 file)))
dad7c716
CY
2462 (member (expand-file-name file dir)
2463 (cdr dired-directory))))
2464 (setq result (cons buf result)))))))
492d2437
RS
2465 result))
2466
ef746164
RS
2467(defun dired-glob-regexp (pattern)
2468 "Convert glob-pattern PATTERN to a regular expression."
2469 (let ((matched-in-pattern 0) ;; How many chars of PATTERN we've handled.
2470 regexp)
2471 (while (string-match "[[?*]" pattern matched-in-pattern)
2472 (let ((op-end (match-end 0))
2473 (next-op (aref pattern (match-beginning 0))))
2474 (setq regexp (concat regexp
2475 (regexp-quote
2476 (substring pattern matched-in-pattern
2477 (match-beginning 0)))))
2478 (cond ((= next-op ??)
2479 (setq regexp (concat regexp "."))
2480 (setq matched-in-pattern op-end))
2481 ((= next-op ?\[)
2482 ;; Fails to handle ^ yet ????
2483 (let* ((set-start (match-beginning 0))
2484 (set-cont
2485 (if (= (aref pattern (1+ set-start)) ?^)
2486 (+ 3 set-start)
2487 (+ 2 set-start)))
cedf5c9d 2488 (set-end (string-match-p "]" pattern set-cont))
ef746164
RS
2489 (set (substring pattern set-start (1+ set-end))))
2490 (setq regexp (concat regexp set))
2491 (setq matched-in-pattern (1+ set-end))))
2492 ((= next-op ?*)
2493 (setq regexp (concat regexp ".*"))
2494 (setq matched-in-pattern op-end)))))
2495 (concat "\\`"
2496 regexp
2497 (regexp-quote
2498 (substring pattern matched-in-pattern))
2499 "\\'")))
2500
c60ee5e7 2501
ef746164 2502
492d2437
RS
2503(defun dired-advertise ()
2504 ;;"Advertise in variable `dired-buffers' that we dired `default-directory'."
2505 ;; With wildcards we actually advertise too much.
38819778
RS
2506 (let ((expanded-default (expand-file-name default-directory)))
2507 (if (memq (current-buffer) (dired-buffers-for-dir expanded-default))
2508 t ; we have already advertised ourselves
2509 (setq dired-buffers
2510 (cons (cons expanded-default (current-buffer))
2511 dired-buffers)))))
492d2437
RS
2512
2513(defun dired-unadvertise (dir)
2514 ;; Remove DIR from the buffer alist in variable dired-buffers.
2515 ;; This has the effect of removing any buffer whose main directory is DIR.
2516 ;; It does not affect buffers in which DIR is a subdir.
2517 ;; Removing is also done as a side-effect in dired-buffer-for-dir.
2518 (setq dired-buffers
38819778 2519 (delq (assoc (expand-file-name dir) dired-buffers) dired-buffers)))
83fadedf 2520\f
492d2437
RS
2521;; Tree Dired
2522
2523;;; utility functions
2524
2525(defun dired-in-this-tree (file dir)
2526 ;;"Is FILE part of the directory tree starting at DIR?"
2527 (let (case-fold-search)
cedf5c9d 2528 (string-match-p (concat "^" (regexp-quote dir)) file)))
492d2437
RS
2529
2530(defun dired-normalize-subdir (dir)
470fa6d1
KS
2531 ;; Prepend default-directory to DIR if relative file name.
2532 ;; dired-get-filename must be able to make a valid file name from a
492d2437
RS
2533 ;; file and its directory DIR.
2534 (file-name-as-directory
2535 (if (file-name-absolute-p dir)
2536 dir
2537 (expand-file-name dir default-directory))))
2538
2539(defun dired-get-subdir ()
2540 ;;"Return the subdir name on this line, or nil if not on a headerline."
2541 ;; Look up in the alist whether this is a headerline.
2542 (save-excursion
2543 (let ((cur-dir (dired-current-directory)))
2544 (beginning-of-line) ; alist stores b-o-l positions
2545 (and (zerop (- (point)
2546 (dired-get-subdir-min (assoc cur-dir
2547 dired-subdir-alist))))
2548 cur-dir))))
2549
492d2437 2550;; can't use macro, must be redefinable for other alist format in dired-nstd.
62f61df0 2551(defalias 'dired-get-subdir-min 'cdr)
492d2437
RS
2552
2553(defun dired-get-subdir-max (elt)
84fc2cfa 2554 (save-excursion
492d2437
RS
2555 (goto-char (dired-get-subdir-min elt))
2556 (dired-subdir-max)))
2557
2558(defun dired-clear-alist ()
2559 (while dired-subdir-alist
2560 (set-marker (dired-get-subdir-min (car dired-subdir-alist)) nil)
2561 (setq dired-subdir-alist (cdr dired-subdir-alist))))
2562
c9d59fc2
RS
2563(defun dired-subdir-index (dir)
2564 ;; Return an index into alist for use with nth
2565 ;; for the sake of subdir moving commands.
2566 (let (found (index 0) (alist dired-subdir-alist))
2567 (while alist
2568 (if (string= dir (car (car alist)))
2569 (setq alist nil found t)
2570 (setq alist (cdr alist) index (1+ index))))
2571 (if found index nil)))
2572
2573(defun dired-next-subdir (arg &optional no-error-if-not-found no-skip)
2574 "Go to next subdirectory, regardless of level."
2575 ;; Use 0 arg to go to this directory's header line.
2576 ;; NO-SKIP prevents moving to end of header line, returning whatever
2577 ;; position was found in dired-subdir-alist.
2578 (interactive "p")
2579 (let ((this-dir (dired-current-directory))
2580 pos index)
2581 ;; nth with negative arg does not return nil but the first element
2582 (setq index (- (dired-subdir-index this-dir) arg))
2583 (setq pos (if (>= index 0)
2584 (dired-get-subdir-min (nth index dired-subdir-alist))))
2585 (if pos
2586 (progn
2587 (goto-char pos)
2588 (or no-skip (skip-chars-forward "^\n\r"))
2589 (point))
2590 (if no-error-if-not-found
2591 nil ; return nil if not found
2592 (error "%s directory" (if (> arg 0) "Last" "First"))))))
2593
3c13627a 2594(defun dired-build-subdir-alist (&optional switches)
492d2437 2595 "Build `dired-subdir-alist' by parsing the buffer.
3c13627a
EZ
2596Returns the new value of the alist.
2597If optional arg SWITCHES is non-nil, use its value
2598instead of `dired-actual-switches'."
492d2437
RS
2599 (interactive)
2600 (dired-clear-alist)
2601 (save-excursion
3c13627a 2602 (let* ((count 0)
f836b98e 2603 (inhibit-read-only t)
784a48b2 2604 (buffer-undo-list t)
3c13627a
EZ
2605 (switches (or switches dired-actual-switches))
2606 new-dir-name
2607 (R-ftp-base-dir-regex
2608 ;; Used to expand subdirectory names correctly in recursive
2609 ;; ange-ftp listings.
cedf5c9d 2610 (and (string-match-p "R" switches)
3c13627a
EZ
2611 (string-match "\\`/.*:\\(/.*\\)" default-directory)
2612 (concat "\\`" (match-string 1 default-directory)))))
84fc2cfa 2613 (goto-char (point-min))
492d2437 2614 (setq dired-subdir-alist nil)
a3d76960
RS
2615 (while (re-search-forward dired-subdir-regexp nil t)
2616 ;; Avoid taking a file name ending in a colon
2617 ;; as a subdir name.
2618 (unless (save-excursion
2619 (goto-char (match-beginning 0))
2620 (beginning-of-line)
2621 (forward-char 2)
cedf5c9d 2622 (looking-at-p dired-re-perms))
a3d76960
RS
2623 (save-excursion
2624 (goto-char (match-beginning 1))
2625 (setq new-dir-name
2626 (buffer-substring-no-properties (point) (match-end 1))
2627 new-dir-name
2628 (save-match-data
2629 (if (and R-ftp-base-dir-regex
2630 (not (string= new-dir-name default-directory))
2631 (string-match R-ftp-base-dir-regex new-dir-name))
2632 (concat default-directory
2633 (substring new-dir-name (match-end 0)))
2634 (expand-file-name new-dir-name))))
2635 (delete-region (point) (match-end 1))
7de3f9a4
RS
2636 (insert new-dir-name))
2637 (setq count (1+ count))
1db03b16
GM
2638 ;; Undo any escaping of newlines and \ by dired-insert-directory.
2639 ;; Convert "n" preceded by odd number of \ to newline, and \\ to \.
01153e44 2640 (when (and (dired-switches-escape-p switches)
9ff5d5a5 2641 (string-match-p "\\\\" new-dir-name))
1db03b16
GM
2642 (let (temp res)
2643 (mapc (lambda (char)
2644 (cond ((equal char ?\\)
2645 (if temp
2646 (setq res (concat res "\\")
2647 temp nil)
2648 (setq temp "\\")))
2649 ((and temp (equal char ?n))
2650 (setq res (concat res "\n")
2651 temp nil))
2652 (t
2653 (setq res (concat res temp (char-to-string char))
2654 temp nil))))
2655 new-dir-name)
2656 (setq new-dir-name res)))
7de3f9a4 2657 (dired-alist-add-1 new-dir-name
1db03b16
GM
2658 ;; Place a sub directory boundary between lines.
2659 (save-excursion
2660 (goto-char (match-beginning 0))
2661 (beginning-of-line)
2662 (point-marker)))))
32226619 2663 (if (and (> count 1) (called-interactively-p 'interactive))
a3d76960
RS
2664 (message "Buffer includes %d directories" count)))
2665 ;; We don't need to sort it because it is in buffer order per
303ad845 2666 ;; constructionem. Return new alist:
a3d76960 2667 dired-subdir-alist))
492d2437
RS
2668
2669(defun dired-alist-add-1 (dir new-marker)
2670 ;; Add new DIR at NEW-MARKER. Don't sort.
2671 (setq dired-subdir-alist
2672 (cons (cons (dired-normalize-subdir dir) new-marker)
2673 dired-subdir-alist)))
2674
2675(defun dired-goto-next-nontrivial-file ()
2676 ;; Position point on first nontrivial file after point.
2677 (dired-goto-next-file);; so there is a file to compare with
2678 (if (stringp dired-trivial-filenames)
2679 (while (and (not (eobp))
cedf5c9d
JB
2680 (string-match-p dired-trivial-filenames
2681 (file-name-nondirectory
2682 (or (dired-get-filename nil t) ""))))
492d2437
RS
2683 (forward-line 1)
2684 (dired-move-to-filename))))
2685
2686(defun dired-goto-next-file ()
2687 (let ((max (1- (dired-subdir-max))))
2688 (while (and (not (dired-move-to-filename)) (< (point) max))
2689 (forward-line 1))))
2690
2691(defun dired-goto-file (file)
cedf5c9d 2692 "Go to line describing file FILE in this Dired buffer."
492d2437 2693 ;; Return value of point on success, else nil.
470fa6d1 2694 ;; FILE must be an absolute file name.
492d2437
RS
2695 ;; Loses if FILE contains control chars like "\007" for which ls
2696 ;; either inserts "?" or "\\007" into the buffer, so we won't find
2697 ;; it in the buffer.
2698 (interactive
2699 (prog1 ; let push-mark display its message
2700 (list (expand-file-name
2701 (read-file-name "Goto file: "
2702 (dired-current-directory))))
2703 (push-mark)))
82dcf4e4
CY
2704 (unless (file-name-absolute-p file)
2705 (error "File name `%s' is not absolute" file))
2706 (setq file (directory-file-name file)) ; does no harm if not a directory
2707 (let* ((case-fold-search nil)
2708 (dir (file-name-directory file))
2709 (found (or
2710 ;; First, look for a listing under the absolute name.
2711 (save-excursion
2712 (goto-char (point-min))
2713 (dired-goto-file-1 file file (point-max)))
2714 ;; Otherwise, look for it as a relative name. The
2715 ;; hair is to get the result of `dired-goto-subdir'
2716 ;; without calling it if we don't have any subdirs.
2717 (save-excursion
2718 (when (if (string= dir (expand-file-name default-directory))
2719 (goto-char (point-min))
2720 (and (cdr dired-subdir-alist)
2721 (dired-goto-subdir dir)))
2722 (dired-goto-file-1 (file-name-nondirectory file)
2723 file
2724 (dired-subdir-max)))))))
2725 ;; Return buffer position, if found.
2726 (if found
2727 (goto-char found))))
2728
2729(defun dired-goto-file-1 (file full-name limit)
2730 "Advance to the Dired listing labeled by FILE; return its position.
2731Return nil if the listing is not found. If FILE contains
2732characters that would not appear in a Dired buffer, search using
2733the quoted forms of those characters.
2734
2735FULL-NAME specifies the actual file name the listing must have,
2736as returned by `dired-get-filename'. LIMIT is the search limit."
2737 (let (str)
2738 (setq str (replace-regexp-in-string "\^m" "\\^m" file nil t))
2739 (setq str (replace-regexp-in-string "\\\\" "\\\\" str nil t))
2740 (and (dired-switches-escape-p dired-actual-switches)
cedf5c9d 2741 (string-match-p "[ \t\n]" str)
82dcf4e4
CY
2742 ;; FIXME: to fix this for embedded control characters etc, we
2743 ;; should escape everything that `ls -b' does.
2744 (setq str (replace-regexp-in-string " " "\\ " str nil t)
2745 str (replace-regexp-in-string "\t" "\\t" str nil t)
2746 str (replace-regexp-in-string "\n" "\\n" str nil t)))
2747 (let ((found nil)
2748 ;; filenames are preceded by SPC, this makes the search faster
2749 ;; (e.g. for the filename "-").
2750 (search-string (concat " " str)))
2751 (while (and (not found)
2752 (search-forward search-string limit 'move))
2753 ;; Check that we are in the right place. Match could have
2754 ;; BASE just as initial substring or in permission bits etc.
2755 (if (equal full-name (dired-get-filename nil t))
2756 (setq found (dired-move-to-filename))
2757 (forward-line 1)))
2758 found)))
492d2437 2759
203784cc
GM
2760(defvar dired-find-subdir)
2761
2762;; FIXME document whatever dired-x is doing.
492d2437 2763(defun dired-initial-position (dirname)
203784cc 2764 "Where point should go in a new listing of DIRNAME.
d4466a91
IK
2765Point assumed at beginning of new subdir line.
2766It runs the hook `dired-initial-position-hook'."
492d2437 2767 (end-of-line)
203784cc
GM
2768 (and (featurep 'dired-x) dired-find-subdir
2769 (dired-goto-subdir dirname))
d4466a91 2770 (if dired-trivial-filenames (dired-goto-next-nontrivial-file))
1d42e5b6 2771 (run-hooks 'dired-initial-position-hook))
83fadedf 2772\f
492d2437
RS
2773;; These are hooks which make tree dired work.
2774;; They are in this file because other parts of dired need to call them.
2775;; But they don't call the rest of tree dired unless there are subdirs loaded.
2776
2777;; This function is called for each retrieved filename.
2778;; It could stand to be faster, though it's mostly function call
2779;; overhead. Avoiding the function call seems to save about 10% in
2780;; dired-get-filename. Make it a defsubst?
2781(defun dired-current-directory (&optional localp)
2782 "Return the name of the subdirectory to which this line belongs.
2783This returns a string with trailing slash, like `default-directory'.
2784Optional argument means return a file name relative to `default-directory'."
2785 (let ((here (point))
2786 (alist (or dired-subdir-alist
2787 ;; probably because called in a non-dired buffer
2788 (error "No subdir-alist in %s" (current-buffer))))
2789 elt dir)
2790 (while alist
2791 (setq elt (car alist)
2792 dir (car elt)
2793 ;; use `<=' (not `<') as subdir line is part of subdir
2794 alist (if (<= (dired-get-subdir-min elt) here)
2795 nil ; found
2796 (cdr alist))))
2797 (if localp
2798 (dired-make-relative dir default-directory)
2799 dir)))
2800
2801;; Subdirs start at the beginning of their header lines and end just
2802;; before the beginning of the next header line (or end of buffer).
2803
2804(defun dired-subdir-max ()
2805 (save-excursion
7b2469ae 2806 (if (or (null (cdr dired-subdir-alist)) (not (dired-next-subdir 1 t t)))
492d2437
RS
2807 (point-max)
2808 (point))))
83fadedf 2809\f
492d2437
RS
2810;; Deleting files
2811
40aa8257 2812(defcustom dired-recursive-deletes 'top
c5695d1d
CY
2813 "Whether Dired deletes directories recursively.
2814If nil, Dired will not delete non-empty directories.
2815`always' means to delete non-empty directories recursively,
2816without asking. This is dangerous!
2817`top' means to ask for each top-level directory specified by the
2818Dired deletion command, and delete its subdirectories without
2819asking.
2820Any other value means to ask for each directory."
53ade5c7
RS
2821 :type '(choice :tag "Delete non-empty directories"
2822 (const :tag "Yes" always)
2823 (const :tag "No--only delete empty directories" nil)
2824 (const :tag "Confirm for each directory" t)
2825 (const :tag "Confirm for each top directory only" top))
f0628026
RS
2826 :group 'dired)
2827
c60ee5e7 2828;; Match anything but `.' and `..'.
f0628026
RS
2829(defvar dired-re-no-dot "^\\([^.]\\|\\.\\([^.]\\|\\..\\)\\).*")
2830
2831;; Delete file, possibly delete a directory and all its files.
a98edce9 2832;; This function is useful outside of dired. One could change its name
f0628026 2833;; to e.g. recursive-delete-file and put it somewhere else.
f1a5d776 2834(defun dired-delete-file (file &optional recursive trash) "\
f0628026
RS
2835Delete FILE or directory (possibly recursively if optional RECURSIVE is true.)
2836RECURSIVE determines what to do with a non-empty directory. If RECURSIVE is:
ee680b2b 2837nil, do not delete.
f0628026
RS
2838`always', delete recursively without asking.
2839`top', ask for each directory at top level.
2840Anything else, ask for each sub-directory."
56808ea0
MA
2841 ;; This test is equivalent to
2842 ;; (and (file-directory-p fn) (not (file-symlink-p fn)))
2843 ;; but more efficient
2844 (if (not (eq t (car (file-attributes file))))
f1a5d776 2845 (delete-file file trash)
56808ea0
MA
2846 (if (and recursive
2847 (directory-files file t dired-re-no-dot) ; Not empty.
2848 (or (eq recursive 'always)
f1a5d776
CY
2849 (yes-or-no-p (format "Recursively %s %s? "
2850 (if (and trash
2851 delete-by-moving-to-trash)
2852 "trash"
2853 "delete")
56808ea0 2854 (dired-make-relative file)))))
f0628026 2855 (if (eq recursive 'top) (setq recursive 'always)) ; Don't ask again.
56808ea0 2856 (setq recursive nil))
f1a5d776 2857 (delete-directory file recursive trash)))
f0628026 2858
7da0e9b4 2859(defun dired-do-flagged-delete (&optional nomessage)
68d2f12f 2860 "In Dired, delete the files flagged for deletion.
7da0e9b4 2861If NOMESSAGE is non-nil, we don't display any message
bce1acc3 2862if there are no flagged files.
40aa8257
JL
2863`dired-recursive-deletes' controls whether deletion of
2864non-empty directories is allowed."
492d2437
RS
2865 (interactive)
2866 (let* ((dired-marker-char dired-del-marker)
2867 (regexp (dired-marker-regexp))
2868 case-fold-search)
2869 (if (save-excursion (goto-char (point-min))
2870 (re-search-forward regexp nil t))
2871 (dired-internal-do-deletions
2872 ;; this can't move point since ARG is nil
2873 (dired-map-over-marks (cons (dired-get-filename) (point))
2874 nil)
f1a5d776 2875 nil t)
7da0e9b4
RS
2876 (or nomessage
2877 (message "(No deletions requested)")))))
492d2437
RS
2878
2879(defun dired-do-delete (&optional arg)
bce1acc3 2880 "Delete all marked (or next ARG) files.
40aa8257
JL
2881`dired-recursive-deletes' controls whether deletion of
2882non-empty directories is allowed."
492d2437
RS
2883 ;; This is more consistent with the file marking feature than
2884 ;; dired-do-flagged-delete.
2885 (interactive "P")
2886 (dired-internal-do-deletions
2887 ;; this may move point if ARG is an integer
2888 (dired-map-over-marks (cons (dired-get-filename) (point))
2889 arg)
f1a5d776 2890 arg t))
492d2437
RS
2891
2892(defvar dired-deletion-confirmer 'yes-or-no-p) ; or y-or-n-p?
2893
f1a5d776 2894(defun dired-internal-do-deletions (l arg &optional trash)
492d2437
RS
2895 ;; L is an alist of files to delete, with their buffer positions.
2896 ;; ARG is the prefix arg.
7c2fb837 2897 ;; Filenames are absolute.
492d2437
RS
2898 ;; (car L) *must* be the *last* (bottommost) file in the dired buffer.
2899 ;; That way as changes are made in the buffer they do not shift the
2900 ;; lines still to be changed, so the (point) values in L stay valid.
2901 ;; Also, for subdirs in natural order, a subdir's files are deleted
2902 ;; before the subdir itself - the other way around would not work.
f1a5d776
CY
2903 (let* ((files (mapcar (function car) l))
2904 (count (length l))
2905 (succ 0)
2906 (trashing (and trash delete-by-moving-to-trash))
2907 (progress-reporter
2908 (make-progress-reporter
2909 (if trashing "Trashing..." "Deleting...")
2910 succ count)))
492d2437
RS
2911 ;; canonicalize file list for pop up
2912 (setq files (nreverse (mapcar (function dired-make-relative) files)))
2913 (if (dired-mark-pop-up
2914 " *Deletions*" 'delete files dired-deletion-confirmer
f1a5d776
CY
2915 (format "%s %s "
2916 (if trashing "Trash" "Delete")
2917 (dired-mark-prompt arg files)))
84fc2cfa 2918 (save-excursion
492d2437
RS
2919 (let (failures);; files better be in reverse order for this loop!
2920 (while l
2921 (goto-char (cdr (car l)))
f836b98e 2922 (let ((inhibit-read-only t))
492d2437
RS
2923 (condition-case err
2924 (let ((fn (car (car l))))
f1a5d776 2925 (dired-delete-file fn dired-recursive-deletes trash)
492d2437
RS
2926 ;; if we get here, removing worked
2927 (setq succ (1+ succ))
f1a5d776 2928 (progress-reporter-update progress-reporter succ)
bf989169
RS
2929 (dired-fun-in-all-buffers
2930 (file-name-directory fn) (file-name-nondirectory fn)
2931 (function dired-delete-entry) fn))
492d2437
RS
2932 (error;; catch errors from failed deletions
2933 (dired-log "%s\n" err)
2934 (setq failures (cons (car (car l)) failures)))))
2935 (setq l (cdr l)))
2936 (if (not failures)
f1a5d776 2937 (progress-reporter-done progress-reporter)
492d2437
RS
2938 (dired-log-summary
2939 (format "%d of %d deletion%s failed"
2940 (length failures) count
2941 (dired-plural-s count))
2942 failures))))
2943 (message "(No deletions performed)")))
2944 (dired-move-to-filename))
2945
bf989169
RS
2946(defun dired-fun-in-all-buffers (directory file fun &rest args)
2947 ;; In all buffers dired'ing DIRECTORY, run FUN with ARGS.
2948 ;; If the buffer has a wildcard pattern, check that it matches FILE.
2949 ;; (FILE does not include a directory component.)
2950 ;; FILE may be nil, in which case ignore it.
2951 ;; Return list of buffers where FUN succeeded (i.e., returned non-nil).
2952 (let (success-list)
2953 (dolist (buf (dired-buffers-for-dir (expand-file-name directory)
2954 file))
2955 (with-current-buffer buf
2956 (if (apply fun args)
2957 (setq success-list (cons (buffer-name buf) success-list)))))
2958 success-list))
2959
c60ee5e7 2960;; Delete the entry for FILE from
bf989169
RS
2961(defun dired-delete-entry (file)
2962 (save-excursion
2963 (and (dired-goto-file file)
f836b98e 2964 (let ((inhibit-read-only t))
bf989169
RS
2965 (delete-region (progn (beginning-of-line) (point))
2966 (save-excursion (forward-line 1) (point))))))
2967 (dired-clean-up-after-deletion file))
2968
42924231
GM
2969(defvar dired-clean-up-buffers-too)
2970
492d2437 2971(defun dired-clean-up-after-deletion (fn)
42924231
GM
2972 "Clean up after a deleted file or directory FN.
2973Removes any expanded subdirectory of deleted directory.
2974If `dired-x' is loaded and `dired-clean-up-buffers-too' is non-nil,
2975also offers to kill buffers visiting deleted files and directories."
7b2469ae
RS
2976 (save-excursion (and (cdr dired-subdir-alist)
2977 (dired-goto-subdir fn)
42924231
GM
2978 (dired-kill-subdir)))
2979 ;; Offer to kill buffer of deleted file FN.
2980 (when (and (featurep 'dired-x) dired-clean-up-buffers-too)
2981 (let ((buf (get-file-buffer fn)))
2982 (and buf
2983 (funcall #'y-or-n-p
2984 (format "Kill buffer of %s, too? "
2985 (file-name-nondirectory fn)))
2986 (kill-buffer buf)))
2987 (let ((buf-list (dired-buffers-for-dir (expand-file-name fn))))
2988 (and buf-list
cedf5c9d 2989 (y-or-n-p (format "Kill Dired buffer%s of %s, too? "
42924231
GM
2990 (dired-plural-s (length buf-list))
2991 (file-name-nondirectory fn)))
2992 (dolist (buf buf-list)
2993 (kill-buffer buf))))))
2994
83fadedf 2995\f
492d2437
RS
2996;; Confirmation
2997
2998(defun dired-marker-regexp ()
2999 (concat "^" (regexp-quote (char-to-string dired-marker-char))))
3000
3001(defun dired-plural-s (count)
3002 (if (= 1 count) "" "s"))
3003
3004(defun dired-mark-prompt (arg files)
f69fd0d2
CY
3005 "Return a string suitable for use in a Dired prompt.
3006ARG is normally the prefix argument for the calling command.
3007FILES should be a list of file names.
3008
3009The return value has a form like \"foo.txt\", \"[next 3 files]\",
3010or \"* [3 files]\"."
bb5527ce
SM
3011 ;; distinguish-one-marked can cause the first element to be just t.
3012 (if (eq (car files) t) (setq files (cdr files)))
492d2437
RS
3013 (let ((count (length files)))
3014 (if (= count 1)
3015 (car files)
3016 ;; more than 1 file:
3017 (if (integerp arg)
3018 ;; abs(arg) = count
3019 ;; Perhaps this is nicer, but it also takes more screen space:
3020 ;;(format "[%s %d files]" (if (> arg 0) "next" "previous")
3021 ;; count)
3022 (format "[next %d files]" arg)
3023 (format "%c [%d files]" dired-marker-char count)))))
3024
3025(defun dired-pop-to-buffer (buf)
7f0995a1 3026 "Pop up buffer BUF in a way suitable for Dired."
93cacb6d 3027 (declare (obsolete dired-mark-pop-up "24.3"))
19998f14
MR
3028 (let ((split-window-preferred-function
3029 (lambda (window)
b50e9ccf
MR
3030 (or (and (let ((split-height-threshold 0))
3031 (window-splittable-p (selected-window)))
19998f14
MR
3032 ;; Try to split the selected window vertically if
3033 ;; that's possible. (Bug#1806)
2d197ffb 3034 (split-window-below))
19998f14 3035 ;; Otherwise, try to split WINDOW sensibly.
6ed96c33
MR
3036 (split-window-sensibly window))))
3037 pop-up-frames)
7f0995a1 3038 (pop-to-buffer (get-buffer-create buf)))
34f10d41
MR
3039 ;; See Bug#12281.
3040 (set-window-start nil (point-min))
492d2437 3041 ;; If dired-shrink-to-fit is t, make its window fit its contents.
d7e78187 3042 (when dired-shrink-to-fit
4d0e7fe3
MR
3043 ;; Try to not delete window when we want to display less than
3044 ;; `window-min-height' lines.
3045 (fit-window-to-buffer (get-buffer-window buf) nil 1)))
492d2437 3046
5afea280 3047(defcustom dired-no-confirm nil
9c0deccb 3048 "A list of symbols for commands Dired should not confirm, or t.
0347d069 3049Command symbols are `byte-compile', `chgrp', `chmod', `chown', `compress',
57654b8c 3050`copy', `delete', `hardlink', `load', `move', `print', `shell', `symlink',
9c0deccb
JB
3051`touch' and `uncompress'.
3052If t, confirmation is never needed."
5afea280 3053 :group 'dired
9c0deccb
JB
3054 :type '(choice (const :tag "Confirmation never needed" t)
3055 (set (const byte-compile) (const chgrp)
3056 (const chmod) (const chown) (const compress)
3057 (const copy) (const delete) (const hardlink)
3058 (const load) (const move) (const print)
3059 (const shell) (const symlink) (const touch)
3060 (const uncompress))))
492d2437 3061
c5e28e39 3062(defun dired-mark-pop-up (buffer-or-name op-symbol files function &rest args)
8421685f 3063 "Return FUNCTION's result on ARGS after showing which files are marked.
c5e28e39
MR
3064Displays the file names in a window showing a buffer named
3065BUFFER-OR-NAME; the default name being \" *Marked Files*\". The
3066window is not shown if there is just one file, `dired-no-confirm'
3067is t, or OP-SYMBOL is a member of the list in `dired-no-confirm'.
3068
93cacb6d
JL
3069By default, Dired shrinks the display buffer to fit the marked files.
3070To disable this, use the Customization interface to add a new rule
3071to `display-buffer-alist' where condition regexp is \"^ \\*Marked Files\\*$\",
3072action argument symbol is `window-height' and its value is nil.
3073
09b092ad
RS
3074FILES is the list of marked files. It can also be (t FILENAME)
3075in the case of one marked file, to distinguish that from using
c5e28e39
MR
3076just the current file.
3077
cedf5c9d 3078FUNCTION should not manipulate files, just read input (an
c5e28e39 3079argument or confirmation)."
0347d069
SM
3080 (if (or (eq dired-no-confirm t)
3081 (memq op-symbol dired-no-confirm)
09b092ad 3082 ;; If FILES defaulted to the current line's file.
492d2437
RS
3083 (= (length files) 1))
3084 (apply function args)
c5e28e39
MR
3085 (let ((buffer (get-buffer-create (or buffer-or-name " *Marked Files*"))))
3086 (with-current-buffer buffer
cf2b7efc
MR
3087 (with-temp-buffer-window
3088 buffer
3089 (cons 'display-buffer-below-selected
3090 '((window-height . fit-window-to-buffer)))
3091 #'(lambda (window _value)
3092 (with-selected-window window
3093 (unwind-protect
3094 (apply function args)
3095 (when (window-live-p window)
3096 (quit-restore-window window 'kill)))))
3097 ;; Handle (t FILE) just like (FILE), here. That value is
3098 ;; used (only in some cases), to mean just one file that was
3099 ;; marked, rather than the current line file.
3100 (dired-format-columns-of-files
3101 (if (eq (car files) t) (cdr files) files))
3102 (remove-text-properties (point-min) (point-max)
3103 '(mouse-face nil help-echo nil)))))))
492d2437
RS
3104
3105(defun dired-format-columns-of-files (files)
991ae4e4
SM
3106 (let ((beg (point)))
3107 (completion--insert-strings files)
3108 (put-text-property beg (point) 'mouse-face nil)))
83fadedf 3109\f
492d2437
RS
3110;; Commands to mark or flag file(s) at or near current line.
3111
3112(defun dired-repeat-over-lines (arg function)
3113 ;; This version skips non-file lines.
cfe89c4f 3114 (let ((pos (make-marker)))
492d2437 3115 (beginning-of-line)
cfe89c4f
RS
3116 (while (and (> arg 0) (not (eobp)))
3117 (setq arg (1- arg))
3118 (beginning-of-line)
3119 (while (and (not (eobp)) (dired-between-files)) (forward-line 1))
3120 (save-excursion
3121 (forward-line 1)
3122 (move-marker pos (1+ (point))))
3123 (save-excursion (funcall function))
3124 ;; Advance to the next line--actually, to the line that *was* next.
3125 ;; (If FUNCTION inserted some new lines in between, skip them.)
3126 (goto-char pos))
3127 (while (and (< arg 0) (not (bobp)))
3128 (setq arg (1+ arg))
3129 (forward-line -1)
3130 (while (and (not (bobp)) (dired-between-files)) (forward-line -1))
3131 (beginning-of-line)
3132 (save-excursion (funcall function)))
3133 (move-marker pos nil)
3134 (dired-move-to-filename)))
492d2437
RS
3135
3136(defun dired-between-files ()
8a372755
MB
3137 ;; This used to be a regexp match of the `total ...' line output by
3138 ;; ls, which is slightly faster, but that is not very robust; notably,
3139 ;; it fails for non-english locales.
3140 (save-excursion (not (dired-move-to-filename))))
492d2437
RS
3141
3142(defun dired-next-marked-file (arg &optional wrap opoint)
3143 "Move to the next marked file, wrapping around the end of the buffer."
3144 (interactive "p\np")
3145 (or opoint (setq opoint (point)));; return to where interactively started
3146 (if (if (> arg 0)
3147 (re-search-forward dired-re-mark nil t arg)
3148 (beginning-of-line)
3149 (re-search-backward dired-re-mark nil t (- arg)))
3150 (dired-move-to-filename)
3151 (if (null wrap)
3152 (progn
3153 (goto-char opoint)
3154 (error "No next marked file"))
3155 (message "(Wraparound for next marked file)")
3156 (goto-char (if (> arg 0) (point-min) (point-max)))
3157 (dired-next-marked-file arg nil opoint))))
3158
3159(defun dired-prev-marked-file (arg &optional wrap)
3160 "Move to the previous marked file, wrapping around the end of the buffer."
3161 (interactive "p\np")
3162 (dired-next-marked-file (- arg) wrap))
3163
3164(defun dired-file-marker (file)
3165 ;; Return FILE's marker, or nil if unmarked.
3166 (save-excursion
3167 (and (dired-goto-file file)
3168 (progn
3169 (beginning-of-line)
3170 (if (not (equal ?\040 (following-char)))
3171 (following-char))))))
3172
3173(defun dired-mark-files-in-region (start end)
f836b98e 3174 (let ((inhibit-read-only t))
492d2437
RS
3175 (if (> start end)
3176 (error "start > end"))
3177 (goto-char start) ; assumed at beginning of line
3178 (while (< (point) end)
3179 ;; Skip subdir line and following garbage like the `total' line:
3180 (while (and (< (point) end) (dired-between-files))
3181 (forward-line 1))
cedf5c9d 3182 (if (and (not (looking-at-p dired-re-dot))
492d2437
RS
3183 (dired-get-filename nil t))
3184 (progn
3185 (delete-char 1)
3186 (insert dired-marker-char)))
3187 (forward-line 1))))
3188
61a2a122 3189(defun dired-mark (arg &optional interactive)
cd996018
CY
3190 "Mark the file at point in the Dired buffer.
3191If the region is active, mark all files in the region.
3192Otherwise, with a prefix arg, mark files on the next ARG lines.
3193
492d2437
RS
3194If on a subdir headerline, mark all its files except `.' and `..'.
3195
3196Use \\[dired-unmark-all-files] to remove all marks
3197and \\[dired-unmark] on a subdir to remove the marks in
3198this subdir."
61a2a122 3199 (interactive (list current-prefix-arg t))
42917e79
JL
3200 (cond
3201 ;; Mark files in the active region.
61a2a122 3202 ((and interactive (use-region-p))
42917e79
JL
3203 (save-excursion
3204 (let ((beg (region-beginning))
3205 (end (region-end)))
3206 (dired-mark-files-in-region
3207 (progn (goto-char beg) (line-beginning-position))
3208 (progn (goto-char end) (line-beginning-position))))))
3209 ;; Mark subdir files from the subdir headerline.
3210 ((dired-get-subdir)
3211 (save-excursion (dired-mark-subdir-files)))
3212 ;; Mark the current (or next ARG) files.
3213 (t
f836b98e 3214 (let ((inhibit-read-only t))
492d2437 3215 (dired-repeat-over-lines
52041219 3216 (prefix-numeric-value arg)
42917e79 3217 (function (lambda () (delete-char 1) (insert dired-marker-char))))))))
492d2437 3218
61a2a122 3219(defun dired-unmark (arg &optional interactive)
cd996018
CY
3220 "Unmark the file at point in the Dired buffer.
3221If the region is active, unmark all files in the region.
3222Otherwise, with a prefix arg, unmark files on the next ARG lines.
3223
42917e79
JL
3224If looking at a subdir, unmark all its files except `.' and `..'.
3225If the region is active in Transient Mark mode, unmark all files
3226in the active region."
61a2a122 3227 (interactive (list current-prefix-arg t))
492d2437 3228 (let ((dired-marker-char ?\040))
61a2a122 3229 (dired-mark arg interactive)))
492d2437 3230
61a2a122 3231(defun dired-flag-file-deletion (arg &optional interactive)
68d2f12f 3232 "In Dired, flag the current line's file for deletion.
cd996018
CY
3233If the region is active, flag all files in the region.
3234Otherwise, with a prefix arg, flag files on the next ARG lines.
3235
42917e79
JL
3236If on a subdir headerline, flag all its files except `.' and `..'.
3237If the region is active in Transient Mark mode, flag all files
3238in the active region."
61a2a122 3239 (interactive (list current-prefix-arg t))
492d2437 3240 (let ((dired-marker-char dired-del-marker))
61a2a122 3241 (dired-mark arg interactive)))
492d2437
RS
3242
3243(defun dired-unmark-backward (arg)
a48868a7
LMI
3244 "In Dired, move up lines and remove marks or deletion flags there.
3245Optional prefix ARG says how many lines to unmark/unflag; default
42917e79
JL
3246is one line.
3247If the region is active in Transient Mark mode, unmark all files
3248in the active region."
492d2437
RS
3249 (interactive "p")
3250 (dired-unmark (- arg)))
e5f0841e 3251
d588eb90
RS
3252(defun dired-toggle-marks ()
3253 "Toggle marks: marked files become unmarked, and vice versa.
e5f0841e
KH
3254Files marked with other flags (such as `D') are not affected.
3255`.' and `..' are never toggled.
3256As always, hidden subdirs are not affected."
3257 (interactive)
3258 (save-excursion
3259 (goto-char (point-min))
f836b98e 3260 (let ((inhibit-read-only t))
e5f0841e
KH
3261 (while (not (eobp))
3262 (or (dired-between-files)
cedf5c9d 3263 (looking-at-p dired-re-dot)
e5f0841e
KH
3264 ;; use subst instead of insdel because it does not move
3265 ;; the gap and thus should be faster and because
3266 ;; other characters are left alone automatically
3267 (apply 'subst-char-in-region
3268 (point) (1+ (point))
3269 (if (eq ?\040 (following-char)) ; SPC
3270 (list ?\040 dired-marker-char)
3271 (list dired-marker-char ?\040))))
3272 (forward-line 1)))))
83fadedf 3273\f
492d2437
RS
3274;;; Commands to mark or flag files based on their characteristics or names.
3275
d2cadc4b
RS
3276(defvar dired-regexp-history nil
3277 "History list of regular expressions used in Dired commands.")
3278
eb2deaff
JL
3279(defun dired-read-regexp (prompt &optional default history)
3280 (read-regexp prompt default (or history 'dired-regexp-history)))
492d2437
RS
3281
3282(defun dired-mark-files-regexp (regexp &optional marker-char)
3283 "Mark all files matching REGEXP for use in later commands.
3284A prefix argument means to unmark them instead.
3285`.' and `..' are never marked.
3286
3287REGEXP is an Emacs regexp, not a shell wildcard. Thus, use `\\.o$' for
3288object files--just `.o' will mark more than you might think."
3289 (interactive
3290 (list (dired-read-regexp (concat (if current-prefix-arg "Unmark" "Mark")
3291 " files (regexp): "))
3292 (if current-prefix-arg ?\040)))
3293 (let ((dired-marker-char (or marker-char dired-marker-char)))
3294 (dired-mark-if
cedf5c9d 3295 (and (not (looking-at-p dired-re-dot))
492d2437 3296 (not (eolp)) ; empty line
fc4f7a23 3297 (let ((fn (dired-get-filename t t)))
cedf5c9d 3298 (and fn (string-match-p regexp fn))))
492d2437
RS
3299 "matching file")))
3300
e9b8e22d
RS
3301(defun dired-mark-files-containing-regexp (regexp &optional marker-char)
3302 "Mark all files with contents containing REGEXP for use in later commands.
3303A prefix argument means to unmark them instead.
3304`.' and `..' are never marked."
3305 (interactive
3306 (list (dired-read-regexp (concat (if current-prefix-arg "Unmark" "Mark")
3307 " files containing (regexp): "))
3308 (if current-prefix-arg ?\040)))
3309 (let ((dired-marker-char (or marker-char dired-marker-char)))
3310 (dired-mark-if
cedf5c9d 3311 (and (not (looking-at-p dired-re-dot))
e9b8e22d
RS
3312 (not (eolp)) ; empty line
3313 (let ((fn (dired-get-filename nil t)))
05a40373
KH
3314 (when (and fn (file-readable-p fn)
3315 (not (file-directory-p fn)))
3316 (let ((prebuf (get-file-buffer fn)))
3317 (message "Checking %s" fn)
3318 ;; For now we do it inside emacs
3319 ;; Grep might be better if there are a lot of files
3320 (if prebuf
3321 (with-current-buffer prebuf
3322 (save-excursion
3323 (goto-char (point-min))
3324 (re-search-forward regexp nil t)))
3325 (with-temp-buffer
3326 (insert-file-contents fn)
3327 (goto-char (point-min))
3328 (re-search-forward regexp nil t))))
0b2bb4d0 3329 )))
e9b8e22d
RS
3330 "matching file")))
3331
492d2437 3332(defun dired-flag-files-regexp (regexp)
68d2f12f 3333 "In Dired, flag all files containing the specified REGEXP for deletion.
492d2437
RS
3334The match is against the non-directory part of the filename. Use `^'
3335 and `$' to anchor matches. Exclude subdirs by hiding them.
3336`.' and `..' are never flagged."
3337 (interactive (list (dired-read-regexp "Flag for deletion (regexp): ")))
3338 (dired-mark-files-regexp regexp dired-del-marker))
3339
3340(defun dired-mark-symlinks (unflag-p)
3341 "Mark all symbolic links.
a48868a7 3342With prefix argument, unmark or unflag all those files."
492d2437
RS
3343 (interactive "P")
3344 (let ((dired-marker-char (if unflag-p ?\040 dired-marker-char)))
cedf5c9d 3345 (dired-mark-if (looking-at-p dired-re-sym) "symbolic link")))
492d2437
RS
3346
3347(defun dired-mark-directories (unflag-p)
3348 "Mark all directory file lines except `.' and `..'.
a48868a7 3349With prefix argument, unmark or unflag all those files."
492d2437
RS
3350 (interactive "P")
3351 (let ((dired-marker-char (if unflag-p ?\040 dired-marker-char)))
cedf5c9d
JB
3352 (dired-mark-if (and (looking-at-p dired-re-dir)
3353 (not (looking-at-p dired-re-dot)))
492d2437
RS
3354 "directory file")))
3355
3356(defun dired-mark-executables (unflag-p)
3357 "Mark all executable files.
a48868a7 3358With prefix argument, unmark or unflag all those files."
492d2437
RS
3359 (interactive "P")
3360 (let ((dired-marker-char (if unflag-p ?\040 dired-marker-char)))
cedf5c9d 3361 (dired-mark-if (looking-at-p dired-re-exe) "executable file")))
492d2437
RS
3362
3363;; dired-x.el has a dired-mark-sexp interactive command: mark
3364;; files for which PREDICATE returns non-nil.
3365
3366(defun dired-flag-auto-save-files (&optional unflag-p)
84fc2cfa 3367 "Flag for deletion files whose names suggest they are auto save files.
a48868a7 3368A prefix argument says to unmark or unflag those files instead."
84fc2cfa 3369 (interactive "P")
492d2437
RS
3370 (let ((dired-marker-char (if unflag-p ?\040 dired-del-marker)))
3371 (dired-mark-if
2a838614 3372 ;; It is less than general to check for # here,
a91526b9
RS
3373 ;; but it's the only way this runs fast enough.
3374 (and (save-excursion (end-of-line)
536ae2dd
RS
3375 (or
3376 (eq (preceding-char) ?#)
3377 ;; Handle executables in case of -F option.
3378 ;; We need not worry about the other kinds
3379 ;; of markings that -F makes, since they won't
3380 ;; appear on real auto-save files.
3381 (if (eq (preceding-char) ?*)
3382 (progn
3383 (forward-char -1)
3384 (eq (preceding-char) ?#)))))
cedf5c9d 3385 (not (looking-at-p dired-re-dir))
a91526b9
RS
3386 (let ((fn (dired-get-filename t t)))
3387 (if fn (auto-save-file-name-p
3388 (file-name-nondirectory fn)))))
3389 "auto save file")))
492d2437 3390
d7aed37c 3391(defcustom dired-garbage-files-regexp
6736ab5a 3392 ;; `log' here is dubious, since it's typically used for useful log
d7aed37c 3393 ;; files, not just TeX stuff. -- fx
d4aeef3b
KG
3394 (concat (regexp-opt
3395 '(".log" ".toc" ".dvi" ".bak" ".orig" ".rej" ".aux"))
c60ee5e7 3396 "\\'")
d7aed37c
SM
3397 "Regular expression to match \"garbage\" files for `dired-flag-garbage-files'."
3398 :type 'regexp
3399 :group 'dired)
84d3f6e8
RS
3400
3401(defun dired-flag-garbage-files ()
84d3f6e8 3402 "Flag for deletion all files that match `dired-garbage-files-regexp'."
f656ec48 3403 (interactive)
84d3f6e8
RS
3404 (dired-flag-files-regexp dired-garbage-files-regexp))
3405
492d2437
RS
3406(defun dired-flag-backup-files (&optional unflag-p)
3407 "Flag all backup files (names ending with `~') for deletion.
a48868a7 3408With prefix argument, unmark or unflag these files."
492d2437 3409 (interactive "P")
ee680b2b 3410 (let ((dired-marker-char (if unflag-p ?\s dired-del-marker)))
492d2437 3411 (dired-mark-if
f13101e9
KH
3412 ;; Don't call backup-file-name-p unless the last character looks like
3413 ;; it might be the end of a backup file name. This isn't very general,
a91526b9
RS
3414 ;; but it's the only way this runs fast enough.
3415 (and (save-excursion (end-of-line)
f13101e9
KH
3416 ;; Handle executables in case of -F option.
3417 ;; We need not worry about the other kinds
3418 ;; of markings that -F makes, since they won't
3419 ;; appear on real backup files.
3420 (if (eq (preceding-char) ?*)
3421 (forward-char -1))
fdee13ec 3422 (eq (preceding-char) ?~))
cedf5c9d 3423 (not (looking-at-p dired-re-dir))
492d2437
RS
3424 (let ((fn (dired-get-filename t t)))
3425 (if fn (backup-file-name-p fn))))
3426 "backup file")))
3427
6482fcac
RS
3428(defun dired-change-marks (&optional old new)
3429 "Change all OLD marks to NEW marks.
3430OLD and NEW are both characters used to mark files."
3431 (interactive
3432 (let* ((cursor-in-echo-area t)
3433 (old (progn (message "Change (old mark): ") (read-char)))
3434 (new (progn (message "Change %c marks to (new mark): " old)
3435 (read-char))))
3436 (list old new)))
e4e02841
RS
3437 (if (or (eq old ?\r) (eq new ?\r))
3438 (ding)
3439 (let ((string (format "\n%c" old))
f836b98e 3440 (inhibit-read-only t))
e4e02841
RS
3441 (save-excursion
3442 (goto-char (point-min))
3443 (while (search-forward string nil t)
ee680b2b 3444 (if (if (= old ?\s)
a15a76f7
RS
3445 (save-match-data
3446 (dired-get-filename 'no-dir t))
3447 t)
3448 (subst-char-in-region (match-beginning 0)
3449 (match-end 0) old new)))))))
6482fcac 3450
534a6edf 3451(defun dired-unmark-all-marks ()
cedf5c9d 3452 "Remove all marks from all files in the Dired buffer."
b1ecd9c6
RS
3453 (interactive)
3454 (dired-unmark-all-files ?\r))
3455
8b87a301 3456(defun dired-unmark-all-files (mark &optional arg)
b602ba2f 3457 "Remove a specific mark (or any mark) from every file.
c60ee5e7 3458After this command, type the mark character to remove,
b602ba2f 3459or type RET to remove all marks.
3585916f 3460With prefix arg, query for each marked file.
492d2437 3461Type \\[help-command] at that time for help."
b602ba2f
RS
3462 (interactive "cRemove marks (RET means all): \nP")
3463 (save-excursion
3464 (let* ((count 0)
d032d5e7 3465 (inhibit-read-only t) case-fold-search
b602ba2f
RS
3466 (string (format "\n%c" mark))
3467 (help-form "\
8b87a301
RS
3468Type SPC or `y' to unmark one file, DEL or `n' to skip to next,
3469`!' to unmark all remaining files with no more questions."))
b602ba2f
RS
3470 (goto-char (point-min))
3471 (while (if (eq mark ?\r)
3472 (re-search-forward dired-re-mark nil t)
3473 (search-forward string nil t))
3474 (if (or (not arg)
e9407052
RS
3475 (let ((file (dired-get-filename t t)))
3476 (and file
3477 (dired-query 'query "Unmark file `%s'? "
3478 file))))
b602ba2f 3479 (progn (subst-char-in-region (1- (point)) (point)
ee680b2b 3480 (preceding-char) ?\s)
b602ba2f
RS
3481 (setq count (1+ count)))))
3482 (message (if (= count 1) "1 mark removed"
3483 "%d marks removed")
3484 count))))
83fadedf 3485\f
492d2437 3486;; Logging failures operating on files, and showing the results.
84fc2cfa 3487
492d2437 3488(defvar dired-log-buffer "*Dired log*")
84fc2cfa 3489
492d2437
RS
3490(defun dired-why ()
3491 "Pop up a buffer with error log output from Dired.
3492A group of errors from a single command ends with a formfeed.
3493Thus, use \\[backward-page] to find the beginning of a group of errors."
3494 (interactive)
3495 (if (get-buffer dired-log-buffer)
3496 (let ((owindow (selected-window))
3497 (window (display-buffer (get-buffer dired-log-buffer))))
3498 (unwind-protect
6482fcac 3499 (progn
492d2437
RS
3500 (select-window window)
3501 (goto-char (point-max))
0b7bc76f
RS
3502 (forward-line -1)
3503 (backward-page 1)
3504 (recenter 0))
492d2437
RS
3505 (select-window owindow)))))
3506
3507(defun dired-log (log &rest args)
3508 ;; Log a message or the contents of a buffer.
3509 ;; If LOG is a string and there are more args, it is formatted with
3510 ;; those ARGS. Usually the LOG string ends with a \n.
c60ee5e7 3511 ;; End each bunch of errors with (dired-log t):
0b7bc76f
RS
3512 ;; this inserts the current time and buffer at the start of the page,
3513 ;; and \f (formfeed) at the end.
492d2437 3514 (let ((obuf (current-buffer)))
0b7bc76f
RS
3515 (with-current-buffer (get-buffer-create dired-log-buffer)
3516 (goto-char (point-max))
3517 (let ((inhibit-read-only t))
3518 (cond ((stringp log)
3519 (insert (if args
3520 (apply (function format) log args)
3521 log)))
3522 ((bufferp log)
88cb5d3c 3523 (insert-buffer-substring log))
0b7bc76f
RS
3524 ((eq t log)
3525 (backward-page 1)
3526 (unless (bolp)
3527 (insert "\n"))
3528 (insert (current-time-string)
3529 "\tBuffer `" (buffer-name obuf) "'\n")
3530 (goto-char (point-max))
3531 (insert "\f\n")))))))
492d2437
RS
3532
3533(defun dired-log-summary (string failures)
ddcfebf1
RS
3534 "State a summary of a command's failures, in echo area and log buffer.
3535STRING is an overall summary of the failures.
3536FAILURES is a list of file names that we failed to operate on,
3537or nil if file names are not applicable."
0b7bc76f
RS
3538 (if (= (length failures) 1)
3539 (message "%s"
3540 (with-current-buffer dired-log-buffer
3541 (goto-char (point-max))
3542 (backward-page 1)
3543 (if (eolp) (forward-line 1))
3544 (buffer-substring (point) (point-max))))
3545 (message (if failures "%s--type ? for details (%s)"
3546 "%s--type ? for details")
3547 string failures))
492d2437 3548 ;; Log a summary describing a bunch of errors.
0b7bc76f 3549 (dired-log (concat "\n" string "\n"))
492d2437 3550 (dired-log t))
83fadedf 3551\f
492d2437
RS
3552;;; Sorting
3553
3554;; Most ls can only sort by name or by date (with -t), nothing else.
3555;; GNU ls sorts on size with -S, on extension with -X, and unsorted with -U.
3556;; So anything that does not contain these is sort "by name".
3557
3558(defvar dired-ls-sorting-switches "SXU"
cedf5c9d 3559 "String of `ls' switches (single letters) except \"t\" that influence sorting.
cfc8b264
EZ
3560
3561This indicates to Dired which option switches to watch out for because they
3562will change the sorting order behavior of `ls'.
3563
cedf5c9d 3564To change the default sorting order (e.g. add a `-v' option), see the
cfc8b264
EZ
3565variable `dired-listing-switches'. To temporarily override the listing
3566format, use `\\[universal-argument] \\[dired]'.")
492d2437
RS
3567
3568(defvar dired-sort-by-date-regexp
8d76af4a
CY
3569 (concat "\\(\\`\\| \\)-[^- ]*t"
3570 ;; `dired-ls-sorting-switches' after -t overrides -t.
3571 "[^ " dired-ls-sorting-switches "]*"
3572 "\\(\\(\\`\\| +\\)\\(--[^ ]+\\|-[^- t"
3573 dired-ls-sorting-switches "]+\\)\\)* *$")
ee680b2b 3574 "Regexp recognized by Dired to set `by date' mode.")
492d2437
RS
3575
3576(defvar dired-sort-by-name-regexp
8d76af4a
CY
3577 (concat "\\`\\(\\(\\`\\| +\\)\\(--[^ ]+\\|"
3578 "-[^- t" dired-ls-sorting-switches "]+\\)\\)* *$")
ee680b2b 3579 "Regexp recognized by Dired to set `by name' mode.")
492d2437 3580
23fc67ea
RS
3581(defvar dired-sort-inhibit nil
3582 "Non-nil means the Dired sort command is disabled.
cedf5c9d 3583The idea is to set this buffer-locally in special Dired buffers.")
23fc67ea 3584
37269466
CY
3585(defun dired-sort-set-mode-line ()
3586 ;; Set mode line display according to dired-actual-switches.
3587 ;; Mode line display of "by name" or "by date" guarantees the user a
492d2437
RS
3588 ;; match with the corresponding regexps. Non-matching switches are
3589 ;; shown literally.
5641671f
NR
3590 (when (eq major-mode 'dired-mode)
3591 (setq mode-name
3592 (let (case-fold-search)
cedf5c9d 3593 (cond ((string-match-p
5641671f
NR
3594 dired-sort-by-name-regexp dired-actual-switches)
3595 "Dired by name")
cedf5c9d 3596 ((string-match-p
5641671f
NR
3597 dired-sort-by-date-regexp dired-actual-switches)
3598 "Dired by date")
3599 (t
3600 (concat "Dired " dired-actual-switches)))))
3601 (force-mode-line-update)))
492d2437 3602
37269466 3603(define-obsolete-function-alias 'dired-sort-set-modeline
2a1e2476 3604 'dired-sort-set-mode-line "24.3")
37269466 3605
492d2437 3606(defun dired-sort-toggle-or-edit (&optional arg)
8d76af4a
CY
3607 "Toggle sorting by date, and refresh the Dired buffer.
3608With a prefix argument, edit the current listing switches instead."
84fc2cfa 3609 (interactive "P")
23fc67ea 3610 (when dired-sort-inhibit
cedf5c9d 3611 (error "Cannot sort this Dired buffer"))
492d2437
RS
3612 (if arg
3613 (dired-sort-other
10195bd6 3614 (read-string "ls switches (must contain -l): " dired-actual-switches))
492d2437
RS
3615 (dired-sort-toggle)))
3616
3617(defun dired-sort-toggle ()
3618 ;; Toggle between sort by date/name. Reverts the buffer.
cedf5c9d
JB
3619 (let ((sorting-by-date (string-match-p dired-sort-by-date-regexp
3620 dired-actual-switches))
8d76af4a
CY
3621 ;; Regexp for finding (possibly embedded) -t switches.
3622 (switch-regexp "\\(\\`\\| \\)-\\([a-su-zA-Z]*\\)\\(t\\)\\([^ ]*\\)")
3623 case-fold-search)
3624 ;; Remove the -t switch.
3625 (while (string-match switch-regexp dired-actual-switches)
3626 (if (and (equal (match-string 2 dired-actual-switches) "")
3627 (equal (match-string 4 dired-actual-switches) ""))
3628 ;; Remove a stand-alone -t switch.
3629 (setq dired-actual-switches
3630 (replace-match "" t t dired-actual-switches))
3631 ;; Remove a switch of the form -XtY for some X and Y.
3632 (setq dired-actual-switches
3633 (replace-match "" t t dired-actual-switches 3))))
3634 ;; Now, if we weren't sorting by date before, add the -t switch.
40714e3d
GM
3635 ;; Some simple-minded ls implementations (eg ftp servers) only
3636 ;; allow a single option string, so try not to add " -t" if possible.
8d76af4a 3637 (unless sorting-by-date
40714e3d
GM
3638 (setq dired-actual-switches
3639 (concat dired-actual-switches
3640 (if (string-match-p "\\`-[[:alnum:]]+\\'"
3641 dired-actual-switches)
3642 "t"
3643 " -t")))))
37269466 3644 (dired-sort-set-mode-line)
492d2437
RS
3645 (revert-buffer))
3646
83fadedf 3647;; Some user code loads dired especially for this.
879fa8d0 3648;; Don't do that--use replace-regexp-in-string instead.
83fadedf
DL
3649(defun dired-replace-in-string (regexp newtext string)
3650 ;; Replace REGEXP with NEWTEXT everywhere in STRING and return result.
3651 ;; NEWTEXT is taken literally---no \\DIGIT escapes will be recognized.
3652 (let ((result "") (start 0) mb me)
3653 (while (string-match regexp string start)
3654 (setq mb (match-beginning 0)
3655 me (match-end 0)
3656 result (concat result (substring string start mb) newtext)
3657 start me))
3658 (concat result (substring string start))))
3659
492d2437 3660(defun dired-sort-other (switches &optional no-revert)
cedf5c9d 3661 "Specify new `ls' SWITCHES for current Dired buffer.
ff3d76aa
SM
3662Values matching `dired-sort-by-date-regexp' or `dired-sort-by-name-regexp'
3663set the minor mode accordingly, others appear literally in the mode line.
3664With optional second arg NO-REVERT, don't refresh the listing afterwards."
e17dba1f 3665 (dired-sort-R-check switches)
492d2437 3666 (setq dired-actual-switches switches)
37269466 3667 (dired-sort-set-mode-line)
492d2437 3668 (or no-revert (revert-buffer)))
e17dba1f 3669
cedf5c9d 3670(defvar-local dired-subdir-alist-pre-R nil
5afea280 3671 "Value of `dired-subdir-alist' before -R switch added.")
e17dba1f
GM
3672
3673(defun dired-sort-R-check (switches)
3674 "Additional processing of -R in ls option string SWITCHES.
3675Saves `dired-subdir-alist' when R is set and restores saved value
3676minus any directories explicitly deleted when R is cleared.
3677To be called first in body of `dired-sort-other', etc."
3678 (cond
cedf5c9d
JB
3679 ((and (string-match-p "R" switches)
3680 (not (string-match-p "R" dired-actual-switches)))
e17dba1f
GM
3681 ;; Adding -R to ls switches -- save `dired-subdir-alist':
3682 (setq dired-subdir-alist-pre-R dired-subdir-alist))
cedf5c9d
JB
3683 ((and (string-match-p "R" dired-actual-switches)
3684 (not (string-match-p "R" switches)))
e17dba1f
GM
3685 ;; Deleting -R from ls switches -- revert to pre-R subdirs
3686 ;; that are still present:
3687 (setq dired-subdir-alist
3688 (if dired-subdir-alist-pre-R
3689 (let (subdirs)
3690 (while dired-subdir-alist-pre-R
3691 (if (assoc (caar dired-subdir-alist-pre-R)
3692 dired-subdir-alist)
3693 ;; subdir still present...
3694 (setq subdirs
3695 (cons (car dired-subdir-alist-pre-R)
3696 subdirs)))
3697 (setq dired-subdir-alist-pre-R
3698 (cdr dired-subdir-alist-pre-R)))
3699 (reverse subdirs))
3700 ;; No pre-R subdir alist, so revert to main directory
3701 ;; listing:
3702 (list (car (reverse dired-subdir-alist))))))))
83fadedf 3703\f
133aad74
JD
3704
3705;;;; Drag and drop support
3706
773933d3 3707(defcustom dired-recursive-copies 'top
c5695d1d
CY
3708 "Whether Dired copies directories recursively.
3709If nil, never copy recursively.
3710`always' means to copy recursively without asking.
3711`top' means to ask for each directory at top level.
3712Any other value means to ask for each directory."
fe02ba07
RS
3713 :type '(choice :tag "Copy directories"
3714 (const :tag "No recursive copies" nil)
3715 (const :tag "Ask for each directory" t)
3716 (const :tag "Ask for each top directory only" top)
3717 (const :tag "Copy directories without asking" always))
3718 :group 'dired)
3719
133aad74 3720(defun dired-dnd-popup-notice ()
fcaed7ce 3721 (message-box
3b1b11e9 3722 "Dired recursive copies are currently disabled.\nSee the variable `dired-recursive-copies'."))
133aad74 3723
e8a11b22 3724(declare-function x-popup-menu "menu.c" (position menu))
133aad74
JD
3725
3726(defun dired-dnd-do-ask-action (uri)
3727 ;; No need to get actions and descriptions from the source,
3728 ;; we only have three actions anyway.
5553077c 3729 (let ((action (x-popup-menu
133aad74
JD
3730 t
3731 (list "What action?"
3732 (cons ""
3733 '(("Copy here" . copy)
3734 ("Move here" . move)
3735 ("Link here" . link)
3736 "--"
3737 ("Cancel" . nil)))))))
3738 (if action
3739 (dired-dnd-handle-local-file uri action)
3740 nil)))
3741
5c4fa70f 3742(declare-function dired-relist-entry "dired-aux" (file))
f36d1cdc 3743(declare-function make-symbolic-link "fileio.c")
5c4fa70f 3744
aa360da1
GM
3745;; Only used when (featurep 'dnd).
3746(declare-function dnd-get-local-file-name "dnd" (uri &optional must-exist))
3747(declare-function dnd-get-local-file-uri "dnd" (uri))
3748
d032d5e7
SM
3749(defvar dired-overwrite-confirmed) ;Defined in dired-aux.
3750
133aad74 3751(defun dired-dnd-handle-local-file (uri action)
cedf5c9d 3752 "Copy, move or link a file to the Dired directory.
133aad74
JD
3753URI is the file to handle, ACTION is one of copy, move, link or ask.
3754Ask means pop up a menu for the user to select one of copy, move or link."
3755 (require 'dired-aux)
361eee8f 3756 (let* ((from (dnd-get-local-file-name uri t))
93ab4de3
CY
3757 (to (when from
3758 (concat (dired-current-directory)
3759 (file-name-nondirectory from)))))
61bfceb6 3760 (when from
93ab4de3 3761 (cond ((eq action 'ask)
61bfceb6 3762 (dired-dnd-do-ask-action uri))
93ab4de3
CY
3763 ;; If copying a directory and dired-recursive-copies is
3764 ;; nil, dired-copy-file fails. Pop up a notice.
3765 ((and (memq action '(copy private))
3766 (file-directory-p from)
3767 (not dired-recursive-copies))
3768 (dired-dnd-popup-notice))
3769 ((memq action '(copy private move link))
3770 (let ((overwrite (and (file-exists-p to)
3771 (y-or-n-p
3772 (format "Overwrite existing file `%s'? " to))))
3773 ;; Binding dired-overwrite-confirmed to nil makes
3774 ;; dired-handle-overwrite a no-op. We instead use
3775 ;; y-or-n-p, which pops a graphical menu.
3776 dired-overwrite-confirmed backup-file)
3777 (when (and overwrite
3778 ;; d-b-o is defined in dired-aux.
3779 (boundp 'dired-backup-overwrite)
3780 dired-backup-overwrite
3781 (setq backup-file
3782 (car (find-backup-file-name to)))
3783 (or (eq dired-backup-overwrite 'always)
3784 (y-or-n-p
3785 (format
3786 "Make backup for existing file `%s'? " to))))
3787 (rename-file to backup-file 0)
3788 (dired-relist-entry backup-file))
3789 (cond ((memq action '(copy private))
3790 (dired-copy-file from to overwrite))
3791 ((eq action 'move)
3792 (dired-rename-file from to overwrite))
3793 ((eq action 'link)
3794 (make-symbolic-link from to overwrite)))
3795 (dired-relist-entry to)
3796 action))))))
133aad74
JD
3797
3798(defun dired-dnd-handle-file (uri action)
cedf5c9d 3799 "Copy, move or link a file to the Dired directory if it is a local file.
133aad74
JD
3800URI is the file to handle. If the hostname in the URI isn't local, do nothing.
3801ACTION is one of copy, move, link or ask.
3802Ask means pop up a menu for the user to select one of copy, move or link."
361eee8f 3803 (let ((local-file (dnd-get-local-file-uri uri)))
133aad74
JD
3804 (if local-file (dired-dnd-handle-local-file local-file action)
3805 nil)))
31b4c848
LH
3806\f
3807
3808;;;; Desktop support
3809
3810(eval-when-compile (require 'desktop))
d7fe6352 3811(declare-function desktop-file-name "desktop" (filename dirname))
31b4c848 3812
295fb2ac 3813(defun dired-desktop-buffer-misc-data (dirname)
31b4c848
LH
3814 "Auxiliary information to be saved in desktop file."
3815 (cons
3816 ;; Value of `dired-directory'.
3817 (if (consp dired-directory)
3818 ;; Directory name followed by list of files.
295fb2ac 3819 (cons (desktop-file-name (car dired-directory) dirname)
31b4c848 3820 (cdr dired-directory))
9d9ee410 3821 ;; Directory name, optionally with shell wildcard.
295fb2ac 3822 (desktop-file-name dired-directory dirname))
31b4c848
LH
3823 ;; Subdirectories in `dired-subdir-alist'.
3824 (cdr
3825 (nreverse
3826 (mapcar
295fb2ac 3827 (function (lambda (f) (desktop-file-name (car f) dirname)))
31b4c848 3828 dired-subdir-alist)))))
133aad74 3829
d032d5e7
SM
3830(defun dired-restore-desktop-buffer (_file-name
3831 _buffer-name
3832 misc-data)
cedf5c9d 3833 "Restore a Dired buffer specified in a desktop file."
d032d5e7 3834 ;; First element of `misc-data' is the value of `dired-directory'.
9d9ee410 3835 ;; This value is a directory name, optionally with shell wildcard or
31b4c848 3836 ;; a directory name followed by list of files.
d032d5e7 3837 (let* ((dired-dir (car misc-data))
31b4c848
LH
3838 (dir (if (consp dired-dir) (car dired-dir) dired-dir)))
3839 (if (file-directory-p (file-name-directory dir))
3840 (progn
3841 (dired dired-dir)
d032d5e7 3842 ;; The following elements of `misc-data' are the keys
31b4c848 3843 ;; from `dired-subdir-alist'.
d032d5e7 3844 (mapc 'dired-maybe-insert-subdir (cdr misc-data))
31b4c848
LH
3845 (current-buffer))
3846 (message "Desktop: Directory %s no longer exists." dir)
3847 (when desktop-missing-file-warning (sit-for 1))
3848 nil)))
133aad74 3849
9e7357b0
AS
3850(add-to-list 'desktop-buffer-mode-handlers
3851 '(dired-mode . dired-restore-desktop-buffer))
a515788d 3852
133aad74 3853\f
7d72f6f1
GM
3854;;; Start of automatically extracted autoloads.
3855\f
c4019074 3856;;;### (autoloads nil "dired-aux" "dired-aux.el" "8861a67d8b72a1110007fba0be161c86")
7d72f6f1
GM
3857;;; Generated autoloads from dired-aux.el
3858
3859(autoload 'dired-diff "dired-aux" "\
3860Compare file at point with file FILE using `diff'.
2fd5e67d 3861If called interactively, prompt for FILE. If the file at point
9d232fc4
JL
3862has a backup file, use that as the default. If the file at point
3863is a backup file, use its original. If the mark is active
2fd5e67d
JL
3864in Transient Mark mode, use the file at the mark as the default.
3865\(That's the mark set by \\[set-mark-command], not by Dired's
3866\\[dired-mark] command.)
35d98877 3867
2fd5e67d
JL
3868FILE is the first file given to `diff'. The file at point
3869is the second file given to `diff'.
3870
3871With prefix arg, prompt for second argument SWITCHES, which is
3872the string of command switches for the third argument of `diff'.
7d72f6f1
GM
3873
3874\(fn FILE &optional SWITCHES)" t nil)
3875
3876(autoload 'dired-backup-diff "dired-aux" "\
3877Diff this file with its backup file or vice versa.
3878Uses the latest backup, if there are several numerical backups.
3879If this file is a backup, diff it with its original.
3880The backup file is the first file given to `diff'.
3881With prefix arg, prompt for argument SWITCHES which is options for `diff'.
3882
3883\(fn &optional SWITCHES)" t nil)
3884
3885(autoload 'dired-compare-directories "dired-aux" "\
3886Mark files with different file attributes in two dired buffers.
3887Compare file attributes of files in the current directory
3888with file attributes in directory DIR2 using PREDICATE on pairs of files
3889with the same name. Mark files for which PREDICATE returns non-nil.
3890Mark files with different names if PREDICATE is nil (or interactively
3891with empty input at the predicate prompt).
3892
3893PREDICATE is a Lisp expression that can refer to the following variables:
3894
3895 size1, size2 - file size in bytes
3896 mtime1, mtime2 - last modification time in seconds, as a float
3897 fa1, fa2 - list of file attributes
3898 returned by function `file-attributes'
3899
3900 where 1 refers to attribute of file in the current dired buffer
3901 and 2 to attribute of file in second dired buffer.
3902
3903Examples of PREDICATE:
3904
3905 (> mtime1 mtime2) - mark newer files
3906 (not (= size1 size2)) - mark files with different sizes
3907 (not (string= (nth 8 fa1) (nth 8 fa2))) - mark files with different modes
3908 (not (and (= (nth 2 fa1) (nth 2 fa2)) - mark files with different UID
3909 (= (nth 3 fa1) (nth 3 fa2)))) and GID.
3910
3911\(fn DIR2 PREDICATE)" t nil)
3912
3913(autoload 'dired-do-chmod "dired-aux" "\
3914Change the mode of the marked (or next ARG) files.
3915Symbolic modes like `g+w' are allowed.
20f70ede
JL
3916Type M-n to pull the file attributes of the file at point
3917into the minibuffer.
7d72f6f1
GM
3918
3919\(fn &optional ARG)" t nil)
3920
3921(autoload 'dired-do-chgrp "dired-aux" "\
3922Change the group of the marked (or next ARG) files.
20f70ede
JL
3923Type M-n to pull the file attributes of the file at point
3924into the minibuffer.
7d72f6f1
GM
3925
3926\(fn &optional ARG)" t nil)
3927
3928(autoload 'dired-do-chown "dired-aux" "\
3929Change the owner of the marked (or next ARG) files.
20f70ede
JL
3930Type M-n to pull the file attributes of the file at point
3931into the minibuffer.
7d72f6f1
GM
3932
3933\(fn &optional ARG)" t nil)
3934
3935(autoload 'dired-do-touch "dired-aux" "\
3936Change the timestamp of the marked (or next ARG) files.
3937This calls touch.
20f70ede
JL
3938Type M-n to pull the file attributes of the file at point
3939into the minibuffer.
7d72f6f1
GM
3940
3941\(fn &optional ARG)" t nil)
3942
3943(autoload 'dired-do-print "dired-aux" "\
3944Print the marked (or next ARG) files.
3945Uses the shell command coming from variables `lpr-command' and
3946`lpr-switches' as default.
3947
3948\(fn &optional ARG)" t nil)
3949
3950(autoload 'dired-clean-directory "dired-aux" "\
3951Flag numerical backups for deletion.
3952Spares `dired-kept-versions' latest versions, and `kept-old-versions' oldest.
3953Positive prefix arg KEEP overrides `dired-kept-versions';
3954Negative prefix arg KEEP overrides `kept-old-versions' with KEEP made positive.
3955
3956To clear the flags on these files, you can use \\[dired-flag-backup-files]
3957with a prefix argument.
3958
3959\(fn KEEP)" t nil)
3960
3961(autoload 'dired-do-async-shell-command "dired-aux" "\
3962Run a shell command COMMAND on the marked files asynchronously.
3963
439f7677
CY
3964Like `dired-do-shell-command', but adds `&' at the end of COMMAND
3965to execute it asynchronously.
3966
3967When operating on multiple files, asynchronous commands
3968are executed in the background on each file in parallel.
3969In shell syntax this means separating the individual commands
3970with `&'. However, when COMMAND ends in `;' or `;&' then commands
3971are executed in the background on each file sequentially waiting
3972for each command to terminate before running the next command.
3973In shell syntax this means separating the individual commands with `;'.
3974
7d72f6f1
GM
3975The output appears in the buffer `*Async Shell Command*'.
3976
3977\(fn COMMAND &optional ARG FILE-LIST)" t nil)
3978
3979(autoload 'dired-do-shell-command "dired-aux" "\
3980Run a shell command COMMAND on the marked files.
439f7677 3981If no files are marked or a numeric prefix arg is given,
7d72f6f1
GM
3982the next ARG files are used. Just \\[universal-argument] means the current file.
3983The prompt mentions the file(s) or the marker, as appropriate.
3984
3985If there is a `*' in COMMAND, surrounded by whitespace, this runs
3986COMMAND just once with the entire file list substituted there.
3987
3988If there is no `*', but there is a `?' in COMMAND, surrounded by
3989whitespace, this runs COMMAND on each file individually with the
3990file name substituted for `?'.
3991
3992Otherwise, this runs COMMAND on each file individually with the
3993file name added at the end of COMMAND (separated by a space).
3994
3995`*' and `?' when not surrounded by whitespace have no special
3996significance for `dired-do-shell-command', and are passed through
cc7f8e29
GM
3997normally to the shell, but you must confirm first.
3998
3999If you want to use `*' as a shell wildcard with whitespace around
4000it, write `*\"\"' in place of just `*'. This is equivalent to just
4001`*' in the shell, but avoids Dired's special handling.
7d72f6f1 4002
439f7677
CY
4003If COMMAND ends in `&', `;', or `;&', it is executed in the
4004background asynchronously, and the output appears in the buffer
4005`*Async Shell Command*'. When operating on multiple files and COMMAND
4006ends in `&', the shell command is executed on each file in parallel.
4007However, when COMMAND ends in `;' or `;&' then commands are executed
4008in the background on each file sequentially waiting for each command
4009to terminate before running the next command. You can also use
4010`dired-do-async-shell-command' that automatically adds `&'.
4011
4012Otherwise, COMMAND is executed synchronously, and the output
4013appears in the buffer `*Shell Command Output*'.
7d72f6f1
GM
4014
4015This feature does not try to redisplay Dired buffers afterward, as
4016there's no telling what files COMMAND may have changed.
4017Type \\[dired-do-redisplay] to redisplay the marked files.
4018
5a0c3f56
JB
4019When COMMAND runs, its working directory is the top-level directory
4020of the Dired buffer, so output files usually are created there
4021instead of in a subdir.
7d72f6f1
GM
4022
4023In a noninteractive call (from Lisp code), you must specify
4024the list of file names explicitly with the FILE-LIST argument, which
4025can be produced by `dired-get-marked-files', for example.
4026
4027\(fn COMMAND &optional ARG FILE-LIST)" t nil)
4028
4029(autoload 'dired-run-shell-command "dired-aux" "\
6a56b5bd 4030
7d72f6f1
GM
4031
4032\(fn COMMAND)" nil nil)
4033
4034(autoload 'dired-do-kill-lines "dired-aux" "\
4035Kill all marked lines (not the files).
4036With a prefix argument, kill that many lines starting with the current line.
4037\(A negative argument kills backward.)
4038If you use this command with a prefix argument to kill the line
4039for a file that is a directory, which you have inserted in the
4040Dired buffer as a subdirectory, then it deletes that subdirectory
4041from the buffer as well.
4042To kill an entire subdirectory (without killing its line in the
4043parent directory), go to its directory header line and use this
4044command with a prefix argument (the value does not matter).
4045
4046\(fn &optional ARG FMT)" t nil)
4047
4048(autoload 'dired-compress-file "dired-aux" "\
6a56b5bd 4049
7d72f6f1
GM
4050
4051\(fn FILE)" nil nil)
4052
4053(autoload 'dired-query "dired-aux" "\
3ef01959
CY
4054Format PROMPT with ARGS, query user, and store the result in SYM.
4055The return value is either nil or t.
7d72f6f1 4056
3ef01959
CY
4057The user may type y or SPC to accept once; n or DEL to skip once;
4058! to accept this and subsequent queries; or q or ESC to decline
4059this and subsequent queries.
4060
4061If SYM is already bound to a non-nil value, this function may
4062return automatically without querying the user. If SYM is !,
4063return t; if SYM is q or ESC, return nil.
4064
4065\(fn SYM PROMPT &rest ARGS)" nil nil)
7d72f6f1
GM
4066
4067(autoload 'dired-do-compress "dired-aux" "\
4068Compress or uncompress marked (or next ARG) files.
4069
4070\(fn &optional ARG)" t nil)
4071
4072(autoload 'dired-do-byte-compile "dired-aux" "\
4073Byte compile marked (or next ARG) Emacs Lisp files.
4074
4075\(fn &optional ARG)" t nil)
4076
4077(autoload 'dired-do-load "dired-aux" "\
4078Load the marked (or next ARG) Emacs Lisp files.
4079
4080\(fn &optional ARG)" t nil)
4081
4082(autoload 'dired-do-redisplay "dired-aux" "\
4083Redisplay all marked (or next ARG) files.
4084If on a subdir line, redisplay that subdirectory. In that case,
4085a prefix arg lets you edit the `ls' switches used for the new listing.
4086
4087Dired remembers switches specified with a prefix arg, so that reverting
4088the buffer will not reset them. However, using `dired-undo' to re-insert
4089or delete subdirectories can bypass this machinery. Hence, you sometimes
4090may have to reset some subdirectory switches after a `dired-undo'.
4091You can reset all subdirectory switches to the default using
4092\\<dired-mode-map>\\[dired-reset-subdir-switches].
4093See Info node `(emacs)Subdir switches' for more details.
4094
4095\(fn &optional ARG TEST-FOR-SUBDIR)" t nil)
4096
4097(autoload 'dired-add-file "dired-aux" "\
6a56b5bd 4098
7d72f6f1
GM
4099
4100\(fn FILENAME &optional MARKER-CHAR)" nil nil)
4101
4102(autoload 'dired-remove-file "dired-aux" "\
6a56b5bd 4103
7d72f6f1
GM
4104
4105\(fn FILE)" nil nil)
4106
4107(autoload 'dired-relist-file "dired-aux" "\
4108Create or update the line for FILE in all Dired buffers it would belong in.
4109
4110\(fn FILE)" nil nil)
4111
4112(autoload 'dired-copy-file "dired-aux" "\
6a56b5bd 4113
7d72f6f1
GM
4114
4115\(fn FROM TO OK-FLAG)" nil nil)
4116
4117(autoload 'dired-rename-file "dired-aux" "\
6a56b5bd 4118
7d72f6f1
GM
4119
4120\(fn FILE NEWNAME OK-IF-ALREADY-EXISTS)" nil nil)
4121
4122(autoload 'dired-create-directory "dired-aux" "\
4123Create a directory called DIRECTORY.
ff854b0b 4124If DIRECTORY already exists, signal an error.
7d72f6f1
GM
4125
4126\(fn DIRECTORY)" t nil)
4127
4128(autoload 'dired-do-copy "dired-aux" "\
4129Copy all marked (or next ARG) files, or copy the current file.
c5695d1d 4130When operating on just the current file, prompt for the new name.
7d72f6f1 4131
c5695d1d
CY
4132When operating on multiple or marked files, prompt for a target
4133directory, and make the new copies in that directory, with the
4134same names as the original files. The initial suggestion for the
4135target directory is the Dired buffer's current directory (or, if
4136`dired-dwim-target' is non-nil, the current directory of a
4137neighboring Dired window).
4138
4139If `dired-copy-preserve-time' is non-nil, this command preserves
4140the modification time of each old file in the copy, similar to
4141the \"-p\" option for the \"cp\" shell command.
4142
4143This command copies symbolic links by creating new ones, similar
4144to the \"-d\" option for the \"cp\" shell command.
7d72f6f1
GM
4145
4146\(fn &optional ARG)" t nil)
4147
4148(autoload 'dired-do-symlink "dired-aux" "\
4149Make symbolic links to current file or all marked (or next ARG) files.
4150When operating on just the current file, you specify the new name.
4151When operating on multiple or marked files, you specify a directory
4152and new symbolic links are made in that directory
4153with the same names that the files currently have. The default
4154suggested for the target directory depends on the value of
4155`dired-dwim-target', which see.
4156
4157For relative symlinks, use \\[dired-do-relsymlink].
4158
4159\(fn &optional ARG)" t nil)
4160
4161(autoload 'dired-do-hardlink "dired-aux" "\
4162Add names (hard links) current file or all marked (or next ARG) files.
4163When operating on just the current file, you specify the new name.
4164When operating on multiple or marked files, you specify a directory
4165and new hard links are made in that directory
4166with the same names that the files currently have. The default
4167suggested for the target directory depends on the value of
4168`dired-dwim-target', which see.
4169
4170\(fn &optional ARG)" t nil)
4171
4172(autoload 'dired-do-rename "dired-aux" "\
4173Rename current file or all marked (or next ARG) files.
4174When renaming just the current file, you specify the new name.
4175When renaming multiple or marked files, you specify a directory.
4176This command also renames any buffers that are visiting the files.
4177The default suggested for the target directory depends on the value
4178of `dired-dwim-target', which see.
4179
4180\(fn &optional ARG)" t nil)
4181
4182(autoload 'dired-do-rename-regexp "dired-aux" "\
4183Rename selected files whose names match REGEXP to NEWNAME.
4184
4185With non-zero prefix argument ARG, the command operates on the next ARG
4186files. Otherwise, it operates on all the marked files, or the current
4187file if none are marked.
4188
4189As each match is found, the user must type a character saying
4190 what to do with it. For directions, type \\[help-command] at that time.
4191NEWNAME may contain \\=\\<n> or \\& as in `query-replace-regexp'.
4192REGEXP defaults to the last regexp used.
4193
4194With a zero prefix arg, renaming by regexp affects the absolute file name.
4195Normally, only the non-directory part of the file name is used and changed.
4196
4197\(fn REGEXP NEWNAME &optional ARG WHOLE-NAME)" t nil)
4198
4199(autoload 'dired-do-copy-regexp "dired-aux" "\
4200Copy selected files whose names match REGEXP to NEWNAME.
4201See function `dired-do-rename-regexp' for more info.
4202
4203\(fn REGEXP NEWNAME &optional ARG WHOLE-NAME)" t nil)
4204
4205(autoload 'dired-do-hardlink-regexp "dired-aux" "\
4206Hardlink selected files whose names match REGEXP to NEWNAME.
4207See function `dired-do-rename-regexp' for more info.
4208
4209\(fn REGEXP NEWNAME &optional ARG WHOLE-NAME)" t nil)
4210
4211(autoload 'dired-do-symlink-regexp "dired-aux" "\
4212Symlink selected files whose names match REGEXP to NEWNAME.
4213See function `dired-do-rename-regexp' for more info.
4214
4215\(fn REGEXP NEWNAME &optional ARG WHOLE-NAME)" t nil)
4216
4217(autoload 'dired-upcase "dired-aux" "\
4218Rename all marked (or next ARG) files to upper case.
4219
4220\(fn &optional ARG)" t nil)
4221
4222(autoload 'dired-downcase "dired-aux" "\
4223Rename all marked (or next ARG) files to lower case.
4224
4225\(fn &optional ARG)" t nil)
4226
4227(autoload 'dired-maybe-insert-subdir "dired-aux" "\
4228Insert this subdirectory into the same dired buffer.
4229If it is already present, just move to it (type \\[dired-do-redisplay] to refresh),
4230 else inserts it at its natural place (as `ls -lR' would have done).
4231With a prefix arg, you may edit the ls switches used for this listing.
4232 You can add `R' to the switches to expand the whole tree starting at
4233 this subdirectory.
4234This function takes some pains to conform to `ls -lR' output.
4235
4236Dired remembers switches specified with a prefix arg, so that reverting
4237the buffer will not reset them. However, using `dired-undo' to re-insert
4238or delete subdirectories can bypass this machinery. Hence, you sometimes
4239may have to reset some subdirectory switches after a `dired-undo'.
4240You can reset all subdirectory switches to the default using
4241\\<dired-mode-map>\\[dired-reset-subdir-switches].
4242See Info node `(emacs)Subdir switches' for more details.
4243
4244\(fn DIRNAME &optional SWITCHES NO-ERROR-IF-NOT-DIR-P)" t nil)
4245
4246(autoload 'dired-insert-subdir "dired-aux" "\
c5695d1d
CY
4247Insert this subdirectory into the same Dired buffer.
4248If it is already present, overwrite the previous entry;
4249 otherwise, insert it at its natural place (as `ls -lR' would
4250 have done).
7d72f6f1
GM
4251With a prefix arg, you may edit the `ls' switches used for this listing.
4252 You can add `R' to the switches to expand the whole tree starting at
4253 this subdirectory.
4254This function takes some pains to conform to `ls -lR' output.
4255
4256\(fn DIRNAME &optional SWITCHES NO-ERROR-IF-NOT-DIR-P)" t nil)
4257
4258(autoload 'dired-prev-subdir "dired-aux" "\
4259Go to previous subdirectory, regardless of level.
4260When called interactively and not on a subdir line, go to this subdir's line.
4261
4262\(fn ARG &optional NO-ERROR-IF-NOT-FOUND NO-SKIP)" t nil)
4263
4264(autoload 'dired-goto-subdir "dired-aux" "\
4265Go to end of header line of DIR in this dired buffer.
4266Return value of point on success, otherwise return nil.
4267The next char is either \\n, or \\r if DIR is hidden.
4268
4269\(fn DIR)" t nil)
4270
4271(autoload 'dired-mark-subdir-files "dired-aux" "\
4272Mark all files except `.' and `..' in current subdirectory.
4273If the Dired buffer shows multiple directories, this command
4274marks the files listed in the subdirectory that point is in.
4275
4276\(fn)" t nil)
4277
4278(autoload 'dired-kill-subdir "dired-aux" "\
4279Remove all lines of current subdirectory.
4280Lower levels are unaffected.
4281
4282\(fn &optional REMEMBER-MARKS)" t nil)
4283
4284(autoload 'dired-tree-up "dired-aux" "\
4285Go up ARG levels in the dired tree.
4286
4287\(fn ARG)" t nil)
4288
4289(autoload 'dired-tree-down "dired-aux" "\
4290Go down in the dired tree.
4291
4292\(fn)" t nil)
4293
4294(autoload 'dired-hide-subdir "dired-aux" "\
4295Hide or unhide the current subdirectory and move to next directory.
4296Optional prefix arg is a repeat factor.
4297Use \\[dired-hide-all] to (un)hide all directories.
4298
4299\(fn ARG)" t nil)
4300
4301(autoload 'dired-hide-all "dired-aux" "\
4302Hide all subdirectories, leaving only their header lines.
4303If there is already something hidden, make everything visible again.
4304Use \\[dired-hide-subdir] to (un)hide a particular subdirectory.
4305
8ae41cbc 4306\(fn &optional IGNORED)" t nil)
7d72f6f1
GM
4307
4308(autoload 'dired-isearch-filenames-setup "dired-aux" "\
4309Set up isearch to search in Dired file names.
4310Intended to be added to `isearch-mode-hook'.
4311
4312\(fn)" nil nil)
4313
4314(autoload 'dired-isearch-filenames "dired-aux" "\
4315Search for a string using Isearch only in file names in the Dired buffer.
4316
4317\(fn)" t nil)
4318
4319(autoload 'dired-isearch-filenames-regexp "dired-aux" "\
4320Search for a regexp using Isearch only in file names in the Dired buffer.
4321
4322\(fn)" t nil)
4323
4324(autoload 'dired-do-isearch "dired-aux" "\
4325Search for a string through all marked files using Isearch.
4326
4327\(fn)" t nil)
4328
4329(autoload 'dired-do-isearch-regexp "dired-aux" "\
4330Search for a regexp through all marked files using Isearch.
4331
4332\(fn)" t nil)
4333
4334(autoload 'dired-do-search "dired-aux" "\
4335Search through all marked files for a match for REGEXP.
4336Stops when a match is found.
4337To continue searching for next match, use command \\[tags-loop-continue].
4338
4339\(fn REGEXP)" t nil)
4340
4341(autoload 'dired-do-query-replace-regexp "dired-aux" "\
4342Do `query-replace-regexp' of FROM with TO, on all marked files.
4343Third arg DELIMITED (prefix arg) means replace only word-delimited matches.
4344If you exit (\\[keyboard-quit], RET or q), you can resume the query replace
4345with the command \\[tags-loop-continue].
4346
4347\(fn FROM TO &optional DELIMITED)" t nil)
4348
4349(autoload 'dired-show-file-type "dired-aux" "\
4350Print the type of FILE, according to the `file' command.
a9e2a8db
GM
4351If you give a prefix to this command, and FILE is a symbolic
4352link, then the type of the file linked to by FILE is printed
4353instead.
7d72f6f1
GM
4354
4355\(fn FILE &optional DEREF-SYMLINKS)" t nil)
4356
4357;;;***
4358\f
1f0d4409 4359;;;### (autoloads nil "dired-x" "dired-x.el" "291bc6e869bf72c900604c45d40f45ed")
7d72f6f1
GM
4360;;; Generated autoloads from dired-x.el
4361
4362(autoload 'dired-jump "dired-x" "\
cedf5c9d
JB
4363Jump to Dired buffer corresponding to current buffer.
4364If in a file, Dired the current directory and move to file's line.
7d72f6f1 4365If in Dired already, pop up a level and goto old directory's line.
cedf5c9d 4366In case the proper Dired file line cannot be found, refresh the dired
7d72f6f1 4367buffer and try again.
cedf5c9d 4368When OTHER-WINDOW is non-nil, jump to Dired buffer in other window.
f5d6548a
JL
4369Interactively with prefix argument, read FILE-NAME and
4370move to its line in dired.
7d72f6f1 4371
f5d6548a 4372\(fn &optional OTHER-WINDOW FILE-NAME)" t nil)
7d72f6f1 4373
42eabe38
AS
4374(autoload 'dired-jump-other-window "dired-x" "\
4375Like \\[dired-jump] (`dired-jump') but in other window.
4376
4377\(fn &optional FILE-NAME)" t nil)
4378
7d72f6f1
GM
4379(autoload 'dired-do-relsymlink "dired-x" "\
4380Relative symlink all marked (or next ARG) files into a directory.
4381Otherwise make a relative symbolic link to the current file.
4382This creates relative symbolic links like
4383
4384 foo -> ../bar/foo
4385
4386not absolute ones like
4387
4388 foo -> /ugly/file/name/that/may/change/any/day/bar/foo
4389
4390For absolute symlinks, use \\[dired-do-symlink].
4391
4392\(fn &optional ARG)" t nil)
4393
4394;;;***
4395\f
4396;;; End of automatically extracted autoloads.
4397
52041219
RS
4398(provide 'dired)
4399
57e15005
BF
4400(run-hooks 'dired-load-hook) ; for your customizations
4401
52041219 4402;;; dired.el ends here