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