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