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