annotate lisp/dired/dired-guess.el @ 9:6f2bbbbbe05a

Added tag r19-15b5 for changeset 4b173ad71786
author cvs
date Mon, 13 Aug 2007 08:47:36 +0200
parents 376386a54a3c
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1 ;;; -*- Mode: Emacs-lisp -*- ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2 ;;; dired-guess.el - In Dired, guess what shell command to apply.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4 ;;; Copyright (C) 1991, 1992 Gregory N. Shapiro
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6 ;;; Author: Gregory N. Shapiro gshapiro@wpi.wpi.edu
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
7 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
8 ;;; This program is free software; you can redistribute it and/or modify
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
9 ;;; it under the terms of the GNU General Public License as published by
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
10 ;;; the Free Software Foundation; either version 2, or (at your option)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
11 ;;; any later version.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
12 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
13 ;;; This program is distributed in the hope that it will be useful,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
14 ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
15 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
16 ;;; GNU General Public License for more details.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
17 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
18 ;;; A copy of the GNU General Public License can be obtained from this
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
19 ;;; program's author (send electronic mail to the above address) or from
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
20 ;;; Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
21
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
22
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
23 ;;; This extension to Sebastian Kremer's (sk@thp.Uni-Koeln.DE) Tree-Dired
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
24 ;;; permits dired to guess a shell command to use when the user performs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
25 ;;; a shell command on a single file.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27 ;;; New variables (user options):
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28 ;;; dired-auto-shell-command-alist
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29 ;;; dired-auto-shell-use-last-extension
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30 ;;; dired-guess-have-gnutar
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32 ;;; Replaces procedures:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33 ;;; dired-read-shell-command (new doc, calls dired-guess-shell-command)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35 ;;; Adds procedures:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36 ;;; dired-guess-shell-command (guesses command by comparing file extensions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37 ;;; to dired-auto-shell-command-alist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39 ;; LISPDIR ENTRY for the Elisp Archive ===============================
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40 ;; LCD Archive Entry:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41 ;; dired-guess|Gregory N. Shapiro|gshapiro@wpi.wpi.edu
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42 ;; |Guess a Dired shell command from the filename.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44 ;; INSTALLATION
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46 ;; Put this file into your load-path and add (load "dired-guess") to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47 ;; your dired-load-hook, e.g.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49 ;; (setq dired-load-hook '(lambda ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50 ;; ;; possibly more statements here
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51 ;; (load "dired-guess")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53 ;; Note: dired-guess must be loaded after dired-extra.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55 ;; If dired-auto-shell-use-last-extension is nil, all file extensions will
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56 ;; be used to determine the command to use. If nil, use all the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57 ;; extensions. For example, foo.tar.Z would guess for the .tar.Z extension.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58 ;; If non-nil, uses only the last extension of the filename. For example,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59 ;; foo.tar.Z would use the guess for the .Z extension.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61 ;; Set dired-guess-have-gnutar to the name of the GNU tar file (defaults to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62 ;; "gnutar"). Set to nil if you don't have GNU tar installed on your system.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63 ;; GNU tar is available for anonymous ftp at prep.ai.mit.edu.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65 (defvar dired-guess-have-gnutar "gnutar"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66 "*If non-nil, name of GNU tar (e.g. \"tar\" or \"gnutar\").
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67 GNU tar's `z' switch is used for compressed tar files.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68 If you don't have GNU tar, set this to nil: a pipe is then used.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70 (defvar dired-guess-tar (or dired-guess-have-gnutar "tar"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72 (defvar dired-auto-shell-command-alist
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73 (list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74 '(".Z" . "uncompress")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75 '(".Z.uu" . "uudecode * | uncompress")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76 '(".uu" . "uudecode")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77 '(".hqx" . "mcvert")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78 '(".sh" . "sh")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79 '(".shar" . "unshar")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80 (cons ".tar" (concat dired-guess-tar " xvf"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81 (cons ".tar.Z" (if dired-guess-have-gnutar
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82 (concat dired-guess-tar " xvfz")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83 (concat "zcat * | " dired-guess-tar " xvf -")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84 (cons ".tar.Z.uu" (if dired-guess-have-gnutar
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85 (concat "uudecode * | " dired-guess-tar " xvfz -")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86 "uudecode * | zcat | tar xvf -")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88 "*Alist of file extensions and their suggested commands.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89 See also variable `dired-auto-shell-use-last-extension'.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91 (defvar dired-auto-shell-use-last-extension nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92 "*If non-nil, uses only the last extension of the filename.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93 For example, foo.tar.Z would use the guess for the .Z extension.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94 If nil, use all the extensions. For example, foo.tar.Z would guess
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95 for the .tar.Z extension.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97 (defun dired-read-shell-command (prompt arg files)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98 "Read a dired shell command using generic minibuffer history.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99 This command tries to guess a command from the filename(s)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100 from the variable `dired-auto-shell-command-alist' (which see)."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101 (dired-mark-pop-up
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102 nil 'shell files ; bufname type files
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103 'dired-guess-shell-command ; function &rest args
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104 (format prompt (dired-mark-prompt arg files)) files))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107 (defun dired-guess-shell-command (prompt files)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108 ;;"Ask user with PROMPT for a shell command, guessing a default from FILES."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109 (let ((defalt (if (cdr files)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110 nil ; If more than one file, don't guess
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111 (cdr (assoc
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112 (substring (car files) ; Separate extension & lookup
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113 (if dired-auto-shell-use-last-extension
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114 (string-match "\.[^.]*$" (car files))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115 (string-match "\\." (car files))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116 dired-auto-shell-command-alist)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117 (if (not (featurep 'gmhist))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118 (read-string prompt defalt)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119 (if defalt
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120 (put 'dired-shell-command-history 'default defalt)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121 (read-with-history-in 'dired-shell-command-history prompt)))