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