1 ;;; dired.el --- directory-browsing commands -*- lexical-binding: t -*-
3 ;; Copyright (C) 1985-1986, 1992-1997, 2000-2013 Free Software
6 ;; Author: Sebastian Kremer <sk@thp.uni-koeln.de>
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/>.
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.
37 (declare-function dired-buffer-more-recently-used-p
38 "dired-x" (buffer1 buffer2
))
40 ;;; Customizable variables
44 :link
'(custom-manual "(emacs)Dired")
47 (defgroup dired-mark nil
48 "Handling marks in Dired."
54 (defcustom dired-listing-switches
(purecopy "-al")
55 "Switches passed to `ls' for Dired. MUST contain the `l' option.
56 May contain all other options that don't contradict `-l';
57 may contain even `F', `b', `i' and `s'. See also the variable
58 `dired-ls-F-marks-symlinks' concerning the `F' switch.
59 On systems such as MS-DOS and MS-Windows, which use `ls' emulation in Lisp,
60 some of the `ls' switches are not supported; see the doc string of
61 `insert-directory' in `ls-lisp.el' for more details."
65 (defcustom dired-subdir-switches nil
66 "If non-nil, switches passed to `ls' for inserting subdirectories.
67 If nil, `dired-listing-switches' is used."
69 :type
'(choice (const :tag
"Use dired-listing-switches" nil
)
70 (string :tag
"Switches")))
72 (defcustom dired-chown-program
73 (purecopy (cond ((executable-find "chown") "chown")
74 ((file-executable-p "/usr/sbin/chown") "/usr/sbin/chown")
75 ((file-executable-p "/etc/chown") "/etc/chown")
77 "Name of chown command (usually `chown')."
81 (defcustom dired-use-ls-dired
'unspecified
82 "Non-nil means Dired should pass the \"--dired\" option to \"ls\".
83 The special value of `unspecified' means to check explicitly, and
84 save the result in this variable. This is performed the first
85 time `dired-insert-directory' is called.
87 Note that if you set this option to nil, either through choice or
88 because your \"ls\" program does not support \"--dired\", Dired
89 will fail to parse some \"unusual\" file names, e.g. those with leading
90 spaces. You might want to install ls from GNU Coreutils, which does
91 support this option. Alternatively, you might want to use Emacs's
92 own emulation of \"ls\", by using:
93 (setq ls-lisp-use-insert-directory-program nil)
95 This is used by default on MS Windows, which does not have an \"ls\" program.
96 Note that `ls-lisp' does not support as many options as GNU ls, though.
97 For more details, see Info node `(emacs)ls in Lisp'."
99 :type
'(choice (const :tag
"Check for --dired support" unspecified
)
100 (const :tag
"Do not use --dired" nil
)
101 (other :tag
"Use --dired" t
)))
103 (defcustom dired-chmod-program
"chmod"
104 "Name of chmod command (usually `chmod')."
108 (defcustom dired-touch-program
"touch"
109 "Name of touch command (usually `touch')."
113 (defcustom dired-ls-F-marks-symlinks nil
114 "Informs Dired about how `ls -lF' marks symbolic links.
115 Set this to t if `ls' (or whatever program is specified by
116 `insert-directory-program') with `-lF' marks the symbolic link
117 itself with a trailing @ (usually the case under Ultrix).
119 Example: if `ln -s foo bar; ls -F bar' gives `bar -> foo', set it to
120 nil (the default), if it gives `bar@ -> foo', set it to t.
122 Dired checks if there is really a @ appended. Thus, if you have a
123 marking `ls' program on one host and a non-marking on another host, and
124 don't care about symbolic links which really end in a @, you can
125 always set this variable to t."
129 (defcustom dired-trivial-filenames
(purecopy "^\\.\\.?$\\|^#")
130 "Regexp of files to skip when finding first file of a directory.
131 A value of nil means move to the subdir line.
132 A value of t means move to first file."
133 :type
'(choice (const :tag
"Move to subdir" nil
)
134 (const :tag
"Move to first" t
)
138 (defcustom dired-keep-marker-rename t
139 ;; Use t as default so that moved files "take their markers with them".
140 "Controls marking of renamed files.
141 If t, files keep their previous marks when they are renamed.
142 If a character, renamed files (whether previously marked or not)
143 are afterward marked with that character.
144 This option affects only files renamed by `dired-do-rename' and
145 `dired-do-rename-regexp'. See `wdired-keep-marker-rename'
146 if you want to do the same for files renamed in WDired mode."
147 :type
'(choice (const :tag
"Keep" t
)
148 (character :tag
"Mark" :value ?R
))
151 (defcustom dired-keep-marker-copy ?C
152 "Controls marking of copied files.
153 If t, copied files are marked if and as the corresponding original files were.
154 If a character, copied files are unconditionally marked with that character."
155 :type
'(choice (const :tag
"Keep" t
)
156 (character :tag
"Mark"))
159 (defcustom dired-keep-marker-hardlink ?H
160 "Controls marking of newly made hard links.
161 If t, they are marked if and as the files linked to were marked.
162 If a character, new links are unconditionally marked with that character."
163 :type
'(choice (const :tag
"Keep" t
)
164 (character :tag
"Mark"))
167 (defcustom dired-keep-marker-symlink ?Y
168 "Controls marking of newly made symbolic links.
169 If t, they are marked if and as the files linked to were marked.
170 If a character, new links are unconditionally marked with that character."
171 :type
'(choice (const :tag
"Keep" t
)
172 (character :tag
"Mark"))
175 (defcustom dired-dwim-target nil
176 "If non-nil, Dired tries to guess a default target directory.
177 This means: if there is a Dired buffer displayed in the next
178 window, use its current directory, instead of this Dired buffer's
181 The target is used in the prompt for file copy, rename etc."
185 (defcustom dired-copy-preserve-time t
186 "If non-nil, Dired preserves the last-modified time in a file copy.
187 \(This works on only some systems.)"
191 ; These variables were deleted and the replacements are on files.el.
192 ; We leave aliases behind for back-compatibility.
193 (defvaralias 'dired-free-space-program
'directory-free-space-program
)
194 (defvaralias 'dired-free-space-args
'directory-free-space-args
)
198 (defcustom dired-load-hook nil
199 "Run after loading Dired.
200 You can customize key bindings or load extensions with this."
204 (defcustom dired-mode-hook nil
205 "Run at the very end of `dired-mode'."
209 (defcustom dired-before-readin-hook nil
210 "This hook is run before a Dired buffer is read in (created or reverted)."
214 (defcustom dired-after-readin-hook nil
215 "Hook run after each time a file or directory is read by Dired.
216 After each listing of a file or directory, this hook is run
217 with the buffer narrowed to the listing."
220 ;; Note this can't simply be run inside function `dired-ls' as the hook
221 ;; functions probably depend on the dired-subdir-alist to be OK.
223 (defcustom dired-initial-point-hook nil
224 "This hook is used to position the point.
225 It is run the function `dired-initial-position'."
230 (defcustom dired-dnd-protocol-alist
231 '(("^file:///" . dired-dnd-handle-local-file
)
232 ("^file://" . dired-dnd-handle-file
)
233 ("^file:" . dired-dnd-handle-local-file
))
234 "The functions to call when a drop in `dired-mode' is made.
235 See `dnd-protocol-alist' for more information. When nil, behave
236 as in other buffers. Changing this option is effective only for
238 :type
'(choice (repeat (cons (regexp) (function)))
239 (const :tag
"Behave as in other buffers" nil
))
243 (defcustom dired-hide-details-hide-symlink-targets t
244 "If non-nil, `dired-hide-details-mode' hides symbolic link targets."
249 (defcustom dired-hide-details-hide-information-lines t
250 "Non-nil means hide lines other than header and file/dir lines."
255 ;; Internal variables
257 (defvar dired-marker-char ?
* ; the answer is 42
258 ;; so that you can write things like
259 ;; (let ((dired-marker-char ?X))
260 ;; ;; great code using X markers ...
262 ;; For example, commands operating on two sets of files, A and B.
263 ;; Or marking files with digits 0-9. This could implicate
264 ;; concentric sets or an order for the marked files.
265 ;; The code depends on dynamic scoping on the marker char.
266 "In Dired, the current mark character.
267 This is what the do-commands look for, and what the mark-commands store.")
269 (defvar dired-del-marker ?D
270 "Character used to flag files for deletion.")
272 (defvar dired-shrink-to-fit t
273 ;; I see no reason ever to make this nil -- rms.
274 ;; (> baud-rate search-slow-speed)
275 "Non-nil means Dired shrinks the display buffer to fit the marked files.")
276 (make-obsolete-variable 'dired-shrink-to-fit
277 "use the Customization interface to add a new rule
278 to `display-buffer-alist' where condition regexp is \"^ \\*Marked Files\\*$\",
279 action argument symbol is `window-height' and its value is nil." "24.3")
281 (defvar dired-file-version-alist
)
284 (defvar dired-directory nil
285 "The directory name or wildcard spec that this Dired directory lists.
286 Local to each Dired buffer. May be a list, in which case the car is the
287 directory name and the cdr is the list of files to mention.
288 The directory name must be absolute, but need not be fully expanded.")
290 ;; Beware of "-l;reboot" etc. See bug#3230.
291 (defun dired-safe-switches-p (switches)
292 "Return non-nil if string SWITCHES does not look risky for Dired."
294 (and (stringp switches
)
295 (< (length switches
) 100) ; arbitrary
296 (string-match-p "\\` *-[- [:alnum:]]+\\'" switches
))))
298 (defvar dired-actual-switches nil
299 "The value of `dired-listing-switches' used to make this buffer's text.")
301 (put 'dired-actual-switches
'safe-local-variable
'dired-safe-switches-p
)
303 (defvar dired-re-inode-size
"[0-9 \t]*"
304 "Regexp for optional initial inode and file size as made by `ls -i -s'.")
306 ;; These regexps must be tested at beginning-of-line, but are also
307 ;; used to search for next matches, so neither omitting "^" nor
308 ;; replacing "^" by "\n" (to make it slightly faster) will work.
310 (defvar dired-re-mark
"^[^ \n]")
311 ;; "Regexp matching a marked line.
312 ;; Important: the match ends just after the marker."
313 (defvar dired-re-maybe-mark
"^. ")
314 ;; The [^:] part after "d" and "l" is to avoid confusion with the
315 ;; DOS/Windows-style drive letters in directory names, like in "d:/foo".
316 (defvar dired-re-dir
(concat dired-re-maybe-mark dired-re-inode-size
"d[^:]"))
317 (defvar dired-re-sym
(concat dired-re-maybe-mark dired-re-inode-size
"l[^:]"))
318 (defvar dired-re-exe
;; match ls permission string of an executable file
321 (concat dired-re-maybe-mark dired-re-inode-size x
)))
322 '("-[-r][-w][xs][-r][-w].[-r][-w]."
323 "-[-r][-w].[-r][-w][xs][-r][-w]."
324 "-[-r][-w].[-r][-w].[-r][-w][xst]")
326 (defvar dired-re-perms
"[-bcdlps][-r][-w].[-r][-w].[-r][-w].")
327 (defvar dired-re-dot
"^.* \\.\\.?/?$")
329 ;; The subdirectory names in the next two lists are expanded.
330 (defvar dired-subdir-alist nil
331 "Association list of subdirectories and their buffer positions.
332 Each subdirectory has an element: (DIRNAME . STARTMARKER).
333 The order of elements is the reverse of the order in the buffer.
334 In simple cases, this list contains one element.")
336 (defvar-local dired-switches-alist nil
337 "Keeps track of which switches to use for inserted subdirectories.
338 This is an alist of the form (SUBDIR . SWITCHES).")
340 (defvaralias 'dired-move-to-filename-regexp
341 'directory-listing-before-filename-regexp
)
343 (defvar dired-subdir-regexp
"^. \\([^\n\r]+\\)\\(:\\)[\n\r]"
344 "Regexp matching a maybe hidden subdirectory line in `ls -lR' output.
345 Subexpression 1 is the subdirectory proper, no trailing colon.
346 The match starts at the beginning of the line and ends after the end
347 of the line (\\n or \\r).
348 Subexpression 2 must end right before the \\n or \\r.")
350 (defgroup dired-faces nil
351 "Faces used by Dired."
355 (defface dired-header
356 '((t (:inherit font-lock-type-face
)))
357 "Face used for directory headers."
360 (defvar dired-header-face
'dired-header
361 "Face name used for directory headers.")
364 '((t (:inherit font-lock-constant-face
)))
365 "Face used for Dired marks."
368 (defvar dired-mark-face
'dired-mark
369 "Face name used for Dired marks.")
371 (defface dired-marked
372 '((t (:inherit warning
)))
373 "Face used for marked files."
376 (defvar dired-marked-face
'dired-marked
377 "Face name used for marked files.")
379 (defface dired-flagged
380 '((t (:inherit error
)))
381 "Face used for files flagged for deletion."
384 (defvar dired-flagged-face
'dired-flagged
385 "Face name used for files flagged for deletion.")
387 (defface dired-warning
388 ;; Inherit from font-lock-warning-face since with min-colors 8
389 ;; font-lock-comment-face is not colored any more.
390 '((t (:inherit font-lock-warning-face
)))
391 "Face used to highlight a part of a buffer that needs user attention."
394 (defvar dired-warning-face
'dired-warning
395 "Face name used for a part of a buffer that needs user attention.")
397 (defface dired-perm-write
398 '((((type w32 pc
)) :inherit default
) ;; These default to rw-rw-rw.
399 ;; Inherit from font-lock-comment-delimiter-face since with min-colors 8
400 ;; font-lock-comment-face is not colored any more.
401 (t (:inherit font-lock-comment-delimiter-face
)))
402 "Face used to highlight permissions of group- and world-writable files."
405 (defvar dired-perm-write-face
'dired-perm-write
406 "Face name used for permissions of group- and world-writable files.")
408 (defface dired-directory
409 '((t (:inherit font-lock-function-name-face
)))
410 "Face used for subdirectories."
413 (defvar dired-directory-face
'dired-directory
414 "Face name used for subdirectories.")
416 (defface dired-symlink
417 '((t (:inherit font-lock-keyword-face
)))
418 "Face used for symbolic links."
421 (defvar dired-symlink-face
'dired-symlink
422 "Face name used for symbolic links.")
424 (defface dired-ignored
425 '((t (:inherit shadow
)))
426 "Face used for files suffixed with `completion-ignored-extensions'."
429 (defvar dired-ignored-face
'dired-ignored
430 "Face name used for files suffixed with `completion-ignored-extensions'.")
432 (defvar dired-font-lock-keywords
436 (list dired-re-mark
'(0 dired-mark-face
))
438 ;; We make heavy use of MATCH-ANCHORED, since the regexps don't identify the
439 ;; file name itself. We search for Dired defined regexps, and then use the
440 ;; Dired defined function `dired-move-to-filename' before searching for the
441 ;; simple regexp ".+". It is that regexp which matches the file name.
444 (list (concat "^[" (char-to-string dired-marker-char
) "]")
445 '(".+" (dired-move-to-filename) nil
(0 dired-marked-face
)))
448 (list (concat "^[" (char-to-string dired-del-marker
) "]")
449 '(".+" (dired-move-to-filename) nil
(0 dired-flagged-face
)))
450 ;; People who are paranoid about security would consider this more
451 ;; important than other things such as whether it is a directory.
452 ;; But we don't want to encourage paranoia, so our default
453 ;; should be what's most useful for non-paranoids. -- rms.
455 ;;; ;; Files that are group or world writable.
456 ;;; (list (concat dired-re-maybe-mark dired-re-inode-size
457 ;;; "\\([-d]\\(....w....\\|.......w.\\)\\)")
458 ;;; '(1 dired-warning-face)
459 ;;; '(".+" (dired-move-to-filename) nil (0 dired-warning-face)))
460 ;; However, we don't need to highlight the file name, only the
461 ;; permissions, to win generally. -- fx.
462 ;; Fixme: we could also put text properties on the permission
463 ;; fields with keymaps to frob the permissions, somewhat a la XEmacs.
464 (list (concat dired-re-maybe-mark dired-re-inode-size
465 "[-d]....\\(w\\)....") ; group writable
466 '(1 dired-perm-write-face
))
467 (list (concat dired-re-maybe-mark dired-re-inode-size
468 "[-d].......\\(w\\).") ; world writable
469 '(1 dired-perm-write-face
))
473 '(".+" (dired-move-to-filename) nil
(0 dired-directory-face
)))
477 '(".+" (dired-move-to-filename) nil
(0 dired-symlink-face
)))
479 ;; Files suffixed with `completion-ignored-extensions'.
481 ;; It is quicker to first find just an extension, then go back to the
482 ;; start of that file name. So we do this complex MATCH-ANCHORED form.
483 (list (concat "\\(" (regexp-opt completion-ignored-extensions
) "\\|#\\)$")
484 '(".+" (dired-move-to-filename) nil
(0 dired-ignored-face
))))
486 ;; Files suffixed with `completion-ignored-extensions'
487 ;; plus a character put in by -F.
489 (list (concat "\\(" (regexp-opt completion-ignored-extensions
)
493 ;; If the last character is not part of the filename,
494 ;; move back to the start of the filename
495 ;; so it can be fontified.
496 ;; Otherwise, leave point at the end of the line;
497 ;; that way, nothing is fontified.
498 (unless (get-text-property (1- (point)) 'mouse-face
)
499 (dired-move-to-filename)))
500 nil
(0 dired-ignored-face
))))
502 ;; Explicitly put the default face on file names ending in a colon to
503 ;; avoid fontifying them as directory header.
504 (list (concat dired-re-maybe-mark dired-re-inode-size dired-re-perms
".*:$")
505 '(".+" (dired-move-to-filename) nil
(0 'default
)))
507 ;; Directory headers.
508 (list dired-subdir-regexp
'(1 dired-header-face
))
510 "Additional expressions to highlight in Dired mode.")
512 (defvar dnd-protocol-alist
)
514 ;;; Macros must be defined before they are used, for the byte compiler.
516 (defmacro dired-mark-if
(predicate msg
)
517 "Mark all files for which PREDICATE evals to non-nil.
518 PREDICATE is evaluated on each line, with point at beginning of line.
519 MSG is a noun phrase for the type of files being marked.
520 It should end with a noun that can be pluralized by adding `s'.
521 Return value is the number of files marked, or nil if none were marked."
522 `(let ((inhibit-read-only t
) count
)
526 (message "%s %ss%s..."
527 (cond ((eq dired-marker-char ?
\040) "Unmarking")
528 ((eq dired-del-marker dired-marker-char
)
532 (if (eq dired-del-marker dired-marker-char
)
535 (goto-char (point-min))
540 (insert dired-marker-char
)
541 (setq count
(1+ count
))))
543 (if ,msg
(message "%s %s%s %s%s."
546 (dired-plural-s count
)
547 (if (eq dired-marker-char ?
\040) "un" "")
548 (if (eq dired-marker-char dired-del-marker
)
549 "flagged" "marked"))))
550 (and (> count
0) count
)))
552 (defmacro dired-map-over-marks
(body arg
&optional show-progress
553 distinguish-one-marked
)
554 "Eval BODY with point on each marked line. Return a list of BODY's results.
555 If no marked file could be found, execute BODY on the current
556 line. ARG, if non-nil, specifies the files to use instead of the
559 If ARG is an integer, use the next ARG (or previous -ARG, if
560 ARG<0) files. In that case, point is dragged along. This is so
561 that commands on the next ARG (instead of the marked) files can
563 For any other non-nil value of ARG, use the current file.
565 If optional third arg SHOW-PROGRESS evaluates to non-nil,
566 redisplay the dired buffer after each file is processed.
568 No guarantee is made about the position on the marked line.
569 BODY must ensure this itself if it depends on this.
571 Search starts at the beginning of the buffer, thus the car of the
572 list corresponds to the line nearest to the buffer's bottom.
573 This is also true for (positive and negative) integer values of
576 BODY should not be too long as it is expanded four times.
578 If DISTINGUISH-ONE-MARKED is non-nil, then if we find just one
579 marked file, return (t FILENAME) instead of (FILENAME)."
581 ;;Warning: BODY must not add new lines before point - this may cause an
583 ;;This warning should not apply any longer, sk 2-Sep-1991 14:10.
585 (let ((inhibit-read-only t
) case-fold-search found results
)
588 (progn ;; no save-excursion, want to move point.
589 (dired-repeat-over-lines
592 (if ,show-progress
(sit-for 0))
593 (setq results
(cons ,body results
)))))
597 ;; non-nil, non-integer ARG means use current file:
599 (let ((regexp (dired-marker-regexp)) next-position
)
601 (goto-char (point-min))
602 ;; remember position of next marked file before BODY
603 ;; can insert lines before the just found file,
604 ;; confusing us by finding the same marked file again
606 (setq next-position
(and (re-search-forward regexp nil t
)
608 found
(not (null next-position
)))
610 (goto-char next-position
)
611 (if ,show-progress
(sit-for 0))
612 (setq results
(cons ,body results
))
613 ;; move after last match
614 (goto-char next-position
)
616 (set-marker next-position nil
)
617 (setq next-position
(and (re-search-forward regexp nil t
)
619 (if (and ,distinguish-one-marked
(= (length results
) 1))
620 (setq results
(cons t results
)))
624 ;; save-excursion loses, again
625 (dired-move-to-filename)))
627 (defun dired-get-marked-files (&optional localp arg filter distinguish-one-marked
)
628 "Return the marked files' names as list of strings.
629 The list is in the same order as the buffer, that is, the car is the
631 Values returned are normally absolute file names.
632 Optional arg LOCALP as in `dired-get-filename'.
633 Optional second argument ARG, if non-nil, specifies files near
634 point instead of marked files. It usually comes from the prefix
636 If ARG is an integer, use the next ARG files.
637 Any other non-nil value means to use the current file instead.
638 Optional third argument FILTER, if non-nil, is a function to select
639 some of the files--those for which (funcall FILTER FILENAME) is non-nil.
641 If DISTINGUISH-ONE-MARKED is non-nil, then if we find just one marked file,
642 return (t FILENAME) instead of (FILENAME).
643 Don't use that together with FILTER."
646 (delq nil
(dired-map-over-marks
647 (dired-get-filename localp
'no-error-if-not-filep
)
648 arg nil distinguish-one-marked
))))
650 (when (equal all-of-them
'(t))
651 (setq all-of-them nil
))
653 (if (and distinguish-one-marked
(eq (car all-of-them
) t
))
655 (nreverse all-of-them
))
656 (dolist (file all-of-them
)
657 (if (funcall filter file
)
663 (defun dired-read-dir-and-switches (str)
664 ;; For use in interactive.
666 (if current-prefix-arg
667 (read-string "Dired listing switches: "
668 dired-listing-switches
))
669 ;; If a dialog is used, call `read-directory-name' so the
670 ;; dialog code knows we want directories. Some dialogs
671 ;; can only select directories or files when popped up,
672 ;; not both. If no dialog is used, call `read-file-name'
673 ;; because the user may want completion of file names for
674 ;; use in a wildcard pattern.
675 (if (next-read-file-uses-dialog-p)
676 (read-directory-name (format "Dired %s(directory): " str
)
677 nil default-directory nil
)
678 (read-file-name (format "Dired %s(directory): " str
)
679 nil default-directory nil
)))))
681 ;; We want to switch to a more sophisticated version of
682 ;; dired-read-dir-and-switches like the following, if there is a way
683 ;; to make it more intuitive. See bug#1285.
685 ;; (defun dired-read-dir-and-switches (str)
686 ;; ;; For use in interactive.
689 ;; (if current-prefix-arg
690 ;; (read-string "Dired listing switches: "
691 ;; dired-listing-switches))
692 ;; ;; If a dialog is about to be used, call read-directory-name so
693 ;; ;; the dialog code knows we want directories. Some dialogs can
694 ;; ;; only select directories or files when popped up, not both.
695 ;; (if (next-read-file-uses-dialog-p)
696 ;; (read-directory-name (format "Dired %s(directory): " str)
697 ;; nil default-directory nil)
699 ;; (dolist (ext completion-ignored-extensions)
700 ;; (if (eq ?/ (aref ext (1- (length ext)))) (push ext cie)))
701 ;; (setq cie (concat (regexp-opt cie "\\(?:") "\\'"))
702 ;; (let* ((default (and buffer-file-name
703 ;; (abbreviate-file-name buffer-file-name)))
706 ;; ;; We need a mix of read-file-name and
707 ;; ;; read-directory-name so that completion to directories
708 ;; ;; is preferred, but if the user wants to enter a global
709 ;; ;; pattern, he can still use completion on filenames to
710 ;; ;; help him write the pattern.
711 ;; ;; Essentially, we want to use
712 ;; ;; (completion-table-with-predicate
713 ;; ;; 'read-file-name-internal 'file-directory-p nil)
714 ;; ;; but that doesn't work because read-file-name-internal
715 ;; ;; does not obey its `predicate' argument.
716 ;; (completion-table-in-turn
717 ;; (lambda (str pred action)
718 ;; (let ((read-file-name-predicate
720 ;; (and (not (member f '("./" "../")))
721 ;; ;; Hack! Faster than file-directory-p!
722 ;; (eq (aref f (1- (length f))) ?/)
723 ;; (not (string-match cie f))))))
724 ;; (complete-with-action
725 ;; action 'read-file-name-internal str nil)))
726 ;; 'read-file-name-internal)))
727 ;; (minibuffer-with-setup-hook
729 ;; (setq minibuffer-default default)
730 ;; (setq minibuffer-completion-table completion-table))
731 ;; (read-file-name (format "Dired %s(directory): " str)
732 ;; nil default-directory nil))))))))
734 (defun dired-file-name-at-point ()
735 "Try to get a file name at point in the current dired buffer.
736 This hook is intended to be put in `file-name-at-point-functions'."
737 (let ((filename (dired-get-filename nil t
)))
739 (if (file-directory-p filename
)
740 (file-name-as-directory (abbreviate-file-name filename
))
741 (abbreviate-file-name filename
)))))
743 ;;;###autoload (define-key ctl-x-map "d" 'dired)
745 (defun dired (dirname &optional switches
)
746 "\"Edit\" directory DIRNAME--delete, rename, print, etc. some files in it.
747 Optional second argument SWITCHES specifies the `ls' options used.
748 \(Interactively, use a prefix argument to be able to specify SWITCHES.)
749 Dired displays a list of files in DIRNAME (which may also have
750 shell wildcards appended to select certain files). If DIRNAME is a cons,
751 its first element is taken as the directory name and the rest as an explicit
752 list of files to make directory entries for.
754 You can flag files for deletion with \\[dired-flag-file-deletion] and then
755 delete them by typing \\[dired-do-flagged-delete].
756 Type \\[describe-mode] after entering Dired for more info.
758 If DIRNAME is already in a Dired buffer, that buffer is used without refresh."
759 ;; Cannot use (interactive "D") because of wildcards.
760 (interactive (dired-read-dir-and-switches ""))
761 (switch-to-buffer (dired-noselect dirname switches
)))
763 ;;;###autoload (define-key ctl-x-4-map "d" 'dired-other-window)
765 (defun dired-other-window (dirname &optional switches
)
766 "\"Edit\" directory DIRNAME. Like `dired' but selects in another window."
767 (interactive (dired-read-dir-and-switches "in other window "))
768 (switch-to-buffer-other-window (dired-noselect dirname switches
)))
770 ;;;###autoload (define-key ctl-x-5-map "d" 'dired-other-frame)
772 (defun dired-other-frame (dirname &optional switches
)
773 "\"Edit\" directory DIRNAME. Like `dired' but makes a new frame."
774 (interactive (dired-read-dir-and-switches "in other frame "))
775 (switch-to-buffer-other-frame (dired-noselect dirname switches
)))
778 (defun dired-noselect (dir-or-list &optional switches
)
779 "Like `dired' but returns the Dired buffer as value, does not select it."
780 (or dir-or-list
(setq dir-or-list default-directory
))
781 ;; This loses the distinction between "/foo/*/" and "/foo/*" that
783 (let (dirname initially-was-dirname
)
784 (if (consp dir-or-list
)
785 (setq dirname
(car dir-or-list
))
786 (setq dirname dir-or-list
))
787 (setq initially-was-dirname
788 (string= (file-name-as-directory dirname
) dirname
))
789 (setq dirname
(abbreviate-file-name
790 (expand-file-name (directory-file-name dirname
))))
791 (if find-file-visit-truename
792 (setq dirname
(file-truename dirname
)))
793 ;; If the argument was syntactically a directory name not a file name,
794 ;; or if it happens to name a file that is a directory,
795 ;; convert it syntactically to a directory name.
796 ;; The reason for checking initially-was-dirname
797 ;; and not just file-directory-p
798 ;; is that file-directory-p is slow over ftp.
799 (if (or initially-was-dirname
(file-directory-p dirname
))
800 (setq dirname
(file-name-as-directory dirname
)))
801 (if (consp dir-or-list
)
802 (setq dir-or-list
(cons dirname
(cdr dir-or-list
)))
803 (setq dir-or-list dirname
))
804 (dired-internal-noselect dir-or-list switches
)))
806 ;; The following is an internal dired function. It returns non-nil if
807 ;; the directory visited by the current dired buffer has changed on
808 ;; disk. DIRNAME should be the directory name of that directory.
809 (defun dired-directory-changed-p (dirname)
810 (not (let ((attributes (file-attributes dirname
))
811 (modtime (visited-file-modtime)))
813 (not (eq (car attributes
) t
))
814 (equal (nth 5 attributes
) modtime
)))))
816 (defun dired-buffer-stale-p (&optional noconfirm
)
817 "Return non-nil if current Dired buffer needs updating.
818 If NOCONFIRM is non-nil, then this function always returns nil
819 for a remote directory. This feature is used by Auto Revert mode."
821 (if (consp dired-directory
) (car dired-directory
) dired-directory
)))
822 (and (stringp dirname
)
823 (not (when noconfirm
(file-remote-p dirname
)))
824 (file-readable-p dirname
)
825 ;; Do not auto-revert when the dired buffer can be currently
826 ;; written by the user as in `wdired-mode'.
828 (dired-directory-changed-p dirname
))))
830 (defcustom dired-auto-revert-buffer nil
831 "Automatically revert Dired buffer on revisiting.
832 If t, revisiting an existing Dired buffer automatically reverts it.
833 If its value is a function, call this function with the directory
834 name as single argument and revert the buffer if it returns non-nil.
835 Otherwise, a message offering to revert the changed dired buffer
837 Note that this is not the same as `auto-revert-mode' that
838 periodically reverts at specified time intervals."
840 (const :tag
"Don't revert" nil
)
841 (const :tag
"Always revert visited Dired buffer" t
)
842 (const :tag
"Revert changed Dired buffer" dired-directory-changed-p
)
843 (function :tag
"Predicate function"))
847 (defun dired-internal-noselect (dir-or-list &optional switches mode
)
848 ;; If there is an existing dired buffer for DIRNAME, just leave
849 ;; buffer as it is (don't even call dired-revert).
850 ;; This saves time especially for deep trees or with ange-ftp.
851 ;; The user can type `g' easily, and it is more consistent with find-file.
852 ;; But if SWITCHES are given they are probably different from the
853 ;; buffer's old value, so call dired-sort-other, which does
854 ;; revert the buffer.
855 ;; A pity we can't possibly do "Directory has changed - refresh? "
856 ;; like find-file does.
857 ;; Optional argument MODE is passed to dired-find-buffer-nocreate,
859 (let* ((old-buf (current-buffer))
860 (dirname (if (consp dir-or-list
) (car dir-or-list
) dir-or-list
))
861 ;; Look for an existing buffer.
862 (buffer (dired-find-buffer-nocreate dirname mode
))
863 ;; Note that buffer already is in dired-mode, if found.
864 (new-buffer-p (null buffer
)))
866 (setq buffer
(create-file-buffer (directory-file-name dirname
))))
868 (if (not new-buffer-p
) ; existing buffer ...
869 (cond (switches ; ... but new switches
870 ;; file list may have changed
871 (setq dired-directory dir-or-list
)
872 ;; this calls dired-revert
873 (dired-sort-other switches
))
874 ;; Always revert regardless of whether it has changed or not.
875 ((eq dired-auto-revert-buffer t
)
877 ;; Revert when predicate function returns non-nil.
878 ((functionp dired-auto-revert-buffer
)
879 (when (funcall dired-auto-revert-buffer dirname
)
881 (message "Changed directory automatically updated")))
882 ;; If directory has changed on disk, offer to revert.
883 ((when (dired-directory-changed-p dirname
)
885 (substitute-command-keys
886 "Directory has changed on disk; type \\[revert-buffer] to update Dired")))))
888 (setq default-directory
889 ;; We can do this unconditionally
890 ;; because dired-noselect ensures that the name
891 ;; is passed in directory name syntax
892 ;; if it was the name of a directory at all.
893 (file-name-directory dirname
))
894 (or switches
(setq switches dired-listing-switches
))
895 (if mode
(funcall mode
)
896 (dired-mode dir-or-list switches
))
897 ;; default-directory and dired-actual-switches are set now
898 ;; (buffer-local), so we can call dired-readin:
901 (progn (dired-readin)
903 ;; dired-readin can fail if parent directories are inaccessible.
904 ;; Don't leave an empty buffer around in that case.
905 (if failed
(kill-buffer buffer
))))
906 (goto-char (point-min))
907 (dired-initial-position dirname
))
911 (defvar dired-buffers nil
912 ;; Enlarged by dired-advertise
913 ;; Queried by function dired-buffers-for-dir. When this detects a
914 ;; killed buffer, it is removed from this list.
915 "Alist of expanded directories and their associated Dired buffers.")
917 (defvar dired-find-subdir
)
919 ;; FIXME add a doc-string, and document dired-x extensions.
920 (defun dired-find-buffer-nocreate (dirname &optional mode
)
921 ;; This differs from dired-buffers-for-dir in that it does not consider
922 ;; subdirs of default-directory and searches for the first match only.
923 ;; Also, the major mode must be MODE.
924 (if (and (featurep 'dired-x
)
926 ;; Don't try to find a wildcard as a subdirectory.
927 (string-equal dirname
(file-name-directory dirname
)))
928 (let* ((cur-buf (current-buffer))
930 (dired-buffers-for-dir (expand-file-name dirname
))))
931 (cur-buf-matches (and (memq cur-buf buffers
)
932 ;; Wildcards must match, too:
933 (equal dired-directory dirname
))))
934 ;; We don't want to switch to the same buffer---
935 (setq buffers
(delq cur-buf buffers
))
936 (or (car (sort buffers
#'dired-buffer-more-recently-used-p
))
937 ;; ---unless it's the only possibility:
938 (and cur-buf-matches cur-buf
)))
939 ;; No dired-x, or dired-find-subdir nil.
940 (setq dirname
(expand-file-name dirname
))
941 (let (found (blist dired-buffers
)) ; was (buffer-list)
942 (or mode
(setq mode
'dired-mode
))
944 (if (null (buffer-name (cdr (car blist
))))
945 (setq blist
(cdr blist
))
946 (with-current-buffer (cdr (car blist
))
947 (if (and (eq major-mode mode
)
948 dired-directory
;; nil during find-alternate-file
951 (if (consp dired-directory
)
952 (car dired-directory
)
954 (setq found
(cdr (car blist
))
956 (setq blist
(cdr blist
))))))
960 ;; Read in a new dired buffer
962 (defun dired-readin ()
963 "Read in a new Dired buffer.
964 Differs from `dired-insert-subdir' in that it accepts
965 wildcards, erases the buffer, and builds the subdir-alist anew
966 \(including making it buffer-local and clearing it first)."
968 ;; default-directory and dired-actual-switches must be buffer-local
969 ;; and initialized by now.
971 ;; This makes readin much much faster.
972 ;; In particular, it prevents the font lock hook from running
973 ;; until the directory is all read in.
974 (inhibit-modification-hooks t
))
975 (if (consp dired-directory
)
976 (setq dirname
(car dired-directory
))
977 (setq dirname dired-directory
))
978 (setq dirname
(expand-file-name dirname
))
980 ;; This hook which may want to modify dired-actual-switches
981 ;; based on dired-directory, e.g. with ange-ftp to a SysV host
982 ;; where ls won't understand -Al switches.
983 (run-hooks 'dired-before-readin-hook
)
984 (if (consp buffer-undo-list
)
985 (setq buffer-undo-list nil
))
986 (setq-local file-name-coding-system
987 (or coding-system-for-read file-name-coding-system
))
988 (let ((inhibit-read-only t
)
989 ;; Don't make undo entries for readin.
990 (buffer-undo-list t
))
993 (dired-readin-insert))
994 (goto-char (point-min))
995 ;; Must first make alist buffer local and set it to nil because
996 ;; dired-build-subdir-alist will call dired-clear-alist first
997 (setq-local dired-subdir-alist nil
)
998 (dired-build-subdir-alist)
999 (let ((attributes (file-attributes dirname
)))
1000 (if (eq (car attributes
) t
)
1001 (set-visited-file-modtime (nth 5 attributes
))))
1002 (set-buffer-modified-p nil
)
1003 ;; No need to narrow since the whole buffer contains just
1004 ;; dired-readin's output, nothing else. The hook can
1005 ;; successfully use dired functions (e.g. dired-get-filename)
1006 ;; as the subdir-alist has been built in dired-readin.
1007 (run-hooks 'dired-after-readin-hook
))))
1009 ;; Subroutines of dired-readin
1011 (defun dired-readin-insert ()
1012 ;; Insert listing for the specified dir (and maybe file list)
1013 ;; already in dired-directory, assuming a clean buffer.
1014 (let (dir file-list
)
1015 (if (consp dired-directory
)
1016 (setq dir
(car dired-directory
)
1017 file-list
(cdr dired-directory
))
1018 (setq dir dired-directory
1020 (setq dir
(expand-file-name dir
))
1021 (if (and (equal "" (file-name-nondirectory dir
))
1023 ;; If we are reading a whole single directory...
1024 (dired-insert-directory dir dired-actual-switches nil nil t
)
1025 (if (not (file-readable-p
1026 (directory-file-name (file-name-directory dir
))))
1027 (error "Directory %s inaccessible or nonexistent" dir
)
1028 ;; Else treat it as a wildcard spec
1029 ;; unless we have an explicit list of files.
1030 (dired-insert-directory dir dired-actual-switches
1031 file-list
(not file-list
) t
)))))
1033 (defun dired-align-file (beg end
)
1034 "Align the fields of a file to the ones of surrounding lines.
1035 BEG..END is the line where the file info is located."
1036 ;; Some versions of ls try to adjust the size of each field so as to just
1037 ;; hold the largest element ("largest" in the current invocation, of
1038 ;; course). So when a single line is output, the size of each field is
1039 ;; just big enough for that one output. Thus when dired refreshes one
1040 ;; line, the alignment if this line w.r.t the rest is messed up because
1041 ;; the fields of that one line will generally be smaller.
1043 ;; To work around this problem, we here add spaces to try and
1044 ;; re-align the fields as needed. Since this is purely aesthetic,
1045 ;; it is of utmost importance that it doesn't mess up anything like
1046 ;; `dired-move-to-filename'. To this end, we limit ourselves to
1047 ;; adding spaces only, and to only add them at places where there
1048 ;; was already at least one space. This way, as long as
1049 ;; `directory-listing-before-filename-regexp' always matches spaces
1050 ;; with "*" or "+", we know we haven't made anything worse. There
1051 ;; is one spot where the exact number of spaces is important, which
1052 ;; is just before the actual filename, so we refrain from adding
1053 ;; spaces there (and within the filename as well, of course).
1055 (let (file file-col other other-col
)
1056 ;; Check that there is indeed a file, and that there is another adjacent
1057 ;; file with which to align, and that additional spaces are needed to
1058 ;; align the filenames.
1059 (when (and (setq file
(progn (goto-char beg
)
1060 (dired-move-to-filename nil end
)))
1061 (setq file-col
(current-column))
1063 (or (and (goto-char beg
)
1064 (zerop (forward-line -
1))
1065 (dired-move-to-filename))
1066 (and (goto-char beg
)
1067 (zerop (forward-line 1))
1068 (dired-move-to-filename))))
1069 (setq other-col
(current-column))
1071 ;; Make sure there is some work left to do.
1072 (> other-col file-col
))
1073 ;; If we've only looked at the line above, check to see if the line
1074 ;; below exists as well and if so, align with the shorter one.
1075 (when (and (< other file
)
1077 (zerop (forward-line 1))
1078 (dired-move-to-filename))
1079 (let ((alt-col (current-column)))
1080 (when (< alt-col other-col
)
1081 (setq other-col alt-col
)
1082 (setq other
(point)))))
1083 ;; Keep positions uptodate when we insert stuff.
1084 (if (> other file
) (setq other
(copy-marker other
)))
1085 (setq file
(copy-marker file
))
1088 (skip-chars-forward " ") ;Skip to the first field.
1089 (while (and (> other-col file-col
)
1090 ;; Don't touch anything just before (and after) the
1091 ;; beginning of the filename.
1093 ;; We're now just in front of a field, with a space behind us.
1094 (let* ((curcol (current-column))
1095 ;; Nums are right-aligned.
1096 (num-align (looking-at-p "[0-9]"))
1097 ;; Let's look at the other line, in the same column: we
1098 ;; should be either near the end of the previous field, or
1099 ;; in the space between that field and the next.
1100 ;; [ Of course, it's also possible that we're already within
1101 ;; the next field or even past it, but that's unlikely since
1102 ;; other-col > file-col. ]
1103 ;; Let's find the distance to the alignment-point (either
1104 ;; the beginning or the end of the next field, depending on
1105 ;; whether this field is left or right aligned).
1109 (move-to-column curcol
)
1112 (if (eq (char-before) ?\s
) " *" "[^ ]* *")
1113 (if num-align
"[0-9][^ ]*")))
1114 (- (match-end 0) (match-beginning 0)))))
1115 ;; Now, the number of spaces to insert is align-pt-offset
1116 ;; minus the distance to the equivalent point on the
1121 (and align-pt-offset
1123 (skip-chars-forward "^ ")
1124 (- align-pt-offset
(- (current-column) curcol
)))))))
1125 (when (and spaces
(> spaces
0))
1126 (setq file-col
(+ spaces file-col
))
1127 (if (> file-col other-col
)
1128 (setq spaces
(- spaces
(- file-col other-col
))))
1129 (insert-char ?\s spaces
)
1130 ;; Let's just make really sure we did not mess up.
1131 (unless (save-excursion
1132 (eq (dired-move-to-filename) (marker-position file
)))
1133 ;; Damn! We messed up: let's revert the change.
1134 (delete-char (- spaces
)))))
1135 ;; Now skip to next field.
1136 (skip-chars-forward "^ ") (skip-chars-forward " "))
1137 (set-marker file nil
)))))
1140 (defvar ls-lisp-use-insert-directory-program
)
1142 (defun dired-switches-escape-p (switches)
1143 "Return non-nil if the string SWITCHES contains -b or --escape."
1144 ;; Do not match things like "--block-size" that happen to contain "b".
1145 (string-match-p "\\(\\`\\| \\)-[[:alnum:]]*b\\|--escape\\>" switches
))
1147 (defun dired-insert-directory (dir switches
&optional file-list wildcard hdr
)
1148 "Insert a directory listing of DIR, Dired style.
1149 Use SWITCHES to make the listings.
1150 If FILE-LIST is non-nil, list only those files.
1151 Otherwise, if WILDCARD is non-nil, expand wildcards;
1152 in that case, DIR should be a file name that uses wildcards.
1153 In other cases, DIR should be a directory name or a directory filename.
1154 If HDR is non-nil, insert a header line with the directory name."
1155 (let ((opoint (point))
1156 (process-environment (copy-sequence process-environment
))
1159 ;; Don't try to invoke `ls' if we are on DOS/Windows where
1160 ;; ls-lisp emulation is used, except if they want to use `ls'
1161 ;; as indicated by `ls-lisp-use-insert-directory-program'.
1162 (not (and (featurep 'ls-lisp
)
1163 (null ls-lisp-use-insert-directory-program
)))
1164 (or (if (eq dired-use-ls-dired
'unspecified
)
1165 ;; Check whether "ls --dired" gives exit code 0, and
1166 ;; save the answer in `dired-use-ls-dired'.
1167 (or (setq dired-use-ls-dired
1168 (eq 0 (call-process insert-directory-program
1169 nil nil nil
"--dired")))
1171 (message "ls does not support --dired; \
1172 see `dired-use-ls-dired' for more details.")
1175 (file-remote-p dir
)))
1176 (setq switches
(concat "--dired " switches
)))
1177 ;; We used to specify the C locale here, to force English month names;
1178 ;; but this should not be necessary any more,
1179 ;; with the new value of `directory-listing-before-filename-regexp'.
1181 (dolist (f file-list
)
1182 (let ((beg (point)))
1183 (insert-directory f switches nil nil
)
1184 ;; Re-align fields, if necessary.
1185 (dired-align-file beg
(point))))
1186 (insert-directory dir switches wildcard
(not wildcard
)))
1187 ;; Quote certain characters, unless ls quoted them for us.
1188 (if (not (dired-switches-escape-p dired-actual-switches
))
1190 (setq end
(point-marker))
1192 (while (search-forward "\\" end t
)
1193 (replace-match (apply #'propertize
1195 (text-properties-at (match-beginning 0)))
1198 (while (search-forward "\^m" end t
)
1199 (replace-match (apply #'propertize
1201 (text-properties-at (match-beginning 0)))
1203 (set-marker end nil
))
1204 ;; Replace any newlines in DIR with literal "\n"s, for the sake
1205 ;; of the header line. To disambiguate a literal "\n" in the
1206 ;; actual dirname, we also replace "\" with "\\".
1207 ;; Personally, I think this should always be done, irrespective
1208 ;; of the value of dired-actual-switches, because:
1209 ;; i) Dired simply does not work with an unescaped newline in
1210 ;; the directory name used in the header (bug=10469#28), and
1211 ;; ii) "\" is always replaced with "\\" in the listing, so doing
1212 ;; it in the header as well makes things consistent.
1213 ;; But at present it is only done if "-b" is in ls-switches,
1214 ;; because newlines in dirnames are uncommon, and people may
1215 ;; have gotten used to seeing unescaped "\" in the headers.
1216 ;; Note: adjust dired-build-subdir-alist if you change this.
1217 (setq dir
(replace-regexp-in-string "\\\\" "\\\\" dir nil t
)
1218 dir
(replace-regexp-in-string "\n" "\\n" dir nil t
)))
1219 ;; If we used --dired and it worked, the lines are already indented.
1220 ;; Otherwise, indent them.
1221 (unless (save-excursion
1224 (let ((indent-tabs-mode nil
))
1225 (indent-rigidly opoint
(point) 2)))
1226 ;; Insert text at the beginning to standardize things.
1227 (let ((content-point opoint
))
1230 (when (and (or hdr wildcard
)
1231 (not (and (looking-at "^ \\(.*\\):$")
1232 (file-name-absolute-p (match-string 1)))))
1233 ;; Note that dired-build-subdir-alist will replace the name
1234 ;; by its expansion, so it does not matter whether what we insert
1235 ;; here is fully expanded, but it should be absolute.
1236 (insert " " (directory-file-name (file-name-directory dir
)) ":\n")
1237 (setq content-point
(point)))
1239 ;; Insert "wildcard" line where "total" line would be for a full dir.
1240 (insert " wildcard " (file-name-nondirectory dir
) "\n")))
1241 (dired-insert-set-properties content-point
(point)))))
1243 (defun dired-insert-set-properties (beg end
)
1244 "Add various text properties to the lines in the region."
1247 (while (< (point) end
)
1249 (if (not (dired-move-to-filename))
1250 (put-text-property (line-beginning-position)
1251 (1+ (line-end-position))
1252 'invisible
'dired-hide-details-information
)
1253 (put-text-property (+ (line-beginning-position) 1) (1- (point))
1254 'invisible
'dired-hide-details-detail
)
1255 (add-text-properties
1258 (dired-move-to-end-of-filename)
1263 help-echo
"mouse-2: visit this file in other window"))
1264 (when (< (+ (point) 4) (line-end-position))
1265 (put-text-property (+ (point) 4) (line-end-position)
1266 'invisible
'dired-hide-details-link
))))
1269 ;; Reverting a dired buffer
1271 (defun dired-revert (&optional _arg _noconfirm
)
1272 "Reread the Dired buffer.
1273 Must also be called after `dired-actual-switches' have changed.
1274 Should not fail even on completely garbaged buffers.
1275 Preserves old cursor, marks/flags, hidden-p.
1277 Dired sets `revert-buffer-function' to this function. The args
1278 ARG and NOCONFIRM, passed from `revert-buffer', are ignored."
1279 (widen) ; just in case user narrowed
1280 (let ((modflag (buffer-modified-p))
1281 (positions (dired-save-positions))
1282 (mark-alist nil
) ; save marked files
1283 (hidden-subdirs (dired-remember-hidden))
1284 (old-subdir-alist (cdr (reverse dired-subdir-alist
))) ; except pwd
1285 (case-fold-search nil
) ; we check for upper case ls flags
1286 (inhibit-read-only t
))
1287 (goto-char (point-min))
1288 (setq mark-alist
;; only after dired-remember-hidden since this unhides:
1289 (dired-remember-marks (point-min) (point-max)))
1290 ;; treat top level dir extra (it may contain wildcards)
1291 (if (not (consp dired-directory
))
1292 (dired-uncache dired-directory
)
1293 (dired-uncache (car dired-directory
))
1294 (dolist (dir (cdr dired-directory
))
1295 (if (file-name-absolute-p dir
)
1296 (dired-uncache dir
))))
1297 ;; Run dired-after-readin-hook just once, below.
1298 (let ((dired-after-readin-hook nil
))
1300 (dired-insert-old-subdirs old-subdir-alist
))
1301 (dired-mark-remembered mark-alist
) ; mark files that were marked
1302 ;; ... run the hook for the whole buffer, and only after markers
1303 ;; have been reinserted (else omitting in dired-x would omit marked files)
1304 (run-hooks 'dired-after-readin-hook
) ; no need to narrow
1305 (dired-restore-positions positions
)
1306 (save-excursion ; hide subdirs that were hidden
1307 (dolist (dir hidden-subdirs
)
1308 (if (dired-goto-subdir dir
)
1309 (dired-hide-subdir 1))))
1310 (unless modflag
(restore-buffer-modified-p nil
)))
1311 ;; outside of the let scope
1312 ;;; Might as well not override the user if the user changed this.
1313 ;;; (setq buffer-read-only t)
1316 ;; Subroutines of dired-revert
1317 ;; Some of these are also used when inserting subdirs.
1319 (defun dired-save-positions ()
1320 "Return current positions in the buffer and all windows with this directory.
1321 The positions have the form (BUFFER-POSITION WINDOW-POSITIONS).
1323 BUFFER-POSITION is the point position in the current Dired buffer.
1324 It has the form (BUFFER DIRED-FILENAME BUFFER-POINT).
1326 WINDOW-POSITIONS are current positions in all windows displaying
1327 this dired buffer. The window positions have the form (WINDOW
1328 DIRED-FILENAME WINDOW-POINT)."
1330 (list (current-buffer) (dired-get-filename nil t
) (point))
1333 (with-selected-window w
1334 (dired-get-filename nil t
))
1336 (get-buffer-window-list nil
0 t
))))
1338 (defun dired-restore-positions (positions)
1339 "Restore POSITIONS saved with `dired-save-positions'."
1340 (let* ((buf-file-pos (nth 0 positions
))
1341 (buffer (nth 0 buf-file-pos
)))
1342 (unless (and (nth 1 buf-file-pos
)
1343 (dired-goto-file (nth 1 buf-file-pos
)))
1344 (goto-char (nth 2 buf-file-pos
))
1345 (dired-move-to-filename))
1346 (dolist (win-file-pos (nth 1 positions
))
1347 ;; Ensure that window still displays the original buffer.
1348 (when (eq (window-buffer (nth 0 win-file-pos
)) buffer
)
1349 (with-selected-window (nth 0 win-file-pos
)
1350 (unless (and (nth 1 win-file-pos
)
1351 (dired-goto-file (nth 1 win-file-pos
)))
1352 (goto-char (nth 2 win-file-pos
))
1353 (dired-move-to-filename)))))))
1355 (defun dired-remember-marks (beg end
)
1356 "Return alist of files and their marks, from BEG to END."
1357 (if selective-display
; must unhide to make this work.
1358 (let ((inhibit-read-only t
))
1359 (subst-char-in-region beg end ?
\r ?
\n)))
1360 (let (fil chr alist
)
1363 (while (re-search-forward dired-re-mark end t
)
1364 (if (setq fil
(dired-get-filename nil t
))
1365 (setq chr
(preceding-char)
1366 alist
(cons (cons fil chr
) alist
)))))
1369 (defun dired-mark-remembered (alist)
1370 "Mark all files remembered in ALIST.
1371 Each element of ALIST looks like (FILE . MARKERCHAR)."
1375 (setq elt
(car alist
)
1379 (when (dired-goto-file fil
)
1384 (defun dired-remember-hidden ()
1385 "Return a list of names of subdirs currently hidden."
1386 (let ((l dired-subdir-alist
) dir pos result
)
1388 (setq dir
(car (car l
))
1392 (skip-chars-forward "^\r\n")
1393 (if (eq (following-char) ?
\r)
1394 (setq result
(cons dir result
))))
1397 (defun dired-insert-old-subdirs (old-subdir-alist)
1398 "Try to insert all subdirs that were displayed before.
1399 Do so according to the former subdir alist OLD-SUBDIR-ALIST."
1400 (or (string-match-p "R" dired-actual-switches
)
1402 (while old-subdir-alist
1403 (setq elt
(car old-subdir-alist
)
1404 old-subdir-alist
(cdr old-subdir-alist
)
1408 (dired-insert-subdir dir
))))))
1410 (defun dired-uncache (dir)
1411 "Remove directory DIR from any directory cache."
1412 (let ((handler (find-file-name-handler dir
'dired-uncache
)))
1414 (funcall handler
'dired-uncache dir
))))
1416 ;; dired mode key bindings and initialization
1418 (defvar dired-mode-map
1419 ;; This looks ugly when substitute-command-keys uses C-d instead d:
1420 ;; (define-key dired-mode-map "\C-d" 'dired-flag-file-deletion)
1421 (let ((map (make-keymap)))
1422 (set-keymap-parent map special-mode-map
)
1423 (define-key map
[mouse-2
] 'dired-mouse-find-file-other-window
)
1424 (define-key map
[follow-link
] 'mouse-face
)
1425 ;; Commands to mark or flag certain categories of files
1426 (define-key map
"#" 'dired-flag-auto-save-files
)
1427 (define-key map
"." 'dired-clean-directory
)
1428 (define-key map
"~" 'dired-flag-backup-files
)
1429 ;; Upper case keys (except !) for operating on the marked files
1430 (define-key map
"A" 'dired-do-search
)
1431 (define-key map
"C" 'dired-do-copy
)
1432 (define-key map
"B" 'dired-do-byte-compile
)
1433 (define-key map
"D" 'dired-do-delete
)
1434 (define-key map
"G" 'dired-do-chgrp
)
1435 (define-key map
"H" 'dired-do-hardlink
)
1436 (define-key map
"L" 'dired-do-load
)
1437 (define-key map
"M" 'dired-do-chmod
)
1438 (define-key map
"O" 'dired-do-chown
)
1439 (define-key map
"P" 'dired-do-print
)
1440 (define-key map
"Q" 'dired-do-query-replace-regexp
)
1441 (define-key map
"R" 'dired-do-rename
)
1442 (define-key map
"S" 'dired-do-symlink
)
1443 (define-key map
"T" 'dired-do-touch
)
1444 (define-key map
"X" 'dired-do-shell-command
)
1445 (define-key map
"Z" 'dired-do-compress
)
1446 (define-key map
"!" 'dired-do-shell-command
)
1447 (define-key map
"&" 'dired-do-async-shell-command
)
1448 ;; Comparison commands
1449 (define-key map
"=" 'dired-diff
)
1450 ;; Tree Dired commands
1451 (define-key map
"\M-\C-?" 'dired-unmark-all-files
)
1452 (define-key map
"\M-\C-d" 'dired-tree-down
)
1453 (define-key map
"\M-\C-u" 'dired-tree-up
)
1454 (define-key map
"\M-\C-n" 'dired-next-subdir
)
1455 (define-key map
"\M-\C-p" 'dired-prev-subdir
)
1456 ;; move to marked files
1457 (define-key map
"\M-{" 'dired-prev-marked-file
)
1458 (define-key map
"\M-}" 'dired-next-marked-file
)
1459 ;; Make all regexp commands share a `%' prefix:
1460 ;; We used to get to the submap via a symbol dired-regexp-prefix,
1461 ;; but that seems to serve little purpose, and copy-keymap
1462 ;; does a better job without it.
1463 (define-key map
"%" nil
)
1464 (define-key map
"%u" 'dired-upcase
)
1465 (define-key map
"%l" 'dired-downcase
)
1466 (define-key map
"%d" 'dired-flag-files-regexp
)
1467 (define-key map
"%g" 'dired-mark-files-containing-regexp
)
1468 (define-key map
"%m" 'dired-mark-files-regexp
)
1469 (define-key map
"%r" 'dired-do-rename-regexp
)
1470 (define-key map
"%C" 'dired-do-copy-regexp
)
1471 (define-key map
"%H" 'dired-do-hardlink-regexp
)
1472 (define-key map
"%R" 'dired-do-rename-regexp
)
1473 (define-key map
"%S" 'dired-do-symlink-regexp
)
1474 (define-key map
"%&" 'dired-flag-garbage-files
)
1475 ;; Commands for marking and unmarking.
1476 (define-key map
"*" nil
)
1477 (define-key map
"**" 'dired-mark-executables
)
1478 (define-key map
"*/" 'dired-mark-directories
)
1479 (define-key map
"*@" 'dired-mark-symlinks
)
1480 (define-key map
"*%" 'dired-mark-files-regexp
)
1481 (define-key map
"*c" 'dired-change-marks
)
1482 (define-key map
"*s" 'dired-mark-subdir-files
)
1483 (define-key map
"*m" 'dired-mark
)
1484 (define-key map
"*u" 'dired-unmark
)
1485 (define-key map
"*?" 'dired-unmark-all-files
)
1486 (define-key map
"*!" 'dired-unmark-all-marks
)
1487 (define-key map
"U" 'dired-unmark-all-marks
)
1488 (define-key map
"*\177" 'dired-unmark-backward
)
1489 (define-key map
"*\C-n" 'dired-next-marked-file
)
1490 (define-key map
"*\C-p" 'dired-prev-marked-file
)
1491 (define-key map
"*t" 'dired-toggle-marks
)
1492 ;; Lower keys for commands not operating on all the marked files
1493 (define-key map
"a" 'dired-find-alternate-file
)
1494 (define-key map
"d" 'dired-flag-file-deletion
)
1495 (define-key map
"e" 'dired-find-file
)
1496 (define-key map
"f" 'dired-find-file
)
1497 (define-key map
"\C-m" 'dired-find-file
)
1498 (put 'dired-find-file
:advertised-binding
"\C-m")
1499 (define-key map
"g" 'revert-buffer
)
1500 (define-key map
"i" 'dired-maybe-insert-subdir
)
1501 (define-key map
"j" 'dired-goto-file
)
1502 (define-key map
"k" 'dired-do-kill-lines
)
1503 (define-key map
"l" 'dired-do-redisplay
)
1504 (define-key map
"m" 'dired-mark
)
1505 (define-key map
"n" 'dired-next-line
)
1506 (define-key map
"o" 'dired-find-file-other-window
)
1507 (define-key map
"\C-o" 'dired-display-file
)
1508 (define-key map
"p" 'dired-previous-line
)
1509 (define-key map
"s" 'dired-sort-toggle-or-edit
)
1510 (define-key map
"t" 'dired-toggle-marks
)
1511 (define-key map
"u" 'dired-unmark
)
1512 (define-key map
"v" 'dired-view-file
)
1513 (define-key map
"w" 'dired-copy-filename-as-kill
)
1514 (define-key map
"x" 'dired-do-flagged-delete
)
1515 (define-key map
"y" 'dired-show-file-type
)
1516 (define-key map
"+" 'dired-create-directory
)
1518 (define-key map
"<" 'dired-prev-dirline
)
1519 (define-key map
">" 'dired-next-dirline
)
1520 (define-key map
"^" 'dired-up-directory
)
1521 (define-key map
" " 'dired-next-line
)
1522 (define-key map
[remap next-line
] 'dired-next-line
)
1523 (define-key map
[remap previous-line
] 'dired-previous-line
)
1525 (define-key map
"$" 'dired-hide-subdir
)
1526 (define-key map
"\M-$" 'dired-hide-all
)
1527 (define-key map
"(" 'dired-hide-details-mode
)
1529 (define-key map
(kbd "M-s a C-s") 'dired-do-isearch
)
1530 (define-key map
(kbd "M-s a M-C-s") 'dired-do-isearch-regexp
)
1531 (define-key map
(kbd "M-s f C-s") 'dired-isearch-filenames
)
1532 (define-key map
(kbd "M-s f M-C-s") 'dired-isearch-filenames-regexp
)
1534 (define-key map
[remap read-only-mode
] 'dired-toggle-read-only
)
1535 ;; `toggle-read-only' is an obsolete alias for `read-only-mode'
1536 (define-key map
[remap toggle-read-only
] 'dired-toggle-read-only
)
1537 (define-key map
"?" 'dired-summary
)
1538 (define-key map
"\177" 'dired-unmark-backward
)
1539 (define-key map
[remap undo
] 'dired-undo
)
1540 (define-key map
[remap advertised-undo
] 'dired-undo
)
1541 ;; thumbnail manipulation (image-dired)
1542 (define-key map
"\C-td" 'image-dired-display-thumbs
)
1543 (define-key map
"\C-tt" 'image-dired-tag-files
)
1544 (define-key map
"\C-tr" 'image-dired-delete-tag
)
1545 (define-key map
"\C-tj" 'image-dired-jump-thumbnail-buffer
)
1546 (define-key map
"\C-ti" 'image-dired-dired-display-image
)
1547 (define-key map
"\C-tx" 'image-dired-dired-display-external
)
1548 (define-key map
"\C-ta" 'image-dired-display-thumbs-append
)
1549 (define-key map
"\C-t." 'image-dired-display-thumb
)
1550 (define-key map
"\C-tc" 'image-dired-dired-comment-files
)
1551 (define-key map
"\C-tf" 'image-dired-mark-tagged-files
)
1552 (define-key map
"\C-t\C-t" 'image-dired-dired-toggle-marked-thumbs
)
1553 (define-key map
"\C-te" 'image-dired-dired-edit-comment-and-tags
)
1554 ;; encryption and decryption (epa-dired)
1555 (define-key map
":d" 'epa-dired-do-decrypt
)
1556 (define-key map
":v" 'epa-dired-do-verify
)
1557 (define-key map
":s" 'epa-dired-do-sign
)
1558 (define-key map
":e" 'epa-dired-do-encrypt
)
1560 ;; Make menu bar items.
1562 ;; No need to fo this, now that top-level items are fewer.
1564 ;; Get rid of the Edit menu bar item to save space.
1565 ;(define-key map [menu-bar edit] 'undefined)
1567 (define-key map
[menu-bar subdir
]
1568 (cons "Subdir" (make-sparse-keymap "Subdir")))
1570 (define-key map
[menu-bar subdir hide-all
]
1571 '(menu-item "Hide All" dired-hide-all
1572 :help
"Hide all subdirectories, leave only header lines"))
1573 (define-key map
[menu-bar subdir hide-subdir
]
1574 '(menu-item "Hide/UnHide Subdir" dired-hide-subdir
1575 :help
"Hide or unhide current directory listing"))
1576 (define-key map
[menu-bar subdir tree-down
]
1577 '(menu-item "Tree Down" dired-tree-down
1578 :help
"Go to first subdirectory header down the tree"))
1579 (define-key map
[menu-bar subdir tree-up
]
1580 '(menu-item "Tree Up" dired-tree-up
1581 :help
"Go to first subdirectory header up the tree"))
1582 (define-key map
[menu-bar subdir up
]
1583 '(menu-item "Up Directory" dired-up-directory
1584 :help
"Edit the parent directory"))
1585 (define-key map
[menu-bar subdir prev-subdir
]
1586 '(menu-item "Prev Subdir" dired-prev-subdir
1587 :help
"Go to previous subdirectory header line"))
1588 (define-key map
[menu-bar subdir next-subdir
]
1589 '(menu-item "Next Subdir" dired-next-subdir
1590 :help
"Go to next subdirectory header line"))
1591 (define-key map
[menu-bar subdir prev-dirline
]
1592 '(menu-item "Prev Dirline" dired-prev-dirline
1593 :help
"Move to next directory-file line"))
1594 (define-key map
[menu-bar subdir next-dirline
]
1595 '(menu-item "Next Dirline" dired-next-dirline
1596 :help
"Move to previous directory-file line"))
1597 (define-key map
[menu-bar subdir insert
]
1598 '(menu-item "Insert This Subdir" dired-maybe-insert-subdir
1599 :help
"Insert contents of subdirectory"
1600 :enable
(let ((f (dired-get-filename nil t
)))
1601 (and f
(file-directory-p f
)))))
1602 (define-key map
[menu-bar immediate
]
1603 (cons "Immediate" (make-sparse-keymap "Immediate")))
1606 [menu-bar immediate image-dired-dired-display-external
]
1607 '(menu-item "Display Image Externally" image-dired-dired-display-external
1608 :help
"Display image in external viewer"))
1610 [menu-bar immediate image-dired-dired-display-image
]
1611 '(menu-item "Display Image" image-dired-dired-display-image
1612 :help
"Display sized image in a separate window"))
1614 [menu-bar immediate image-dired-dired-toggle-marked-thumbs
]
1615 '(menu-item "Toggle Image Thumbnails in This Buffer" image-dired-dired-toggle-marked-thumbs
1616 :help
"Add or remove image thumbnails in front of marked file names"))
1618 (define-key map
[menu-bar immediate hide-details
]
1619 '(menu-item "Hide Details" dired-hide-details-mode
1620 :help
"Hide details in buffer"
1621 :button
(:toggle . dired-hide-details-mode
)))
1622 (define-key map
[menu-bar immediate revert-buffer
]
1623 '(menu-item "Refresh" revert-buffer
1624 :help
"Update contents of shown directories"))
1626 (define-key map
[menu-bar immediate dashes
]
1629 (define-key map
[menu-bar immediate isearch-filenames-regexp
]
1630 '(menu-item "Isearch Regexp in File Names..." dired-isearch-filenames-regexp
1631 :help
"Incrementally search for regexp in file names only"))
1632 (define-key map
[menu-bar immediate isearch-filenames
]
1633 '(menu-item "Isearch in File Names..." dired-isearch-filenames
1634 :help
"Incrementally search for string in file names only."))
1635 (define-key map
[menu-bar immediate compare-directories
]
1636 '(menu-item "Compare Directories..." dired-compare-directories
1637 :help
"Mark files with different attributes in two Dired buffers"))
1638 (define-key map
[menu-bar immediate backup-diff
]
1639 '(menu-item "Compare with Backup" dired-backup-diff
1640 :help
"Diff file at cursor with its latest backup"))
1641 (define-key map
[menu-bar immediate diff
]
1642 '(menu-item "Diff..." dired-diff
1643 :help
"Compare file at cursor with another file"))
1644 (define-key map
[menu-bar immediate view
]
1645 '(menu-item "View This File" dired-view-file
1646 :help
"Examine file at cursor in read-only mode"))
1647 (define-key map
[menu-bar immediate display
]
1648 '(menu-item "Display in Other Window" dired-display-file
1649 :help
"Display file at cursor in other window"))
1650 (define-key map
[menu-bar immediate find-file-other-window
]
1651 '(menu-item "Find in Other Window" dired-find-file-other-window
1652 :help
"Edit file at cursor in other window"))
1653 (define-key map
[menu-bar immediate find-file
]
1654 '(menu-item "Find This File" dired-find-file
1655 :help
"Edit file at cursor"))
1656 (define-key map
[menu-bar immediate create-directory
]
1657 '(menu-item "Create Directory..." dired-create-directory
1658 :help
"Create a directory"))
1659 (define-key map
[menu-bar immediate wdired-mode
]
1660 '(menu-item "Edit File Names" wdired-change-to-wdired-mode
1661 :help
"Put a Dired buffer in a mode in which filenames are editable"
1663 :filter
(lambda (x) (if (eq major-mode
'dired-mode
) x
))))
1665 (define-key map
[menu-bar regexp
]
1666 (cons "Regexp" (make-sparse-keymap "Regexp")))
1669 [menu-bar regexp image-dired-mark-tagged-files
]
1670 '(menu-item "Mark From Image Tag..." image-dired-mark-tagged-files
1671 :help
"Mark files whose image tags matches regexp"))
1673 (define-key map
[menu-bar regexp dashes-1
]
1676 (define-key map
[menu-bar regexp downcase
]
1677 '(menu-item "Downcase" dired-downcase
1678 ;; When running on plain MS-DOS, there's only one
1679 ;; letter-case for file names.
1680 :enable
(or (not (fboundp 'msdos-long-file-names
))
1681 (msdos-long-file-names))
1682 :help
"Rename marked files to lower-case name"))
1683 (define-key map
[menu-bar regexp upcase
]
1684 '(menu-item "Upcase" dired-upcase
1685 :enable
(or (not (fboundp 'msdos-long-file-names
))
1686 (msdos-long-file-names))
1687 :help
"Rename marked files to upper-case name"))
1688 (define-key map
[menu-bar regexp hardlink
]
1689 '(menu-item "Hardlink..." dired-do-hardlink-regexp
1690 :help
"Make hard links for files matching regexp"))
1691 (define-key map
[menu-bar regexp symlink
]
1692 '(menu-item "Symlink..." dired-do-symlink-regexp
1693 :visible
(fboundp 'make-symbolic-link
)
1694 :help
"Make symbolic links for files matching regexp"))
1695 (define-key map
[menu-bar regexp rename
]
1696 '(menu-item "Rename..." dired-do-rename-regexp
1697 :help
"Rename marked files matching regexp"))
1698 (define-key map
[menu-bar regexp copy
]
1699 '(menu-item "Copy..." dired-do-copy-regexp
1700 :help
"Copy marked files matching regexp"))
1701 (define-key map
[menu-bar regexp flag
]
1702 '(menu-item "Flag..." dired-flag-files-regexp
1703 :help
"Flag files matching regexp for deletion"))
1704 (define-key map
[menu-bar regexp mark
]
1705 '(menu-item "Mark..." dired-mark-files-regexp
1706 :help
"Mark files matching regexp for future operations"))
1707 (define-key map
[menu-bar regexp mark-cont
]
1708 '(menu-item "Mark Containing..." dired-mark-files-containing-regexp
1709 :help
"Mark files whose contents matches regexp"))
1711 (define-key map
[menu-bar mark
]
1712 (cons "Mark" (make-sparse-keymap "Mark")))
1714 (define-key map
[menu-bar mark prev
]
1715 '(menu-item "Previous Marked" dired-prev-marked-file
1716 :help
"Move to previous marked file"))
1717 (define-key map
[menu-bar mark next
]
1718 '(menu-item "Next Marked" dired-next-marked-file
1719 :help
"Move to next marked file"))
1720 (define-key map
[menu-bar mark marks
]
1721 '(menu-item "Change Marks..." dired-change-marks
1722 :help
"Replace marker with another character"))
1723 (define-key map
[menu-bar mark unmark-all
]
1724 '(menu-item "Unmark All" dired-unmark-all-marks
))
1725 (define-key map
[menu-bar mark symlinks
]
1726 '(menu-item "Mark Symlinks" dired-mark-symlinks
1727 :visible
(fboundp 'make-symbolic-link
)
1728 :help
"Mark all symbolic links"))
1729 (define-key map
[menu-bar mark directories
]
1730 '(menu-item "Mark Directories" dired-mark-directories
1731 :help
"Mark all directories except `.' and `..'"))
1732 (define-key map
[menu-bar mark directory
]
1733 '(menu-item "Mark Old Backups" dired-clean-directory
1734 :help
"Flag old numbered backups for deletion"))
1735 (define-key map
[menu-bar mark executables
]
1736 '(menu-item "Mark Executables" dired-mark-executables
1737 :help
"Mark all executable files"))
1738 (define-key map
[menu-bar mark garbage-files
]
1739 '(menu-item "Flag Garbage Files" dired-flag-garbage-files
1740 :help
"Flag unneeded files for deletion"))
1741 (define-key map
[menu-bar mark backup-files
]
1742 '(menu-item "Flag Backup Files" dired-flag-backup-files
1743 :help
"Flag all backup files for deletion"))
1744 (define-key map
[menu-bar mark auto-save-files
]
1745 '(menu-item "Flag Auto-save Files" dired-flag-auto-save-files
1746 :help
"Flag auto-save files for deletion"))
1747 (define-key map
[menu-bar mark deletion
]
1748 '(menu-item "Flag" dired-flag-file-deletion
1749 :help
"Flag current line's file for deletion"))
1750 (define-key map
[menu-bar mark unmark
]
1751 '(menu-item "Unmark" dired-unmark
1752 :help
"Unmark or unflag current line's file"))
1753 (define-key map
[menu-bar mark mark
]
1754 '(menu-item "Mark" dired-mark
1755 :help
"Mark current line's file for future operations"))
1756 (define-key map
[menu-bar mark toggle-marks
]
1757 '(menu-item "Toggle Marks" dired-toggle-marks
1758 :help
"Mark unmarked files, unmark marked ones"))
1760 (define-key map
[menu-bar operate
]
1761 (cons "Operate" (make-sparse-keymap "Operate")))
1764 [menu-bar operate image-dired-delete-tag
]
1765 '(menu-item "Delete Image Tag..." image-dired-delete-tag
1766 :help
"Delete image tag from current or marked files"))
1768 [menu-bar operate image-dired-tag-files
]
1769 '(menu-item "Add Image Tags..." image-dired-tag-files
1770 :help
"Add image tags to current or marked files"))
1772 [menu-bar operate image-dired-dired-comment-files
]
1773 '(menu-item "Add Image Comment..." image-dired-dired-comment-files
1774 :help
"Add image comment to current or marked files"))
1776 [menu-bar operate image-dired-display-thumbs
]
1777 '(menu-item "Display Image Thumbnails" image-dired-display-thumbs
1778 :help
"Display image thumbnails for current or marked image files"))
1780 (define-key map
[menu-bar operate dashes-4
]
1784 [menu-bar operate epa-dired-do-decrypt
]
1785 '(menu-item "Decrypt..." epa-dired-do-decrypt
1786 :help
"Decrypt file at cursor"))
1789 [menu-bar operate epa-dired-do-verify
]
1790 '(menu-item "Verify" epa-dired-do-verify
1791 :help
"Verify digital signature of file at cursor"))
1794 [menu-bar operate epa-dired-do-sign
]
1795 '(menu-item "Sign..." epa-dired-do-sign
1796 :help
"Create digital signature of file at cursor"))
1799 [menu-bar operate epa-dired-do-encrypt
]
1800 '(menu-item "Encrypt..." epa-dired-do-encrypt
1801 :help
"Encrypt file at cursor"))
1803 (define-key map
[menu-bar operate dashes-3
]
1806 (define-key map
[menu-bar operate query-replace
]
1807 '(menu-item "Query Replace in Files..." dired-do-query-replace-regexp
1808 :help
"Replace regexp in marked files"))
1809 (define-key map
[menu-bar operate search
]
1810 '(menu-item "Search Files..." dired-do-search
1811 :help
"Search marked files for regexp"))
1812 (define-key map
[menu-bar operate isearch-regexp
]
1813 '(menu-item "Isearch Regexp Files..." dired-do-isearch-regexp
1814 :help
"Incrementally search marked files for regexp"))
1815 (define-key map
[menu-bar operate isearch
]
1816 '(menu-item "Isearch Files..." dired-do-isearch
1817 :help
"Incrementally search marked files for string"))
1818 (define-key map
[menu-bar operate chown
]
1819 '(menu-item "Change Owner..." dired-do-chown
1820 :visible
(not (memq system-type
'(ms-dos windows-nt
)))
1821 :help
"Change the owner of marked files"))
1822 (define-key map
[menu-bar operate chgrp
]
1823 '(menu-item "Change Group..." dired-do-chgrp
1824 :visible
(not (memq system-type
'(ms-dos windows-nt
)))
1825 :help
"Change the group of marked files"))
1826 (define-key map
[menu-bar operate chmod
]
1827 '(menu-item "Change Mode..." dired-do-chmod
1828 :help
"Change mode (attributes) of marked files"))
1829 (define-key map
[menu-bar operate touch
]
1830 '(menu-item "Change Timestamp..." dired-do-touch
1831 :help
"Change timestamp of marked files"))
1832 (define-key map
[menu-bar operate load
]
1833 '(menu-item "Load" dired-do-load
1834 :help
"Load marked Emacs Lisp files"))
1835 (define-key map
[menu-bar operate compile
]
1836 '(menu-item "Byte-compile" dired-do-byte-compile
1837 :help
"Byte-compile marked Emacs Lisp files"))
1838 (define-key map
[menu-bar operate compress
]
1839 '(menu-item "Compress" dired-do-compress
1840 :help
"Compress/uncompress marked files"))
1841 (define-key map
[menu-bar operate print
]
1842 '(menu-item "Print..." dired-do-print
1843 :help
"Ask for print command and print marked files"))
1844 (define-key map
[menu-bar operate hardlink
]
1845 '(menu-item "Hardlink to..." dired-do-hardlink
1846 :help
"Make hard links for current or marked files"))
1847 (define-key map
[menu-bar operate symlink
]
1848 '(menu-item "Symlink to..." dired-do-symlink
1849 :visible
(fboundp 'make-symbolic-link
)
1850 :help
"Make symbolic links for current or marked files"))
1851 (define-key map
[menu-bar operate async-command
]
1852 '(menu-item "Asynchronous Shell Command..." dired-do-async-shell-command
1853 :help
"Run a shell command asynchronously on current or marked files"))
1854 (define-key map
[menu-bar operate command
]
1855 '(menu-item "Shell Command..." dired-do-shell-command
1856 :help
"Run a shell command on current or marked files"))
1857 (define-key map
[menu-bar operate delete
]
1858 '(menu-item "Delete" dired-do-delete
1859 :help
"Delete current file or all marked files"))
1860 (define-key map
[menu-bar operate rename
]
1861 '(menu-item "Rename to..." dired-do-rename
1862 :help
"Rename current file or move marked files"))
1863 (define-key map
[menu-bar operate copy
]
1864 '(menu-item "Copy to..." dired-do-copy
1865 :help
"Copy current file or all marked files"))
1868 "Local keymap for Dired mode buffers.")
1870 ;; Dired mode is suitable only for specially formatted data.
1871 (put 'dired-mode
'mode-class
'special
)
1873 ;; Autoload cookie needed by desktop.el
1875 (defun dired-mode (&optional dirname switches
)
1877 Mode for \"editing\" directory listings.
1878 In Dired, you are \"editing\" a list of the files in a directory and
1879 (optionally) its subdirectories, in the format of `ls -lR'.
1880 Each directory is a page: use \\[backward-page] and \\[forward-page] to move pagewise.
1881 \"Editing\" means that you can run shell commands on files, visit,
1882 compress, load or byte-compile them, change their file attributes
1883 and insert subdirectories into the same buffer. You can \"mark\"
1884 files for later commands or \"flag\" them for deletion, either file
1885 by file or all files matching certain criteria.
1886 You can move using the usual cursor motion commands.\\<dired-mode-map>
1887 The buffer is read-only. Digits are prefix arguments.
1888 Type \\[dired-flag-file-deletion] to flag a file `D' for deletion.
1889 Type \\[dired-mark] to Mark a file or subdirectory for later commands.
1890 Most commands operate on the marked files and use the current file
1891 if no files are marked. Use a numeric prefix argument to operate on
1892 the next ARG (or previous -ARG if ARG<0) files, or just `1'
1893 to operate on the current file only. Prefix arguments override marks.
1894 Mark-using commands display a list of failures afterwards. Type \\[dired-summary]
1895 to see why something went wrong.
1896 Type \\[dired-unmark] to Unmark a file or all files of an inserted subdirectory.
1897 Type \\[dired-unmark-backward] to back up one line and unmark or unflag.
1898 Type \\[dired-do-flagged-delete] to delete (eXecute) the files flagged `D'.
1899 Type \\[dired-find-file] to Find the current line's file
1900 (or dired it in another buffer, if it is a directory).
1901 Type \\[dired-find-file-other-window] to find file or Dired directory in Other window.
1902 Type \\[dired-maybe-insert-subdir] to Insert a subdirectory in this buffer.
1903 Type \\[dired-do-rename] to Rename a file or move the marked files to another directory.
1904 Type \\[dired-do-copy] to Copy files.
1905 Type \\[dired-sort-toggle-or-edit] to toggle Sorting by name/date or change the `ls' switches.
1906 Type \\[revert-buffer] to read all currently expanded directories aGain.
1907 This retains all marks and hides subdirs again that were hidden before.
1908 Use `SPC' and `DEL' to move down and up by lines.
1910 If Dired ever gets confused, you can either type \\[revert-buffer] \
1912 directories again, type \\[dired-do-redisplay] \
1913 to relist the file at point or the marked files or a
1914 subdirectory, or type \\[dired-build-subdir-alist] to parse the buffer
1915 again for the directory tree.
1917 Customization variables (rename this buffer and type \\[describe-variable] on each line
1920 `dired-listing-switches'
1921 `dired-trivial-filenames'
1924 `dired-keep-marker-rename'
1925 `dired-keep-marker-copy'
1926 `dired-keep-marker-hardlink'
1927 `dired-keep-marker-symlink'
1929 Hooks (use \\[describe-variable] to see their documentation):
1931 `dired-before-readin-hook'
1932 `dired-after-readin-hook'
1938 ;; Not to be called interactively (e.g. dired-directory will be set
1939 ;; to default-directory, which is wrong with wildcards).
1940 (kill-all-local-variables)
1941 (use-local-map dired-mode-map
)
1942 (dired-advertise) ; default-directory is already set
1943 (setq major-mode
'dired-mode
1945 ;; case-fold-search nil
1947 selective-display t
; for subdirectory hiding
1948 mode-line-buffer-identification
1949 (propertized-buffer-identification "%17b"))
1950 ;; Ignore dired-hide-details-* value of invisible text property by default.
1951 (when (eq buffer-invisibility-spec t
)
1952 (setq buffer-invisibility-spec
(list t
)))
1953 (setq-local revert-buffer-function
(function dired-revert
))
1954 (setq-local buffer-stale-function
(function dired-buffer-stale-p
))
1955 (setq-local page-delimiter
"\n\n")
1956 (setq-local dired-directory
(or dirname default-directory
))
1957 ;; list-buffers uses this to display the dir being edited in this buffer.
1958 (setq list-buffers-directory
1959 (expand-file-name (if (listp dired-directory
)
1960 (car dired-directory
)
1962 (setq-local dired-actual-switches
(or switches dired-listing-switches
))
1963 (setq-local font-lock-defaults
1964 '(dired-font-lock-keywords t nil nil beginning-of-line
))
1965 (setq-local desktop-save-buffer
'dired-desktop-buffer-misc-data
)
1966 (setq dired-switches-alist nil
)
1967 (hack-dir-local-variables-non-file-buffer) ; before sorting
1968 (dired-sort-other dired-actual-switches t
)
1969 (when (featurep 'dnd
)
1970 (setq-local dnd-protocol-alist
1971 (append dired-dnd-protocol-alist dnd-protocol-alist
)))
1972 (add-hook 'file-name-at-point-functions
'dired-file-name-at-point nil t
)
1973 (add-hook 'isearch-mode-hook
'dired-isearch-filenames-setup nil t
)
1974 (run-mode-hooks 'dired-mode-hook
))
1976 ;; Idiosyncratic dired commands that don't deal with marks.
1978 (defun dired-summary ()
1979 "Summarize basic Dired commands and show recent Dired errors."
1982 ;>> this should check the key-bindings and use substitute-command-keys if non-standard
1984 "d-elete, u-ndelete, x-punge, f-ind, o-ther window, R-ename, C-opy, h-elp"))
1986 (defun dired-undo ()
1987 "Undo in a Dired buffer.
1988 This doesn't recover lost files, it just undoes changes in the buffer itself.
1989 You can use it to recover marks, killed lines or subdirs."
1991 (let ((inhibit-read-only t
))
1993 (dired-build-subdir-alist)
1994 (message "Change in Dired buffer undone.
1995 Actual changes in files cannot be undone by Emacs."))
1997 (defun dired-toggle-read-only ()
1998 "Edit Dired buffer with Wdired, or make it read-only.
1999 If the current buffer can be edited with Wdired, (i.e. the major
2000 mode is `dired-mode'), call `wdired-change-to-wdired-mode'.
2001 Otherwise, call `toggle-read-only'."
2003 (if (derived-mode-p 'dired-mode
)
2004 (wdired-change-to-wdired-mode)
2005 (read-only-mode 'toggle
)))
2007 (defun dired-next-line (arg)
2008 "Move down lines then position at filename.
2009 Optional prefix ARG says how many lines to move; default is one line."
2011 (let ((line-move-visual)
2014 ;; We never want to move point into an invisible line.
2015 (while (and (invisible-p (point))
2016 (not (if (and arg
(< arg
0)) (bobp) (eobp))))
2017 (forward-char (if (and arg
(< arg
0)) -
1 1)))
2018 (dired-move-to-filename))
2020 (defun dired-previous-line (arg)
2021 "Move up lines then position at filename.
2022 Optional prefix ARG says how many lines to move; default is one line."
2024 (dired-next-line (- (or arg
1))))
2026 (defun dired-next-dirline (arg &optional opoint
)
2027 "Goto ARGth next directory file line."
2029 (or opoint
(setq opoint
(point)))
2031 (re-search-forward dired-re-dir nil t arg
)
2033 (re-search-backward dired-re-dir nil t
(- arg
)))
2034 (dired-move-to-filename) ; user may type `i' or `f'
2036 (error "No more subdirectories")))
2038 (defun dired-prev-dirline (arg)
2039 "Goto ARGth previous directory file line."
2041 (dired-next-dirline (- arg
)))
2043 (defun dired-up-directory (&optional other-window
)
2044 "Run Dired on parent directory of current directory.
2045 Find the parent directory either in this buffer or another buffer.
2046 Creates a buffer if necessary."
2048 (let* ((dir (dired-current-directory))
2049 (up (file-name-directory (directory-file-name dir
))))
2050 (or (dired-goto-file (directory-file-name dir
))
2051 ;; Only try dired-goto-subdir if buffer has more than one dir.
2052 (and (cdr dired-subdir-alist
)
2053 (dired-goto-subdir up
))
2056 (dired-other-window up
)
2058 (dired-goto-file dir
)))))
2060 (defun dired-get-file-for-visit ()
2061 "Get the current line's file name, with an error if file does not exist."
2063 ;; We pass t for second arg so that we don't get error for `.' and `..'.
2064 (let ((raw (dired-get-filename nil t
))
2067 (error "No file on this line"))
2068 (setq file-name
(file-name-sans-versions raw t
))
2069 (if (file-exists-p file-name
)
2071 (if (file-symlink-p file-name
)
2072 (error "File is a symlink to a nonexistent target")
2073 (error "File no longer exists; type `g' to update Dired buffer")))))
2075 ;; Force C-m keybinding rather than `f' or `e' in the mode doc:
2076 (define-obsolete-function-alias 'dired-advertised-find-file
'dired-find-file
"23.2")
2077 (defun dired-find-file ()
2078 "In Dired, visit the file or directory named on this line."
2080 ;; Bind `find-file-run-dired' so that the command works on directories
2081 ;; too, independent of the user's setting.
2082 (let ((find-file-run-dired t
))
2083 (find-file (dired-get-file-for-visit))))
2085 (defun dired-find-alternate-file ()
2086 "In Dired, visit this file or directory instead of the Dired buffer."
2088 (set-buffer-modified-p nil
)
2089 (find-alternate-file (dired-get-file-for-visit)))
2090 ;; Don't override the setting from .emacs.
2091 ;;;###autoload (put 'dired-find-alternate-file 'disabled t)
2093 (defun dired-mouse-find-file-other-window (event)
2094 "In Dired, visit the file or directory name you click on."
2096 (let (window pos file
)
2098 (setq window
(posn-window (event-end event
))
2099 pos
(posn-point (event-end event
)))
2100 (if (not (windowp window
))
2101 (error "No file chosen"))
2102 (set-buffer (window-buffer window
))
2104 (setq file
(dired-get-file-for-visit)))
2105 (if (file-directory-p file
)
2106 (or (and (cdr dired-subdir-alist
)
2107 (dired-goto-subdir file
))
2109 (select-window window
)
2110 (dired-other-window file
)))
2111 (select-window window
)
2112 (find-file-other-window (file-name-sans-versions file t
)))))
2114 (defun dired-view-file ()
2115 "In Dired, examine a file in view mode, returning to Dired when done.
2116 When file is a directory, show it in this buffer if it is inserted.
2117 Otherwise, display it in another buffer."
2119 (let ((file (dired-get-file-for-visit)))
2120 (if (file-directory-p file
)
2121 (or (and (cdr dired-subdir-alist
)
2122 (dired-goto-subdir file
))
2126 (defun dired-find-file-other-window ()
2127 "In Dired, visit this file or directory in another window."
2129 (find-file-other-window (dired-get-file-for-visit)))
2131 (defun dired-display-file ()
2132 "In Dired, display this file or directory in another window."
2134 (display-buffer (find-file-noselect (dired-get-file-for-visit))))
2136 ;;; Functions for extracting and manipulating file names in Dired buffers.
2138 (defun dired-get-filename (&optional localp no-error-if-not-filep
)
2139 "In Dired, return name of file mentioned on this line.
2140 Value returned normally includes the directory name.
2141 Optional arg LOCALP with value `no-dir' means don't include directory
2142 name in result. A value of `verbatim' means to return the name exactly as
2143 it occurs in the buffer, and a value of t means construct name relative to
2144 `default-directory', which still may contain slashes if in a subdirectory.
2145 Optional arg NO-ERROR-IF-NOT-FILEP means treat `.' and `..' as
2146 regular filenames and return nil if no filename on this line.
2147 Otherwise, an error occurs in these cases."
2148 (let (case-fold-search file p1 p2 already-absolute
)
2150 (if (setq p1
(dired-move-to-filename (not no-error-if-not-filep
)))
2151 (setq p2
(dired-move-to-end-of-filename no-error-if-not-filep
))))
2152 ;; nil if no file on this line, but no-error-if-not-filep is t:
2153 (if (setq file
(and p1 p2
(buffer-substring p1 p2
)))
2155 ;; Get rid of the mouse-face property that file names have.
2156 (set-text-properties 0 (length file
) nil file
)
2157 ;; Unquote names quoted by ls or by dired-insert-directory.
2158 ;; This code was written using `read' to unquote, because
2159 ;; it's faster than substituting \007 (4 chars) -> ^G (1
2160 ;; char) etc. in a lisp loop. Unfortunately, this decision
2161 ;; has necessitated hacks such as dealing with filenames
2162 ;; with quotation marks in their names.
2163 (while (string-match "\\(?:[^\\]\\|\\`\\)\\(\"\\)" file
)
2164 (setq file
(replace-match "\\\"" nil t file
1)))
2165 ;; Unescape any spaces escaped by ls -b (bug#10469).
2166 ;; Other -b quotes, eg \t, \n, work transparently.
2167 (if (dired-switches-escape-p dired-actual-switches
)
2171 (if (eq localp
'verbatim
)
2174 (while (string-match "\\(\\\\\\) " file start
)
2175 (setq file
(replace-match rep nil t file
1)
2176 start
(+ shift
(match-end 0))))))
2177 (when (eq system-type
'windows-nt
)
2180 (while (string-match "\\\\" file start
)
2181 (aset file
(match-beginning 0) ?
/)
2182 (setq start
(match-end 0))))))
2184 ;; Hence we don't need to worry about converting `\\' back to `\'.
2185 (setq file
(read (concat "\"" file
"\"")))
2186 ;; The above `read' will return a unibyte string if FILE
2187 ;; contains eight-bit-control/graphic characters.
2188 (if (and enable-multibyte-characters
2189 (not (multibyte-string-p file
)))
2190 (setq file
(string-to-multibyte file
)))))
2191 (and file
(file-name-absolute-p file
)
2192 ;; A relative file name can start with ~.
2193 ;; Don't treat it as absolute in this context.
2194 (not (eq (aref file
0) ?~
))
2195 (setq already-absolute t
))
2199 ((eq localp
'verbatim
)
2201 ((and (not no-error-if-not-filep
)
2202 (member file
'("." "..")))
2203 (error "Cannot operate on `.' or `..'"))
2204 ((and (eq localp
'no-dir
) already-absolute
)
2205 (file-name-nondirectory file
))
2207 (let ((handler (find-file-name-handler file nil
)))
2208 ;; check for safe-magic property so that we won't
2209 ;; put /: for names that don't really need them.
2210 ;; For instance, .gz files when auto-compression-mode is on.
2211 (if (and handler
(not (get handler
'safe-magic
)))
2214 ((eq localp
'no-dir
)
2216 ((equal (dired-current-directory) "/")
2217 (setq file
(concat (dired-current-directory localp
) file
))
2218 (let ((handler (find-file-name-handler file nil
)))
2219 ;; check for safe-magic property so that we won't
2220 ;; put /: for names that don't really need them.
2221 ;; For instance, .gz files when auto-compression-mode is on.
2222 (if (and handler
(not (get handler
'safe-magic
)))
2226 (concat (dired-current-directory localp
) file
)))))
2228 (defun dired-string-replace-match (regexp string newtext
2229 &optional literal global
)
2230 "Replace first match of REGEXP in STRING with NEWTEXT.
2231 If it does not match, nil is returned instead of the new string.
2232 Optional arg LITERAL means to take NEWTEXT literally.
2233 Optional arg GLOBAL means to replace all matches."
2235 (let ((start 0) ret
)
2236 (while (string-match regexp string start
)
2237 (let ((from-end (- (length string
) (match-end 0))))
2238 (setq ret
(setq string
(replace-match newtext t literal string
)))
2239 (setq start
(- (length string
) from-end
))))
2241 (if (not (string-match regexp string
0))
2243 (replace-match newtext t literal string
))))
2245 (defun dired-make-absolute (file &optional dir
)
2246 ;;"Convert FILE (a file name relative to DIR) to an absolute file name."
2247 ;; We can't always use expand-file-name as this would get rid of `.'
2248 ;; or expand in / instead default-directory if DIR=="".
2249 ;; This should be good enough for ange-ftp.
2250 ;; It should be reasonably fast, though, as it is called in
2251 ;; dired-get-filename.
2252 (concat (or dir default-directory
) file
))
2254 (defun dired-make-relative (file &optional dir
)
2255 "Convert FILE (an absolute file name) to a name relative to DIR.
2256 If DIR is omitted or nil, it defaults to `default-directory'.
2257 If FILE is not in the directory tree of DIR, return FILE
2259 (or dir
(setq dir default-directory
))
2260 ;; This case comes into play if default-directory is set to
2262 (if (and (> (length dir
) 0) (= (aref dir
0) ?~
))
2263 (setq dir
(expand-file-name dir
)))
2264 (if (string-match (concat "^" (regexp-quote dir
)) file
)
2265 (substring file
(match-end 0))
2268 ;;; Minor mode for hiding details
2270 (define-minor-mode dired-hide-details-mode
2271 "Hide details in Dired mode."
2273 (unless (derived-mode-p 'dired-mode
)
2274 (error "Not a Dired buffer"))
2275 (dired-hide-details-update-invisibility-spec)
2276 (if dired-hide-details-mode
2277 (add-hook 'wdired-mode-hook
2278 'dired-hide-details-update-invisibility-spec
2281 (remove-hook 'wdired-mode-hook
2282 'dired-hide-details-update-invisibility-spec
2285 (defun dired-hide-details-update-invisibility-spec ()
2286 (funcall (if dired-hide-details-mode
2287 'add-to-invisibility-spec
2288 'remove-from-invisibility-spec
)
2289 'dired-hide-details-detail
)
2290 (funcall (if (and dired-hide-details-mode
2291 dired-hide-details-hide-information-lines
)
2292 'add-to-invisibility-spec
2293 'remove-from-invisibility-spec
)
2294 'dired-hide-details-information
)
2295 (funcall (if (and dired-hide-details-mode
2296 dired-hide-details-hide-symlink-targets
2297 (not (derived-mode-p 'wdired-mode
)))
2298 'add-to-invisibility-spec
2299 'remove-from-invisibility-spec
)
2300 'dired-hide-details-link
))
2302 ;;; Functions for finding the file name in a dired buffer line.
2304 (defvar dired-permission-flags-regexp
2305 "\\([^ ]\\)[-r][-w]\\([^ ]\\)[-r][-w]\\([^ ]\\)[-r][-w]\\([^ ]\\)"
2306 "Regular expression to match the permission flags in `ls -l'.")
2308 ;; Move to first char of filename on this line.
2309 ;; Returns position (point) or nil if no filename on this line."
2310 (defun dired-move-to-filename (&optional raise-error eol
)
2311 "Move to the beginning of the filename on the current line.
2312 Return the position of the beginning of the filename, or nil if none found."
2313 ;; This is the UNIX version.
2314 (or eol
(setq eol
(line-end-position)))
2316 ;; First try assuming `ls --dired' was used.
2317 (let ((change (next-single-property-change (point) 'dired-filename nil eol
)))
2319 ((and change
(< change eol
))
2321 ((re-search-forward directory-listing-before-filename-regexp eol t
)
2322 (goto-char (match-end 0)))
2323 ((re-search-forward dired-permission-flags-regexp eol t
)
2324 ;; Ha! There *is* a file. Our regexp-from-hell just failed to find it.
2326 (error "Unrecognized line! Check directory-listing-before-filename-regexp"))
2330 (error "No file on this line")))))
2332 (defun dired-move-to-end-of-filename (&optional no-error
)
2333 ;; Assumes point is at beginning of filename,
2334 ;; thus the rwx bit re-search-backward below will succeed in *this*
2335 ;; line if at all. So, it should be called only after
2336 ;; (dired-move-to-filename t).
2337 ;; On failure, signals an error (with non-nil NO-ERROR just returns nil).
2338 ;; This is the UNIX version.
2339 (if (get-text-property (point) 'dired-filename
)
2340 (goto-char (next-single-property-change (point) 'dired-filename
))
2341 (let (opoint file-type executable symlink hidden case-fold-search used-F eol
)
2342 ;; case-fold-search is nil now, so we can test for capital F:
2343 (setq used-F
(string-match-p "F" dired-actual-switches
)
2345 eol
(line-end-position)
2346 hidden
(and selective-display
2347 (save-excursion (search-forward "\r" eol t
))))
2350 (save-excursion ;; Find out what kind of file this is:
2351 ;; Restrict perm bits to be non-blank,
2352 ;; otherwise this matches one char to early (looking backward):
2353 ;; "l---------" (some systems make symlinks that way)
2354 ;; "----------" (plain file with zero perms)
2355 (if (re-search-backward
2356 dired-permission-flags-regexp nil t
)
2357 (setq file-type
(char-after (match-beginning 1))
2358 symlink
(eq file-type ?l
)
2359 ;; Only with -F we need to know whether it's an executable
2363 "[xst]" ;; execute bit set anywhere?
2367 (match-string 4)))))
2368 (or no-error
(error "No file on this line"))))
2369 ;; Move point to end of name:
2371 (if (search-forward " -> " eol t
)
2375 dired-ls-F-marks-symlinks
2376 (eq (preceding-char) ?
@) ;; did ls really mark the link?
2377 (forward-char -
1))))
2378 (goto-char eol
) ;; else not a symbolic link
2379 ;; ls -lF marks dirs, sockets, fifos and executables with exactly
2380 ;; one trailing character. (Executable bits on symlinks ain't mean
2381 ;; a thing, even to ls, but we know it's not a symlink.)
2383 (or (memq file-type
'(?d ?s ?p
))
2385 (forward-char -
1))))
2387 (not (eq opoint
(point)))
2388 (error "%s" (if hidden
2389 (substitute-command-keys
2390 "File line is hidden, type \\[dired-hide-subdir] to unhide")
2391 "No file on this line")))
2392 (if (eq opoint
(point))
2397 ;;; COPY NAMES OF MARKED FILES INTO KILL-RING.
2399 (defun dired-copy-filename-as-kill (&optional arg
)
2400 "Copy names of marked (or next ARG) files into the kill ring.
2401 The names are separated by a space.
2402 With a zero prefix arg, use the absolute file name of each marked file.
2403 With \\[universal-argument], use the file name relative to the Dired buffer's
2404 `default-directory'. (This still may contain slashes if in a subdirectory.)
2406 If on a subdir headerline, use absolute subdirname instead;
2407 prefix arg and marked files are ignored in this case.
2409 You can then feed the file name(s) to other commands with \\[yank]."
2412 (or (dired-get-subdir)
2413 (mapconcat (function identity
)
2415 (cond ((zerop (prefix-numeric-value arg
))
2416 (dired-get-marked-files))
2418 (dired-get-marked-files t
))
2420 (dired-get-marked-files
2421 'no-dir
(prefix-numeric-value arg
))))
2422 (dired-get-marked-files 'no-dir
))
2424 (if (eq last-command
'kill-region
)
2425 (kill-append string nil
)
2427 (message "%s" string
)))
2430 ;; Keeping Dired buffers in sync with the filesystem and with each other
2432 (defun dired-buffers-for-dir (dir &optional file
)
2433 ;; Return a list of buffers for DIR (top level or in-situ subdir).
2434 ;; If FILE is non-nil, include only those whose wildcard pattern (if any)
2436 ;; The list is in reverse order of buffer creation, most recent last.
2437 ;; As a side effect, killed dired buffers for DIR are removed from
2439 (setq dir
(file-name-as-directory dir
))
2441 (dolist (elt dired-buffers
)
2442 (setq buf
(cdr elt
))
2444 ((null (buffer-name buf
))
2445 ;; Buffer is killed - clean up:
2446 (setq dired-buffers
(delq elt dired-buffers
)))
2447 ((dired-in-this-tree dir
(car elt
))
2448 (with-current-buffer buf
2449 (and (assoc dir dired-subdir-alist
)
2451 (if (stringp dired-directory
)
2452 (let ((wildcards (file-name-nondirectory
2454 (or (zerop (length wildcards
))
2455 (string-match-p (dired-glob-regexp wildcards
)
2457 (member (expand-file-name file dir
)
2458 (cdr dired-directory
))))
2459 (setq result
(cons buf result
)))))))
2462 (defun dired-glob-regexp (pattern)
2463 "Convert glob-pattern PATTERN to a regular expression."
2464 (let ((matched-in-pattern 0) ;; How many chars of PATTERN we've handled.
2466 (while (string-match "[[?*]" pattern matched-in-pattern
)
2467 (let ((op-end (match-end 0))
2468 (next-op (aref pattern
(match-beginning 0))))
2469 (setq regexp
(concat regexp
2471 (substring pattern matched-in-pattern
2472 (match-beginning 0)))))
2473 (cond ((= next-op ??
)
2474 (setq regexp
(concat regexp
"."))
2475 (setq matched-in-pattern op-end
))
2477 ;; Fails to handle ^ yet ????
2478 (let* ((set-start (match-beginning 0))
2480 (if (= (aref pattern
(1+ set-start
)) ?^
)
2483 (set-end (string-match-p "]" pattern set-cont
))
2484 (set (substring pattern set-start
(1+ set-end
))))
2485 (setq regexp
(concat regexp set
))
2486 (setq matched-in-pattern
(1+ set-end
))))
2488 (setq regexp
(concat regexp
".*"))
2489 (setq matched-in-pattern op-end
)))))
2493 (substring pattern matched-in-pattern
))
2498 (defun dired-advertise ()
2499 ;;"Advertise in variable `dired-buffers' that we dired `default-directory'."
2500 ;; With wildcards we actually advertise too much.
2501 (let ((expanded-default (expand-file-name default-directory
)))
2502 (if (memq (current-buffer) (dired-buffers-for-dir expanded-default
))
2503 t
; we have already advertised ourselves
2505 (cons (cons expanded-default
(current-buffer))
2508 (defun dired-unadvertise (dir)
2509 ;; Remove DIR from the buffer alist in variable dired-buffers.
2510 ;; This has the effect of removing any buffer whose main directory is DIR.
2511 ;; It does not affect buffers in which DIR is a subdir.
2512 ;; Removing is also done as a side-effect in dired-buffer-for-dir.
2514 (delq (assoc (expand-file-name dir
) dired-buffers
) dired-buffers
)))
2518 ;;; utility functions
2520 (defun dired-in-this-tree (file dir
)
2521 ;;"Is FILE part of the directory tree starting at DIR?"
2522 (let (case-fold-search)
2523 (string-match-p (concat "^" (regexp-quote dir
)) file
)))
2525 (defun dired-normalize-subdir (dir)
2526 ;; Prepend default-directory to DIR if relative file name.
2527 ;; dired-get-filename must be able to make a valid file name from a
2528 ;; file and its directory DIR.
2529 (file-name-as-directory
2530 (if (file-name-absolute-p dir
)
2532 (expand-file-name dir default-directory
))))
2534 (defun dired-get-subdir ()
2535 ;;"Return the subdir name on this line, or nil if not on a headerline."
2536 ;; Look up in the alist whether this is a headerline.
2538 (let ((cur-dir (dired-current-directory)))
2539 (beginning-of-line) ; alist stores b-o-l positions
2540 (and (zerop (- (point)
2541 (dired-get-subdir-min (assoc cur-dir
2542 dired-subdir-alist
))))
2545 ;; can't use macro, must be redefinable for other alist format in dired-nstd.
2546 (defalias 'dired-get-subdir-min
'cdr
)
2548 (defun dired-get-subdir-max (elt)
2550 (goto-char (dired-get-subdir-min elt
))
2551 (dired-subdir-max)))
2553 (defun dired-clear-alist ()
2554 (while dired-subdir-alist
2555 (set-marker (dired-get-subdir-min (car dired-subdir-alist
)) nil
)
2556 (setq dired-subdir-alist
(cdr dired-subdir-alist
))))
2558 (defun dired-subdir-index (dir)
2559 ;; Return an index into alist for use with nth
2560 ;; for the sake of subdir moving commands.
2561 (let (found (index 0) (alist dired-subdir-alist
))
2563 (if (string= dir
(car (car alist
)))
2564 (setq alist nil found t
)
2565 (setq alist
(cdr alist
) index
(1+ index
))))
2566 (if found index nil
)))
2568 (defun dired-next-subdir (arg &optional no-error-if-not-found no-skip
)
2569 "Go to next subdirectory, regardless of level."
2570 ;; Use 0 arg to go to this directory's header line.
2571 ;; NO-SKIP prevents moving to end of header line, returning whatever
2572 ;; position was found in dired-subdir-alist.
2574 (let ((this-dir (dired-current-directory))
2576 ;; nth with negative arg does not return nil but the first element
2577 (setq index
(- (dired-subdir-index this-dir
) arg
))
2578 (setq pos
(if (>= index
0)
2579 (dired-get-subdir-min (nth index dired-subdir-alist
))))
2583 (or no-skip
(skip-chars-forward "^\n\r"))
2585 (if no-error-if-not-found
2586 nil
; return nil if not found
2587 (error "%s directory" (if (> arg
0) "Last" "First"))))))
2589 (defun dired-build-subdir-alist (&optional switches
)
2590 "Build `dired-subdir-alist' by parsing the buffer.
2591 Returns the new value of the alist.
2592 If optional arg SWITCHES is non-nil, use its value
2593 instead of `dired-actual-switches'."
2598 (inhibit-read-only t
)
2599 (buffer-undo-list t
)
2600 (switches (or switches dired-actual-switches
))
2602 (R-ftp-base-dir-regex
2603 ;; Used to expand subdirectory names correctly in recursive
2604 ;; ange-ftp listings.
2605 (and (string-match-p "R" switches
)
2606 (string-match "\\`/.*:\\(/.*\\)" default-directory
)
2607 (concat "\\`" (match-string 1 default-directory
)))))
2608 (goto-char (point-min))
2609 (setq dired-subdir-alist nil
)
2610 (while (re-search-forward dired-subdir-regexp nil t
)
2611 ;; Avoid taking a file name ending in a colon
2612 ;; as a subdir name.
2613 (unless (save-excursion
2614 (goto-char (match-beginning 0))
2617 (looking-at-p dired-re-perms
))
2619 (goto-char (match-beginning 1))
2621 (buffer-substring-no-properties (point) (match-end 1))
2624 (if (and R-ftp-base-dir-regex
2625 (not (string= new-dir-name default-directory
))
2626 (string-match R-ftp-base-dir-regex new-dir-name
))
2627 (concat default-directory
2628 (substring new-dir-name
(match-end 0)))
2629 (expand-file-name new-dir-name
))))
2630 (delete-region (point) (match-end 1))
2631 (insert new-dir-name
))
2632 (setq count
(1+ count
))
2633 ;; Undo any escaping of newlines and \ by dired-insert-directory.
2634 ;; Convert "n" preceded by odd number of \ to newline, and \\ to \.
2635 (when (and (dired-switches-escape-p switches
)
2636 (string-match-p "\\\\" new-dir-name
))
2638 (mapc (lambda (char)
2639 (cond ((equal char ?
\\)
2641 (setq res
(concat res
"\\")
2644 ((and temp
(equal char ?n
))
2645 (setq res
(concat res
"\n")
2648 (setq res
(concat res temp
(char-to-string char
))
2651 (setq new-dir-name res
)))
2652 (dired-alist-add-1 new-dir-name
2653 ;; Place a sub directory boundary between lines.
2655 (goto-char (match-beginning 0))
2658 (if (and (> count
1) (called-interactively-p 'interactive
))
2659 (message "Buffer includes %d directories" count
)))
2660 ;; We don't need to sort it because it is in buffer order per
2661 ;; constructionem. Return new alist:
2662 dired-subdir-alist
))
2664 (defun dired-alist-add-1 (dir new-marker
)
2665 ;; Add new DIR at NEW-MARKER. Don't sort.
2666 (setq dired-subdir-alist
2667 (cons (cons (dired-normalize-subdir dir
) new-marker
)
2668 dired-subdir-alist
)))
2670 (defun dired-goto-next-nontrivial-file ()
2671 ;; Position point on first nontrivial file after point.
2672 (dired-goto-next-file);; so there is a file to compare with
2673 (if (stringp dired-trivial-filenames
)
2674 (while (and (not (eobp))
2675 (string-match-p dired-trivial-filenames
2676 (file-name-nondirectory
2677 (or (dired-get-filename nil t
) ""))))
2679 (dired-move-to-filename))))
2681 (defun dired-goto-next-file ()
2682 (let ((max (1- (dired-subdir-max))))
2683 (while (and (not (dired-move-to-filename)) (< (point) max
))
2686 (defun dired-goto-file (file)
2687 "Go to line describing file FILE in this Dired buffer."
2688 ;; Return value of point on success, else nil.
2689 ;; FILE must be an absolute file name.
2690 ;; Loses if FILE contains control chars like "\007" for which ls
2691 ;; either inserts "?" or "\\007" into the buffer, so we won't find
2692 ;; it in the buffer.
2694 (prog1 ; let push-mark display its message
2695 (list (expand-file-name
2696 (read-file-name "Goto file: "
2697 (dired-current-directory))))
2699 (unless (file-name-absolute-p file
)
2700 (error "File name `%s' is not absolute" file
))
2701 (setq file
(directory-file-name file
)) ; does no harm if not a directory
2702 (let* ((case-fold-search nil
)
2703 (dir (file-name-directory file
))
2705 ;; First, look for a listing under the absolute name.
2707 (goto-char (point-min))
2708 (dired-goto-file-1 file file
(point-max)))
2709 ;; Otherwise, look for it as a relative name. The
2710 ;; hair is to get the result of `dired-goto-subdir'
2711 ;; without calling it if we don't have any subdirs.
2713 (when (if (string= dir
(expand-file-name default-directory
))
2714 (goto-char (point-min))
2715 (and (cdr dired-subdir-alist
)
2716 (dired-goto-subdir dir
)))
2717 (dired-goto-file-1 (file-name-nondirectory file
)
2719 (dired-subdir-max)))))))
2720 ;; Return buffer position, if found.
2722 (goto-char found
))))
2724 (defun dired-goto-file-1 (file full-name limit
)
2725 "Advance to the Dired listing labeled by FILE; return its position.
2726 Return nil if the listing is not found. If FILE contains
2727 characters that would not appear in a Dired buffer, search using
2728 the quoted forms of those characters.
2730 FULL-NAME specifies the actual file name the listing must have,
2731 as returned by `dired-get-filename'. LIMIT is the search limit."
2733 (setq str
(replace-regexp-in-string "\^m" "\\^m" file nil t
))
2734 (setq str
(replace-regexp-in-string "\\\\" "\\\\" str nil t
))
2735 (and (dired-switches-escape-p dired-actual-switches
)
2736 (string-match-p "[ \t\n]" str
)
2737 ;; FIXME: to fix this for embedded control characters etc, we
2738 ;; should escape everything that `ls -b' does.
2739 (setq str
(replace-regexp-in-string " " "\\ " str nil t
)
2740 str
(replace-regexp-in-string "\t" "\\t" str nil t
)
2741 str
(replace-regexp-in-string "\n" "\\n" str nil t
)))
2743 ;; filenames are preceded by SPC, this makes the search faster
2744 ;; (e.g. for the filename "-").
2745 (search-string (concat " " str
)))
2746 (while (and (not found
)
2747 (search-forward search-string limit
'move
))
2748 ;; Check that we are in the right place. Match could have
2749 ;; BASE just as initial substring or in permission bits etc.
2750 (if (equal full-name
(dired-get-filename nil t
))
2751 (setq found
(dired-move-to-filename))
2755 (defvar dired-find-subdir
)
2757 ;; FIXME document whatever dired-x is doing.
2758 (defun dired-initial-position (dirname)
2759 "Where point should go in a new listing of DIRNAME.
2760 Point assumed at beginning of new subdir line.
2761 It runs the hook `dired-initial-position-hook'."
2763 (and (featurep 'dired-x
) dired-find-subdir
2764 (dired-goto-subdir dirname
))
2765 (if dired-trivial-filenames
(dired-goto-next-nontrivial-file))
2766 (run-hooks 'dired-initial-point-hook
))
2768 ;; These are hooks which make tree dired work.
2769 ;; They are in this file because other parts of dired need to call them.
2770 ;; But they don't call the rest of tree dired unless there are subdirs loaded.
2772 ;; This function is called for each retrieved filename.
2773 ;; It could stand to be faster, though it's mostly function call
2774 ;; overhead. Avoiding the function call seems to save about 10% in
2775 ;; dired-get-filename. Make it a defsubst?
2776 (defun dired-current-directory (&optional localp
)
2777 "Return the name of the subdirectory to which this line belongs.
2778 This returns a string with trailing slash, like `default-directory'.
2779 Optional argument means return a file name relative to `default-directory'."
2780 (let ((here (point))
2781 (alist (or dired-subdir-alist
2782 ;; probably because called in a non-dired buffer
2783 (error "No subdir-alist in %s" (current-buffer))))
2786 (setq elt
(car alist
)
2788 ;; use `<=' (not `<') as subdir line is part of subdir
2789 alist
(if (<= (dired-get-subdir-min elt
) here
)
2793 (dired-make-relative dir default-directory
)
2796 ;; Subdirs start at the beginning of their header lines and end just
2797 ;; before the beginning of the next header line (or end of buffer).
2799 (defun dired-subdir-max ()
2801 (if (or (null (cdr dired-subdir-alist
)) (not (dired-next-subdir 1 t t
)))
2807 (defcustom dired-recursive-deletes
'top
2808 "Whether Dired deletes directories recursively.
2809 If nil, Dired will not delete non-empty directories.
2810 `always' means to delete non-empty directories recursively,
2811 without asking. This is dangerous!
2812 `top' means to ask for each top-level directory specified by the
2813 Dired deletion command, and delete its subdirectories without
2815 Any other value means to ask for each directory."
2816 :type
'(choice :tag
"Delete non-empty directories"
2817 (const :tag
"Yes" always
)
2818 (const :tag
"No--only delete empty directories" nil
)
2819 (const :tag
"Confirm for each directory" t
)
2820 (const :tag
"Confirm for each top directory only" top
))
2823 ;; Match anything but `.' and `..'.
2824 (defvar dired-re-no-dot
"^\\([^.]\\|\\.\\([^.]\\|\\..\\)\\).*")
2826 ;; Delete file, possibly delete a directory and all its files.
2827 ;; This function is useful outside of dired. One could change its name
2828 ;; to e.g. recursive-delete-file and put it somewhere else.
2829 (defun dired-delete-file (file &optional recursive trash
) "\
2830 Delete FILE or directory (possibly recursively if optional RECURSIVE is true.)
2831 RECURSIVE determines what to do with a non-empty directory. If RECURSIVE is:
2833 `always', delete recursively without asking.
2834 `top', ask for each directory at top level.
2835 Anything else, ask for each sub-directory."
2836 ;; This test is equivalent to
2837 ;; (and (file-directory-p fn) (not (file-symlink-p fn)))
2838 ;; but more efficient
2839 (if (not (eq t
(car (file-attributes file
))))
2840 (delete-file file trash
)
2842 (directory-files file t dired-re-no-dot
) ; Not empty.
2843 (or (eq recursive
'always
)
2844 (yes-or-no-p (format "Recursively %s %s? "
2846 delete-by-moving-to-trash
)
2849 (dired-make-relative file
)))))
2850 (if (eq recursive
'top
) (setq recursive
'always
)) ; Don't ask again.
2851 (setq recursive nil
))
2852 (delete-directory file recursive trash
)))
2854 (defun dired-do-flagged-delete (&optional nomessage
)
2855 "In Dired, delete the files flagged for deletion.
2856 If NOMESSAGE is non-nil, we don't display any message
2857 if there are no flagged files.
2858 `dired-recursive-deletes' controls whether deletion of
2859 non-empty directories is allowed."
2861 (let* ((dired-marker-char dired-del-marker
)
2862 (regexp (dired-marker-regexp))
2864 (if (save-excursion (goto-char (point-min))
2865 (re-search-forward regexp nil t
))
2866 (dired-internal-do-deletions
2867 ;; this can't move point since ARG is nil
2868 (dired-map-over-marks (cons (dired-get-filename) (point))
2872 (message "(No deletions requested)")))))
2874 (defun dired-do-delete (&optional arg
)
2875 "Delete all marked (or next ARG) files.
2876 `dired-recursive-deletes' controls whether deletion of
2877 non-empty directories is allowed."
2878 ;; This is more consistent with the file marking feature than
2879 ;; dired-do-flagged-delete.
2881 (dired-internal-do-deletions
2882 ;; this may move point if ARG is an integer
2883 (dired-map-over-marks (cons (dired-get-filename) (point))
2887 (defvar dired-deletion-confirmer
'yes-or-no-p
) ; or y-or-n-p?
2889 (defun dired-internal-do-deletions (l arg
&optional trash
)
2890 ;; L is an alist of files to delete, with their buffer positions.
2891 ;; ARG is the prefix arg.
2892 ;; Filenames are absolute.
2893 ;; (car L) *must* be the *last* (bottommost) file in the dired buffer.
2894 ;; That way as changes are made in the buffer they do not shift the
2895 ;; lines still to be changed, so the (point) values in L stay valid.
2896 ;; Also, for subdirs in natural order, a subdir's files are deleted
2897 ;; before the subdir itself - the other way around would not work.
2898 (let* ((files (mapcar (function car
) l
))
2901 (trashing (and trash delete-by-moving-to-trash
))
2903 (make-progress-reporter
2904 (if trashing
"Trashing..." "Deleting...")
2906 ;; canonicalize file list for pop up
2907 (setq files
(nreverse (mapcar (function dired-make-relative
) files
)))
2908 (if (dired-mark-pop-up
2909 " *Deletions*" 'delete files dired-deletion-confirmer
2911 (if trashing
"Trash" "Delete")
2912 (dired-mark-prompt arg files
)))
2914 (let (failures);; files better be in reverse order for this loop!
2916 (goto-char (cdr (car l
)))
2917 (let ((inhibit-read-only t
))
2919 (let ((fn (car (car l
))))
2920 (dired-delete-file fn dired-recursive-deletes trash
)
2921 ;; if we get here, removing worked
2922 (setq succ
(1+ succ
))
2923 (progress-reporter-update progress-reporter succ
)
2924 (dired-fun-in-all-buffers
2925 (file-name-directory fn
) (file-name-nondirectory fn
)
2926 (function dired-delete-entry
) fn
))
2927 (error;; catch errors from failed deletions
2928 (dired-log "%s\n" err
)
2929 (setq failures
(cons (car (car l
)) failures
)))))
2932 (progress-reporter-done progress-reporter
)
2934 (format "%d of %d deletion%s failed"
2935 (length failures
) count
2936 (dired-plural-s count
))
2938 (message "(No deletions performed)")))
2939 (dired-move-to-filename))
2941 (defun dired-fun-in-all-buffers (directory file fun
&rest args
)
2942 ;; In all buffers dired'ing DIRECTORY, run FUN with ARGS.
2943 ;; If the buffer has a wildcard pattern, check that it matches FILE.
2944 ;; (FILE does not include a directory component.)
2945 ;; FILE may be nil, in which case ignore it.
2946 ;; Return list of buffers where FUN succeeded (i.e., returned non-nil).
2948 (dolist (buf (dired-buffers-for-dir (expand-file-name directory
)
2950 (with-current-buffer buf
2951 (if (apply fun args
)
2952 (setq success-list
(cons (buffer-name buf
) success-list
)))))
2955 ;; Delete the entry for FILE from
2956 (defun dired-delete-entry (file)
2958 (and (dired-goto-file file
)
2959 (let ((inhibit-read-only t
))
2960 (delete-region (progn (beginning-of-line) (point))
2961 (save-excursion (forward-line 1) (point))))))
2962 (dired-clean-up-after-deletion file
))
2964 (defvar dired-clean-up-buffers-too
)
2966 (defun dired-clean-up-after-deletion (fn)
2967 "Clean up after a deleted file or directory FN.
2968 Removes any expanded subdirectory of deleted directory.
2969 If `dired-x' is loaded and `dired-clean-up-buffers-too' is non-nil,
2970 also offers to kill buffers visiting deleted files and directories."
2971 (save-excursion (and (cdr dired-subdir-alist
)
2972 (dired-goto-subdir fn
)
2973 (dired-kill-subdir)))
2974 ;; Offer to kill buffer of deleted file FN.
2975 (when (and (featurep 'dired-x
) dired-clean-up-buffers-too
)
2976 (let ((buf (get-file-buffer fn
)))
2979 (format "Kill buffer of %s, too? "
2980 (file-name-nondirectory fn
)))
2982 (let ((buf-list (dired-buffers-for-dir (expand-file-name fn
))))
2984 (y-or-n-p (format "Kill Dired buffer%s of %s, too? "
2985 (dired-plural-s (length buf-list
))
2986 (file-name-nondirectory fn
)))
2987 (dolist (buf buf-list
)
2988 (kill-buffer buf
))))))
2993 (defun dired-marker-regexp ()
2994 (concat "^" (regexp-quote (char-to-string dired-marker-char
))))
2996 (defun dired-plural-s (count)
2997 (if (= 1 count
) "" "s"))
2999 (defun dired-mark-prompt (arg files
)
3000 "Return a string suitable for use in a Dired prompt.
3001 ARG is normally the prefix argument for the calling command.
3002 FILES should be a list of file names.
3004 The return value has a form like \"foo.txt\", \"[next 3 files]\",
3005 or \"* [3 files]\"."
3006 ;; distinguish-one-marked can cause the first element to be just t.
3007 (if (eq (car files
) t
) (setq files
(cdr files
)))
3008 (let ((count (length files
)))
3011 ;; more than 1 file:
3014 ;; Perhaps this is nicer, but it also takes more screen space:
3015 ;;(format "[%s %d files]" (if (> arg 0) "next" "previous")
3017 (format "[next %d files]" arg
)
3018 (format "%c [%d files]" dired-marker-char count
)))))
3020 (defun dired-pop-to-buffer (buf)
3021 "Pop up buffer BUF in a way suitable for Dired."
3022 (declare (obsolete dired-mark-pop-up
"24.3"))
3023 (let ((split-window-preferred-function
3025 (or (and (let ((split-height-threshold 0))
3026 (window-splittable-p (selected-window)))
3027 ;; Try to split the selected window vertically if
3028 ;; that's possible. (Bug#1806)
3029 (split-window-below))
3030 ;; Otherwise, try to split WINDOW sensibly.
3031 (split-window-sensibly window
))))
3033 (pop-to-buffer (get-buffer-create buf
)))
3035 (set-window-start nil
(point-min))
3036 ;; If dired-shrink-to-fit is t, make its window fit its contents.
3037 (when dired-shrink-to-fit
3038 ;; Try to not delete window when we want to display less than
3039 ;; `window-min-height' lines.
3040 (fit-window-to-buffer (get-buffer-window buf
) nil
1)))
3042 (defcustom dired-no-confirm nil
3043 "A list of symbols for commands Dired should not confirm, or t.
3044 Command symbols are `byte-compile', `chgrp', `chmod', `chown', `compress',
3045 `copy', `delete', `hardlink', `load', `move', `print', `shell', `symlink',
3046 `touch' and `uncompress'.
3047 If t, confirmation is never needed."
3049 :type
'(choice (const :tag
"Confirmation never needed" t
)
3050 (set (const byte-compile
) (const chgrp
)
3051 (const chmod
) (const chown
) (const compress
)
3052 (const copy
) (const delete
) (const hardlink
)
3053 (const load
) (const move
) (const print
)
3054 (const shell
) (const symlink
) (const touch
)
3055 (const uncompress
))))
3057 (defun dired-mark-pop-up (buffer-or-name op-symbol files function
&rest args
)
3058 "Return FUNCTION's result on ARGS after showing which files are marked.
3059 Displays the file names in a window showing a buffer named
3060 BUFFER-OR-NAME; the default name being \" *Marked Files*\". The
3061 window is not shown if there is just one file, `dired-no-confirm'
3062 is t, or OP-SYMBOL is a member of the list in `dired-no-confirm'.
3064 By default, Dired shrinks the display buffer to fit the marked files.
3065 To disable this, use the Customization interface to add a new rule
3066 to `display-buffer-alist' where condition regexp is \"^ \\*Marked Files\\*$\",
3067 action argument symbol is `window-height' and its value is nil.
3069 FILES is the list of marked files. It can also be (t FILENAME)
3070 in the case of one marked file, to distinguish that from using
3071 just the current file.
3073 FUNCTION should not manipulate files, just read input (an
3074 argument or confirmation)."
3075 (if (or (eq dired-no-confirm t
)
3076 (memq op-symbol dired-no-confirm
)
3077 ;; If FILES defaulted to the current line's file.
3078 (= (length files
) 1))
3079 (apply function args
)
3080 (let ((buffer (get-buffer-create (or buffer-or-name
" *Marked Files*"))))
3081 (with-current-buffer buffer
3082 (let ((split-height-threshold 0))
3083 (with-temp-buffer-window
3085 (cons 'display-buffer-below-selected
3086 '((window-height . fit-window-to-buffer
)))
3087 #'(lambda (window _value
)
3088 (with-selected-window window
3090 (apply function args
)
3091 (when (window-live-p window
)
3092 (quit-restore-window window
'kill
)))))
3093 ;; Handle (t FILE) just like (FILE), here. That value is
3094 ;; used (only in some cases), to mean just one file that was
3095 ;; marked, rather than the current line file.
3096 (dired-format-columns-of-files
3097 (if (eq (car files
) t
) (cdr files
) files
))
3098 (remove-text-properties (point-min) (point-max)
3099 '(mouse-face nil help-echo nil
))))))))
3101 (defun dired-format-columns-of-files (files)
3102 (let ((beg (point)))
3103 (completion--insert-strings files
)
3104 (put-text-property beg
(point) 'mouse-face nil
)))
3106 ;; Commands to mark or flag file(s) at or near current line.
3108 (defun dired-repeat-over-lines (arg function
)
3109 ;; This version skips non-file lines.
3110 (let ((pos (make-marker)))
3112 (while (and (> arg
0) (not (eobp)))
3115 (while (and (not (eobp)) (dired-between-files)) (forward-line 1))
3118 (move-marker pos
(1+ (point))))
3119 (save-excursion (funcall function
))
3120 ;; Advance to the next line--actually, to the line that *was* next.
3121 ;; (If FUNCTION inserted some new lines in between, skip them.)
3123 (while (and (< arg
0) (not (bobp)))
3126 (while (and (not (bobp)) (dired-between-files)) (forward-line -
1))
3128 (save-excursion (funcall function
)))
3129 (move-marker pos nil
)
3130 (dired-move-to-filename)))
3132 (defun dired-between-files ()
3133 ;; This used to be a regexp match of the `total ...' line output by
3134 ;; ls, which is slightly faster, but that is not very robust; notably,
3135 ;; it fails for non-english locales.
3136 (save-excursion (not (dired-move-to-filename))))
3138 (defun dired-next-marked-file (arg &optional wrap opoint
)
3139 "Move to the next marked file, wrapping around the end of the buffer."
3140 (interactive "p\np")
3141 (or opoint
(setq opoint
(point)));; return to where interactively started
3143 (re-search-forward dired-re-mark nil t arg
)
3145 (re-search-backward dired-re-mark nil t
(- arg
)))
3146 (dired-move-to-filename)
3150 (error "No next marked file"))
3151 (message "(Wraparound for next marked file)")
3152 (goto-char (if (> arg
0) (point-min) (point-max)))
3153 (dired-next-marked-file arg nil opoint
))))
3155 (defun dired-prev-marked-file (arg &optional wrap
)
3156 "Move to the previous marked file, wrapping around the end of the buffer."
3157 (interactive "p\np")
3158 (dired-next-marked-file (- arg
) wrap
))
3160 (defun dired-file-marker (file)
3161 ;; Return FILE's marker, or nil if unmarked.
3163 (and (dired-goto-file file
)
3166 (if (not (equal ?
\040 (following-char)))
3167 (following-char))))))
3169 (defun dired-mark-files-in-region (start end
)
3170 (let ((inhibit-read-only t
))
3172 (error "start > end"))
3173 (goto-char start
) ; assumed at beginning of line
3174 (while (< (point) end
)
3175 ;; Skip subdir line and following garbage like the `total' line:
3176 (while (and (< (point) end
) (dired-between-files))
3178 (if (and (not (looking-at-p dired-re-dot
))
3179 (dired-get-filename nil t
))
3182 (insert dired-marker-char
)))
3185 (defun dired-mark (arg &optional interactive
)
3186 "Mark the file at point in the Dired buffer.
3187 If the region is active, mark all files in the region.
3188 Otherwise, with a prefix arg, mark files on the next ARG lines.
3190 If on a subdir headerline, mark all its files except `.' and `..'.
3192 Use \\[dired-unmark-all-files] to remove all marks
3193 and \\[dired-unmark] on a subdir to remove the marks in
3195 (interactive (list current-prefix-arg t
))
3197 ;; Mark files in the active region.
3198 ((and interactive
(use-region-p))
3200 (let ((beg (region-beginning))
3202 (dired-mark-files-in-region
3203 (progn (goto-char beg
) (line-beginning-position))
3204 (progn (goto-char end
) (line-beginning-position))))))
3205 ;; Mark subdir files from the subdir headerline.
3207 (save-excursion (dired-mark-subdir-files)))
3208 ;; Mark the current (or next ARG) files.
3210 (let ((inhibit-read-only t
))
3211 (dired-repeat-over-lines
3212 (prefix-numeric-value arg
)
3213 (function (lambda () (delete-char 1) (insert dired-marker-char
))))))))
3215 (defun dired-unmark (arg &optional interactive
)
3216 "Unmark the file at point in the Dired buffer.
3217 If the region is active, unmark all files in the region.
3218 Otherwise, with a prefix arg, unmark files on the next ARG lines.
3220 If looking at a subdir, unmark all its files except `.' and `..'.
3221 If the region is active in Transient Mark mode, unmark all files
3222 in the active region."
3223 (interactive (list current-prefix-arg t
))
3224 (let ((dired-marker-char ?
\040))
3225 (dired-mark arg interactive
)))
3227 (defun dired-flag-file-deletion (arg &optional interactive
)
3228 "In Dired, flag the current line's file for deletion.
3229 If the region is active, flag all files in the region.
3230 Otherwise, with a prefix arg, flag files on the next ARG lines.
3232 If on a subdir headerline, flag all its files except `.' and `..'.
3233 If the region is active in Transient Mark mode, flag all files
3234 in the active region."
3235 (interactive (list current-prefix-arg t
))
3236 (let ((dired-marker-char dired-del-marker
))
3237 (dired-mark arg interactive
)))
3239 (defun dired-unmark-backward (arg)
3240 "In Dired, move up lines and remove marks or deletion flags there.
3241 Optional prefix ARG says how many lines to unmark/unflag; default
3243 If the region is active in Transient Mark mode, unmark all files
3244 in the active region."
3246 (dired-unmark (- arg
)))
3248 (defun dired-toggle-marks ()
3249 "Toggle marks: marked files become unmarked, and vice versa.
3250 Files marked with other flags (such as `D') are not affected.
3251 `.' and `..' are never toggled.
3252 As always, hidden subdirs are not affected."
3255 (goto-char (point-min))
3256 (let ((inhibit-read-only t
))
3258 (or (dired-between-files)
3259 (looking-at-p dired-re-dot
)
3260 ;; use subst instead of insdel because it does not move
3261 ;; the gap and thus should be faster and because
3262 ;; other characters are left alone automatically
3263 (apply 'subst-char-in-region
3264 (point) (1+ (point))
3265 (if (eq ?
\040 (following-char)) ; SPC
3266 (list ?
\040 dired-marker-char
)
3267 (list dired-marker-char ?
\040))))
3268 (forward-line 1)))))
3270 ;;; Commands to mark or flag files based on their characteristics or names.
3272 (defvar dired-regexp-history nil
3273 "History list of regular expressions used in Dired commands.")
3275 (defun dired-read-regexp (prompt &optional default history
)
3276 (read-regexp prompt default
(or history
'dired-regexp-history
)))
3278 (defun dired-mark-files-regexp (regexp &optional marker-char
)
3279 "Mark all files matching REGEXP for use in later commands.
3280 A prefix argument means to unmark them instead.
3281 `.' and `..' are never marked.
3283 REGEXP is an Emacs regexp, not a shell wildcard. Thus, use `\\.o$' for
3284 object files--just `.o' will mark more than you might think."
3286 (list (dired-read-regexp (concat (if current-prefix-arg
"Unmark" "Mark")
3287 " files (regexp): "))
3288 (if current-prefix-arg ?
\040)))
3289 (let ((dired-marker-char (or marker-char dired-marker-char
)))
3291 (and (not (looking-at-p dired-re-dot
))
3292 (not (eolp)) ; empty line
3293 (let ((fn (dired-get-filename t t
)))
3294 (and fn
(string-match-p regexp fn
))))
3297 (defun dired-mark-files-containing-regexp (regexp &optional marker-char
)
3298 "Mark all files with contents containing REGEXP for use in later commands.
3299 A prefix argument means to unmark them instead.
3300 `.' and `..' are never marked."
3302 (list (dired-read-regexp (concat (if current-prefix-arg
"Unmark" "Mark")
3303 " files containing (regexp): "))
3304 (if current-prefix-arg ?
\040)))
3305 (let ((dired-marker-char (or marker-char dired-marker-char
)))
3307 (and (not (looking-at-p dired-re-dot
))
3308 (not (eolp)) ; empty line
3309 (let ((fn (dired-get-filename nil t
)))
3310 (when (and fn
(file-readable-p fn
)
3311 (not (file-directory-p fn
)))
3312 (let ((prebuf (get-file-buffer fn
)))
3313 (message "Checking %s" fn
)
3314 ;; For now we do it inside emacs
3315 ;; Grep might be better if there are a lot of files
3317 (with-current-buffer prebuf
3319 (goto-char (point-min))
3320 (re-search-forward regexp nil t
)))
3322 (insert-file-contents fn
)
3323 (goto-char (point-min))
3324 (re-search-forward regexp nil t
))))
3328 (defun dired-flag-files-regexp (regexp)
3329 "In Dired, flag all files containing the specified REGEXP for deletion.
3330 The match is against the non-directory part of the filename. Use `^'
3331 and `$' to anchor matches. Exclude subdirs by hiding them.
3332 `.' and `..' are never flagged."
3333 (interactive (list (dired-read-regexp "Flag for deletion (regexp): ")))
3334 (dired-mark-files-regexp regexp dired-del-marker
))
3336 (defun dired-mark-symlinks (unflag-p)
3337 "Mark all symbolic links.
3338 With prefix argument, unmark or unflag all those files."
3340 (let ((dired-marker-char (if unflag-p ?
\040 dired-marker-char
)))
3341 (dired-mark-if (looking-at-p dired-re-sym
) "symbolic link")))
3343 (defun dired-mark-directories (unflag-p)
3344 "Mark all directory file lines except `.' and `..'.
3345 With prefix argument, unmark or unflag all those files."
3347 (let ((dired-marker-char (if unflag-p ?
\040 dired-marker-char
)))
3348 (dired-mark-if (and (looking-at-p dired-re-dir
)
3349 (not (looking-at-p dired-re-dot
)))
3352 (defun dired-mark-executables (unflag-p)
3353 "Mark all executable files.
3354 With prefix argument, unmark or unflag all those files."
3356 (let ((dired-marker-char (if unflag-p ?
\040 dired-marker-char
)))
3357 (dired-mark-if (looking-at-p dired-re-exe
) "executable file")))
3359 ;; dired-x.el has a dired-mark-sexp interactive command: mark
3360 ;; files for which PREDICATE returns non-nil.
3362 (defun dired-flag-auto-save-files (&optional unflag-p
)
3363 "Flag for deletion files whose names suggest they are auto save files.
3364 A prefix argument says to unmark or unflag those files instead."
3366 (let ((dired-marker-char (if unflag-p ?
\040 dired-del-marker
)))
3368 ;; It is less than general to check for # here,
3369 ;; but it's the only way this runs fast enough.
3370 (and (save-excursion (end-of-line)
3372 (eq (preceding-char) ?
#)
3373 ;; Handle executables in case of -F option.
3374 ;; We need not worry about the other kinds
3375 ;; of markings that -F makes, since they won't
3376 ;; appear on real auto-save files.
3377 (if (eq (preceding-char) ?
*)
3380 (eq (preceding-char) ?
#)))))
3381 (not (looking-at-p dired-re-dir
))
3382 (let ((fn (dired-get-filename t t
)))
3383 (if fn
(auto-save-file-name-p
3384 (file-name-nondirectory fn
)))))
3387 (defcustom dired-garbage-files-regexp
3388 ;; `log' here is dubious, since it's typically used for useful log
3389 ;; files, not just TeX stuff. -- fx
3391 '(".log" ".toc" ".dvi" ".bak" ".orig" ".rej" ".aux"))
3393 "Regular expression to match \"garbage\" files for `dired-flag-garbage-files'."
3397 (defun dired-flag-garbage-files ()
3398 "Flag for deletion all files that match `dired-garbage-files-regexp'."
3400 (dired-flag-files-regexp dired-garbage-files-regexp
))
3402 (defun dired-flag-backup-files (&optional unflag-p
)
3403 "Flag all backup files (names ending with `~') for deletion.
3404 With prefix argument, unmark or unflag these files."
3406 (let ((dired-marker-char (if unflag-p ?\s dired-del-marker
)))
3408 ;; Don't call backup-file-name-p unless the last character looks like
3409 ;; it might be the end of a backup file name. This isn't very general,
3410 ;; but it's the only way this runs fast enough.
3411 (and (save-excursion (end-of-line)
3412 ;; Handle executables in case of -F option.
3413 ;; We need not worry about the other kinds
3414 ;; of markings that -F makes, since they won't
3415 ;; appear on real backup files.
3416 (if (eq (preceding-char) ?
*)
3418 (eq (preceding-char) ?~
))
3419 (not (looking-at-p dired-re-dir
))
3420 (let ((fn (dired-get-filename t t
)))
3421 (if fn
(backup-file-name-p fn
))))
3424 (defun dired-change-marks (&optional old new
)
3425 "Change all OLD marks to NEW marks.
3426 OLD and NEW are both characters used to mark files."
3428 (let* ((cursor-in-echo-area t
)
3429 (old (progn (message "Change (old mark): ") (read-char)))
3430 (new (progn (message "Change %c marks to (new mark): " old
)
3433 (if (or (eq old ?
\r) (eq new ?
\r))
3435 (let ((string (format "\n%c" old
))
3436 (inhibit-read-only t
))
3438 (goto-char (point-min))
3439 (while (search-forward string nil t
)
3442 (dired-get-filename 'no-dir t
))
3444 (subst-char-in-region (match-beginning 0)
3445 (match-end 0) old new
)))))))
3447 (defun dired-unmark-all-marks ()
3448 "Remove all marks from all files in the Dired buffer."
3450 (dired-unmark-all-files ?
\r))
3452 (defun dired-unmark-all-files (mark &optional arg
)
3453 "Remove a specific mark (or any mark) from every file.
3454 After this command, type the mark character to remove,
3455 or type RET to remove all marks.
3456 With prefix arg, query for each marked file.
3457 Type \\[help-command] at that time for help."
3458 (interactive "cRemove marks (RET means all): \nP")
3461 (inhibit-read-only t
) case-fold-search
3462 (string (format "\n%c" mark
))
3464 Type SPC or `y' to unmark one file, DEL or `n' to skip to next,
3465 `!' to unmark all remaining files with no more questions."))
3466 (goto-char (point-min))
3467 (while (if (eq mark ?
\r)
3468 (re-search-forward dired-re-mark nil t
)
3469 (search-forward string nil t
))
3471 (let ((file (dired-get-filename t t
)))
3473 (dired-query 'query
"Unmark file `%s'? "
3475 (progn (subst-char-in-region (1- (point)) (point)
3476 (preceding-char) ?\s
)
3477 (setq count
(1+ count
)))))
3478 (message (if (= count
1) "1 mark removed"
3482 ;; Logging failures operating on files, and showing the results.
3484 (defvar dired-log-buffer
"*Dired log*")
3487 "Pop up a buffer with error log output from Dired.
3488 A group of errors from a single command ends with a formfeed.
3489 Thus, use \\[backward-page] to find the beginning of a group of errors."
3491 (if (get-buffer dired-log-buffer
)
3492 (let ((owindow (selected-window))
3493 (window (display-buffer (get-buffer dired-log-buffer
))))
3496 (select-window window
)
3497 (goto-char (point-max))
3501 (select-window owindow
)))))
3503 (defun dired-log (log &rest args
)
3504 ;; Log a message or the contents of a buffer.
3505 ;; If LOG is a string and there are more args, it is formatted with
3506 ;; those ARGS. Usually the LOG string ends with a \n.
3507 ;; End each bunch of errors with (dired-log t):
3508 ;; this inserts the current time and buffer at the start of the page,
3509 ;; and \f (formfeed) at the end.
3510 (let ((obuf (current-buffer)))
3511 (with-current-buffer (get-buffer-create dired-log-buffer
)
3512 (goto-char (point-max))
3513 (let ((inhibit-read-only t
))
3514 (cond ((stringp log
)
3516 (apply (function format
) log args
)
3519 (insert-buffer-substring log
))
3524 (insert (current-time-string)
3525 "\tBuffer `" (buffer-name obuf
) "'\n")
3526 (goto-char (point-max))
3527 (insert "\f\n")))))))
3529 (defun dired-log-summary (string failures
)
3530 "State a summary of a command's failures, in echo area and log buffer.
3531 STRING is an overall summary of the failures.
3532 FAILURES is a list of file names that we failed to operate on,
3533 or nil if file names are not applicable."
3534 (if (= (length failures
) 1)
3536 (with-current-buffer dired-log-buffer
3537 (goto-char (point-max))
3539 (if (eolp) (forward-line 1))
3540 (buffer-substring (point) (point-max))))
3541 (message (if failures
"%s--type ? for details (%s)"
3542 "%s--type ? for details")
3544 ;; Log a summary describing a bunch of errors.
3545 (dired-log (concat "\n" string
"\n"))
3550 ;; Most ls can only sort by name or by date (with -t), nothing else.
3551 ;; GNU ls sorts on size with -S, on extension with -X, and unsorted with -U.
3552 ;; So anything that does not contain these is sort "by name".
3554 (defvar dired-ls-sorting-switches
"SXU"
3555 "String of `ls' switches (single letters) except \"t\" that influence sorting.
3557 This indicates to Dired which option switches to watch out for because they
3558 will change the sorting order behavior of `ls'.
3560 To change the default sorting order (e.g. add a `-v' option), see the
3561 variable `dired-listing-switches'. To temporarily override the listing
3562 format, use `\\[universal-argument] \\[dired]'.")
3564 (defvar dired-sort-by-date-regexp
3565 (concat "\\(\\`\\| \\)-[^- ]*t"
3566 ;; `dired-ls-sorting-switches' after -t overrides -t.
3567 "[^ " dired-ls-sorting-switches
"]*"
3568 "\\(\\(\\`\\| +\\)\\(--[^ ]+\\|-[^- t"
3569 dired-ls-sorting-switches
"]+\\)\\)* *$")
3570 "Regexp recognized by Dired to set `by date' mode.")
3572 (defvar dired-sort-by-name-regexp
3573 (concat "\\`\\(\\(\\`\\| +\\)\\(--[^ ]+\\|"
3574 "-[^- t" dired-ls-sorting-switches
"]+\\)\\)* *$")
3575 "Regexp recognized by Dired to set `by name' mode.")
3577 (defvar dired-sort-inhibit nil
3578 "Non-nil means the Dired sort command is disabled.
3579 The idea is to set this buffer-locally in special Dired buffers.")
3581 (defun dired-sort-set-mode-line ()
3582 ;; Set mode line display according to dired-actual-switches.
3583 ;; Mode line display of "by name" or "by date" guarantees the user a
3584 ;; match with the corresponding regexps. Non-matching switches are
3586 (when (eq major-mode
'dired-mode
)
3588 (let (case-fold-search)
3589 (cond ((string-match-p
3590 dired-sort-by-name-regexp dired-actual-switches
)
3593 dired-sort-by-date-regexp dired-actual-switches
)
3596 (concat "Dired " dired-actual-switches
)))))
3597 (force-mode-line-update)))
3599 (define-obsolete-function-alias 'dired-sort-set-modeline
3600 'dired-sort-set-mode-line
"24.3")
3602 (defun dired-sort-toggle-or-edit (&optional arg
)
3603 "Toggle sorting by date, and refresh the Dired buffer.
3604 With a prefix argument, edit the current listing switches instead."
3606 (when dired-sort-inhibit
3607 (error "Cannot sort this Dired buffer"))
3610 (read-string "ls switches (must contain -l): " dired-actual-switches
))
3611 (dired-sort-toggle)))
3613 (defun dired-sort-toggle ()
3614 ;; Toggle between sort by date/name. Reverts the buffer.
3615 (let ((sorting-by-date (string-match-p dired-sort-by-date-regexp
3616 dired-actual-switches
))
3617 ;; Regexp for finding (possibly embedded) -t switches.
3618 (switch-regexp "\\(\\`\\| \\)-\\([a-su-zA-Z]*\\)\\(t\\)\\([^ ]*\\)")
3620 ;; Remove the -t switch.
3621 (while (string-match switch-regexp dired-actual-switches
)
3622 (if (and (equal (match-string 2 dired-actual-switches
) "")
3623 (equal (match-string 4 dired-actual-switches
) ""))
3624 ;; Remove a stand-alone -t switch.
3625 (setq dired-actual-switches
3626 (replace-match "" t t dired-actual-switches
))
3627 ;; Remove a switch of the form -XtY for some X and Y.
3628 (setq dired-actual-switches
3629 (replace-match "" t t dired-actual-switches
3))))
3630 ;; Now, if we weren't sorting by date before, add the -t switch.
3631 ;; Some simple-minded ls implementations (eg ftp servers) only
3632 ;; allow a single option string, so try not to add " -t" if possible.
3633 (unless sorting-by-date
3634 (setq dired-actual-switches
3635 (concat dired-actual-switches
3636 (if (string-match-p "\\`-[[:alnum:]]+\\'"
3637 dired-actual-switches
)
3640 (dired-sort-set-mode-line)
3643 ;; Some user code loads dired especially for this.
3644 ;; Don't do that--use replace-regexp-in-string instead.
3645 (defun dired-replace-in-string (regexp newtext string
)
3646 ;; Replace REGEXP with NEWTEXT everywhere in STRING and return result.
3647 ;; NEWTEXT is taken literally---no \\DIGIT escapes will be recognized.
3648 (let ((result "") (start 0) mb me
)
3649 (while (string-match regexp string start
)
3650 (setq mb
(match-beginning 0)
3652 result
(concat result
(substring string start mb
) newtext
)
3654 (concat result
(substring string start
))))
3656 (defun dired-sort-other (switches &optional no-revert
)
3657 "Specify new `ls' SWITCHES for current Dired buffer.
3658 Values matching `dired-sort-by-date-regexp' or `dired-sort-by-name-regexp'
3659 set the minor mode accordingly, others appear literally in the mode line.
3660 With optional second arg NO-REVERT, don't refresh the listing afterwards."
3661 (dired-sort-R-check switches
)
3662 (setq dired-actual-switches switches
)
3663 (dired-sort-set-mode-line)
3664 (or no-revert
(revert-buffer)))
3666 (defvar-local dired-subdir-alist-pre-R nil
3667 "Value of `dired-subdir-alist' before -R switch added.")
3669 (defun dired-sort-R-check (switches)
3670 "Additional processing of -R in ls option string SWITCHES.
3671 Saves `dired-subdir-alist' when R is set and restores saved value
3672 minus any directories explicitly deleted when R is cleared.
3673 To be called first in body of `dired-sort-other', etc."
3675 ((and (string-match-p "R" switches
)
3676 (not (string-match-p "R" dired-actual-switches
)))
3677 ;; Adding -R to ls switches -- save `dired-subdir-alist':
3678 (setq dired-subdir-alist-pre-R dired-subdir-alist
))
3679 ((and (string-match-p "R" dired-actual-switches
)
3680 (not (string-match-p "R" switches
)))
3681 ;; Deleting -R from ls switches -- revert to pre-R subdirs
3682 ;; that are still present:
3683 (setq dired-subdir-alist
3684 (if dired-subdir-alist-pre-R
3686 (while dired-subdir-alist-pre-R
3687 (if (assoc (caar dired-subdir-alist-pre-R
)
3689 ;; subdir still present...
3691 (cons (car dired-subdir-alist-pre-R
)
3693 (setq dired-subdir-alist-pre-R
3694 (cdr dired-subdir-alist-pre-R
)))
3696 ;; No pre-R subdir alist, so revert to main directory
3698 (list (car (reverse dired-subdir-alist
))))))))
3701 ;;;; Drag and drop support
3703 (defcustom dired-recursive-copies
'top
3704 "Whether Dired copies directories recursively.
3705 If nil, never copy recursively.
3706 `always' means to copy recursively without asking.
3707 `top' means to ask for each directory at top level.
3708 Any other value means to ask for each directory."
3709 :type
'(choice :tag
"Copy directories"
3710 (const :tag
"No recursive copies" nil
)
3711 (const :tag
"Ask for each directory" t
)
3712 (const :tag
"Ask for each top directory only" top
)
3713 (const :tag
"Copy directories without asking" always
))
3716 (defun dired-dnd-popup-notice ()
3718 "Dired recursive copies are currently disabled.\nSee the variable `dired-recursive-copies'."))
3720 (declare-function x-popup-menu
"menu.c" (position menu
))
3722 (defun dired-dnd-do-ask-action (uri)
3723 ;; No need to get actions and descriptions from the source,
3724 ;; we only have three actions anyway.
3725 (let ((action (x-popup-menu
3727 (list "What action?"
3729 '(("Copy here" . copy
)
3730 ("Move here" . move
)
3731 ("Link here" . link
)
3733 ("Cancel" . nil
)))))))
3735 (dired-dnd-handle-local-file uri action
)
3738 (declare-function dired-relist-entry
"dired-aux" (file))
3739 (declare-function make-symbolic-link
"fileio.c")
3741 ;; Only used when (featurep 'dnd).
3742 (declare-function dnd-get-local-file-name
"dnd" (uri &optional must-exist
))
3743 (declare-function dnd-get-local-file-uri
"dnd" (uri))
3745 (defvar dired-overwrite-confirmed
) ;Defined in dired-aux.
3747 (defun dired-dnd-handle-local-file (uri action
)
3748 "Copy, move or link a file to the Dired directory.
3749 URI is the file to handle, ACTION is one of copy, move, link or ask.
3750 Ask means pop up a menu for the user to select one of copy, move or link."
3751 (require 'dired-aux
)
3752 (let* ((from (dnd-get-local-file-name uri t
))
3754 (concat (dired-current-directory)
3755 (file-name-nondirectory from
)))))
3757 (cond ((eq action
'ask
)
3758 (dired-dnd-do-ask-action uri
))
3759 ;; If copying a directory and dired-recursive-copies is
3760 ;; nil, dired-copy-file fails. Pop up a notice.
3761 ((and (memq action
'(copy private
))
3762 (file-directory-p from
)
3763 (not dired-recursive-copies
))
3764 (dired-dnd-popup-notice))
3765 ((memq action
'(copy private move link
))
3766 (let ((overwrite (and (file-exists-p to
)
3768 (format "Overwrite existing file `%s'? " to
))))
3769 ;; Binding dired-overwrite-confirmed to nil makes
3770 ;; dired-handle-overwrite a no-op. We instead use
3771 ;; y-or-n-p, which pops a graphical menu.
3772 dired-overwrite-confirmed backup-file
)
3773 (when (and overwrite
3774 ;; d-b-o is defined in dired-aux.
3775 (boundp 'dired-backup-overwrite
)
3776 dired-backup-overwrite
3778 (car (find-backup-file-name to
)))
3779 (or (eq dired-backup-overwrite
'always
)
3782 "Make backup for existing file `%s'? " to
))))
3783 (rename-file to backup-file
0)
3784 (dired-relist-entry backup-file
))
3785 (cond ((memq action
'(copy private
))
3786 (dired-copy-file from to overwrite
))
3788 (dired-rename-file from to overwrite
))
3790 (make-symbolic-link from to overwrite
)))
3791 (dired-relist-entry to
)
3794 (defun dired-dnd-handle-file (uri action
)
3795 "Copy, move or link a file to the Dired directory if it is a local file.
3796 URI is the file to handle. If the hostname in the URI isn't local, do nothing.
3797 ACTION is one of copy, move, link or ask.
3798 Ask means pop up a menu for the user to select one of copy, move or link."
3799 (let ((local-file (dnd-get-local-file-uri uri
)))
3800 (if local-file
(dired-dnd-handle-local-file local-file action
)
3804 ;;;; Desktop support
3806 (eval-when-compile (require 'desktop
))
3807 (declare-function desktop-file-name
"desktop" (filename dirname
))
3809 (defun dired-desktop-buffer-misc-data (dirname)
3810 "Auxiliary information to be saved in desktop file."
3812 ;; Value of `dired-directory'.
3813 (if (consp dired-directory
)
3814 ;; Directory name followed by list of files.
3815 (cons (desktop-file-name (car dired-directory
) dirname
)
3816 (cdr dired-directory
))
3817 ;; Directory name, optionally with shell wildcard.
3818 (desktop-file-name dired-directory dirname
))
3819 ;; Subdirectories in `dired-subdir-alist'.
3823 (function (lambda (f) (desktop-file-name (car f
) dirname
)))
3824 dired-subdir-alist
)))))
3826 (defun dired-restore-desktop-buffer (_file-name
3829 "Restore a Dired buffer specified in a desktop file."
3830 ;; First element of `misc-data' is the value of `dired-directory'.
3831 ;; This value is a directory name, optionally with shell wildcard or
3832 ;; a directory name followed by list of files.
3833 (let* ((dired-dir (car misc-data
))
3834 (dir (if (consp dired-dir
) (car dired-dir
) dired-dir
)))
3835 (if (file-directory-p (file-name-directory dir
))
3838 ;; The following elements of `misc-data' are the keys
3839 ;; from `dired-subdir-alist'.
3840 (mapc 'dired-maybe-insert-subdir
(cdr misc-data
))
3842 (message "Desktop: Directory %s no longer exists." dir
)
3843 (when desktop-missing-file-warning
(sit-for 1))
3846 (add-to-list 'desktop-buffer-mode-handlers
3847 '(dired-mode . dired-restore-desktop-buffer
))
3850 ;;; Start of automatically extracted autoloads.
3852 ;;;### (autoloads nil "dired-aux" "dired-aux.el" "04b4cb6bde3220f55574eb1d99ac0d29")
3853 ;;; Generated autoloads from dired-aux.el
3855 (autoload 'dired-diff
"dired-aux" "\
3856 Compare file at point with file FILE using `diff'.
3857 If called interactively, prompt for FILE. If the file at point
3858 has a backup file, use that as the default. If the file at point
3859 is a backup file, use its original. If the mark is active
3860 in Transient Mark mode, use the file at the mark as the default.
3861 \(That's the mark set by \\[set-mark-command], not by Dired's
3862 \\[dired-mark] command.)
3864 FILE is the first file given to `diff'. The file at point
3865 is the second file given to `diff'.
3867 With prefix arg, prompt for second argument SWITCHES, which is
3868 the string of command switches for the third argument of `diff'.
3870 \(fn FILE &optional SWITCHES)" t nil
)
3872 (autoload 'dired-backup-diff
"dired-aux" "\
3873 Diff this file with its backup file or vice versa.
3874 Uses the latest backup, if there are several numerical backups.
3875 If this file is a backup, diff it with its original.
3876 The backup file is the first file given to `diff'.
3877 With prefix arg, prompt for argument SWITCHES which is options for `diff'.
3879 \(fn &optional SWITCHES)" t nil
)
3881 (autoload 'dired-compare-directories
"dired-aux" "\
3882 Mark files with different file attributes in two dired buffers.
3883 Compare file attributes of files in the current directory
3884 with file attributes in directory DIR2 using PREDICATE on pairs of files
3885 with the same name. Mark files for which PREDICATE returns non-nil.
3886 Mark files with different names if PREDICATE is nil (or interactively
3887 with empty input at the predicate prompt).
3889 PREDICATE is a Lisp expression that can refer to the following variables:
3891 size1, size2 - file size in bytes
3892 mtime1, mtime2 - last modification time in seconds, as a float
3893 fa1, fa2 - list of file attributes
3894 returned by function `file-attributes'
3896 where 1 refers to attribute of file in the current dired buffer
3897 and 2 to attribute of file in second dired buffer.
3899 Examples of PREDICATE:
3901 (> mtime1 mtime2) - mark newer files
3902 (not (= size1 size2)) - mark files with different sizes
3903 (not (string= (nth 8 fa1) (nth 8 fa2))) - mark files with different modes
3904 (not (and (= (nth 2 fa1) (nth 2 fa2)) - mark files with different UID
3905 (= (nth 3 fa1) (nth 3 fa2)))) and GID.
3907 \(fn DIR2 PREDICATE)" t nil
)
3909 (autoload 'dired-do-chmod
"dired-aux" "\
3910 Change the mode of the marked (or next ARG) files.
3911 Symbolic modes like `g+w' are allowed.
3912 Type M-n to pull the file attributes of the file at point
3913 into the minibuffer.
3915 \(fn &optional ARG)" t nil
)
3917 (autoload 'dired-do-chgrp
"dired-aux" "\
3918 Change the group of the marked (or next ARG) files.
3919 Type M-n to pull the file attributes of the file at point
3920 into the minibuffer.
3922 \(fn &optional ARG)" t nil
)
3924 (autoload 'dired-do-chown
"dired-aux" "\
3925 Change the owner of the marked (or next ARG) files.
3926 Type M-n to pull the file attributes of the file at point
3927 into the minibuffer.
3929 \(fn &optional ARG)" t nil
)
3931 (autoload 'dired-do-touch
"dired-aux" "\
3932 Change the timestamp of the marked (or next ARG) files.
3934 Type M-n to pull the file attributes of the file at point
3935 into the minibuffer.
3937 \(fn &optional ARG)" t nil
)
3939 (autoload 'dired-do-print
"dired-aux" "\
3940 Print the marked (or next ARG) files.
3941 Uses the shell command coming from variables `lpr-command' and
3942 `lpr-switches' as default.
3944 \(fn &optional ARG)" t nil
)
3946 (autoload 'dired-clean-directory
"dired-aux" "\
3947 Flag numerical backups for deletion.
3948 Spares `dired-kept-versions' latest versions, and `kept-old-versions' oldest.
3949 Positive prefix arg KEEP overrides `dired-kept-versions';
3950 Negative prefix arg KEEP overrides `kept-old-versions' with KEEP made positive.
3952 To clear the flags on these files, you can use \\[dired-flag-backup-files]
3953 with a prefix argument.
3957 (autoload 'dired-do-async-shell-command
"dired-aux" "\
3958 Run a shell command COMMAND on the marked files asynchronously.
3960 Like `dired-do-shell-command', but adds `&' at the end of COMMAND
3961 to execute it asynchronously.
3963 When operating on multiple files, asynchronous commands
3964 are executed in the background on each file in parallel.
3965 In shell syntax this means separating the individual commands
3966 with `&'. However, when COMMAND ends in `;' or `;&' then commands
3967 are executed in the background on each file sequentially waiting
3968 for each command to terminate before running the next command.
3969 In shell syntax this means separating the individual commands with `;'.
3971 The output appears in the buffer `*Async Shell Command*'.
3973 \(fn COMMAND &optional ARG FILE-LIST)" t nil
)
3975 (autoload 'dired-do-shell-command
"dired-aux" "\
3976 Run a shell command COMMAND on the marked files.
3977 If no files are marked or a numeric prefix arg is given,
3978 the next ARG files are used. Just \\[universal-argument] means the current file.
3979 The prompt mentions the file(s) or the marker, as appropriate.
3981 If there is a `*' in COMMAND, surrounded by whitespace, this runs
3982 COMMAND just once with the entire file list substituted there.
3984 If there is no `*', but there is a `?' in COMMAND, surrounded by
3985 whitespace, this runs COMMAND on each file individually with the
3986 file name substituted for `?'.
3988 Otherwise, this runs COMMAND on each file individually with the
3989 file name added at the end of COMMAND (separated by a space).
3991 `*' and `?' when not surrounded by whitespace have no special
3992 significance for `dired-do-shell-command', and are passed through
3993 normally to the shell, but you must confirm first.
3995 If you want to use `*' as a shell wildcard with whitespace around
3996 it, write `*\"\"' in place of just `*'. This is equivalent to just
3997 `*' in the shell, but avoids Dired's special handling.
3999 If COMMAND ends in `&', `;', or `;&', it is executed in the
4000 background asynchronously, and the output appears in the buffer
4001 `*Async Shell Command*'. When operating on multiple files and COMMAND
4002 ends in `&', the shell command is executed on each file in parallel.
4003 However, when COMMAND ends in `;' or `;&' then commands are executed
4004 in the background on each file sequentially waiting for each command
4005 to terminate before running the next command. You can also use
4006 `dired-do-async-shell-command' that automatically adds `&'.
4008 Otherwise, COMMAND is executed synchronously, and the output
4009 appears in the buffer `*Shell Command Output*'.
4011 This feature does not try to redisplay Dired buffers afterward, as
4012 there's no telling what files COMMAND may have changed.
4013 Type \\[dired-do-redisplay] to redisplay the marked files.
4015 When COMMAND runs, its working directory is the top-level directory
4016 of the Dired buffer, so output files usually are created there
4017 instead of in a subdir.
4019 In a noninteractive call (from Lisp code), you must specify
4020 the list of file names explicitly with the FILE-LIST argument, which
4021 can be produced by `dired-get-marked-files', for example.
4023 \(fn COMMAND &optional ARG FILE-LIST)" t nil
)
4025 (autoload 'dired-run-shell-command
"dired-aux" "\
4028 \(fn COMMAND)" nil nil
)
4030 (autoload 'dired-do-kill-lines
"dired-aux" "\
4031 Kill all marked lines (not the files).
4032 With a prefix argument, kill that many lines starting with the current line.
4033 \(A negative argument kills backward.)
4034 If you use this command with a prefix argument to kill the line
4035 for a file that is a directory, which you have inserted in the
4036 Dired buffer as a subdirectory, then it deletes that subdirectory
4037 from the buffer as well.
4038 To kill an entire subdirectory (without killing its line in the
4039 parent directory), go to its directory header line and use this
4040 command with a prefix argument (the value does not matter).
4042 \(fn &optional ARG FMT)" t nil
)
4044 (autoload 'dired-compress-file
"dired-aux" "\
4047 \(fn FILE)" nil nil
)
4049 (autoload 'dired-query
"dired-aux" "\
4050 Format PROMPT with ARGS, query user, and store the result in SYM.
4051 The return value is either nil or t.
4053 The user may type y or SPC to accept once; n or DEL to skip once;
4054 ! to accept this and subsequent queries; or q or ESC to decline
4055 this and subsequent queries.
4057 If SYM is already bound to a non-nil value, this function may
4058 return automatically without querying the user. If SYM is !,
4059 return t; if SYM is q or ESC, return nil.
4061 \(fn SYM PROMPT &rest ARGS)" nil nil
)
4063 (autoload 'dired-do-compress
"dired-aux" "\
4064 Compress or uncompress marked (or next ARG) files.
4066 \(fn &optional ARG)" t nil
)
4068 (autoload 'dired-do-byte-compile
"dired-aux" "\
4069 Byte compile marked (or next ARG) Emacs Lisp files.
4071 \(fn &optional ARG)" t nil
)
4073 (autoload 'dired-do-load
"dired-aux" "\
4074 Load the marked (or next ARG) Emacs Lisp files.
4076 \(fn &optional ARG)" t nil
)
4078 (autoload 'dired-do-redisplay
"dired-aux" "\
4079 Redisplay all marked (or next ARG) files.
4080 If on a subdir line, redisplay that subdirectory. In that case,
4081 a prefix arg lets you edit the `ls' switches used for the new listing.
4083 Dired remembers switches specified with a prefix arg, so that reverting
4084 the buffer will not reset them. However, using `dired-undo' to re-insert
4085 or delete subdirectories can bypass this machinery. Hence, you sometimes
4086 may have to reset some subdirectory switches after a `dired-undo'.
4087 You can reset all subdirectory switches to the default using
4088 \\<dired-mode-map>\\[dired-reset-subdir-switches].
4089 See Info node `(emacs)Subdir switches' for more details.
4091 \(fn &optional ARG TEST-FOR-SUBDIR)" t nil
)
4093 (autoload 'dired-add-file
"dired-aux" "\
4096 \(fn FILENAME &optional MARKER-CHAR)" nil nil
)
4098 (autoload 'dired-remove-file
"dired-aux" "\
4101 \(fn FILE)" nil nil
)
4103 (autoload 'dired-relist-file
"dired-aux" "\
4104 Create or update the line for FILE in all Dired buffers it would belong in.
4106 \(fn FILE)" nil nil
)
4108 (autoload 'dired-copy-file
"dired-aux" "\
4111 \(fn FROM TO OK-FLAG)" nil nil
)
4113 (autoload 'dired-rename-file
"dired-aux" "\
4116 \(fn FILE NEWNAME OK-IF-ALREADY-EXISTS)" nil nil
)
4118 (autoload 'dired-create-directory
"dired-aux" "\
4119 Create a directory called DIRECTORY.
4120 If DIRECTORY already exists, signal an error.
4122 \(fn DIRECTORY)" t nil
)
4124 (autoload 'dired-do-copy
"dired-aux" "\
4125 Copy all marked (or next ARG) files, or copy the current file.
4126 When operating on just the current file, prompt for the new name.
4128 When operating on multiple or marked files, prompt for a target
4129 directory, and make the new copies in that directory, with the
4130 same names as the original files. The initial suggestion for the
4131 target directory is the Dired buffer's current directory (or, if
4132 `dired-dwim-target' is non-nil, the current directory of a
4133 neighboring Dired window).
4135 If `dired-copy-preserve-time' is non-nil, this command preserves
4136 the modification time of each old file in the copy, similar to
4137 the \"-p\" option for the \"cp\" shell command.
4139 This command copies symbolic links by creating new ones, similar
4140 to the \"-d\" option for the \"cp\" shell command.
4142 \(fn &optional ARG)" t nil
)
4144 (autoload 'dired-do-symlink
"dired-aux" "\
4145 Make symbolic links to current file or all marked (or next ARG) files.
4146 When operating on just the current file, you specify the new name.
4147 When operating on multiple or marked files, you specify a directory
4148 and new symbolic links are made in that directory
4149 with the same names that the files currently have. The default
4150 suggested for the target directory depends on the value of
4151 `dired-dwim-target', which see.
4153 For relative symlinks, use \\[dired-do-relsymlink].
4155 \(fn &optional ARG)" t nil
)
4157 (autoload 'dired-do-hardlink
"dired-aux" "\
4158 Add names (hard links) current file or all marked (or next ARG) files.
4159 When operating on just the current file, you specify the new name.
4160 When operating on multiple or marked files, you specify a directory
4161 and new hard links are made in that directory
4162 with the same names that the files currently have. The default
4163 suggested for the target directory depends on the value of
4164 `dired-dwim-target', which see.
4166 \(fn &optional ARG)" t nil
)
4168 (autoload 'dired-do-rename
"dired-aux" "\
4169 Rename current file or all marked (or next ARG) files.
4170 When renaming just the current file, you specify the new name.
4171 When renaming multiple or marked files, you specify a directory.
4172 This command also renames any buffers that are visiting the files.
4173 The default suggested for the target directory depends on the value
4174 of `dired-dwim-target', which see.
4176 \(fn &optional ARG)" t nil
)
4178 (autoload 'dired-do-rename-regexp
"dired-aux" "\
4179 Rename selected files whose names match REGEXP to NEWNAME.
4181 With non-zero prefix argument ARG, the command operates on the next ARG
4182 files. Otherwise, it operates on all the marked files, or the current
4183 file if none are marked.
4185 As each match is found, the user must type a character saying
4186 what to do with it. For directions, type \\[help-command] at that time.
4187 NEWNAME may contain \\=\\<n> or \\& as in `query-replace-regexp'.
4188 REGEXP defaults to the last regexp used.
4190 With a zero prefix arg, renaming by regexp affects the absolute file name.
4191 Normally, only the non-directory part of the file name is used and changed.
4193 \(fn REGEXP NEWNAME &optional ARG WHOLE-NAME)" t nil
)
4195 (autoload 'dired-do-copy-regexp
"dired-aux" "\
4196 Copy selected files whose names match REGEXP to NEWNAME.
4197 See function `dired-do-rename-regexp' for more info.
4199 \(fn REGEXP NEWNAME &optional ARG WHOLE-NAME)" t nil
)
4201 (autoload 'dired-do-hardlink-regexp
"dired-aux" "\
4202 Hardlink selected files whose names match REGEXP to NEWNAME.
4203 See function `dired-do-rename-regexp' for more info.
4205 \(fn REGEXP NEWNAME &optional ARG WHOLE-NAME)" t nil
)
4207 (autoload 'dired-do-symlink-regexp
"dired-aux" "\
4208 Symlink selected files whose names match REGEXP to NEWNAME.
4209 See function `dired-do-rename-regexp' for more info.
4211 \(fn REGEXP NEWNAME &optional ARG WHOLE-NAME)" t nil
)
4213 (autoload 'dired-upcase
"dired-aux" "\
4214 Rename all marked (or next ARG) files to upper case.
4216 \(fn &optional ARG)" t nil
)
4218 (autoload 'dired-downcase
"dired-aux" "\
4219 Rename all marked (or next ARG) files to lower case.
4221 \(fn &optional ARG)" t nil
)
4223 (autoload 'dired-maybe-insert-subdir
"dired-aux" "\
4224 Insert this subdirectory into the same dired buffer.
4225 If it is already present, just move to it (type \\[dired-do-redisplay] to refresh),
4226 else inserts it at its natural place (as `ls -lR' would have done).
4227 With a prefix arg, you may edit the ls switches used for this listing.
4228 You can add `R' to the switches to expand the whole tree starting at
4230 This function takes some pains to conform to `ls -lR' output.
4232 Dired remembers switches specified with a prefix arg, so that reverting
4233 the buffer will not reset them. However, using `dired-undo' to re-insert
4234 or delete subdirectories can bypass this machinery. Hence, you sometimes
4235 may have to reset some subdirectory switches after a `dired-undo'.
4236 You can reset all subdirectory switches to the default using
4237 \\<dired-mode-map>\\[dired-reset-subdir-switches].
4238 See Info node `(emacs)Subdir switches' for more details.
4240 \(fn DIRNAME &optional SWITCHES NO-ERROR-IF-NOT-DIR-P)" t nil
)
4242 (autoload 'dired-insert-subdir
"dired-aux" "\
4243 Insert this subdirectory into the same Dired buffer.
4244 If it is already present, overwrite the previous entry;
4245 otherwise, insert it at its natural place (as `ls -lR' would
4247 With a prefix arg, you may edit the `ls' switches used for this listing.
4248 You can add `R' to the switches to expand the whole tree starting at
4250 This function takes some pains to conform to `ls -lR' output.
4252 \(fn DIRNAME &optional SWITCHES NO-ERROR-IF-NOT-DIR-P)" t nil
)
4254 (autoload 'dired-prev-subdir
"dired-aux" "\
4255 Go to previous subdirectory, regardless of level.
4256 When called interactively and not on a subdir line, go to this subdir's line.
4258 \(fn ARG &optional NO-ERROR-IF-NOT-FOUND NO-SKIP)" t nil
)
4260 (autoload 'dired-goto-subdir
"dired-aux" "\
4261 Go to end of header line of DIR in this dired buffer.
4262 Return value of point on success, otherwise return nil.
4263 The next char is either \\n, or \\r if DIR is hidden.
4267 (autoload 'dired-mark-subdir-files
"dired-aux" "\
4268 Mark all files except `.' and `..' in current subdirectory.
4269 If the Dired buffer shows multiple directories, this command
4270 marks the files listed in the subdirectory that point is in.
4274 (autoload 'dired-kill-subdir
"dired-aux" "\
4275 Remove all lines of current subdirectory.
4276 Lower levels are unaffected.
4278 \(fn &optional REMEMBER-MARKS)" t nil
)
4280 (autoload 'dired-tree-up
"dired-aux" "\
4281 Go up ARG levels in the dired tree.
4285 (autoload 'dired-tree-down
"dired-aux" "\
4286 Go down in the dired tree.
4290 (autoload 'dired-hide-subdir
"dired-aux" "\
4291 Hide or unhide the current subdirectory and move to next directory.
4292 Optional prefix arg is a repeat factor.
4293 Use \\[dired-hide-all] to (un)hide all directories.
4297 (autoload 'dired-hide-all
"dired-aux" "\
4298 Hide all subdirectories, leaving only their header lines.
4299 If there is already something hidden, make everything visible again.
4300 Use \\[dired-hide-subdir] to (un)hide a particular subdirectory.
4302 \(fn &optional IGNORED)" t nil
)
4304 (autoload 'dired-isearch-filenames-setup
"dired-aux" "\
4305 Set up isearch to search in Dired file names.
4306 Intended to be added to `isearch-mode-hook'.
4310 (autoload 'dired-isearch-filenames
"dired-aux" "\
4311 Search for a string using Isearch only in file names in the Dired buffer.
4315 (autoload 'dired-isearch-filenames-regexp
"dired-aux" "\
4316 Search for a regexp using Isearch only in file names in the Dired buffer.
4320 (autoload 'dired-do-isearch
"dired-aux" "\
4321 Search for a string through all marked files using Isearch.
4325 (autoload 'dired-do-isearch-regexp
"dired-aux" "\
4326 Search for a regexp through all marked files using Isearch.
4330 (autoload 'dired-do-search
"dired-aux" "\
4331 Search through all marked files for a match for REGEXP.
4332 Stops when a match is found.
4333 To continue searching for next match, use command \\[tags-loop-continue].
4335 \(fn REGEXP)" t nil
)
4337 (autoload 'dired-do-query-replace-regexp
"dired-aux" "\
4338 Do `query-replace-regexp' of FROM with TO, on all marked files.
4339 Third arg DELIMITED (prefix arg) means replace only word-delimited matches.
4340 If you exit (\\[keyboard-quit], RET or q), you can resume the query replace
4341 with the command \\[tags-loop-continue].
4343 \(fn FROM TO &optional DELIMITED)" t nil
)
4345 (autoload 'dired-show-file-type
"dired-aux" "\
4346 Print the type of FILE, according to the `file' command.
4347 If you give a prefix to this command, and FILE is a symbolic
4348 link, then the type of the file linked to by FILE is printed
4351 \(fn FILE &optional DEREF-SYMLINKS)" t nil
)
4355 ;;;### (autoloads nil "dired-x" "dired-x.el" "732d08c173295dd14a0736fa222f532a")
4356 ;;; Generated autoloads from dired-x.el
4358 (autoload 'dired-jump
"dired-x" "\
4359 Jump to Dired buffer corresponding to current buffer.
4360 If in a file, Dired the current directory and move to file's line.
4361 If in Dired already, pop up a level and goto old directory's line.
4362 In case the proper Dired file line cannot be found, refresh the dired
4363 buffer and try again.
4364 When OTHER-WINDOW is non-nil, jump to Dired buffer in other window.
4365 Interactively with prefix argument, read FILE-NAME and
4366 move to its line in dired.
4368 \(fn &optional OTHER-WINDOW FILE-NAME)" t nil
)
4370 (autoload 'dired-jump-other-window
"dired-x" "\
4371 Like \\[dired-jump] (`dired-jump') but in other window.
4373 \(fn &optional FILE-NAME)" t nil
)
4375 (autoload 'dired-do-relsymlink
"dired-x" "\
4376 Relative symlink all marked (or next ARG) files into a directory.
4377 Otherwise make a relative symbolic link to the current file.
4378 This creates relative symbolic links like
4382 not absolute ones like
4384 foo -> /ugly/file/name/that/may/change/any/day/bar/foo
4386 For absolute symlinks, use \\[dired-do-symlink].
4388 \(fn &optional ARG)" t nil
)
4392 ;;; End of automatically extracted autoloads.
4396 (run-hooks 'dired-load-hook
) ; for your customizations
4398 ;;; dired.el ends here