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