Regenerate autotools stuff, grumble.
[emacs.git] / lisp / dired.el
blobc4374503a6f3ea6bb5cc9f8018d4d0a9f504b75b
1 ;;; dired.el --- directory-browsing commands
3 ;; Copyright (C) 1985-1986, 1992-1997, 2000-2011
4 ;; Free Software Foundation, Inc.
6 ;; Author: Sebastian Kremer <sk@thp.uni-koeln.de>
7 ;; Maintainer: FSF
8 ;; Keywords: files
9 ;; Package: emacs
11 ;; This file is part of GNU Emacs.
13 ;; GNU Emacs is free software: you can redistribute it and/or modify
14 ;; it under the terms of the GNU General Public License as published by
15 ;; the Free Software Foundation, either version 3 of the License, or
16 ;; (at your option) any later version.
18 ;; GNU Emacs is distributed in the hope that it will be useful,
19 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 ;; GNU General Public License for more details.
23 ;; You should have received a copy of the GNU General Public License
24 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
26 ;;; Commentary:
28 ;; This is a major mode for directory browsing and editing.
29 ;; It is documented in the Emacs manual.
31 ;; Rewritten in 1990/1991 to add tree features, file marking and
32 ;; sorting by Sebastian Kremer <sk@thp.uni-koeln.de>.
33 ;; Finished up by rms in 1992.
35 ;;; Code:
37 (eval-when-compile (require 'cl))
39 ;;; Customizable variables
41 (defgroup dired nil
42 "Directory editing."
43 :link '(custom-manual "(emacs)Dired")
44 :group 'files)
46 (defgroup dired-mark nil
47 "Handling marks in Dired."
48 :prefix "dired-"
49 :group 'dired)
52 ;;;###autoload
53 (defcustom dired-listing-switches (purecopy "-al")
54 "Switches passed to `ls' for Dired. MUST contain the `l' option.
55 May contain all other options that don't contradict `-l';
56 may contain even `F', `b', `i' and `s'. See also the variable
57 `dired-ls-F-marks-symlinks' concerning the `F' switch.
58 On systems such as MS-DOS and MS-Windows, which use `ls' emulation in Lisp,
59 some of the `ls' switches are not supported; see the doc string of
60 `insert-directory' in `ls-lisp.el' for more details."
61 :type 'string
62 :group 'dired)
64 (defcustom dired-subdir-switches nil
65 "If non-nil, switches passed to `ls' for inserting subdirectories.
66 If nil, `dired-listing-switches' is used."
67 :group 'dired
68 :type '(choice (const :tag "Use dired-listing-switches" nil)
69 (string :tag "Switches")))
71 (defcustom dired-chown-program
72 (purecopy (cond ((executable-find "chown") "chown")
73 ((file-executable-p "/usr/sbin/chown") "/usr/sbin/chown")
74 ((file-executable-p "/etc/chown") "/etc/chown")
75 (t "chown")))
76 "Name of chown command (usually `chown')."
77 :group 'dired
78 :type 'file)
80 (defcustom dired-use-ls-dired 'unspecified
81 "Non-nil means Dired should use \"ls --dired\".
82 The special value of `unspecified' means to check explicitly, and
83 save the result in this variable. This is performed the first
84 time `dired-insert-directory' is called."
85 :group 'dired
86 :type '(choice (const :tag "Check for --dired support" unspecified)
87 (const :tag "Do not use --dired" nil)
88 (other :tag "Use --dired" t)))
90 (defcustom dired-chmod-program "chmod"
91 "Name of chmod command (usually `chmod')."
92 :group 'dired
93 :type 'file)
95 (defcustom dired-touch-program "touch"
96 "Name of touch command (usually `touch')."
97 :group 'dired
98 :type 'file)
100 (defcustom dired-ls-F-marks-symlinks nil
101 "Informs Dired about how `ls -lF' marks symbolic links.
102 Set this to t if `ls' (or whatever program is specified by
103 `insert-directory-program') with `-lF' marks the symbolic link
104 itself with a trailing @ (usually the case under Ultrix).
106 Example: if `ln -s foo bar; ls -F bar' gives `bar -> foo', set it to
107 nil (the default), if it gives `bar@ -> foo', set it to t.
109 Dired checks if there is really a @ appended. Thus, if you have a
110 marking `ls' program on one host and a non-marking on another host, and
111 don't care about symbolic links which really end in a @, you can
112 always set this variable to t."
113 :type 'boolean
114 :group 'dired-mark)
116 (defcustom dired-trivial-filenames (purecopy "^\\.\\.?$\\|^#")
117 "Regexp of files to skip when finding first file of a directory.
118 A value of nil means move to the subdir line.
119 A value of t means move to first file."
120 :type '(choice (const :tag "Move to subdir" nil)
121 (const :tag "Move to first" t)
122 regexp)
123 :group 'dired)
125 (defcustom dired-keep-marker-rename t
126 ;; Use t as default so that moved files "take their markers with them".
127 "Controls marking of renamed files.
128 If t, files keep their previous marks when they are renamed.
129 If a character, renamed files (whether previously marked or not)
130 are afterward marked with that character."
131 :type '(choice (const :tag "Keep" t)
132 (character :tag "Mark"))
133 :group 'dired-mark)
135 (defcustom dired-keep-marker-copy ?C
136 "Controls marking of copied files.
137 If t, copied files are marked if and as the corresponding original files were.
138 If a character, copied files are unconditionally marked with that character."
139 :type '(choice (const :tag "Keep" t)
140 (character :tag "Mark"))
141 :group 'dired-mark)
143 (defcustom dired-keep-marker-hardlink ?H
144 "Controls marking of newly made hard links.
145 If t, they are marked if and as the files linked to were marked.
146 If a character, new links are unconditionally marked with that character."
147 :type '(choice (const :tag "Keep" t)
148 (character :tag "Mark"))
149 :group 'dired-mark)
151 (defcustom dired-keep-marker-symlink ?Y
152 "Controls marking of newly made symbolic links.
153 If t, they are marked if and as the files linked to were marked.
154 If a character, new links are unconditionally marked with that character."
155 :type '(choice (const :tag "Keep" t)
156 (character :tag "Mark"))
157 :group 'dired-mark)
159 (defcustom dired-dwim-target nil
160 "If non-nil, Dired tries to guess a default target directory.
161 This means: if there is a dired buffer displayed in the next window,
162 use its current subdir, instead of the current subdir of this dired buffer.
164 The target is used in the prompt for file copy, rename etc."
165 :type 'boolean
166 :group 'dired)
168 (defcustom dired-copy-preserve-time t
169 "If non-nil, Dired preserves the last-modified time in a file copy.
170 \(This works on only some systems.)"
171 :type 'boolean
172 :group 'dired)
174 ; These variables were deleted and the replacements are on files.el.
175 ; We leave aliases behind for back-compatibility.
176 (defvaralias 'dired-free-space-program 'directory-free-space-program)
177 (defvaralias 'dired-free-space-args 'directory-free-space-args)
179 ;;; Hook variables
181 (defcustom dired-load-hook nil
182 "Run after loading Dired.
183 You can customize key bindings or load extensions with this."
184 :group 'dired
185 :type 'hook)
187 (defcustom dired-mode-hook nil
188 "Run at the very end of `dired-mode'."
189 :group 'dired
190 :type 'hook)
192 (defcustom dired-before-readin-hook nil
193 "This hook is run before a dired buffer is read in (created or reverted)."
194 :group 'dired
195 :type 'hook)
197 (defcustom dired-after-readin-hook nil
198 "Hook run after each time a file or directory is read by Dired.
199 After each listing of a file or directory, this hook is run
200 with the buffer narrowed to the listing."
201 :group 'dired
202 :type 'hook)
203 ;; Note this can't simply be run inside function `dired-ls' as the hook
204 ;; functions probably depend on the dired-subdir-alist to be OK.
206 (defcustom dired-dnd-protocol-alist
207 '(("^file:///" . dired-dnd-handle-local-file)
208 ("^file://" . dired-dnd-handle-file)
209 ("^file:" . dired-dnd-handle-local-file))
210 "The functions to call when a drop in `dired-mode' is made.
211 See `dnd-protocol-alist' for more information. When nil, behave
212 as in other buffers. Changing this option is effective only for
213 new dired buffers."
214 :type '(choice (repeat (cons (regexp) (function)))
215 (const :tag "Behave as in other buffers" nil))
216 :version "22.1"
217 :group 'dired)
219 ;; Internal variables
221 (defvar dired-marker-char ?* ; the answer is 42
222 ;; so that you can write things like
223 ;; (let ((dired-marker-char ?X))
224 ;; ;; great code using X markers ...
225 ;; )
226 ;; For example, commands operating on two sets of files, A and B.
227 ;; Or marking files with digits 0-9. This could implicate
228 ;; concentric sets or an order for the marked files.
229 ;; The code depends on dynamic scoping on the marker char.
230 "In Dired, the current mark character.
231 This is what the do-commands look for, and what the mark-commands store.")
233 (defvar dired-del-marker ?D
234 "Character used to flag files for deletion.")
236 (defvar dired-shrink-to-fit t
237 ;; I see no reason ever to make this nil -- rms.
238 ;; (> baud-rate search-slow-speed)
239 "Non-nil means Dired shrinks the display buffer to fit the marked files.")
241 (defvar dired-flagging-regexp nil);; Last regexp used to flag files.
243 (defvar dired-file-version-alist)
245 ;;;###autoload
246 (defvar dired-directory nil
247 "The directory name or wildcard spec that this dired directory lists.
248 Local to each dired buffer. May be a list, in which case the car is the
249 directory name and the cdr is the list of files to mention.
250 The directory name must be absolute, but need not be fully expanded.")
252 ;; Beware of "-l;reboot" etc. See bug#3230.
253 (defun dired-safe-switches-p (switches)
254 "Return non-nil if string SWITCHES does not look risky for dired."
255 (or (not switches)
256 (and (stringp switches)
257 (< (length switches) 100) ; arbitrary
258 (string-match "\\` *-[- [:alnum:]]+\\'" switches))))
260 (defvar dired-actual-switches nil
261 "The value of `dired-listing-switches' used to make this buffer's text.")
263 (put 'dired-actual-switches 'safe-local-variable 'dired-safe-switches-p)
265 (defvar dired-re-inode-size "[0-9 \t]*"
266 "Regexp for optional initial inode and file size as made by `ls -i -s'.")
268 ;; These regexps must be tested at beginning-of-line, but are also
269 ;; used to search for next matches, so neither omitting "^" nor
270 ;; replacing "^" by "\n" (to make it slightly faster) will work.
272 (defvar dired-re-mark "^[^ \n]")
273 ;; "Regexp matching a marked line.
274 ;; Important: the match ends just after the marker."
275 (defvar dired-re-maybe-mark "^. ")
276 ;; The [^:] part after "d" and "l" is to avoid confusion with the
277 ;; DOS/Windows-style drive letters in directory names, like in "d:/foo".
278 (defvar dired-re-dir (concat dired-re-maybe-mark dired-re-inode-size "d[^:]"))
279 (defvar dired-re-sym (concat dired-re-maybe-mark dired-re-inode-size "l[^:]"))
280 (defvar dired-re-exe;; match ls permission string of an executable file
281 (mapconcat (function
282 (lambda (x)
283 (concat dired-re-maybe-mark dired-re-inode-size x)))
284 '("-[-r][-w][xs][-r][-w].[-r][-w]."
285 "-[-r][-w].[-r][-w][xs][-r][-w]."
286 "-[-r][-w].[-r][-w].[-r][-w][xst]")
287 "\\|"))
288 (defvar dired-re-perms "[-bcdlps][-r][-w].[-r][-w].[-r][-w].")
289 (defvar dired-re-dot "^.* \\.\\.?/?$")
291 ;; The subdirectory names in the next two lists are expanded.
292 (defvar dired-subdir-alist nil
293 "Association list of subdirectories and their buffer positions.
294 Each subdirectory has an element: (DIRNAME . STARTMARKER).
295 The order of elements is the reverse of the order in the buffer.
296 In simple cases, this list contains one element.")
298 (defvar dired-switches-alist nil
299 "Keeps track of which switches to use for inserted subdirectories.
300 This is an alist of the form (SUBDIR . SWITCHES).")
301 (make-variable-buffer-local 'dired-switches-alist)
303 (defvaralias 'dired-move-to-filename-regexp
304 'directory-listing-before-filename-regexp)
306 (defvar dired-subdir-regexp "^. \\([^\n\r]+\\)\\(:\\)[\n\r]"
307 "Regexp matching a maybe hidden subdirectory line in `ls -lR' output.
308 Subexpression 1 is the subdirectory proper, no trailing colon.
309 The match starts at the beginning of the line and ends after the end
310 of the line (\\n or \\r).
311 Subexpression 2 must end right before the \\n or \\r.")
313 (defgroup dired-faces nil
314 "Faces used by Dired."
315 :group 'dired
316 :group 'faces)
318 (defface dired-header
319 '((t (:inherit font-lock-type-face)))
320 "Face used for directory headers."
321 :group 'dired-faces
322 :version "22.1")
323 (defvar dired-header-face 'dired-header
324 "Face name used for directory headers.")
326 (defface dired-mark
327 '((t (:inherit font-lock-constant-face)))
328 "Face used for dired marks."
329 :group 'dired-faces
330 :version "22.1")
331 (defvar dired-mark-face 'dired-mark
332 "Face name used for dired marks.")
334 (defface dired-marked
335 '((t (:inherit font-lock-warning-face)))
336 "Face used for marked files."
337 :group 'dired-faces
338 :version "22.1")
339 (defvar dired-marked-face 'dired-marked
340 "Face name used for marked files.")
342 (defface dired-flagged
343 '((t (:inherit font-lock-warning-face)))
344 "Face used for flagged files."
345 :group 'dired-faces
346 :version "22.1")
347 (defvar dired-flagged-face 'dired-flagged
348 "Face name used for flagged files.")
350 (defface dired-warning
351 ;; Inherit from font-lock-warning-face since with min-colors 8
352 ;; font-lock-comment-face is not colored any more.
353 '((t (:inherit font-lock-warning-face)))
354 "Face used to highlight a part of a buffer that needs user attention."
355 :group 'dired-faces
356 :version "22.1")
357 (defvar dired-warning-face 'dired-warning
358 "Face name used for a part of a buffer that needs user attention.")
360 (defface dired-perm-write
361 '((((type w32 pc)) :inherit default) ;; These default to rw-rw-rw.
362 ;; Inherit from font-lock-comment-delimiter-face since with min-colors 8
363 ;; font-lock-comment-face is not colored any more.
364 (t (:inherit font-lock-comment-delimiter-face)))
365 "Face used to highlight permissions of group- and world-writable files."
366 :group 'dired-faces
367 :version "22.2")
368 (defvar dired-perm-write-face 'dired-perm-write
369 "Face name used for permissions of group- and world-writable files.")
371 (defface dired-directory
372 '((t (:inherit font-lock-function-name-face)))
373 "Face used for subdirectories."
374 :group 'dired-faces
375 :version "22.1")
376 (defvar dired-directory-face 'dired-directory
377 "Face name used for subdirectories.")
379 (defface dired-symlink
380 '((t (:inherit font-lock-keyword-face)))
381 "Face used for symbolic links."
382 :group 'dired-faces
383 :version "22.1")
384 (defvar dired-symlink-face 'dired-symlink
385 "Face name used for symbolic links.")
387 (defface dired-ignored
388 '((t (:inherit shadow)))
389 "Face used for files suffixed with `completion-ignored-extensions'."
390 :group 'dired-faces
391 :version "22.1")
392 (defvar dired-ignored-face 'dired-ignored
393 "Face name used for files suffixed with `completion-ignored-extensions'.")
395 (defvar dired-font-lock-keywords
396 (list
398 ;; Dired marks.
399 (list dired-re-mark '(0 dired-mark-face))
401 ;; We make heavy use of MATCH-ANCHORED, since the regexps don't identify the
402 ;; file name itself. We search for Dired defined regexps, and then use the
403 ;; Dired defined function `dired-move-to-filename' before searching for the
404 ;; simple regexp ".+". It is that regexp which matches the file name.
406 ;; Marked files.
407 (list (concat "^[" (char-to-string dired-marker-char) "]")
408 '(".+" (dired-move-to-filename) nil (0 dired-marked-face)))
410 ;; Flagged files.
411 (list (concat "^[" (char-to-string dired-del-marker) "]")
412 '(".+" (dired-move-to-filename) nil (0 dired-flagged-face)))
413 ;; People who are paranoid about security would consider this more
414 ;; important than other things such as whether it is a directory.
415 ;; But we don't want to encourage paranoia, so our default
416 ;; should be what's most useful for non-paranoids. -- rms.
417 ;;; ;;
418 ;;; ;; Files that are group or world writable.
419 ;;; (list (concat dired-re-maybe-mark dired-re-inode-size
420 ;;; "\\([-d]\\(....w....\\|.......w.\\)\\)")
421 ;;; '(1 dired-warning-face)
422 ;;; '(".+" (dired-move-to-filename) nil (0 dired-warning-face)))
423 ;; However, we don't need to highlight the file name, only the
424 ;; permissions, to win generally. -- fx.
425 ;; Fixme: we could also put text properties on the permission
426 ;; fields with keymaps to frob the permissions, somewhat a la XEmacs.
427 (list (concat dired-re-maybe-mark dired-re-inode-size
428 "[-d]....\\(w\\)....") ; group writable
429 '(1 dired-perm-write-face))
430 (list (concat dired-re-maybe-mark dired-re-inode-size
431 "[-d].......\\(w\\).") ; world writable
432 '(1 dired-perm-write-face))
434 ;; Subdirectories.
435 (list dired-re-dir
436 '(".+" (dired-move-to-filename) nil (0 dired-directory-face)))
438 ;; Symbolic links.
439 (list dired-re-sym
440 '(".+" (dired-move-to-filename) nil (0 dired-symlink-face)))
442 ;; Files suffixed with `completion-ignored-extensions'.
443 '(eval .
444 ;; It is quicker to first find just an extension, then go back to the
445 ;; start of that file name. So we do this complex MATCH-ANCHORED form.
446 (list (concat "\\(" (regexp-opt completion-ignored-extensions) "\\|#\\)$")
447 '(".+" (dired-move-to-filename) nil (0 dired-ignored-face))))
449 ;; Files suffixed with `completion-ignored-extensions'
450 ;; plus a character put in by -F.
451 '(eval .
452 (list (concat "\\(" (regexp-opt completion-ignored-extensions)
453 "\\|#\\)[*=|]$")
454 '(".+" (progn
455 (end-of-line)
456 ;; If the last character is not part of the filename,
457 ;; move back to the start of the filename
458 ;; so it can be fontified.
459 ;; Otherwise, leave point at the end of the line;
460 ;; that way, nothing is fontified.
461 (unless (get-text-property (1- (point)) 'mouse-face)
462 (dired-move-to-filename)))
463 nil (0 dired-ignored-face))))
465 ;; Explicitly put the default face on file names ending in a colon to
466 ;; avoid fontifying them as directory header.
467 (list (concat dired-re-maybe-mark dired-re-inode-size dired-re-perms ".*:$")
468 '(".+" (dired-move-to-filename) nil (0 'default)))
470 ;; Directory headers.
471 (list dired-subdir-regexp '(1 dired-header-face))
473 "Additional expressions to highlight in Dired mode.")
475 (defvar dnd-protocol-alist)
477 ;;; Macros must be defined before they are used, for the byte compiler.
479 (defmacro dired-mark-if (predicate msg)
480 "Mark all files for which PREDICATE evals to non-nil.
481 PREDICATE is evaluated on each line, with point at beginning of line.
482 MSG is a noun phrase for the type of files being marked.
483 It should end with a noun that can be pluralized by adding `s'.
484 Return value is the number of files marked, or nil if none were marked."
485 `(let ((inhibit-read-only t) count)
486 (save-excursion
487 (setq count 0)
488 (if ,msg (message "Marking %ss..." ,msg))
489 (goto-char (point-min))
490 (while (not (eobp))
491 (if ,predicate
492 (progn
493 (delete-char 1)
494 (insert dired-marker-char)
495 (setq count (1+ count))))
496 (forward-line 1))
497 (if ,msg (message "%s %s%s %s%s."
498 count
499 ,msg
500 (dired-plural-s count)
501 (if (eq dired-marker-char ?\040) "un" "")
502 (if (eq dired-marker-char dired-del-marker)
503 "flagged" "marked"))))
504 (and (> count 0) count)))
506 (defmacro dired-map-over-marks (body arg &optional show-progress
507 distinguish-one-marked)
508 "Eval BODY with point on each marked line. Return a list of BODY's results.
509 If no marked file could be found, execute BODY on the current line.
510 ARG, if non-nil, specifies the files to use instead of the marked files.
511 If ARG is an integer, use the next ARG (or previous -ARG, if
512 ARG<0) files. In that case, point is dragged along. This is
513 so that commands on the next ARG (instead of the marked) files
514 can be chained easily.
515 For any other non-nil value of ARG, use the current file.
516 If optional third arg SHOW-PROGRESS evaluates to non-nil,
517 redisplay the dired buffer after each file is processed.
518 No guarantee is made about the position on the marked line.
519 BODY must ensure this itself if it depends on this.
520 Search starts at the beginning of the buffer, thus the car of the list
521 corresponds to the line nearest to the buffer's bottom. This
522 is also true for (positive and negative) integer values of ARG.
523 BODY should not be too long as it is expanded four times.
525 If DISTINGUISH-ONE-MARKED is non-nil, then if we find just one marked file,
526 return (t FILENAME) instead of (FILENAME)."
528 ;;Warning: BODY must not add new lines before point - this may cause an
529 ;;endless loop.
530 ;;This warning should not apply any longer, sk 2-Sep-1991 14:10.
531 `(prog1
532 (let ((inhibit-read-only t) case-fold-search found results)
533 (if ,arg
534 (if (integerp ,arg)
535 (progn ;; no save-excursion, want to move point.
536 (dired-repeat-over-lines
537 ,arg
538 (function (lambda ()
539 (if ,show-progress (sit-for 0))
540 (setq results (cons ,body results)))))
541 (if (< ,arg 0)
542 (nreverse results)
543 results))
544 ;; non-nil, non-integer ARG means use current file:
545 (list ,body))
546 (let ((regexp (dired-marker-regexp)) next-position)
547 (save-excursion
548 (goto-char (point-min))
549 ;; remember position of next marked file before BODY
550 ;; can insert lines before the just found file,
551 ;; confusing us by finding the same marked file again
552 ;; and again and...
553 (setq next-position (and (re-search-forward regexp nil t)
554 (point-marker))
555 found (not (null next-position)))
556 (while next-position
557 (goto-char next-position)
558 (if ,show-progress (sit-for 0))
559 (setq results (cons ,body results))
560 ;; move after last match
561 (goto-char next-position)
562 (forward-line 1)
563 (set-marker next-position nil)
564 (setq next-position (and (re-search-forward regexp nil t)
565 (point-marker)))))
566 (if (and ,distinguish-one-marked (= (length results) 1))
567 (setq results (cons t results)))
568 (if found
569 results
570 (list ,body)))))
571 ;; save-excursion loses, again
572 (dired-move-to-filename)))
574 (defun dired-get-marked-files (&optional localp arg filter distinguish-one-marked)
575 "Return the marked files' names as list of strings.
576 The list is in the same order as the buffer, that is, the car is the
577 first marked file.
578 Values returned are normally absolute file names.
579 Optional arg LOCALP as in `dired-get-filename'.
580 Optional second argument ARG, if non-nil, specifies files near
581 point instead of marked files. It usually comes from the prefix
582 argument.
583 If ARG is an integer, use the next ARG files.
584 Any other non-nil value means to use the current file instead.
585 Optional third argument FILTER, if non-nil, is a function to select
586 some of the files--those for which (funcall FILTER FILENAME) is non-nil.
588 If DISTINGUISH-ONE-MARKED is non-nil, then if we find just one marked file,
589 return (t FILENAME) instead of (FILENAME).
590 Don't use that together with FILTER."
591 (let* ((all-of-them
592 (save-excursion
593 (dired-map-over-marks
594 (dired-get-filename localp)
595 arg nil distinguish-one-marked)))
596 result)
597 (if (not filter)
598 (if (and distinguish-one-marked (eq (car all-of-them) t))
599 all-of-them
600 (nreverse all-of-them))
601 (dolist (file all-of-them)
602 (if (funcall filter file)
603 (push file result)))
604 result)))
606 ;; The dired command
608 (defun dired-read-dir-and-switches (str)
609 ;; For use in interactive.
610 (reverse (list
611 (if current-prefix-arg
612 (read-string "Dired listing switches: "
613 dired-listing-switches))
614 ;; If a dialog is used, call `read-directory-name' so the
615 ;; dialog code knows we want directories. Some dialogs
616 ;; can only select directories or files when popped up,
617 ;; not both. If no dialog is used, call `read-file-name'
618 ;; because the user may want completion of file names for
619 ;; use in a wildcard pattern.
620 (if (next-read-file-uses-dialog-p)
621 (read-directory-name (format "Dired %s(directory): " str)
622 nil default-directory nil)
623 (read-file-name (format "Dired %s(directory): " str)
624 nil default-directory nil)))))
626 ;; We want to switch to a more sophisticated version of
627 ;; dired-read-dir-and-switches like the following, if there is a way
628 ;; to make it more intuitive. See bug#1285.
630 ;; (defun dired-read-dir-and-switches (str)
631 ;; ;; For use in interactive.
632 ;; (reverse
633 ;; (list
634 ;; (if current-prefix-arg
635 ;; (read-string "Dired listing switches: "
636 ;; dired-listing-switches))
637 ;; ;; If a dialog is about to be used, call read-directory-name so
638 ;; ;; the dialog code knows we want directories. Some dialogs can
639 ;; ;; only select directories or files when popped up, not both.
640 ;; (if (next-read-file-uses-dialog-p)
641 ;; (read-directory-name (format "Dired %s(directory): " str)
642 ;; nil default-directory nil)
643 ;; (let ((cie ()))
644 ;; (dolist (ext completion-ignored-extensions)
645 ;; (if (eq ?/ (aref ext (1- (length ext)))) (push ext cie)))
646 ;; (setq cie (concat (regexp-opt cie "\\(?:") "\\'"))
647 ;; (lexical-let* ((default (and buffer-file-name
648 ;; (abbreviate-file-name buffer-file-name)))
649 ;; (cie cie)
650 ;; (completion-table
651 ;; ;; We need a mix of read-file-name and
652 ;; ;; read-directory-name so that completion to directories
653 ;; ;; is preferred, but if the user wants to enter a global
654 ;; ;; pattern, he can still use completion on filenames to
655 ;; ;; help him write the pattern.
656 ;; ;; Essentially, we want to use
657 ;; ;; (completion-table-with-predicate
658 ;; ;; 'read-file-name-internal 'file-directory-p nil)
659 ;; ;; but that doesn't work because read-file-name-internal
660 ;; ;; does not obey its `predicate' argument.
661 ;; (completion-table-in-turn
662 ;; (lambda (str pred action)
663 ;; (let ((read-file-name-predicate
664 ;; (lambda (f)
665 ;; (and (not (member f '("./" "../")))
666 ;; ;; Hack! Faster than file-directory-p!
667 ;; (eq (aref f (1- (length f))) ?/)
668 ;; (not (string-match cie f))))))
669 ;; (complete-with-action
670 ;; action 'read-file-name-internal str nil)))
671 ;; 'read-file-name-internal)))
672 ;; (minibuffer-with-setup-hook
673 ;; (lambda ()
674 ;; (setq minibuffer-default default)
675 ;; (setq minibuffer-completion-table completion-table))
676 ;; (read-file-name (format "Dired %s(directory): " str)
677 ;; nil default-directory nil))))))))
679 (defun dired-file-name-at-point ()
680 "Try to get a file name at point in the current dired buffer.
681 This hook is inteneded to be put in `file-name-at-point-functions'."
682 (let ((filename (dired-get-filename nil t)))
683 (when filename
684 (if (file-directory-p filename)
685 (file-name-as-directory (abbreviate-file-name filename))
686 (abbreviate-file-name filename)))))
688 ;;;###autoload (define-key ctl-x-map "d" 'dired)
689 ;;;###autoload
690 (defun dired (dirname &optional switches)
691 "\"Edit\" directory DIRNAME--delete, rename, print, etc. some files in it.
692 Optional second argument SWITCHES specifies the `ls' options used.
693 \(Interactively, use a prefix argument to be able to specify SWITCHES.)
694 Dired displays a list of files in DIRNAME (which may also have
695 shell wildcards appended to select certain files). If DIRNAME is a cons,
696 its first element is taken as the directory name and the rest as an explicit
697 list of files to make directory entries for.
698 \\<dired-mode-map>\
699 You can move around in it with the usual commands.
700 You can flag files for deletion with \\[dired-flag-file-deletion] and then
701 delete them by typing \\[dired-do-flagged-delete].
702 Type \\[describe-mode] after entering Dired for more info.
704 If DIRNAME is already in a dired buffer, that buffer is used without refresh."
705 ;; Cannot use (interactive "D") because of wildcards.
706 (interactive (dired-read-dir-and-switches ""))
707 (switch-to-buffer (dired-noselect dirname switches)))
709 ;;;###autoload (define-key ctl-x-4-map "d" 'dired-other-window)
710 ;;;###autoload
711 (defun dired-other-window (dirname &optional switches)
712 "\"Edit\" directory DIRNAME. Like `dired' but selects in another window."
713 (interactive (dired-read-dir-and-switches "in other window "))
714 (switch-to-buffer-other-window (dired-noselect dirname switches)))
716 ;;;###autoload (define-key ctl-x-5-map "d" 'dired-other-frame)
717 ;;;###autoload
718 (defun dired-other-frame (dirname &optional switches)
719 "\"Edit\" directory DIRNAME. Like `dired' but makes a new frame."
720 (interactive (dired-read-dir-and-switches "in other frame "))
721 (switch-to-buffer-other-frame (dired-noselect dirname switches)))
723 ;;;###autoload
724 (defun dired-noselect (dir-or-list &optional switches)
725 "Like `dired' but returns the dired buffer as value, does not select it."
726 (or dir-or-list (setq dir-or-list default-directory))
727 ;; This loses the distinction between "/foo/*/" and "/foo/*" that
728 ;; some shells make:
729 (let (dirname initially-was-dirname)
730 (if (consp dir-or-list)
731 (setq dirname (car dir-or-list))
732 (setq dirname dir-or-list))
733 (setq initially-was-dirname
734 (string= (file-name-as-directory dirname) dirname))
735 (setq dirname (abbreviate-file-name
736 (expand-file-name (directory-file-name dirname))))
737 (if find-file-visit-truename
738 (setq dirname (file-truename dirname)))
739 ;; If the argument was syntactically a directory name not a file name,
740 ;; or if it happens to name a file that is a directory,
741 ;; convert it syntactically to a directory name.
742 ;; The reason for checking initially-was-dirname
743 ;; and not just file-directory-p
744 ;; is that file-directory-p is slow over ftp.
745 (if (or initially-was-dirname (file-directory-p dirname))
746 (setq dirname (file-name-as-directory dirname)))
747 (if (consp dir-or-list)
748 (setq dir-or-list (cons dirname (cdr dir-or-list)))
749 (setq dir-or-list dirname))
750 (dired-internal-noselect dir-or-list switches)))
752 ;; The following is an internal dired function. It returns non-nil if
753 ;; the directory visited by the current dired buffer has changed on
754 ;; disk. DIRNAME should be the directory name of that directory.
755 (defun dired-directory-changed-p (dirname)
756 (not (let ((attributes (file-attributes dirname))
757 (modtime (visited-file-modtime)))
758 (or (eq modtime 0)
759 (not (eq (car attributes) t))
760 (equal (nth 5 attributes) modtime)))))
762 (defun dired-buffer-stale-p (&optional noconfirm)
763 "Return non-nil if current dired buffer needs updating.
764 If NOCONFIRM is non-nil, then this function always returns nil
765 for a remote directory. This feature is used by Auto Revert Mode."
766 (let ((dirname
767 (if (consp dired-directory) (car dired-directory) dired-directory)))
768 (and (stringp dirname)
769 (not (when noconfirm (file-remote-p dirname)))
770 (file-readable-p dirname)
771 ;; Do not auto-revert when the dired buffer can be currently
772 ;; written by the user as in `wdired-mode'.
773 buffer-read-only
774 (dired-directory-changed-p dirname))))
776 (defcustom dired-auto-revert-buffer nil
777 "Automatically revert dired buffer on revisiting.
778 If t, revisiting an existing dired buffer automatically reverts it.
779 If its value is a function, call this function with the directory
780 name as single argument and revert the buffer if it returns non-nil.
781 Otherwise, a message offering to revert the changed dired buffer
782 is displayed.
783 Note that this is not the same as `auto-revert-mode' that
784 periodically reverts at specified time intervals."
785 :type '(choice
786 (const :tag "Don't revert" nil)
787 (const :tag "Always revert visited dired buffer" t)
788 (const :tag "Revert changed dired buffer" dired-directory-changed-p)
789 (function :tag "Predicate function"))
790 :group 'dired
791 :version "23.2")
793 (defun dired-internal-noselect (dir-or-list &optional switches mode)
794 ;; If there is an existing dired buffer for DIRNAME, just leave
795 ;; buffer as it is (don't even call dired-revert).
796 ;; This saves time especially for deep trees or with ange-ftp.
797 ;; The user can type `g' easily, and it is more consistent with find-file.
798 ;; But if SWITCHES are given they are probably different from the
799 ;; buffer's old value, so call dired-sort-other, which does
800 ;; revert the buffer.
801 ;; A pity we can't possibly do "Directory has changed - refresh? "
802 ;; like find-file does.
803 ;; Optional argument MODE is passed to dired-find-buffer-nocreate,
804 ;; see there.
805 (let* ((old-buf (current-buffer))
806 (dirname (if (consp dir-or-list) (car dir-or-list) dir-or-list))
807 ;; Look for an existing buffer.
808 (buffer (dired-find-buffer-nocreate dirname mode))
809 ;; Note that buffer already is in dired-mode, if found.
810 (new-buffer-p (null buffer)))
811 (or buffer
812 (setq buffer (create-file-buffer (directory-file-name dirname))))
813 (set-buffer buffer)
814 (if (not new-buffer-p) ; existing buffer ...
815 (cond (switches ; ... but new switches
816 ;; file list may have changed
817 (setq dired-directory dir-or-list)
818 ;; this calls dired-revert
819 (dired-sort-other switches))
820 ;; Always revert regardless of whether it has changed or not.
821 ((eq dired-auto-revert-buffer t)
822 (revert-buffer))
823 ;; Revert when predicate function returns non-nil.
824 ((functionp dired-auto-revert-buffer)
825 (when (funcall dired-auto-revert-buffer dirname)
826 (revert-buffer)
827 (message "Changed directory automatically updated")))
828 ;; If directory has changed on disk, offer to revert.
829 ((when (dired-directory-changed-p dirname)
830 (message "%s"
831 (substitute-command-keys
832 "Directory has changed on disk; type \\[revert-buffer] to update Dired")))))
833 ;; Else a new buffer
834 (setq default-directory
835 ;; We can do this unconditionally
836 ;; because dired-noselect ensures that the name
837 ;; is passed in directory name syntax
838 ;; if it was the name of a directory at all.
839 (file-name-directory dirname))
840 (or switches (setq switches dired-listing-switches))
841 (if mode (funcall mode)
842 (dired-mode dir-or-list switches))
843 ;; default-directory and dired-actual-switches are set now
844 ;; (buffer-local), so we can call dired-readin:
845 (let ((failed t))
846 (unwind-protect
847 (progn (dired-readin)
848 (setq failed nil))
849 ;; dired-readin can fail if parent directories are inaccessible.
850 ;; Don't leave an empty buffer around in that case.
851 (if failed (kill-buffer buffer))))
852 (goto-char (point-min))
853 (dired-initial-position dirname))
854 (set-buffer old-buf)
855 buffer))
857 (defvar dired-buffers nil
858 ;; Enlarged by dired-advertise
859 ;; Queried by function dired-buffers-for-dir. When this detects a
860 ;; killed buffer, it is removed from this list.
861 "Alist of expanded directories and their associated dired buffers.")
863 (defvar dired-find-subdir)
865 ;; FIXME add a doc-string, and document dired-x extensions.
866 (defun dired-find-buffer-nocreate (dirname &optional mode)
867 ;; This differs from dired-buffers-for-dir in that it does not consider
868 ;; subdirs of default-directory and searches for the first match only.
869 ;; Also, the major mode must be MODE.
870 (if (and (featurep 'dired-x)
871 dired-find-subdir
872 ;; Don't try to find a wildcard as a subdirectory.
873 (string-equal dirname (file-name-directory dirname)))
874 (let* ((cur-buf (current-buffer))
875 (buffers (nreverse
876 (dired-buffers-for-dir (expand-file-name dirname))))
877 (cur-buf-matches (and (memq cur-buf buffers)
878 ;; Wildcards must match, too:
879 (equal dired-directory dirname))))
880 ;; We don't want to switch to the same buffer---
881 (setq buffers (delq cur-buf buffers))
882 (or (car (sort buffers #'dired-buffer-more-recently-used-p))
883 ;; ---unless it's the only possibility:
884 (and cur-buf-matches cur-buf)))
885 ;; No dired-x, or dired-find-subdir nil.
886 (setq dirname (expand-file-name dirname))
887 (let (found (blist dired-buffers)) ; was (buffer-list)
888 (or mode (setq mode 'dired-mode))
889 (while blist
890 (if (null (buffer-name (cdr (car blist))))
891 (setq blist (cdr blist))
892 (with-current-buffer (cdr (car blist))
893 (if (and (eq major-mode mode)
894 dired-directory ;; nil during find-alternate-file
895 (equal dirname
896 (expand-file-name
897 (if (consp dired-directory)
898 (car dired-directory)
899 dired-directory))))
900 (setq found (cdr (car blist))
901 blist nil)
902 (setq blist (cdr blist))))))
903 found)))
906 ;; Read in a new dired buffer
908 (defun dired-readin ()
909 "Read in a new dired buffer.
910 Differs from `dired-insert-subdir' in that it accepts
911 wildcards, erases the buffer, and builds the subdir-alist anew
912 \(including making it buffer-local and clearing it first)."
914 ;; default-directory and dired-actual-switches must be buffer-local
915 ;; and initialized by now.
916 (let (dirname
917 ;; This makes readin much much faster.
918 ;; In particular, it prevents the font lock hook from running
919 ;; until the directory is all read in.
920 (inhibit-modification-hooks t))
921 (if (consp dired-directory)
922 (setq dirname (car dired-directory))
923 (setq dirname dired-directory))
924 (setq dirname (expand-file-name dirname))
925 (save-excursion
926 ;; This hook which may want to modify dired-actual-switches
927 ;; based on dired-directory, e.g. with ange-ftp to a SysV host
928 ;; where ls won't understand -Al switches.
929 (run-hooks 'dired-before-readin-hook)
930 (if (consp buffer-undo-list)
931 (setq buffer-undo-list nil))
932 (make-local-variable 'file-name-coding-system)
933 (setq file-name-coding-system
934 (or coding-system-for-read file-name-coding-system))
935 (let ((inhibit-read-only t)
936 ;; Don't make undo entries for readin.
937 (buffer-undo-list t))
938 (widen)
939 (erase-buffer)
940 (dired-readin-insert))
941 (goto-char (point-min))
942 ;; Must first make alist buffer local and set it to nil because
943 ;; dired-build-subdir-alist will call dired-clear-alist first
944 (set (make-local-variable 'dired-subdir-alist) nil)
945 (dired-build-subdir-alist)
946 (let ((attributes (file-attributes dirname)))
947 (if (eq (car attributes) t)
948 (set-visited-file-modtime (nth 5 attributes))))
949 (set-buffer-modified-p nil)
950 ;; No need to narrow since the whole buffer contains just
951 ;; dired-readin's output, nothing else. The hook can
952 ;; successfully use dired functions (e.g. dired-get-filename)
953 ;; as the subdir-alist has been built in dired-readin.
954 (run-hooks 'dired-after-readin-hook))))
956 ;; Subroutines of dired-readin
958 (defun dired-readin-insert ()
959 ;; Insert listing for the specified dir (and maybe file list)
960 ;; already in dired-directory, assuming a clean buffer.
961 (let (dir file-list)
962 (if (consp dired-directory)
963 (setq dir (car dired-directory)
964 file-list (cdr dired-directory))
965 (setq dir dired-directory
966 file-list nil))
967 (setq dir (expand-file-name dir))
968 (if (and (equal "" (file-name-nondirectory dir))
969 (not file-list))
970 ;; If we are reading a whole single directory...
971 (dired-insert-directory dir dired-actual-switches nil nil t)
972 (if (not (file-readable-p
973 (directory-file-name (file-name-directory dir))))
974 (error "Directory %s inaccessible or nonexistent" dir)
975 ;; Else treat it as a wildcard spec
976 ;; unless we have an explicit list of files.
977 (dired-insert-directory dir dired-actual-switches
978 file-list (not file-list) t)))))
980 (defun dired-align-file (beg end)
981 "Align the fields of a file to the ones of surrounding lines.
982 BEG..END is the line where the file info is located."
983 ;; Some versions of ls try to adjust the size of each field so as to just
984 ;; hold the largest element ("largest" in the current invocation, of
985 ;; course). So when a single line is output, the size of each field is
986 ;; just big enough for that one output. Thus when dired refreshes one
987 ;; line, the alignment if this line w.r.t the rest is messed up because
988 ;; the fields of that one line will generally be smaller.
990 ;; To work around this problem, we here add spaces to try and
991 ;; re-align the fields as needed. Since this is purely aesthetic,
992 ;; it is of utmost importance that it doesn't mess up anything like
993 ;; `dired-move-to-filename'. To this end, we limit ourselves to
994 ;; adding spaces only, and to only add them at places where there
995 ;; was already at least one space. This way, as long as
996 ;; `directory-listing-before-filename-regexp' always matches spaces
997 ;; with "*" or "+", we know we haven't made anything worse. There
998 ;; is one spot where the exact number of spaces is important, which
999 ;; is just before the actual filename, so we refrain from adding
1000 ;; spaces there (and within the filename as well, of course).
1001 (save-excursion
1002 (let (file file-col other other-col)
1003 ;; Check that there is indeed a file, and that there is anoter adjacent
1004 ;; file with which to align, and that additional spaces are needed to
1005 ;; align the filenames.
1006 (when (and (setq file (progn (goto-char beg)
1007 (dired-move-to-filename nil end)))
1008 (setq file-col (current-column))
1009 (setq other
1010 (or (and (goto-char beg)
1011 (zerop (forward-line -1))
1012 (dired-move-to-filename))
1013 (and (goto-char beg)
1014 (zerop (forward-line 1))
1015 (dired-move-to-filename))))
1016 (setq other-col (current-column))
1017 (/= file other)
1018 ;; Make sure there is some work left to do.
1019 (> other-col file-col))
1020 ;; If we've only looked at the line above, check to see if the line
1021 ;; below exists as well and if so, align with the shorter one.
1022 (when (and (< other file)
1023 (goto-char beg)
1024 (zerop (forward-line 1))
1025 (dired-move-to-filename))
1026 (let ((alt-col (current-column)))
1027 (when (< alt-col other-col)
1028 (setq other-col alt-col)
1029 (setq other (point)))))
1030 ;; Keep positions uptodate when we insert stuff.
1031 (if (> other file) (setq other (copy-marker other)))
1032 (setq file (copy-marker file))
1033 ;; Main loop.
1034 (goto-char beg)
1035 (skip-chars-forward " ") ;Skip to the first field.
1036 (while (and (> other-col file-col)
1037 ;; Don't touch anything just before (and after) the
1038 ;; beginning of the filename.
1039 (> file (point)))
1040 ;; We're now just in front of a field, with a space behind us.
1041 (let* ((curcol (current-column))
1042 ;; Nums are right-aligned.
1043 (num-align (looking-at "[0-9]"))
1044 ;; Let's look at the other line, in the same column: we
1045 ;; should be either near the end of the previous field, or
1046 ;; in the space between that field and the next.
1047 ;; [ Of course, it's also possible that we're already within
1048 ;; the next field or even past it, but that's unlikely since
1049 ;; other-col > file-col. ]
1050 ;; Let's find the distance to the alignment-point (either
1051 ;; the beginning or the end of the next field, depending on
1052 ;; whether this field is left or right aligned).
1053 (align-pt-offset
1054 (save-excursion
1055 (goto-char other)
1056 (move-to-column curcol)
1057 (when (looking-at
1058 (concat
1059 (if (eq (char-before) ?\s) " *" "[^ ]* *")
1060 (if num-align "[0-9][^ ]*")))
1061 (- (match-end 0) (match-beginning 0)))))
1062 ;; Now, the number of spaces to insert is align-pt-offset
1063 ;; minus the distance to the equivalent point on the
1064 ;; current line.
1065 (spaces
1066 (if (not num-align)
1067 align-pt-offset
1068 (and align-pt-offset
1069 (save-excursion
1070 (skip-chars-forward "^ ")
1071 (- align-pt-offset (- (current-column) curcol)))))))
1072 (when (and spaces (> spaces 0))
1073 (setq file-col (+ spaces file-col))
1074 (if (> file-col other-col)
1075 (setq spaces (- spaces (- file-col other-col))))
1076 (insert-char ?\s spaces)
1077 ;; Let's just make really sure we did not mess up.
1078 (unless (save-excursion
1079 (eq (dired-move-to-filename) (marker-position file)))
1080 ;; Damn! We messed up: let's revert the change.
1081 (delete-char (- spaces)))))
1082 ;; Now skip to next field.
1083 (skip-chars-forward "^ ") (skip-chars-forward " "))
1084 (set-marker file nil)))))
1087 (defvar ls-lisp-use-insert-directory-program)
1089 (defun dired-insert-directory (dir switches &optional file-list wildcard hdr)
1090 "Insert a directory listing of DIR, Dired style.
1091 Use SWITCHES to make the listings.
1092 If FILE-LIST is non-nil, list only those files.
1093 Otherwise, if WILDCARD is non-nil, expand wildcards;
1094 in that case, DIR should be a file name that uses wildcards.
1095 In other cases, DIR should be a directory name or a directory filename.
1096 If HDR is non-nil, insert a header line with the directory name."
1097 (let ((opoint (point))
1098 (process-environment (copy-sequence process-environment))
1099 end)
1100 (if (and
1101 ;; Don't try to invoke `ls' if we are on DOS/Windows where
1102 ;; ls-lisp emulation is used, except if they want to use `ls'
1103 ;; as indicated by `ls-lisp-use-insert-directory-program'.
1104 (not (and (featurep 'ls-lisp)
1105 (null ls-lisp-use-insert-directory-program)))
1106 (or (if (eq dired-use-ls-dired 'unspecified)
1107 ;; Check whether "ls --dired" gives exit code 0, and
1108 ;; save the answer in `dired-use-ls-dired'.
1109 (setq dired-use-ls-dired
1110 (eq (call-process insert-directory-program nil nil nil "--dired")
1112 dired-use-ls-dired)
1113 (file-remote-p dir)))
1114 (setq switches (concat "--dired " switches)))
1115 ;; We used to specify the C locale here, to force English month names;
1116 ;; but this should not be necessary any more,
1117 ;; with the new value of `directory-listing-before-filename-regexp'.
1118 (if file-list
1119 (dolist (f file-list)
1120 (let ((beg (point)))
1121 (insert-directory f switches nil nil)
1122 ;; Re-align fields, if necessary.
1123 (dired-align-file beg (point))))
1124 (insert-directory dir switches wildcard (not wildcard)))
1125 ;; Quote certain characters, unless ls quoted them for us.
1126 (if (not (string-match "b" dired-actual-switches))
1127 (save-excursion
1128 (setq end (point-marker))
1129 (goto-char opoint)
1130 (while (search-forward "\\" end t)
1131 (replace-match (apply #'propertize
1132 "\\\\"
1133 (text-properties-at (match-beginning 0)))
1134 nil t))
1135 (goto-char opoint)
1136 (while (search-forward "\^m" end t)
1137 (replace-match (apply #'propertize
1138 "\\015"
1139 (text-properties-at (match-beginning 0)))
1140 nil t))
1141 (set-marker end nil)))
1142 (dired-insert-set-properties opoint (point))
1143 ;; If we used --dired and it worked, the lines are already indented.
1144 ;; Otherwise, indent them.
1145 (unless (save-excursion
1146 (goto-char opoint)
1147 (looking-at " "))
1148 (let ((indent-tabs-mode nil))
1149 (indent-rigidly opoint (point) 2)))
1150 ;; Insert text at the beginning to standardize things.
1151 (save-excursion
1152 (goto-char opoint)
1153 (if (and (or hdr wildcard)
1154 (not (and (looking-at "^ \\(.*\\):$")
1155 (file-name-absolute-p (match-string 1)))))
1156 ;; Note that dired-build-subdir-alist will replace the name
1157 ;; by its expansion, so it does not matter whether what we insert
1158 ;; here is fully expanded, but it should be absolute.
1159 (insert " " (directory-file-name (file-name-directory dir)) ":\n"))
1160 (when wildcard
1161 ;; Insert "wildcard" line where "total" line would be for a full dir.
1162 (insert " wildcard " (file-name-nondirectory dir) "\n")))))
1164 (defun dired-insert-set-properties (beg end)
1165 "Make the file names highlight when the mouse is on them."
1166 (save-excursion
1167 (goto-char beg)
1168 (while (< (point) end)
1169 (condition-case nil
1170 (if (dired-move-to-filename)
1171 (add-text-properties
1172 (point)
1173 (save-excursion
1174 (dired-move-to-end-of-filename)
1175 (point))
1176 '(mouse-face highlight
1177 dired-filename t
1178 help-echo "mouse-2: visit this file in other window")))
1179 (error nil))
1180 (forward-line 1))))
1182 ;; Reverting a dired buffer
1184 (defun dired-revert (&optional arg noconfirm)
1185 "Reread the dired buffer.
1186 Must also be called after `dired-actual-switches' have changed.
1187 Should not fail even on completely garbaged buffers.
1188 Preserves old cursor, marks/flags, hidden-p.
1190 Dired sets `revert-buffer-function' to this function. The args
1191 ARG and NOCONFIRM, passed from `revert-buffer', are ignored."
1192 (widen) ; just in case user narrowed
1193 (let ((modflag (buffer-modified-p))
1194 (positions (dired-save-positions))
1195 (mark-alist nil) ; save marked files
1196 (hidden-subdirs (dired-remember-hidden))
1197 (old-subdir-alist (cdr (reverse dired-subdir-alist))) ; except pwd
1198 (case-fold-search nil) ; we check for upper case ls flags
1199 (inhibit-read-only t))
1200 (goto-char (point-min))
1201 (setq mark-alist;; only after dired-remember-hidden since this unhides:
1202 (dired-remember-marks (point-min) (point-max)))
1203 ;; treat top level dir extra (it may contain wildcards)
1204 (if (not (consp dired-directory))
1205 (dired-uncache dired-directory)
1206 (dired-uncache (car dired-directory))
1207 (dolist (dir (cdr dired-directory))
1208 (if (file-name-absolute-p dir)
1209 (dired-uncache dir))))
1210 ;; Run dired-after-readin-hook just once, below.
1211 (let ((dired-after-readin-hook nil))
1212 (dired-readin)
1213 (dired-insert-old-subdirs old-subdir-alist))
1214 (dired-mark-remembered mark-alist) ; mark files that were marked
1215 ;; ... run the hook for the whole buffer, and only after markers
1216 ;; have been reinserted (else omitting in dired-x would omit marked files)
1217 (run-hooks 'dired-after-readin-hook) ; no need to narrow
1218 (dired-restore-positions positions)
1219 (save-excursion ; hide subdirs that were hidden
1220 (dolist (dir hidden-subdirs)
1221 (if (dired-goto-subdir dir)
1222 (dired-hide-subdir 1))))
1223 (unless modflag (restore-buffer-modified-p nil)))
1224 ;; outside of the let scope
1225 ;;; Might as well not override the user if the user changed this.
1226 ;;; (setq buffer-read-only t)
1229 ;; Subroutines of dired-revert
1230 ;; Some of these are also used when inserting subdirs.
1232 (defun dired-save-positions ()
1233 "Return current positions in the buffer and all windows with this directory.
1234 The positions have the form (BUFFER-POSITION WINDOW-POSITIONS).
1236 BUFFER-POSITION is the point position in the current dired buffer.
1237 It has the form (BUFFER DIRED-FILENAME BUFFER-POINT).
1239 WINDOW-POSITIONS are current positions in all windows displaying
1240 this dired buffer. The window positions have the form (WINDOW
1241 DIRED-FILENAME WINDOW-POINT)."
1242 (list
1243 (list (current-buffer) (dired-get-filename nil t) (point))
1244 (mapcar (lambda (w)
1245 (list w
1246 (with-selected-window w
1247 (dired-get-filename nil t))
1248 (window-point w)))
1249 (get-buffer-window-list nil 0 t))))
1251 (defun dired-restore-positions (positions)
1252 "Restore POSITIONS saved with `dired-save-positions'."
1253 (let* ((buf-file-pos (nth 0 positions))
1254 (buffer (nth 0 buf-file-pos)))
1255 (unless (and (nth 1 buf-file-pos)
1256 (dired-goto-file (nth 1 buf-file-pos)))
1257 (goto-char (nth 2 buf-file-pos))
1258 (dired-move-to-filename))
1259 (dolist (win-file-pos (nth 1 positions))
1260 ;; Ensure that window still displays the original buffer.
1261 (when (eq (window-buffer (nth 0 win-file-pos)) buffer)
1262 (with-selected-window (nth 0 win-file-pos)
1263 (unless (and (nth 1 win-file-pos)
1264 (dired-goto-file (nth 1 win-file-pos)))
1265 (goto-char (nth 2 win-file-pos))
1266 (dired-move-to-filename)))))))
1268 (defun dired-remember-marks (beg end)
1269 "Return alist of files and their marks, from BEG to END."
1270 (if selective-display ; must unhide to make this work.
1271 (let ((inhibit-read-only t))
1272 (subst-char-in-region beg end ?\r ?\n)))
1273 (let (fil chr alist)
1274 (save-excursion
1275 (goto-char beg)
1276 (while (re-search-forward dired-re-mark end t)
1277 (if (setq fil (dired-get-filename nil t))
1278 (setq chr (preceding-char)
1279 alist (cons (cons fil chr) alist)))))
1280 alist))
1282 (defun dired-mark-remembered (alist)
1283 "Mark all files remembered in ALIST.
1284 Each element of ALIST looks like (FILE . MARKERCHAR)."
1285 (let (elt fil chr)
1286 (while alist
1287 (setq elt (car alist)
1288 alist (cdr alist)
1289 fil (car elt)
1290 chr (cdr elt))
1291 (if (dired-goto-file fil)
1292 (save-excursion
1293 (beginning-of-line)
1294 (delete-char 1)
1295 (insert chr))))))
1297 (defun dired-remember-hidden ()
1298 "Return a list of names of subdirs currently hidden."
1299 (let ((l dired-subdir-alist) dir pos result)
1300 (while l
1301 (setq dir (car (car l))
1302 pos (cdr (car l))
1303 l (cdr l))
1304 (goto-char pos)
1305 (skip-chars-forward "^\r\n")
1306 (if (eq (following-char) ?\r)
1307 (setq result (cons dir result))))
1308 result))
1310 (defun dired-insert-old-subdirs (old-subdir-alist)
1311 "Try to insert all subdirs that were displayed before.
1312 Do so according to the former subdir alist OLD-SUBDIR-ALIST."
1313 (or (string-match "R" dired-actual-switches)
1314 (let (elt dir)
1315 (while old-subdir-alist
1316 (setq elt (car old-subdir-alist)
1317 old-subdir-alist (cdr old-subdir-alist)
1318 dir (car elt))
1319 (condition-case ()
1320 (progn
1321 (dired-uncache dir)
1322 (dired-insert-subdir dir))
1323 (error nil))))))
1325 (defun dired-uncache (dir)
1326 "Remove directory DIR from any directory cache."
1327 (let ((handler (find-file-name-handler dir 'dired-uncache)))
1328 (if handler
1329 (funcall handler 'dired-uncache dir))))
1331 ;; dired mode key bindings and initialization
1333 (defvar dired-mode-map
1334 ;; This looks ugly when substitute-command-keys uses C-d instead d:
1335 ;; (define-key dired-mode-map "\C-d" 'dired-flag-file-deletion)
1336 (let ((map (make-keymap)))
1337 (set-keymap-parent map special-mode-map)
1338 (define-key map [mouse-2] 'dired-mouse-find-file-other-window)
1339 (define-key map [follow-link] 'mouse-face)
1340 ;; Commands to mark or flag certain categories of files
1341 (define-key map "#" 'dired-flag-auto-save-files)
1342 (define-key map "." 'dired-clean-directory)
1343 (define-key map "~" 'dired-flag-backup-files)
1344 ;; Upper case keys (except !) for operating on the marked files
1345 (define-key map "A" 'dired-do-search)
1346 (define-key map "C" 'dired-do-copy)
1347 (define-key map "B" 'dired-do-byte-compile)
1348 (define-key map "D" 'dired-do-delete)
1349 (define-key map "G" 'dired-do-chgrp)
1350 (define-key map "H" 'dired-do-hardlink)
1351 (define-key map "L" 'dired-do-load)
1352 (define-key map "M" 'dired-do-chmod)
1353 (define-key map "O" 'dired-do-chown)
1354 (define-key map "P" 'dired-do-print)
1355 (define-key map "Q" 'dired-do-query-replace-regexp)
1356 (define-key map "R" 'dired-do-rename)
1357 (define-key map "S" 'dired-do-symlink)
1358 (define-key map "T" 'dired-do-touch)
1359 (define-key map "X" 'dired-do-shell-command)
1360 (define-key map "Z" 'dired-do-compress)
1361 (define-key map "!" 'dired-do-shell-command)
1362 (define-key map "&" 'dired-do-async-shell-command)
1363 ;; Comparison commands
1364 (define-key map "=" 'dired-diff)
1365 (define-key map "\M-=" 'dired-backup-diff)
1366 ;; Tree Dired commands
1367 (define-key map "\M-\C-?" 'dired-unmark-all-files)
1368 (define-key map "\M-\C-d" 'dired-tree-down)
1369 (define-key map "\M-\C-u" 'dired-tree-up)
1370 (define-key map "\M-\C-n" 'dired-next-subdir)
1371 (define-key map "\M-\C-p" 'dired-prev-subdir)
1372 ;; move to marked files
1373 (define-key map "\M-{" 'dired-prev-marked-file)
1374 (define-key map "\M-}" 'dired-next-marked-file)
1375 ;; Make all regexp commands share a `%' prefix:
1376 ;; We used to get to the submap via a symbol dired-regexp-prefix,
1377 ;; but that seems to serve little purpose, and copy-keymap
1378 ;; does a better job without it.
1379 (define-key map "%" nil)
1380 (define-key map "%u" 'dired-upcase)
1381 (define-key map "%l" 'dired-downcase)
1382 (define-key map "%d" 'dired-flag-files-regexp)
1383 (define-key map "%g" 'dired-mark-files-containing-regexp)
1384 (define-key map "%m" 'dired-mark-files-regexp)
1385 (define-key map "%r" 'dired-do-rename-regexp)
1386 (define-key map "%C" 'dired-do-copy-regexp)
1387 (define-key map "%H" 'dired-do-hardlink-regexp)
1388 (define-key map "%R" 'dired-do-rename-regexp)
1389 (define-key map "%S" 'dired-do-symlink-regexp)
1390 (define-key map "%&" 'dired-flag-garbage-files)
1391 ;; Commands for marking and unmarking.
1392 (define-key map "*" nil)
1393 (define-key map "**" 'dired-mark-executables)
1394 (define-key map "*/" 'dired-mark-directories)
1395 (define-key map "*@" 'dired-mark-symlinks)
1396 (define-key map "*%" 'dired-mark-files-regexp)
1397 (define-key map "*c" 'dired-change-marks)
1398 (define-key map "*s" 'dired-mark-subdir-files)
1399 (define-key map "*m" 'dired-mark)
1400 (define-key map "*u" 'dired-unmark)
1401 (define-key map "*?" 'dired-unmark-all-files)
1402 (define-key map "*!" 'dired-unmark-all-marks)
1403 (define-key map "U" 'dired-unmark-all-marks)
1404 (define-key map "*\177" 'dired-unmark-backward)
1405 (define-key map "*\C-n" 'dired-next-marked-file)
1406 (define-key map "*\C-p" 'dired-prev-marked-file)
1407 (define-key map "*t" 'dired-toggle-marks)
1408 ;; Lower keys for commands not operating on all the marked files
1409 (define-key map "a" 'dired-find-alternate-file)
1410 (define-key map "d" 'dired-flag-file-deletion)
1411 (define-key map "e" 'dired-find-file)
1412 (define-key map "f" 'dired-find-file)
1413 (define-key map "\C-m" 'dired-find-file)
1414 (put 'dired-find-file :advertised-binding "\C-m")
1415 (define-key map "g" 'revert-buffer)
1416 (define-key map "i" 'dired-maybe-insert-subdir)
1417 (define-key map "j" 'dired-goto-file)
1418 (define-key map "k" 'dired-do-kill-lines)
1419 (define-key map "l" 'dired-do-redisplay)
1420 (define-key map "m" 'dired-mark)
1421 (define-key map "n" 'dired-next-line)
1422 (define-key map "o" 'dired-find-file-other-window)
1423 (define-key map "\C-o" 'dired-display-file)
1424 (define-key map "p" 'dired-previous-line)
1425 (define-key map "s" 'dired-sort-toggle-or-edit)
1426 (define-key map "t" 'dired-toggle-marks)
1427 (define-key map "u" 'dired-unmark)
1428 (define-key map "v" 'dired-view-file)
1429 (define-key map "w" 'dired-copy-filename-as-kill)
1430 (define-key map "x" 'dired-do-flagged-delete)
1431 (define-key map "y" 'dired-show-file-type)
1432 (define-key map "+" 'dired-create-directory)
1433 ;; moving
1434 (define-key map "<" 'dired-prev-dirline)
1435 (define-key map ">" 'dired-next-dirline)
1436 (define-key map "^" 'dired-up-directory)
1437 (define-key map " " 'dired-next-line)
1438 (define-key map [remap next-line] 'dired-next-line)
1439 (define-key map [remap previous-line] 'dired-previous-line)
1440 ;; hiding
1441 (define-key map "$" 'dired-hide-subdir)
1442 (define-key map "\M-$" 'dired-hide-all)
1443 ;; isearch
1444 (define-key map (kbd "M-s a C-s") 'dired-do-isearch)
1445 (define-key map (kbd "M-s a M-C-s") 'dired-do-isearch-regexp)
1446 (define-key map (kbd "M-s f C-s") 'dired-isearch-filenames)
1447 (define-key map (kbd "M-s f M-C-s") 'dired-isearch-filenames-regexp)
1448 ;; misc
1449 (define-key map [remap toggle-read-only] 'dired-toggle-read-only)
1450 (define-key map "?" 'dired-summary)
1451 (define-key map "\177" 'dired-unmark-backward)
1452 (define-key map [remap undo] 'dired-undo)
1453 (define-key map [remap advertised-undo] 'dired-undo)
1454 ;; thumbnail manipulation (image-dired)
1455 (define-key map "\C-td" 'image-dired-display-thumbs)
1456 (define-key map "\C-tt" 'image-dired-tag-files)
1457 (define-key map "\C-tr" 'image-dired-delete-tag)
1458 (define-key map "\C-tj" 'image-dired-jump-thumbnail-buffer)
1459 (define-key map "\C-ti" 'image-dired-dired-display-image)
1460 (define-key map "\C-tx" 'image-dired-dired-display-external)
1461 (define-key map "\C-ta" 'image-dired-display-thumbs-append)
1462 (define-key map "\C-t." 'image-dired-display-thumb)
1463 (define-key map "\C-tc" 'image-dired-dired-comment-files)
1464 (define-key map "\C-tf" 'image-dired-mark-tagged-files)
1465 (define-key map "\C-t\C-t" 'image-dired-dired-toggle-marked-thumbs)
1466 (define-key map "\C-te" 'image-dired-dired-edit-comment-and-tags)
1467 ;; encryption and decryption (epa-dired)
1468 (define-key map ":d" 'epa-dired-do-decrypt)
1469 (define-key map ":v" 'epa-dired-do-verify)
1470 (define-key map ":s" 'epa-dired-do-sign)
1471 (define-key map ":e" 'epa-dired-do-encrypt)
1473 ;; Make menu bar items.
1475 ;; No need to fo this, now that top-level items are fewer.
1476 ;;;;
1477 ;; Get rid of the Edit menu bar item to save space.
1478 ;(define-key map [menu-bar edit] 'undefined)
1480 (define-key map [menu-bar subdir]
1481 (cons "Subdir" (make-sparse-keymap "Subdir")))
1483 (define-key map [menu-bar subdir hide-all]
1484 '(menu-item "Hide All" dired-hide-all
1485 :help "Hide all subdirectories, leave only header lines"))
1486 (define-key map [menu-bar subdir hide-subdir]
1487 '(menu-item "Hide/UnHide Subdir" dired-hide-subdir
1488 :help "Hide or unhide current directory listing"))
1489 (define-key map [menu-bar subdir tree-down]
1490 '(menu-item "Tree Down" dired-tree-down
1491 :help "Go to first subdirectory header down the tree"))
1492 (define-key map [menu-bar subdir tree-up]
1493 '(menu-item "Tree Up" dired-tree-up
1494 :help "Go to first subdirectory header up the tree"))
1495 (define-key map [menu-bar subdir up]
1496 '(menu-item "Up Directory" dired-up-directory
1497 :help "Edit the parent directory"))
1498 (define-key map [menu-bar subdir prev-subdir]
1499 '(menu-item "Prev Subdir" dired-prev-subdir
1500 :help "Go to previous subdirectory header line"))
1501 (define-key map [menu-bar subdir next-subdir]
1502 '(menu-item "Next Subdir" dired-next-subdir
1503 :help "Go to next subdirectory header line"))
1504 (define-key map [menu-bar subdir prev-dirline]
1505 '(menu-item "Prev Dirline" dired-prev-dirline
1506 :help "Move to next directory-file line"))
1507 (define-key map [menu-bar subdir next-dirline]
1508 '(menu-item "Next Dirline" dired-next-dirline
1509 :help "Move to previous directory-file line"))
1510 (define-key map [menu-bar subdir insert]
1511 '(menu-item "Insert This Subdir" dired-maybe-insert-subdir
1512 :help "Insert contents of subdirectory"
1513 :enable (let ((f (dired-get-filename nil t)))
1514 (and f (file-directory-p f)))))
1515 (define-key map [menu-bar immediate]
1516 (cons "Immediate" (make-sparse-keymap "Immediate")))
1518 (define-key map
1519 [menu-bar immediate image-dired-dired-display-external]
1520 '(menu-item "Display Image Externally" image-dired-dired-display-external
1521 :help "Display image in external viewer"))
1522 (define-key map
1523 [menu-bar immediate image-dired-dired-display-image]
1524 '(menu-item "Display Image" image-dired-dired-display-image
1525 :help "Display sized image in a separate window"))
1527 (define-key map [menu-bar immediate revert-buffer]
1528 '(menu-item "Refresh" revert-buffer
1529 :help "Update contents of shown directories"))
1531 (define-key map [menu-bar immediate dashes]
1532 '("--"))
1534 (define-key map [menu-bar immediate isearch-filenames-regexp]
1535 '(menu-item "Isearch Regexp in File Names..." dired-isearch-filenames-regexp
1536 :help "Incrementally search for regexp in file names only"))
1537 (define-key map [menu-bar immediate isearch-filenames]
1538 '(menu-item "Isearch in File Names..." dired-isearch-filenames
1539 :help "Incrementally search for string in file names only."))
1540 (define-key map [menu-bar immediate compare-directories]
1541 '(menu-item "Compare Directories..." dired-compare-directories
1542 :help "Mark files with different attributes in two dired buffers"))
1543 (define-key map [menu-bar immediate backup-diff]
1544 '(menu-item "Compare with Backup" dired-backup-diff
1545 :help "Diff file at cursor with its latest backup"))
1546 (define-key map [menu-bar immediate diff]
1547 '(menu-item "Diff..." dired-diff
1548 :help "Compare file at cursor with another file"))
1549 (define-key map [menu-bar immediate view]
1550 '(menu-item "View This File" dired-view-file
1551 :help "Examine file at cursor in read-only mode"))
1552 (define-key map [menu-bar immediate display]
1553 '(menu-item "Display in Other Window" dired-display-file
1554 :help "Display file at cursor in other window"))
1555 (define-key map [menu-bar immediate find-file-other-window]
1556 '(menu-item "Find in Other Window" dired-find-file-other-window
1557 :help "Edit file at cursor in other window"))
1558 (define-key map [menu-bar immediate find-file]
1559 '(menu-item "Find This File" dired-find-file
1560 :help "Edit file at cursor"))
1561 (define-key map [menu-bar immediate create-directory]
1562 '(menu-item "Create Directory..." dired-create-directory
1563 :help "Create a directory"))
1564 (define-key map [menu-bar immediate wdired-mode]
1565 '(menu-item "Edit File Names" wdired-change-to-wdired-mode
1566 :help "Put a dired buffer in a mode in which filenames are editable"
1567 :keys "C-x C-q"
1568 :filter (lambda (x) (if (eq major-mode 'dired-mode) x))))
1570 (define-key map [menu-bar regexp]
1571 (cons "Regexp" (make-sparse-keymap "Regexp")))
1573 (define-key map
1574 [menu-bar regexp image-dired-mark-tagged-files]
1575 '(menu-item "Mark From Image Tag..." image-dired-mark-tagged-files
1576 :help "Mark files whose image tags matches regexp"))
1578 (define-key map [menu-bar regexp dashes-1]
1579 '("--"))
1581 (define-key map [menu-bar regexp downcase]
1582 '(menu-item "Downcase" dired-downcase
1583 ;; When running on plain MS-DOS, there's only one
1584 ;; letter-case for file names.
1585 :enable (or (not (fboundp 'msdos-long-file-names))
1586 (msdos-long-file-names))
1587 :help "Rename marked files to lower-case name"))
1588 (define-key map [menu-bar regexp upcase]
1589 '(menu-item "Upcase" dired-upcase
1590 :enable (or (not (fboundp 'msdos-long-file-names))
1591 (msdos-long-file-names))
1592 :help "Rename marked files to upper-case name"))
1593 (define-key map [menu-bar regexp hardlink]
1594 '(menu-item "Hardlink..." dired-do-hardlink-regexp
1595 :help "Make hard links for files matching regexp"))
1596 (define-key map [menu-bar regexp symlink]
1597 '(menu-item "Symlink..." dired-do-symlink-regexp
1598 :visible (fboundp 'make-symbolic-link)
1599 :help "Make symbolic links for files matching regexp"))
1600 (define-key map [menu-bar regexp rename]
1601 '(menu-item "Rename..." dired-do-rename-regexp
1602 :help "Rename marked files matching regexp"))
1603 (define-key map [menu-bar regexp copy]
1604 '(menu-item "Copy..." dired-do-copy-regexp
1605 :help "Copy marked files matching regexp"))
1606 (define-key map [menu-bar regexp flag]
1607 '(menu-item "Flag..." dired-flag-files-regexp
1608 :help "Flag files matching regexp for deletion"))
1609 (define-key map [menu-bar regexp mark]
1610 '(menu-item "Mark..." dired-mark-files-regexp
1611 :help "Mark files matching regexp for future operations"))
1612 (define-key map [menu-bar regexp mark-cont]
1613 '(menu-item "Mark Containing..." dired-mark-files-containing-regexp
1614 :help "Mark files whose contents matches regexp"))
1616 (define-key map [menu-bar mark]
1617 (cons "Mark" (make-sparse-keymap "Mark")))
1619 (define-key map [menu-bar mark prev]
1620 '(menu-item "Previous Marked" dired-prev-marked-file
1621 :help "Move to previous marked file"))
1622 (define-key map [menu-bar mark next]
1623 '(menu-item "Next Marked" dired-next-marked-file
1624 :help "Move to next marked file"))
1625 (define-key map [menu-bar mark marks]
1626 '(menu-item "Change Marks..." dired-change-marks
1627 :help "Replace marker with another character"))
1628 (define-key map [menu-bar mark unmark-all]
1629 '(menu-item "Unmark All" dired-unmark-all-marks))
1630 (define-key map [menu-bar mark symlinks]
1631 '(menu-item "Mark Symlinks" dired-mark-symlinks
1632 :visible (fboundp 'make-symbolic-link)
1633 :help "Mark all symbolic links"))
1634 (define-key map [menu-bar mark directories]
1635 '(menu-item "Mark Directories" dired-mark-directories
1636 :help "Mark all directories except `.' and `..'"))
1637 (define-key map [menu-bar mark directory]
1638 '(menu-item "Mark Old Backups" dired-clean-directory
1639 :help "Flag old numbered backups for deletion"))
1640 (define-key map [menu-bar mark executables]
1641 '(menu-item "Mark Executables" dired-mark-executables
1642 :help "Mark all executable files"))
1643 (define-key map [menu-bar mark garbage-files]
1644 '(menu-item "Flag Garbage Files" dired-flag-garbage-files
1645 :help "Flag unneeded files for deletion"))
1646 (define-key map [menu-bar mark backup-files]
1647 '(menu-item "Flag Backup Files" dired-flag-backup-files
1648 :help "Flag all backup files for deletion"))
1649 (define-key map [menu-bar mark auto-save-files]
1650 '(menu-item "Flag Auto-save Files" dired-flag-auto-save-files
1651 :help "Flag auto-save files for deletion"))
1652 (define-key map [menu-bar mark deletion]
1653 '(menu-item "Flag" dired-flag-file-deletion
1654 :help "Flag current line's file for deletion"))
1655 (define-key map [menu-bar mark unmark]
1656 '(menu-item "Unmark" dired-unmark
1657 :help "Unmark or unflag current line's file"))
1658 (define-key map [menu-bar mark mark]
1659 '(menu-item "Mark" dired-mark
1660 :help "Mark current line's file for future operations"))
1661 (define-key map [menu-bar mark toggle-marks]
1662 '(menu-item "Toggle Marks" dired-toggle-marks
1663 :help "Mark unmarked files, unmark marked ones"))
1665 (define-key map [menu-bar operate]
1666 (cons "Operate" (make-sparse-keymap "Operate")))
1668 (define-key map
1669 [menu-bar operate image-dired-delete-tag]
1670 '(menu-item "Delete Image Tag..." image-dired-delete-tag
1671 :help "Delete image tag from current or marked files"))
1672 (define-key map
1673 [menu-bar operate image-dired-tag-files]
1674 '(menu-item "Add Image Tags..." image-dired-tag-files
1675 :help "Add image tags to current or marked files"))
1676 (define-key map
1677 [menu-bar operate image-dired-dired-comment-files]
1678 '(menu-item "Add Image Comment..." image-dired-dired-comment-files
1679 :help "Add image comment to current or marked files"))
1680 (define-key map
1681 [menu-bar operate image-dired-display-thumbs]
1682 '(menu-item "Display image thumbnails" image-dired-display-thumbs
1683 :help "Display image thumbnails for current or marked image files"))
1685 (define-key map [menu-bar operate dashes-4]
1686 '("--"))
1688 (define-key map
1689 [menu-bar operate epa-dired-do-decrypt]
1690 '(menu-item "Decrypt" epa-dired-do-decrypt
1691 :help "Decrypt file at cursor"))
1693 (define-key map
1694 [menu-bar operate epa-dired-do-verify]
1695 '(menu-item "Verify" epa-dired-do-verify
1696 :help "Verify digital signature of file at cursor"))
1698 (define-key map
1699 [menu-bar operate epa-dired-do-sign]
1700 '(menu-item "Sign" epa-dired-do-sign
1701 :help "Create digital signature of file at cursor"))
1703 (define-key map
1704 [menu-bar operate epa-dired-do-encrypt]
1705 '(menu-item "Encrypt" epa-dired-do-encrypt
1706 :help "Encrypt file at cursor"))
1708 (define-key map [menu-bar operate dashes-3]
1709 '("--"))
1711 (define-key map [menu-bar operate query-replace]
1712 '(menu-item "Query Replace in Files..." dired-do-query-replace-regexp
1713 :help "Replace regexp in marked files"))
1714 (define-key map [menu-bar operate search]
1715 '(menu-item "Search Files..." dired-do-search
1716 :help "Search marked files for regexp"))
1717 (define-key map [menu-bar operate isearch-regexp]
1718 '(menu-item "Isearch Regexp Files..." dired-do-isearch-regexp
1719 :help "Incrementally search marked files for regexp"))
1720 (define-key map [menu-bar operate isearch]
1721 '(menu-item "Isearch Files..." dired-do-isearch
1722 :help "Incrementally search marked files for string"))
1723 (define-key map [menu-bar operate chown]
1724 '(menu-item "Change Owner..." dired-do-chown
1725 :visible (not (memq system-type '(ms-dos windows-nt)))
1726 :help "Change the owner of marked files"))
1727 (define-key map [menu-bar operate chgrp]
1728 '(menu-item "Change Group..." dired-do-chgrp
1729 :visible (not (memq system-type '(ms-dos windows-nt)))
1730 :help "Change the group of marked files"))
1731 (define-key map [menu-bar operate chmod]
1732 '(menu-item "Change Mode..." dired-do-chmod
1733 :help "Change mode (attributes) of marked files"))
1734 (define-key map [menu-bar operate touch]
1735 '(menu-item "Change Timestamp..." dired-do-touch
1736 :help "Change timestamp of marked files"))
1737 (define-key map [menu-bar operate load]
1738 '(menu-item "Load" dired-do-load
1739 :help "Load marked Emacs Lisp files"))
1740 (define-key map [menu-bar operate compile]
1741 '(menu-item "Byte-compile" dired-do-byte-compile
1742 :help "Byte-compile marked Emacs Lisp files"))
1743 (define-key map [menu-bar operate compress]
1744 '(menu-item "Compress" dired-do-compress
1745 :help "Compress/uncompress marked files"))
1746 (define-key map [menu-bar operate print]
1747 '(menu-item "Print..." dired-do-print
1748 :help "Ask for print command and print marked files"))
1749 (define-key map [menu-bar operate hardlink]
1750 '(menu-item "Hardlink to..." dired-do-hardlink
1751 :help "Make hard links for current or marked files"))
1752 (define-key map [menu-bar operate symlink]
1753 '(menu-item "Symlink to..." dired-do-symlink
1754 :visible (fboundp 'make-symbolic-link)
1755 :help "Make symbolic links for current or marked files"))
1756 (define-key map [menu-bar operate async-command]
1757 '(menu-item "Asynchronous Shell Command..." dired-do-async-shell-command
1758 :help "Run a shell command asynchronously on current or marked files"))
1759 (define-key map [menu-bar operate command]
1760 '(menu-item "Shell Command..." dired-do-shell-command
1761 :help "Run a shell command on current or marked files"))
1762 (define-key map [menu-bar operate delete]
1763 '(menu-item "Delete" dired-do-delete
1764 :help "Delete current file or all marked files"))
1765 (define-key map [menu-bar operate rename]
1766 '(menu-item "Rename to..." dired-do-rename
1767 :help "Rename current file or move marked files"))
1768 (define-key map [menu-bar operate copy]
1769 '(menu-item "Copy to..." dired-do-copy
1770 :help "Copy current file or all marked files"))
1772 map)
1773 "Local keymap for `dired-mode' buffers.")
1775 ;; Dired mode is suitable only for specially formatted data.
1776 (put 'dired-mode 'mode-class 'special)
1778 ;; Autoload cookie needed by desktop.el
1779 ;;;###autoload
1780 (defun dired-mode (&optional dirname switches)
1782 Mode for \"editing\" directory listings.
1783 In Dired, you are \"editing\" a list of the files in a directory and
1784 \(optionally) its subdirectories, in the format of `ls -lR'.
1785 Each directory is a page: use \\[backward-page] and \\[forward-page] to move pagewise.
1786 \"Editing\" means that you can run shell commands on files, visit,
1787 compress, load or byte-compile them, change their file attributes
1788 and insert subdirectories into the same buffer. You can \"mark\"
1789 files for later commands or \"flag\" them for deletion, either file
1790 by file or all files matching certain criteria.
1791 You can move using the usual cursor motion commands.\\<dired-mode-map>
1792 Letters no longer insert themselves. Digits are prefix arguments.
1793 Instead, type \\[dired-flag-file-deletion] to flag a file for Deletion.
1794 Type \\[dired-mark] to Mark a file or subdirectory for later commands.
1795 Most commands operate on the marked files and use the current file
1796 if no files are marked. Use a numeric prefix argument to operate on
1797 the next ARG (or previous -ARG if ARG<0) files, or just `1'
1798 to operate on the current file only. Prefix arguments override marks.
1799 Mark-using commands display a list of failures afterwards. Type \\[dired-summary]
1800 to see why something went wrong.
1801 Type \\[dired-unmark] to Unmark a file or all files of a subdirectory.
1802 Type \\[dired-unmark-backward] to back up one line and unflag.
1803 Type \\[dired-do-flagged-delete] to eXecute the deletions requested.
1804 Type \\[dired-find-file] to Find the current line's file
1805 (or dired it in another buffer, if it is a directory).
1806 Type \\[dired-find-file-other-window] to find file or dired directory in Other window.
1807 Type \\[dired-maybe-insert-subdir] to Insert a subdirectory in this buffer.
1808 Type \\[dired-do-rename] to Rename a file or move the marked files to another directory.
1809 Type \\[dired-do-copy] to Copy files.
1810 Type \\[dired-sort-toggle-or-edit] to toggle Sorting by name/date or change the `ls' switches.
1811 Type \\[revert-buffer] to read all currently expanded directories aGain.
1812 This retains all marks and hides subdirs again that were hidden before.
1813 SPC and DEL can be used to move down and up by lines.
1815 If Dired ever gets confused, you can either type \\[revert-buffer] \
1816 to read the
1817 directories again, type \\[dired-do-redisplay] \
1818 to relist a single or the marked files or a
1819 subdirectory, or type \\[dired-build-subdir-alist] to parse the buffer
1820 again for the directory tree.
1822 Customization variables (rename this buffer and type \\[describe-variable] on each line
1823 for more info):
1825 `dired-listing-switches'
1826 `dired-trivial-filenames'
1827 `dired-shrink-to-fit'
1828 `dired-marker-char'
1829 `dired-del-marker'
1830 `dired-keep-marker-rename'
1831 `dired-keep-marker-copy'
1832 `dired-keep-marker-hardlink'
1833 `dired-keep-marker-symlink'
1835 Hooks (use \\[describe-variable] to see their documentation):
1837 `dired-before-readin-hook'
1838 `dired-after-readin-hook'
1839 `dired-mode-hook'
1840 `dired-load-hook'
1842 Keybindings:
1843 \\{dired-mode-map}"
1844 ;; Not to be called interactively (e.g. dired-directory will be set
1845 ;; to default-directory, which is wrong with wildcards).
1846 (kill-all-local-variables)
1847 (use-local-map dired-mode-map)
1848 (dired-advertise) ; default-directory is already set
1849 (setq major-mode 'dired-mode
1850 mode-name "Dired"
1851 ;; case-fold-search nil
1852 buffer-read-only t
1853 selective-display t ; for subdirectory hiding
1854 mode-line-buffer-identification
1855 (propertized-buffer-identification "%17b"))
1856 (set (make-local-variable 'revert-buffer-function)
1857 (function dired-revert))
1858 (set (make-local-variable 'buffer-stale-function)
1859 (function dired-buffer-stale-p))
1860 (set (make-local-variable 'page-delimiter)
1861 "\n\n")
1862 (set (make-local-variable 'dired-directory)
1863 (or dirname default-directory))
1864 ;; list-buffers uses this to display the dir being edited in this buffer.
1865 (setq list-buffers-directory
1866 (expand-file-name (if (listp dired-directory)
1867 (car dired-directory)
1868 dired-directory)))
1869 (set (make-local-variable 'dired-actual-switches)
1870 (or switches dired-listing-switches))
1871 (set (make-local-variable 'font-lock-defaults)
1872 '(dired-font-lock-keywords t nil nil beginning-of-line))
1873 (set (make-local-variable 'desktop-save-buffer)
1874 'dired-desktop-buffer-misc-data)
1875 (setq dired-switches-alist nil)
1876 (hack-dir-local-variables-non-file-buffer) ; before sorting
1877 (dired-sort-other dired-actual-switches t)
1878 (when (featurep 'dnd)
1879 (set (make-local-variable 'dnd-protocol-alist)
1880 (append dired-dnd-protocol-alist dnd-protocol-alist)))
1881 (add-hook 'file-name-at-point-functions 'dired-file-name-at-point nil t)
1882 (add-hook 'isearch-mode-hook 'dired-isearch-filenames-setup nil t)
1883 (run-mode-hooks 'dired-mode-hook))
1885 ;; Idiosyncratic dired commands that don't deal with marks.
1887 (defun dired-summary ()
1888 "Summarize basic Dired commands and show recent dired errors."
1889 (interactive)
1890 (dired-why)
1891 ;>> this should check the key-bindings and use substitute-command-keys if non-standard
1892 (message
1893 "d-elete, u-ndelete, x-punge, f-ind, o-ther window, R-ename, C-opy, h-elp"))
1895 (defun dired-undo ()
1896 "Undo in a dired buffer.
1897 This doesn't recover lost files, it just undoes changes in the buffer itself.
1898 You can use it to recover marks, killed lines or subdirs."
1899 (interactive)
1900 (let ((inhibit-read-only t))
1901 (undo))
1902 (dired-build-subdir-alist)
1903 (message "Change in dired buffer undone.
1904 Actual changes in files cannot be undone by Emacs."))
1906 (defun dired-toggle-read-only ()
1907 "Edit dired buffer with Wdired, or set it read-only.
1908 Call `wdired-change-to-wdired-mode' in dired buffers whose editing is
1909 supported by Wdired (the major mode of the dired buffer is `dired-mode').
1910 Otherwise, for buffers inheriting from dired-mode, call `toggle-read-only'."
1911 (interactive)
1912 (if (eq major-mode 'dired-mode)
1913 (wdired-change-to-wdired-mode)
1914 (toggle-read-only)))
1916 (defun dired-next-line (arg)
1917 "Move down lines then position at filename.
1918 Optional prefix ARG says how many lines to move; default is one line."
1919 (interactive "p")
1920 (forward-line arg)
1921 (dired-move-to-filename))
1923 (defun dired-previous-line (arg)
1924 "Move up lines then position at filename.
1925 Optional prefix ARG says how many lines to move; default is one line."
1926 (interactive "p")
1927 (forward-line (- arg))
1928 (dired-move-to-filename))
1930 (defun dired-next-dirline (arg &optional opoint)
1931 "Goto ARG'th next directory file line."
1932 (interactive "p")
1933 (or opoint (setq opoint (point)))
1934 (if (if (> arg 0)
1935 (re-search-forward dired-re-dir nil t arg)
1936 (beginning-of-line)
1937 (re-search-backward dired-re-dir nil t (- arg)))
1938 (dired-move-to-filename) ; user may type `i' or `f'
1939 (goto-char opoint)
1940 (error "No more subdirectories")))
1942 (defun dired-prev-dirline (arg)
1943 "Goto ARG'th previous directory file line."
1944 (interactive "p")
1945 (dired-next-dirline (- arg)))
1947 (defun dired-up-directory (&optional other-window)
1948 "Run Dired on parent directory of current directory.
1949 Find the parent directory either in this buffer or another buffer.
1950 Creates a buffer if necessary."
1951 (interactive "P")
1952 (let* ((dir (dired-current-directory))
1953 (up (file-name-directory (directory-file-name dir))))
1954 (or (dired-goto-file (directory-file-name dir))
1955 ;; Only try dired-goto-subdir if buffer has more than one dir.
1956 (and (cdr dired-subdir-alist)
1957 (dired-goto-subdir up))
1958 (progn
1959 (if other-window
1960 (dired-other-window up)
1961 (dired up))
1962 (dired-goto-file dir)))))
1964 (defun dired-get-file-for-visit ()
1965 "Get the current line's file name, with an error if file does not exist."
1966 (interactive)
1967 ;; We pass t for second arg so that we don't get error for `.' and `..'.
1968 (let ((raw (dired-get-filename nil t))
1969 file-name)
1970 (if (null raw)
1971 (error "No file on this line"))
1972 (setq file-name (file-name-sans-versions raw t))
1973 (if (file-exists-p file-name)
1974 file-name
1975 (if (file-symlink-p file-name)
1976 (error "File is a symlink to a nonexistent target")
1977 (error "File no longer exists; type `g' to update dired buffer")))))
1979 ;; Force C-m keybinding rather than `f' or `e' in the mode doc:
1980 (define-obsolete-function-alias 'dired-advertised-find-file 'dired-find-file "23.2")
1981 (defun dired-find-file ()
1982 "In Dired, visit the file or directory named on this line."
1983 (interactive)
1984 ;; Bind `find-file-run-dired' so that the command works on directories
1985 ;; too, independent of the user's setting.
1986 (let ((find-file-run-dired t))
1987 (find-file (dired-get-file-for-visit))))
1989 (defun dired-find-alternate-file ()
1990 "In Dired, visit this file or directory instead of the dired buffer."
1991 (interactive)
1992 (set-buffer-modified-p nil)
1993 (find-alternate-file (dired-get-file-for-visit)))
1994 ;; Don't override the setting from .emacs.
1995 ;;;###autoload (put 'dired-find-alternate-file 'disabled t)
1997 (defun dired-mouse-find-file-other-window (event)
1998 "In Dired, visit the file or directory name you click on."
1999 (interactive "e")
2000 (let (window pos file)
2001 (save-excursion
2002 (setq window (posn-window (event-end event))
2003 pos (posn-point (event-end event)))
2004 (if (not (windowp window))
2005 (error "No file chosen"))
2006 (set-buffer (window-buffer window))
2007 (goto-char pos)
2008 (setq file (dired-get-file-for-visit)))
2009 (if (file-directory-p file)
2010 (or (and (cdr dired-subdir-alist)
2011 (dired-goto-subdir file))
2012 (progn
2013 (select-window window)
2014 (dired-other-window file)))
2015 (select-window window)
2016 (find-file-other-window (file-name-sans-versions file t)))))
2018 (defun dired-view-file ()
2019 "In Dired, examine a file in view mode, returning to Dired when done.
2020 When file is a directory, show it in this buffer if it is inserted.
2021 Otherwise, display it in another buffer."
2022 (interactive)
2023 (let ((file (dired-get-file-for-visit)))
2024 (if (file-directory-p file)
2025 (or (and (cdr dired-subdir-alist)
2026 (dired-goto-subdir file))
2027 (dired file))
2028 (view-file file))))
2030 (defun dired-find-file-other-window ()
2031 "In Dired, visit this file or directory in another window."
2032 (interactive)
2033 (find-file-other-window (dired-get-file-for-visit)))
2035 (defun dired-display-file ()
2036 "In Dired, display this file or directory in another window."
2037 (interactive)
2038 (display-buffer (find-file-noselect (dired-get-file-for-visit))))
2040 ;;; Functions for extracting and manipulating file names in Dired buffers.
2042 (defun dired-get-filename (&optional localp no-error-if-not-filep)
2043 "In Dired, return name of file mentioned on this line.
2044 Value returned normally includes the directory name.
2045 Optional arg LOCALP with value `no-dir' means don't include directory
2046 name in result. A value of `verbatim' means to return the name exactly as
2047 it occurs in the buffer, and a value of t means construct name relative to
2048 `default-directory', which still may contain slashes if in a subdirectory.
2049 Optional arg NO-ERROR-IF-NOT-FILEP means treat `.' and `..' as
2050 regular filenames and return nil if no filename on this line.
2051 Otherwise, an error occurs in these cases."
2052 (let (case-fold-search file p1 p2 already-absolute)
2053 (save-excursion
2054 (if (setq p1 (dired-move-to-filename (not no-error-if-not-filep)))
2055 (setq p2 (dired-move-to-end-of-filename no-error-if-not-filep))))
2056 ;; nil if no file on this line, but no-error-if-not-filep is t:
2057 (if (setq file (and p1 p2 (buffer-substring p1 p2)))
2058 (progn
2059 ;; Get rid of the mouse-face property that file names have.
2060 (set-text-properties 0 (length file) nil file)
2061 ;; Unquote names quoted by ls or by dired-insert-directory.
2062 ;; This code was written using `read' to unquote, because
2063 ;; it's faster than substituting \007 (4 chars) -> ^G (1
2064 ;; char) etc. in a lisp loop. Unfortunately, this decision
2065 ;; has necessitated hacks such as dealing with filenames
2066 ;; with quotation marks in their names.
2067 (while (string-match "\\(?:[^\\]\\|\\`\\)\\(\"\\)" file)
2068 (setq file (replace-match "\\\"" nil t file 1)))
2070 (when (eq system-type 'windows-nt)
2071 (save-match-data
2072 (let ((start 0))
2073 (while (string-match "\\\\" file start)
2074 (aset file (match-beginning 0) ?/)
2075 (setq start (match-end 0))))))
2077 (setq file (read (concat "\"" file "\"")))
2078 ;; The above `read' will return a unibyte string if FILE
2079 ;; contains eight-bit-control/graphic characters.
2080 (if (and enable-multibyte-characters
2081 (not (multibyte-string-p file)))
2082 (setq file (string-to-multibyte file)))))
2083 (and file (file-name-absolute-p file)
2084 ;; A relative file name can start with ~.
2085 ;; Don't treat it as absolute in this context.
2086 (not (eq (aref file 0) ?~))
2087 (setq already-absolute t))
2088 (cond
2089 ((null file)
2090 nil)
2091 ((eq localp 'verbatim)
2092 file)
2093 ((and (not no-error-if-not-filep)
2094 (member file '("." "..")))
2095 (error "Cannot operate on `.' or `..'"))
2096 ((and (eq localp 'no-dir) already-absolute)
2097 (file-name-nondirectory file))
2098 (already-absolute
2099 (let ((handler (find-file-name-handler file nil)))
2100 ;; check for safe-magic property so that we won't
2101 ;; put /: for names that don't really need them.
2102 ;; For instance, .gz files when auto-compression-mode is on.
2103 (if (and handler (not (get handler 'safe-magic)))
2104 (concat "/:" file)
2105 file)))
2106 ((eq localp 'no-dir)
2107 file)
2108 ((equal (dired-current-directory) "/")
2109 (setq file (concat (dired-current-directory localp) file))
2110 (let ((handler (find-file-name-handler file nil)))
2111 ;; check for safe-magic property so that we won't
2112 ;; put /: for names that don't really need them.
2113 ;; For instance, .gz files when auto-compression-mode is on.
2114 (if (and handler (not (get handler 'safe-magic)))
2115 (concat "/:" file)
2116 file)))
2118 (concat (dired-current-directory localp) file)))))
2120 (defun dired-string-replace-match (regexp string newtext
2121 &optional literal global)
2122 "Replace first match of REGEXP in STRING with NEWTEXT.
2123 If it does not match, nil is returned instead of the new string.
2124 Optional arg LITERAL means to take NEWTEXT literally.
2125 Optional arg GLOBAL means to replace all matches."
2126 (if global
2127 (let ((start 0) ret)
2128 (while (string-match regexp string start)
2129 (let ((from-end (- (length string) (match-end 0))))
2130 (setq ret (setq string (replace-match newtext t literal string)))
2131 (setq start (- (length string) from-end))))
2132 ret)
2133 (if (not (string-match regexp string 0))
2135 (replace-match newtext t literal string))))
2137 (defun dired-make-absolute (file &optional dir)
2138 ;;"Convert FILE (a file name relative to DIR) to an absolute file name."
2139 ;; We can't always use expand-file-name as this would get rid of `.'
2140 ;; or expand in / instead default-directory if DIR=="".
2141 ;; This should be good enough for ange-ftp.
2142 ;; It should be reasonably fast, though, as it is called in
2143 ;; dired-get-filename.
2144 (concat (or dir default-directory) file))
2146 (defun dired-make-relative (file &optional dir ignore)
2147 "Convert FILE (an absolute file name) to a name relative to DIR.
2148 If this is impossible, return FILE unchanged.
2149 DIR must be a directory name, not a file name."
2150 (or dir (setq dir default-directory))
2151 ;; This case comes into play if default-directory is set to
2152 ;; use ~.
2153 (if (and (> (length dir) 0) (= (aref dir 0) ?~))
2154 (setq dir (expand-file-name dir)))
2155 (if (string-match (concat "^" (regexp-quote dir)) file)
2156 (substring file (match-end 0))
2157 ;;; (or no-error
2158 ;;; (error "%s: not in directory tree growing at %s" file dir))
2159 file))
2161 ;;; Functions for finding the file name in a dired buffer line.
2163 (defvar dired-permission-flags-regexp
2164 "\\([^ ]\\)[-r][-w]\\([^ ]\\)[-r][-w]\\([^ ]\\)[-r][-w]\\([^ ]\\)"
2165 "Regular expression to match the permission flags in `ls -l'.")
2167 ;; Move to first char of filename on this line.
2168 ;; Returns position (point) or nil if no filename on this line."
2169 (defun dired-move-to-filename (&optional raise-error eol)
2170 "Move to the beginning of the filename on the current line.
2171 Return the position of the beginning of the filename, or nil if none found."
2172 ;; This is the UNIX version.
2173 (or eol (setq eol (line-end-position)))
2174 (beginning-of-line)
2175 ;; First try assuming `ls --dired' was used.
2176 (let ((change (next-single-property-change (point) 'dired-filename nil eol)))
2177 (cond
2178 ((and change (< change eol))
2179 (goto-char change))
2180 ((re-search-forward directory-listing-before-filename-regexp eol t)
2181 (goto-char (match-end 0)))
2182 ((re-search-forward dired-permission-flags-regexp eol t)
2183 ;; Ha! There *is* a file. Our regexp-from-hell just failed to find it.
2184 (if raise-error
2185 (error "Unrecognized line! Check directory-listing-before-filename-regexp"))
2186 (beginning-of-line)
2187 nil)
2188 (raise-error
2189 (error "No file on this line")))))
2191 (defun dired-move-to-end-of-filename (&optional no-error)
2192 ;; Assumes point is at beginning of filename,
2193 ;; thus the rwx bit re-search-backward below will succeed in *this*
2194 ;; line if at all. So, it should be called only after
2195 ;; (dired-move-to-filename t).
2196 ;; On failure, signals an error (with non-nil NO-ERROR just returns nil).
2197 ;; This is the UNIX version.
2198 (if (get-text-property (point) 'dired-filename)
2199 (goto-char (next-single-property-change (point) 'dired-filename))
2200 (let (opoint file-type executable symlink hidden case-fold-search used-F eol)
2201 ;; case-fold-search is nil now, so we can test for capital F:
2202 (setq used-F (string-match "F" dired-actual-switches)
2203 opoint (point)
2204 eol (line-end-position)
2205 hidden (and selective-display
2206 (save-excursion (search-forward "\r" eol t))))
2207 (if hidden
2209 (save-excursion ;; Find out what kind of file this is:
2210 ;; Restrict perm bits to be non-blank,
2211 ;; otherwise this matches one char to early (looking backward):
2212 ;; "l---------" (some systems make symlinks that way)
2213 ;; "----------" (plain file with zero perms)
2214 (if (re-search-backward
2215 dired-permission-flags-regexp nil t)
2216 (setq file-type (char-after (match-beginning 1))
2217 symlink (eq file-type ?l)
2218 ;; Only with -F we need to know whether it's an executable
2219 executable (and
2220 used-F
2221 (string-match
2222 "[xst]" ;; execute bit set anywhere?
2223 (concat
2224 (match-string 2)
2225 (match-string 3)
2226 (match-string 4)))))
2227 (or no-error (error "No file on this line"))))
2228 ;; Move point to end of name:
2229 (if symlink
2230 (if (search-forward " -> " eol t)
2231 (progn
2232 (forward-char -4)
2233 (and used-F
2234 dired-ls-F-marks-symlinks
2235 (eq (preceding-char) ?@) ;; did ls really mark the link?
2236 (forward-char -1))))
2237 (goto-char eol) ;; else not a symbolic link
2238 ;; ls -lF marks dirs, sockets, fifos and executables with exactly
2239 ;; one trailing character. (Executable bits on symlinks ain't mean
2240 ;; a thing, even to ls, but we know it's not a symlink.)
2241 (and used-F
2242 (or (memq file-type '(?d ?s ?p))
2243 executable)
2244 (forward-char -1))))
2245 (or no-error
2246 (not (eq opoint (point)))
2247 (error "%s" (if hidden
2248 (substitute-command-keys
2249 "File line is hidden, type \\[dired-hide-subdir] to unhide")
2250 "No file on this line")))
2251 (if (eq opoint (point))
2253 (point)))))
2256 ;;; COPY NAMES OF MARKED FILES INTO KILL-RING.
2258 (defun dired-copy-filename-as-kill (&optional arg)
2259 "Copy names of marked (or next ARG) files into the kill ring.
2260 The names are separated by a space.
2261 With a zero prefix arg, use the absolute file name of each marked file.
2262 With \\[universal-argument], use the file name relative to the dired buffer's
2263 `default-directory'. (This still may contain slashes if in a subdirectory.)
2265 If on a subdir headerline, use absolute subdirname instead;
2266 prefix arg and marked files are ignored in this case.
2268 You can then feed the file name(s) to other commands with \\[yank]."
2269 (interactive "P")
2270 (let ((string
2271 (or (dired-get-subdir)
2272 (mapconcat (function identity)
2273 (if arg
2274 (cond ((zerop (prefix-numeric-value arg))
2275 (dired-get-marked-files))
2276 ((consp arg)
2277 (dired-get-marked-files t))
2279 (dired-get-marked-files
2280 'no-dir (prefix-numeric-value arg))))
2281 (dired-get-marked-files 'no-dir))
2282 " "))))
2283 (if (eq last-command 'kill-region)
2284 (kill-append string nil)
2285 (kill-new string))
2286 (message "%s" string)))
2289 ;; Keeping Dired buffers in sync with the filesystem and with each other
2291 (defun dired-buffers-for-dir (dir &optional file)
2292 ;; Return a list of buffers for DIR (top level or in-situ subdir).
2293 ;; If FILE is non-nil, include only those whose wildcard pattern (if any)
2294 ;; matches FILE.
2295 ;; The list is in reverse order of buffer creation, most recent last.
2296 ;; As a side effect, killed dired buffers for DIR are removed from
2297 ;; dired-buffers.
2298 (setq dir (file-name-as-directory dir))
2299 (let (result buf)
2300 (dolist (elt dired-buffers)
2301 (setq buf (cdr elt))
2302 (cond
2303 ((null (buffer-name buf))
2304 ;; Buffer is killed - clean up:
2305 (setq dired-buffers (delq elt dired-buffers)))
2306 ((dired-in-this-tree dir (car elt))
2307 (with-current-buffer buf
2308 (and (assoc dir dired-subdir-alist)
2309 (or (null file)
2310 (if (stringp dired-directory)
2311 (let ((wildcards (file-name-nondirectory
2312 dired-directory)))
2313 (or (= 0 (length wildcards))
2314 (string-match (dired-glob-regexp wildcards)
2315 file)))
2316 (member (expand-file-name file dir)
2317 (cdr dired-directory))))
2318 (setq result (cons buf result)))))))
2319 result))
2321 (defun dired-glob-regexp (pattern)
2322 "Convert glob-pattern PATTERN to a regular expression."
2323 (let ((matched-in-pattern 0) ;; How many chars of PATTERN we've handled.
2324 regexp)
2325 (while (string-match "[[?*]" pattern matched-in-pattern)
2326 (let ((op-end (match-end 0))
2327 (next-op (aref pattern (match-beginning 0))))
2328 (setq regexp (concat regexp
2329 (regexp-quote
2330 (substring pattern matched-in-pattern
2331 (match-beginning 0)))))
2332 (cond ((= next-op ??)
2333 (setq regexp (concat regexp "."))
2334 (setq matched-in-pattern op-end))
2335 ((= next-op ?\[)
2336 ;; Fails to handle ^ yet ????
2337 (let* ((set-start (match-beginning 0))
2338 (set-cont
2339 (if (= (aref pattern (1+ set-start)) ?^)
2340 (+ 3 set-start)
2341 (+ 2 set-start)))
2342 (set-end (string-match "]" pattern set-cont))
2343 (set (substring pattern set-start (1+ set-end))))
2344 (setq regexp (concat regexp set))
2345 (setq matched-in-pattern (1+ set-end))))
2346 ((= next-op ?*)
2347 (setq regexp (concat regexp ".*"))
2348 (setq matched-in-pattern op-end)))))
2349 (concat "\\`"
2350 regexp
2351 (regexp-quote
2352 (substring pattern matched-in-pattern))
2353 "\\'")))
2357 (defun dired-advertise ()
2358 ;;"Advertise in variable `dired-buffers' that we dired `default-directory'."
2359 ;; With wildcards we actually advertise too much.
2360 (let ((expanded-default (expand-file-name default-directory)))
2361 (if (memq (current-buffer) (dired-buffers-for-dir expanded-default))
2362 t ; we have already advertised ourselves
2363 (setq dired-buffers
2364 (cons (cons expanded-default (current-buffer))
2365 dired-buffers)))))
2367 (defun dired-unadvertise (dir)
2368 ;; Remove DIR from the buffer alist in variable dired-buffers.
2369 ;; This has the effect of removing any buffer whose main directory is DIR.
2370 ;; It does not affect buffers in which DIR is a subdir.
2371 ;; Removing is also done as a side-effect in dired-buffer-for-dir.
2372 (setq dired-buffers
2373 (delq (assoc (expand-file-name dir) dired-buffers) dired-buffers)))
2375 ;; Tree Dired
2377 ;;; utility functions
2379 (defun dired-in-this-tree (file dir)
2380 ;;"Is FILE part of the directory tree starting at DIR?"
2381 (let (case-fold-search)
2382 (string-match (concat "^" (regexp-quote dir)) file)))
2384 (defun dired-normalize-subdir (dir)
2385 ;; Prepend default-directory to DIR if relative file name.
2386 ;; dired-get-filename must be able to make a valid file name from a
2387 ;; file and its directory DIR.
2388 (file-name-as-directory
2389 (if (file-name-absolute-p dir)
2391 (expand-file-name dir default-directory))))
2393 (defun dired-get-subdir ()
2394 ;;"Return the subdir name on this line, or nil if not on a headerline."
2395 ;; Look up in the alist whether this is a headerline.
2396 (save-excursion
2397 (let ((cur-dir (dired-current-directory)))
2398 (beginning-of-line) ; alist stores b-o-l positions
2399 (and (zerop (- (point)
2400 (dired-get-subdir-min (assoc cur-dir
2401 dired-subdir-alist))))
2402 cur-dir))))
2404 ;(defun dired-get-subdir-min (elt)
2405 ; (cdr elt))
2406 ;; can't use macro, must be redefinable for other alist format in dired-nstd.
2407 (defalias 'dired-get-subdir-min 'cdr)
2409 (defun dired-get-subdir-max (elt)
2410 (save-excursion
2411 (goto-char (dired-get-subdir-min elt))
2412 (dired-subdir-max)))
2414 (defun dired-clear-alist ()
2415 (while dired-subdir-alist
2416 (set-marker (dired-get-subdir-min (car dired-subdir-alist)) nil)
2417 (setq dired-subdir-alist (cdr dired-subdir-alist))))
2419 (defun dired-subdir-index (dir)
2420 ;; Return an index into alist for use with nth
2421 ;; for the sake of subdir moving commands.
2422 (let (found (index 0) (alist dired-subdir-alist))
2423 (while alist
2424 (if (string= dir (car (car alist)))
2425 (setq alist nil found t)
2426 (setq alist (cdr alist) index (1+ index))))
2427 (if found index nil)))
2429 (defun dired-next-subdir (arg &optional no-error-if-not-found no-skip)
2430 "Go to next subdirectory, regardless of level."
2431 ;; Use 0 arg to go to this directory's header line.
2432 ;; NO-SKIP prevents moving to end of header line, returning whatever
2433 ;; position was found in dired-subdir-alist.
2434 (interactive "p")
2435 (let ((this-dir (dired-current-directory))
2436 pos index)
2437 ;; nth with negative arg does not return nil but the first element
2438 (setq index (- (dired-subdir-index this-dir) arg))
2439 (setq pos (if (>= index 0)
2440 (dired-get-subdir-min (nth index dired-subdir-alist))))
2441 (if pos
2442 (progn
2443 (goto-char pos)
2444 (or no-skip (skip-chars-forward "^\n\r"))
2445 (point))
2446 (if no-error-if-not-found
2447 nil ; return nil if not found
2448 (error "%s directory" (if (> arg 0) "Last" "First"))))))
2450 (defun dired-build-subdir-alist (&optional switches)
2451 "Build `dired-subdir-alist' by parsing the buffer.
2452 Returns the new value of the alist.
2453 If optional arg SWITCHES is non-nil, use its value
2454 instead of `dired-actual-switches'."
2455 (interactive)
2456 (dired-clear-alist)
2457 (save-excursion
2458 (let* ((count 0)
2459 (inhibit-read-only t)
2460 (buffer-undo-list t)
2461 (switches (or switches dired-actual-switches))
2462 new-dir-name
2463 (R-ftp-base-dir-regex
2464 ;; Used to expand subdirectory names correctly in recursive
2465 ;; ange-ftp listings.
2466 (and (string-match "R" switches)
2467 (string-match "\\`/.*:\\(/.*\\)" default-directory)
2468 (concat "\\`" (match-string 1 default-directory)))))
2469 (goto-char (point-min))
2470 (setq dired-subdir-alist nil)
2471 (while (re-search-forward dired-subdir-regexp nil t)
2472 ;; Avoid taking a file name ending in a colon
2473 ;; as a subdir name.
2474 (unless (save-excursion
2475 (goto-char (match-beginning 0))
2476 (beginning-of-line)
2477 (forward-char 2)
2478 (save-match-data (looking-at dired-re-perms)))
2479 (save-excursion
2480 (goto-char (match-beginning 1))
2481 (setq new-dir-name
2482 (buffer-substring-no-properties (point) (match-end 1))
2483 new-dir-name
2484 (save-match-data
2485 (if (and R-ftp-base-dir-regex
2486 (not (string= new-dir-name default-directory))
2487 (string-match R-ftp-base-dir-regex new-dir-name))
2488 (concat default-directory
2489 (substring new-dir-name (match-end 0)))
2490 (expand-file-name new-dir-name))))
2491 (delete-region (point) (match-end 1))
2492 (insert new-dir-name))
2493 (setq count (1+ count))
2494 (dired-alist-add-1 new-dir-name
2495 ;; Place a sub directory boundary between lines.
2496 (save-excursion
2497 (goto-char (match-beginning 0))
2498 (beginning-of-line)
2499 (point-marker)))))
2500 (if (and (> count 1) (called-interactively-p 'interactive))
2501 (message "Buffer includes %d directories" count)))
2502 ;; We don't need to sort it because it is in buffer order per
2503 ;; constructionem. Return new alist:
2504 dired-subdir-alist))
2506 (defun dired-alist-add-1 (dir new-marker)
2507 ;; Add new DIR at NEW-MARKER. Don't sort.
2508 (setq dired-subdir-alist
2509 (cons (cons (dired-normalize-subdir dir) new-marker)
2510 dired-subdir-alist)))
2512 (defun dired-goto-next-nontrivial-file ()
2513 ;; Position point on first nontrivial file after point.
2514 (dired-goto-next-file);; so there is a file to compare with
2515 (if (stringp dired-trivial-filenames)
2516 (while (and (not (eobp))
2517 (string-match dired-trivial-filenames
2518 (file-name-nondirectory
2519 (or (dired-get-filename nil t) ""))))
2520 (forward-line 1)
2521 (dired-move-to-filename))))
2523 (defun dired-goto-next-file ()
2524 (let ((max (1- (dired-subdir-max))))
2525 (while (and (not (dired-move-to-filename)) (< (point) max))
2526 (forward-line 1))))
2528 (defun dired-goto-file (file)
2529 "Go to line describing file FILE in this dired buffer."
2530 ;; Return value of point on success, else nil.
2531 ;; FILE must be an absolute file name.
2532 ;; Loses if FILE contains control chars like "\007" for which ls
2533 ;; either inserts "?" or "\\007" into the buffer, so we won't find
2534 ;; it in the buffer.
2535 (interactive
2536 (prog1 ; let push-mark display its message
2537 (list (expand-file-name
2538 (read-file-name "Goto file: "
2539 (dired-current-directory))))
2540 (push-mark)))
2541 (setq file (directory-file-name file)) ; does no harm if no directory
2542 (let (found case-fold-search dir)
2543 (setq dir (or (file-name-directory file)
2544 (error "File name `%s' is not absolute" file)))
2545 (save-excursion
2546 ;; The hair here is to get the result of dired-goto-subdir
2547 ;; without really calling it if we don't have any subdirs.
2548 (if (if (string= dir (expand-file-name default-directory))
2549 (goto-char (point-min))
2550 (and (cdr dired-subdir-alist)
2551 (dired-goto-subdir dir)))
2552 (let ((base (file-name-nondirectory file))
2553 search-string
2554 (boundary (dired-subdir-max)))
2555 (setq search-string
2556 (replace-regexp-in-string "\^m" "\\^m" base nil t))
2557 (setq search-string
2558 (replace-regexp-in-string "\\\\" "\\\\" search-string nil t))
2559 (while (and (not found)
2560 ;; filenames are preceded by SPC, this makes
2561 ;; the search faster (e.g. for the filename "-"!).
2562 (search-forward (concat " " search-string)
2563 boundary 'move))
2564 ;; Match could have BASE just as initial substring or
2565 ;; or in permission bits or date or
2566 ;; not be a proper filename at all:
2567 (if (equal base (dired-get-filename 'no-dir t))
2568 ;; Must move to filename since an (actually
2569 ;; correct) match could have been elsewhere on the
2570 ;; ;; line (e.g. "-" would match somewhere in the
2571 ;; permission bits).
2572 (setq found (dired-move-to-filename))
2573 ;; If this isn't the right line, move forward to avoid
2574 ;; trying this line again.
2575 (forward-line 1))))))
2576 (and found
2577 ;; return value of point (i.e., FOUND):
2578 (goto-char found))))
2580 (defvar dired-find-subdir)
2582 ;; FIXME document whatever dired-x is doing.
2583 (defun dired-initial-position (dirname)
2584 "Where point should go in a new listing of DIRNAME.
2585 Point assumed at beginning of new subdir line."
2586 (end-of-line)
2587 (and (featurep 'dired-x) dired-find-subdir
2588 (dired-goto-subdir dirname))
2589 (if dired-trivial-filenames (dired-goto-next-nontrivial-file)))
2591 ;; These are hooks which make tree dired work.
2592 ;; They are in this file because other parts of dired need to call them.
2593 ;; But they don't call the rest of tree dired unless there are subdirs loaded.
2595 ;; This function is called for each retrieved filename.
2596 ;; It could stand to be faster, though it's mostly function call
2597 ;; overhead. Avoiding the function call seems to save about 10% in
2598 ;; dired-get-filename. Make it a defsubst?
2599 (defun dired-current-directory (&optional localp)
2600 "Return the name of the subdirectory to which this line belongs.
2601 This returns a string with trailing slash, like `default-directory'.
2602 Optional argument means return a file name relative to `default-directory'."
2603 (let ((here (point))
2604 (alist (or dired-subdir-alist
2605 ;; probably because called in a non-dired buffer
2606 (error "No subdir-alist in %s" (current-buffer))))
2607 elt dir)
2608 (while alist
2609 (setq elt (car alist)
2610 dir (car elt)
2611 ;; use `<=' (not `<') as subdir line is part of subdir
2612 alist (if (<= (dired-get-subdir-min elt) here)
2613 nil ; found
2614 (cdr alist))))
2615 (if localp
2616 (dired-make-relative dir default-directory)
2617 dir)))
2619 ;; Subdirs start at the beginning of their header lines and end just
2620 ;; before the beginning of the next header line (or end of buffer).
2622 (defun dired-subdir-max ()
2623 (save-excursion
2624 (if (or (null (cdr dired-subdir-alist)) (not (dired-next-subdir 1 t t)))
2625 (point-max)
2626 (point))))
2628 ;; Deleting files
2630 (defcustom dired-recursive-deletes 'top
2631 "Decide whether recursive deletes are allowed.
2632 A value of nil means no recursive deletes.
2633 `always' means delete recursively without asking. This is DANGEROUS!
2634 `top' means ask for each directory at top level, but delete its subdirectories
2635 without asking.
2636 Anything else means ask for each directory."
2637 :type '(choice :tag "Delete non-empty directories"
2638 (const :tag "Yes" always)
2639 (const :tag "No--only delete empty directories" nil)
2640 (const :tag "Confirm for each directory" t)
2641 (const :tag "Confirm for each top directory only" top))
2642 :group 'dired)
2644 ;; Match anything but `.' and `..'.
2645 (defvar dired-re-no-dot "^\\([^.]\\|\\.\\([^.]\\|\\..\\)\\).*")
2647 ;; Delete file, possibly delete a directory and all its files.
2648 ;; This function is usefull outside of dired. One could change it's name
2649 ;; to e.g. recursive-delete-file and put it somewhere else.
2650 (defun dired-delete-file (file &optional recursive trash) "\
2651 Delete FILE or directory (possibly recursively if optional RECURSIVE is true.)
2652 RECURSIVE determines what to do with a non-empty directory. If RECURSIVE is:
2653 nil, do not delete.
2654 `always', delete recursively without asking.
2655 `top', ask for each directory at top level.
2656 Anything else, ask for each sub-directory."
2657 ;; This test is equivalent to
2658 ;; (and (file-directory-p fn) (not (file-symlink-p fn)))
2659 ;; but more efficient
2660 (if (not (eq t (car (file-attributes file))))
2661 (delete-file file trash)
2662 (if (and recursive
2663 (directory-files file t dired-re-no-dot) ; Not empty.
2664 (or (eq recursive 'always)
2665 (yes-or-no-p (format "Recursively %s %s? "
2666 (if (and trash
2667 delete-by-moving-to-trash)
2668 "trash"
2669 "delete")
2670 (dired-make-relative file)))))
2671 (if (eq recursive 'top) (setq recursive 'always)) ; Don't ask again.
2672 (setq recursive nil))
2673 (delete-directory file recursive trash)))
2675 (defun dired-do-flagged-delete (&optional nomessage)
2676 "In Dired, delete the files flagged for deletion.
2677 If NOMESSAGE is non-nil, we don't display any message
2678 if there are no flagged files.
2679 `dired-recursive-deletes' controls whether deletion of
2680 non-empty directories is allowed."
2681 (interactive)
2682 (let* ((dired-marker-char dired-del-marker)
2683 (regexp (dired-marker-regexp))
2684 case-fold-search)
2685 (if (save-excursion (goto-char (point-min))
2686 (re-search-forward regexp nil t))
2687 (dired-internal-do-deletions
2688 ;; this can't move point since ARG is nil
2689 (dired-map-over-marks (cons (dired-get-filename) (point))
2690 nil)
2691 nil t)
2692 (or nomessage
2693 (message "(No deletions requested)")))))
2695 (defun dired-do-delete (&optional arg)
2696 "Delete all marked (or next ARG) files.
2697 `dired-recursive-deletes' controls whether deletion of
2698 non-empty directories is allowed."
2699 ;; This is more consistent with the file marking feature than
2700 ;; dired-do-flagged-delete.
2701 (interactive "P")
2702 (dired-internal-do-deletions
2703 ;; this may move point if ARG is an integer
2704 (dired-map-over-marks (cons (dired-get-filename) (point))
2705 arg)
2706 arg t))
2708 (defvar dired-deletion-confirmer 'yes-or-no-p) ; or y-or-n-p?
2710 (defun dired-internal-do-deletions (l arg &optional trash)
2711 ;; L is an alist of files to delete, with their buffer positions.
2712 ;; ARG is the prefix arg.
2713 ;; Filenames are absolute.
2714 ;; (car L) *must* be the *last* (bottommost) file in the dired buffer.
2715 ;; That way as changes are made in the buffer they do not shift the
2716 ;; lines still to be changed, so the (point) values in L stay valid.
2717 ;; Also, for subdirs in natural order, a subdir's files are deleted
2718 ;; before the subdir itself - the other way around would not work.
2719 (let* ((files (mapcar (function car) l))
2720 (count (length l))
2721 (succ 0)
2722 (trashing (and trash delete-by-moving-to-trash))
2723 (progress-reporter
2724 (make-progress-reporter
2725 (if trashing "Trashing..." "Deleting...")
2726 succ count)))
2727 ;; canonicalize file list for pop up
2728 (setq files (nreverse (mapcar (function dired-make-relative) files)))
2729 (if (dired-mark-pop-up
2730 " *Deletions*" 'delete files dired-deletion-confirmer
2731 (format "%s %s "
2732 (if trashing "Trash" "Delete")
2733 (dired-mark-prompt arg files)))
2734 (save-excursion
2735 (let (failures);; files better be in reverse order for this loop!
2736 (while l
2737 (goto-char (cdr (car l)))
2738 (let ((inhibit-read-only t))
2739 (condition-case err
2740 (let ((fn (car (car l))))
2741 (dired-delete-file fn dired-recursive-deletes trash)
2742 ;; if we get here, removing worked
2743 (setq succ (1+ succ))
2744 (progress-reporter-update progress-reporter succ)
2745 (dired-fun-in-all-buffers
2746 (file-name-directory fn) (file-name-nondirectory fn)
2747 (function dired-delete-entry) fn))
2748 (error;; catch errors from failed deletions
2749 (dired-log "%s\n" err)
2750 (setq failures (cons (car (car l)) failures)))))
2751 (setq l (cdr l)))
2752 (if (not failures)
2753 (progress-reporter-done progress-reporter)
2754 (dired-log-summary
2755 (format "%d of %d deletion%s failed"
2756 (length failures) count
2757 (dired-plural-s count))
2758 failures))))
2759 (message "(No deletions performed)")))
2760 (dired-move-to-filename))
2762 (defun dired-fun-in-all-buffers (directory file fun &rest args)
2763 ;; In all buffers dired'ing DIRECTORY, run FUN with ARGS.
2764 ;; If the buffer has a wildcard pattern, check that it matches FILE.
2765 ;; (FILE does not include a directory component.)
2766 ;; FILE may be nil, in which case ignore it.
2767 ;; Return list of buffers where FUN succeeded (i.e., returned non-nil).
2768 (let (success-list)
2769 (dolist (buf (dired-buffers-for-dir (expand-file-name directory)
2770 file))
2771 (with-current-buffer buf
2772 (if (apply fun args)
2773 (setq success-list (cons (buffer-name buf) success-list)))))
2774 success-list))
2776 ;; Delete the entry for FILE from
2777 (defun dired-delete-entry (file)
2778 (save-excursion
2779 (and (dired-goto-file file)
2780 (let ((inhibit-read-only t))
2781 (delete-region (progn (beginning-of-line) (point))
2782 (save-excursion (forward-line 1) (point))))))
2783 (dired-clean-up-after-deletion file))
2785 (defvar dired-clean-up-buffers-too)
2787 (defun dired-clean-up-after-deletion (fn)
2788 "Clean up after a deleted file or directory FN.
2789 Removes any expanded subdirectory of deleted directory.
2790 If `dired-x' is loaded and `dired-clean-up-buffers-too' is non-nil,
2791 also offers to kill buffers visiting deleted files and directories."
2792 (save-excursion (and (cdr dired-subdir-alist)
2793 (dired-goto-subdir fn)
2794 (dired-kill-subdir)))
2795 ;; Offer to kill buffer of deleted file FN.
2796 (when (and (featurep 'dired-x) dired-clean-up-buffers-too)
2797 (let ((buf (get-file-buffer fn)))
2798 (and buf
2799 (funcall #'y-or-n-p
2800 (format "Kill buffer of %s, too? "
2801 (file-name-nondirectory fn)))
2802 (kill-buffer buf)))
2803 (let ((buf-list (dired-buffers-for-dir (expand-file-name fn))))
2804 (and buf-list
2805 (y-or-n-p (format "Kill dired buffer%s of %s, too? "
2806 (dired-plural-s (length buf-list))
2807 (file-name-nondirectory fn)))
2808 (dolist (buf buf-list)
2809 (kill-buffer buf))))))
2812 ;; Confirmation
2814 (defun dired-marker-regexp ()
2815 (concat "^" (regexp-quote (char-to-string dired-marker-char))))
2817 (defun dired-plural-s (count)
2818 (if (= 1 count) "" "s"))
2820 (defun dired-mark-prompt (arg files)
2821 "Return a string for use in a prompt, either the current file
2822 name, or the marker and a count of marked files."
2823 ;; distinguish-one-marked can cause the first element to be just t.
2824 (if (eq (car files) t) (setq files (cdr files)))
2825 (let ((count (length files)))
2826 (if (= count 1)
2827 (car files)
2828 ;; more than 1 file:
2829 (if (integerp arg)
2830 ;; abs(arg) = count
2831 ;; Perhaps this is nicer, but it also takes more screen space:
2832 ;;(format "[%s %d files]" (if (> arg 0) "next" "previous")
2833 ;; count)
2834 (format "[next %d files]" arg)
2835 (format "%c [%d files]" dired-marker-char count)))))
2837 (defun dired-pop-to-buffer (buf)
2838 "Pop up buffer BUF in a way suitable for Dired."
2839 (let ((split-window-preferred-function
2840 (lambda (window)
2841 (or (and (let ((split-height-threshold 0))
2842 (window-splittable-p (selected-window)))
2843 ;; Try to split the selected window vertically if
2844 ;; that's possible. (Bug#1806)
2845 (split-window-vertically))
2846 ;; Otherwise, try to split WINDOW sensibly.
2847 (split-window-sensibly window))))
2848 pop-up-frames)
2849 (pop-to-buffer (get-buffer-create buf)))
2850 ;; If dired-shrink-to-fit is t, make its window fit its contents.
2851 (when dired-shrink-to-fit
2852 ;; Try to not delete window when we want to display less than
2853 ;; `window-min-height' lines.
2854 (fit-window-to-buffer (get-buffer-window buf) nil 1)))
2856 (defcustom dired-no-confirm nil
2857 "A list of symbols for commands Dired should not confirm, or t.
2858 Command symbols are `byte-compile', `chgrp', `chmod', `chown', `compress',
2859 `copy', `delete', `hardlink', `load', `move', `print', `shell', `symlink',
2860 `touch' and `uncompress'.
2861 If t, confirmation is never needed."
2862 :group 'dired
2863 :type '(choice (const :tag "Confirmation never needed" t)
2864 (set (const byte-compile) (const chgrp)
2865 (const chmod) (const chown) (const compress)
2866 (const copy) (const delete) (const hardlink)
2867 (const load) (const move) (const print)
2868 (const shell) (const symlink) (const touch)
2869 (const uncompress))))
2871 (defun dired-mark-pop-up (bufname op-symbol files function &rest args)
2872 "Return FUNCTION's result on ARGS after showing which files are marked.
2873 Displays the file names in a buffer named BUFNAME;
2874 nil gives \" *Marked Files*\".
2875 This uses function `dired-pop-to-buffer' to do that.
2877 FUNCTION should not manipulate files, just read input
2878 (an argument or confirmation).
2879 The window is not shown if there is just one file or
2880 OP-SYMBOL is a member of the list in `dired-no-confirm'.
2881 FILES is the list of marked files. It can also be (t FILENAME)
2882 in the case of one marked file, to distinguish that from using
2883 just the current file."
2884 (or bufname (setq bufname " *Marked Files*"))
2885 (if (or (eq dired-no-confirm t)
2886 (memq op-symbol dired-no-confirm)
2887 ;; If FILES defaulted to the current line's file.
2888 (= (length files) 1))
2889 (apply function args)
2890 (with-current-buffer (get-buffer-create bufname)
2891 (erase-buffer)
2892 ;; Handle (t FILE) just like (FILE), here.
2893 ;; That value is used (only in some cases), to mean
2894 ;; just one file that was marked, rather than the current line file.
2895 (dired-format-columns-of-files (if (eq (car files) t) (cdr files) files))
2896 (remove-text-properties (point-min) (point-max)
2897 '(mouse-face nil help-echo nil)))
2898 (save-window-excursion
2899 (dired-pop-to-buffer bufname)
2900 (apply function args))))
2902 (defun dired-format-columns-of-files (files)
2903 (let ((beg (point)))
2904 (completion--insert-strings files)
2905 (put-text-property beg (point) 'mouse-face nil)))
2907 ;; Commands to mark or flag file(s) at or near current line.
2909 (defun dired-repeat-over-lines (arg function)
2910 ;; This version skips non-file lines.
2911 (let ((pos (make-marker)))
2912 (beginning-of-line)
2913 (while (and (> arg 0) (not (eobp)))
2914 (setq arg (1- arg))
2915 (beginning-of-line)
2916 (while (and (not (eobp)) (dired-between-files)) (forward-line 1))
2917 (save-excursion
2918 (forward-line 1)
2919 (move-marker pos (1+ (point))))
2920 (save-excursion (funcall function))
2921 ;; Advance to the next line--actually, to the line that *was* next.
2922 ;; (If FUNCTION inserted some new lines in between, skip them.)
2923 (goto-char pos))
2924 (while (and (< arg 0) (not (bobp)))
2925 (setq arg (1+ arg))
2926 (forward-line -1)
2927 (while (and (not (bobp)) (dired-between-files)) (forward-line -1))
2928 (beginning-of-line)
2929 (save-excursion (funcall function)))
2930 (move-marker pos nil)
2931 (dired-move-to-filename)))
2933 (defun dired-between-files ()
2934 ;; This used to be a regexp match of the `total ...' line output by
2935 ;; ls, which is slightly faster, but that is not very robust; notably,
2936 ;; it fails for non-english locales.
2937 (save-excursion (not (dired-move-to-filename))))
2939 (defun dired-next-marked-file (arg &optional wrap opoint)
2940 "Move to the next marked file, wrapping around the end of the buffer."
2941 (interactive "p\np")
2942 (or opoint (setq opoint (point)));; return to where interactively started
2943 (if (if (> arg 0)
2944 (re-search-forward dired-re-mark nil t arg)
2945 (beginning-of-line)
2946 (re-search-backward dired-re-mark nil t (- arg)))
2947 (dired-move-to-filename)
2948 (if (null wrap)
2949 (progn
2950 (goto-char opoint)
2951 (error "No next marked file"))
2952 (message "(Wraparound for next marked file)")
2953 (goto-char (if (> arg 0) (point-min) (point-max)))
2954 (dired-next-marked-file arg nil opoint))))
2956 (defun dired-prev-marked-file (arg &optional wrap)
2957 "Move to the previous marked file, wrapping around the end of the buffer."
2958 (interactive "p\np")
2959 (dired-next-marked-file (- arg) wrap))
2961 (defun dired-file-marker (file)
2962 ;; Return FILE's marker, or nil if unmarked.
2963 (save-excursion
2964 (and (dired-goto-file file)
2965 (progn
2966 (beginning-of-line)
2967 (if (not (equal ?\040 (following-char)))
2968 (following-char))))))
2970 (defun dired-mark-files-in-region (start end)
2971 (let ((inhibit-read-only t))
2972 (if (> start end)
2973 (error "start > end"))
2974 (goto-char start) ; assumed at beginning of line
2975 (while (< (point) end)
2976 ;; Skip subdir line and following garbage like the `total' line:
2977 (while (and (< (point) end) (dired-between-files))
2978 (forward-line 1))
2979 (if (and (not (looking-at dired-re-dot))
2980 (dired-get-filename nil t))
2981 (progn
2982 (delete-char 1)
2983 (insert dired-marker-char)))
2984 (forward-line 1))))
2986 (defun dired-mark (arg)
2987 "Mark the current (or next ARG) files.
2988 If on a subdir headerline, mark all its files except `.' and `..'.
2990 Use \\[dired-unmark-all-files] to remove all marks
2991 and \\[dired-unmark] on a subdir to remove the marks in
2992 this subdir."
2993 (interactive "P")
2994 (if (dired-get-subdir)
2995 (save-excursion (dired-mark-subdir-files))
2996 (let ((inhibit-read-only t))
2997 (dired-repeat-over-lines
2998 (prefix-numeric-value arg)
2999 (function (lambda () (delete-char 1) (insert dired-marker-char)))))))
3001 (defun dired-unmark (arg)
3002 "Unmark the current (or next ARG) files.
3003 If looking at a subdir, unmark all its files except `.' and `..'."
3004 (interactive "P")
3005 (let ((dired-marker-char ?\040))
3006 (dired-mark arg)))
3008 (defun dired-flag-file-deletion (arg)
3009 "In Dired, flag the current line's file for deletion.
3010 With prefix arg, repeat over several lines.
3012 If on a subdir headerline, mark all its files except `.' and `..'."
3013 (interactive "P")
3014 (let ((dired-marker-char dired-del-marker))
3015 (dired-mark arg)))
3017 (defun dired-unmark-backward (arg)
3018 "In Dired, move up lines and remove deletion flag there.
3019 Optional prefix ARG says how many lines to unflag; default is one line."
3020 (interactive "p")
3021 (dired-unmark (- arg)))
3023 (defun dired-toggle-marks ()
3024 "Toggle marks: marked files become unmarked, and vice versa.
3025 Files marked with other flags (such as `D') are not affected.
3026 `.' and `..' are never toggled.
3027 As always, hidden subdirs are not affected."
3028 (interactive)
3029 (save-excursion
3030 (goto-char (point-min))
3031 (let ((inhibit-read-only t))
3032 (while (not (eobp))
3033 (or (dired-between-files)
3034 (looking-at dired-re-dot)
3035 ;; use subst instead of insdel because it does not move
3036 ;; the gap and thus should be faster and because
3037 ;; other characters are left alone automatically
3038 (apply 'subst-char-in-region
3039 (point) (1+ (point))
3040 (if (eq ?\040 (following-char)) ; SPC
3041 (list ?\040 dired-marker-char)
3042 (list dired-marker-char ?\040))))
3043 (forward-line 1)))))
3045 ;;; Commands to mark or flag files based on their characteristics or names.
3047 (defvar dired-regexp-history nil
3048 "History list of regular expressions used in Dired commands.")
3050 (defun dired-read-regexp (prompt)
3051 (read-from-minibuffer prompt nil nil nil 'dired-regexp-history))
3053 (defun dired-mark-files-regexp (regexp &optional marker-char)
3054 "Mark all files matching REGEXP for use in later commands.
3055 A prefix argument means to unmark them instead.
3056 `.' and `..' are never marked.
3058 REGEXP is an Emacs regexp, not a shell wildcard. Thus, use `\\.o$' for
3059 object files--just `.o' will mark more than you might think."
3060 (interactive
3061 (list (dired-read-regexp (concat (if current-prefix-arg "Unmark" "Mark")
3062 " files (regexp): "))
3063 (if current-prefix-arg ?\040)))
3064 (let ((dired-marker-char (or marker-char dired-marker-char)))
3065 (dired-mark-if
3066 (and (not (looking-at dired-re-dot))
3067 (not (eolp)) ; empty line
3068 (let ((fn (dired-get-filename nil t)))
3069 (and fn (string-match regexp (file-name-nondirectory fn)))))
3070 "matching file")))
3072 (defun dired-mark-files-containing-regexp (regexp &optional marker-char)
3073 "Mark all files with contents containing REGEXP for use in later commands.
3074 A prefix argument means to unmark them instead.
3075 `.' and `..' are never marked."
3076 (interactive
3077 (list (dired-read-regexp (concat (if current-prefix-arg "Unmark" "Mark")
3078 " files containing (regexp): "))
3079 (if current-prefix-arg ?\040)))
3080 (let ((dired-marker-char (or marker-char dired-marker-char)))
3081 (dired-mark-if
3082 (and (not (looking-at dired-re-dot))
3083 (not (eolp)) ; empty line
3084 (let ((fn (dired-get-filename nil t)))
3085 (when (and fn (file-readable-p fn)
3086 (not (file-directory-p fn)))
3087 (let ((prebuf (get-file-buffer fn)))
3088 (message "Checking %s" fn)
3089 ;; For now we do it inside emacs
3090 ;; Grep might be better if there are a lot of files
3091 (if prebuf
3092 (with-current-buffer prebuf
3093 (save-excursion
3094 (goto-char (point-min))
3095 (re-search-forward regexp nil t)))
3096 (with-temp-buffer
3097 (insert-file-contents fn)
3098 (goto-char (point-min))
3099 (re-search-forward regexp nil t))))
3101 "matching file")))
3103 (defun dired-flag-files-regexp (regexp)
3104 "In Dired, flag all files containing the specified REGEXP for deletion.
3105 The match is against the non-directory part of the filename. Use `^'
3106 and `$' to anchor matches. Exclude subdirs by hiding them.
3107 `.' and `..' are never flagged."
3108 (interactive (list (dired-read-regexp "Flag for deletion (regexp): ")))
3109 (dired-mark-files-regexp regexp dired-del-marker))
3111 (defun dired-mark-symlinks (unflag-p)
3112 "Mark all symbolic links.
3113 With prefix argument, unflag all those files."
3114 (interactive "P")
3115 (let ((dired-marker-char (if unflag-p ?\040 dired-marker-char)))
3116 (dired-mark-if (looking-at dired-re-sym) "symbolic link")))
3118 (defun dired-mark-directories (unflag-p)
3119 "Mark all directory file lines except `.' and `..'.
3120 With prefix argument, unflag all those files."
3121 (interactive "P")
3122 (let ((dired-marker-char (if unflag-p ?\040 dired-marker-char)))
3123 (dired-mark-if (and (looking-at dired-re-dir)
3124 (not (looking-at dired-re-dot)))
3125 "directory file")))
3127 (defun dired-mark-executables (unflag-p)
3128 "Mark all executable files.
3129 With prefix argument, unflag all those files."
3130 (interactive "P")
3131 (let ((dired-marker-char (if unflag-p ?\040 dired-marker-char)))
3132 (dired-mark-if (looking-at dired-re-exe) "executable file")))
3134 ;; dired-x.el has a dired-mark-sexp interactive command: mark
3135 ;; files for which PREDICATE returns non-nil.
3137 (defun dired-flag-auto-save-files (&optional unflag-p)
3138 "Flag for deletion files whose names suggest they are auto save files.
3139 A prefix argument says to unflag those files instead."
3140 (interactive "P")
3141 (let ((dired-marker-char (if unflag-p ?\040 dired-del-marker)))
3142 (dired-mark-if
3143 ;; It is less than general to check for # here,
3144 ;; but it's the only way this runs fast enough.
3145 (and (save-excursion (end-of-line)
3147 (eq (preceding-char) ?#)
3148 ;; Handle executables in case of -F option.
3149 ;; We need not worry about the other kinds
3150 ;; of markings that -F makes, since they won't
3151 ;; appear on real auto-save files.
3152 (if (eq (preceding-char) ?*)
3153 (progn
3154 (forward-char -1)
3155 (eq (preceding-char) ?#)))))
3156 (not (looking-at dired-re-dir))
3157 (let ((fn (dired-get-filename t t)))
3158 (if fn (auto-save-file-name-p
3159 (file-name-nondirectory fn)))))
3160 "auto save file")))
3162 (defcustom dired-garbage-files-regexp
3163 ;; `log' here is dubious, since it's typically used for useful log
3164 ;; files, not just TeX stuff. -- fx
3165 (concat (regexp-opt
3166 '(".log" ".toc" ".dvi" ".bak" ".orig" ".rej" ".aux"))
3167 "\\'")
3168 "Regular expression to match \"garbage\" files for `dired-flag-garbage-files'."
3169 :type 'regexp
3170 :group 'dired)
3172 (defun dired-flag-garbage-files ()
3173 "Flag for deletion all files that match `dired-garbage-files-regexp'."
3174 (interactive)
3175 (dired-flag-files-regexp dired-garbage-files-regexp))
3177 (defun dired-flag-backup-files (&optional unflag-p)
3178 "Flag all backup files (names ending with `~') for deletion.
3179 With prefix argument, unflag these files."
3180 (interactive "P")
3181 (let ((dired-marker-char (if unflag-p ?\s dired-del-marker)))
3182 (dired-mark-if
3183 ;; Don't call backup-file-name-p unless the last character looks like
3184 ;; it might be the end of a backup file name. This isn't very general,
3185 ;; but it's the only way this runs fast enough.
3186 (and (save-excursion (end-of-line)
3187 ;; Handle executables in case of -F option.
3188 ;; We need not worry about the other kinds
3189 ;; of markings that -F makes, since they won't
3190 ;; appear on real backup files.
3191 (if (eq (preceding-char) ?*)
3192 (forward-char -1))
3193 (eq (preceding-char) ?~))
3194 (not (looking-at dired-re-dir))
3195 (let ((fn (dired-get-filename t t)))
3196 (if fn (backup-file-name-p fn))))
3197 "backup file")))
3199 (defun dired-change-marks (&optional old new)
3200 "Change all OLD marks to NEW marks.
3201 OLD and NEW are both characters used to mark files."
3202 (interactive
3203 (let* ((cursor-in-echo-area t)
3204 (old (progn (message "Change (old mark): ") (read-char)))
3205 (new (progn (message "Change %c marks to (new mark): " old)
3206 (read-char))))
3207 (list old new)))
3208 (if (or (eq old ?\r) (eq new ?\r))
3209 (ding)
3210 (let ((string (format "\n%c" old))
3211 (inhibit-read-only t))
3212 (save-excursion
3213 (goto-char (point-min))
3214 (while (search-forward string nil t)
3215 (if (if (= old ?\s)
3216 (save-match-data
3217 (dired-get-filename 'no-dir t))
3219 (subst-char-in-region (match-beginning 0)
3220 (match-end 0) old new)))))))
3222 (defun dired-unmark-all-marks ()
3223 "Remove all marks from all files in the dired buffer."
3224 (interactive)
3225 (dired-unmark-all-files ?\r))
3227 (defun dired-unmark-all-files (mark &optional arg)
3228 "Remove a specific mark (or any mark) from every file.
3229 After this command, type the mark character to remove,
3230 or type RET to remove all marks.
3231 With prefix arg, query for each marked file.
3232 Type \\[help-command] at that time for help."
3233 (interactive "cRemove marks (RET means all): \nP")
3234 (save-excursion
3235 (let* ((count 0)
3236 (inhibit-read-only t) case-fold-search query
3237 (string (format "\n%c" mark))
3238 (help-form "\
3239 Type SPC or `y' to unmark one file, DEL or `n' to skip to next,
3240 `!' to unmark all remaining files with no more questions."))
3241 (goto-char (point-min))
3242 (while (if (eq mark ?\r)
3243 (re-search-forward dired-re-mark nil t)
3244 (search-forward string nil t))
3245 (if (or (not arg)
3246 (let ((file (dired-get-filename t t)))
3247 (and file
3248 (dired-query 'query "Unmark file `%s'? "
3249 file))))
3250 (progn (subst-char-in-region (1- (point)) (point)
3251 (preceding-char) ?\s)
3252 (setq count (1+ count)))))
3253 (message (if (= count 1) "1 mark removed"
3254 "%d marks removed")
3255 count))))
3257 ;; Logging failures operating on files, and showing the results.
3259 (defvar dired-log-buffer "*Dired log*")
3261 (defun dired-why ()
3262 "Pop up a buffer with error log output from Dired.
3263 A group of errors from a single command ends with a formfeed.
3264 Thus, use \\[backward-page] to find the beginning of a group of errors."
3265 (interactive)
3266 (if (get-buffer dired-log-buffer)
3267 (let ((owindow (selected-window))
3268 (window (display-buffer (get-buffer dired-log-buffer))))
3269 (unwind-protect
3270 (progn
3271 (select-window window)
3272 (goto-char (point-max))
3273 (forward-line -1)
3274 (backward-page 1)
3275 (recenter 0))
3276 (select-window owindow)))))
3278 (defun dired-log (log &rest args)
3279 ;; Log a message or the contents of a buffer.
3280 ;; If LOG is a string and there are more args, it is formatted with
3281 ;; those ARGS. Usually the LOG string ends with a \n.
3282 ;; End each bunch of errors with (dired-log t):
3283 ;; this inserts the current time and buffer at the start of the page,
3284 ;; and \f (formfeed) at the end.
3285 (let ((obuf (current-buffer)))
3286 (with-current-buffer (get-buffer-create dired-log-buffer)
3287 (goto-char (point-max))
3288 (let ((inhibit-read-only t))
3289 (cond ((stringp log)
3290 (insert (if args
3291 (apply (function format) log args)
3292 log)))
3293 ((bufferp log)
3294 (insert-buffer-substring log))
3295 ((eq t log)
3296 (backward-page 1)
3297 (unless (bolp)
3298 (insert "\n"))
3299 (insert (current-time-string)
3300 "\tBuffer `" (buffer-name obuf) "'\n")
3301 (goto-char (point-max))
3302 (insert "\f\n")))))))
3304 (defun dired-log-summary (string failures)
3305 "State a summary of a command's failures, in echo area and log buffer.
3306 STRING is an overall summary of the failures.
3307 FAILURES is a list of file names that we failed to operate on,
3308 or nil if file names are not applicable."
3309 (if (= (length failures) 1)
3310 (message "%s"
3311 (with-current-buffer dired-log-buffer
3312 (goto-char (point-max))
3313 (backward-page 1)
3314 (if (eolp) (forward-line 1))
3315 (buffer-substring (point) (point-max))))
3316 (message (if failures "%s--type ? for details (%s)"
3317 "%s--type ? for details")
3318 string failures))
3319 ;; Log a summary describing a bunch of errors.
3320 (dired-log (concat "\n" string "\n"))
3321 (dired-log t))
3323 ;;; Sorting
3325 ;; Most ls can only sort by name or by date (with -t), nothing else.
3326 ;; GNU ls sorts on size with -S, on extension with -X, and unsorted with -U.
3327 ;; So anything that does not contain these is sort "by name".
3329 (defvar dired-ls-sorting-switches "SXU"
3330 "String of `ls' switches \(single letters\) except \"t\" that influence sorting.
3332 This indicates to Dired which option switches to watch out for because they
3333 will change the sorting order behavior of `ls'.
3335 To change the default sorting order \(e.g. add a `-v' option\), see the
3336 variable `dired-listing-switches'. To temporarily override the listing
3337 format, use `\\[universal-argument] \\[dired]'.")
3339 (defvar dired-sort-by-date-regexp
3340 (concat "\\(\\`\\| \\)-[^- ]*t"
3341 ;; `dired-ls-sorting-switches' after -t overrides -t.
3342 "[^ " dired-ls-sorting-switches "]*"
3343 "\\(\\(\\`\\| +\\)\\(--[^ ]+\\|-[^- t"
3344 dired-ls-sorting-switches "]+\\)\\)* *$")
3345 "Regexp recognized by Dired to set `by date' mode.")
3347 (defvar dired-sort-by-name-regexp
3348 (concat "\\`\\(\\(\\`\\| +\\)\\(--[^ ]+\\|"
3349 "-[^- t" dired-ls-sorting-switches "]+\\)\\)* *$")
3350 "Regexp recognized by Dired to set `by name' mode.")
3352 (defvar dired-sort-inhibit nil
3353 "Non-nil means the Dired sort command is disabled.
3354 The idea is to set this buffer-locally in special dired buffers.")
3356 (defun dired-sort-set-modeline ()
3357 ;; Set modeline display according to dired-actual-switches.
3358 ;; Modeline display of "by name" or "by date" guarantees the user a
3359 ;; match with the corresponding regexps. Non-matching switches are
3360 ;; shown literally.
3361 (when (eq major-mode 'dired-mode)
3362 (setq mode-name
3363 (let (case-fold-search)
3364 (cond ((string-match
3365 dired-sort-by-name-regexp dired-actual-switches)
3366 "Dired by name")
3367 ((string-match
3368 dired-sort-by-date-regexp dired-actual-switches)
3369 "Dired by date")
3371 (concat "Dired " dired-actual-switches)))))
3372 (force-mode-line-update)))
3374 (defun dired-sort-toggle-or-edit (&optional arg)
3375 "Toggle sorting by date, and refresh the Dired buffer.
3376 With a prefix argument, edit the current listing switches instead."
3377 (interactive "P")
3378 (when dired-sort-inhibit
3379 (error "Cannot sort this dired buffer"))
3380 (if arg
3381 (dired-sort-other
3382 (read-string "ls switches (must contain -l): " dired-actual-switches))
3383 (dired-sort-toggle)))
3385 (defun dired-sort-toggle ()
3386 ;; Toggle between sort by date/name. Reverts the buffer.
3387 (let ((sorting-by-date (string-match dired-sort-by-date-regexp
3388 dired-actual-switches))
3389 ;; Regexp for finding (possibly embedded) -t switches.
3390 (switch-regexp "\\(\\`\\| \\)-\\([a-su-zA-Z]*\\)\\(t\\)\\([^ ]*\\)")
3391 case-fold-search)
3392 ;; Remove the -t switch.
3393 (while (string-match switch-regexp dired-actual-switches)
3394 (if (and (equal (match-string 2 dired-actual-switches) "")
3395 (equal (match-string 4 dired-actual-switches) ""))
3396 ;; Remove a stand-alone -t switch.
3397 (setq dired-actual-switches
3398 (replace-match "" t t dired-actual-switches))
3399 ;; Remove a switch of the form -XtY for some X and Y.
3400 (setq dired-actual-switches
3401 (replace-match "" t t dired-actual-switches 3))))
3402 ;; Now, if we weren't sorting by date before, add the -t switch.
3403 (unless sorting-by-date
3404 (setq dired-actual-switches (concat dired-actual-switches " -t"))))
3405 (dired-sort-set-modeline)
3406 (revert-buffer))
3408 ;; Some user code loads dired especially for this.
3409 ;; Don't do that--use replace-regexp-in-string instead.
3410 (defun dired-replace-in-string (regexp newtext string)
3411 ;; Replace REGEXP with NEWTEXT everywhere in STRING and return result.
3412 ;; NEWTEXT is taken literally---no \\DIGIT escapes will be recognized.
3413 (let ((result "") (start 0) mb me)
3414 (while (string-match regexp string start)
3415 (setq mb (match-beginning 0)
3416 me (match-end 0)
3417 result (concat result (substring string start mb) newtext)
3418 start me))
3419 (concat result (substring string start))))
3421 (defun dired-sort-other (switches &optional no-revert)
3422 "Specify new `ls' SWITCHES for current dired buffer.
3423 Values matching `dired-sort-by-date-regexp' or `dired-sort-by-name-regexp'
3424 set the minor mode accordingly, others appear literally in the mode line.
3425 With optional second arg NO-REVERT, don't refresh the listing afterwards."
3426 (dired-sort-R-check switches)
3427 (setq dired-actual-switches switches)
3428 (dired-sort-set-modeline)
3429 (or no-revert (revert-buffer)))
3431 (defvar dired-subdir-alist-pre-R nil
3432 "Value of `dired-subdir-alist' before -R switch added.")
3433 (make-variable-buffer-local 'dired-subdir-alist-pre-R)
3435 (defun dired-sort-R-check (switches)
3436 "Additional processing of -R in ls option string SWITCHES.
3437 Saves `dired-subdir-alist' when R is set and restores saved value
3438 minus any directories explicitly deleted when R is cleared.
3439 To be called first in body of `dired-sort-other', etc."
3440 (cond
3441 ((and (string-match "R" switches)
3442 (not (string-match "R" dired-actual-switches)))
3443 ;; Adding -R to ls switches -- save `dired-subdir-alist':
3444 (setq dired-subdir-alist-pre-R dired-subdir-alist))
3445 ((and (string-match "R" dired-actual-switches)
3446 (not (string-match "R" switches)))
3447 ;; Deleting -R from ls switches -- revert to pre-R subdirs
3448 ;; that are still present:
3449 (setq dired-subdir-alist
3450 (if dired-subdir-alist-pre-R
3451 (let (subdirs)
3452 (while dired-subdir-alist-pre-R
3453 (if (assoc (caar dired-subdir-alist-pre-R)
3454 dired-subdir-alist)
3455 ;; subdir still present...
3456 (setq subdirs
3457 (cons (car dired-subdir-alist-pre-R)
3458 subdirs)))
3459 (setq dired-subdir-alist-pre-R
3460 (cdr dired-subdir-alist-pre-R)))
3461 (reverse subdirs))
3462 ;; No pre-R subdir alist, so revert to main directory
3463 ;; listing:
3464 (list (car (reverse dired-subdir-alist))))))))
3467 ;;;; Drag and drop support
3469 (defcustom dired-recursive-copies 'top
3470 "Decide whether recursive copies are allowed.
3471 A value of nil means no recursive copies.
3472 `always' means copy recursively without asking.
3473 `top' means ask for each directory at top level.
3474 Anything else means ask for each directory."
3475 :type '(choice :tag "Copy directories"
3476 (const :tag "No recursive copies" nil)
3477 (const :tag "Ask for each directory" t)
3478 (const :tag "Ask for each top directory only" top)
3479 (const :tag "Copy directories without asking" always))
3480 :group 'dired)
3482 (defun dired-dnd-popup-notice ()
3483 (message-box
3484 "Dired recursive copies are currently disabled.\nSee the variable `dired-recursive-copies'."))
3486 (declare-function x-popup-menu "menu.c" (position menu))
3488 (defun dired-dnd-do-ask-action (uri)
3489 ;; No need to get actions and descriptions from the source,
3490 ;; we only have three actions anyway.
3491 (let ((action (x-popup-menu
3493 (list "What action?"
3494 (cons ""
3495 '(("Copy here" . copy)
3496 ("Move here" . move)
3497 ("Link here" . link)
3498 "--"
3499 ("Cancel" . nil)))))))
3500 (if action
3501 (dired-dnd-handle-local-file uri action)
3502 nil)))
3504 (declare-function dired-relist-entry "dired-aux" (file))
3505 (declare-function make-symbolic-link "fileio.c")
3507 ;; Only used when (featurep 'dnd).
3508 (declare-function dnd-get-local-file-name "dnd" (uri &optional must-exist))
3509 (declare-function dnd-get-local-file-uri "dnd" (uri))
3511 (defun dired-dnd-handle-local-file (uri action)
3512 "Copy, move or link a file to the dired directory.
3513 URI is the file to handle, ACTION is one of copy, move, link or ask.
3514 Ask means pop up a menu for the user to select one of copy, move or link."
3515 (require 'dired-aux)
3516 (let* ((from (dnd-get-local-file-name uri t))
3517 (to (when from
3518 (concat (dired-current-directory)
3519 (file-name-nondirectory from)))))
3520 (when from
3521 (cond ((eq action 'ask)
3522 (dired-dnd-do-ask-action uri))
3523 ;; If copying a directory and dired-recursive-copies is
3524 ;; nil, dired-copy-file fails. Pop up a notice.
3525 ((and (memq action '(copy private))
3526 (file-directory-p from)
3527 (not dired-recursive-copies))
3528 (dired-dnd-popup-notice))
3529 ((memq action '(copy private move link))
3530 (let ((overwrite (and (file-exists-p to)
3531 (y-or-n-p
3532 (format "Overwrite existing file `%s'? " to))))
3533 ;; Binding dired-overwrite-confirmed to nil makes
3534 ;; dired-handle-overwrite a no-op. We instead use
3535 ;; y-or-n-p, which pops a graphical menu.
3536 dired-overwrite-confirmed backup-file)
3537 (when (and overwrite
3538 ;; d-b-o is defined in dired-aux.
3539 (boundp 'dired-backup-overwrite)
3540 dired-backup-overwrite
3541 (setq backup-file
3542 (car (find-backup-file-name to)))
3543 (or (eq dired-backup-overwrite 'always)
3544 (y-or-n-p
3545 (format
3546 "Make backup for existing file `%s'? " to))))
3547 (rename-file to backup-file 0)
3548 (dired-relist-entry backup-file))
3549 (cond ((memq action '(copy private))
3550 (dired-copy-file from to overwrite))
3551 ((eq action 'move)
3552 (dired-rename-file from to overwrite))
3553 ((eq action 'link)
3554 (make-symbolic-link from to overwrite)))
3555 (dired-relist-entry to)
3556 action))))))
3558 (defun dired-dnd-handle-file (uri action)
3559 "Copy, move or link a file to the dired directory if it is a local file.
3560 URI is the file to handle. If the hostname in the URI isn't local, do nothing.
3561 ACTION is one of copy, move, link or ask.
3562 Ask means pop up a menu for the user to select one of copy, move or link."
3563 (let ((local-file (dnd-get-local-file-uri uri)))
3564 (if local-file (dired-dnd-handle-local-file local-file action)
3565 nil)))
3568 ;;;; Desktop support
3570 (eval-when-compile (require 'desktop))
3572 (defun dired-desktop-buffer-misc-data (desktop-dirname)
3573 "Auxiliary information to be saved in desktop file."
3574 (cons
3575 ;; Value of `dired-directory'.
3576 (if (consp dired-directory)
3577 ;; Directory name followed by list of files.
3578 (cons (desktop-file-name (car dired-directory) desktop-dirname)
3579 (cdr dired-directory))
3580 ;; Directory name, optionally with shell wildcard.
3581 (desktop-file-name dired-directory desktop-dirname))
3582 ;; Subdirectories in `dired-subdir-alist'.
3583 (cdr
3584 (nreverse
3585 (mapcar
3586 (function (lambda (f) (desktop-file-name (car f) desktop-dirname)))
3587 dired-subdir-alist)))))
3589 (defun dired-restore-desktop-buffer (desktop-buffer-file-name
3590 desktop-buffer-name
3591 desktop-buffer-misc)
3592 "Restore a dired buffer specified in a desktop file."
3593 ;; First element of `desktop-buffer-misc' is the value of `dired-directory'.
3594 ;; This value is a directory name, optionally with shell wildcard or
3595 ;; a directory name followed by list of files.
3596 (let* ((dired-dir (car desktop-buffer-misc))
3597 (dir (if (consp dired-dir) (car dired-dir) dired-dir)))
3598 (if (file-directory-p (file-name-directory dir))
3599 (progn
3600 (dired dired-dir)
3601 ;; The following elements of `desktop-buffer-misc' are the keys
3602 ;; from `dired-subdir-alist'.
3603 (mapc 'dired-maybe-insert-subdir (cdr desktop-buffer-misc))
3604 (current-buffer))
3605 (message "Desktop: Directory %s no longer exists." dir)
3606 (when desktop-missing-file-warning (sit-for 1))
3607 nil)))
3609 (add-to-list 'desktop-buffer-mode-handlers
3610 '(dired-mode . dired-restore-desktop-buffer))
3613 ;;; Start of automatically extracted autoloads.
3615 ;;;### (autoloads (dired-show-file-type dired-do-query-replace-regexp
3616 ;;;;;; dired-do-search dired-do-isearch-regexp dired-do-isearch
3617 ;;;;;; dired-isearch-filenames-regexp dired-isearch-filenames dired-isearch-filenames-setup
3618 ;;;;;; dired-hide-all dired-hide-subdir dired-tree-down dired-tree-up
3619 ;;;;;; dired-kill-subdir dired-mark-subdir-files dired-goto-subdir
3620 ;;;;;; dired-prev-subdir dired-insert-subdir dired-maybe-insert-subdir
3621 ;;;;;; dired-downcase dired-upcase dired-do-symlink-regexp dired-do-hardlink-regexp
3622 ;;;;;; dired-do-copy-regexp dired-do-rename-regexp dired-do-rename
3623 ;;;;;; dired-do-hardlink dired-do-symlink dired-do-copy dired-create-directory
3624 ;;;;;; dired-rename-file dired-copy-file dired-relist-file dired-remove-file
3625 ;;;;;; dired-add-file dired-do-redisplay dired-do-load dired-do-byte-compile
3626 ;;;;;; dired-do-compress dired-query dired-compress-file dired-do-kill-lines
3627 ;;;;;; dired-run-shell-command dired-do-shell-command dired-do-async-shell-command
3628 ;;;;;; dired-clean-directory dired-do-print dired-do-touch dired-do-chown
3629 ;;;;;; dired-do-chgrp dired-do-chmod dired-compare-directories dired-backup-diff
3630 ;;;;;; dired-diff) "dired-aux" "dired-aux.el" "154cdfbf451aedec60c5012b625ff329")
3631 ;;; Generated autoloads from dired-aux.el
3633 (autoload 'dired-diff "dired-aux" "\
3634 Compare file at point with file FILE using `diff'.
3635 FILE defaults to the file at the mark. (That's the mark set by
3636 \\[set-mark-command], not by Dired's \\[dired-mark] command.)
3637 The prompted-for file is the first file given to `diff'.
3638 With prefix arg, prompt for second argument SWITCHES,
3639 which is options for `diff'.
3641 \(fn FILE &optional SWITCHES)" t nil)
3643 (autoload 'dired-backup-diff "dired-aux" "\
3644 Diff this file with its backup file or vice versa.
3645 Uses the latest backup, if there are several numerical backups.
3646 If this file is a backup, diff it with its original.
3647 The backup file is the first file given to `diff'.
3648 With prefix arg, prompt for argument SWITCHES which is options for `diff'.
3650 \(fn &optional SWITCHES)" t nil)
3652 (autoload 'dired-compare-directories "dired-aux" "\
3653 Mark files with different file attributes in two dired buffers.
3654 Compare file attributes of files in the current directory
3655 with file attributes in directory DIR2 using PREDICATE on pairs of files
3656 with the same name. Mark files for which PREDICATE returns non-nil.
3657 Mark files with different names if PREDICATE is nil (or interactively
3658 with empty input at the predicate prompt).
3660 PREDICATE is a Lisp expression that can refer to the following variables:
3662 size1, size2 - file size in bytes
3663 mtime1, mtime2 - last modification time in seconds, as a float
3664 fa1, fa2 - list of file attributes
3665 returned by function `file-attributes'
3667 where 1 refers to attribute of file in the current dired buffer
3668 and 2 to attribute of file in second dired buffer.
3670 Examples of PREDICATE:
3672 (> mtime1 mtime2) - mark newer files
3673 (not (= size1 size2)) - mark files with different sizes
3674 (not (string= (nth 8 fa1) (nth 8 fa2))) - mark files with different modes
3675 (not (and (= (nth 2 fa1) (nth 2 fa2)) - mark files with different UID
3676 (= (nth 3 fa1) (nth 3 fa2)))) and GID.
3678 \(fn DIR2 PREDICATE)" t nil)
3680 (autoload 'dired-do-chmod "dired-aux" "\
3681 Change the mode of the marked (or next ARG) files.
3682 Symbolic modes like `g+w' are allowed.
3684 \(fn &optional ARG)" t nil)
3686 (autoload 'dired-do-chgrp "dired-aux" "\
3687 Change the group of the marked (or next ARG) files.
3689 \(fn &optional ARG)" t nil)
3691 (autoload 'dired-do-chown "dired-aux" "\
3692 Change the owner of the marked (or next ARG) files.
3694 \(fn &optional ARG)" t nil)
3696 (autoload 'dired-do-touch "dired-aux" "\
3697 Change the timestamp of the marked (or next ARG) files.
3698 This calls touch.
3700 \(fn &optional ARG)" t nil)
3702 (autoload 'dired-do-print "dired-aux" "\
3703 Print the marked (or next ARG) files.
3704 Uses the shell command coming from variables `lpr-command' and
3705 `lpr-switches' as default.
3707 \(fn &optional ARG)" t nil)
3709 (autoload 'dired-clean-directory "dired-aux" "\
3710 Flag numerical backups for deletion.
3711 Spares `dired-kept-versions' latest versions, and `kept-old-versions' oldest.
3712 Positive prefix arg KEEP overrides `dired-kept-versions';
3713 Negative prefix arg KEEP overrides `kept-old-versions' with KEEP made positive.
3715 To clear the flags on these files, you can use \\[dired-flag-backup-files]
3716 with a prefix argument.
3718 \(fn KEEP)" t nil)
3720 (autoload 'dired-do-async-shell-command "dired-aux" "\
3721 Run a shell command COMMAND on the marked files asynchronously.
3723 Like `dired-do-shell-command' but if COMMAND doesn't end in ampersand,
3724 adds `* &' surrounded by whitespace and executes the command asynchronously.
3725 The output appears in the buffer `*Async Shell Command*'.
3727 \(fn COMMAND &optional ARG FILE-LIST)" t nil)
3729 (autoload 'dired-do-shell-command "dired-aux" "\
3730 Run a shell command COMMAND on the marked files.
3731 If no files are marked or a specific numeric prefix arg is given,
3732 the next ARG files are used. Just \\[universal-argument] means the current file.
3733 The prompt mentions the file(s) or the marker, as appropriate.
3735 If there is a `*' in COMMAND, surrounded by whitespace, this runs
3736 COMMAND just once with the entire file list substituted there.
3738 If there is no `*', but there is a `?' in COMMAND, surrounded by
3739 whitespace, this runs COMMAND on each file individually with the
3740 file name substituted for `?'.
3742 Otherwise, this runs COMMAND on each file individually with the
3743 file name added at the end of COMMAND (separated by a space).
3745 `*' and `?' when not surrounded by whitespace have no special
3746 significance for `dired-do-shell-command', and are passed through
3747 normally to the shell, but you must confirm first. To pass `*' by
3748 itself to the shell as a wildcard, type `*\"\"'.
3750 If COMMAND produces output, it goes to a separate buffer.
3752 This feature does not try to redisplay Dired buffers afterward, as
3753 there's no telling what files COMMAND may have changed.
3754 Type \\[dired-do-redisplay] to redisplay the marked files.
3756 When COMMAND runs, its working directory is the top-level directory
3757 of the Dired buffer, so output files usually are created there
3758 instead of in a subdir.
3760 In a noninteractive call (from Lisp code), you must specify
3761 the list of file names explicitly with the FILE-LIST argument, which
3762 can be produced by `dired-get-marked-files', for example.
3764 \(fn COMMAND &optional ARG FILE-LIST)" t nil)
3766 (autoload 'dired-run-shell-command "dired-aux" "\
3767 Not documented
3769 \(fn COMMAND)" nil nil)
3771 (autoload 'dired-do-kill-lines "dired-aux" "\
3772 Kill all marked lines (not the files).
3773 With a prefix argument, kill that many lines starting with the current line.
3774 \(A negative argument kills backward.)
3775 If you use this command with a prefix argument to kill the line
3776 for a file that is a directory, which you have inserted in the
3777 Dired buffer as a subdirectory, then it deletes that subdirectory
3778 from the buffer as well.
3779 To kill an entire subdirectory (without killing its line in the
3780 parent directory), go to its directory header line and use this
3781 command with a prefix argument (the value does not matter).
3783 \(fn &optional ARG FMT)" t nil)
3785 (autoload 'dired-compress-file "dired-aux" "\
3786 Not documented
3788 \(fn FILE)" nil nil)
3790 (autoload 'dired-query "dired-aux" "\
3791 Format PROMPT with ARGS, query user, and store the result in SYM.
3792 The return value is either nil or t.
3794 The user may type y or SPC to accept once; n or DEL to skip once;
3795 ! to accept this and subsequent queries; or q or ESC to decline
3796 this and subsequent queries.
3798 If SYM is already bound to a non-nil value, this function may
3799 return automatically without querying the user. If SYM is !,
3800 return t; if SYM is q or ESC, return nil.
3802 \(fn SYM PROMPT &rest ARGS)" nil nil)
3804 (autoload 'dired-do-compress "dired-aux" "\
3805 Compress or uncompress marked (or next ARG) files.
3807 \(fn &optional ARG)" t nil)
3809 (autoload 'dired-do-byte-compile "dired-aux" "\
3810 Byte compile marked (or next ARG) Emacs Lisp files.
3812 \(fn &optional ARG)" t nil)
3814 (autoload 'dired-do-load "dired-aux" "\
3815 Load the marked (or next ARG) Emacs Lisp files.
3817 \(fn &optional ARG)" t nil)
3819 (autoload 'dired-do-redisplay "dired-aux" "\
3820 Redisplay all marked (or next ARG) files.
3821 If on a subdir line, redisplay that subdirectory. In that case,
3822 a prefix arg lets you edit the `ls' switches used for the new listing.
3824 Dired remembers switches specified with a prefix arg, so that reverting
3825 the buffer will not reset them. However, using `dired-undo' to re-insert
3826 or delete subdirectories can bypass this machinery. Hence, you sometimes
3827 may have to reset some subdirectory switches after a `dired-undo'.
3828 You can reset all subdirectory switches to the default using
3829 \\<dired-mode-map>\\[dired-reset-subdir-switches].
3830 See Info node `(emacs)Subdir switches' for more details.
3832 \(fn &optional ARG TEST-FOR-SUBDIR)" t nil)
3834 (autoload 'dired-add-file "dired-aux" "\
3835 Not documented
3837 \(fn FILENAME &optional MARKER-CHAR)" nil nil)
3839 (autoload 'dired-remove-file "dired-aux" "\
3840 Not documented
3842 \(fn FILE)" nil nil)
3844 (autoload 'dired-relist-file "dired-aux" "\
3845 Create or update the line for FILE in all Dired buffers it would belong in.
3847 \(fn FILE)" nil nil)
3849 (autoload 'dired-copy-file "dired-aux" "\
3850 Not documented
3852 \(fn FROM TO OK-FLAG)" nil nil)
3854 (autoload 'dired-rename-file "dired-aux" "\
3855 Not documented
3857 \(fn FILE NEWNAME OK-IF-ALREADY-EXISTS)" nil nil)
3859 (autoload 'dired-create-directory "dired-aux" "\
3860 Create a directory called DIRECTORY.
3862 \(fn DIRECTORY)" t nil)
3864 (autoload 'dired-do-copy "dired-aux" "\
3865 Copy all marked (or next ARG) files, or copy the current file.
3866 This normally preserves the last-modified date when copying.
3867 When operating on just the current file, you specify the new name.
3868 When operating on multiple or marked files, you specify a directory,
3869 and new copies of these files are made in that directory
3870 with the same names that the files currently have. The default
3871 suggested for the target directory depends on the value of
3872 `dired-dwim-target', which see.
3874 This command copies symbolic links by creating new ones,
3875 like `cp -d'.
3877 \(fn &optional ARG)" t nil)
3879 (autoload 'dired-do-symlink "dired-aux" "\
3880 Make symbolic links to current file or all marked (or next ARG) files.
3881 When operating on just the current file, you specify the new name.
3882 When operating on multiple or marked files, you specify a directory
3883 and new symbolic links are made in that directory
3884 with the same names that the files currently have. The default
3885 suggested for the target directory depends on the value of
3886 `dired-dwim-target', which see.
3888 For relative symlinks, use \\[dired-do-relsymlink].
3890 \(fn &optional ARG)" t nil)
3892 (autoload 'dired-do-hardlink "dired-aux" "\
3893 Add names (hard links) current file or all marked (or next ARG) files.
3894 When operating on just the current file, you specify the new name.
3895 When operating on multiple or marked files, you specify a directory
3896 and new hard links are made in that directory
3897 with the same names that the files currently have. The default
3898 suggested for the target directory depends on the value of
3899 `dired-dwim-target', which see.
3901 \(fn &optional ARG)" t nil)
3903 (autoload 'dired-do-rename "dired-aux" "\
3904 Rename current file or all marked (or next ARG) files.
3905 When renaming just the current file, you specify the new name.
3906 When renaming multiple or marked files, you specify a directory.
3907 This command also renames any buffers that are visiting the files.
3908 The default suggested for the target directory depends on the value
3909 of `dired-dwim-target', which see.
3911 \(fn &optional ARG)" t nil)
3913 (autoload 'dired-do-rename-regexp "dired-aux" "\
3914 Rename selected files whose names match REGEXP to NEWNAME.
3916 With non-zero prefix argument ARG, the command operates on the next ARG
3917 files. Otherwise, it operates on all the marked files, or the current
3918 file if none are marked.
3920 As each match is found, the user must type a character saying
3921 what to do with it. For directions, type \\[help-command] at that time.
3922 NEWNAME may contain \\=\\<n> or \\& as in `query-replace-regexp'.
3923 REGEXP defaults to the last regexp used.
3925 With a zero prefix arg, renaming by regexp affects the absolute file name.
3926 Normally, only the non-directory part of the file name is used and changed.
3928 \(fn REGEXP NEWNAME &optional ARG WHOLE-NAME)" t nil)
3930 (autoload 'dired-do-copy-regexp "dired-aux" "\
3931 Copy selected files whose names match REGEXP to NEWNAME.
3932 See function `dired-do-rename-regexp' for more info.
3934 \(fn REGEXP NEWNAME &optional ARG WHOLE-NAME)" t nil)
3936 (autoload 'dired-do-hardlink-regexp "dired-aux" "\
3937 Hardlink selected files whose names match REGEXP to NEWNAME.
3938 See function `dired-do-rename-regexp' for more info.
3940 \(fn REGEXP NEWNAME &optional ARG WHOLE-NAME)" t nil)
3942 (autoload 'dired-do-symlink-regexp "dired-aux" "\
3943 Symlink selected files whose names match REGEXP to NEWNAME.
3944 See function `dired-do-rename-regexp' for more info.
3946 \(fn REGEXP NEWNAME &optional ARG WHOLE-NAME)" t nil)
3948 (autoload 'dired-upcase "dired-aux" "\
3949 Rename all marked (or next ARG) files to upper case.
3951 \(fn &optional ARG)" t nil)
3953 (autoload 'dired-downcase "dired-aux" "\
3954 Rename all marked (or next ARG) files to lower case.
3956 \(fn &optional ARG)" t nil)
3958 (autoload 'dired-maybe-insert-subdir "dired-aux" "\
3959 Insert this subdirectory into the same dired buffer.
3960 If it is already present, just move to it (type \\[dired-do-redisplay] to refresh),
3961 else inserts it at its natural place (as `ls -lR' would have done).
3962 With a prefix arg, you may edit the ls switches used for this listing.
3963 You can add `R' to the switches to expand the whole tree starting at
3964 this subdirectory.
3965 This function takes some pains to conform to `ls -lR' output.
3967 Dired remembers switches specified with a prefix arg, so that reverting
3968 the buffer will not reset them. However, using `dired-undo' to re-insert
3969 or delete subdirectories can bypass this machinery. Hence, you sometimes
3970 may have to reset some subdirectory switches after a `dired-undo'.
3971 You can reset all subdirectory switches to the default using
3972 \\<dired-mode-map>\\[dired-reset-subdir-switches].
3973 See Info node `(emacs)Subdir switches' for more details.
3975 \(fn DIRNAME &optional SWITCHES NO-ERROR-IF-NOT-DIR-P)" t nil)
3977 (autoload 'dired-insert-subdir "dired-aux" "\
3978 Insert this subdirectory into the same dired buffer.
3979 If it is already present, overwrites previous entry,
3980 else inserts it at its natural place (as `ls -lR' would have done).
3981 With a prefix arg, you may edit the `ls' switches used for this listing.
3982 You can add `R' to the switches to expand the whole tree starting at
3983 this subdirectory.
3984 This function takes some pains to conform to `ls -lR' output.
3986 \(fn DIRNAME &optional SWITCHES NO-ERROR-IF-NOT-DIR-P)" t nil)
3988 (autoload 'dired-prev-subdir "dired-aux" "\
3989 Go to previous subdirectory, regardless of level.
3990 When called interactively and not on a subdir line, go to this subdir's line.
3992 \(fn ARG &optional NO-ERROR-IF-NOT-FOUND NO-SKIP)" t nil)
3994 (autoload 'dired-goto-subdir "dired-aux" "\
3995 Go to end of header line of DIR in this dired buffer.
3996 Return value of point on success, otherwise return nil.
3997 The next char is either \\n, or \\r if DIR is hidden.
3999 \(fn DIR)" t nil)
4001 (autoload 'dired-mark-subdir-files "dired-aux" "\
4002 Mark all files except `.' and `..' in current subdirectory.
4003 If the Dired buffer shows multiple directories, this command
4004 marks the files listed in the subdirectory that point is in.
4006 \(fn)" t nil)
4008 (autoload 'dired-kill-subdir "dired-aux" "\
4009 Remove all lines of current subdirectory.
4010 Lower levels are unaffected.
4012 \(fn &optional REMEMBER-MARKS)" t nil)
4014 (autoload 'dired-tree-up "dired-aux" "\
4015 Go up ARG levels in the dired tree.
4017 \(fn ARG)" t nil)
4019 (autoload 'dired-tree-down "dired-aux" "\
4020 Go down in the dired tree.
4022 \(fn)" t nil)
4024 (autoload 'dired-hide-subdir "dired-aux" "\
4025 Hide or unhide the current subdirectory and move to next directory.
4026 Optional prefix arg is a repeat factor.
4027 Use \\[dired-hide-all] to (un)hide all directories.
4029 \(fn ARG)" t nil)
4031 (autoload 'dired-hide-all "dired-aux" "\
4032 Hide all subdirectories, leaving only their header lines.
4033 If there is already something hidden, make everything visible again.
4034 Use \\[dired-hide-subdir] to (un)hide a particular subdirectory.
4036 \(fn &optional IGNORED)" t nil)
4038 (autoload 'dired-isearch-filenames-setup "dired-aux" "\
4039 Set up isearch to search in Dired file names.
4040 Intended to be added to `isearch-mode-hook'.
4042 \(fn)" nil nil)
4044 (autoload 'dired-isearch-filenames "dired-aux" "\
4045 Search for a string using Isearch only in file names in the Dired buffer.
4047 \(fn)" t nil)
4049 (autoload 'dired-isearch-filenames-regexp "dired-aux" "\
4050 Search for a regexp using Isearch only in file names in the Dired buffer.
4052 \(fn)" t nil)
4054 (autoload 'dired-do-isearch "dired-aux" "\
4055 Search for a string through all marked files using Isearch.
4057 \(fn)" t nil)
4059 (autoload 'dired-do-isearch-regexp "dired-aux" "\
4060 Search for a regexp through all marked files using Isearch.
4062 \(fn)" t nil)
4064 (autoload 'dired-do-search "dired-aux" "\
4065 Search through all marked files for a match for REGEXP.
4066 Stops when a match is found.
4067 To continue searching for next match, use command \\[tags-loop-continue].
4069 \(fn REGEXP)" t nil)
4071 (autoload 'dired-do-query-replace-regexp "dired-aux" "\
4072 Do `query-replace-regexp' of FROM with TO, on all marked files.
4073 Third arg DELIMITED (prefix arg) means replace only word-delimited matches.
4074 If you exit (\\[keyboard-quit], RET or q), you can resume the query replace
4075 with the command \\[tags-loop-continue].
4077 \(fn FROM TO &optional DELIMITED)" t nil)
4079 (autoload 'dired-show-file-type "dired-aux" "\
4080 Print the type of FILE, according to the `file' command.
4081 If FILE is a symbolic link and the optional argument DEREF-SYMLINKS is
4082 true then the type of the file linked to by FILE is printed instead.
4084 \(fn FILE &optional DEREF-SYMLINKS)" t nil)
4086 ;;;***
4088 ;;;### (autoloads (dired-do-relsymlink dired-jump-other-window dired-jump)
4089 ;;;;;; "dired-x" "dired-x.el" "87fd4ae2fdade7e0f11c4a0b1cfdeda2")
4090 ;;; Generated autoloads from dired-x.el
4092 (autoload 'dired-jump "dired-x" "\
4093 Jump to dired buffer corresponding to current buffer.
4094 If in a file, dired the current directory and move to file's line.
4095 If in Dired already, pop up a level and goto old directory's line.
4096 In case the proper dired file line cannot be found, refresh the dired
4097 buffer and try again.
4098 When OTHER-WINDOW is non-nil, jump to dired buffer in other window.
4099 Interactively with prefix argument, read FILE-NAME and
4100 move to its line in dired.
4102 \(fn &optional OTHER-WINDOW FILE-NAME)" t nil)
4104 (autoload 'dired-jump-other-window "dired-x" "\
4105 Like \\[dired-jump] (`dired-jump') but in other window.
4107 \(fn &optional FILE-NAME)" t nil)
4109 (autoload 'dired-do-relsymlink "dired-x" "\
4110 Relative symlink all marked (or next ARG) files into a directory.
4111 Otherwise make a relative symbolic link to the current file.
4112 This creates relative symbolic links like
4114 foo -> ../bar/foo
4116 not absolute ones like
4118 foo -> /ugly/file/name/that/may/change/any/day/bar/foo
4120 For absolute symlinks, use \\[dired-do-symlink].
4122 \(fn &optional ARG)" t nil)
4124 ;;;***
4126 ;;; End of automatically extracted autoloads.
4128 (provide 'dired)
4130 (run-hooks 'dired-load-hook) ; for your customizations
4132 ;;; dired.el ends here