annotate lisp/efs/dired-shell.el @ 185:3d6bfa290dbd r20-3b19

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