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