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