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