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