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