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