Added *.txt to .cvsignore list.
[emacs.git] / lisp / dired.el
blobbc49f0bf3015c10cebfc7b01997771634ea8fdfb
1 ;;; dired.el --- directory-browsing commands
3 ;; Copyright (C) 1985, 86, 92, 93, 94, 95, 96, 1997, 2000, 2001
4 ;; Free Software Foundation, Inc.
6 ;; Author: Sebastian Kremer <sk@thp.uni-koeln.de>
7 ;; Maintainer: FSF
8 ;; Keywords: files
10 ;; This file is part of GNU Emacs.
12 ;; GNU Emacs is free software; you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation; either version 2, or (at your option)
15 ;; any later version.
17 ;; GNU Emacs is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ;; GNU General Public License for more details.
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs; see the file COPYING. If not, write to the
24 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
25 ;; Boston, MA 02111-1307, USA.
27 ;;; Commentary:
29 ;; This is a major mode for directory browsing and editing. It is
30 ;; 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 ;;; Customizable variables
40 (defgroup dired nil
41 "Directory editing."
42 :group 'environment)
44 (defgroup dired-mark nil
45 "Handling marks in Dired."
46 :prefix "dired-"
47 :group 'dired)
50 ;;;###autoload
51 (defcustom dired-listing-switches "-al"
52 "*Switches passed to `ls' for dired. MUST contain the `l' option.
53 May contain all other options that don't contradict `-l';
54 may contain even `F', `b', `i' and `s'. See also the variable
55 `dired-ls-F-marks-symlinks' concerning the `F' switch.
56 On systems such as MS-DOS and MS-Windows, which use `ls' emulation in Lisp,
57 some of the `ls' switches are not supported; see the doc string of
58 `insert-directory' on ls-lisp.el for more details."
59 :type 'string
60 :group 'dired)
62 ; Don't use absolute paths as /bin should be in any PATH and people
63 ; may prefer /usr/local/gnu/bin or whatever. However, chown is
64 ; usually not in PATH.
66 ;;;###autoload
67 (defvar dired-chown-program
68 (if (memq system-type '(hpux dgux usg-unix-v irix linux gnu/linux))
69 "chown"
70 (if (file-exists-p "/usr/sbin/chown")
71 "/usr/sbin/chown"
72 "/etc/chown"))
73 "Name of chown command (usually `chown' or `/etc/chown').")
75 (defvar dired-chmod-program "chmod"
76 "Name of chmod command (usually `chmod').")
78 ;;;###autoload
79 (defcustom dired-ls-F-marks-symlinks nil
80 "*Informs dired about how `ls -lF' marks symbolic links.
81 Set this to t if `ls' (or whatever program is specified by
82 `insert-directory-program') with `-lF' marks the symbolic link
83 itself with a trailing @ (usually the case under Ultrix).
85 Example: if `ln -s foo bar; ls -F bar' gives `bar -> foo', set it to
86 nil (the default), if it gives `bar@ -> foo', set it to t.
88 Dired checks if there is really a @ appended. Thus, if you have a
89 marking `ls' program on one host and a non-marking on another host, and
90 don't care about symbolic links which really end in a @, you can
91 always set this variable to t."
92 :type 'boolean
93 :group 'dired-mark)
95 ;;;###autoload
96 (defcustom dired-trivial-filenames "^\\.\\.?$\\|^#"
97 "*Regexp of files to skip when finding first file of a directory.
98 A value of nil means move to the subdir line.
99 A value of t means move to first file."
100 :type '(choice (const :tag "Move to subdir" nil)
101 (const :tag "Move to first" t)
102 regexp)
103 :group 'dired)
105 ;;;###autoload
106 (defcustom dired-keep-marker-rename t
107 ;; Use t as default so that moved files "take their markers with them".
108 "*Controls marking of renamed files.
109 If t, files keep their previous marks when they are renamed.
110 If a character, renamed files (whether previously marked or not)
111 are afterward marked with that character."
112 :type '(choice (const :tag "Keep" t)
113 (character :tag "Mark"))
114 :group 'dired-mark)
116 ;;;###autoload
117 (defcustom dired-keep-marker-copy ?C
118 "*Controls marking of copied files.
119 If t, copied files are marked if and as the corresponding original files were.
120 If a character, copied files are unconditionally marked with that character."
121 :type '(choice (const :tag "Keep" t)
122 (character :tag "Mark"))
123 :group 'dired-mark)
125 ;;;###autoload
126 (defcustom dired-keep-marker-hardlink ?H
127 "*Controls marking of newly made hard links.
128 If t, they are marked if and as the files linked to were marked.
129 If a character, new links are unconditionally marked with that character."
130 :type '(choice (const :tag "Keep" t)
131 (character :tag "Mark"))
132 :group 'dired-mark)
134 ;;;###autoload
135 (defcustom dired-keep-marker-symlink ?Y
136 "*Controls marking of newly made symbolic links.
137 If t, they are marked if and as the files linked to were marked.
138 If a character, new links are unconditionally marked with that character."
139 :type '(choice (const :tag "Keep" t)
140 (character :tag "Mark"))
141 :group 'dired-mark)
143 ;;;###autoload
144 (defcustom dired-dwim-target nil
145 "*If non-nil, dired tries to guess a default target directory.
146 This means: if there is a dired buffer displayed in the next window,
147 use its current subdir, instead of the current subdir of this dired buffer.
149 The target is used in the prompt for file copy, rename etc."
150 :type 'boolean
151 :group 'dired)
153 ;;;###autoload
154 (defcustom dired-copy-preserve-time t
155 "*If non-nil, Dired preserves the last-modified time in a file copy.
156 \(This works on only some systems.)"
157 :type 'boolean
158 :group 'dired)
160 (defcustom dired-free-space-program "df"
161 "*Program to get the amount of free space on a file system.
162 We assume the output has the format of `df'.
163 The value of this variable must be just a command name or file name;
164 if you want to specify options, use `dired-free-space-args'.
166 A value of nil disables this feature."
167 :type '(choice (string :tag "Program") (const :tag "None" nil))
168 :group 'dired)
170 (defcustom dired-free-space-args "-Pk"
171 "*Options to use when running `dired-free-space-program'."
172 :type 'string
173 :group 'dired)
175 ;;; Hook variables
177 (defvar dired-load-hook nil
178 "Run after loading dired.
179 You can customize key bindings or load extensions with this.")
181 (defvar dired-mode-hook nil
182 "Run at the very end of dired-mode.")
184 (defvar dired-before-readin-hook nil
185 "This hook is run before a dired buffer is read in (created or reverted).")
187 (defvar dired-after-readin-hook nil
188 "Hook run after each time a file or directory is read by Dired.
189 After each listing of a file or directory, this hook is run
190 with the buffer narrowed to the listing.")
191 ;; Note this can't simply be run inside function `dired-ls' as the hook
192 ;; functions probably depend on the dired-subdir-alist to be OK.
194 ;;; Internal variables
196 (defvar dired-marker-char ?* ; the answer is 42
197 ;; so that you can write things like
198 ;; (let ((dired-marker-char ?X))
199 ;; ;; great code using X markers ...
200 ;; )
201 ;; For example, commands operating on two sets of files, A and B.
202 ;; Or marking files with digits 0-9. This could implicate
203 ;; concentric sets or an order for the marked files.
204 ;; The code depends on dynamic scoping on the marker char.
205 "In Dired, the current mark character.
206 This is what the `do' commands look for and what the `mark' commands store.")
208 (defvar dired-del-marker ?D
209 "Character used to flag files for deletion.")
211 (defvar dired-shrink-to-fit
213 ;; I see no reason ever to make this nil -- rms.
214 ;; (> baud-rate search-slow-speed)
215 "Non-nil means Dired shrinks the display buffer to fit the marked files.")
217 (defvar dired-flagging-regexp nil);; Last regexp used to flag files.
219 (defvar dired-file-version-alist)
221 (defvar dired-directory nil
222 "The directory name or shell wildcard that was used as argument to `ls'.
223 Local to each dired buffer. May be a list, in which case the car is the
224 directory name and the cdr is the actual files to list.")
226 (defvar dired-actual-switches nil
227 "The value of `dired-listing-switches' used to make this buffer's text.")
229 (defvar dired-re-inode-size "[0-9 \t]*"
230 "Regexp for optional initial inode and file size as made by `ls -i -s'.")
232 ;; These regexps must be tested at beginning-of-line, but are also
233 ;; used to search for next matches, so neither omitting "^" nor
234 ;; replacing "^" by "\n" (to make it slightly faster) will work.
236 (defvar dired-re-mark "^[^ \n]")
237 ;; "Regexp matching a marked line.
238 ;; Important: the match ends just after the marker."
239 (defvar dired-re-maybe-mark "^. ")
240 ;; The [^:] part after "d" and "l" is to avoid confusion with the
241 ;; DOS/Windows-style drive letters in directory names, like in "d:/foo".
242 (defvar dired-re-dir (concat dired-re-maybe-mark dired-re-inode-size "d[^:]"))
243 (defvar dired-re-sym (concat dired-re-maybe-mark dired-re-inode-size "l[^:]"))
244 (defvar dired-re-exe;; match ls permission string of an executable file
245 (mapconcat (function
246 (lambda (x)
247 (concat dired-re-maybe-mark dired-re-inode-size x)))
248 '("-[-r][-w][xs][-r][-w].[-r][-w]."
249 "-[-r][-w].[-r][-w][xs][-r][-w]."
250 "-[-r][-w].[-r][-w].[-r][-w][xst]")
251 "\\|"))
252 (defvar dired-re-perms "[-bcdlps][-r][-w].[-r][-w].[-r][-w].")
253 (defvar dired-re-dot "^.* \\.\\.?$")
255 ;; The subdirectory names in this list are expanded.
256 (defvar dired-subdir-alist nil
257 "Association list of subdirectories and their buffer positions.
258 Each subdirectory has an element: (DIRNAME . STARTMARKER).
259 The order of elements is the reverse of the order in the buffer.
260 In simple cases, this list contains one element.")
262 (defvar dired-subdir-regexp "^. \\([^\n\r]+\\)\\(:\\)[\n\r]"
263 "Regexp matching a maybe hidden subdirectory line in `ls -lR' output.
264 Subexpression 1 is the subdirectory proper, no trailing colon.
265 The match starts at the beginning of the line and ends after the end
266 of the line (\\n or \\r).
267 Subexpression 2 must end right before the \\n or \\r.")
269 (defvar dired-font-lock-keywords
270 (list
272 ;; Directory headers.
273 (list dired-subdir-regexp '(1 font-lock-type-face))
275 ;; We make heavy use of MATCH-ANCHORED, since the regexps don't identify the
276 ;; file name itself. We search for Dired defined regexps, and then use the
277 ;; Dired defined function `dired-move-to-filename' before searching for the
278 ;; simple regexp ".+". It is that regexp which matches the file name.
280 ;; Dired marks.
281 (list dired-re-mark
282 '(0 font-lock-constant-face)
283 '(".+" (dired-move-to-filename) nil (0 font-lock-warning-face)))
284 ;; People who are paranoid about security would consider this more
285 ;; important than other things such as whether it is a directory.
286 ;; But we don't want to encourage paranoia, so our default
287 ;; should be what's most useful for non-paranoids. -- rms.
288 ;;; ;;
289 ;;; ;; Files that are group or world writable.
290 ;;; (list (concat dired-re-maybe-mark dired-re-inode-size
291 ;;; "\\([-d]\\(....w....\\|.......w.\\)\\)")
292 ;;; '(1 font-lock-comment-face)
293 ;;; '(".+" (dired-move-to-filename) nil (0 font-lock-comment-face)))
295 ;; Subdirectories.
296 (list dired-re-dir
297 '(".+" (dired-move-to-filename) nil (0 font-lock-function-name-face)))
299 ;; Symbolic links.
300 (list dired-re-sym
301 '(".+" (dired-move-to-filename) nil (0 font-lock-keyword-face)))
303 ;; Files suffixed with `completion-ignored-extensions'.
304 '(eval .
305 (let ((extensions (mapcar 'regexp-quote completion-ignored-extensions)))
306 ;; It is quicker to first find just an extension, then go back to the
307 ;; start of that file name. So we do this complex MATCH-ANCHORED form.
308 (list (concat "\\(" (mapconcat 'identity extensions "\\|") "\\|#\\)$")
309 '(".+" (dired-move-to-filename) nil (0 font-lock-string-face))))))
310 "Additional expressions to highlight in Dired mode.")
312 ;;; Macros must be defined before they are used, for the byte compiler.
314 ;; Mark all files for which CONDITION evals to non-nil.
315 ;; CONDITION is evaluated on each line, with point at beginning of line.
316 ;; MSG is a noun phrase for the type of files being marked.
317 ;; It should end with a noun that can be pluralized by adding `s'.
318 ;; Return value is the number of files marked, or nil if none were marked.
319 (defmacro dired-mark-if (predicate msg)
320 `(let (buffer-read-only count)
321 (save-excursion
322 (setq count 0)
323 (if ,msg (message "Marking %ss..." ,msg))
324 (goto-char (point-min))
325 (while (not (eobp))
326 (if ,predicate
327 (progn
328 (delete-char 1)
329 (insert dired-marker-char)
330 (setq count (1+ count))))
331 (forward-line 1))
332 (if ,msg (message "%s %s%s %s%s."
333 count
334 ,msg
335 (dired-plural-s count)
336 (if (eq dired-marker-char ?\040) "un" "")
337 (if (eq dired-marker-char dired-del-marker)
338 "flagged" "marked"))))
339 (and (> count 0) count)))
341 (defmacro dired-map-over-marks (body arg &optional show-progress)
342 "Eval BODY with point on each marked line. Return a list of BODY's results.
343 If no marked file could be found, execute BODY on the current line.
344 If ARG is an integer, use the next ARG (or previous -ARG, if ARG<0)
345 files instead of the marked files.
346 In that case point is dragged along. This is so that commands on
347 the next ARG (instead of the marked) files can be chained easily.
348 If ARG is otherwise non-nil, use current file instead.
349 If optional third arg SHOW-PROGRESS evaluates to non-nil,
350 redisplay the dired buffer after each file is processed.
351 No guarantee is made about the position on the marked line.
352 BODY must ensure this itself if it depends on this.
353 Search starts at the beginning of the buffer, thus the car of the list
354 corresponds to the line nearest to the buffer's bottom. This
355 is also true for (positive and negative) integer values of ARG.
356 BODY should not be too long as it is expanded four times."
358 ;;Warning: BODY must not add new lines before point - this may cause an
359 ;;endless loop.
360 ;;This warning should not apply any longer, sk 2-Sep-1991 14:10.
361 `(prog1
362 (let (buffer-read-only case-fold-search found results)
363 (if ,arg
364 (if (integerp ,arg)
365 (progn ;; no save-excursion, want to move point.
366 (dired-repeat-over-lines
367 ,arg
368 (function (lambda ()
369 (if ,show-progress (sit-for 0))
370 (setq results (cons ,body results)))))
371 (if (< ,arg 0)
372 (nreverse results)
373 results))
374 ;; non-nil, non-integer ARG means use current file:
375 (list ,body))
376 (let ((regexp (dired-marker-regexp)) next-position)
377 (save-excursion
378 (goto-char (point-min))
379 ;; remember position of next marked file before BODY
380 ;; can insert lines before the just found file,
381 ;; confusing us by finding the same marked file again
382 ;; and again and...
383 (setq next-position (and (re-search-forward regexp nil t)
384 (point-marker))
385 found (not (null next-position)))
386 (while next-position
387 (goto-char next-position)
388 (if ,show-progress (sit-for 0))
389 (setq results (cons ,body results))
390 ;; move after last match
391 (goto-char next-position)
392 (forward-line 1)
393 (set-marker next-position nil)
394 (setq next-position (and (re-search-forward regexp nil t)
395 (point-marker)))))
396 (if found
397 results
398 (list ,body)))))
399 ;; save-excursion loses, again
400 (dired-move-to-filename)))
402 (defun dired-get-marked-files (&optional localp arg)
403 "Return the marked files' names as list of strings.
404 The list is in the same order as the buffer, that is, the car is the
405 first marked file.
406 Values returned are normally absolute pathnames.
407 Optional arg LOCALP as in `dired-get-filename'.
408 Optional second argument ARG forces to use other files. If ARG is an
409 integer, use the next ARG files. If ARG is otherwise non-nil, use
410 current file. Usually ARG comes from the current prefix arg."
411 (save-excursion
412 (nreverse (dired-map-over-marks (dired-get-filename localp) arg))))
415 ;; Function dired-ls is redefinable for VMS, ange-ftp, Prospero or
416 ;; other special applications.
418 ;; The dired command
420 (defun dired-read-dir-and-switches (str)
421 ;; For use in interactive.
422 (reverse (list
423 (if current-prefix-arg
424 (read-string "Dired listing switches: "
425 dired-listing-switches))
426 (read-file-name (format "Dired %s(directory): " str)
427 nil default-directory nil))))
429 ;;;###autoload (define-key ctl-x-map "d" 'dired)
430 ;;;###autoload
431 (defun dired (dirname &optional switches)
432 "\"Edit\" directory DIRNAME--delete, rename, print, etc. some files in it.
433 Optional second argument SWITCHES specifies the `ls' options used.
434 \(Interactively, use a prefix argument to be able to specify SWITCHES.)
435 Dired displays a list of files in DIRNAME (which may also have
436 shell wildcards appended to select certain files). If DIRNAME is a cons,
437 its first element is taken as the directory name and the rest as an explicit
438 list of files to make directory entries for.
439 \\<dired-mode-map>\
440 You can move around in it with the usual commands.
441 You can flag files for deletion with \\[dired-flag-file-deletion] and then
442 delete them by typing \\[dired-do-flagged-delete].
443 Type \\[describe-mode] after entering dired for more info.
445 If DIRNAME is already in a dired buffer, that buffer is used without refresh."
446 ;; Cannot use (interactive "D") because of wildcards.
447 (interactive (dired-read-dir-and-switches ""))
448 (switch-to-buffer (dired-noselect dirname switches)))
450 ;;;###autoload (define-key ctl-x-4-map "d" 'dired-other-window)
451 ;;;###autoload
452 (defun dired-other-window (dirname &optional switches)
453 "\"Edit\" directory DIRNAME. Like `dired' but selects in another window."
454 (interactive (dired-read-dir-and-switches "in other window "))
455 (switch-to-buffer-other-window (dired-noselect dirname switches)))
457 ;;;###autoload (define-key ctl-x-5-map "d" 'dired-other-frame)
458 ;;;###autoload
459 (defun dired-other-frame (dirname &optional switches)
460 "\"Edit\" directory DIRNAME. Like `dired' but makes a new frame."
461 (interactive (dired-read-dir-and-switches "in other frame "))
462 (switch-to-buffer-other-frame (dired-noselect dirname switches)))
464 ;;;###autoload
465 (defun dired-noselect (dir-or-list &optional switches)
466 "Like `dired' but returns the dired buffer as value, does not select it."
467 (or dir-or-list (setq dir-or-list default-directory))
468 ;; This loses the distinction between "/foo/*/" and "/foo/*" that
469 ;; some shells make:
470 (let (dirname initially-was-dirname)
471 (if (consp dir-or-list)
472 (setq dirname (car dir-or-list))
473 (setq dirname dir-or-list))
474 (setq initially-was-dirname
475 (string= (file-name-as-directory dirname) dirname))
476 (setq dirname (abbreviate-file-name
477 (expand-file-name (directory-file-name dirname))))
478 (if find-file-visit-truename
479 (setq dirname (file-truename dirname)))
480 ;; If the argument was syntactically a directory name not a file name,
481 ;; or if it happens to name a file that is a directory,
482 ;; convert it syntactically to a directory name.
483 ;; The reason for checking initially-was-dirname
484 ;; and not just file-directory-p
485 ;; is that file-directory-p is slow over ftp.
486 (if (or initially-was-dirname (file-directory-p dirname))
487 (setq dirname (file-name-as-directory dirname)))
488 (if (consp dir-or-list)
489 (setq dir-or-list (cons dirname (cdr dir-or-list)))
490 (setq dir-or-list dirname))
491 (dired-internal-noselect dir-or-list switches)))
493 ;; Separate function from dired-noselect for the sake of dired-vms.el.
494 (defun dired-internal-noselect (dir-or-list &optional switches mode)
495 ;; If there is an existing dired buffer for DIRNAME, just leave
496 ;; buffer as it is (don't even call dired-revert).
497 ;; This saves time especially for deep trees or with ange-ftp.
498 ;; The user can type `g'easily, and it is more consistent with find-file.
499 ;; But if SWITCHES are given they are probably different from the
500 ;; buffer's old value, so call dired-sort-other, which does
501 ;; revert the buffer.
502 ;; A pity we can't possibly do "Directory has changed - refresh? "
503 ;; like find-file does.
504 ;; Optional argument MODE is passed to dired-find-buffer-nocreate,
505 ;; see there.
506 (let* ((dirname (if (consp dir-or-list) (car dir-or-list) dir-or-list))
507 ;; The following line used to use dir-or-list.
508 ;; That never found an existing buffer, in the case
509 ;; where it is a list.
510 (buffer (dired-find-buffer-nocreate dirname mode))
511 ;; note that buffer already is in dired-mode, if found
512 (new-buffer-p (not buffer))
513 (old-buf (current-buffer)))
514 (or buffer
515 (let ((default-major-mode 'fundamental-mode))
516 ;; We don't want default-major-mode to run hooks and set auto-fill
517 ;; or whatever, now that dired-mode does not
518 ;; kill-all-local-variables any longer.
519 (setq buffer (create-file-buffer (directory-file-name dirname)))))
520 (set-buffer buffer)
521 (if (not new-buffer-p) ; existing buffer ...
522 (cond (switches ; ... but new switches
523 ;; file list may have changed
524 (if (consp dir-or-list)
525 (setq dired-directory dir-or-list))
526 ;; this calls dired-revert
527 (dired-sort-other switches))
528 ;; If directory has changed on disk, offer to revert.
529 ((if (let ((attributes (file-attributes dirname))
530 (modtime (visited-file-modtime)))
531 (or (eq modtime 0)
532 (not (eq (car attributes) t))
533 (and (= (car (nth 5 attributes)) (car modtime))
534 (= (nth 1 (nth 5 attributes)) (cdr modtime)))))
536 (message "%s"
537 (substitute-command-keys
538 "Directory has changed on disk; type \\[revert-buffer] to update Dired")))))
539 ;; Else a new buffer
540 (setq default-directory
541 ;; We can do this unconditionally
542 ;; because dired-noselect ensures that the name
543 ;; is passed in directory name syntax
544 ;; if it was the name of a directory at all.
545 (file-name-directory dirname))
546 (or switches (setq switches dired-listing-switches))
547 (if mode (funcall mode)
548 (dired-mode dirname switches))
549 ;; default-directory and dired-actual-switches are set now
550 ;; (buffer-local), so we can call dired-readin:
551 (let ((failed t))
552 (unwind-protect
553 (progn (dired-readin dir-or-list buffer)
554 (setq failed nil))
555 ;; dired-readin can fail if parent directories are inaccessible.
556 ;; Don't leave an empty buffer around in that case.
557 (if failed (kill-buffer buffer))))
558 ;; No need to narrow since the whole buffer contains just
559 ;; dired-readin's output, nothing else. The hook can
560 ;; successfully use dired functions (e.g. dired-get-filename)
561 ;; as the subdir-alist has been built in dired-readin.
562 (run-hooks 'dired-after-readin-hook)
563 (goto-char (point-min))
564 (dired-initial-position dirname))
565 (set-buffer old-buf)
566 buffer))
568 (defvar dired-buffers nil
569 ;; Enlarged by dired-advertise
570 ;; Queried by function dired-buffers-for-dir. When this detects a
571 ;; killed buffer, it is removed from this list.
572 "Alist of expanded directories and their associated dired buffers.")
574 (defun dired-find-buffer-nocreate (dirname &optional mode)
575 ;; This differs from dired-buffers-for-dir in that it does not consider
576 ;; subdirs of default-directory and searches for the first match only.
577 ;; Also, the major mode must be MODE.
578 (let (found (blist dired-buffers)) ; was (buffer-list)
579 (or mode (setq mode 'dired-mode))
580 (while blist
581 (if (null (buffer-name (cdr (car blist))))
582 (setq blist (cdr blist))
583 (save-excursion
584 (set-buffer (cdr (car blist)))
585 (if (and (eq major-mode mode)
586 (if (consp dired-directory)
587 (equal (car dired-directory) dirname)
588 (equal dired-directory dirname)))
589 (setq found (cdr (car blist))
590 blist nil)
591 (setq blist (cdr blist))))))
592 found))
595 ;; Read in a new dired buffer
597 ;; dired-readin differs from dired-insert-subdir in that it accepts
598 ;; wildcards, erases the buffer, and builds the subdir-alist anew
599 ;; (including making it buffer-local and clearing it first).
600 (defun dired-readin (dir-or-list buffer)
601 ;; default-directory and dired-actual-switches must be buffer-local
602 ;; and initialized by now.
603 ;; Thus we can test (equal default-directory dirname) instead of
604 ;; (file-directory-p dirname) and save a filesystem transaction.
605 ;; Also, we can run this hook which may want to modify the switches
606 ;; based on default-directory, e.g. with ange-ftp to a SysV host
607 ;; where ls won't understand -Al switches.
608 (let (dirname
609 (indent-tabs-mode nil))
610 (if (consp dir-or-list)
611 (setq dirname (car dir-or-list))
612 (setq dirname dir-or-list))
613 (setq dirname (expand-file-name dirname))
614 (if (consp dir-or-list)
615 (setq dir-or-list (cons dirname (cdr dir-or-list))))
616 (run-hooks 'dired-before-readin-hook)
617 (save-excursion
618 (message "Reading directory %s..." dirname)
619 (set-buffer buffer)
620 (let (buffer-read-only (failed t))
621 (widen)
622 (erase-buffer)
623 (dired-readin-insert dir-or-list)
624 (indent-rigidly (point-min) (point-max) 2)
625 ;; We need this to make the root dir have a header line as all
626 ;; other subdirs have:
627 (goto-char (point-min))
628 (if (not (looking-at "^ /.*:$"))
629 (dired-insert-headerline default-directory))
630 ;; can't run dired-after-readin-hook here, it may depend on the subdir
631 ;; alist to be OK.
633 (message "Reading directory %s...done" dirname)
634 ;; Must first make alist buffer local and set it to nil because
635 ;; dired-build-subdir-alist will call dired-clear-alist first
636 (set (make-local-variable 'dired-subdir-alist) nil)
637 (dired-build-subdir-alist)
638 (let ((attributes (file-attributes dirname)))
639 (if (eq (car attributes) t)
640 (set-visited-file-modtime (nth 5 attributes))))
641 (set-buffer-modified-p nil))))
643 ;; Subroutines of dired-readin
645 (defun dired-readin-insert (dir-or-list)
646 ;; Just insert listing for the passed-in directory or
647 ;; directory-and-file list, assuming a clean buffer.
648 (let (dirname)
649 (if (consp dir-or-list)
650 (setq dirname (car dir-or-list))
651 (setq dirname dir-or-list))
652 ;; Expand before comparing in case one or both have been abbreviated.
653 (if (and (equal (expand-file-name default-directory)
654 (expand-file-name dirname))
655 (not (consp dir-or-list)))
656 ;; If we are reading a whole single directory...
657 (dired-insert-directory dir-or-list dired-actual-switches nil t)
658 (if (not (file-readable-p
659 (directory-file-name (file-name-directory dirname))))
660 (error "Directory %s inaccessible or nonexistent" dirname)
661 ;; Else assume it contains wildcards,
662 ;; unless it is an explicit list of files.
663 (dired-insert-directory dir-or-list dired-actual-switches
664 (not (listp dir-or-list)))
665 (or (consp dir-or-list)
666 (save-excursion ;; insert wildcard instead of total line:
667 (goto-char (point-min))
668 (insert "wildcard " (file-name-nondirectory dirname) "\n")))))))
670 (defun dired-insert-directory (dir-or-list switches &optional wildcard full-p)
671 ;; Do the right thing whether dir-or-list is atomic or not. If it is,
672 ;; inset all files listed in the cdr (the car is the passed-in directory
673 ;; list).
674 (let ((opoint (point))
675 (process-environment (copy-sequence process-environment))
676 end)
677 ;; We used to specify the C locale here, to force English month names;
678 ;; but this should not be necessary any more,
679 ;; with the new value of dired-move-to-filename-regexp.
680 (if (consp dir-or-list)
681 ;; In this case, use the file names in the cdr
682 ;; exactly as originally given to dired-noselect.
683 (mapcar
684 (function (lambda (x) (insert-directory x switches wildcard full-p)))
685 (cdr dir-or-list))
686 ;; Expand the file name here because it may have been abbreviated
687 ;; in dired-noselect.
688 (insert-directory (expand-file-name dir-or-list) switches wildcard full-p)
689 (when (and full-p dired-free-space-program)
690 (save-excursion
691 (goto-char (point-min))
692 (when (re-search-forward "total [0-9]+$" nil t)
693 (insert " free ")
694 ;; Non-Posix systems don't always have dired-free-space-program,
695 ;; but might have an equivalent system call.
696 (if (fboundp 'file-system-info)
697 (let ((beg (point))
698 (fsinfo (file-system-info dir-or-list)))
699 (if fsinfo
700 (insert
701 (format "%.0f" (/ (nth 2 fsinfo) 1024)))
702 ;; file-system-info failed; delete " free ".
703 (delete-region (- beg 7) beg)))
704 (let ((beg (point)))
705 (condition-case nil
706 (if (zerop (call-process dired-free-space-program nil t nil
707 dired-free-space-args
708 (expand-file-name dir-or-list)))
709 (progn
710 (goto-char beg)
711 (forward-line 1)
712 (skip-chars-forward "^ \t")
713 (forward-word 2)
714 (skip-chars-forward " \t")
715 (delete-region beg (point))
716 (forward-word 1)
717 (delete-region (point)
718 (progn (forward-line 1) (point))))
719 ;; The dired-free-space-program failed; delete its output
720 (delete-region (- beg 7) (point)))
721 (error (delete-region (- beg 7) (point))))))))))
722 ;; Quote certain characters, unless ls quoted them for us.
723 (if (not (string-match "b" dired-actual-switches))
724 (save-excursion
725 (setq end (point-marker))
726 (goto-char opoint)
727 (while (search-forward "\\" end t)
728 (replace-match "\\\\" nil t))
729 (goto-char opoint)
730 (while (search-forward "\^m" end t)
731 (replace-match "\\015" nil t))
732 (set-marker end nil)))
733 (dired-insert-set-properties opoint (point)))
734 (setq dired-directory dir-or-list))
736 ;; Make the file names highlight when the mouse is on them.
737 (defun dired-insert-set-properties (beg end)
738 (save-excursion
739 (goto-char beg)
740 (while (< (point) end)
741 (condition-case nil
742 (if (dired-move-to-filename)
743 (add-text-properties
744 (point)
745 (save-excursion
746 (dired-move-to-end-of-filename)
747 (point))
748 '(mouse-face highlight
749 help-echo "mouse-2: visit this file in other window")))
750 (error nil))
751 (forward-line 1))))
753 (defun dired-insert-headerline (dir);; also used by dired-insert-subdir
754 ;; Insert DIR's headerline with no trailing slash, exactly like ls
755 ;; would, and put cursor where dired-build-subdir-alist puts subdir
756 ;; boundaries.
757 (save-excursion (insert " " (directory-file-name dir) ":\n")))
760 ;; Reverting a dired buffer
762 (defun dired-revert (&optional arg noconfirm)
763 ;; Reread the dired buffer. Must also be called after
764 ;; dired-actual-switches have changed.
765 ;; Should not fail even on completely garbaged buffers.
766 ;; Preserves old cursor, marks/flags, hidden-p.
767 (widen) ; just in case user narrowed
768 (let ((opoint (point))
769 (ofile (dired-get-filename nil t))
770 (mark-alist nil) ; save marked files
771 (hidden-subdirs (dired-remember-hidden))
772 (old-subdir-alist (cdr (reverse dired-subdir-alist))) ; except pwd
773 (case-fold-search nil) ; we check for upper case ls flags
774 buffer-read-only)
775 (goto-char (point-min))
776 (setq mark-alist;; only after dired-remember-hidden since this unhides:
777 (dired-remember-marks (point-min) (point-max)))
778 ;; treat top level dir extra (it may contain wildcards)
779 (dired-uncache
780 (if (consp dired-directory) (car dired-directory) dired-directory))
781 (dired-readin dired-directory (current-buffer))
782 (let ((dired-after-readin-hook nil))
783 ;; don't run that hook for each subdir...
784 (dired-insert-old-subdirs old-subdir-alist))
785 (dired-mark-remembered mark-alist) ; mark files that were marked
786 ;; ... run the hook for the whole buffer, and only after markers
787 ;; have been reinserted (else omitting in dired-x would omit marked files)
788 (run-hooks 'dired-after-readin-hook) ; no need to narrow
789 (or (and ofile (dired-goto-file ofile)) ; move cursor to where it
790 (goto-char opoint)) ; was before
791 (dired-move-to-filename)
792 (save-excursion ; hide subdirs that were hidden
793 (mapcar (function (lambda (dir)
794 (if (dired-goto-subdir dir)
795 (dired-hide-subdir 1))))
796 hidden-subdirs)))
797 ;; outside of the let scope
798 ;;; Might as well not override the user if the user changed this.
799 ;;; (setq buffer-read-only t)
802 ;; Subroutines of dired-revert
803 ;; Some of these are also used when inserting subdirs.
805 (defun dired-remember-marks (beg end)
806 ;; Return alist of files and their marks, from BEG to END.
807 (if selective-display ; must unhide to make this work.
808 (let (buffer-read-only)
809 (subst-char-in-region beg end ?\r ?\n)))
810 (let (fil chr alist)
811 (save-excursion
812 (goto-char beg)
813 (while (re-search-forward dired-re-mark end t)
814 (if (setq fil (dired-get-filename nil t))
815 (setq chr (preceding-char)
816 alist (cons (cons fil chr) alist)))))
817 alist))
819 ;; Mark all files remembered in ALIST.
820 ;; Each element of ALIST looks like (FILE . MARKERCHAR).
821 (defun dired-mark-remembered (alist)
822 (let (elt fil chr)
823 (while alist
824 (setq elt (car alist)
825 alist (cdr alist)
826 fil (car elt)
827 chr (cdr elt))
828 (if (dired-goto-file fil)
829 (save-excursion
830 (beginning-of-line)
831 (delete-char 1)
832 (insert chr))))))
834 ;; Return a list of names of subdirs currently hidden.
835 (defun dired-remember-hidden ()
836 (let ((l dired-subdir-alist) dir pos result)
837 (while l
838 (setq dir (car (car l))
839 pos (cdr (car l))
840 l (cdr l))
841 (goto-char pos)
842 (skip-chars-forward "^\r\n")
843 (if (eq (following-char) ?\r)
844 (setq result (cons dir result))))
845 result))
847 ;; Try to insert all subdirs that were displayed before,
848 ;; according to the former subdir alist OLD-SUBDIR-ALIST.
849 (defun dired-insert-old-subdirs (old-subdir-alist)
850 (or (string-match "R" dired-actual-switches)
851 (let (elt dir)
852 (while old-subdir-alist
853 (setq elt (car old-subdir-alist)
854 old-subdir-alist (cdr old-subdir-alist)
855 dir (car elt))
856 (condition-case ()
857 (progn
858 (dired-uncache dir)
859 (dired-insert-subdir dir))
860 (error nil))))))
862 ;; Remove directory DIR from any directory cache.
863 (defun dired-uncache (dir)
864 (let ((handler (find-file-name-handler dir 'dired-uncache)))
865 (if handler
866 (funcall handler 'dired-uncache dir))))
868 ;; dired mode key bindings and initialization
870 (defvar dired-mode-map nil "Local keymap for dired-mode buffers.")
871 (if dired-mode-map
873 ;; This looks ugly when substitute-command-keys uses C-d instead d:
874 ;; (define-key dired-mode-map "\C-d" 'dired-flag-file-deletion)
876 (let ((map (make-keymap)))
877 (suppress-keymap map)
878 (define-key map [mouse-2] 'dired-mouse-find-file-other-window)
879 ;; Commands to mark or flag certain categories of files
880 (define-key map "#" 'dired-flag-auto-save-files)
881 (define-key map "." 'dired-clean-directory)
882 (define-key map "~" 'dired-flag-backup-files)
883 (define-key map "&" 'dired-flag-garbage-files)
884 ;; Upper case keys (except !) for operating on the marked files
885 (define-key map "A" 'dired-do-search)
886 (define-key map "C" 'dired-do-copy)
887 (define-key map "B" 'dired-do-byte-compile)
888 (define-key map "D" 'dired-do-delete)
889 (define-key map "G" 'dired-do-chgrp)
890 (define-key map "H" 'dired-do-hardlink)
891 (define-key map "L" 'dired-do-load)
892 (define-key map "M" 'dired-do-chmod)
893 (define-key map "O" 'dired-do-chown)
894 (define-key map "P" 'dired-do-print)
895 (define-key map "Q" 'dired-do-query-replace-regexp)
896 (define-key map "R" 'dired-do-rename)
897 (define-key map "S" 'dired-do-symlink)
898 (define-key map "X" 'dired-do-shell-command)
899 (define-key map "Z" 'dired-do-compress)
900 (define-key map "!" 'dired-do-shell-command)
901 ;; Comparison commands
902 (define-key map "=" 'dired-diff)
903 (define-key map "\M-=" 'dired-backup-diff)
904 ;; Tree Dired commands
905 (define-key map "\M-\C-?" 'dired-unmark-all-files)
906 (define-key map "\M-\C-d" 'dired-tree-down)
907 (define-key map "\M-\C-u" 'dired-tree-up)
908 (define-key map "\M-\C-n" 'dired-next-subdir)
909 (define-key map "\M-\C-p" 'dired-prev-subdir)
910 ;; move to marked files
911 (define-key map "\M-{" 'dired-prev-marked-file)
912 (define-key map "\M-}" 'dired-next-marked-file)
913 ;; Make all regexp commands share a `%' prefix:
914 ;; We used to get to the submap via a symbol dired-regexp-prefix,
915 ;; but that seems to serve little purpose, and copy-keymap
916 ;; does a better job without it.
917 (define-key map "%" nil)
918 (define-key map "%u" 'dired-upcase)
919 (define-key map "%l" 'dired-downcase)
920 (define-key map "%d" 'dired-flag-files-regexp)
921 (define-key map "%g" 'dired-mark-files-containing-regexp)
922 (define-key map "%m" 'dired-mark-files-regexp)
923 (define-key map "%r" 'dired-do-rename-regexp)
924 (define-key map "%C" 'dired-do-copy-regexp)
925 (define-key map "%H" 'dired-do-hardlink-regexp)
926 (define-key map "%R" 'dired-do-rename-regexp)
927 (define-key map "%S" 'dired-do-symlink-regexp)
928 ;; Commands for marking and unmarking.
929 (define-key map "*" nil)
930 (define-key map "**" 'dired-mark-executables)
931 (define-key map "*/" 'dired-mark-directories)
932 (define-key map "*@" 'dired-mark-symlinks)
933 (define-key map "*%" 'dired-mark-files-regexp)
934 (define-key map "*c" 'dired-change-marks)
935 (define-key map "*s" 'dired-mark-subdir-files)
936 (define-key map "*m" 'dired-mark)
937 (define-key map "*u" 'dired-unmark)
938 (define-key map "*?" 'dired-unmark-all-files)
939 (define-key map "*!" 'dired-unmark-all-marks)
940 (define-key map "*\177" 'dired-unmark-backward)
941 (define-key map "*\C-n" 'dired-next-marked-file)
942 (define-key map "*\C-p" 'dired-prev-marked-file)
943 (define-key map "*t" 'dired-do-toggle)
944 ;; Lower keys for commands not operating on all the marked files
945 (define-key map "a" 'dired-find-alternate-file)
946 (define-key map "d" 'dired-flag-file-deletion)
947 (define-key map "e" 'dired-find-file)
948 (define-key map "f" 'dired-find-file)
949 (define-key map "\C-m" 'dired-advertised-find-file)
950 (define-key map "g" 'revert-buffer)
951 (define-key map "h" 'describe-mode)
952 (define-key map "i" 'dired-maybe-insert-subdir)
953 (define-key map "k" 'dired-do-kill-lines)
954 (define-key map "l" 'dired-do-redisplay)
955 (define-key map "m" 'dired-mark)
956 (define-key map "n" 'dired-next-line)
957 (define-key map "o" 'dired-find-file-other-window)
958 (define-key map "\C-o" 'dired-display-file)
959 (define-key map "p" 'dired-previous-line)
960 (define-key map "q" 'quit-window)
961 (define-key map "s" 'dired-sort-toggle-or-edit)
962 (define-key map "t" 'dired-do-toggle)
963 (define-key map "u" 'dired-unmark)
964 (define-key map "v" 'dired-view-file)
965 (define-key map "x" 'dired-do-flagged-delete)
966 (define-key map "y" 'dired-show-file-type)
967 (define-key map "+" 'dired-create-directory)
968 ;; moving
969 (define-key map "<" 'dired-prev-dirline)
970 (define-key map ">" 'dired-next-dirline)
971 (define-key map "^" 'dired-up-directory)
972 (define-key map " " 'dired-next-line)
973 (define-key map "\C-n" 'dired-next-line)
974 (define-key map "\C-p" 'dired-previous-line)
975 (define-key map [down] 'dired-next-line)
976 (define-key map [up] 'dired-previous-line)
977 ;; hiding
978 (define-key map "$" 'dired-hide-subdir)
979 (define-key map "\M-$" 'dired-hide-all)
980 ;; misc
981 (define-key map "?" 'dired-summary)
982 (define-key map "\177" 'dired-unmark-backward)
983 (define-key map "\C-_" 'dired-undo)
984 (define-key map "\C-xu" 'dired-undo)
986 ;; Make menu bar items.
988 ;; No need to fo this, now that top-level items are fewer.
989 ;;;;
990 ;; Get rid of the Edit menu bar item to save space.
991 ;(define-key map [menu-bar edit] 'undefined)
993 (define-key map [menu-bar subdir]
994 (cons "Subdir" (make-sparse-keymap "Subdir")))
996 (define-key map [menu-bar subdir hide-all]
997 '(menu-item "Hide All" dired-hide-all
998 :help "Hide all subdirectories, leave only header lines"))
999 (define-key map [menu-bar subdir hide-subdir]
1000 '(menu-item "Hide/UnHide Subdir" dired-hide-subdir
1001 :help "Hide or unhide current directory listing"))
1002 (define-key map [menu-bar subdir tree-down]
1003 '(menu-item "Tree Down" dired-tree-down
1004 :help "Go to first subdirectory header down the tree"))
1005 (define-key map [menu-bar subdir tree-up]
1006 '(menu-item "Tree Up" dired-tree-up
1007 :help "Go to first subdirectory header up the tree"))
1008 (define-key map [menu-bar subdir up]
1009 '(menu-item "Up Directory" dired-up-directory
1010 :help "Edit the parent directory"))
1011 (define-key map [menu-bar subdir prev-subdir]
1012 '(menu-item "Prev Subdir" dired-prev-subdir
1013 :help "Go to previous subdirectory header line"))
1014 (define-key map [menu-bar subdir next-subdir]
1015 '(menu-item "Next Subdir" dired-next-subdir
1016 :help "Go to next subdirectory header line"))
1017 (define-key map [menu-bar subdir prev-dirline]
1018 '(menu-item "Prev Dirline" dired-prev-dirline
1019 :help "Move to next directory-file line"))
1020 (define-key map [menu-bar subdir next-dirline]
1021 '(menu-item "Next Dirline" dired-next-dirline
1022 :help "Move to previous directory-file line"))
1023 (define-key map [menu-bar subdir insert]
1024 '(menu-item "Insert This Subdir" dired-maybe-insert-subdir
1025 :help "Insert contents of subdirectory"))
1027 (define-key map [menu-bar immediate]
1028 (cons "Immediate" (make-sparse-keymap "Immediate")))
1030 (define-key map [menu-bar immediate revert-buffer]
1031 '(menu-item "Refresh" revert-buffer
1032 :help "Update contents of shown directories"))
1034 (define-key map [menu-bar immediate dashes]
1035 '("--"))
1037 (define-key map [menu-bar immediate backup-diff]
1038 '(menu-item "Compare with Backup" dired-backup-diff
1039 :help "Diff file at cursor with its latest backup"))
1040 (define-key map [menu-bar immediate diff]
1041 '(menu-item "Diff..." dired-diff
1042 :help "Compare file at cursor with another file"))
1043 (define-key map [menu-bar immediate view]
1044 '(menu-item "View This File" dired-view-file
1045 :help "Examine file at cursor in read-only mode"))
1046 (define-key map [menu-bar immediate display]
1047 '(menu-item "Display in Other Window" dired-display-file
1048 :help "Display file at cursor in other window"))
1049 (define-key map [menu-bar immediate find-file-other-window]
1050 '(menu-item "Find in Other Window" dired-find-file-other-window
1051 :help "Edit file at cursor in other window"))
1052 (define-key map [menu-bar immediate find-file]
1053 '(menu-item "Find This File" dired-find-file
1054 :help "Edit file at cursor"))
1055 (define-key map [menu-bar immediate create-directory]
1056 '(menu-item "Create Directory..." dired-create-directory))
1058 (define-key map [menu-bar regexp]
1059 (cons "Regexp" (make-sparse-keymap "Regexp")))
1061 (define-key map [menu-bar regexp downcase]
1062 '(menu-item "Downcase" dired-downcase
1063 ;; When running on plain MS-DOS, there's only one
1064 ;; letter-case for file names.
1065 :enable (or (not (fboundp 'msdos-long-file-names))
1066 (msdos-long-file-names))
1067 :help "Rename marked files to lower-case name"))
1068 (define-key map [menu-bar regexp upcase]
1069 '(menu-item "Upcase" dired-upcase
1070 :enable (or (not (fboundp 'msdos-long-file-names))
1071 (msdos-long-file-names))
1072 :help "Rename marked files to upper-case name"))
1073 (define-key map [menu-bar regexp hardlink]
1074 '(menu-item "Hardlink..." dired-do-hardlink-regexp
1075 :help "Make hard links for files matching regexp"))
1076 (define-key map [menu-bar regexp symlink]
1077 '(menu-item "Symlink..." dired-do-symlink-regexp
1078 :visible (fboundp 'make-symbolic-link)
1079 :help "Make symbolic links for files matching regexp"))
1080 (define-key map [menu-bar regexp rename]
1081 '(menu-item "Rename..." dired-do-rename-regexp
1082 :help "Rename marked files matching regexp"))
1083 (define-key map [menu-bar regexp copy]
1084 '(menu-item "Copy..." dired-do-copy-regexp
1085 :help "Copy marked files matching regexp"))
1086 (define-key map [menu-bar regexp flag]
1087 '(menu-item "Flag..." dired-flag-files-regexp
1088 :help "Flag files matching regexp for deletion"))
1089 (define-key map [menu-bar regexp mark]
1090 '(menu-item "Mark..." dired-mark-files-regexp
1091 :help "Mark files matching regexp for future operations"))
1092 (define-key map [menu-bar regexp mark-cont]
1093 '(menu-item "Mark Containing..." dired-mark-files-containing-regexp
1094 :help "Mark files whose contents matches regexp"))
1096 (define-key map [menu-bar mark]
1097 (cons "Mark" (make-sparse-keymap "Mark")))
1099 (define-key map [menu-bar mark prev]
1100 '(menu-item "Previous Marked" dired-prev-marked-file
1101 :help "Move to previous marked file"))
1102 (define-key map [menu-bar mark next]
1103 '(menu-item "Next Marked" dired-next-marked-file
1104 :help "Move to next marked file"))
1105 (define-key map [menu-bar mark marks]
1106 '(menu-item "Change Marks..." dired-change-marks
1107 :help "Replace marker with another character"))
1108 (define-key map [menu-bar mark unmark-all]
1109 '(menu-item "Unmark All" dired-unmark-all-marks))
1110 (define-key map [menu-bar mark symlinks]
1111 '(menu-item "Mark Symlinks" dired-mark-symlinks
1112 :visible (fboundp 'make-symbolic-link)
1113 :help "Mark all symbolic links"))
1114 (define-key map [menu-bar mark directories]
1115 '(menu-item "Mark Directories" dired-mark-directories
1116 :help "Mark all directories except `.' and `..'"))
1117 (define-key map [menu-bar mark directory]
1118 '(menu-item "Mark Old Backups" dired-clean-directory
1119 :help "Flag old numbered backups for deletion"))
1120 (define-key map [menu-bar mark executables]
1121 '(menu-item "Mark Executables" dired-mark-executables
1122 :help "Mark all executable files"))
1123 (define-key map [menu-bar mark garbage-files]
1124 '(menu-item "Flag Garbage Files" dired-flag-garbage-files
1125 :help "Flag unneeded files for deletion"))
1126 (define-key map [menu-bar mark backup-files]
1127 '(menu-item "Flag Backup Files" dired-flag-backup-files
1128 :help "Flag all backup files for deletion"))
1129 (define-key map [menu-bar mark auto-save-files]
1130 '(menu-item "Flag Auto-save Files" dired-flag-auto-save-files
1131 :help "Flag auto-save files for deletion"))
1132 (define-key map [menu-bar mark deletion]
1133 '(menu-item "Flag" dired-flag-file-deletion
1134 :help "Flag current line's file for deletion"))
1135 (define-key map [menu-bar mark unmark]
1136 '(menu-item "Unmark" dired-unmark
1137 :help "Unmark or unflag current line's file"))
1138 (define-key map [menu-bar mark mark]
1139 '(menu-item "Mark" dired-mark
1140 :help "Mark current line's file for future operations"))
1141 (define-key map [menu-bar mark toggle-marks]
1142 '(menu-item "Toggle Marks" dired-do-toggle
1143 :help "Mark unmarked files, unmark marked ones"))
1145 (define-key map [menu-bar operate]
1146 (cons "Operate" (make-sparse-keymap "Operate")))
1148 (define-key map [menu-bar operate query-replace]
1149 '(menu-item "Query Replace in Files..." dired-do-query-replace-regexp
1150 :help "Replace regexp in marked files"))
1151 (define-key map [menu-bar operate search]
1152 '(menu-item "Search Files..." dired-do-search
1153 :help "Search marked files for regexp"))
1154 (define-key map [menu-bar operate chown]
1155 '(menu-item "Change Owner..." dired-do-chown
1156 :visible (not (memq system-type '(ms-dos windows-nt)))
1157 :help "Change the owner of marked files"))
1158 (define-key map [menu-bar operate chgrp]
1159 '(menu-item "Change Group..." dired-do-chgrp
1160 :visible (not (memq system-type '(ms-dos windows-nt)))
1161 :help "Change the group of marked files"))
1162 (define-key map [menu-bar operate chmod]
1163 '(menu-item "Change Mode..." dired-do-chmod
1164 :help "Change mode (attributes) of marked files"))
1165 (define-key map [menu-bar operate load]
1166 '(menu-item "Load" dired-do-load
1167 :help "Load marked Emacs Lisp files"))
1168 (define-key map [menu-bar operate compile]
1169 '(menu-item "Byte-compile" dired-do-byte-compile
1170 :help "Byte-compile marked Emacs Lisp files"))
1171 (define-key map [menu-bar operate compress]
1172 '(menu-item "Compress" dired-do-compress
1173 :help "Compress/uncompress marked files"))
1174 (define-key map [menu-bar operate print]
1175 '(menu-item "Print..." dired-do-print
1176 :help "Ask for print command and print marked files"))
1177 (define-key map [menu-bar operate hardlink]
1178 '(menu-item "Hardlink to..." dired-do-hardlink
1179 :help "Make hard links for current or marked files"))
1180 (define-key map [menu-bar operate symlink]
1181 '(menu-item "Symlink to..." dired-do-symlink
1182 :visible (fboundp 'make-symbolic-link)
1183 :help "Make symbolic links for current or marked files"))
1184 (define-key map [menu-bar operate command]
1185 '(menu-item "Shell Command..." dired-do-shell-command
1186 :help "Run a shell command on each of marked files"))
1187 (define-key map [menu-bar operate delete]
1188 '(menu-item "Delete" dired-do-delete
1189 :help "Delete current file or all marked files"))
1190 (define-key map [menu-bar operate rename]
1191 '(menu-item "Rename to..." dired-do-rename
1192 :help "Rename current file or move marked files"))
1193 (define-key map [menu-bar operate copy]
1194 '(menu-item "Copy to..." dired-do-copy
1195 :help "Copy current file or all marked files"))
1197 (setq dired-mode-map map)))
1199 ;; Dired mode is suitable only for specially formatted data.
1200 (put 'dired-mode 'mode-class 'special)
1202 (defun dired-mode (&optional dirname switches)
1204 Mode for \"editing\" directory listings.
1205 In Dired, you are \"editing\" a list of the files in a directory and
1206 \(optionally) its subdirectories, in the format of `ls -lR'.
1207 Each directory is a page: use \\[backward-page] and \\[forward-page] to move pagewise.
1208 \"Editing\" means that you can run shell commands on files, visit,
1209 compress, load or byte-compile them, change their file attributes
1210 and insert subdirectories into the same buffer. You can \"mark\"
1211 files for later commands or \"flag\" them for deletion, either file
1212 by file or all files matching certain criteria.
1213 You can move using the usual cursor motion commands.\\<dired-mode-map>
1214 Letters no longer insert themselves. Digits are prefix arguments.
1215 Instead, type \\[dired-flag-file-deletion] to flag a file for Deletion.
1216 Type \\[dired-mark] to Mark a file or subdirectory for later commands.
1217 Most commands operate on the marked files and use the current file
1218 if no files are marked. Use a numeric prefix argument to operate on
1219 the next ARG (or previous -ARG if ARG<0) files, or just `1'
1220 to operate on the current file only. Prefix arguments override marks.
1221 Mark-using commands display a list of failures afterwards. Type \\[dired-summary]
1222 to see why something went wrong.
1223 Type \\[dired-unmark] to Unmark a file or all files of a subdirectory.
1224 Type \\[dired-unmark-backward] to back up one line and unflag.
1225 Type \\[dired-do-flagged-delete] to eXecute the deletions requested.
1226 Type \\[dired-advertised-find-file] to Find the current line's file
1227 (or dired it in another buffer, if it is a directory).
1228 Type \\[dired-find-file-other-window] to find file or dired directory in Other window.
1229 Type \\[dired-maybe-insert-subdir] to Insert a subdirectory in this buffer.
1230 Type \\[dired-do-rename] to Rename a file or move the marked files to another directory.
1231 Type \\[dired-do-copy] to Copy files.
1232 Type \\[dired-sort-toggle-or-edit] to toggle sorting by name/date or change the `ls' switches.
1233 Type \\[revert-buffer] to read all currently expanded directories again.
1234 This retains all marks and hides subdirs again that were hidden before.
1235 SPC and DEL can be used to move down and up by lines.
1237 If dired ever gets confused, you can either type \\[revert-buffer] \
1238 to read the
1239 directories again, type \\[dired-do-redisplay] \
1240 to relist a single or the marked files or a
1241 subdirectory, or type \\[dired-build-subdir-alist] to parse the buffer
1242 again for the directory tree.
1244 Customization variables (rename this buffer and type \\[describe-variable] on each line
1245 for more info):
1247 dired-listing-switches
1248 dired-trivial-filenames
1249 dired-shrink-to-fit
1250 dired-marker-char
1251 dired-del-marker
1252 dired-keep-marker-rename
1253 dired-keep-marker-copy
1254 dired-keep-marker-hardlink
1255 dired-keep-marker-symlink
1257 Hooks (use \\[describe-variable] to see their documentation):
1259 dired-before-readin-hook
1260 dired-after-readin-hook
1261 dired-mode-hook
1262 dired-load-hook
1264 Keybindings:
1265 \\{dired-mode-map}"
1266 ;; Not to be called interactively (e.g. dired-directory will be set
1267 ;; to default-directory, which is wrong with wildcards).
1268 (kill-all-local-variables)
1269 (use-local-map dired-mode-map)
1270 (dired-advertise) ; default-directory is already set
1271 (setq major-mode 'dired-mode
1272 mode-name "Dired"
1273 ;; case-fold-search nil
1274 buffer-read-only t
1275 selective-display t ; for subdirectory hiding
1276 mode-line-buffer-identification
1277 (propertized-buffer-identification "%17b"))
1278 (set (make-local-variable 'revert-buffer-function)
1279 (function dired-revert))
1280 (set (make-local-variable 'page-delimiter)
1281 "\n\n")
1282 (set (make-local-variable 'dired-directory)
1283 (or dirname default-directory))
1284 ;; list-buffers uses this to display the dir being edited in this buffer.
1285 (set (make-local-variable 'list-buffers-directory)
1286 (expand-file-name dired-directory))
1287 (set (make-local-variable 'dired-actual-switches)
1288 (or switches dired-listing-switches))
1289 (set (make-local-variable 'font-lock-defaults) '(dired-font-lock-keywords t))
1290 (dired-sort-other dired-actual-switches t)
1291 (run-hooks 'dired-mode-hook))
1293 ;; Idiosyncratic dired commands that don't deal with marks.
1295 (defun dired-summary ()
1296 "Summarize basic Dired commands and show recent Dired errors."
1297 (interactive)
1298 (dired-why)
1299 ;>> this should check the key-bindings and use substitute-command-keys if non-standard
1300 (message
1301 "d-elete, u-ndelete, x-punge, f-ind, o-ther window, R-ename, C-opy, h-elp"))
1303 (defun dired-undo ()
1304 "Undo in a dired buffer.
1305 This doesn't recover lost files, it just undoes changes in the buffer itself.
1306 You can use it to recover marks, killed lines or subdirs.
1307 In the latter case, you have to do \\[dired-build-subdir-alist] to
1308 parse the buffer again."
1309 (interactive)
1310 (let (buffer-read-only)
1311 (undo)
1312 (message "Change in Dired buffer undone.
1313 Actual changes in files cannot be undone by Emacs.")))
1315 (defun dired-next-line (arg)
1316 "Move down lines then position at filename.
1317 Optional prefix ARG says how many lines to move; default is one line."
1318 (interactive "p")
1319 (next-line arg)
1320 (dired-move-to-filename))
1322 (defun dired-previous-line (arg)
1323 "Move up lines then position at filename.
1324 Optional prefix ARG says how many lines to move; default is one line."
1325 (interactive "p")
1326 (previous-line arg)
1327 (dired-move-to-filename))
1329 (defun dired-next-dirline (arg &optional opoint)
1330 "Goto ARG'th next directory file line."
1331 (interactive "p")
1332 (or opoint (setq opoint (point)))
1333 (if (if (> arg 0)
1334 (re-search-forward dired-re-dir nil t arg)
1335 (beginning-of-line)
1336 (re-search-backward dired-re-dir nil t (- arg)))
1337 (dired-move-to-filename) ; user may type `i' or `f'
1338 (goto-char opoint)
1339 (error "No more subdirectories")))
1341 (defun dired-prev-dirline (arg)
1342 "Goto ARG'th previous directory file line."
1343 (interactive "p")
1344 (dired-next-dirline (- arg)))
1346 (defun dired-up-directory (&optional other-window)
1347 "Run Dired on parent directory of current directory.
1348 Find the parent directory either in this buffer or another buffer.
1349 Creates a buffer if necessary."
1350 (interactive "P")
1351 (let* ((dir (dired-current-directory))
1352 (up (file-name-directory (directory-file-name dir))))
1353 (or (dired-goto-file (directory-file-name dir))
1354 ;; Only try dired-goto-subdir if buffer has more than one dir.
1355 (and (cdr dired-subdir-alist)
1356 (dired-goto-subdir up))
1357 (progn
1358 (if other-window
1359 (dired-other-window up)
1360 (dired up))
1361 (dired-goto-file dir)))))
1363 (defun dired-get-file-for-visit ()
1364 "Get the current line's file name, with an error if file does not exist."
1365 (interactive)
1366 (let ((file-name (file-name-sans-versions (dired-get-filename) t)))
1367 (if (file-exists-p file-name)
1368 file-name
1369 (if (file-symlink-p file-name)
1370 (error "File is a symlink to a nonexistent target")
1371 (error "File no longer exists; type `g' to update Dired buffer")))))
1373 ;; Force `f' rather than `e' in the mode doc:
1374 (defalias 'dired-advertised-find-file 'dired-find-file)
1375 (defun dired-find-file ()
1376 "In Dired, visit the file or directory named on this line."
1377 (interactive)
1378 (find-file (dired-get-file-for-visit)))
1380 (defun dired-find-alternate-file ()
1381 "In Dired, visit this file or directory instead of the dired buffer."
1382 (interactive)
1383 (set-buffer-modified-p nil)
1384 (find-alternate-file (dired-get-file-for-visit)))
1386 (defun dired-mouse-find-file-other-window (event)
1387 "In Dired, visit the file or directory name you click on."
1388 (interactive "e")
1389 (let (file)
1390 (save-excursion
1391 (set-buffer (window-buffer (posn-window (event-end event))))
1392 (save-excursion
1393 (goto-char (posn-point (event-end event)))
1394 (setq file (dired-get-file-for-visit))))
1395 (select-window (posn-window (event-end event)))
1396 (find-file-other-window (file-name-sans-versions file t))))
1398 (defun dired-view-file ()
1399 "In Dired, examine a file in view mode, returning to dired when done.
1400 When file is a directory, show it in this buffer if it is inserted;
1401 otherwise, display it in another buffer."
1402 (interactive)
1403 (let ((file (dired-get-file-for-visit)))
1404 (if (file-directory-p file)
1405 (or (and (cdr dired-subdir-alist)
1406 (dired-goto-subdir file))
1407 (dired file))
1408 (view-file file))))
1410 (defun dired-find-file-other-window ()
1411 "In Dired, visit this file or directory in another window."
1412 (interactive)
1413 (find-file-other-window (dired-get-file-for-visit)))
1415 (defun dired-display-file ()
1416 "In Dired, display this file or directory in another window."
1417 (interactive)
1418 (display-buffer (find-file-noselect (dired-get-file-for-visit))))
1420 ;;; Functions for extracting and manipulating file names in Dired buffers.
1422 (defun dired-get-filename (&optional localp no-error-if-not-filep)
1423 "In Dired, return name of file mentioned on this line.
1424 Value returned normally includes the directory name.
1425 Optional arg LOCALP with value `no-dir' means don't include directory
1426 name in result. A value of `verbatim' means to return the name exactly as
1427 it occurs in the buffer, and a value of t means construct name relative to
1428 `default-directory', which still may contain slashes if in a subdirectory.
1429 Optional arg NO-ERROR-IF-NOT-FILEP means return nil if no filename on
1430 this line, otherwise an error occurs."
1431 (let (case-fold-search file p1 p2 already-absolute)
1432 (save-excursion
1433 (if (setq p1 (dired-move-to-filename (not no-error-if-not-filep)))
1434 (setq p2 (dired-move-to-end-of-filename no-error-if-not-filep))))
1435 ;; nil if no file on this line, but no-error-if-not-filep is t:
1436 (if (setq file (and p1 p2 (buffer-substring p1 p2)))
1437 (progn
1438 ;; Get rid of the mouse-face property that file names have.
1439 (set-text-properties 0 (length file) nil file)
1440 ;; Unquote names quoted by ls or by dired-insert-directory.
1441 ;; Using read to unquote is much faster than substituting
1442 ;; \007 (4 chars) -> ^G (1 char) etc. in a lisp loop.
1443 (setq file
1444 (read
1445 (concat "\""
1446 ;; some ls -b don't escape quotes, argh!
1447 ;; This is not needed for GNU ls, though.
1448 (or (dired-string-replace-match
1449 "\\([^\\]\\|\\`\\)\"" file "\\1\\\\\"" nil t)
1450 file)
1451 "\"")))))
1452 (and file (file-name-absolute-p file)
1453 ;; A relative file name can start with ~.
1454 ;; Don't treat it as absolute in this context.
1455 (not (eq (aref file 0) ?~))
1456 (setq already-absolute t))
1457 (and file buffer-file-coding-system
1458 (not file-name-coding-system)
1459 (not default-file-name-coding-system)
1460 (setq file (encode-coding-string file buffer-file-coding-system)))
1461 (cond
1462 ((eq localp 'verbatim)
1463 file)
1464 ((and (eq localp 'no-dir) already-absolute)
1465 (file-name-nondirectory file))
1466 ((or already-absolute (eq localp 'no-dir))
1467 file)
1469 (and file (concat (dired-current-directory localp) file))))))
1471 (defun dired-string-replace-match (regexp string newtext
1472 &optional literal global)
1473 "Replace first match of REGEXP in STRING with NEWTEXT.
1474 If it does not match, nil is returned instead of the new string.
1475 Optional arg LITERAL means to take NEWTEXT literally.
1476 Optional arg GLOBAL means to replace all matches."
1477 (if global
1478 (let ((start 0) ret)
1479 (while (string-match regexp string start)
1480 (let ((from-end (- (length string) (match-end 0))))
1481 (setq ret (setq string (replace-match newtext t literal string)))
1482 (setq start (- (length string) from-end))))
1483 ret)
1484 (if (not (string-match regexp string 0))
1486 (replace-match newtext t literal string))))
1488 (defun dired-make-absolute (file &optional dir)
1489 ;;"Convert FILE (a pathname relative to DIR) to an absolute pathname."
1490 ;; We can't always use expand-file-name as this would get rid of `.'
1491 ;; or expand in / instead default-directory if DIR=="".
1492 ;; This should be good enough for ange-ftp, but might easily be
1493 ;; redefined (for VMS?).
1494 ;; It should be reasonably fast, though, as it is called in
1495 ;; dired-get-filename.
1496 (concat (or dir default-directory) file))
1498 (defun dired-make-relative (file &optional dir ignore)
1499 "Convert FILE (an absolute file name) to a name relative to DIR.
1500 If this is impossible, return FILE unchanged.
1501 DIR must be a directory name, not a file name."
1502 (or dir (setq dir default-directory))
1503 ;; This case comes into play if default-directory is set to
1504 ;; use ~.
1505 (if (and (> (length dir) 0) (= (aref dir 0) ?~))
1506 (setq dir (expand-file-name dir)))
1507 (if (string-match (concat "^" (regexp-quote dir)) file)
1508 (substring file (match-end 0))
1509 ;;; (or no-error
1510 ;;; (error "%s: not in directory tree growing at %s" file dir))
1511 file))
1513 ;;; Functions for finding the file name in a dired buffer line.
1515 (defvar dired-move-to-filename-regexp
1516 (let* ((l "\\([A-Za-z]\\|[^\0-\177]\\)")
1517 ;; In some locales, month abbreviations are as short as 2 letters,
1518 ;; and they can be followed by ".".
1519 (month (concat l l "+\\.?"))
1520 (s " ")
1521 (yyyy "[0-9][0-9][0-9][0-9]")
1522 (dd "[ 0-3][0-9]")
1523 (HH:MM "[ 0-2][0-9]:[0-5][0-9]")
1524 (seconds "[0-6][0-9]\\([.,][0-9]+\\)?")
1525 (zone "[-+][0-2][0-9][0-5][0-9]")
1526 (iso-mm-dd "[01][0-9]-[0-3][0-9]")
1527 (iso-time (concat HH:MM "\\(:" seconds "\\( ?" zone "\\)?\\)?"))
1528 (iso (concat "\\(\\(" yyyy "-\\)?" iso-mm-dd "[ T]" iso-time
1529 "\\|" yyyy "-" iso-mm-dd "\\)"))
1530 (western (concat "\\(" month s "+" dd "\\|" dd "\\.?" s month "\\)"
1531 s "+"
1532 "\\(" HH:MM "\\|" yyyy "\\)"))
1533 (western-comma (concat month s "+" dd "," s "+" yyyy))
1534 ;; Japanese MS-Windows ls-lisp has one-digit months, and
1535 ;; omits the Kanji characters after month and day-of-month.
1536 (mm "[ 0-1]?[0-9]")
1537 (japanese
1538 (concat mm l "?" s dd l "?" s "+"
1539 "\\(" HH:MM "\\|" yyyy l "?" "\\)")))
1540 ;; The "[0-9]" below requires the previous column to end in a digit.
1541 ;; This avoids recognizing `1 may 1997' as a date in the line:
1542 ;; -r--r--r-- 1 may 1997 1168 Oct 19 16:49 README
1543 ;; The "[kMGTPEZY]?" below supports "ls -alh" output.
1544 ;; The ".*" below finds the last match if there are multiple matches.
1545 ;; This avoids recognizing `jservice 10 1024' as a date in the line:
1546 ;; drwxr-xr-x 3 jservice 10 1024 Jul 2 1997 esg-host
1547 (concat ".*[0-9][kMGTPEZY]?" s
1548 "\\(" western "\\|" western-comma "\\|" japanese "\\|" iso "\\)"
1549 s "+"))
1550 "Regular expression to match up to the file name in a directory listing.
1551 The default value is designed to recognize dates and times
1552 regardless of the language.")
1554 (defvar dired-permission-flags-regexp
1555 "\\([^ ]\\)[-r][-w]\\([^ ]\\)[-r][-w]\\([^ ]\\)[-r][-w]\\([^ ]\\)"
1556 "Regular expression to match the permission flags in `ls -l'.")
1558 ;; Move to first char of filename on this line.
1559 ;; Returns position (point) or nil if no filename on this line."
1560 (defun dired-move-to-filename (&optional raise-error eol)
1561 ;; This is the UNIX version.
1562 (or eol (setq eol (progn (end-of-line) (point))))
1563 (beginning-of-line)
1564 (if (re-search-forward dired-move-to-filename-regexp eol t)
1565 (goto-char (match-end 0))
1566 (if raise-error
1567 (error "No file on this line"))))
1569 (defun dired-move-to-end-of-filename (&optional no-error)
1570 ;; Assumes point is at beginning of filename,
1571 ;; thus the rwx bit re-search-backward below will succeed in *this*
1572 ;; line if at all. So, it should be called only after
1573 ;; (dired-move-to-filename t).
1574 ;; On failure, signals an error (with non-nil NO-ERROR just returns nil).
1575 ;; This is the UNIX version.
1576 (let (opoint file-type executable symlink hidden case-fold-search used-F eol)
1577 ;; case-fold-search is nil now, so we can test for capital F:
1578 (setq used-F (string-match "F" dired-actual-switches)
1579 opoint (point)
1580 eol (save-excursion (end-of-line) (point))
1581 hidden (and selective-display
1582 (save-excursion (search-forward "\r" eol t))))
1583 (if hidden
1585 (save-excursion;; Find out what kind of file this is:
1586 ;; Restrict perm bits to be non-blank,
1587 ;; otherwise this matches one char to early (looking backward):
1588 ;; "l---------" (some systems make symlinks that way)
1589 ;; "----------" (plain file with zero perms)
1590 (if (re-search-backward
1591 dired-permission-flags-regexp nil t)
1592 (setq file-type (char-after (match-beginning 1))
1593 symlink (eq file-type ?l)
1594 ;; Only with -F we need to know whether it's an executable
1595 executable (and
1596 used-F
1597 (string-match
1598 "[xst]";; execute bit set anywhere?
1599 (concat
1600 (buffer-substring (match-beginning 2)
1601 (match-end 2))
1602 (buffer-substring (match-beginning 3)
1603 (match-end 3))
1604 (buffer-substring (match-beginning 4)
1605 (match-end 4))))))
1606 (or no-error (error "No file on this line"))))
1607 ;; Move point to end of name:
1608 (if symlink
1609 (if (search-forward " ->" eol t)
1610 (progn
1611 (forward-char -3)
1612 (and used-F
1613 dired-ls-F-marks-symlinks
1614 (eq (preceding-char) ?@);; did ls really mark the link?
1615 (forward-char -1))))
1616 (goto-char eol);; else not a symbolic link
1617 ;; ls -lF marks dirs, sockets and executables with exactly one
1618 ;; trailing character. (Executable bits on symlinks ain't mean
1619 ;; a thing, even to ls, but we know it's not a symlink.)
1620 (and used-F
1621 (or (memq file-type '(?d ?s))
1622 executable)
1623 (forward-char -1))))
1624 (or no-error
1625 (not (eq opoint (point)))
1626 (error (if hidden
1627 (substitute-command-keys
1628 "File line is hidden, type \\[dired-hide-subdir] to unhide")
1629 "No file on this line")))
1630 (if (eq opoint (point))
1632 (point))))
1635 ;; Keeping Dired buffers in sync with the filesystem and with each other
1637 (defun dired-buffers-for-dir (dir &optional file)
1638 ;; Return a list of buffers that dired DIR (top level or in-situ subdir).
1639 ;; If FILE is non-nil, include only those whose wildcard pattern (if any)
1640 ;; matches FILE.
1641 ;; The list is in reverse order of buffer creation, most recent last.
1642 ;; As a side effect, killed dired buffers for DIR are removed from
1643 ;; dired-buffers.
1644 (setq dir (file-name-as-directory dir))
1645 (let ((alist dired-buffers) result elt buf pattern)
1646 (while alist
1647 (setq elt (car alist)
1648 buf (cdr elt))
1649 (if (buffer-name buf)
1650 (if (dired-in-this-tree dir (car elt))
1651 (with-current-buffer buf
1652 (and (assoc dir dired-subdir-alist)
1653 (or (null file)
1654 (let ((wildcards
1655 (file-name-nondirectory dired-directory)))
1656 (or (= 0 (length wildcards))
1657 (string-match (dired-glob-regexp wildcards)
1658 file))))
1659 (setq result (cons buf result)))))
1660 ;; else buffer is killed - clean up:
1661 (setq dired-buffers (delq elt dired-buffers)))
1662 (setq alist (cdr alist)))
1663 result))
1665 (defun dired-glob-regexp (pattern)
1666 "Convert glob-pattern PATTERN to a regular expression."
1667 (let ((matched-in-pattern 0) ;; How many chars of PATTERN we've handled.
1668 regexp)
1669 (while (string-match "[[?*]" pattern matched-in-pattern)
1670 (let ((op-end (match-end 0))
1671 (next-op (aref pattern (match-beginning 0))))
1672 (setq regexp (concat regexp
1673 (regexp-quote
1674 (substring pattern matched-in-pattern
1675 (match-beginning 0)))))
1676 (cond ((= next-op ??)
1677 (setq regexp (concat regexp "."))
1678 (setq matched-in-pattern op-end))
1679 ((= next-op ?\[)
1680 ;; Fails to handle ^ yet ????
1681 (let* ((set-start (match-beginning 0))
1682 (set-cont
1683 (if (= (aref pattern (1+ set-start)) ?^)
1684 (+ 3 set-start)
1685 (+ 2 set-start)))
1686 (set-end (string-match "]" pattern set-cont))
1687 (set (substring pattern set-start (1+ set-end))))
1688 (setq regexp (concat regexp set))
1689 (setq matched-in-pattern (1+ set-end))))
1690 ((= next-op ?*)
1691 (setq regexp (concat regexp ".*"))
1692 (setq matched-in-pattern op-end)))))
1693 (concat "\\`"
1694 regexp
1695 (regexp-quote
1696 (substring pattern matched-in-pattern))
1697 "\\'")))
1701 (defun dired-advertise ()
1702 ;;"Advertise in variable `dired-buffers' that we dired `default-directory'."
1703 ;; With wildcards we actually advertise too much.
1704 (let ((expanded-default (expand-file-name default-directory)))
1705 (if (memq (current-buffer) (dired-buffers-for-dir expanded-default))
1706 t ; we have already advertised ourselves
1707 (setq dired-buffers
1708 (cons (cons expanded-default (current-buffer))
1709 dired-buffers)))))
1711 (defun dired-unadvertise (dir)
1712 ;; Remove DIR from the buffer alist in variable dired-buffers.
1713 ;; This has the effect of removing any buffer whose main directory is DIR.
1714 ;; It does not affect buffers in which DIR is a subdir.
1715 ;; Removing is also done as a side-effect in dired-buffer-for-dir.
1716 (setq dired-buffers
1717 (delq (assoc (expand-file-name dir) dired-buffers) dired-buffers)))
1719 ;; Tree Dired
1721 ;;; utility functions
1723 (defun dired-in-this-tree (file dir)
1724 ;;"Is FILE part of the directory tree starting at DIR?"
1725 (let (case-fold-search)
1726 (string-match (concat "^" (regexp-quote dir)) file)))
1728 (defun dired-normalize-subdir (dir)
1729 ;; Prepend default-directory to DIR if relative path name.
1730 ;; dired-get-filename must be able to make a valid filename from a
1731 ;; file and its directory DIR.
1732 (file-name-as-directory
1733 (if (file-name-absolute-p dir)
1735 (expand-file-name dir default-directory))))
1737 (defun dired-get-subdir ()
1738 ;;"Return the subdir name on this line, or nil if not on a headerline."
1739 ;; Look up in the alist whether this is a headerline.
1740 (save-excursion
1741 (let ((cur-dir (dired-current-directory)))
1742 (beginning-of-line) ; alist stores b-o-l positions
1743 (and (zerop (- (point)
1744 (dired-get-subdir-min (assoc cur-dir
1745 dired-subdir-alist))))
1746 cur-dir))))
1748 ;(defun dired-get-subdir-min (elt)
1749 ; (cdr elt))
1750 ;; can't use macro, must be redefinable for other alist format in dired-nstd.
1751 (defalias 'dired-get-subdir-min 'cdr)
1753 (defun dired-get-subdir-max (elt)
1754 (save-excursion
1755 (goto-char (dired-get-subdir-min elt))
1756 (dired-subdir-max)))
1758 (defun dired-clear-alist ()
1759 (while dired-subdir-alist
1760 (set-marker (dired-get-subdir-min (car dired-subdir-alist)) nil)
1761 (setq dired-subdir-alist (cdr dired-subdir-alist))))
1763 (defun dired-subdir-index (dir)
1764 ;; Return an index into alist for use with nth
1765 ;; for the sake of subdir moving commands.
1766 (let (found (index 0) (alist dired-subdir-alist))
1767 (while alist
1768 (if (string= dir (car (car alist)))
1769 (setq alist nil found t)
1770 (setq alist (cdr alist) index (1+ index))))
1771 (if found index nil)))
1773 (defun dired-next-subdir (arg &optional no-error-if-not-found no-skip)
1774 "Go to next subdirectory, regardless of level."
1775 ;; Use 0 arg to go to this directory's header line.
1776 ;; NO-SKIP prevents moving to end of header line, returning whatever
1777 ;; position was found in dired-subdir-alist.
1778 (interactive "p")
1779 (let ((this-dir (dired-current-directory))
1780 pos index)
1781 ;; nth with negative arg does not return nil but the first element
1782 (setq index (- (dired-subdir-index this-dir) arg))
1783 (setq pos (if (>= index 0)
1784 (dired-get-subdir-min (nth index dired-subdir-alist))))
1785 (if pos
1786 (progn
1787 (goto-char pos)
1788 (or no-skip (skip-chars-forward "^\n\r"))
1789 (point))
1790 (if no-error-if-not-found
1791 nil ; return nil if not found
1792 (error "%s directory" (if (> arg 0) "Last" "First"))))))
1794 (defun dired-build-subdir-alist (&optional switches)
1795 "Build `dired-subdir-alist' by parsing the buffer.
1796 Returns the new value of the alist.
1797 If optional arg SWITCHES is non-nil, use its value
1798 instead of `dired-actual-switches'."
1799 (interactive)
1800 (dired-clear-alist)
1801 (save-excursion
1802 (let* ((count 0)
1803 (buffer-read-only nil)
1804 (switches (or switches dired-actual-switches))
1805 new-dir-name
1806 (R-ftp-base-dir-regex
1807 ;; Used to expand subdirectory names correctly in recursive
1808 ;; ange-ftp listings.
1809 (and (string-match "R" switches)
1810 (string-match "\\`/.*:\\(/.*\\)" default-directory)
1811 (concat "\\`" (match-string 1 default-directory)))))
1812 (goto-char (point-min))
1813 (setq dired-subdir-alist nil)
1814 (while (and (re-search-forward dired-subdir-regexp nil t)
1815 ;; Avoid taking a file name ending in a colon
1816 ;; as a subdir name.
1817 (not (save-excursion
1818 (goto-char (match-beginning 0))
1819 (beginning-of-line)
1820 (forward-char 2)
1821 (save-match-data (looking-at dired-re-perms)))))
1822 (save-excursion
1823 (goto-char (match-beginning 1))
1824 (setq new-dir-name
1825 (buffer-substring-no-properties (point) (match-end 1))
1826 new-dir-name
1827 (save-match-data
1828 (if (and R-ftp-base-dir-regex
1829 (not (string= new-dir-name default-directory))
1830 (string-match R-ftp-base-dir-regex new-dir-name))
1831 (concat default-directory
1832 (substring new-dir-name (match-end 0)))
1833 (expand-file-name new-dir-name))))
1834 (delete-region (point) (match-end 1))
1835 (insert new-dir-name))
1836 (setq count (1+ count))
1837 (dired-alist-add-1 new-dir-name
1838 ;; Place a sub directory boundary between lines.
1839 (save-excursion
1840 (goto-char (match-beginning 0))
1841 (beginning-of-line)
1842 (point-marker))))
1843 (if (> count 1)
1844 (message "Buffer includes %d directories" count))
1845 ;; We don't need to sort it because it is in buffer order per
1846 ;; constructionem. Return new alist:
1847 dired-subdir-alist)))
1849 (defun dired-alist-add-1 (dir new-marker)
1850 ;; Add new DIR at NEW-MARKER. Don't sort.
1851 (setq dired-subdir-alist
1852 (cons (cons (dired-normalize-subdir dir) new-marker)
1853 dired-subdir-alist)))
1855 (defun dired-goto-next-nontrivial-file ()
1856 ;; Position point on first nontrivial file after point.
1857 (dired-goto-next-file);; so there is a file to compare with
1858 (if (stringp dired-trivial-filenames)
1859 (while (and (not (eobp))
1860 (string-match dired-trivial-filenames
1861 (file-name-nondirectory
1862 (or (dired-get-filename nil t) ""))))
1863 (forward-line 1)
1864 (dired-move-to-filename))))
1866 (defun dired-goto-next-file ()
1867 (let ((max (1- (dired-subdir-max))))
1868 (while (and (not (dired-move-to-filename)) (< (point) max))
1869 (forward-line 1))))
1871 (defun dired-goto-file (file)
1872 "Go to file line of FILE in this dired buffer."
1873 ;; Return value of point on success, else nil.
1874 ;; FILE must be an absolute pathname.
1875 ;; Loses if FILE contains control chars like "\007" for which ls
1876 ;; either inserts "?" or "\\007" into the buffer, so we won't find
1877 ;; it in the buffer.
1878 (interactive
1879 (prog1 ; let push-mark display its message
1880 (list (expand-file-name
1881 (read-file-name "Goto file: "
1882 (dired-current-directory))))
1883 (push-mark)))
1884 (setq file (directory-file-name file)) ; does no harm if no directory
1885 (let (found case-fold-search dir)
1886 (setq dir (or (file-name-directory file)
1887 (error "Need absolute pathname for %s" file)))
1888 (save-excursion
1889 ;; The hair here is to get the result of dired-goto-subdir
1890 ;; without really calling it if we don't have any subdirs.
1891 (if (if (string= dir (expand-file-name default-directory))
1892 (goto-char (point-min))
1893 (and (cdr dired-subdir-alist)
1894 (dired-goto-subdir dir)))
1895 (let ((base (file-name-nondirectory file))
1896 (boundary (dired-subdir-max)))
1897 (while (and (not found)
1898 ;; filenames are preceded by SPC, this makes
1899 ;; the search faster (e.g. for the filename "-"!).
1900 (search-forward (concat " " base) boundary 'move))
1901 ;; Match could have BASE just as initial substring or
1902 ;; or in permission bits or date or
1903 ;; not be a proper filename at all:
1904 (if (equal base (dired-get-filename 'no-dir t))
1905 ;; Must move to filename since an (actually
1906 ;; correct) match could have been elsewhere on the
1907 ;; ;; line (e.g. "-" would match somewhere in the
1908 ;; permission bits).
1909 (setq found (dired-move-to-filename))
1910 ;; If this isn't the right line, move forward to avoid
1911 ;; trying this line again.
1912 (forward-line 1))))))
1913 (and found
1914 ;; return value of point (i.e., FOUND):
1915 (goto-char found))))
1917 (defun dired-initial-position (dirname)
1918 ;; Where point should go in a new listing of DIRNAME.
1919 ;; Point assumed at beginning of new subdir line.
1920 ;; You may redefine this function as you wish, e.g. like in dired-x.el.
1921 (end-of-line)
1922 (if dired-trivial-filenames (dired-goto-next-nontrivial-file)))
1924 ;; These are hooks which make tree dired work.
1925 ;; They are in this file because other parts of dired need to call them.
1926 ;; But they don't call the rest of tree dired unless there are subdirs loaded.
1928 ;; This function is called for each retrieved filename.
1929 ;; It could stand to be faster, though it's mostly function call
1930 ;; overhead. Avoiding the function call seems to save about 10% in
1931 ;; dired-get-filename. Make it a defsubst?
1932 (defun dired-current-directory (&optional localp)
1933 "Return the name of the subdirectory to which this line belongs.
1934 This returns a string with trailing slash, like `default-directory'.
1935 Optional argument means return a file name relative to `default-directory'."
1936 (let ((here (point))
1937 (alist (or dired-subdir-alist
1938 ;; probably because called in a non-dired buffer
1939 (error "No subdir-alist in %s" (current-buffer))))
1940 elt dir)
1941 (while alist
1942 (setq elt (car alist)
1943 dir (car elt)
1944 ;; use `<=' (not `<') as subdir line is part of subdir
1945 alist (if (<= (dired-get-subdir-min elt) here)
1946 nil ; found
1947 (cdr alist))))
1948 (if localp
1949 (dired-make-relative dir default-directory)
1950 dir)))
1952 ;; Subdirs start at the beginning of their header lines and end just
1953 ;; before the beginning of the next header line (or end of buffer).
1955 (defun dired-subdir-max ()
1956 (save-excursion
1957 (if (or (null (cdr dired-subdir-alist)) (not (dired-next-subdir 1 t t)))
1958 (point-max)
1959 (point))))
1961 ;; Deleting files
1963 (defcustom dired-recursive-deletes nil ; Default only delete empty directories.
1964 "*Decide whether recursive deletes are allowed.
1965 Nil means no recursive deletes.
1966 `always' means delete recursively without asking. This is DANGEROUS!
1967 `top' means ask for each directory at top level, but delete its subdirectories
1968 without asking.
1969 Anything else means ask for each directory."
1970 :type '(choice :tag "Delete not empty directory"
1971 (const :tag "No. Only empty directories" nil)
1972 (const :tag "Ask for each directory" t)
1973 (const :tag "Ask for each top directory only" top))
1974 :group 'dired)
1976 ;; Match anything but `.' and `..'.
1977 (defvar dired-re-no-dot "^\\([^.]\\|\\.\\([^.]\\|\\..\\)\\).*")
1979 ;; Delete file, possibly delete a directory and all its files.
1980 ;; This function is usefull outside of dired. One could change it's name
1981 ;; to e.g. recursive-delete-file and put it somewhere else.
1982 (defun dired-delete-file (file &optional recursive) "\
1983 Delete FILE or directory (possibly recursively if optional RECURSIVE is true.)
1984 RECURSIVE determines what to do with a non-empty directory. If RECURSIVE is:
1985 Nil, do not delete.
1986 `always', delete recursively without asking.
1987 `top', ask for each directory at top level.
1988 Anything else, ask for each sub-directory."
1989 (let (files)
1990 ;; This test is equivalent to
1991 ;; (and (file-directory-p fn) (not (file-symlink-p fn)))
1992 ;; but more efficient
1993 (if (not (eq t (car (file-attributes file))))
1994 (delete-file file)
1995 (when (and recursive
1996 (setq files
1997 (directory-files file t dired-re-no-dot)) ; Not empty.
1998 (or (eq recursive 'always)
1999 (yes-or-no-p (format "Recursive delete of %s "
2000 (dired-make-relative file)))))
2001 (if (eq recursive 'top) (setq recursive 'always)) ; Don't ask again.
2002 (while files ; Recursively delete (possibly asking).
2003 (dired-delete-file (car files) recursive)
2004 (setq files (cdr files))))
2005 (delete-directory file))))
2007 (defun dired-do-flagged-delete (&optional nomessage)
2008 "In Dired, delete the files flagged for deletion.
2009 If NOMESSAGE is non-nil, we don't display any message
2010 if there are no flagged files."
2011 (interactive)
2012 (let* ((dired-marker-char dired-del-marker)
2013 (regexp (dired-marker-regexp))
2014 case-fold-search)
2015 (if (save-excursion (goto-char (point-min))
2016 (re-search-forward regexp nil t))
2017 (dired-internal-do-deletions
2018 ;; this can't move point since ARG is nil
2019 (dired-map-over-marks (cons (dired-get-filename) (point))
2020 nil)
2021 nil)
2022 (or nomessage
2023 (message "(No deletions requested)")))))
2025 (defun dired-do-delete (&optional arg)
2026 "Delete all marked (or next ARG) files."
2027 ;; This is more consistent with the file marking feature than
2028 ;; dired-do-flagged-delete.
2029 (interactive "P")
2030 (dired-internal-do-deletions
2031 ;; this may move point if ARG is an integer
2032 (dired-map-over-marks (cons (dired-get-filename) (point))
2033 arg)
2034 arg))
2036 (defvar dired-deletion-confirmer 'yes-or-no-p) ; or y-or-n-p?
2038 (defun dired-internal-do-deletions (l arg)
2039 ;; L is an alist of files to delete, with their buffer positions.
2040 ;; ARG is the prefix arg.
2041 ;; Filenames are absolute (VMS needs this for logical search paths).
2042 ;; (car L) *must* be the *last* (bottommost) file in the dired buffer.
2043 ;; That way as changes are made in the buffer they do not shift the
2044 ;; lines still to be changed, so the (point) values in L stay valid.
2045 ;; Also, for subdirs in natural order, a subdir's files are deleted
2046 ;; before the subdir itself - the other way around would not work.
2047 (let ((files (mapcar (function car) l))
2048 (count (length l))
2049 (succ 0))
2050 ;; canonicalize file list for pop up
2051 (setq files (nreverse (mapcar (function dired-make-relative) files)))
2052 (if (dired-mark-pop-up
2053 " *Deletions*" 'delete files dired-deletion-confirmer
2054 (format "Delete %s " (dired-mark-prompt arg files)))
2055 (save-excursion
2056 (let (failures);; files better be in reverse order for this loop!
2057 (while l
2058 (goto-char (cdr (car l)))
2059 (let (buffer-read-only)
2060 (condition-case err
2061 (let ((fn (car (car l))))
2062 (dired-delete-file fn dired-recursive-deletes)
2063 ;; if we get here, removing worked
2064 (setq succ (1+ succ))
2065 (message "%s of %s deletions" succ count)
2066 (delete-region (progn (beginning-of-line) (point))
2067 (progn (forward-line 1) (point)))
2068 (dired-clean-up-after-deletion fn))
2069 (error;; catch errors from failed deletions
2070 (dired-log "%s\n" err)
2071 (setq failures (cons (car (car l)) failures)))))
2072 (setq l (cdr l)))
2073 (if (not failures)
2074 (message "%d deletion%s done" count (dired-plural-s count))
2075 (dired-log-summary
2076 (format "%d of %d deletion%s failed"
2077 (length failures) count
2078 (dired-plural-s count))
2079 failures))))
2080 (message "(No deletions performed)")))
2081 (dired-move-to-filename))
2083 ;; This is a separate function for the sake of dired-x.el.
2084 (defun dired-clean-up-after-deletion (fn)
2085 ;; Clean up after a deleted file or directory FN.
2086 (save-excursion (and (cdr dired-subdir-alist)
2087 (dired-goto-subdir fn)
2088 (dired-kill-subdir))))
2090 ;; Confirmation
2092 (defun dired-marker-regexp ()
2093 (concat "^" (regexp-quote (char-to-string dired-marker-char))))
2095 (defun dired-plural-s (count)
2096 (if (= 1 count) "" "s"))
2098 (defun dired-mark-prompt (arg files)
2099 ;; Return a string for use in a prompt, either the current file
2100 ;; name, or the marker and a count of marked files.
2101 (let ((count (length files)))
2102 (if (= count 1)
2103 (car files)
2104 ;; more than 1 file:
2105 (if (integerp arg)
2106 ;; abs(arg) = count
2107 ;; Perhaps this is nicer, but it also takes more screen space:
2108 ;;(format "[%s %d files]" (if (> arg 0) "next" "previous")
2109 ;; count)
2110 (format "[next %d files]" arg)
2111 (format "%c [%d files]" dired-marker-char count)))))
2113 (defun dired-pop-to-buffer (buf)
2114 ;; Pop up buffer BUF.
2115 ;; If dired-shrink-to-fit is t, make its window fit its contents.
2116 (if (not dired-shrink-to-fit)
2117 (pop-to-buffer (get-buffer-create buf))
2118 ;; let window shrink to fit:
2119 (let ((window (selected-window))
2120 target-lines w2)
2121 (cond ;; if split-window-threshold is enabled, use the largest window
2122 ((and (> (window-height (setq w2 (get-largest-window)))
2123 split-height-threshold)
2124 (= (frame-width) (window-width w2)))
2125 (setq window w2))
2126 ;; if the least-recently-used window is big enough, use it
2127 ((and (> (window-height (setq w2 (get-lru-window)))
2128 (* 2 window-min-height))
2129 (= (frame-width) (window-width w2)))
2130 (setq window w2)))
2131 (save-excursion
2132 (set-buffer buf)
2133 (goto-char (point-max))
2134 (skip-chars-backward "\n\r\t ")
2135 (setq target-lines (count-lines (point-min) (point)))
2136 ;; Don't forget to count the last line.
2137 (if (not (bolp))
2138 (setq target-lines (1+ target-lines))))
2139 (if (<= (window-height window) (* 2 window-min-height))
2140 ;; At this point, every window on the frame is too small to split.
2141 (setq w2 (display-buffer buf))
2142 (setq w2 (split-window window
2143 (max window-min-height
2144 (- (window-height window)
2145 (1+ (max window-min-height target-lines)))))))
2146 (set-window-buffer w2 buf)
2147 (if (< (1- (window-height w2)) target-lines)
2148 (progn
2149 (select-window w2)
2150 (enlarge-window (- target-lines (1- (window-height w2))))))
2151 (set-window-start w2 1)
2154 (defvar dired-no-confirm nil
2155 "A list of symbols for commands dired should not confirm.
2156 Command symbols are `byte-compile', `chgrp', `chmod', `chown', `compress',
2157 `copy', `delete', `hardlink', `load', `move', `print', `shell', `symlink' and
2158 `uncompress'.")
2160 (defun dired-mark-pop-up (bufname op-symbol files function &rest args)
2161 "Args BUFNAME OP-SYMBOL FILES FUNCTION &rest ARGS.
2162 Return FUNCTION's result on ARGS after popping up a window (in a buffer
2163 named BUFNAME, nil gives \" *Marked Files*\") showing the marked
2164 files. Uses function `dired-pop-to-buffer' to do that.
2165 FUNCTION should not manipulate files.
2166 It should only read input (an argument or confirmation).
2167 The window is not shown if there is just one file or
2168 OP-SYMBOL is a member of the list in `dired-no-confirm'.
2169 FILES is the list of marked files."
2170 (or bufname (setq bufname " *Marked Files*"))
2171 (if (or (eq dired-no-confirm t)
2172 (memq op-symbol dired-no-confirm)
2173 (= (length files) 1))
2174 (apply function args)
2175 (with-current-buffer (get-buffer-create bufname)
2176 (erase-buffer)
2177 (dired-format-columns-of-files files)
2178 (remove-text-properties (point-min) (point-max)
2179 '(mouse-face nil help-echo nil)))
2180 (save-window-excursion
2181 (dired-pop-to-buffer bufname)
2182 (apply function args))))
2184 (defun dired-format-columns-of-files (files)
2185 ;; Files should be in forward order for this loop.
2186 ;; i.e., (car files) = first file in buffer.
2187 ;; Returns the number of lines used.
2188 (let* ((maxlen (+ 2 (apply 'max (mapcar 'length files))))
2189 (width (- (window-width (selected-window)) 2))
2190 (columns (max 1 (/ width maxlen)))
2191 (nfiles (length files))
2192 (rows (+ (/ nfiles columns)
2193 (if (zerop (% nfiles columns)) 0 1)))
2194 (i 0)
2195 (j 0))
2196 (setq files (nconc (copy-sequence files) ; fill up with empty fns
2197 (make-list (- (* columns rows) nfiles) "")))
2198 (setcdr (nthcdr (1- (length files)) files) files) ; make circular
2199 (while (< j rows)
2200 (while (< i columns)
2201 (indent-to (* i maxlen))
2202 (insert (car files))
2203 (setq files (nthcdr rows files)
2204 i (1+ i)))
2205 (insert "\n")
2206 (setq i 0
2207 j (1+ j)
2208 files (cdr files)))
2209 rows))
2211 ;; Commands to mark or flag file(s) at or near current line.
2213 (defun dired-repeat-over-lines (arg function)
2214 ;; This version skips non-file lines.
2215 (let ((pos (make-marker)))
2216 (beginning-of-line)
2217 (while (and (> arg 0) (not (eobp)))
2218 (setq arg (1- arg))
2219 (beginning-of-line)
2220 (while (and (not (eobp)) (dired-between-files)) (forward-line 1))
2221 (save-excursion
2222 (forward-line 1)
2223 (move-marker pos (1+ (point))))
2224 (save-excursion (funcall function))
2225 ;; Advance to the next line--actually, to the line that *was* next.
2226 ;; (If FUNCTION inserted some new lines in between, skip them.)
2227 (goto-char pos))
2228 (while (and (< arg 0) (not (bobp)))
2229 (setq arg (1+ arg))
2230 (forward-line -1)
2231 (while (and (not (bobp)) (dired-between-files)) (forward-line -1))
2232 (beginning-of-line)
2233 (save-excursion (funcall function)))
2234 (move-marker pos nil)
2235 (dired-move-to-filename)))
2237 (defun dired-between-files ()
2238 ;; Point must be at beginning of line
2239 ;; Should be equivalent to (save-excursion (not (dired-move-to-filename)))
2240 ;; but is about 1.5..2.0 times as fast. (Actually that's not worth it)
2241 (or (looking-at "^$\\|^. *$\\|^. total\\|^. wildcard\\|^. used\\|^. find")
2242 (and (looking-at dired-subdir-regexp)
2243 (save-excursion (not (dired-move-to-filename))))))
2245 (defun dired-next-marked-file (arg &optional wrap opoint)
2246 "Move to the next marked file, wrapping around the end of the buffer."
2247 (interactive "p\np")
2248 (or opoint (setq opoint (point)));; return to where interactively started
2249 (if (if (> arg 0)
2250 (re-search-forward dired-re-mark nil t arg)
2251 (beginning-of-line)
2252 (re-search-backward dired-re-mark nil t (- arg)))
2253 (dired-move-to-filename)
2254 (if (null wrap)
2255 (progn
2256 (goto-char opoint)
2257 (error "No next marked file"))
2258 (message "(Wraparound for next marked file)")
2259 (goto-char (if (> arg 0) (point-min) (point-max)))
2260 (dired-next-marked-file arg nil opoint))))
2262 (defun dired-prev-marked-file (arg &optional wrap)
2263 "Move to the previous marked file, wrapping around the end of the buffer."
2264 (interactive "p\np")
2265 (dired-next-marked-file (- arg) wrap))
2267 (defun dired-file-marker (file)
2268 ;; Return FILE's marker, or nil if unmarked.
2269 (save-excursion
2270 (and (dired-goto-file file)
2271 (progn
2272 (beginning-of-line)
2273 (if (not (equal ?\040 (following-char)))
2274 (following-char))))))
2276 (defun dired-mark-files-in-region (start end)
2277 (let (buffer-read-only)
2278 (if (> start end)
2279 (error "start > end"))
2280 (goto-char start) ; assumed at beginning of line
2281 (while (< (point) end)
2282 ;; Skip subdir line and following garbage like the `total' line:
2283 (while (and (< (point) end) (dired-between-files))
2284 (forward-line 1))
2285 (if (and (not (looking-at dired-re-dot))
2286 (dired-get-filename nil t))
2287 (progn
2288 (delete-char 1)
2289 (insert dired-marker-char)))
2290 (forward-line 1))))
2292 (defun dired-mark (arg)
2293 "Mark the current (or next ARG) files.
2294 If on a subdir headerline, mark all its files except `.' and `..'.
2296 Use \\[dired-unmark-all-files] to remove all marks
2297 and \\[dired-unmark] on a subdir to remove the marks in
2298 this subdir."
2299 (interactive "P")
2300 (if (dired-get-subdir)
2301 (save-excursion (dired-mark-subdir-files))
2302 (let (buffer-read-only)
2303 (dired-repeat-over-lines
2304 (prefix-numeric-value arg)
2305 (function (lambda () (delete-char 1) (insert dired-marker-char)))))))
2307 (defun dired-unmark (arg)
2308 "Unmark the current (or next ARG) files.
2309 If looking at a subdir, unmark all its files except `.' and `..'."
2310 (interactive "P")
2311 (let ((dired-marker-char ?\040))
2312 (dired-mark arg)))
2314 (defun dired-flag-file-deletion (arg)
2315 "In Dired, flag the current line's file for deletion.
2316 With prefix arg, repeat over several lines.
2318 If on a subdir headerline, mark all its files except `.' and `..'."
2319 (interactive "P")
2320 (let ((dired-marker-char dired-del-marker))
2321 (dired-mark arg)))
2323 (defun dired-unmark-backward (arg)
2324 "In Dired, move up lines and remove deletion flag there.
2325 Optional prefix ARG says how many lines to unflag; default is one line."
2326 (interactive "p")
2327 (dired-unmark (- arg)))
2329 (defun dired-do-toggle ()
2330 "Toggle marks.
2331 That is, currently marked files become unmarked and vice versa.
2332 Files marked with other flags (such as `D') are not affected.
2333 `.' and `..' are never toggled.
2334 As always, hidden subdirs are not affected."
2335 (interactive)
2336 (save-excursion
2337 (goto-char (point-min))
2338 (let (buffer-read-only)
2339 (while (not (eobp))
2340 (or (dired-between-files)
2341 (looking-at dired-re-dot)
2342 ;; use subst instead of insdel because it does not move
2343 ;; the gap and thus should be faster and because
2344 ;; other characters are left alone automatically
2345 (apply 'subst-char-in-region
2346 (point) (1+ (point))
2347 (if (eq ?\040 (following-char)) ; SPC
2348 (list ?\040 dired-marker-char)
2349 (list dired-marker-char ?\040))))
2350 (forward-line 1)))))
2352 ;;; Commands to mark or flag files based on their characteristics or names.
2354 (defvar dired-regexp-history nil
2355 "History list of regular expressions used in Dired commands.")
2357 (defun dired-read-regexp (prompt)
2358 (read-from-minibuffer prompt nil nil nil 'dired-regexp-history))
2360 (defun dired-mark-files-regexp (regexp &optional marker-char)
2361 "Mark all files matching REGEXP for use in later commands.
2362 A prefix argument means to unmark them instead.
2363 `.' and `..' are never marked.
2365 REGEXP is an Emacs regexp, not a shell wildcard. Thus, use `\\.o$' for
2366 object files--just `.o' will mark more than you might think."
2367 (interactive
2368 (list (dired-read-regexp (concat (if current-prefix-arg "Unmark" "Mark")
2369 " files (regexp): "))
2370 (if current-prefix-arg ?\040)))
2371 (let ((dired-marker-char (or marker-char dired-marker-char)))
2372 (dired-mark-if
2373 (and (not (looking-at dired-re-dot))
2374 (not (eolp)) ; empty line
2375 (let ((fn (dired-get-filename nil t)))
2376 (and fn (string-match regexp (file-name-nondirectory fn)))))
2377 "matching file")))
2379 (defun dired-mark-files-containing-regexp (regexp &optional marker-char)
2380 "Mark all files with contents containing REGEXP for use in later commands.
2381 A prefix argument means to unmark them instead.
2382 `.' and `..' are never marked."
2383 (interactive
2384 (list (dired-read-regexp (concat (if current-prefix-arg "Unmark" "Mark")
2385 " files containing (regexp): "))
2386 (if current-prefix-arg ?\040)))
2387 (let ((dired-marker-char (or marker-char dired-marker-char)))
2388 (dired-mark-if
2389 (and (not (looking-at dired-re-dot))
2390 (not (eolp)) ; empty line
2391 (let ((fn (dired-get-filename nil t)))
2392 (when (and fn (file-readable-p fn)
2393 (not (file-directory-p fn)))
2394 (let ((prebuf (get-file-buffer fn)))
2395 (message "Checking %s" fn)
2396 ;; For now we do it inside emacs
2397 ;; Grep might be better if there are a lot of files
2398 (if prebuf
2399 (with-current-buffer prebuf
2400 (save-excursion
2401 (goto-char (point-min))
2402 (re-search-forward regexp nil t)))
2403 (with-temp-buffer
2404 (insert-file-contents fn)
2405 (goto-char (point-min))
2406 (re-search-forward regexp nil t))))
2408 "matching file")))
2410 (defun dired-flag-files-regexp (regexp)
2411 "In Dired, flag all files containing the specified REGEXP for deletion.
2412 The match is against the non-directory part of the filename. Use `^'
2413 and `$' to anchor matches. Exclude subdirs by hiding them.
2414 `.' and `..' are never flagged."
2415 (interactive (list (dired-read-regexp "Flag for deletion (regexp): ")))
2416 (dired-mark-files-regexp regexp dired-del-marker))
2418 (defun dired-mark-symlinks (unflag-p)
2419 "Mark all symbolic links.
2420 With prefix argument, unflag all those files."
2421 (interactive "P")
2422 (let ((dired-marker-char (if unflag-p ?\040 dired-marker-char)))
2423 (dired-mark-if (looking-at dired-re-sym) "symbolic link")))
2425 (defun dired-mark-directories (unflag-p)
2426 "Mark all directory file lines except `.' and `..'.
2427 With prefix argument, unflag all those files."
2428 (interactive "P")
2429 (let ((dired-marker-char (if unflag-p ?\040 dired-marker-char)))
2430 (dired-mark-if (and (looking-at dired-re-dir)
2431 (not (looking-at dired-re-dot)))
2432 "directory file")))
2434 (defun dired-mark-executables (unflag-p)
2435 "Mark all executable files.
2436 With prefix argument, unflag all those files."
2437 (interactive "P")
2438 (let ((dired-marker-char (if unflag-p ?\040 dired-marker-char)))
2439 (dired-mark-if (looking-at dired-re-exe) "executable file")))
2441 ;; dired-x.el has a dired-mark-sexp interactive command: mark
2442 ;; files for which PREDICATE returns non-nil.
2444 (defun dired-flag-auto-save-files (&optional unflag-p)
2445 "Flag for deletion files whose names suggest they are auto save files.
2446 A prefix argument says to unflag those files instead."
2447 (interactive "P")
2448 (let ((dired-marker-char (if unflag-p ?\040 dired-del-marker)))
2449 (dired-mark-if
2450 ;; It is less than general to check for # here,
2451 ;; but it's the only way this runs fast enough.
2452 (and (save-excursion (end-of-line)
2454 (eq (preceding-char) ?#)
2455 ;; Handle executables in case of -F option.
2456 ;; We need not worry about the other kinds
2457 ;; of markings that -F makes, since they won't
2458 ;; appear on real auto-save files.
2459 (if (eq (preceding-char) ?*)
2460 (progn
2461 (forward-char -1)
2462 (eq (preceding-char) ?#)))))
2463 (not (looking-at dired-re-dir))
2464 (let ((fn (dired-get-filename t t)))
2465 (if fn (auto-save-file-name-p
2466 (file-name-nondirectory fn)))))
2467 "auto save file")))
2469 (defvar dired-garbage-files-regexp
2470 "\\.log$\\|\\.toc$\\|\\.dvi$\\|\\.bak$\\|\\.orig$\\|\\.rej$"
2471 "*Regular expression to match \"garbage\" files for `dired-flag-garbage-files'.")
2473 (defun dired-flag-garbage-files ()
2474 "Flag for deletion all files that match `dired-garbage-files-regexp'."
2475 (interactive)
2476 (dired-flag-files-regexp dired-garbage-files-regexp))
2478 (defun dired-flag-backup-files (&optional unflag-p)
2479 "Flag all backup files (names ending with `~') for deletion.
2480 With prefix argument, unflag these files."
2481 (interactive "P")
2482 (let ((dired-marker-char (if unflag-p ?\ dired-del-marker)))
2483 (dired-mark-if
2484 ;; Don't call backup-file-name-p unless the last character looks like
2485 ;; it might be the end of a backup file name. This isn't very general,
2486 ;; but it's the only way this runs fast enough.
2487 (and (save-excursion (end-of-line)
2488 ;; Handle executables in case of -F option.
2489 ;; We need not worry about the other kinds
2490 ;; of markings that -F makes, since they won't
2491 ;; appear on real backup files.
2492 (if (eq (preceding-char) ?*)
2493 (forward-char -1))
2494 (eq (preceding-char) ?~))
2495 (not (looking-at dired-re-dir))
2496 (let ((fn (dired-get-filename t t)))
2497 (if fn (backup-file-name-p fn))))
2498 "backup file")))
2500 (defun dired-change-marks (&optional old new)
2501 "Change all OLD marks to NEW marks.
2502 OLD and NEW are both characters used to mark files."
2503 (interactive
2504 (let* ((cursor-in-echo-area t)
2505 (old (progn (message "Change (old mark): ") (read-char)))
2506 (new (progn (message "Change %c marks to (new mark): " old)
2507 (read-char))))
2508 (list old new)))
2509 (if (or (eq old ?\r) (eq new ?\r))
2510 (ding)
2511 (let ((string (format "\n%c" old))
2512 (buffer-read-only))
2513 (save-excursion
2514 (goto-char (point-min))
2515 (while (search-forward string nil t)
2516 (if (if (= old ?\ )
2517 (save-match-data
2518 (dired-get-filename 'no-dir t))
2520 (subst-char-in-region (match-beginning 0)
2521 (match-end 0) old new)))))))
2523 (defun dired-unmark-all-marks ()
2524 "Remove all marks from all files in the Dired buffer."
2525 (interactive)
2526 (dired-unmark-all-files ?\r))
2528 (defun dired-unmark-all-files (mark &optional arg)
2529 "Remove a specific mark (or any mark) from every file.
2530 After this command, type the mark character to remove,
2531 or type RET to remove all marks.
2532 With prefix arg, query for each marked file.
2533 Type \\[help-command] at that time for help."
2534 (interactive "cRemove marks (RET means all): \nP")
2535 (save-excursion
2536 (let* ((count 0)
2537 buffer-read-only case-fold-search query
2538 (string (format "\n%c" mark))
2539 (help-form "\
2540 Type SPC or `y' to unmark one file, DEL or `n' to skip to next,
2541 `!' to unmark all remaining files with no more questions."))
2542 (goto-char (point-min))
2543 (while (if (eq mark ?\r)
2544 (re-search-forward dired-re-mark nil t)
2545 (search-forward string nil t))
2546 (if (or (not arg)
2547 (dired-query 'query "Unmark file `%s'? "
2548 (dired-get-filename t)))
2549 (progn (subst-char-in-region (1- (point)) (point)
2550 (preceding-char) ?\ )
2551 (setq count (1+ count)))))
2552 (message (if (= count 1) "1 mark removed"
2553 "%d marks removed")
2554 count))))
2556 ;; Logging failures operating on files, and showing the results.
2558 (defvar dired-log-buffer "*Dired log*")
2560 (defun dired-why ()
2561 "Pop up a buffer with error log output from Dired.
2562 A group of errors from a single command ends with a formfeed.
2563 Thus, use \\[backward-page] to find the beginning of a group of errors."
2564 (interactive)
2565 (if (get-buffer dired-log-buffer)
2566 (let ((owindow (selected-window))
2567 (window (display-buffer (get-buffer dired-log-buffer))))
2568 (unwind-protect
2569 (progn
2570 (select-window window)
2571 (goto-char (point-max))
2572 (recenter -1))
2573 (select-window owindow)))))
2575 (defun dired-log (log &rest args)
2576 ;; Log a message or the contents of a buffer.
2577 ;; If LOG is a string and there are more args, it is formatted with
2578 ;; those ARGS. Usually the LOG string ends with a \n.
2579 ;; End each bunch of errors with (dired-log t): this inserts
2580 ;; current time and buffer, and a \f (formfeed).
2581 (let ((obuf (current-buffer)))
2582 (unwind-protect ; want to move point
2583 (progn
2584 (set-buffer (get-buffer-create dired-log-buffer))
2585 (goto-char (point-max))
2586 (let (buffer-read-only)
2587 (cond ((stringp log)
2588 (insert (if args
2589 (apply (function format) log args)
2590 log)))
2591 ((bufferp log)
2592 (insert-buffer log))
2593 ((eq t log)
2594 (insert "\n\t" (current-time-string)
2595 "\tBuffer `" (buffer-name obuf) "'\n\f\n")))))
2596 (set-buffer obuf))))
2598 (defun dired-log-summary (string failures)
2599 (message (if failures "%s--type ? for details (%s)"
2600 "%s--type ? for details")
2601 string failures)
2602 ;; Log a summary describing a bunch of errors.
2603 (dired-log (concat "\n" string))
2604 (dired-log t))
2606 ;;; Sorting
2608 ;; Most ls can only sort by name or by date (with -t), nothing else.
2609 ;; GNU ls sorts on size with -S, on extension with -X, and unsorted with -U.
2610 ;; So anything that does not contain these is sort "by name".
2612 (defvar dired-ls-sorting-switches "SXU"
2613 "String of `ls' switches (single letters) except `t' that influence sorting.")
2615 (defvar dired-sort-by-date-regexp
2616 (concat "^-[^" dired-ls-sorting-switches
2617 "]*t[^" dired-ls-sorting-switches "]*$")
2618 "Regexp recognized by dired to set `by date' mode.")
2620 (defvar dired-sort-by-name-regexp
2621 (concat "^-[^t" dired-ls-sorting-switches "]+$")
2622 "Regexp recognized by dired to set `by name' mode.")
2624 (defun dired-sort-set-modeline ()
2625 ;; Set modeline display according to dired-actual-switches.
2626 ;; Modeline display of "by name" or "by date" guarantees the user a
2627 ;; match with the corresponding regexps. Non-matching switches are
2628 ;; shown literally.
2629 (setq mode-name
2630 (let (case-fold-search)
2631 (cond ((string-match dired-sort-by-name-regexp dired-actual-switches)
2632 "Dired by name")
2633 ((string-match dired-sort-by-date-regexp dired-actual-switches)
2634 "Dired by date")
2636 (concat "Dired " dired-actual-switches)))))
2637 (force-mode-line-update))
2639 (defun dired-sort-toggle-or-edit (&optional arg)
2640 "Toggle between sort by date/name and refresh the dired buffer.
2641 With a prefix argument you can edit the current listing switches instead."
2642 (interactive "P")
2643 (if arg
2644 (dired-sort-other
2645 (read-string "ls switches (must contain -l): " dired-actual-switches))
2646 (dired-sort-toggle)))
2648 (defun dired-sort-toggle ()
2649 ;; Toggle between sort by date/name. Reverts the buffer.
2650 (setq dired-actual-switches
2651 (let (case-fold-search)
2652 (if (string-match " " dired-actual-switches)
2653 ;; New toggle scheme: add/remove a trailing " -t"
2654 (if (string-match " -t\\'" dired-actual-switches)
2655 (dired-replace-in-string " -t\\'" "" dired-actual-switches)
2656 (concat dired-actual-switches " -t"))
2657 ;; old toggle scheme: look for some 't' switch and add/remove it
2658 (concat
2659 "-l"
2660 (dired-replace-in-string (concat "[-lt"
2661 dired-ls-sorting-switches "]")
2663 dired-actual-switches)
2664 (if (string-match (concat "[t" dired-ls-sorting-switches "]")
2665 dired-actual-switches)
2667 "t")))))
2668 (dired-sort-set-modeline)
2669 (revert-buffer))
2671 ;; Some user code loads dired especially for this.
2672 (defun dired-replace-in-string (regexp newtext string)
2673 ;; Replace REGEXP with NEWTEXT everywhere in STRING and return result.
2674 ;; NEWTEXT is taken literally---no \\DIGIT escapes will be recognized.
2675 (let ((result "") (start 0) mb me)
2676 (while (string-match regexp string start)
2677 (setq mb (match-beginning 0)
2678 me (match-end 0)
2679 result (concat result (substring string start mb) newtext)
2680 start me))
2681 (concat result (substring string start))))
2683 (defun dired-sort-other (switches &optional no-revert)
2684 ;; Specify new ls SWITCHES for current dired buffer. Values matching
2685 ;; `dired-sort-by-date-regexp' or `dired-sort-by-name-regexp' set the
2686 ;; minor mode accordingly, others appear literally in the mode line.
2687 ;; With optional second arg NO-REVERT, don't refresh the listing afterwards.
2688 (dired-sort-R-check switches)
2689 (setq dired-actual-switches switches)
2690 (if (eq major-mode 'dired-mode) (dired-sort-set-modeline))
2691 (or no-revert (revert-buffer)))
2693 (make-variable-buffer-local
2694 (defvar dired-subdir-alist-pre-R nil
2695 "Value of `dired-subdir-alist' before -R switch added."))
2697 (defun dired-sort-R-check (switches)
2698 "Additional processing of -R in ls option string SWITCHES.
2699 Saves `dired-subdir-alist' when R is set and restores saved value
2700 minus any directories explicitly deleted when R is cleared.
2701 To be called first in body of `dired-sort-other', etc."
2702 (cond
2703 ((and (string-match "R" switches)
2704 (not (string-match "R" dired-actual-switches)))
2705 ;; Adding -R to ls switches -- save `dired-subdir-alist':
2706 (setq dired-subdir-alist-pre-R dired-subdir-alist))
2707 ((and (string-match "R" dired-actual-switches)
2708 (not (string-match "R" switches)))
2709 ;; Deleting -R from ls switches -- revert to pre-R subdirs
2710 ;; that are still present:
2711 (setq dired-subdir-alist
2712 (if dired-subdir-alist-pre-R
2713 (let (subdirs)
2714 (while dired-subdir-alist-pre-R
2715 (if (assoc (caar dired-subdir-alist-pre-R)
2716 dired-subdir-alist)
2717 ;; subdir still present...
2718 (setq subdirs
2719 (cons (car dired-subdir-alist-pre-R)
2720 subdirs)))
2721 (setq dired-subdir-alist-pre-R
2722 (cdr dired-subdir-alist-pre-R)))
2723 (reverse subdirs))
2724 ;; No pre-R subdir alist, so revert to main directory
2725 ;; listing:
2726 (list (car (reverse dired-subdir-alist))))))))
2728 ;; To make this file smaller, the less common commands
2729 ;; go in a separate file. But autoload them here
2730 ;; to make the separation invisible.
2732 (autoload 'dired-diff "dired-aux"
2733 "Compare file at point with file FILE using `diff'.
2734 FILE defaults to the file at the mark. (That's the mark set by
2735 \\[set-mark-command], not by Dired's \\[dired-mark] command.)
2736 The prompted-for file is the first file given to `diff'."
2739 (autoload 'dired-backup-diff "dired-aux"
2740 "Diff this file with its backup file or vice versa.
2741 Uses the latest backup, if there are several numerical backups.
2742 If this file is a backup, diff it with its original.
2743 The backup file is the first file given to `diff'."
2746 (autoload 'dired-clean-directory "dired-aux"
2747 "Flag numerical backups for deletion.
2748 Spares `dired-kept-versions' latest versions, and `kept-old-versions' oldest.
2749 Positive prefix arg KEEP overrides `dired-kept-versions';
2750 Negative prefix arg KEEP overrides `kept-old-versions' with KEEP made positive.
2752 To clear the flags on these files, you can use \\[dired-flag-backup-files]
2753 with a prefix argument."
2756 (autoload 'dired-do-chmod "dired-aux"
2757 "Change the mode of the marked (or next ARG) files.
2758 This calls chmod, thus symbolic modes like `g+w' are allowed."
2761 (autoload 'dired-do-chgrp "dired-aux"
2762 "Change the group of the marked (or next ARG) files."
2765 (autoload 'dired-do-chown "dired-aux"
2766 "Change the owner of the marked (or next ARG) files."
2769 (autoload 'dired-do-print "dired-aux"
2770 "Print the marked (or next ARG) files.
2771 Uses the shell command coming from variables `lpr-command' and
2772 `lpr-switches' as default."
2775 (autoload 'dired-do-shell-command "dired-aux"
2776 "Run a shell command COMMAND on the marked files.
2777 If no files are marked or a specific numeric prefix arg is given,
2778 the next ARG files are used. Just \\[universal-argument] means the current file.
2779 The prompt mentions the file(s) or the marker, as appropriate.
2781 If there is output, it goes to a separate buffer.
2783 Normally the command is run on each file individually.
2784 However, if there is a `*' in the command then it is run
2785 just once with the entire file list substituted there.
2787 No automatic redisplay of dired buffers is attempted, as there's no
2788 telling what files the command may have changed. Type
2789 \\[dired-do-redisplay] to redisplay the marked files.
2791 The shell command has the top level directory as working directory, so
2792 output files usually are created there instead of in a subdir."
2795 (autoload 'dired-do-kill-lines "dired-aux"
2796 "Kill all marked lines (not the files).
2797 With a prefix arg, kill all lines not marked or flagged."
2800 (autoload 'dired-do-compress "dired-aux"
2801 "Compress or uncompress marked (or next ARG) files."
2804 (autoload 'dired-do-byte-compile "dired-aux"
2805 "Byte compile marked (or next ARG) Emacs Lisp files."
2808 (autoload 'dired-do-load "dired-aux"
2809 "Load the marked (or next ARG) Emacs Lisp files."
2812 (autoload 'dired-do-redisplay "dired-aux"
2813 "Redisplay all marked (or next ARG) files.
2814 If on a subdir line, redisplay that subdirectory. In that case,
2815 a prefix arg lets you edit the `ls' switches used for the new listing."
2818 (autoload 'dired-create-directory "dired-aux"
2819 "Create a directory called DIRECTORY."
2822 (autoload 'dired-do-copy "dired-aux"
2823 "Copy all marked (or next ARG) files, or copy the current file.
2824 Thus, a zero prefix argument copies nothing. But it toggles the
2825 variable `dired-copy-preserve-time' (which see)."
2828 (autoload 'dired-do-symlink "dired-aux"
2829 "Make symbolic links to current file or all marked (or next ARG) files.
2830 When operating on just the current file, you specify the new name.
2831 When operating on multiple or marked files, you specify a directory
2832 and new symbolic links are made in that directory
2833 with the same names that the files currently have."
2836 (autoload 'dired-do-hardlink "dired-aux"
2837 "Add names (hard links) current file or all marked (or next ARG) files.
2838 When operating on just the current file, you specify the new name.
2839 When operating on multiple or marked files, you specify a directory
2840 and new hard links are made in that directory
2841 with the same names that the files currently have."
2844 (autoload 'dired-do-rename "dired-aux"
2845 "Rename current file or all marked (or next ARG) files.
2846 When renaming just the current file, you specify the new name.
2847 When renaming multiple or marked files, you specify a directory."
2850 (autoload 'dired-do-rename-regexp "dired-aux"
2851 "Rename marked files containing REGEXP to NEWNAME.
2852 As each match is found, the user must type a character saying
2853 what to do with it. For directions, type \\[help-command] at that time.
2854 NEWNAME may contain \\=\\<n> or \\& as in `query-replace-regexp'.
2855 REGEXP defaults to the last regexp used.
2856 With a zero prefix arg, renaming by regexp affects the complete
2857 pathname - usually only the non-directory part of file names is used
2858 and changed."
2861 (autoload 'dired-do-copy-regexp "dired-aux"
2862 "Copy all marked files containing REGEXP to NEWNAME.
2863 See function `dired-do-rename-regexp' for more info."
2866 (autoload 'dired-do-hardlink-regexp "dired-aux"
2867 "Hardlink all marked files containing REGEXP to NEWNAME.
2868 See function `dired-do-rename-regexp' for more info."
2871 (autoload 'dired-do-symlink-regexp "dired-aux"
2872 "Symlink all marked files containing REGEXP to NEWNAME.
2873 See function `dired-do-rename-regexp' for more info."
2876 (autoload 'dired-upcase "dired-aux"
2877 "Rename all marked (or next ARG) files to upper case."
2880 (autoload 'dired-downcase "dired-aux"
2881 "Rename all marked (or next ARG) files to lower case."
2884 (autoload 'dired-maybe-insert-subdir "dired-aux"
2885 "Insert this subdirectory into the same dired buffer.
2886 If it is already present, just move to it (type \\[dired-do-redisplay] to refresh),
2887 else inserts it at its natural place (as `ls -lR' would have done).
2888 With a prefix arg, you may edit the ls switches used for this listing.
2889 You can add `R' to the switches to expand the whole tree starting at
2890 this subdirectory.
2891 This function takes some pains to conform to `ls -lR' output."
2894 (autoload 'dired-next-subdir "dired-aux"
2895 "Go to next subdirectory, regardless of level."
2898 (autoload 'dired-prev-subdir "dired-aux"
2899 "Go to previous subdirectory, regardless of level.
2900 When called interactively and not on a subdir line, go to this subdir's line."
2903 (autoload 'dired-goto-subdir "dired-aux"
2904 "Go to end of header line of DIR in this dired buffer.
2905 Return value of point on success, otherwise return nil.
2906 The next char is either \\n, or \\r if DIR is hidden."
2909 (autoload 'dired-mark-subdir-files "dired-aux"
2910 "Mark all files except `.' and `..'."
2913 (autoload 'dired-kill-subdir "dired-aux"
2914 "Remove all lines of current subdirectory.
2915 Lower levels are unaffected."
2918 (autoload 'dired-tree-up "dired-aux"
2919 "Go up ARG levels in the dired tree."
2922 (autoload 'dired-tree-down "dired-aux"
2923 "Go down in the dired tree."
2926 (autoload 'dired-hide-subdir "dired-aux"
2927 "Hide or unhide the current subdirectory and move to next directory.
2928 Optional prefix arg is a repeat factor.
2929 Use \\[dired-hide-all] to (un)hide all directories."
2932 (autoload 'dired-hide-all "dired-aux"
2933 "Hide all subdirectories, leaving only their header lines.
2934 If there is already something hidden, make everything visible again.
2935 Use \\[dired-hide-subdir] to (un)hide a particular subdirectory."
2938 (autoload 'dired-show-file-type "dired-aux"
2939 "Print the type of FILE, according to the `file' command.
2940 If FILE is a symbolic link and the optional argument DEREF-SYMLINKS is
2941 true then the type of the file linked to by FILE is printed instead."
2944 (if (eq system-type 'vax-vms)
2945 (load "dired-vms"))
2947 (provide 'dired)
2949 (run-hooks 'dired-load-hook) ; for your customizations
2951 ;;; dired.el ends here