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