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