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