annotate lisp/efs/dired-shell.el @ 98:0d2f883870bc r20-1b1

Import from CVS: tag r20-1b1
author cvs
date Mon, 13 Aug 2007 09:13:56 +0200
parents 8fc7fe29b841
children 7e54bd776075 8619ce7e4c50
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
22
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2 ;;
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3 ;; File: dired-shell.el
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4 ;; Dired Version: $Revision: 1.1 $
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5 ;; RCS:
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6 ;; Description: Commands for running shell commands on marked files.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
7 ;;
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
8 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
9
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
10 ;;; Requirements and provisions
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
11 (provide 'dired-shell)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
12 (require 'dired)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
13 (autoload 'comint-mode "comint")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
14
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
15 ;;; Variables
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
16
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
17 (defvar dired-postscript-print-command
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
18 (concat
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
19 (if (boundp 'lpr-command)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
20 lpr-command
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
21 (if (memq system-type
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
22 '(usg-unix-v hpux silicon-graphics-unix))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
23 "lp"
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
24 "lpr"))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
25 (if (and (boundp 'lpr-switches) lpr-switches)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
26 (concat " "
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
27 (mapconcat 'identity lpr-switches " ")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
28 " ")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
29 " "))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
30 "Command to print a postscript file.")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
31
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
32 (defvar dired-text-print-command (concat dired-postscript-print-command " -p")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
33 "Command to print a text file.")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
34
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
35 (defvar dired-print-program-alist
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
36 (list
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
37 (cons "\\.gif$" (concat "giftoppm * | ppmtopgm | pnmtops | "
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
38 dired-postscript-print-command))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
39 (cons "\\.\\(fts\\|FTS\\)$" (concat "fitstopgm * | pnmtops | "
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
40 dired-postscript-print-command))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
41 ;; People with colour printers won't want the g-flag in djpeg
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
42 (cons "\\.\\(JPG\\|jpg\\)$" (concat "djpeg -Pg * | pnmtops | "
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
43 dired-postscript-print-command))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
44 (cons "\\.ps\\.\\(gz\\|Z\\)$" (concat "zcat * | "
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
45 dired-postscript-print-command))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
46 (cons "\\.ps$" dired-postscript-print-command)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
47 (cons "\\.\\(gz\\|Z\\)$" (concat "zcat * | "
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
48 dired-postscript-print-command))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
49 (cons "\\.dvi$" "dvips")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
50 (cons ".*" dired-text-print-command))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
51 "Alist of regexps and print commands.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
52 This is used by `dired-do-print' to determine the default print command for
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
53 printing the marked files.")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
54
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
55 (defvar dired-auto-shell-command-alist nil
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
56 "*Alist of regexps and command lists to guess shell commands.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
57 Each element of this list should be a list of regular expression, and a list
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
58 of guesses for shell commands to be used if the file name matches the regular
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
59 expression. The list of guesses is evalled. This alist is appended to the front
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
60 of dired-default-auto-shell-command-alist before prompting for each shell
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
61 command.")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
62
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
63 (defvar dired-default-auto-shell-command-alist
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
64 (list
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
65
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
66 ;; Archiving
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
67 '("\\.tar$"
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
68 (if dired-gnutar-program
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
69 (concat dired-gnutar-program " xvf")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
70 "tar xvf")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
71 (if dired-gnutar-program
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
72 (concat dired-gnutar-program " tvf")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
73 "tar tvf"))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
74 ;; regexps for compressed archives must come before the .Z rule to
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
75 ;; be recognized:
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
76 '("\\.tar\\.\\([zZ]\\|gz\\)\\|\\.tgz$" ; .tgz is for DOS
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
77 (if dired-gnutar-program
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
78 (concat dired-gnutar-program " zxvf")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
79 "zcat * | tar xvf -")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
80 (if dired-gnutar-program
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
81 (concat dired-gnutar-program " ztvf")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
82 "zcat * | tar tvf -"))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
83 '("\\.shar.[zZ]$" (if dired-unshar-program
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
84 (concat "zcat * | " dired-unshar-program)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
85 "zcat * | sh"))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
86 '("\\.zoo$" "zoo x//")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
87 '("\\.zip$" "unzip" "unzip -v")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
88 '("\\.lzh$" "lharc x")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
89 '("\\.arc$" "arc x")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
90 '("\\.shar$" (if dired-unshar-program dired-unshar-program "sh"))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
91
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
92 ;; Encoding/compressing
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
93 '("\\.uu$" "uudecode")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
94 '("\\.hqx$" "mcvert")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
95
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
96 ;; Executing (in the generalized sense)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
97 '("\\.sh$" "sh") ; execute shell scripts
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
98 '("^[Mm]akefile$" "make -f *")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
99 '("\\.diff$" "patch -t <")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
100
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
101 ;; Displaying (assumes X)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
102 '("\\.xbm$" "bitmap") ; view X11 bitmaps
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
103 '("\\.gp$" "gnuplot")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
104 '("\\.gif$" "xv") ; view gif pictures
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
105 '("\\.fig$" "xfig") ; edit fig pictures
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
106 '("\\.ps$" "ghostview")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
107
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
108 ;; Typesetting. For printing documents, see dired-print-program-alist.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
109 '("\\.tex$" "latex" "tex")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
110 '("\\.texi\\(nfo\\)?$" "makeinfo" "texi2dvi")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
111 (if (eq window-system 'x)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
112 (if dired-use-file-transformers
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
113 '("\\.dvi$" "xdvi" "dvips -o *b.ps *")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
114 '("\\.dvi$" "xdvi" "dvips"))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
115 (if dired-use-file-transformers
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
116 '("\\.dvi$" "dvips -o *b.ps *")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
117 '("\\.dvi$" "dvips")))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
118
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
119 ;; The last word. Things that cannot be grokked with a regexp.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
120 '("." (if (> (length files) 1)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
121 "tar cvf "
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
122 (and (= (length files) 1) (file-directory-p
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
123 (expand-file-name
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
124 (car files)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
125 (dired-current-directory)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
126 (concat "tar cvf " (file-name-nondirectory
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
127 (directory-file-name (car files)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
128 ".tar"))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
129 )
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
130 "Default for variable `dired-auto-shell-command-alist' (which see).
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
131 Set this to nil to turn off shell command guessing.")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
132
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
133 ;; Might use {,} for bash or csh:
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
134 (defvar dired-shell-prefix ""
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
135 "Prepended to marked files in dired shell commands.")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
136 (defvar dired-shell-postfix ""
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
137 "Appended to marked files in dired shell commands.")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
138 (defvar dired-shell-separator " "
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
139 "Separates marked files in dired shell commands.")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
140
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
141 (defvar dired-file-wildcard ?*
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
142 "Wildcard character used by dired shell commands.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
143 Indicates where file names should be inserted.")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
144
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
145 (defvar dired-shell-command-separators '(?\ ?| ?> ?< ?& ?;)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
146 "Defines the start of a string specifying a word in a shell command.")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
147
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
148 (defvar dired-trans-map
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
149 (list
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
150 (cons ?f 'identity)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
151 (cons ?n 'file-name-nondirectory)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
152 (cons ?d 'file-name-directory)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
153 (cons ?b 'dired-file-name-base)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
154 (cons ?e 'dired-file-name-extension)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
155 (cons ?v 'dired-file-name-sans-rcs-extension)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
156 (cons ?z 'dired-file-name-sans-compress-extension))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
157 "Alist that associates keys with file transformer functions
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
158 Each transformer function should be a funcion of one argument, the file name.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
159 The keys are characters.")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
160
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
161 (defvar dired-shell-failure-marker ?!
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
162 "*A marker to mark files on which shell commands fail.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
163 If nil, such files are not marked.")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
164
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
165 ;;; Internal variables
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
166
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
167 ;; Make sure this gets defined.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
168 (defvar shell-command-history nil
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
169 "History list of previous shell commands.")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
170
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
171 (defvar dired-print-history nil
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
172 "History of commands used to print files.")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
173
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
174 (defvar dired-shell-input-start) ; only defined in shell output buffers
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
175
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
176 ;;; Utility functions and Macros
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
177
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
178 (defun dired-shell-quote (filename)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
179 ;; Quote a file name for inferior shell (see variable shell-file-name).
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
180 ;; Quote everything except POSIX filename characters.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
181 ;; This should be safe enough even for really wierd shells.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
182 (let ((result "") (start 0) end)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
183 (while (string-match "[^---0-9a-zA-Z_./]" filename start)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
184 (setq end (match-beginning 0)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
185 result (concat result (substring filename start end)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
186 "\\" (substring filename end (1+ end)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
187 start (1+ end)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
188 (concat result (substring filename start))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
189
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
190 (defun dired-uniquefy-list (list)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
191 ;; Returns list, after removing 2nd and higher occurrences
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
192 ;; of all elements. Tests elements with equal. Retains the relative
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
193 ;; order of the elements.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
194 ;; For small lists, this way is probably faster than sorting.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
195 (let (result)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
196 (while list
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
197 (or (member (car list) result)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
198 (setq result (nconc result (list (car list)))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
199 (setq list (cdr list)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
200 result))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
201
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
202 (defun dired-read-shell-command (prompt arg files)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
203 ;; Read a dired shell command prompting with PROMPT (using read-string).
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
204 ;; ARG is the prefix arg and may be used to indicate in the prompt which
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
205 ;; files are affected.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
206 (dired-mark-pop-up
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
207 nil 'shell files
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
208 (function
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
209 (lambda (prompt files)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
210 (let* ((default (car shell-command-history))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
211 (guesses (dired-guess-default files))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
212 (len (length guesses))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
213 cmd)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
214 (or (zerop len)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
215 (setq prompt (format "%s{%d guess%s} "
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
216 prompt len (if (= len 1) "" "es"))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
217 (if default (setq prompt (concat prompt "[" default "] ")))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
218 (put 'guesses 'no-default t) ; for gmhist, in case.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
219 (setq guesses (nconc guesses (copy-sequence shell-command-history))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
220 cmd (dired-read-with-history prompt nil 'guesses))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
221 (if (string-match "^[ \t\n]*$" cmd)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
222 (if default
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
223 (setq cmd default)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
224 (error "No shell command given.")))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
225 (setq shell-command-history
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
226 (dired-uniquefy-list
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
227 (cons cmd shell-command-history)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
228 cmd)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
229 (format prompt (dired-mark-prompt arg files)) files))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
230
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
231 (defmacro dired-trans-subst (transformers filename dir)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
232 ;; Applies each transformer supplied in the string TRANSFORMERS in sequence
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
233 ;; to FILE and returns the concatenation of the results. Also unquotes \\'s.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
234 ;; Returns a string if no file transformations were done, otherwise a list
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
235 ;; consisting of a single string.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
236 (` (let* ((transformers (, transformers))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
237 (filename (, filename))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
238 (len (length transformers))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
239 (pos 0)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
240 (last 0)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
241 (transformed nil)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
242 (quoted nil)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
243 char result trans)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
244 (while (< pos len)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
245 (setq char (aref transformers pos))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
246 (cond
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
247 (quoted (setq pos (1+ pos)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
248 quoted nil))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
249 ((= ?\\ char)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
250 (setq quoted t
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
251 result (concat result (substring transformers last pos))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
252 pos (1+ pos)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
253 last pos))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
254 ((and (null quoted) (= char dired-file-wildcard))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
255 (setq pos (1+ pos)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
256 trans (and (< pos len)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
257 dired-use-file-transformers
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
258 (assq (aref transformers pos)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
259 dired-trans-map))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
260 transformed t)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
261 (if trans
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
262 (setq result (concat result
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
263 (substring transformers last (1- pos))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
264 (funcall (cdr trans) filename))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
265 pos (1+ pos)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
266 last pos)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
267 (setq result (concat result (substring transformers last (1- pos))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
268 (dired-make-relative filename (, dir) t))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
269 last pos)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
270 ((setq pos (1+ pos)))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
271 (if result
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
272 (progn
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
273 (setq result (dired-shell-quote
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
274 (concat result (substring transformers last))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
275 (if transformed (list result) result))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
276 transformers))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
277
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
278 (defun dired-trans-filenames (transformers files dir)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
279 ;; Applies a transformer string to a list of filenames,
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
280 ;; concatenating them into a string. The result will be prefixed
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
281 ;; by dired-shell-prefix, the filenames separated by dired-shell-separator,
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
282 ;; and postfixed by dired-shell-postfix.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
283 ;; Returns a list if filename subst. was done. A string otherwise.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
284 (let ((list files)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
285 (res nil)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
286 trans)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
287 (while list
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
288 (setq trans (dired-trans-subst transformers (car list) dir))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
289 (if (listp trans)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
290 (setq res (nconc res trans)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
291 list (cdr list))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
292 (setq res trans
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
293 list nil)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
294 (if (listp res)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
295 (list
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
296 (if (> (length files) 1)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
297 (concat dired-shell-prefix
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
298 (mapconcat 'identity res dired-shell-separator)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
299 dired-shell-postfix)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
300 (car res)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
301 res)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
302
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
303 (defun dired-trans-command (command files dir)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
304 ;; Do all of the trans substitutions in COMMAND for the list
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
305 ;; of files FILES. FILES must be a list of *absolute* pathnames.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
306 ;; DIR is an absolute directory wrto which filenames may be relativized.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
307 (let ((len (length command))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
308 (start 0)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
309 (pos 0)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
310 (last 0)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
311 result char transed transform)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
312 (while (< pos len)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
313 ;; read over word separators.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
314 (while (and (< pos len) (memq (aref command pos)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
315 dired-shell-command-separators))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
316 (setq pos (1+ pos)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
317 (setq start pos)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
318 ;; read a word
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
319 (while (and (< pos len) (not (memq (setq char (aref command pos))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
320 dired-shell-command-separators)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
321 (setq pos (1+ pos))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
322 ;; look out for quoted separators
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
323 (and (= ?\\ char) (< pos len) (or (memq (setq char (aref command pos))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
324 dired-shell-command-separators)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
325 (= ?\\ char))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
326 (setq pos (1+ pos))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
327 (setq transform (if (= start pos)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
328 ""
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
329 (dired-trans-filenames (substring command start pos)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
330 files dir))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
331 ;; remember if we did any transforming
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
332 transed (or transed (listp transform))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
333 result (concat result
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
334 (substring command last start)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
335 (if (listp transform)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
336 (car transform)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
337 transform))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
338 last pos))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
339 (if transed
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
340 ;; just return result
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
341 result
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
342 ;; add the filenames at the end.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
343 (let ((fns (if (> (length files) 1)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
344 (concat dired-shell-prefix
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
345 (mapconcat
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
346 (function
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
347 (lambda (fn)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
348 (dired-shell-quote
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
349 (dired-make-relative fn dir t))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
350 files dired-shell-separator)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
351 dired-shell-postfix)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
352 (dired-shell-quote
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
353 (dired-make-relative (car files) dir t)))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
354 (concat result " " fns)))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
355
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
356 (defun dired-shell-stuff-it (command file-list dir on-each)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
357 ;; Make up a shell command line from COMMAND and FILE-LIST.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
358 ;; If ON-EACH is t, COMMAND should be applied to each file, else
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
359 ;; simply concat all files and apply COMMAND to this.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
360 ;; If ON-EACH is 'dir, the command is run in the directory of each file
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
361 ;; In this case FILE-LIST must be a list of full paths.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
362 ;; FILE-LIST's elements will be quoted for the shell.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
363 (cond
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
364 ((eq on-each 'dir)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
365 (let ((subshell-dir nil)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
366 (list file-list)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
367 (result nil))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
368 (while list
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
369 (let ((cmd (dired-trans-command command (list (car list))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
370 (file-name-directory (car list))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
371 (fdir (dired-shell-quote (file-name-directory (car list)))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
372 (setq result
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
373 (apply 'concat
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
374 result
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
375 (if subshell-dir
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
376 (if (string-equal dir subshell-dir)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
377 (list "\; " cmd)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
378 (if (string-equal dir fdir)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
379 (progn
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
380 (setq subshell-dir nil)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
381 (list "\)\; " cmd))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
382 (setq subshell-dir fdir)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
383 (list "\)\; \(cd "
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
384 fdir
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
385 "\; "
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
386 cmd)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
387 (if (string-equal fdir dir)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
388 (list (and result "\; ")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
389 cmd)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
390 (setq subshell-dir fdir)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
391 (list (and result "\; ")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
392 "\(cd "
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
393 fdir
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
394 "\; "
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
395 cmd)))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
396 (setq list (cdr list))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
397 (concat result (and subshell-dir ")"))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
398 (on-each
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
399 (mapconcat (function
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
400 (lambda (fn)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
401 (dired-trans-command command (list fn) dir)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
402 file-list "; "))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
403
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
404 (t (dired-trans-command command file-list dir))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
405
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
406 (defun dired-guess-default (files)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
407 ;; Guess a list of possible shell commands for FILES.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
408 (and dired-default-auto-shell-command-alist
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
409 files
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
410 (let ((alist (append dired-auto-shell-command-alist
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
411 dired-default-auto-shell-command-alist))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
412 guesses)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
413 (while alist
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
414 (let* ((elt (car alist))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
415 (regexp (car elt)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
416 (setq guesses
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
417 (nconc guesses
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
418 (catch 'missed
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
419 (mapcar (function
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
420 (lambda (file)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
421 (or (string-match regexp file)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
422 (throw 'missed nil))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
423 files)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
424 (delq nil (mapcar 'eval (cdr elt)))))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
425 (setq alist (cdr alist)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
426 (dired-uniquefy-list guesses))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
427
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
428 (defun dired-shell-unhandle-file-name (filename)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
429 "Turn a file name into a form that can be sent to a shell process.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
430 This is particularly usefull if we are sending file names to a remote shell."
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
431 (let ((handler (find-file-name-handler filename 'dired-shell-unhandle-file-name)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
432 (if handler
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
433 (funcall handler 'dired-shell-unhandle-file-name filename)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
434 filename)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
435
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
436 ;;; Actually running the shell command
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
437
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
438 (defun dired-run-shell-command-closeout (buffer &optional message)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
439 ;; Report on the number of lines produced by a shell command.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
440 (if (get-buffer buffer)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
441 (save-excursion
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
442 (set-buffer buffer)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
443 (if (zerop (buffer-size))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
444 (progn
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
445 (if message
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
446 (message "Shell command completed with no output. %s"
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
447 message)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
448 (message "Shell command completed with no output."))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
449 (kill-buffer buffer))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
450 (set-window-start (display-buffer buffer) 1)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
451 (if message
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
452 (message "Shell command completed. %s" message)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
453 (message "Shell command completed."))))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
454
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
455 (defun dired-rsc-filter (proc string)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
456 ;; Do save-excursion by hand so that we can leave point
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
457 ;; numerically unchanged despite an insertion immediately
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
458 ;; after it.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
459 (let* ((obuf (current-buffer))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
460 (buffer (process-buffer proc))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
461 opoint
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
462 (window (get-buffer-window buffer))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
463 (pos (window-start window)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
464 (unwind-protect
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
465 (progn
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
466 (set-buffer buffer)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
467 (setq opoint (point))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
468 (goto-char (point-max))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
469 (insert-before-markers string))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
470 ;; insert-before-markers moved this marker: set it back.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
471 (set-window-start window pos)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
472 ;; Finish our save-excursion.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
473 (goto-char opoint)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
474 (set-buffer obuf))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
475
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
476 (defun dired-rsc-sentinel (process signal)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
477 ;; Sentinel function used by dired-run-shell-command
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
478 (if (memq (process-status process) '(exit signal))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
479 (let ((buffer (get-buffer (process-buffer process))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
480 (if buffer
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
481 (save-excursion
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
482 (set-buffer buffer)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
483 (if (zerop (buffer-size))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
484 (message
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
485 "Dired & shell command completed with no output.")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
486 (let ((lines (count-lines dired-shell-input-start
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
487 (point-max))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
488 (message
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
489 "Dired & shell command completed with %d line%s of output."
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
490 lines (dired-plural-s lines))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
491 (setq mode-line-process nil)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
492 (delete-process process))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
493
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
494 (defun dired-shell-call-process (command dir &optional in-background)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
495 ;; Call a shell command as a process in the current buffer.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
496 ;; The process should try to run in DIR. DIR is also
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
497 ;; used to lookup a file-name-handler.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
498 ;; Must return the process object if IN-BACKGROUND is non-nil,
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
499 ;; otherwise the process exit status.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
500 (let ((handler (find-file-name-handler dir 'dired-shell-call-process)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
501 (if handler
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
502 (funcall handler 'dired-shell-call-process command dir in-background)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
503 (let ((process-connection-type ; don't waste pty's
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
504 (null (null in-background))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
505 (setq default-directory dir)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
506 (if in-background
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
507 (progn
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
508 (setq mode-line-process '(": %s"))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
509 (start-process "Shell" (current-buffer)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
510 shell-file-name "-c" command))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
511 (call-process shell-file-name nil t nil "-c" command))))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
512
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
513 (defun dired-run-shell-command (command dir in-background &optional append)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
514 ;; COMMAND is shell command
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
515 ;; DIR is directory in which to do the shell command.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
516 ;; If IN-BACKGROUND is non-nil, the shell command is run in the background.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
517 ;; If it is a string, this is written as header into the output buffer
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
518 ;; before the command is run.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
519 ;; If APPEND is non-nil, the results are appended to the contents
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
520 ;; of *shell-command* buffer, without erasing its previous contents.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
521 (save-excursion
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
522 (if in-background
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
523 (let* ((buffer (get-buffer-create
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
524 "*Background Shell Command Output*"))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
525 (n 2)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
526 proc)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
527 ;; No reason why we can't run two+ background commands.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
528 (while (get-buffer-process buffer)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
529 (setq buffer (get-buffer-create
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
530 (concat "*Background Shell Command Output*<"
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
531 (int-to-string n) ">"))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
532 n (1+ n)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
533 (set-buffer buffer)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
534 (or (eq major-mode 'comint-mode)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
535 (progn
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
536 (comint-mode)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
537 (set (make-local-variable 'comint-prompt-regexp)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
538 "^[^\n]*\\? *")))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
539 (display-buffer buffer)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
540 (barf-if-buffer-read-only)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
541 ;; If will kill a process, query first.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
542
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
543 (set (make-local-variable 'dired-shell-input-start) (point-min))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
544 (if append
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
545 (progn
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
546 (goto-char (point-max))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
547 (or (= (preceding-char) ?\n) (bobp) (insert "\n")))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
548 (erase-buffer)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
549 (if (stringp in-background)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
550 (progn
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
551 (insert in-background)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
552 (set (make-local-variable 'dired-shell-input-start)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
553 (point)))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
554 (setq proc (dired-shell-call-process command dir t))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
555 (set-marker (process-mark proc) (point))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
556 (set-process-sentinel proc 'dired-rsc-sentinel)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
557 (set-process-filter proc 'dired-rsc-filter)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
558 nil) ; return
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
559 (let ((buffer (get-buffer-create "*Shell Command Output*")))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
560 (set-buffer buffer)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
561 (barf-if-buffer-read-only)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
562 (set (make-local-variable 'dired-shell-input-start) (point-min))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
563 (if append
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
564 (progn
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
565 (goto-char (point-max))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
566 (or (= (preceding-char) ?\n) (bobp) (insert "\n")))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
567 (erase-buffer))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
568 (dired-shell-call-process command dir)))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
569
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
570 ;;; User commands
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
571
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
572 (defun dired-do-shell-command (command arg files &optional in-background)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
573 ;; ARG = (16) means operate on each file, in its own directory.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
574 ;; ARG = (4) means operate on each file, but in the current
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
575 ;; default-directory.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
576 "Run a shell command COMMAND on the marked files.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
577 If no files are marked or a non-zero numeric prefix arg is given,
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
578 the next ARG files are used. Use prefix 1 to indicate the current file.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
579
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
580 Normally the shell command is executed in the current dired subdirectory.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
581 This is the directory in the dired buffer which currently contains the point.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
582 One shell command is run for all of the files.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
583 e.g. cmd file1 file2 file3 ...
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
584 If the total length of of the command exceeds 10000 characters, the files will
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
585 be bunched to forms commands shorter than this length, and successive commands
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
586 will be sent.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
587
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
588 With a prefix of \\[universal-argument], a separate command for each file will
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
589 be executed.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
590
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
591 With a prefix of \\[universal-argument] \\[universal-argument], a separate command will be sent for each file,
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
592 and the command will be executed in the directory of that file. The explicit
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
593 command will be of the form
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
594
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
595 cd dir; cmd file
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
596
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
597 When prompting for the shell command, dired will always indicate the directory
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
598 in which the command will be executed.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
599
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
600 The following documentation depends on the settings of `dired-file-wildcard',
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
601 `dired-shell-command-separators', `dired-trans-map', `dired-shell-prefix',
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
602 `dired-shell-separator', and `dired-shell-postfix'. See the documentation for
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
603 these variables. Below, I will assume default settings for these variables.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
604
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
605 If the shell command contains a *, then the list of files is substituted for *.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
606 The filenames will be written as relative to the directory in which the shell
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
607 command is executing. If there is no *, and the command does not end in &,
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
608 then the files are appended to the end of the command. If the command ends in
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
609 a &, then the files are inserted before the &.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
610
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
611 If `dired-use-file-transformers' is non-nil, then certain 2-character
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
612 sequences represent parts of the file name.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
613 The default transformers are:
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
614 *f = full file name
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
615 *n = file name without directory
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
616 *d = file name's directory
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
617 This will end in a \"/\" in unix.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
618 *e = file names extension
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
619 By default this the part of the file name without directory, which
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
620 proceeds the first \".\". If \".\" is the first character of the name,
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
621 then this \".\" is ignored. The definition of extension can
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
622 be customized with `dired-filename-re-ext'.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
623 *b = file base name
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
624 This is the part of the file name without directory that precedes
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
625 the extension.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
626 *v = file name with out version control extension (i.e. \",v\")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
627 *z = file name without compression extension
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
628 (i.e. \".Z\", \".z\", or \".gz\")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
629
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
630 Shell commands are divided into words separated by spaces. Then for each
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
631 word the file name transformers are applied to the list of files, the result
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
632 concatenated together and substituted for the word in the shell command.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
633
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
634 For example
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
635 cmd -a *f -b *d*b.fizzle applied to /foo/bar and /la/di/da results in
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
636 cmd -a /foo/bar /la/di/da -b /foo/bar.fizzle /la/di/da.fizzle
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
637
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
638 The \"on-each\" prefixes \\[universal-argument] and 0, also apply while
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
639 using file transformers. As well, when using file-transformers * still
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
640 represents the file name relative to the current directory. Not that this
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
641 differs from *f, which always represents the full pathname.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
642
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
643 A \"\\\" can always be used to quote any character having special meaning.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
644 For example, if the current directory is /la, then *n applied
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
645 to /la/di/da returns la, whereas *\\n returns di/dan. Similarly,
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
646 \"*d\\ *n\" returns \"/la/di da\".
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
647
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
648 The prefix character for file name transformers is always the same as
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
649 `dired-file-wildcard'."
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
650
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
651 (interactive
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
652 (let ((on-each (or (equal '(4) current-prefix-arg)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
653 (equal '(16) current-prefix-arg)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
654 (files (dired-get-marked-files
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
655 nil (and (not (consp current-prefix-arg))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
656 current-prefix-arg)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
657 (dir (and (not (equal current-prefix-arg '(16)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
658 (dired-current-directory))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
659 (list
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
660 (dired-read-shell-command
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
661 (concat (if dir
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
662 (format "! in %s" (dired-abbreviate-file-name dir))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
663 "cd <dir>; ! ")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
664 "on "
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
665 (if on-each "each ")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
666 "%s: ")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
667 (and (not on-each) current-prefix-arg)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
668 (if dir
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
669 (mapcar (function
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
670 (lambda (fn)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
671 (dired-make-relative fn dir t)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
672 files)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
673 files))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
674 current-prefix-arg files nil)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
675
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
676 ;; Check for background commands
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
677 (if (string-match "[ \t]*&[ \t]*$" command)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
678 (setq command (substring command 0 (match-beginning 0))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
679 in-background t))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
680
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
681 ;; Look out for remote file names.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
682
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
683 (let* ((on-each (or (equal arg '(4)) (and (equal arg '(16)) 'dir)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
684 (ufiles (mapcar 'dired-shell-unhandle-file-name files))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
685 (dir (dired-current-directory))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
686 (udir (dired-shell-unhandle-file-name dir)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
687
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
688 (save-excursion ; in case `shell-command' changes buffer
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
689 (cond
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
690
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
691 ((null ufiles)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
692 ;; Just run as a command on no files.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
693 (if in-background
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
694 (dired-run-shell-command command dir t)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
695 (dired-run-shell-command command dir nil)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
696 (dired-run-shell-command-closeout "*Shell Command Output*")))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
697
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
698 (in-background
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
699 ;; Can't use dired-bunch-files for background shell commands.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
700 ;; as we will create a bunch of process running simultaneously.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
701 ;; A better solution needs to be found.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
702 (dired-run-shell-command
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
703 (dired-shell-stuff-it command ufiles udir on-each)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
704 dir (if (equal arg '(16))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
705 (concat "cd <dir>; \"" command "\"\n\n")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
706 (concat "\"" command "\" in " dir "\n\n"))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
707 (on-each
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
708 (let ((buff (get-buffer "*Shell Command Output*"))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
709 failures this-command this-dir ufile return message)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
710 (if buff
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
711 (save-excursion
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
712 (set-buffer buff)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
713 (erase-buffer)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
714 (while ufiles
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
715 (setq ufile (car ufiles))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
716 (if (eq on-each 'dir)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
717 (setq this-dir (dired-shell-quote (file-name-directory (directory-file-name ufile)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
718 this-command (concat "cd " this-dir "; " command))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
719 (setq this-command command)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
720 (or this-dir (setq this-dir udir)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
721 (setq return
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
722 (dired-run-shell-command
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
723 (dired-shell-stuff-it this-command (list ufile) this-dir nil)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
724 this-dir nil t))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
725 (if (and (integerp return) (/= return 0))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
726 (save-excursion
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
727 (let ((file (nth (- (length files) (length (member ufile ufiles))) files)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
728 (if (and dired-shell-failure-marker
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
729 (dired-goto-file file))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
730 (let ((dired-marker-char dired-shell-failure-marker))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
731 (dired-mark 1)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
732 (setq failures (cons file failures)))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
733 (setq ufiles (cdr ufiles)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
734 (if failures
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
735 (let ((num (length failures)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
736 (setq message
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
737 (if dired-shell-failure-marker
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
738 (format
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
739 "Marked %d failure%s with %c."
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
740 num (dired-plural-s num)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
741 dired-shell-failure-marker)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
742 "Failed on %d file%s." num
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
743 (dired-plural-s num)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
744 (dired-log
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
745 (current-buffer)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
746 "Shell command %s failed (non-zero exit status) for:\n %s"
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
747 command failures)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
748 (dired-log (current-buffer) t)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
749 (dired-run-shell-command-closeout "*Shell Command Output*" message)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
750
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
751 (t
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
752 (dired-bunch-files
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
753 (- 10000 (length command))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
754 (function (lambda (&rest ufiles)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
755 (dired-run-shell-command
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
756 (dired-shell-stuff-it command ufiles udir nil)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
757 dir nil)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
758 nil)) ; for the sake of nconc in dired-bunch-files
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
759 nil ufiles)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
760 (dired-run-shell-command-closeout "*Shell Command Output*"))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
761 ;; Update any directories
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
762 (or in-background
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
763 (let ((dired-no-confirm '(revert-subdirs)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
764 (dired-verify-modtimes)))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
765
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
766 (defun dired-do-background-shell-command (command arg files)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
767 "Like \\[dired-do-shell-command], but starts command in background.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
768 Note that you can type input to the command in its buffer.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
769 This requires background.el from the comint package to work."
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
770 ;; With the version in emacs-19.el, you can alternatively just
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
771 ;; append an `&' to any shell command to make it run in the
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
772 ;; background, but you can't type input to it.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
773 (interactive
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
774 (let ((on-each (or (equal '(4) current-prefix-arg)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
775 (equal '(16) current-prefix-arg)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
776 (files (dired-get-marked-files
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
777 nil (and (not (consp current-prefix-arg))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
778 current-prefix-arg)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
779 (dir (and (not (equal current-prefix-arg '(16)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
780 (dired-current-directory))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
781 (list
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
782 (dired-read-shell-command
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
783 (concat "& "
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
784 (if dir
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
785 (format "in %s " (dired-abbreviate-file-name dir))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
786 "cd <dir>; ")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
787 "on "
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
788 (if on-each "each ")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
789 "%s: ")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
790 (and (not on-each) current-prefix-arg)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
791 (if dir
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
792 (mapcar (function
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
793 (lambda (fn)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
794 (dired-make-relative fn dir t)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
795 files)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
796 files))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
797 current-prefix-arg files)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
798 (dired-do-shell-command command arg files t))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
799
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
800 ;;; Printing files
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
801
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
802 (defun dired-do-print (&optional arg command files)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
803 "Print the marked (or next ARG) files.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
804 Uses the shell command coming from variable `dired-print-program-alist'."
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
805 (interactive
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
806 (progn
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
807 (if dired-print-history
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
808 (setq dired-print-history (dired-uniquefy-list dired-print-history))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
809 (setq dired-print-history (mapcar 'cdr dired-print-program-alist)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
810 (let* ((files (dired-get-marked-files nil current-prefix-arg))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
811 (rel-files (mapcar (function
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
812 (lambda (fn)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
813 (dired-make-relative
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
814 fn
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
815 (dired-current-directory) t)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
816 files))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
817 (alist dired-print-program-alist)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
818 (first (car files))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
819 (dired-print-history (copy-sequence dired-print-history))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
820 elt initial command)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
821 ;; For gmhist
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
822 (put 'dired-print-history 'no-default t)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
823 (if first
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
824 (while (and alist (not initial))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
825 (if (string-match (car (car alist)) first)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
826 (setq initial (cdr (car alist)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
827 (setq alist (cdr alist)))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
828 (if (and initial (setq elt (member initial dired-print-history)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
829 (setq dired-print-history (nconc
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
830 (delq (car elt) dired-print-history)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
831 (list initial))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
832 (setq command
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
833 (dired-mark-read-string
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
834 "Print %s with: "
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
835 initial 'print current-prefix-arg rel-files
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
836 'dired-print-history))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
837 (list current-prefix-arg command files))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
838 (or files
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
839 (setq files (dired-get-marked-files nil arg)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
840 (while files
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
841 (dired-print-file command (car files))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
842 (setq files (cdr files))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
843
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
844 (defun dired-print-file (command file)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
845 ;; Using COMMAND, print FILE.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
846 (let ((handler (find-file-name-handler file 'dired-print-file)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
847 (if handler
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
848 (funcall handler 'dired-print-file command file)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
849 (let ((rel-file (dired-make-relative file (dired-current-directory) t)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
850 (message "Spooling %s..." rel-file)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
851 (shell-command (dired-trans-command command (list file) ""))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
852 (message "Spooling %s...done" rel-file)))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
853
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
854 ;;; end of dired-shell.el