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