(hl-line): Doc fix.
[bpt/emacs.git] / lisp / dired-x.el
CommitLineData
cb3fe1f0
RS
1;;; dired-x.el --- Sebastian Kremer's Extra DIRED hacked up for GNU Emacs19
2
3;; Author: Sebastian Kremer <sk@thp.uni-koeln.de>
4;; Lawrence R. Dodd <dodd@roebling.poly.edu>
5;; Maintainer: Lawrence R. Dodd <dodd@roebling.poly.edu>
9b5ef74b
RS
6;; Version: 2.37+
7;; Date: 1994/08/18 19:27:42
cb3fe1f0
RS
8;; Keywords: dired extensions
9
286c247d 10;; Copyright (C) 1993, 1994, 1997 Free Software Foundation, Inc.
cb3fe1f0
RS
11
12;; This file is part of GNU Emacs.
13
14;; GNU Emacs is free software; you can redistribute it and/or modify
15;; it under the terms of the GNU General Public License as published by
de3b6439 16;; the Free Software Foundation; either version 2, or (at your option)
cb3fe1f0
RS
17;; any later version.
18
19;; GNU Emacs is distributed in the hope that it will be useful,
20;; but WITHOUT ANY WARRANTY; without even the implied warranty of
21;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22;; GNU General Public License for more details.
23
24;; You should have received a copy of the GNU General Public License
b578f267
EN
25;; along with GNU Emacs; see the file COPYING. If not, write to the
26;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
27;; Boston, MA 02111-1307, USA.
cb3fe1f0 28
9572a9dd 29;;; Commentary:
cb3fe1f0 30
b578f267
EN
31;; This is Sebastian Kremer's excellent dired-x.el (Dired Extra), version
32;; 1.191, hacked up for GNU Emacs 19. Redundant or conflicting material
33;; has been removed or renamed in order to work properly with dired of
34;; GNU Emacs 19. All suggestions or comments are most welcomed.
35
36;;
37;; Please, PLEASE, *PLEASE* see the info pages.
38;;
39
40;; BUGS: Type M-x dired-x-submit-report and a report will be generated.
41
42;; INSTALLATION: In your ~/.emacs,
43;;
44;; (add-hook 'dired-load-hook
45;; (function (lambda ()
46;; (load "dired-x")
47;; ;; Set global variables here. For example:
48;; ;; (setq dired-guess-shell-gnutar "gtar")
49;; )))
50;; (add-hook 'dired-mode-hook
51;; (function (lambda ()
52;; ;; Set buffer-local variables here. For example:
53;; ;; (setq dired-omit-files-p t)
54;; )))
55;;
56;; At load time dired-x.el will install itself, redefine some functions, and
57;; bind some dired keys. *Please* see the info pages for more details.
58
59;; CAUTION: If you are using a version of GNU Emacs earlier than 19.20 than
60;; you may have to edit dired.el. The copy of dired.el in GNU Emacs versions
61;; earlier than 19.20 incorrectly had the call to run-hooks *before* the call
62;; to provide. In such a case, it is possible that byte-compiling and/or
63;; loading dired can cause an infinite loop. To prevent this, make sure the
64;; line of code
65;;
66;; (run-hooks 'dired-load-hook)
67;;
68;; is the *last* executable line in the file dired.el. That is, make sure it
69;; comes *after* the line
70;;
71;; (provide 'dired)
72;;
73;; *Please* see the info pages for more details.
74
75;; User defined variables:
76;;
77;; dired-bind-vm
78;; dired-vm-read-only-folders
79;; dired-bind-jump
80;; dired-bind-info
81;; dired-bind-man
82;; dired-x-hands-off-my-keys
83;; dired-find-subdir
84;; dired-enable-local-variables
85;; dired-local-variables-file
86;; dired-guess-shell-gnutar
87;; dired-guess-shell-gzip-quiet
88;; dired-guess-shell-znew-switches
89;; dired-guess-shell-alist-user
90;; dired-clean-up-buffers-too
91;; dired-omit-files-p
92;; dired-omit-files
93;; dired-omit-extensions
ad8c4554 94;; dired-omit-size-limit
b578f267
EN
95;;
96;; To find out more about these variables, load this file, put your cursor at
97;; the end of any of the variable names, and hit C-h v [RET]. *Please* see
98;; the info pages for more details.
99
100;; When loaded this code redefines the following functions of GNU Emacs
101;;
102;; Function Found in this file of GNU Emacs
103;; -------- -------------------------------
104;; dired-clean-up-after-deletion ../lisp/dired.el
105;; dired-find-buffer-nocreate ../lisp/dired.el
106;; dired-initial-position ../lisp/dired.el
107;;
108;; dired-add-entry ../lisp/dired-aux.el
109;; dired-read-shell-command ../lisp/dired-aux.el
110;;
111;; One drawback is that dired-x.el will load dired-aux.el as soon as dired is
112;; loaded. Thus, the advantage of separating out non-essential dired stuff
113;; into dired-aux.el and only loading when necessary will be lost. Please
114;; note also that some of the comments in dired.el and dired-aux.el are
115;; Kremer's that referred to the old dired-x.el. This now should be referring
116;; to this program. (This is also a good reason to call this dired-x.el
117;; instead of dired-x19.el.)
cb3fe1f0
RS
118
119\f
b578f267 120;;; Code:
cb3fe1f0 121
b578f267 122;; LOAD.
cb3fe1f0 123
b578f267
EN
124;; This is a no-op if dired-x is being loaded via `dired-load-hook'. It is
125;; here in case the user has autoloaded dired-x via the dired-jump key binding
126;; (instead of autoloading to dired as is suggested in the info-pages).
9572a9dd 127
d82cfc0c 128(require 'dired)
9572a9dd 129
b578f267
EN
130;; We will redefine some functions and also need some macros so we need to
131;; load dired stuff of GNU Emacs.
d82cfc0c
RS
132
133(require 'dired-aux)
9572a9dd 134
b578f267 135;;; User-defined variables.
cb3fe1f0 136
286c247d
RS
137(defgroup dired-x nil
138 "Extended directory editing (dired-x)."
139 :group 'dired)
cb3fe1f0 140
286c247d
RS
141(defgroup dired-keys nil
142 "Dired keys customizations."
143 :prefix "dired-"
144 :group 'dired-x)
cb3fe1f0 145
286c247d
RS
146(defcustom dired-bind-vm nil
147 "*t says \"V\" in dired-mode will `dired-vm', otherwise \"V\" is `dired-rmail'.
148Also, RMAIL files contain -*- rmail -*- at the top so \"f\",
149`dired-advertised-find-file', will run rmail."
150 :type 'boolean
151 :group 'dired-keys)
152
153(defcustom dired-bind-jump t
154 "*t says bind `dired-jump' to C-x C-j, otherwise do not."
155 :type 'boolean
156 :group 'dired-keys)
157
158(defcustom dired-bind-man t
159 "*t says bind `dired-man' to \"N\" in dired-mode, otherwise do not."
160 :type 'boolean
161 :group 'dired-keys)
162
163(defcustom dired-bind-info t
164 "*t says bind `dired-info' to \"I\" in dired-mode, otherwise do not."
165 :type 'boolean
166 :group 'dired-keys)
167
168(defcustom dired-vm-read-only-folders nil
cb3fe1f0
RS
169 "*If t, \\[dired-vm] will visit all folders read-only.
170If neither nil nor t, e.g. the symbol `if-file-read-only', only
171files not writable by you are visited read-only.
172
286c247d
RS
173Read-only folders only work in VM 5, not in VM 4."
174 :type '(choice (const :tag "off" nil)
175 (const :tag "on" t)
e2c146c1 176 (other :tag "non-writable only" if-file-read-only))
286c247d 177 :group 'dired-x)
cb3fe1f0 178
286c247d 179(defcustom dired-omit-files-p nil
cb3fe1f0
RS
180 "*If non-nil, \"uninteresting\" files are not listed (buffer-local).
181Use \\[dired-omit-toggle] to toggle its value.
182Uninteresting files are those whose filenames match regexp `dired-omit-files',
286c247d
RS
183plus those ending with extensions in `dired-omit-extensions'."
184 :type 'boolean
185 :group 'dired-x)
e2439696 186(make-variable-buffer-local 'dired-omit-files-p)
cb3fe1f0 187
99358b97 188(defcustom dired-omit-files "^\\.?#\\|^\\.$\\|^\\.\\.$"
e2439696 189 "*Filenames matching this regexp will not be displayed.
685ff9f8
RS
190This only has effect when `dired-omit-files-p' is t. See interactive function
191`dired-omit-toggle' \(\\[dired-omit-toggle]\) and variable
99358b97
RS
192`dired-omit-extensions'. The default is to omit `.', `..', auto-save
193files and lock files."
286c247d
RS
194 :type 'regexp
195 :group 'dired-x)
cb3fe1f0 196
286c247d 197(defcustom dired-find-subdir nil ; t is pretty near to DWIM...
0a44133e
RS
198 "*If non-nil, Dired always finds a directory in a buffer of its own.
199If nil, Dired finds the directory as a subdirectory in some other buffer
200if it is present as one.
cb3fe1f0
RS
201
202If there are several Dired buffers for a directory, the most recently
203used is chosen.
204
205Dired avoids switching to the current buffer, so that if you have
206a normal and a wildcard buffer for the same directory, C-x d RET will
286c247d
RS
207toggle between those two."
208 :type 'boolean
209 :group 'dired-x)
210
8e458944 211(defcustom dired-omit-size-limit 30000
286c247d
RS
212 "*Maximum size for the \"omitting\" feature.
213If nil, there is no maximum size."
214 :type '(choice (const :tag "no maximum" nil) integer)
215 :group 'dired-x)
cb3fe1f0 216
286c247d 217(defcustom dired-enable-local-variables t
cb3fe1f0
RS
218 "*Control use of local-variables lists in dired.
219The value can be t, nil or something else.
220A value of t means local-variables lists are obeyed;
221nil means they are ignored; anything else means query.
222
223This temporarily overrides the value of `enable-local-variables' when listing
286c247d
RS
224a directory. See also `dired-local-variables-file'."
225 :type 'boolean
226 :group 'dired-x)
cb3fe1f0 227
286c247d 228(defcustom dired-guess-shell-gnutar nil
cb3fe1f0
RS
229 "*If non-nil, name of GNU tar executable (e.g., \"tar\" or \"gtar\") and `z'
230switch will be used for compressed or gzip'ed tar files. If no GNU tar, set
286c247d
RS
231to nil: a pipe using `zcat' or `gunzip -c' will be used."
232 :type 'boolean
233 :group 'dired-x)
234
235(defcustom dired-guess-shell-gzip-quiet t
236 "*non-nil says pass -q to gzip overriding verbose GZIP environment."
237 :type 'boolean
238 :group 'dired-x)
239
240(defcustom dired-guess-shell-znew-switches nil
241 "*If non-nil, then string of switches passed to `znew', example: \"-K\""
242 :type 'boolean
243 :group 'dired-x)
244
245(defcustom dired-clean-up-buffers-too t
246 "*t says offer to kill buffers visiting files and dirs deleted in dired."
247 :type 'boolean
248 :group 'dired-x)
cb3fe1f0 249
b578f267 250;;; KEY BINDINGS.
cb3fe1f0
RS
251
252(define-key dired-mode-map "\M-o" 'dired-omit-toggle)
253(define-key dired-mode-map "\M-(" 'dired-mark-sexp)
582bd36a
RS
254(define-key dired-mode-map "*(" 'dired-mark-sexp)
255(define-key dired-mode-map "*." 'dired-mark-extension)
cb3fe1f0 256(define-key dired-mode-map "\M-!" 'dired-smart-shell-command)
cb3fe1f0
RS
257(define-key dired-mode-map "w" 'dired-copy-filename-as-kill)
258(define-key dired-mode-map "\M-g" 'dired-goto-file)
259(define-key dired-mode-map "\M-G" 'dired-goto-subdir)
260(define-key dired-mode-map "F" 'dired-do-find-marked-files)
261(define-key dired-mode-map "Y" 'dired-do-relsymlink)
262(define-key dired-mode-map "%Y" 'dired-do-relsymlink-regexp)
263(define-key dired-mode-map "V" 'dired-do-run-mail)
264
265(if dired-bind-man
266 (define-key dired-mode-map "N" 'dired-man))
267
268(if dired-bind-info
269 (define-key dired-mode-map "I" 'dired-info))
270
9572a9dd 271;;; GLOBAL BINDING.
cb3fe1f0
RS
272(if dired-bind-jump
273 (progn
274 (define-key global-map "\C-x\C-j" 'dired-jump)
275 (define-key global-map "\C-x4\C-j" 'dired-jump-other-window)))
276
277\f
b578f267 278;;; Install into appropriate hooks.
cb3fe1f0
RS
279
280(add-hook 'dired-mode-hook 'dired-extra-startup)
281(add-hook 'dired-after-readin-hook 'dired-omit-expunge)
282
283(defun dired-extra-startup ()
284 "Automatically put on dired-mode-hook to get extra dired features:
285\\<dired-mode-map>
286
287 \\[dired-do-run-mail]\t-- run mail on folder (see `dired-bind-vm')
288 \\[dired-info]\t-- run info on file
289 \\[dired-man]\t-- run man on file
290 \\[dired-do-find-marked-files]\t-- visit all marked files simultaneously
291 \\[dired-omit-toggle]\t-- toggle omitting of files
cb3fe1f0
RS
292 \\[dired-mark-sexp]\t-- mark by lisp expression
293 \\[dired-copy-filename-as-kill]\t-- copy the file or subdir names into the kill ring.
294 \t You can feed it to other commands using \\[yank].
295
296For more features, see variables
297
298 dired-bind-vm
299 dired-bind-jump
300 dired-bind-info
301 dired-bind-man
302 dired-vm-read-only-folders
303 dired-omit-files-p
304 dired-omit-files
305 dired-omit-extensions
ad8c4554 306 dired-omit-size-limit
cb3fe1f0
RS
307 dired-find-subdir
308 dired-enable-local-variables
309 dired-local-variables-file
310 dired-guess-shell-gnutar
311 dired-guess-shell-gzip-quiet
312 dired-guess-shell-znew-switches
313 dired-guess-shell-alist-user
9572a9dd 314 dired-clean-up-buffers-too
cb3fe1f0
RS
315
316See also functions
317
318 dired-flag-extension
319 dired-virtual
320 dired-jump
321 dired-man
322 dired-vm
323 dired-rmail
324 dired-info
325 dired-do-find-marked-files
326"
327 (interactive)
328
329 ;; These must be done in each new dired buffer.
330 (dired-hack-local-variables)
331 (dired-omit-startup))
332
333\f
b578f267 334;;; BUFFER CLEANING.
cb3fe1f0 335
b578f267 336;; REDEFINE.
cb3fe1f0
RS
337(defun dired-clean-up-after-deletion (fn)
338
339 ;; Clean up after a deleted file or directory FN.
340 ;; Remove expanded subdir of deleted dir, if any.
341 (save-excursion (and (cdr dired-subdir-alist)
342 (dired-goto-subdir fn)
343 (dired-kill-subdir)))
344
345 ;; Offer to kill buffer of deleted file FN.
346 (if dired-clean-up-buffers-too
347 (progn
348 (let ((buf (get-file-buffer fn)))
349 (and buf
350 (funcall (function y-or-n-p)
351 (format "Kill buffer of %s, too? "
352 (file-name-nondirectory fn)))
353 (save-excursion ; you never know where kill-buffer leaves you
354 (kill-buffer buf))))
12c38283 355 (let ((buf-list (dired-buffers-for-dir (expand-file-name fn)))
cb3fe1f0
RS
356 (buf nil))
357 (and buf-list
358 (y-or-n-p (format "Kill dired buffer%s of %s, too? "
359 (dired-plural-s (length buf-list))
360 (file-name-nondirectory fn)))
361 (while buf-list
362 (save-excursion (kill-buffer (car buf-list)))
363 (setq buf-list (cdr buf-list)))))))
9572a9dd 364 ;; Anything else?
cb3fe1f0
RS
365 )
366
367\f
b578f267 368;;; EXTENSION MARKING FUNCTIONS.
cb3fe1f0 369
9572a9dd 370;;; Mark files with some extension.
cb3fe1f0
RS
371(defun dired-mark-extension (extension &optional marker-char)
372 "Mark all files with a certain extension for use in later commands.
373A `.' is not automatically prepended to the string entered."
374 ;; EXTENSION may also be a list of extensions instead of a single one.
375 ;; Optional MARKER-CHAR is marker to use.
376 (interactive "sMarking extension: \nP")
377 (or (listp extension)
378 (setq extension (list extension)))
379 (dired-mark-files-regexp
380 (concat ".";; don't match names with nothing but an extension
381 "\\("
382 (mapconcat 'regexp-quote extension "\\|")
383 "\\)$")
384 marker-char))
385
386(defun dired-flag-extension (extension)
387 "In dired, flag all files with a certain extension for deletion.
388A `.' is *not* automatically prepended to the string entered."
389 (interactive "sFlagging extension: ")
390 (dired-mark-extension extension dired-del-marker))
391
392;;; Define some unpopular file extensions. Used for cleaning and omitting.
393
394(defvar dired-patch-unclean-extensions
395 '(".rej" ".orig")
396 "List of extensions of dispensable files created by the `patch' program.")
397
398(defvar dired-tex-unclean-extensions
399 '(".toc" ".log" ".aux");; these are already in completion-ignored-extensions
400 "List of extensions of dispensable files created by TeX.")
401
402(defvar dired-latex-unclean-extensions
403 '(".idx" ".lof" ".lot" ".glo")
404 "List of extensions of dispensable files created by LaTeX.")
405
406(defvar dired-bibtex-unclean-extensions
407 '(".blg" ".bbl")
408 "List of extensions of dispensable files created by BibTeX.")
409
410(defvar dired-texinfo-unclean-extensions
411 '(".cp" ".cps" ".fn" ".fns" ".ky" ".kys" ".pg" ".pgs"
412 ".tp" ".tps" ".vr" ".vrs")
413 "List of extensions of dispensable files created by texinfo.")
414
415(defun dired-clean-patch ()
416 "Flag dispensable files created by patch for deletion.
417See variable `dired-patch-unclean-extensions'."
418 (interactive)
419 (dired-flag-extension dired-patch-unclean-extensions))
420
421(defun dired-clean-tex ()
9572a9dd
KH
422 "Flag dispensable files created by [La]TeX etc. for deletion.
423See variables `dired-texinfo-unclean-extensions',
424`dired-latex-unclean-extensions', `dired-bibtex-unclean-extensions' and
425`dired-texinfo-unclean-extensions'."
cb3fe1f0
RS
426 (interactive)
427 (dired-flag-extension (append dired-texinfo-unclean-extensions
428 dired-latex-unclean-extensions
429 dired-bibtex-unclean-extensions
430 dired-tex-unclean-extensions)))
431
9572a9dd
KH
432(defun dired-very-clean-tex ()
433 "Flag dispensable files created by [La]TeX *and* \".dvi\" for deletion.
434See variables `dired-texinfo-unclean-extensions',
435`dired-latex-unclean-extensions', `dired-bibtex-unclean-extensions' and
436`dired-texinfo-unclean-extensions'."
cb3fe1f0 437 (interactive)
9572a9dd
KH
438 (dired-flag-extension (append dired-texinfo-unclean-extensions
439 dired-latex-unclean-extensions
440 dired-bibtex-unclean-extensions
441 dired-tex-unclean-extensions
442 (list ".dvi"))))
cb3fe1f0 443\f
b578f267 444;;; JUMP.
cb3fe1f0 445
40c8b203 446;;;###autoload
cb3fe1f0
RS
447(defun dired-jump (&optional other-window)
448 "Jump to dired buffer corresponding to current buffer.
449If in a file, dired the current directory and move to file's line.
450If in dired already, pop up a level and goto old directory's line.
451In case the proper dired file line cannot be found, refresh the dired
452buffer and try again."
453 (interactive "P")
454 (let* ((file buffer-file-name)
455 (dir (if file (file-name-directory file) default-directory)))
456 (if (eq major-mode 'dired-mode)
457 (progn
458 (setq dir (dired-current-directory))
459 (dired-up-directory other-window)
460 (or (dired-goto-file dir)
461 ;; refresh and try again
9572a9dd 462 (progn
cb3fe1f0
RS
463 (dired-insert-subdir (file-name-directory dir))
464 (dired-goto-file dir))))
465 (if other-window
466 (dired-other-window dir)
467 (dired dir))
468 (if file
469 (or (dired-goto-file file)
470 ;; refresh and try again
9572a9dd 471 (progn
cb3fe1f0 472 (dired-insert-subdir (file-name-directory file))
7e90bcf5
RS
473 (dired-goto-file file))
474 ;; Toggle omitting, if it is on, and try again.
475 (if dired-omit-files-p
476 (progn
477 (dired-omit-toggle)
478 (dired-goto-file file))))))))
cb3fe1f0
RS
479
480(defun dired-jump-other-window ()
481 "Like \\[dired-jump] (dired-jump) but in other window."
482 (interactive)
483 (dired-jump t))
cb3fe1f0 484\f
b578f267 485;;; COPY NAMES OF MARKED FILES INTO KILL-RING.
9572a9dd 486
cb3fe1f0
RS
487(defun dired-copy-filename-as-kill (&optional arg)
488 "Copy names of marked (or next ARG) files into the kill ring.
489The names are separated by a space.
490With a zero prefix arg, use the complete pathname of each marked file.
491With \\[universal-argument], use the relative pathname of each marked file.
492
493If on a subdir headerline, use subdirname instead; prefix arg is ignored
494in this case.
495
496You can then feed the file name(s) to other commands with \\[yank]."
497 (interactive "P")
498 (let ((string
499 (or (dired-get-subdir)
500 (mapconcat (function identity)
501 (if arg
502 (cond ((zerop (prefix-numeric-value arg))
503 (dired-get-marked-files))
504 ((integerp arg)
505 (dired-get-marked-files 'no-dir arg))
506 (t ; else a raw arg
507 (dired-get-marked-files t)))
508 (dired-get-marked-files 'no-dir))
509 " "))))
510 (kill-new string)
511 (message "%s" string)))
512
513\f
b578f267 514;;; OMITTING.
cb3fe1f0
RS
515
516;;; Enhanced omitting of lines from directory listings.
517;;; Marked files are never omitted.
518
519;; should probably get rid of this and always use 'no-dir.
520;; sk 28-Aug-1991 09:37
521(defvar dired-omit-localp 'no-dir
522 "The LOCALP argument dired-omit-expunge passes to dired-get-filename.
523If it is 'no-dir, omitting is much faster, but you can only match
524against the basename of the file. Set it to nil if you need to match the
525whole pathname.")
526
527;; \017=^O for Omit - other packages can chose other control characters.
528(defvar dired-omit-marker-char ?\017
529 "Temporary marker used by by dired-omit.
530Should never be used as marker by the user or other packages.")
531
532(defun dired-omit-startup ()
cb3fe1f0
RS
533 (or (assq 'dired-omit-files-p minor-mode-alist)
534 (setq minor-mode-alist
535 (append '((dired-omit-files-p " Omit")) minor-mode-alist))))
536
537(defun dired-omit-toggle (&optional flag)
685ff9f8 538 "Toggle omitting files matching `dired-omit-files' and `dired-omit-extensions'.
cb3fe1f0
RS
539With an arg, and if omitting was off, don't toggle and just mark the
540 files but don't actually omit them.
541With an arg, and if omitting was on, turn it off but don't refresh the buffer."
542 (interactive "P")
543 (if flag
544 (if dired-omit-files-p
545 (setq dired-omit-files-p (not dired-omit-files-p))
546 (dired-mark-unmarked-files (dired-omit-regexp) nil nil
547 dired-omit-localp))
548 ;; no FLAG
549 (setq dired-omit-files-p (not dired-omit-files-p))
550 (if (not dired-omit-files-p)
551 (revert-buffer)
552 ;; this will mention how many were omitted:
ad8c4554
RS
553 (let ((dired-omit-size-limit nil))
554 (dired-omit-expunge)))))
cb3fe1f0
RS
555
556(defvar dired-omit-extensions
557 (append completion-ignored-extensions
558 dired-latex-unclean-extensions
559 dired-bibtex-unclean-extensions
560 dired-texinfo-unclean-extensions)
685ff9f8
RS
561 "If non-nil, a list of extensions \(strings\) to omit from Dired listings.
562Defaults to elements of `completion-ignored-extensions',
563`dired-latex-unclean-extensions', `dired-bibtex-unclean-extensions', and
564`dired-texinfo-unclean-extensions'.
565
566See interactive function `dired-omit-toggle' \(\\[dired-omit-toggle]\) and
567variables `dired-omit-files-p' and `dired-omit-files'.")
cb3fe1f0
RS
568
569(defun dired-omit-expunge (&optional regexp)
570 "Erases all unmarked files matching REGEXP.
ad8c4554
RS
571Does nothing if global variable `dired-omit-files-p' is nil, or if called
572 non-interactively and buffer is bigger than `dired-omit-size-limit'.
cb3fe1f0
RS
573If REGEXP is nil or not specified, uses `dired-omit-files', and also omits
574 filenames ending in `dired-omit-extensions'.
575If REGEXP is the empty string, this function is a no-op.
576
577This functions works by temporarily binding `dired-marker-char' to
578`dired-omit-marker-char' and calling `dired-do-kill-lines'."
579 (interactive "sOmit files (regexp): ")
ad8c4554
RS
580 (if (and dired-omit-files-p
581 (or (interactive-p)
582 (not dired-omit-size-limit)
8e458944
RS
583 (< (buffer-size) dired-omit-size-limit)
584 (progn
585 (message "Not omitting: directory larger than %d characters."
586 dired-omit-size-limit)
587 (setq dired-omit-files-p nil)
588 nil)))
cb3fe1f0 589 (let ((omit-re (or regexp (dired-omit-regexp)))
9b5ef74b 590 (old-modified-p (buffer-modified-p))
cb3fe1f0
RS
591 count)
592 (or (string= omit-re "")
593 (let ((dired-marker-char dired-omit-marker-char))
594 (message "Omitting...")
595 (if (dired-mark-unmarked-files omit-re nil nil dired-omit-localp)
596 (progn
597 (setq count (dired-do-kill-lines nil "Omitted %d line%s."))
048ea441 598 (force-mode-line-update))
cb3fe1f0 599 (message "(Nothing to omit)"))))
9b5ef74b
RS
600 ;; Try to preserve modified state of buffer. So `%*' doesn't appear
601 ;; in mode-line of omitted buffers.
602 (set-buffer-modified-p (and old-modified-p
603 (save-excursion
604 (goto-char (point-min))
605 (re-search-forward dired-re-mark nil t))))
cb3fe1f0
RS
606 count)))
607
608(defun dired-omit-regexp ()
609 (concat (if dired-omit-files (concat "\\(" dired-omit-files "\\)") "")
610 (if (and dired-omit-files dired-omit-extensions) "\\|" "")
611 (if dired-omit-extensions
612 (concat ".";; a non-extension part should exist
613 "\\("
614 (mapconcat 'regexp-quote dired-omit-extensions "\\|")
615 "\\)$")
616 "")))
617
618;; Returns t if any work was done, nil otherwise.
619(defun dired-mark-unmarked-files (regexp msg &optional unflag-p localp)
620 "Marks unmarked files matching REGEXP, displaying MSG.
621REGEXP is matched against the complete pathname.
622Does not re-mark files which already have a mark.
623With prefix argument, unflag all those files.
624Second optional argument LOCALP is as in `dired-get-filename'."
625 (interactive "P")
626 (let ((dired-marker-char (if unflag-p ?\ dired-marker-char)))
627 (dired-mark-if
628 (and
629 ;; not already marked
630 (looking-at " ")
631 ;; uninteresting
632 (let ((fn (dired-get-filename localp t)))
633 (and fn (string-match regexp fn))))
634 msg)))
635
9572a9dd 636;;; REDEFINE.
c8225cbe 637(defun dired-omit-new-add-entry (filename &optional marker-char relative)
cb3fe1f0
RS
638 ;; This redefines dired-aux.el's dired-add-entry to avoid calling ls for
639 ;; files that are going to be omitted anyway.
640 (if dired-omit-files-p
641 ;; perhaps return t without calling ls
642 (let ((omit-re (dired-omit-regexp)))
643 (if (or (string= omit-re "")
644 (not
645 (string-match omit-re
646 (cond
647 ((eq 'no-dir dired-omit-localp)
648 filename)
649 ((eq t dired-omit-localp)
650 (dired-make-relative filename))
651 (t
652 (dired-make-absolute
653 filename
654 (file-name-directory filename)))))))
655 ;; if it didn't match, go ahead and add the entry
c8225cbe 656 (dired-omit-old-add-entry filename marker-char relative)
cb3fe1f0
RS
657 ;; dired-add-entry returns t for success, perhaps we should
658 ;; return file-exists-p
659 t))
660 ;; omitting is not turned on at all
c8225cbe 661 (dired-omit-old-add-entry filename marker-char relative)))
cb3fe1f0 662
9572a9dd 663;;; REDEFINE.
cb3fe1f0
RS
664;;; Redefine dired-aux.el's version of `dired-add-entry'
665;;; Save old defun if not already done:
666(or (fboundp 'dired-omit-old-add-entry)
667 (fset 'dired-omit-old-add-entry (symbol-function 'dired-add-entry)))
668;; Redefine it.
669(fset 'dired-add-entry 'dired-omit-new-add-entry)
670
671\f
b578f267 672;;; VIRTUAL DIRED MODE.
cb3fe1f0
RS
673
674;;; For browsing `ls -lR' listings in a dired-like fashion.
675
676(fset 'virtual-dired 'dired-virtual)
677(defun dired-virtual (dirname &optional switches)
678 "Put this buffer into Virtual Dired mode.
679
680In Virtual Dired mode, all commands that do not actually consult the
681filesystem will work.
682
683This is useful if you want to peruse and move around in an ls -lR
684output file, for example one you got from an ftp server. With
685ange-ftp, you can even dired a directory containing an ls-lR file,
686visit that file and turn on virtual dired mode. But don't try to save
687this file, as dired-virtual indents the listing and thus changes the
688buffer.
689
690If you have save a Dired buffer in a file you can use \\[dired-virtual] to
691resume it in a later session.
692
693Type \\<dired-mode-map>\\[revert-buffer] in the
694Virtual Dired buffer and answer `y' to convert the virtual to a real
695dired buffer again. You don't have to do this, though: you can relist
696single subdirs using \\[dired-do-redisplay].
697"
698
699 ;; DIRNAME is the top level directory of the buffer. It will become
700 ;; its `default-directory'. If nil, the old value of
701 ;; default-directory is used.
702
703 ;; Optional SWITCHES are the ls switches to use.
704
705 ;; Shell wildcards will be used if there already is a `wildcard'
706 ;; line in the buffer (thus it is a saved Dired buffer), but there
707 ;; is no other way to get wildcards. Insert a `wildcard' line by
708 ;; hand if you want them.
709
710 (interactive
711 (list (read-string "Virtual Dired directory: " (dired-virtual-guess-dir))))
712 (goto-char (point-min))
713 (or (looking-at " ")
714 ;; if not already indented, do it now:
715 (indent-region (point-min) (point-max) 2))
716 (or dirname (setq dirname default-directory))
717 (setq dirname (expand-file-name (file-name-as-directory dirname)))
718 (setq default-directory dirname) ; contains no wildcards
719 (let ((wildcard (save-excursion
720 (goto-char (point-min))
721 (forward-line 1)
722 (and (looking-at "^ wildcard ")
723 (buffer-substring (match-end 0)
724 (progn (end-of-line) (point)))))))
725 (if wildcard
726 (setq dirname (expand-file-name wildcard default-directory))))
727 ;; If raw ls listing (not a saved old dired buffer), give it a
728 ;; decent subdir headerline:
729 (goto-char (point-min))
730 (or (looking-at dired-subdir-regexp)
731 (dired-insert-headerline default-directory))
732 (dired-mode dirname (or switches dired-listing-switches))
733 (setq mode-name "Virtual Dired"
734 revert-buffer-function 'dired-virtual-revert)
735 (set (make-local-variable 'dired-subdir-alist) nil)
736 (dired-build-subdir-alist)
737 (goto-char (point-min))
738 (dired-initial-position dirname))
739
740(defun dired-virtual-guess-dir ()
741
742 ;; Guess and return appropriate working directory of this buffer,
743 ;; assumed to be in Dired or ls -lR format.
744 ;; The guess is based upon buffer contents.
745 ;; If nothing could be guessed, returns nil.
746
747 (let ((regexp "^\\( \\)?\\([^ \n\r]*\\)\\(:\\)[\n\r]")
748 (subexpr 2))
749 (goto-char (point-min))
750 (cond ((looking-at regexp)
751 ;; If a saved dired buffer, look to which dir and
752 ;; perhaps wildcard it belongs:
753 (let ((dir (buffer-substring (match-beginning subexpr)
754 (match-end subexpr))))
755 (file-name-as-directory dir)))
756 ;; Else no match for headerline found. It's a raw ls listing.
757 ;; In raw ls listings the directory does not have a headerline
758 ;; try parent of first subdir, if any
759 ((re-search-forward regexp nil t)
760 (file-name-directory
761 (directory-file-name
762 (file-name-as-directory
763 (buffer-substring (match-beginning subexpr)
764 (match-end subexpr))))))
765 (t ; if all else fails
766 nil))))
767
768
769(defun dired-virtual-revert (&optional arg noconfirm)
770 (if (not
771 (y-or-n-p "Cannot revert a Virtual Dired buffer - switch to Real Dired mode? "))
772 (error "Cannot revert a Virtual Dired buffer.")
773 (setq mode-name "Dired"
774 revert-buffer-function 'dired-revert)
775 (revert-buffer)))
776
777;; A zero-arg version of dired-virtual.
778;; You need my modified version of set-auto-mode for the
779;; `buffer-contents-mode-alist'.
780;; Or you use infer-mode.el and infer-mode-alist, same syntax.
781(defun dired-virtual-mode ()
782 "Put current buffer into virtual dired mode (see `dired-virtual').
783Useful on `buffer-contents-mode-alist' (which see) with the regexp
784
785 \"^ \\(/[^ /]+\\)/?+:$\"
786
787to put saved dired buffers automatically into virtual dired mode.
788
789Also useful for `auto-mode-alist' (which see) like this:
790
e7070c01 791 \(setq auto-mode-alist (cons '(\"[^/]\\.dired\\'\" . dired-virtual-mode)
cb3fe1f0
RS
792 auto-mode-alist)\)"
793 (interactive)
794 (dired-virtual (dired-virtual-guess-dir)))
795
796\f
b578f267 797;;; SMART SHELL.
cb3fe1f0
RS
798
799;;; An Emacs buffer can have but one working directory, stored in the
800;;; buffer-local variable `default-directory'. A Dired buffer may have
801;;; several subdirectories inserted, but still has but one working directory:
802;;; that of the top level Dired directory in that buffer. For some commands
803;;; it is appropriate that they use the current Dired directory instead of
804;;; `default-directory', e.g., `find-file' and `compile'. This is a general
805;;; mechanism is provided for special handling of the working directory in
806;;; special major modes.
807
808;; It's easier to add to this alist than redefine function
809;; default-directory while keeping the old information.
810(defconst default-directory-alist
811 '((dired-mode . (if (fboundp 'dired-current-directory)
812 (dired-current-directory)
813 default-directory)))
814 "Alist of major modes and their opinion on default-directory, as a
815lisp expression to evaluate. A resulting value of nil is ignored in
816favor of default-directory.")
817
818(defun default-directory ()
819 "Usage like variable `default-directory', but knows about the special
820cases in variable `default-directory-alist' (which see)."
821 (or (eval (cdr (assq major-mode default-directory-alist)))
822 default-directory))
823
824(defun dired-smart-shell-command (cmd &optional insert)
825 "Like function `shell-command', but in the current Tree Dired directory."
93714f3c
GM
826 (interactive (list (read-from-minibuffer "Shell command: "
827 nil nil nil 'shell-command-history)
828 current-prefix-arg))
cb3fe1f0
RS
829 (let ((default-directory (default-directory)))
830 (shell-command cmd insert)))
831
832\f
b578f267 833;;; LOCAL VARIABLES FOR DIRED BUFFERS.
cb3fe1f0 834
9572a9dd
KH
835;;; Brief Description:
836;;;
837;;; * `dired-extra-startup' is part of the `dired-mode-hook'.
838;;;
cb3fe1f0 839;;; * `dired-extra-startup' calls `dired-hack-local-variables'
9572a9dd 840;;;
cb3fe1f0 841;;; * `dired-hack-local-variables' checks the value of
9572a9dd
KH
842;;; `dired-local-variables-file'
843;;;
cb3fe1f0
RS
844;;; * Check if `dired-local-variables-file' is a non-nil string and is a
845;;; filename found in the directory of the Dired Buffer being created.
9572a9dd 846;;;
cb3fe1f0
RS
847;;; * If `dired-local-variables-file' satisfies the above, then temporarily
848;;; include it in the Dired Buffer at the bottom.
9572a9dd 849;;;
cb3fe1f0
RS
850;;; * Set `enable-local-variables' temporarily to the user variable
851;;; `dired-enable-local-variables' and run `hack-local-variables' on the
852;;; Dired Buffer.
853
db8f8812 854(defvar dired-local-variables-file (convert-standard-filename ".dired")
cb3fe1f0
RS
855 "Filename, as string, containing local dired buffer variables to be hacked.
856If this file found in current directory, then it will be inserted into dired
857buffer and `hack-local-variables' will be run. See Emacs Info pages for more
858information on local variables. See also `dired-enable-local-variables'.")
859
860(defun dired-hack-local-variables ()
861 "Evaluate local variables in `dired-local-variables-file' for dired buffer."
862 (if (and dired-local-variables-file
863 (stringp dired-local-variables-file)
864 (file-exists-p dired-local-variables-file))
865 (let ((opoint (point-max))
866 buffer-read-only
867 ;; In case user has `enable-local-variables' set to nil we
868 ;; override it locally with dired's variable.
869 (enable-local-variables dired-enable-local-variables))
870 ;; Insert 'em.
871 (save-excursion
872 (goto-char opoint)
873 (insert "\^L\n")
874 (insert-file-contents dired-local-variables-file))
875 ;; Hack 'em.
876 (let ((buffer-file-name dired-local-variables-file))
877 (hack-local-variables))
878 ;; Make sure that the modeline shows the proper information.
879 (dired-sort-set-modeline)
880 ;; Delete this stuff: `eobp' is used to find last subdir by dired.el.
9572a9dd 881 (delete-region opoint (point-max)))))
cb3fe1f0 882
9572a9dd 883(defun dired-omit-here-always ()
cb3fe1f0
RS
884 "Creates `dired-local-variables-file' for omitting and reverts directory.
885Sets dired-omit-file-p to t in a local variables file that is readable by
886dired."
9572a9dd 887 (interactive)
cb3fe1f0
RS
888 (if (file-exists-p dired-local-variables-file)
889 (message "File `./%s' already exists." dired-local-variables-file)
890
891 ;; Create `dired-local-variables-file'.
892 (save-excursion
893 (set-buffer (get-buffer-create " *dot-dired*"))
894 (erase-buffer)
895 (insert "Local Variables:\ndired-omit-files-p: t\nEnd:\n")
896 (write-file dired-local-variables-file)
897 (kill-buffer (current-buffer)))
898
899 ;; Run extra-hooks and revert directory.
900 (dired-extra-startup)
901 (dired-revert)))
902
903\f
b578f267 904;;; GUESS SHELL COMMAND.
cb3fe1f0 905
9572a9dd
KH
906;;; Brief Description:
907;;;
908;;; `dired-do-shell-command' is bound to `!' by dired.el.
909;;;
cb3fe1f0
RS
910;;; * Redefine `dired-do-shell-command' so it calls
911;;; `dired-guess-shell-command'.
9572a9dd 912;;;
cb3fe1f0
RS
913;;; * `dired-guess-shell-command' calls `dired-guess-default' with list of
914;;; marked files.
9572a9dd 915;;;
cb3fe1f0
RS
916;;; * Parse `dired-guess-shell-alist-user' and
917;;; `dired-guess-shell-alist-default' (in that order) for the first REGEXP
918;;; that matches the first file in the file list.
9572a9dd 919;;;
cb3fe1f0 920;;; * If the REGEXP matches all the entries of the file list then evaluate
c0d79871 921;;; COMMAND, which is either a string or a Lisp expression returning a
cb3fe1f0 922;;; string. COMMAND may be a list of commands.
9572a9dd 923;;;
cb3fe1f0 924;;; * Return this command to `dired-guess-shell-command' which prompts user
34ff2275 925;;; with it. The list of commands is temporarily put into the history list.
cb3fe1f0
RS
926;;; If a command is used successfully then it is stored permanently in
927;;; `dired-shell-command-history'.
928
929;;; Guess what shell command to apply to a file.
930(defvar dired-shell-command-history nil
931 "History list for commands that read dired-shell commands.")
932
9572a9dd 933;;; Default list of shell commands.
cb3fe1f0
RS
934
935;;; NOTE: Use `gunzip -c' instead of `zcat' on `.gz' files. Some do not
936;;; install GNU zip's version of zcat.
937
938(defvar dired-guess-shell-alist-default
939 (list
940 (list "\\.tar$" '(if dired-guess-shell-gnutar
941 (concat dired-guess-shell-gnutar " xvf")
942 "tar xvf"))
943
944 ;; REGEXPS for compressed archives must come before the .Z rule to
945 ;; be recognized:
946 (list "\\.tar\\.Z$"
947 ;; Untar it.
948 '(if dired-guess-shell-gnutar
949 (concat dired-guess-shell-gnutar " zxvf")
950 (concat "zcat * | tar xvf -"))
951 ;; Optional conversion to gzip format.
952 '(concat "znew" (if dired-guess-shell-gzip-quiet " -q")
953 " " dired-guess-shell-znew-switches))
954
955 ;; gzip'ed archives
2f017676 956 (list "\\.t\\(ar\\.\\)?gz$"
cb3fe1f0
RS
957 '(if dired-guess-shell-gnutar
958 (concat dired-guess-shell-gnutar " zxvf")
959 (concat "gunzip -qc * | tar xvf -"))
960 ;; Optional decompression.
961 '(concat "gunzip" (if dired-guess-shell-gzip-quiet " -q" "")))
7ba7b794
KH
962 ;; bzip2'ed archives
963 (list "\\.tar\\.bz2$"
964 "bunzip2 -c * | tar xvf -"
965 ;; Optional decompression.
966 "bunzip2")
cb3fe1f0
RS
967
968 '("\\.shar.Z$" "zcat * | unshar")
969 '("\\.shar.g?z$" "gunzip -qc * | unshar")
970
85400f54 971 '("\\.e?ps$" "ghostview" "xloadimage" "lpr")
35f58ede 972 (list "\\.e?ps.g?z$" "gunzip -qc * | ghostview -"
cb3fe1f0
RS
973 ;; Optional decompression.
974 '(concat "gunzip" (if dired-guess-shell-gzip-quiet " -q")))
35f58ede 975 (list "\\.e?ps.Z$" "zcat * | ghostview -"
cb3fe1f0
RS
976 ;; Optional conversion to gzip format.
977 '(concat "znew" (if dired-guess-shell-gzip-quiet " -q")
978 " " dired-guess-shell-znew-switches))
979 '("\\.patch$" "cat * | patch")
980 '("\\.patch.g?z$" "gunzip -qc * | patch")
981 (list "\\.patch.Z$" "zcat * | patch"
982 ;; Optional conversion to gzip format.
983 '(concat "znew" (if dired-guess-shell-gzip-quiet " -q")
984 " " dired-guess-shell-znew-switches))
985
986 '("\\.dvi$" "xdvi" "dvips") ; preview and printing
9572a9dd 987 '("\\.au$" "play") ; play Sun audiofiles
cb3fe1f0
RS
988 '("\\.mpg$" "mpeg_play")
989 '("\\.uu$" "uudecode") ; for uudecoded files
990 '("\\.hqx$" "mcvert")
991 '("\\.sh$" "sh") ; execute shell scripts
992 '("\\.xbm$" "bitmap") ; view X11 bitmaps
993 '("\\.gp$" "gnuplot")
85400f54
RS
994 '("\\.p[bgpn]m$" "xloadimage")
995 '("\\.gif$" "xloadimage") ; view gif pictures
996 '("\\.tif$" "xloadimage")
997 '("\\.png$" "xloadimage")
998 '("\\.jpg$" "xloadimage")
cb3fe1f0
RS
999 '("\\.fig$" "xfig") ; edit fig pictures
1000 '("\\.out$" "xgraph") ; for plotting purposes.
1001 '("\\.tex$" "latex" "tex")
1002 '("\\.texi\\(nfo\\)?$" "makeinfo" "texi2dvi")
ccdd9d57 1003 '("\\.pdf$" "xpdf") ; edit PDF files
cb3fe1f0
RS
1004
1005 ;; Some other popular archivers.
1006 '("\\.zoo$" "zoo x//")
1007 '("\\.zip$" "unzip")
1008 '("\\.lzh$" "lharc x")
1009 '("\\.arc$" "arc x")
1010 '("\\.shar$" "unshar")
1011
1012 ;; Compression.
1013 (list "\\.g?z$" '(concat "gunzip" (if dired-guess-shell-gzip-quiet " -q")))
7ba7b794 1014 (list "\\.bz2$" "bunzip2")
cb3fe1f0
RS
1015 (list "\\.Z$" "uncompress"
1016 ;; Optional conversion to gzip format.
1017 '(concat "znew" (if dired-guess-shell-gzip-quiet " -q")
1018 " " dired-guess-shell-znew-switches))
1019 )
9572a9dd 1020
cb3fe1f0
RS
1021 "Default alist used for shell command guessing.
1022See `dired-guess-shell-alist-user'")
1023
1024(defvar dired-guess-shell-alist-user nil
1025 "User-defined alist of rules for suggested commands. These rules take
1026precedence over the predefined rules in the variable
1027`dired-guess-shell-alist-default' (to which they are prepended).
1028
1029Each element of this list looks like
1030
1031 \(REGEXP COMMAND...\)
1032
1033where each COMMAND can either be a string or a lisp expression that evaluates
1034to a string. If several COMMANDs are given, the first one will be the default
1035and the rest will be added temporarily to the history and can be retrieved
1036with \\[previous-history-element] (M-p) .
1037
1038You can set this variable in your ~/.emacs. For example, to add rules for
1039`.foo' and `.bar' files, write
1040
1041 \(setq dired-guess-shell-alist-user
1042 (list (list \"\\\\.foo$\" \"FOO-COMMAND\");; fixed rule
1043 ;; possibly more rules ...
1044 (list \"\\\\.bar$\";; rule with condition test
1045 '(if condition
1046 \"BAR-COMMAND-1\"
1047 \"BAR-COMMAND-2\")))\)
1048")
1049
1050(defun dired-guess-default (files)
1051
9572a9dd
KH
1052 ;; Guess a shell commands for FILES. Return command or list of commands.
1053 ;; See `dired-guess-shell-alist-user'.
cb3fe1f0
RS
1054
1055 (let* ((case-fold-search nil) ; case-sensitive matching
1056 ;; Prepend the user's alist to the default alist.
1057 (alist (append dired-guess-shell-alist-user
1058 dired-guess-shell-alist-default))
1059 (file (car files))
1060 (flist (cdr files))
1061 elt regexp cmds)
1062
1063 ;; Find the first match in the alist for first file in FILES.
1064 (while alist
1065 (setq elt (car alist)
1066 regexp (car elt)
1067 alist (cdr alist))
1068 (if (string-match regexp file)
1069 (setq cmds (cdr elt)
1070 alist nil)))
1071
1072 ;; If more than one file, see if all of FILES match regular expression.
1073 (while (and flist
1074 (string-match regexp (car flist)))
1075 (setq flist (cdr flist)))
9572a9dd 1076
cb3fe1f0
RS
1077 ;; If flist is still non-nil, then do not guess since this means that not
1078 ;; all the files in FILES were matched by the regexp.
1079 (setq cmds (and (not flist) cmds))
1080
9572a9dd
KH
1081 ;; Return commands or nil if flist is still non-nil.
1082 ;; Evaluate the commands in order that any logical testing will be done.
cb3fe1f0
RS
1083 (cond ((not (cdr cmds))
1084 (eval (car cmds))) ; single command
1085 (t
1086 (mapcar (function eval) cmds)))))
1087
1088(defun dired-guess-shell-command (prompt files)
1089
1090 ;; Ask user with PROMPT for a shell command, guessing a default from FILES.
1091
1092 (let ((default (dired-guess-default files))
1093 default-list old-history val (failed t))
1094
1095 (if (null default)
1096 ;; Nothing to guess
1097 (read-from-minibuffer prompt nil nil nil 'dired-shell-command-history)
1098
1099 ;; Save current history list
1100 (setq old-history dired-shell-command-history)
1101
1102 (if (listp default)
1103
1104 ;; More than one guess
1105 (setq default-list default
1106 default (car default)
1107 prompt (concat
1108 prompt
1109 (format "{%d guesses} " (length default-list))))
1110
1111 ;; Just one guess
1112 (setq default-list (list default)))
1113
1114 ;; Push all guesses onto history so that they can be retrieved with M-p
1115 ;; and put the first guess in the prompt but not in the initial value.
1116 (setq dired-shell-command-history
1117 (append default-list dired-shell-command-history)
1118 prompt (concat prompt (format "[%s] " default)))
1119
1120 ;; The unwind-protect returns VAL, and we too.
1121 (unwind-protect
1122 ;; BODYFORM
1123 (progn
1124 (setq val (read-from-minibuffer prompt nil nil nil
1125 'dired-shell-command-history)
1126 failed nil)
1127 ;; If we got a return, then use default.
1128 (if (equal val "")
1129 (setq val default))
1130 val)
1131
1132 ;; UNWINDFORMS
1133 ;; Undo pushing onto the history list so that an aborted
1134 ;; command doesn't get the default in the next command.
1135 (setq dired-shell-command-history old-history)
1136 (if (not failed)
1137 (or (equal val (car-safe dired-shell-command-history))
1138 (setq dired-shell-command-history
1139 (cons val dired-shell-command-history))))))))
1140
1141
9572a9dd 1142;;; REDEFINE.
cb3fe1f0
RS
1143;;; Redefine dired-aux.el's version:
1144(defun dired-read-shell-command (prompt arg files)
1145;; "Read a dired shell command prompting with PROMPT (using read-string).
1146;;ARG is the prefix arg and may be used to indicate in the prompt which
1147;; files are affected.
1148;;This is an extra function so that you can redefine it, e.g., to use gmhist."
1149 (dired-mark-pop-up
1150 nil 'shell files
1151 'dired-guess-shell-command
1152 (format prompt (dired-mark-prompt arg files)) ; PROMPT
1153 files)) ; FILES
1154
1155\f
b578f267 1156;;; RELATIVE SYMBOLIC LINKS.
cb3fe1f0
RS
1157
1158(defvar dired-keep-marker-relsymlink ?S
1159 "See variable `dired-keep-marker-move'.")
1160
1161(defun dired-make-relative-symlink (file1 file2 &optional ok-if-already-exists)
1162 "Three arguments: FILE1 FILE2 &optional OK-IF-ALREADY-EXISTS
1163Make a symbolic link (pointing to FILE1) in FILE2.
1164The link is relative (if possible), for example
1165
1166 \"/vol/tex/bin/foo\" \"/vol/local/bin/foo\"
1167
1168results in
1169
1170 \"../../tex/bin/foo\" \"/vol/local/bin/foo\"
1171"
1172 (interactive "FRelSymLink: \nFRelSymLink %s: \np")
1173 (let (name1 name2 len1 len2 (index 0) sub)
1174 (setq file1 (expand-file-name file1)
1175 file2 (expand-file-name file2)
1176 len1 (length file1)
1177 len2 (length file2))
1178 ;; Find common initial pathname components:
1179 (let (next)
1180 (while (and (setq next (string-match "/" file1 index))
1181 (setq next (1+ next))
1182 (< next (min len1 len2))
1183 ;; For the comparison, both substrings must end in
1184 ;; `/', so NEXT is *one plus* the result of the
1185 ;; string-match.
1186 ;; E.g., consider the case of linking "/tmp/a/abc"
34ff2275 1187 ;; to "/tmp/abc" erroneously giving "/tmp/a" instead
cb3fe1f0
RS
1188 ;; of "/tmp/" as common initial component
1189 (string-equal (substring file1 0 next)
1190 (substring file2 0 next)))
1191 (setq index next))
1192 (setq name2 file2
1193 sub (substring file1 0 index)
1194 name1 (substring file1 index)))
1195 (if (string-equal sub "/")
1196 ;; No common initial pathname found
1197 (setq name1 file1)
1198 ;; Else they have a common parent directory
1199 (let ((tem (substring file2 index))
1200 (start 0)
1201 (count 0))
1202 ;; Count number of slashes we must compensate for ...
1203 (while (setq start (string-match "/" tem start))
1204 (setq count (1+ count)
1205 start (1+ start)))
1206 ;; ... and prepend a "../" for each slash found:
1207 (while (> count 0)
1208 (setq count (1- count)
1209 name1 (concat "../" name1)))))
1210 (make-symbolic-link
1211 (directory-file-name name1) ; must not link to foo/
1212 ; (trailing slash!)
1213 name2 ok-if-already-exists)))
1214
1215(defun dired-do-relsymlink (&optional arg)
1216 "Relative symlink all marked (or next ARG) files into a directory,
1217or make a relative symbolic link to the current file.
1218This creates relative symbolic links like
1219
1220 foo -> ../bar/foo
1221
1222not absolute ones like
1223
1224 foo -> /ugly/path/that/may/change/any/day/bar/foo"
1225 (interactive "P")
1226 (dired-do-create-files 'relsymlink (function dired-make-relative-symlink)
1227 "RelSymLink" arg dired-keep-marker-relsymlink))
1228
1229(defun dired-do-relsymlink-regexp (regexp newname &optional whole-path)
1230 "RelSymlink all marked files containing REGEXP to NEWNAME.
1231See functions `dired-do-rename-regexp' and `dired-do-relsymlink'
1232for more info."
1233 (interactive (dired-mark-read-regexp "RelSymLink"))
1234 (dired-do-create-files-regexp
1235 (function dired-make-relative-symlink)
1236 "RelSymLink" nil regexp newname whole-path dired-keep-marker-relsymlink))
1237
1238\f
b578f267 1239;;; VISIT ALL MARKED FILES SIMULTANEOUSLY.
cb3fe1f0 1240
9572a9dd
KH
1241;;; Brief Description:
1242;;;
1243;;; `dired-do-find-marked-files' is bound to `F' by dired-x.el.
1244;;;
cb3fe1f0 1245;;; * Use `dired-get-marked-files' to collect the marked files in the current
9572a9dd
KH
1246;;; Dired Buffer into a list of filenames `FILE-LIST'.
1247;;;
cb3fe1f0
RS
1248;;; * Pass FILE-LIST to `dired-simultaneous-find-file' all with
1249;;; `dired-do-find-marked-files''s prefix argument NOSELECT.
9572a9dd 1250;;;
cb3fe1f0
RS
1251;;; * `dired-simultaneous-find-file' runs through FILE-LIST decrementing the
1252;;; list each time.
9572a9dd 1253;;;
cb3fe1f0
RS
1254;;; * If NOSELECT is non-nil then just run `find-file-noselect' on each
1255;;; element of FILE-LIST.
9572a9dd 1256;;;
cb3fe1f0
RS
1257;;; * If NOSELECT is nil then calculate the `size' of the window for each file
1258;;; by dividing the `window-height' by length of FILE-LIST. Thus, `size' is
1259;;; cognizant of the window-configuration.
9572a9dd 1260;;;
cb3fe1f0
RS
1261;;; * If `size' is too small abort, otherwise run `find-file' on each element
1262;;; of FILE-LIST giving each a window of height `size'.
1263
1264(defun dired-do-find-marked-files (&optional noselect)
1265 "Find all marked files displaying all of them simultaneously.
1266With optional NOSELECT just find files but do not select them.
1267
1268The current window is split across all files marked, as evenly as possible.
1269Remaining lines go to bottom-most window. The number of files that can be
1270displayed this way is restricted by the height of the current window and
1271`window-min-height'.
1272
9572a9dd 1273To keep dired buffer displayed, type \\[split-window-vertically] first.
cb3fe1f0
RS
1274To display just marked files, type \\[delete-other-windows] first."
1275
1276 (interactive "P")
1277 (dired-simultaneous-find-file (dired-get-marked-files) noselect))
1278
1279(defun dired-simultaneous-find-file (file-list noselect)
1280
1281 ;; Visit all files in FILE-LIST and display them simultaneously. The
1282 ;; current window is split across all files in FILE-LIST, as evenly as
1283 ;; possible. Remaining lines go to the bottom-most window. The number of
1284 ;; files that can be displayed this way is restricted by the height of the
1285 ;; current window and the variable `window-min-height'. With non-nil
1286 ;; NOSELECT the files are merely found but not selected.
9572a9dd 1287
cb3fe1f0
RS
1288 ;; We don't make this function interactive because it is usually too clumsy
1289 ;; to specify FILE-LIST interactively unless via dired.
1290
1291 (let (size)
1292
1293 (if noselect
1294 ;; Do not select the buffer.
1295 (find-file-noselect (car file-list))
1296
1297 ;; We will have to select the buffer. Calculate and check window size.
1298 (setq size (/ (window-height) (length file-list)))
1299 (or (<= window-min-height size)
1300 (error "Too many files to visit simultaneously. Try C-u prefix."))
1301 (find-file (car file-list)))
1302
1303 ;; Decrement.
1304 (setq file-list (cdr file-list))
1305
1306 (while file-list
1307
1308 (if noselect
1309 ;; Do not select the buffer.
1310 (find-file-noselect (car file-list))
1311
1312 ;; Vertically split off a window of desired size. Upper window will
1313 ;; have SIZE lines. Select lower (larger) window. We split it again.
1314 (select-window (split-window nil size))
1315 (find-file (car file-list)))
1316
1317 ;; Decrement.
1318 (setq file-list (cdr file-list)))))
1319
1320\f
b578f267 1321;;; MISCELLANEOUS COMMANDS.
cb3fe1f0 1322
9572a9dd
KH
1323;;; Run man on files.
1324
cb3fe1f0 1325(defun dired-man ()
9572a9dd 1326 "Run man on this file. Display old buffer if buffer name matches filename.
685ff9f8 1327Uses ../lisp/man.el of \\[manual-entry] fame."
cb3fe1f0 1328 (interactive)
685ff9f8
RS
1329 (require 'man)
1330 (let ((file (dired-get-filename))
9b5ef74b 1331 (manual-program "nroff -man -h"))
685ff9f8 1332 (Man-getpage-in-background file)))
cb3fe1f0
RS
1333
1334;;; Run Info on files.
1335
1336(defun dired-info ()
1337 "Run info on this file."
1338 (interactive)
1339 (info (dired-get-filename)))
1340
1341;;; Run mail on mail folders.
1342
9572a9dd
KH
1343;;; (and (not (fboundp 'vm-visit-folder))
1344;;; (defun vm-visit-folder (file &optional arg)
1345;;; nil))
1346
cb3fe1f0
RS
1347(defun dired-vm (&optional read-only)
1348 "Run VM on this file.
1349With prefix arg, visit folder read-only (this requires at least VM 5).
1350See also variable `dired-vm-read-only-folders'."
1351 (interactive "P")
1352 (let ((dir (dired-current-directory))
1353 (fil (dired-get-filename)))
1354 ;; take care to supply 2nd arg only if requested - may still run VM 4!
1355 (cond (read-only (vm-visit-folder fil t))
1356 ((eq t dired-vm-read-only-folders) (vm-visit-folder fil t))
1357 ((null dired-vm-read-only-folders) (vm-visit-folder fil))
1358 (t (vm-visit-folder fil (not (file-writable-p fil)))))
1359 ;; so that pressing `v' inside VM does prompt within current directory:
1360 (set (make-local-variable 'vm-folder-directory) dir)))
1361
1362(defun dired-rmail ()
1363 "Run RMAIL on this file."
1364 (interactive)
1365 (rmail (dired-get-filename)))
1366
1367(defun dired-do-run-mail ()
1368 "If `dired-bind-vm' is t, then function `dired-vm', otherwise `dired-rmail'."
1369 (interactive)
1370 (if dired-bind-vm
1371 ;; Read mail folder using vm.
1372 (dired-vm)
1373 ;; Read mail folder using rmail.
1374 (dired-rmail)))
1375
1376\f
b578f267 1377;;; MISCELLANEOUS INTERNAL FUNCTIONS.
cb3fe1f0
RS
1378
1379(or (fboundp 'dired-old-find-buffer-nocreate)
1380 (fset 'dired-old-find-buffer-nocreate
1381 (symbol-function 'dired-find-buffer-nocreate)))
1382
9572a9dd 1383;;; REDEFINE.
cb3fe1f0 1384;;; Redefines dired.el's version of `dired-find-buffer-nocreate'
ac1ce341 1385(defun dired-find-buffer-nocreate (dirname &optional mode)
10774fb5
KH
1386 (if (and dired-find-subdir
1387 ;; don't try to find a wildcard as a subdirectory
1388 (string-equal dirname (file-name-directory dirname)))
cb3fe1f0 1389 (let* ((cur-buf (current-buffer))
10774fb5 1390 (buffers (nreverse
12c38283 1391 (dired-buffers-for-dir (expand-file-name dirname))))
10774fb5
KH
1392 (cur-buf-matches (and (memq cur-buf buffers)
1393 ;; wildcards must match, too:
1394 (equal dired-directory dirname))))
1395 ;; We don't want to switch to the same buffer---
1396 (setq buffers (delq cur-buf buffers));;need setq with delq
1397 (or (car (sort buffers (function dired-buffer-more-recently-used-p)))
1398 ;; ---unless it's the only possibility:
1399 (and cur-buf-matches cur-buf)))
ac1ce341 1400 (dired-old-find-buffer-nocreate dirname mode)))
cb3fe1f0
RS
1401
1402;; This should be a builtin
1403(defun dired-buffer-more-recently-used-p (buffer1 buffer2)
1404 "Return t if BUFFER1 is more recently used than BUFFER2."
1405 (if (equal buffer1 buffer2)
1406 nil
1407 (let ((more-recent nil)
1408 (list (buffer-list)))
1409 (while (and list
1410 (not (setq more-recent (equal buffer1 (car list))))
1411 (not (equal buffer2 (car list))))
1412 (setq list (cdr list)))
1413 more-recent)))
1414
1415;;; Same thing as `dired-buffers-for-dir' of dired.el? - lrd 11/23/93
1416;;; (defun dired-buffers-for-dir-exact (dir)
1417;;; ;; Return a list of buffers that dired DIR (a directory or wildcard)
1418;;; ;; at top level, or as subdirectory.
1419;;; ;; Top level matches must match the wildcard part too, if any.
1420;;; ;; The list is in reverse order of buffer creation, most recent last.
1421;;; ;; As a side effect, killed dired buffers for DIR are removed from
1422;;; ;; dired-buffers.
1423;;; (let ((alist dired-buffers) result elt)
1424;;; (while alist
1425;;; (setq elt (car alist)
1426;;; alist (cdr alist))
1427;;; (let ((buf (cdr elt)))
1428;;; (if (buffer-name buf)
1429;;; ;; Top level must match exactly against dired-directory in
1430;;; ;; case one of them is a wildcard.
1431;;; (if (or (equal dir (save-excursion (set-buffer buf)
1432;;; dired-directory))
1433;;; (assoc dir (save-excursion (set-buffer buf)
1434;;; dired-subdir-alist)))
1435;;; (setq result (cons buf result)))
1436;;; ;; else buffer is killed - clean up:
1437;;; (setq dired-buffers (delq elt dired-buffers)))))
1438;;; result))
1439
9572a9dd 1440;;; REDEFINE.
cb3fe1f0
RS
1441;;; Redefines dired.el's version of `dired-initial-position'
1442(defun dired-initial-position (dirname)
1443 (end-of-line)
1444 (if dired-find-subdir (dired-goto-subdir dirname)) ; new
1445 (if dired-trivial-filenames (dired-goto-next-nontrivial-file)))
1446
1447\f
1448;; Does anyone use this? - lrd 6/29/93.
44c816da 1449;; Apparently people do use it. - lrd 12/22/97.
cb3fe1f0
RS
1450(defun dired-mark-sexp (predicate &optional unflag-p)
1451 "Mark files for which PREDICATE returns non-nil.
1452With a prefix arg, unflag those files instead.
1453
1454PREDICATE is a lisp expression that can refer to the following symbols:
1455
1456 inode [integer] the inode of the file (only for ls -i output)
1457 s [integer] the size of the file for ls -s output
34ff2275 1458 (usually in blocks or, with -k, in KByte)
cb3fe1f0
RS
1459 mode [string] file permission bits, e.g. \"-rw-r--r--\"
1460 nlink [integer] number of links to file
1461 uid [string] owner
1462 gid [string] group (If the gid is not displayed by ls,
1463 this will still be set (to the same as uid))
1464 size [integer] file size in bytes
1465 time [string] the time that ls displays, e.g. \"Feb 12 14:17\"
1466 name [string] the name of the file
1467 sym [string] if file is a symbolic link, the linked-to name, else \"\"
1468
1469For example, use
1470
1471 (equal 0 size)
1472
1473to mark all zero length files."
1474 ;; Using sym="" instead of nil avoids the trap of
1475 ;; (string-match "foo" sym) into which a user would soon fall.
1476 ;; Give `equal' instead of `=' in the example, as this works on
1477 ;; integers and strings.
1478 (interactive "xMark if (lisp expr): \nP")
1479 (message "%s" predicate)
1480 (let ((dired-marker-char (if unflag-p ?\040 dired-marker-char))
1481 inode s mode nlink uid gid size time name sym)
1482 (dired-mark-if
1483 (save-excursion
1484 (and
1485 ;; Sets vars
1486 ;; inode s mode nlink uid gid size time name sym
1487
1488 ;; according to current file line. Returns t for success, nil if
1489 ;; there is no file line. Upon success, all variables are set, either
1490 ;; to nil or the appropriate value, so they need not be initialized.
1491 ;; Moves point within the current line.
1492 (if (dired-move-to-filename)
1493 (let (pos
1494 (mode-len 10) ; length of mode string
1495 ;; like in dired.el, but with subexpressions \1=inode, \2=s:
1496 (dired-re-inode-size "\\s *\\([0-9]*\\)\\s *\\([0-9]*\\) ?"))
1497 (beginning-of-line)
1498 (forward-char 2)
1499 (if (looking-at dired-re-inode-size)
1500 (progn
1501 (goto-char (match-end 0))
1502 (setq inode (string-to-int (buffer-substring (match-beginning 1)
1503 (match-end 1)))
1504 s (string-to-int (buffer-substring (match-beginning 2)
1505 (match-end 2)))))
1506 (setq inode nil
1507 s nil))
1508 (setq mode (buffer-substring (point) (+ mode-len (point))))
1509 (forward-char mode-len)
1510 (setq nlink (read (current-buffer)))
44c816da
RS
1511 ;; Karsten Wenger <kw@cis.uni-muenchen.de> fixed uid.
1512 (setq uid (buffer-substring (+ (point) 1) (progn (forward-word 1) (point))))
cb3fe1f0
RS
1513 (re-search-forward "\\(Jan\\|Feb\\|Mar\\|Apr\\|May\\|Jun\\|Jul\\|Aug\\|Sep\\|Oct\\|Nov\\|Dec\\)")
1514 (goto-char (match-beginning 1))
1515 (forward-char -1)
1516 (setq size (string-to-int (buffer-substring (save-excursion
1517 (backward-word 1)
1518 (setq pos (point)))
1519 (point))))
1520 (goto-char pos)
1521 (backward-word 1)
1522 ;; if no gid is displayed, gid will be set to uid
1523 ;; but user will then not reference it anyway in PREDICATE.
1524 (setq gid (buffer-substring (save-excursion (forward-word 1) (point))
1525 (point))
1526 time (buffer-substring (match-beginning 1)
1527 (1- (dired-move-to-filename)))
1528 name (buffer-substring (point)
1529 (or (dired-move-to-end-of-filename t)
1530 (point)))
1531 sym (progn
1532 (if (looking-at " -> ")
1533 (buffer-substring (progn (forward-char 4) (point))
1534 (progn (end-of-line) (point)))
1535 "")))
1536 t)
1537 nil)
1538 (eval predicate)))
1539 (format "'%s file" predicate))))
1540
1541\f
b578f267 1542;;; FIND FILE AT POINT.
cb3fe1f0 1543
ccb1d39a
RS
1544(defvar dired-x-hands-off-my-keys t
1545 "*t means don't bind `dired-x-find-file' over `find-file' on keyboard.
1546Similarly for `dired-x-find-file-other-window' over `find-file-other-window'.
1547If you change this variable after dired-x.el is loaded then do
1548\\[dired-x-bind-find-file].")
1549
1550;;; Bind `dired-x-find-file{-other-window}' over wherever
1551;;; `find-file{-other-window}' is bound?
1552(defun dired-x-bind-find-file ()
1553 "Bind `dired-x-find-file' in place of `find-file' \(or reverse\).
1554Similarly for `dired-x-find-file-other-window' and `find-file-other-window'.
1555Binding direction based on `dired-x-hands-off-my-keys'.
1556This function part of `after-init-hook'."
1557 (interactive)
1558 (if (interactive-p)
1559 (setq dired-x-hands-off-my-keys
1560 (not (y-or-n-p "Bind dired-x-find-file over find-file? "))))
1561 (cond ((not dired-x-hands-off-my-keys)
1562 (substitute-key-definition 'find-file
1563 'dired-x-find-file
1564 (current-global-map))
1565 (substitute-key-definition 'find-file-other-window
1566 'dired-x-find-file-other-window
1567 (current-global-map)))
1568 (t
1569 (substitute-key-definition 'dired-x-find-file
1570 'find-file
1571 (current-global-map))
1572 (substitute-key-definition 'dired-x-find-file-other-window
1573 'find-file-other-window
1574 (current-global-map))))
1575 ;; Clear mini-buffer.
1576 (message nil))
1577
1578;;; Now call it so binding is correct and put on `after-init-hook' in case
1579;;; user changes binding.
1580(dired-x-bind-find-file)
1581(add-hook 'after-init-hook 'dired-x-bind-find-file)
1582
1583(defun dired-x-find-file (filename)
1584 "Edit file FILENAME.
1585May create a new window, or reuse an existing one.
1586See the function `display-buffer'.
1587
1588Identical to `find-file' except when called interactively, with a prefix arg
1589\(e.g., \\[universal-argument]\), in which case it guesses filename near
1590point. Useful for editing file mentioned in buffer you are viewing, or to
1591test if that file exists. Use minibuffer after snatching filename."
1592 (interactive (list (read-filename-at-point "Find file: ")))
1593 (find-file (expand-file-name filename)))
1594
1595(defun dired-x-find-file-other-window (filename)
1596 "Edit file FILENAME, in another window.
1597May create a new window, or reuse an existing one.
1598See the function `display-buffer'.
1599
1600Identical to `find-file-other-window' except when called interactively, with a
1601prefix arg \(e.g., \\[universal-argument]\), in which case it guesses filename
1602near point. Useful for editing file mentioned in buffer you are viewing, or
1603to test if that file exists. Use minibuffer after snatching filename."
1604 (interactive (list (read-filename-at-point "Find file: ")))
1605 (find-file-other-window (expand-file-name filename)))
1606
1607;;; Internal functions.
cb3fe1f0
RS
1608(defun dired-filename-at-point ()
1609
1610 ;; Get the filename closest to point, but do not change position. Has a
1611 ;; preference for looking backward when not directly on a symbol. Not
1612 ;; perfect - point must be in middle of or end of filename.
1613
6b622862 1614 (let ((filename-chars ".a-zA-Z0-9---_/:$+@")
cb3fe1f0
RS
1615 (bol (save-excursion (beginning-of-line) (point)))
1616 (eol (save-excursion (end-of-line) (point)))
6b622862 1617 start end filename prefix)
cb3fe1f0
RS
1618
1619 (save-excursion
1620 ;; First see if just past a filename.
1621 (if (not (eobp))
1622 (if (looking-at "[] \t\n[{}()]") ; whitespace or some parens
1623 (progn
1624 (skip-chars-backward " \n\t\r({[]})")
1625 (if (not (bobp))
1626 (backward-char 1)))))
9572a9dd 1627
cb3fe1f0
RS
1628 (if (string-match (concat "[" filename-chars "]")
1629 (char-to-string (following-char)))
1630 (progn
1631 (skip-chars-backward filename-chars)
1632 (setq start (point))
6b622862
GM
1633 (setq prefix
1634 (and (string-match "^\\w+@"
1635 (buffer-substring start eol))
1636 "/"))
1637 (goto-char start)
cb3fe1f0
RS
1638 (if (string-match "[/~]" (char-to-string (preceding-char)))
1639 (setq start (1- start)))
1640 (skip-chars-forward filename-chars))
1641
1642 (error "No file found around point!"))
1643
9572a9dd 1644 ;; Return string.
6b622862 1645 (expand-file-name (concat prefix (buffer-substring start (point)))))))
cb3fe1f0 1646
ccb1d39a
RS
1647(defun read-filename-at-point (prompt)
1648 ;;; Returns filename prompting with PROMPT with completion. If
1649 ;;; `current-prefix-arg' is non-nil, uses name at point as guess.
1650 (if current-prefix-arg
1651 (let ((guess (dired-filename-at-point)))
1652 (read-file-name prompt
1653 (file-name-directory guess)
1654 guess
1655 nil (file-name-nondirectory guess)))
1656 (read-file-name prompt default-directory)))
1657
cb3fe1f0 1658\f
b578f267 1659;;; BUG REPORTS
cb3fe1f0
RS
1660
1661;;; This section is provided for reports. It uses Barry A. Warsaw's
1662;;; reporter.el which is bundled with GNU Emacs v19.
1663
ccb1d39a 1664(defconst dired-x-version "2.37"
cb3fe1f0 1665 "Revision number of dired-x.el -- dired extra for GNU Emacs v19.
9572a9dd 1666Type \\[dired-x-submit-report] to send a bug report. Available via anonymous
cb3fe1f0
RS
1667ftp in
1668
1669 /roebling.poly.edu:/pub/packages/dired-x.tar.gz")
1670
1671(defconst dired-x-help-address "dodd@roebling.poly.edu"
1672 "Address(es) accepting submission of reports on dired-x.el.")
1673
1674(defconst dired-x-maintainer "Larry"
1675 "First name(s) of people accepting submission of reports on dired-x.el.")
1676
1677(defconst dired-x-file "dired-x.el"
1678 "Name of file containing emacs lisp code.")
1679
1680(defconst dired-x-variable-list
9572a9dd 1681 (list
cb3fe1f0
RS
1682 'dired-bind-vm
1683 'dired-vm-read-only-folders
1684 'dired-bind-jump
1685 'dired-bind-info
1686 'dired-bind-man
1687 'dired-find-subdir
1688 'dired-enable-local-variables
1689 'dired-local-variables-file
1690 'dired-guess-shell-gnutar
1691 'dired-guess-shell-gzip-quiet
1692 'dired-guess-shell-znew-switches
1693 'dired-guess-shell-alist-user
1694 'dired-clean-up-buffers-too
1695 'dired-omit-files-p
1696 'dired-omit-files
1697 'dired-omit-extensions
1698 )
1699 "List of variables to be appended to reports sent by `dired-x-submit-report.'")
1700
1701(defun dired-x-submit-report ()
1702 "Submit via reporter.el a bug report on program. Send report on `dired-x-file'
1703version `dired-x-version,' to `dired-x-maintainer' at address `dired-x-help-address'
1704listing variables `dired-x-variable-list' in the message."
1705 (interactive)
1706
1707 ;; In case we can't find reporter...
1708 (condition-case err
1709 (progn
1710 ;; Get it if we can.
1711 (require 'reporter)
1712
1713 (reporter-submit-bug-report
1714 dired-x-help-address ; address
1715 (concat dired-x-file " (" dired-x-version ")") ; pkgname
1716 dired-x-variable-list ; varlist
1717 nil nil ; pre-/post-hooks
1718 (concat dired-x-maintainer ","))) ; salutation
1719
1720 ;; ...fail gracefully.
9572a9dd 1721 (error
cb3fe1f0
RS
1722 (beep)
1723 (message "Sorry, reporter.el not found."))))
1724
1725\f
1726;; As Barry Warsaw would say: "This might be useful..."
1727(provide 'dired-x)
1728
1729;;; dired-x.el ends here