annotate lisp/dired/dired-cd.el @ 82:6a378aca36af r20-0b91

Import from CVS: tag r20-0b91
author cvs
date Mon, 13 Aug 2007 09:07:36 +0200
parents 376386a54a3c
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1 ;;; -*- Mode: Emacs-lisp -*- ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2 ;;; dired-cd.el - Adjust Working Directory for Tree Dired Shell Commands
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3 ;;; Id: dired-cd.el,v 1.14 1991/11/01 14:28:27 sk RelBeta
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4 ;;; Copyright (C) 1991 Hugh Secker-Walker
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6 ;;; Author: Hugh Secker-Walker hugh@ear-ache.mit.edu
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
7 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
8 ;;; Modified by Sebastian Kremer <sk@thp.uni-koeln.de>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
9 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
10 ;;; This program is free software; you can redistribute it and/or modify
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
11 ;;; it under the terms of the GNU General Public License as published by
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
12 ;;; the Free Software Foundation; either version 1, or (at your option)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
13 ;;; any later version.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
14 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
15 ;;; This program is distributed in the hope that it will be useful,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
16 ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
17 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
18 ;;; GNU General Public License for more details.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
19 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
20 ;;; A copy of the GNU General Public License can be obtained from this
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
21 ;;; program's author (send electronic mail to the above address) or from
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
22 ;;; Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
23
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
24 ;; LISPDIR ENTRY for the Elisp Archive ===============================
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
25 ;; LCD Archive Entry:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26 ;; dired-cd|Hugh Secker-Walker|hugh@ear-ache.mit.edu
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27 ;; |Adjust Working Directory for Tree Dired Shell Commands
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28 ;; |Date: 1991/11/01 14:28:27 |Revision: 1.14 |
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30 ;;; SUMMARY
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32 ;;; This extension to Sebastian Kremer's (sk@thp.Uni-Koeln.DE) Tree-Dired
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33 ;;; permits the working directory of the dired shell commands
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34 ;;; dired-do-shell-command and dired-do-background-shell-command
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35 ;;; to be the files' subdirectory under certain circumstances.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36 ;;; Loading this extension does not change the behavior of dired until
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37 ;;; the variables dired-cd-same-subdir and/or dired-cd-on-each are
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38 ;;; non-nil.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41 ;;; FUNCTIONALITY PROVIDED
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43 ;;; If dired-cd-same-subdir is non-nil and if all the selected files
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44 ;;; (marked, non-zero numeric ARG, etc.) are in the same directory, then
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45 ;;; dired-do-shell-command and dired-do-background-shell-command will
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46 ;;; cause the shell to perform a cd into that directory before the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47 ;;; commands are executed. Also, the selected filenames will be provided
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48 ;;; to the command without any directory components.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50 ;;; If dired-cd-on-each is non-nil and if the on-each option is specified
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51 ;;; (numeric arg of zero), then dired-do-shell-command and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52 ;;; dired-do-background-shell-command will perform a cd into the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53 ;;; directory of each file before the commands on that file are executed.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54 ;;; Also, each filename will be provided to the command without any
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55 ;;; directory components. Note that this on-each behavior occurs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56 ;;; regardless of whether the files are all in the same directory or not.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58 ;;; After the above "cd wrapping" has occured, the existing
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59 ;;; dired-shell-stuff-it is used to do file-name substitution and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60 ;;; quoting, so custom versions of this procedure should work, e.g.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61 ;;; dired-trans will transform commands correctly. However, since
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62 ;;; filenames lack any directory components, features that use the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63 ;;; directory components will fail, e.g. the dired-trans [d] transform
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64 ;;; specifier will be empty.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66 ;;; New variables (user options):
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67 ;;; dired-cd-same-subdir
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68 ;;; dired-cd-on-each
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70 ;;; Replaces procedures:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71 ;;; dired-do-shell-command (new doc and prompt, calls dired-cd-wrap-it)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73 ;;; Adds procedures:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74 ;;; dired-cd-wrap-it (wraps calls to dired-shell-stuff-it with "cd <dir>")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75 ;;; dired-files-same-directory
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78 ;; INSTALLATION
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80 ;; Put this file into your load-path and add (load "dired-cd") to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81 ;; your dired-load-hook, e.g.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83 ;; (setq dired-load-hook '(lambda ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84 ;; ;; possibly more statements here
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85 ;; (load "dired-cd")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87 ;; Do (setq dired-cd-same-subdir t) and perhaps (setq dired-cd-on-each t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88 ;; in your .emacs. By default, dired-cd doesn't change the behavior of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89 ;; dired when it is loaded.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91 ;; If dired-cd-same-subdir is non-nil, then the shell commands cd to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92 ;; the appropriate directory if all the selected files (marked,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93 ;; numeric ARG, etc.) are in that directory; however, on-each behavior
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94 ;; is not changed.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96 ;; If dired-cd-on-each is non-nil, then each instance of the command
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97 ;; for an on-each shell command runs in the file's directory
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98 ;; regardless of whether the files are all in the same directory.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101 (defvar dired-cd-same-subdir nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102 "*If non-nil, and selected file(s) (by marks, numeric arg, \\[universal-argument]) are in same
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103 subdir, causes dired shell command to run in that subdir. Filenames provided
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104 to shell commands are stripped of their directory components. Does not
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105 affect behavior of on-each, for that see variable dired-cd-on-each.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107 (defvar dired-cd-on-each nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108 "*If non-nil, on-each causes each dired shell command to run in the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109 file's directory. Filenames provided to shell commands are stripped of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110 their directory components. Also see variable dired-cd-same-subdir.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112 ;; Redefines dired.el's version.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113 ;; Changes to documentation and prompt, and uses dired-cd-wrap-it.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114 (defun dired-do-shell-command (&optional arg in-background)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115 "Run a shell command on the marked files.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116 If there is output, it goes to a separate buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117 The list of marked files is appended to the command string unless asterisks
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118 `*' indicate the place(s) where the list should go.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119 If no files are marked or a specific numeric prefix arg is given, uses
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120 next ARG files. With a zero argument, run command on each marked file
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121 separately: `cmd * foo' results in `cmd F1 foo; ...; cmd Fn foo'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122 As always, a raw arg (\\[universal-argument]) means the current file.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123 The option variables dired-cd-same-subdir and dired-cd-on-each
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124 permit the command\(s\) to run in the files' directories if appropriate,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125 and thus determine where output files are created. Default is top
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126 directory. The prompt mentions the file(s) or the marker, the cd subdir,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127 and the on-each flags when they apply.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128 No automatic redisplay is attempted, as the file names may have
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129 changed. Type \\[dired-do-redisplay] to redisplay the marked files."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
130 ;; Function dired-shell-stuff-it (called by dired-cd-wrap-it) does the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131 ;; actual file-name substitution and can be redefined for customization.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
132 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
133 (let* ((on-each (equal arg 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
134 (file-list (dired-mark-get-files t (if on-each nil arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
135 (prompt (concat (if in-background "& " "! ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
136 (if (or (and on-each dired-cd-on-each)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
137 (and dired-cd-same-subdir
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
138 (not on-each)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
139 (dired-files-same-directory file-list)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
140 "cd <dir>; " "")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
141 "on "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
142 (if on-each "each " "")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
143 "%s: "))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
144 ;; Give feedback on file(s) and working directory status
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
145 (command (dired-read-shell-command
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
146 prompt (if on-each nil arg) file-list))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
147 (result (dired-cd-wrap-it command file-list on-each arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
148 ;; execute the shell command
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
149 (dired-run-shell-command result in-background)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
150
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
151 (defun dired-cd-wrap-it (command files on-each &optional raw)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
152 "Args COMMAND FILES ON-EACH &optional RAW-ARG, like dired-shell-stuff-it.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
153 Calls dired-shell-stuff-it, but wraps the resulting command\(s\)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
154 with \"cd <dir>\" commands when appropriate. Note: when ON-EACH is non-nil,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
155 dired-shell-stuff-it is called once for each file in FILES.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
156 See documentation of variables dired-cd-same-subdir and dired-cd-on-each
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
157 for wrap conditions."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
158 (if on-each;; command applied to each file separately
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
159 ;; cd's are done in subshells since all shells I know of have subshells
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
160 (let* ((cwd "");; current working directory
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
161 (in-subshell nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
162 (cmd (mapconcat;; files over command, fuss with "cd <dir>"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
163 (function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
164 (lambda (file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
165 (let ((cd "") d);; cd command and file's directory
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
166 (if (not dired-cd-on-each) nil;; poor man's (when ...)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
167 (setq d;; directory, relative to default-directory
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
168 (directory-file-name
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
169 (or (file-name-directory file) ""))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
170 file (file-name-nondirectory file))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
171 (if (not (string= d cwd));; new subdir, new subshell
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
172 (setq cwd d
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
173 ;; close existing subshell,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
174 ;; open a new one
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
175 cd (concat (if in-subshell "); " "")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
176 "(cd " (shell-quote cwd) "; ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
177 in-subshell t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
178 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
179 ;; existing dired-shell-stuff-it does
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
180 ;; actual command substitution
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
181 (concat cd (dired-shell-stuff-it command (list file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
182 on-each raw)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
183 files "; ")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
184 (if in-subshell (concat cmd ")") cmd));; close an open subshell
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
185
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
186 ;; not on-each, all files are args to single command instance
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
187 (let ((same-dir (and dired-cd-same-subdir
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
188 (dired-files-same-directory files nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
189 (cd ""))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
190 ;; Let the prepended cd command be relative to default-directory,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
191 ;; and only give it if necessary. This way, after ange-ftp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
192 ;; prepends its own cd command, it will still work.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
193 ;; sk 3-Sep-1991 14:23
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
194 ;; hsw 31-Oct-1991 -- filenames relative to default-directory
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
195 (if (and same-dir (not (equal same-dir "")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
196 (setq files (mapcar (function file-name-nondirectory) files)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
197 cd (concat "cd " (shell-quote same-dir) "; ")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
198 ;; existing dired-shell-stuff-it does the command substitution
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
199 (concat cd (dired-shell-stuff-it command files on-each raw)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
200
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
201 (defun dired-files-same-directory (file-list &optional absolute)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
202 "If all files in LIST are in the same directory return it, otherwise nil.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
203 Returned name has no trailing slash. \"Same\" means file-name-directory of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
204 the files are string=. File names in LIST must all be absolute or all be
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
205 relative. Implicitly, relative file names are in default-directory. If
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
206 optional ABS is non-nil, the returned name will be absolute, otherwise the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
207 returned name will be absolute or relative as per the files in LIST."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
208 (let ((dir (file-name-directory (car file-list))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
209 (if (memq nil (mapcar (function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
210 (lambda (file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
211 (string= dir (file-name-directory file))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
212 file-list))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
213 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
214 (directory-file-name
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
215 (if (or (not absolute) (and dir (file-name-absolute-p dir)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
216 (or dir "")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
217 (concat default-directory dir))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
218
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
219 (provide 'dired-cd)