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