annotate lisp/dired/dired.el @ 0:376386a54a3c r19-14

Import from CVS: tag r19-14
author cvs
date Mon, 13 Aug 2007 08:45:50 +0200
parents
children ac2d302a0011
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 ;;; dired.el --- directory-browsing commands
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2 ;; Keywords: dired extensions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4 ;; Copyright (C) 1985, 1986, 1991, 1992 Free Software Foundation, Inc.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6 ;; This file is part of XEmacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
7
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
8 ;; XEmacs is free software; you can redistribute it and/or modify it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
9 ;; under the terms of the GNU General Public License as published by
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
10 ;; the Free Software Foundation; either version 2, or (at your option)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
11 ;; any later version.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
12
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
13 ;; XEmacs is distributed in the hope that it will be useful, but
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
14 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
15 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
16 ;; General Public License for more details.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
17
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
18 ;; You should have received a copy of the GNU General Public License
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
19 ;; along with XEmacs; see the file COPYING. If not, write to the Free
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
20 ;; Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
21
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
22 ;; Rewritten in 1990/1991 to add tree features, file marking and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
23 ;; sorting by Sebastian Kremer <sk@thp.uni-koeln.de>.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
24
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
25 (provide 'dired)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27 (defconst dired-version (substring "!Revision: 6.0 !" 11 -2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28 "The revision number of Tree Dired (as string). The complete RCS id is:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30 !Id: dired.el,v 6.0 1992/05/15 14:25:45 sk RelBeta !
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32 Don't forget to mention this when reporting bugs to:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34 Sebastian Kremer <sk@thp.uni-koeln.de>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36 Tree dired is available for anonymous ftp in USA in:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38 ftp.cs.buffalo.edu:pub/Emacs/diredall.tar.Z
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40 and in Europe at my own site in Germany:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42 ftp.uni-koeln.de:/pub/gnu/emacs/diredall.tar.Z")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43 ;; Should perhaps later give bug-gnu-emacs@prep.gnu.ai.mit.edu instead.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45 ;; compatibility package when using Emacs 18.55
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46 ;; XEmacs fix:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47 (defvar dired-emacs-19-p (not (equal (substring emacs-version 0 2) "18")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48 ;;;#### install (is there a better way to test for Emacs 19?)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49 (or dired-emacs-19-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50 (require 'emacs-19))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52 ;;; Customizable variables
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54 ;;; The funny comments are for autoload.el, to automagically update
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55 ;;; loaddefs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57 (defvar dired-use-gzip-instead-of-compress t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58 "*If non-nil, use gzip instead of compress as the standard compress
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59 program")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61 (defvar dired-make-gzip-quiet t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62 "*If non-nil, pass -q to shell commands involving gzip this will override
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63 GZIP environment variable.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65 (defvar dired-znew-switches nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66 "*If non-nil, a string of switches that will be passed to `znew'
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67 example: \"-K\"")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69 (defvar dired-gzip-file-extension ".gz"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70 "*A string representing the suffix created by gzip. This should probably
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71 match the value of --suffix or -S in the GZIP environment variable if it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72 exists and \".gz\" if it does not.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75 (defvar dired-listing-switches (purecopy "-al")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76 "*Switches passed to ls for dired. MUST contain the `l' option.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77 Can contain even `F', `b', `i' and `s'.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79 ; Don't use absolute paths as /bin should be in any PATH and people
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80 ; may prefer /usr/local/gnu/bin or whatever. However, chown is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81 ; usually not in PATH.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84 (defvar dired-chown-program
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85 (purecopy
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86 (if (memq system-type '(dgux-unix hpux usg-unix-v silicon-graphics-unix irix))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87 "chown" "/etc/chown"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88 "*Name of chown command (usully `chown' or `/etc/chown').")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91 (defvar dired-ls-program (purecopy "ls")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92 "*Absolute or relative name of the ls program used by dired.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95 (defvar dired-ls-F-marks-symlinks t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96 "*Informs dired about how ls -lF marks symbolic links.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97 Set this to t if `dired-ls-program' with -lF marks the symbolic link
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98 itself with a trailing @ (usually the case under Ultrix).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100 Example: if `ln -s foo bar; ls -F bar' gives `bar -> foo', set it to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101 nil, if it gives `bar@ -> foo', set it to t.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103 Dired checks if there is really a @ appended. Thus, if you have a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104 marking ls program on one host and a non-marking on another host, and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105 don't care about symbolic links which really end in a @, you can
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106 always set this variable to t.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109 (defvar dired-trivial-filenames (purecopy "^\\.\\.?$\\|^#")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110 "*Regexp of files to skip when moving point to the first file of a new directory listing.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111 Nil means move to the subdir line, t means move to first file.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114 (defvar dired-keep-marker-move t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115 ;; Use t as default so that moved files `take their markers with them'
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116 "If t, moved marked files are marked if their originals were.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117 If a character, those files (marked or not) are marked with that character.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120 (defvar dired-keep-marker-copy ?C
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121 "If t, copied files are marked if their source files were.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122 If a character, those files are always marked with that character.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125 (defvar dired-keep-marker-hardlink ?H
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126 "If t, hard-linked files are marked if the linked-to files were.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127 If a character, those files are always marked with that character.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
130 (defvar dired-keep-marker-symlink ?Y
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131 "If t, symlinked marked files are marked if the linked-to files were.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
132 If a character, those files are always marked with that character.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
133
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
134 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
135 (defvar dired-dwim-target nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
136 "*If non-nil, dired tries to guess a default target directory:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
137 If there is a dired buffer displayed in the next window, use
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
138 its current subdir, instead of the current subdir of this dired
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
139 buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
140
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
141 The target is used in the prompt for file copy, move etc.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
142
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
143 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
144 (defvar dired-copy-preserve-time nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
145 "*If non-nil, Dired preserves the last-modified time in a file copy.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
146 \(This works on only some systems.)\\<dired-mode-map>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
147 Use `\\[dired-do-copy]' with a zero prefix argument to toggle its value.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
148
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
149 ;;; Hook variables
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
150
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
151 (defvar dired-load-hook nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
152 "Run after loading dired.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
153 You can customize key bindings or load extensions with this.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
154
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
155 (defvar dired-mode-hook nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
156 "Run at the very end of dired-mode.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
157
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
158 (defvar dired-before-readin-hook nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
159 "This hook is run before a dired buffer is newly read in (created or reverted).")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
160
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
161 (defvar dired-after-readin-hook nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
162 "After each listing of a file or directory, this hook is run
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
163 with the buffer narrowed to the listing.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
164 ;; Note this can't simply be run inside function dired-ls as the hook
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
165 ;; functions probably depend on the dired-subdir-alist to be OK.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
166
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
167 ;;; Internal variables
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
168
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
169 (defvar dired-marker-char ?* ; the answer is 42
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
170 ;; so that you can write things like
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
171 ;; (let ((dired-marker-char ?X))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
172 ;; ;; great code using X markers ...
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
173 ;; )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
174 ;; For example, commands operating on two sets of files, A and B.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
175 ;; Or marking files with digits 0-9. This could implicate
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
176 ;; concentric sets or an order for the marked files.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
177 ;; The code depends on dynamic scoping on the marker char.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
178 "In dired, character used to mark files for later commands.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
179
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
180 (defvar dired-del-marker ?D
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
181 "Character used to flag files for deletion.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
182
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
183 (defvar dired-shrink-to-fit
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
184 (if (fboundp 'baud-rate) (> (baud-rate) search-slow-speed) t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
185 "Whether dired shrinks the display buffer to fit the marked files.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
186
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
187 (defvar dired-flagging-regexp nil);; Last regexp used to flag files.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
188
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
189 (defvar dired-directory nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
190 "The directory name or shell wildcard passed as argument to ls.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
191 Local to each dired buffer.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
192
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
193 (defvar dired-actual-switches nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
194 "The actual (buffer-local) value of `dired-listing-switches'.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
195
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
196 (defvar dired-re-inode-size "[0-9 \t]*"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
197 "Regexp for optional initial inode and file size as produced by ls' -i and -s flags.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
198
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
199 ;; These regexps must be tested at beginning-of-line, but are also
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
200 ;; used to search for next matches, so neither omitting "^" nor
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
201 ;; replacing "^" by "\n" (to make it slightly faster) will work.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
202
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
203 (defvar dired-re-mark "^[^ \n]")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
204 ;; "Regexp matching a marked line.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
205 ;; Important: the match ends just after the marker."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
206 (defvar dired-re-maybe-mark "^. ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
207 ;; Note that dired-re-inode-size allows for an arbitray amount of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
208 ;; whitespace, making nested indentation in dired-nstd.el work.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
209 (defvar dired-re-dir (concat dired-re-maybe-mark dired-re-inode-size "d"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
210 (defvar dired-re-sym (concat dired-re-maybe-mark dired-re-inode-size "l"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
211 (defvar dired-re-exe;; match ls permission string of an executable file
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
212 (mapconcat (function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
213 (lambda (x)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
214 (concat dired-re-maybe-mark dired-re-inode-size x)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
215 '("-[-r][-w][xs][-r][-w].[-r][-w]."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
216 "-[-r][-w].[-r][-w][xs][-r][-w]."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
217 "-[-r][-w].[-r][-w].[-r][-w][xst]")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
218 "\\|"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
219 (defvar dired-re-dot "^.* \\.\\.?/?$") ; with -F, might end in `/'
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
220
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
221 (defvar dired-subdir-alist nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
222 "Association list of subdirectories and their buffer positions:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
223
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
224 \((LASTDIR . LASTMARKER) ... (DEFAULT-DIRECTORY . FIRSTMARKER)).")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
225
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
226 (defvar dired-subdir-regexp "^. \\([^ \n\r]+\\)\\(:\\)[\n\r]"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
227 "Regexp matching a maybe hidden subdirectory line in ls -lR output.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
228 Subexpression 1 is the subdirectory proper, no trailing colon.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
229 The match starts at the beginning of the line and ends after the end
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
230 of the line (\\n or \\r).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
231 Subexpression 2 must end right before the \\n or \\r.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
232
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
233
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
234 ;;; Macros must be defined before they are used - for the byte compiler.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
235
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
236 ;; Returns the count if any work was done, nil otherwise.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
237 (defmacro dired-mark-if (predicate msg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
238 (` (let (buffer-read-only count)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
239 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
240 (setq count 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
241 (if (, msg) (message "Marking %ss..." (, msg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
242 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
243 (while (not (eobp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
244 (if (, predicate)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
245 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
246 (delete-char 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
247 (insert dired-marker-char)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
248 (setq count (1+ count))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
249 (forward-line 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
250 (if (, msg) (message "%s %s%s %s%s."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
251 count
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
252 (, msg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
253 (dired-plural-s count)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
254 (if (eq dired-marker-char ?\040) "un" "")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
255 (if (eq dired-marker-char dired-del-marker)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
256 "flagged" "marked"))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
257 (and (> count 0) count))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
258
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
259 (defmacro dired-mark-map (body arg &optional show-progress)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
260 ;; "Macro: Perform BODY with point somewhere on each marked line
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
261 ;;and return a list of BODY's results.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
262 ;;If no marked file could be found, execute BODY on the current line.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
263 ;; If ARG is an integer, use the next ARG (or previous -ARG, if ARG<0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
264 ;; files instead of the marked files.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
265 ;; In that case point is dragged along. This is so that commands on
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
266 ;; the next ARG (instead of the marked) files can be chained easily.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
267 ;; If ARG is otherwise non-nil, use current file instead.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
268 ;;If optional third arg SHOW-PROGRESS evaluates to non-nil,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
269 ;; redisplay the dired buffer after each file is processed.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
270 ;;No guarantee is made about the position on the marked line.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
271 ;; BODY must ensure this itself if it depends on this.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
272 ;;Search starts at the beginning of the buffer, thus the car of the list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
273 ;; corresponds to the line nearest to the buffer's bottom. This
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
274 ;; is also true for (positive and negative) integer values of ARG.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
275 ;;BODY should not be too long as it is expanded four times."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
276 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
277 ;;Warning: BODY must not add new lines before point - this may cause an
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
278 ;;endless loop.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
279 ;;This warning should not apply any longer, sk 2-Sep-1991 14:10.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
280 (` (prog1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
281 (let (buffer-read-only case-fold-search found results)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
282 (if (, arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
283 (if (integerp (, arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
284 (progn;; no save-excursion, want to move point.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
285 (dired-repeat-over-lines
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
286 (, arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
287 (function (lambda ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
288 (if (, show-progress) (sit-for 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
289 (setq results (cons (, body) results)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
290 (if (< (, arg) 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
291 (nreverse results)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
292 results))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
293 ;; non-nil, non-integer ARG means use current file:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
294 (list (, body)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
295 (let ((regexp (dired-marker-regexp)) next-position)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
296 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
297 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
298 ;; remember position of next marked file before BODY
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
299 ;; can insert lines before the just found file,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
300 ;; confusing us by finding the same marked file again
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
301 ;; and again and...
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
302 (setq next-position (and (re-search-forward regexp nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
303 (point-marker))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
304 found (not (null next-position)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
305 (while next-position
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
306 (goto-char next-position)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
307 (if (, show-progress) (sit-for 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
308 (setq results (cons (, body) results))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
309 ;; move after last match
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
310 (goto-char next-position)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
311 (forward-line 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
312 (set-marker next-position nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
313 (setq next-position (and (re-search-forward regexp nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
314 (point-marker)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
315 (if found
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
316 results
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
317 (list (, body))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
318 ;; save-excursion loses, again
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
319 (dired-move-to-filename))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
320
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
321 (defun dired-mark-get-files (&optional localp arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
322 "Return the marked files as list of strings.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
323 The list is in the same order as the buffer, that is, the car is the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
324 first marked file.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
325 Values returned are normally absolute pathnames.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
326 Optional arg LOCALP as in `dired-get-filename'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
327 Optional second argument ARG forces to use other files. If ARG is an
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
328 integer, use the next ARG files. If ARG is otherwise non-nil, use
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
329 current file. Usually ARG comes from the current prefix arg."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
330 (nreverse (save-excursion (dired-mark-map (dired-get-filename localp) arg))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
331
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
332
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
333 ;; Function dired-ls is redefinable for VMS, ange-ftp, Prospero or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
334 ;; other special applications.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
335
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
336 ;; dired-ls
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
337 ;; - must insert _exactly_one_line_ describing FILE if WILDCARD and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
338 ;; FULL-DIRECTORY-P is nil.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
339 ;; The single line of output must display FILE's name as it was
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
340 ;; given, namely, an absolute path name.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
341 ;; - must insert exactly one line for each file if WILDCARD or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
342 ;; FULL-DIRECTORY-P is t, plus one optional "total" line
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
343 ;; before the file lines, plus optional text after the file lines.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
344 ;; Lines are delimited by "\n", so filenames containing "\n" are not
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
345 ;; allowed.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
346 ;; File lines should display the basename, not a path name.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
347 ;; - must drag point after inserted text
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
348 ;; - must be consistent with
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
349 ;; - functions dired-move-to-filename, (these two define what a file line is)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
350 ;; dired-move-to-end-of-filename,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
351 ;; dired-between-files, (shortcut for (not (dired-move-to-filename)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
352 ;; dired-insert-headerline
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
353 ;; dired-after-subdir-garbage (defines what a "total" line is)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
354 ;; - variables dired-subdir-regexp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
355 (defun dired-ls (file switches &optional wildcard full-directory-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
356 ; "Insert ls output of FILE, formatted according to SWITCHES.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
357 ;Optional third arg WILDCARD means treat FILE as shell wildcard.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
358 ;Optional fourth arg FULL-DIRECTORY-P means file is a directory and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
359 ;switches do not contain `d', so that a full listing is expected.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
360 ;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
361 ;Uses dired-ls-program (and shell-file-name if WILDCARD) to do the work."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
362 (if wildcard
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
363 (let ((default-directory (file-name-directory file)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
364 (call-process shell-file-name nil t nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
365 "-c" (concat dired-ls-program " -d " switches " "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
366 (file-name-nondirectory file))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
367 (call-process dired-ls-program nil t nil switches file)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
368
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
369 ;; The dired command
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
370
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
371 (defun dired-read-dir-and-switches (str)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
372 ;; For use in interactive.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
373 (reverse (list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
374 (if current-prefix-arg
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
375 (read-string "Dired listing switches: "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
376 dired-listing-switches))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
377 (read-file-name (format "Dired %s(directory): " str)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
378 nil default-directory nil))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
379
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
380 ;;;###autoload (define-key ctl-x-map "d" 'dired)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
381 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
382 (defun dired (dirname &optional switches)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
383 "\"Edit\" directory DIRNAME--delete, rename, print, etc. some files in it.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
384 With an optional prefix argument you can specify the ls SWITCHES that are used.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
385 Dired displays a list of files in DIRNAME (which may also have
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
386 shell wildcards appended to select certain files).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
387 You can move around in it with the usual commands.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
388 You can flag files for deletion with \\<dired-mode-map>\\[dired-flag-file-deleted] and then delete them by
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
389 typing \\[dired-do-deletions].
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
390 Type \\[describe-mode] after entering dired for more info.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
391
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
392 If DIRNAME is already in a dired buffer, that buffer is used without refresh."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
393 ;; Cannot use (interactive "D") because of wildcards.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
394 (interactive (dired-read-dir-and-switches ""))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
395 (switch-to-buffer (dired-noselect dirname switches)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
396
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
397 ;;;###autoload (define-key ctl-x-4-map "d" 'dired-other-window)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
398 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
399 (defun dired-other-window (dirname &optional switches)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
400 "\"Edit\" directory DIRNAME. Like `dired' but selects in another window."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
401 (interactive (dired-read-dir-and-switches "in other window "))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
402 (switch-to-buffer-other-window (dired-noselect dirname switches)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
403
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
404 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
405 (defun dired-noselect (dirname &optional switches)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
406 "Like `dired' but returns the dired buffer as value, does not select it."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
407 (or dirname (setq dirname default-directory))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
408 ;; This loses the distinction between "/foo/*/" and "/foo/*" that
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
409 ;; some shells make:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
410 (setq dirname (expand-file-name (directory-file-name dirname)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
411 (if (file-directory-p dirname)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
412 (setq dirname (file-name-as-directory dirname)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
413 (dired-internal-noselect dirname switches))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
414
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
415 ;; Separate function from dired-noselect for the sake of dired-vms.el.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
416 (defun dired-internal-noselect (dirname &optional switches)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
417 ;; If there is an existing dired buffer for DIRNAME, just leave
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
418 ;; buffer as it is (don't even call dired-revert).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
419 ;; This saves time especially for deep trees or with ange-ftp.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
420 ;; The user can type `g'easily, and it is more consistent with find-file.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
421 ;; But if SWITCHES are given they are probably different from the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
422 ;; buffer's old value, so call dired-sort-other, which does
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
423 ;; revert the buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
424 ;; A pity we can't possibly do "Directory has changed - refresh? "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
425 ;; like find-file does...maybe in the GNU OS.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
426 (let* ((buffer (dired-find-buffer-nocreate dirname))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
427 ;; note that buffer already is in dired-mode, if found
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
428 (new-buffer-p (not buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
429 (old-buf (current-buffer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
430 (or buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
431 (let ((default-major-mode 'fundamental-mode))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
432 ;; We don't want default-major-mode to run hooks and set auto-fill
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
433 ;; or whatever, now that dired-mode does not
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
434 ;; kill-all-local-variables any longer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
435 (setq buffer (create-file-buffer (directory-file-name dirname)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
436 (set-buffer buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
437 (if (not new-buffer-p) ; existing buffer ...
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
438 (if switches ; ... but new switches
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
439 (dired-sort-other switches)) ; this calls dired-revert
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
440 ;; Else a new buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
441 (setq default-directory (if (file-directory-p dirname)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
442 dirname
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
443 (file-name-directory dirname)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
444 (or switches (setq switches dired-listing-switches))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
445 (dired-mode dirname switches)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
446 ;; default-directory and dired-actual-switches are set now
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
447 ;; (buffer-local), so we can call dired-readin:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
448 (let ((failed t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
449 (unwind-protect
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
450 (progn (dired-readin dirname buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
451 (setq failed nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
452 ;; dired-readin can fail if parent directories are inaccessible.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
453 ;; Don't leave an empty buffer around in that case.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
454 (if failed (kill-buffer buffer))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
455 ;; No need to narrow since the whole buffer contains just
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
456 ;; dired-readin's output, nothing else. The hook can
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
457 ;; successfully use dired functions (e.g. dired-get-filename)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
458 ;; as the subdir-alist has been built in dired-readin.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
459 (run-hooks 'dired-after-readin-hook)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
460 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
461 (dired-initial-position dirname))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
462 (set-buffer old-buf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
463 buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
464
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
465 ;; This differs from dired-buffers-for-dir in that it does not consider
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
466 ;; subdirs of default-directory and searches for the first match only
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
467 (defun dired-find-buffer-nocreate (dirname)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
468 (let (found (blist (buffer-list)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
469 (while blist
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
470 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
471 (set-buffer (car blist))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
472 (if (and (eq major-mode 'dired-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
473 (equal dired-directory dirname))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
474 (setq found (car blist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
475 blist nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
476 (setq blist (cdr blist)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
477 found))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
478
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
479
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
480 ;; Read in a new dired buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
481
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
482 ;; dired-readin differs from dired-insert-subdir in that it accepts
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
483 ;; wildcards, erases the buffer, and builds the subdir-alist anew
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
484 ;; (including making it buffer-local and clearing it first).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
485 (defun dired-readin (dirname buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
486 ;; default-directory and dired-actual-switches must be buffer-local
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
487 ;; and initialized by now.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
488 ;; Thus we can test (equal default-directory dirname) instead of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
489 ;; (file-directory-p dirname) and save a filesystem transaction.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
490 ;; Also, we can run this hook which may want to modify the switches
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
491 ;; based on default-directory, e.g. with ange-ftp to a SysV host
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
492 ;; where ls won't understand -Al switches.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
493 (setq dirname (expand-file-name dirname))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
494 (run-hooks 'dired-before-readin-hook)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
495 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
496 (message "Reading directory %s..." dirname)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
497 (set-buffer buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
498 (let (buffer-read-only)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
499 (widen)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
500 (erase-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
501 (dired-readin-insert dirname)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
502 (dired-indent-rigidly (point-min) (point-max) 2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
503 ;; We need this to make the root dir have a header line as all
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
504 ;; other subdirs have:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
505 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
506 (dired-insert-headerline default-directory)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
507 ;; can't run dired-after-readin-hook here, it may depend on the subdir
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
508 ;; alist to be OK.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
509 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
510 (message "Reading directory %s...done" dirname)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
511 (set-buffer-modified-p nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
512 ;; Must first make alist buffer local and set it to nil because
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
513 ;; dired-build-subdir-alist will call dired-clear-alist first
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
514 (set (make-local-variable 'dired-subdir-alist) nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
515 (let (case-fold-search)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
516 (if (string-match "R" dired-actual-switches)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
517 (dired-build-subdir-alist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
518 ;; no need to parse the buffer if listing is not recursive
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
519 (dired-simple-subdir-alist)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
520
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
521 ;; Subroutines of dired-readin
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
522
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
523 (defun dired-readin-insert (dirname)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
524 ;; Just insert listing for DIRNAME, assuming a clean buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
525 (let ((font-lock-mode nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
526 (if (equal default-directory dirname);; i.e., (file-directory-p dirname)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
527 (dired-ls (if (or (let (case-fold-search)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
528 (string-match "R" dired-actual-switches))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
529 (eq system-type 'vax-vms))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
530 dirname
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
531 ;; On SysV derived system, symbolic links to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
532 ;; directories are not resolved, while on BSD
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
533 ;; derived it suffices to let DIRNAME end in slash.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
534 ;; We always let it end in "/." since it does no
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
535 ;; harm on BSD and makes Dired work on such links on
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
536 ;; SysV.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
537 ;; Cannot do this with -R since "dir/./subdir"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
538 ;; headerlines would result, utterly confusing dired.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
539 (concat dirname "."))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
540 dired-actual-switches nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
541 (if (not (file-readable-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
542 (directory-file-name (file-name-directory dirname))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
543 (error "Directory %s inaccessible or nonexistent" dirname)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
544 ;; else assume it contains wildcards:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
545 (dired-ls dirname dired-actual-switches t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
546 (save-excursion;; insert wildcard instead of total line:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
547 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
548 (insert "wildcard " (file-name-nondirectory dirname) "\n"))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
549
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
550 (defun dired-insert-headerline (dir);; also used by dired-insert-subdir
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
551 ;; Insert DIR's headerline with no trailing slash, exactly like ls
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
552 ;; would, and put cursor where dired-build-subdir-alist puts subdir
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
553 ;; boundaries.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
554 (save-excursion (insert " " (directory-file-name dir) ":\n")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
555
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
556 ;; Make the file names highlight when the mouse is on them.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
557 ;; from FSF 19.30.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
558 (defun dired-insert-set-properties (beg end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
559 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
560 (goto-char beg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
561 (while (< (point) end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
562 (condition-case nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
563 (if (dired-move-to-filename)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
564 (put-text-property (point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
565 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
566 (dired-move-to-end-of-filename)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
567 (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
568 'highlight t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
569 (error nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
570 (forward-line 1))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
571
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
572
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
573 ;; Reverting a dired buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
574
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
575 (defun dired-revert (&optional arg noconfirm)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
576 ;; Reread the dired buffer. Must also be called after
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
577 ;; dired-actual-switches have changed.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
578 ;; Should not fail even on completely garbaged buffers.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
579 ;; Preserves old cursor, marks/flags, hidden-p.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
580 (widen) ; just in case user narrowed
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
581 (let ((opoint (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
582 (ofile (dired-get-filename nil t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
583 (mark-alist nil) ; save marked files
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
584 (hidden-subdirs (dired-remember-hidden))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
585 (old-subdir-alist (cdr (reverse dired-subdir-alist))) ; except pwd
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
586 case-fold-search ; we check for upper case ls flags
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
587 buffer-read-only)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
588 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
589 (setq mark-alist;; only after dired-remember-hidden since this unhides:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
590 (dired-remember-marks (point-min) (point-max)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
591 ;; treat top level dir extra (it may contain wildcards)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
592 (dired-readin dired-directory (current-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
593 (let ((dired-after-readin-hook nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
594 ;; don't run that hook for each subdir...
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
595 (dired-insert-old-subdirs old-subdir-alist))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
596 (dired-mark-remembered mark-alist) ; mark files that were marked
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
597 ;; ... run the hook for the whole buffer, and only after markers
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
598 ;; have been reinserted (else omitting in dired-x would omit marked files)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
599 (run-hooks 'dired-after-readin-hook) ; no need to narrow
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
600 (or (and ofile (dired-goto-file ofile)) ; move cursor to where it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
601 (goto-char opoint)) ; was before
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
602 (dired-move-to-filename)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
603 (save-excursion ; hide subdirs that were hidden
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
604 (mapcar (function (lambda (dir)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
605 (if (dired-goto-subdir dir)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
606 (dired-hide-subdir 1))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
607 hidden-subdirs)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
608 ;; outside of the let scope
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
609 (setq buffer-read-only t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
610
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
611 ;; Subroutines of dired-revert
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
612 ;; Some of these are also used when inserting subdirs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
613
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
614 (defun dired-remember-marks (beg end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
615 ;; Return alist of files and their marks, from BEG to END.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
616 (if selective-display ; must unhide to make this work.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
617 (let (buffer-read-only)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
618 (subst-char-in-region beg end ?\r ?\n)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
619 (let (fil chr alist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
620 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
621 (goto-char beg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
622 (while (re-search-forward dired-re-mark end t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
623 (if (setq fil (dired-get-filename nil t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
624 (setq chr (preceding-char)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
625 alist (cons (cons fil chr) alist)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
626 alist))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
627
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
628 (defun dired-mark-remembered (alist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
629 ;; Mark all files remembered in ALIST.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
630 (let (elt fil chr)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
631 (while alist
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
632 (setq elt (car alist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
633 alist (cdr alist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
634 fil (car elt)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
635 chr (cdr elt))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
636 (if (dired-goto-file fil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
637 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
638 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
639 (delete-char 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
640 (insert chr))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
641
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
642 (defun dired-remember-hidden ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
643 (let ((l dired-subdir-alist) dir result)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
644 (while l
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
645 (setq dir (car (car l))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
646 l (cdr l))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
647 (if (dired-subdir-hidden-p dir)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
648 (setq result (cons dir result))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
649 result))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
650
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
651 (defun dired-insert-old-subdirs (old-subdir-alist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
652 ;; Try to insert all subdirs that were displayed before
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
653 (or (string-match "R" dired-actual-switches)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
654 (let (elt dir)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
655 (while old-subdir-alist
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
656 (setq elt (car old-subdir-alist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
657 old-subdir-alist (cdr old-subdir-alist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
658 dir (car elt))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
659 (condition-case ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
660 (dired-insert-subdir dir)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
661 (error nil))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
662
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
663
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
664 ;; dired mode key bindings and initialization
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
665
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
666 (defvar dired-mode-map nil "Local keymap for dired-mode buffers.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
667 (if dired-mode-map
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
668 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
669 ;; Force `f' rather than `e' in the mode doc:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
670 (fset 'dired-advertised-find-file 'dired-find-file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
671 ;; This looks ugly when substitute-command-keys uses C-d instead d:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
672 ;; (define-key dired-mode-map "\C-d" 'dired-flag-file-deleted)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
673
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
674 (setq dired-mode-map (make-keymap))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
675 (suppress-keymap dired-mode-map)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
676 ;; Commands to mark certain categories of files
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
677 (define-key dired-mode-map "#" 'dired-flag-auto-save-files)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
678 (define-key dired-mode-map "*" 'dired-mark-executables)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
679 (define-key dired-mode-map "." 'dired-clean-directory)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
680 (define-key dired-mode-map "/" 'dired-mark-directories)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
681 (define-key dired-mode-map "@" 'dired-mark-symlinks)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
682 ;; Upper case keys (except !, c, r) for operating on the marked files
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
683 (define-key dired-mode-map "c" 'dired-do-copy)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
684 (define-key dired-mode-map "r" 'dired-do-move)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
685 (define-key dired-mode-map "!" 'dired-do-shell-command)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
686 (define-key dired-mode-map "B" 'dired-do-byte-compile)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
687 (define-key dired-mode-map "C" 'dired-do-compress)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
688 (define-key dired-mode-map "G" 'dired-do-chgrp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
689 (define-key dired-mode-map "H" 'dired-do-hardlink)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
690 (define-key dired-mode-map "L" 'dired-do-load)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
691 (define-key dired-mode-map "M" 'dired-do-chmod)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
692 (define-key dired-mode-map "O" 'dired-do-chown)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
693 (define-key dired-mode-map "P" 'dired-do-print)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
694 (define-key dired-mode-map "U" 'dired-do-uncompress)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
695 (define-key dired-mode-map "X" 'dired-do-delete)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
696 (define-key dired-mode-map "Y" 'dired-do-symlink)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
697 ;; exceptions to the upper key rule
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
698 (define-key dired-mode-map "D" 'dired-diff)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
699 (define-key dired-mode-map "W" 'dired-why)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
700 ;; Tree Dired commands
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
701 (define-key dired-mode-map "\M-\C-?" 'dired-unflag-all-files)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
702 (define-key dired-mode-map "\M-\C-d" 'dired-tree-down)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
703 (define-key dired-mode-map "\M-\C-u" 'dired-tree-up)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
704 (define-key dired-mode-map "\M-\C-n" 'dired-next-subdir)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
705 (define-key dired-mode-map "\M-\C-p" 'dired-prev-subdir)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
706 ;; move to marked files
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
707 (define-key dired-mode-map "\M-{" 'dired-prev-marked-file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
708 (define-key dired-mode-map "\M-}" 'dired-next-marked-file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
709 ;; kill marked files
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
710 (define-key dired-mode-map "\M-k" 'dired-do-kill)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
711 ;; Make all regexp commands share a `%' prefix:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
712 (fset 'dired-regexp-prefix (make-sparse-keymap))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
713 (define-key dired-mode-map "%" 'dired-regexp-prefix)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
714 (define-key dired-mode-map "%u" 'dired-upcase)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
715 (define-key dired-mode-map "%l" 'dired-downcase)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
716 (define-key dired-mode-map "%d" 'dired-flag-regexp-files)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
717 (define-key dired-mode-map "%m" 'dired-mark-files-regexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
718 (define-key dired-mode-map "%r" 'dired-do-rename-regexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
719 (define-key dired-mode-map "%c" 'dired-do-copy-regexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
720 (define-key dired-mode-map "%H" 'dired-do-hardlink-regexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
721 (define-key dired-mode-map "%Y" 'dired-do-symlink-regexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
722 ;; Lower keys for commands not operating on all the marked files
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
723 (define-key dired-mode-map "d" 'dired-flag-file-deleted)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
724 (define-key dired-mode-map "e" 'dired-find-file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
725 (define-key dired-mode-map "f" 'dired-advertised-find-file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
726 (define-key dired-mode-map "g" 'revert-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
727 (define-key dired-mode-map "h" 'describe-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
728 (define-key dired-mode-map "i" 'dired-maybe-insert-subdir)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
729 (define-key dired-mode-map "k" 'dired-kill-line-or-subdir)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
730 (define-key dired-mode-map "l" 'dired-do-redisplay)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
731 (define-key dired-mode-map "m" 'dired-mark-subdir-or-file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
732 (define-key dired-mode-map "n" 'dired-next-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
733 (define-key dired-mode-map "o" 'dired-find-file-other-window)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
734 (define-key dired-mode-map "p" 'dired-previous-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
735 (define-key dired-mode-map "q" 'dired-quit)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
736 (define-key dired-mode-map "s" 'dired-sort-toggle-or-edit)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
737 (define-key dired-mode-map "u" 'dired-unmark-subdir-or-file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
738 (define-key dired-mode-map "v" 'dired-view-file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
739 (define-key dired-mode-map "x" 'dired-do-deletions)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
740 (define-key dired-mode-map "~" 'dired-flag-backup-files)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
741 (define-key dired-mode-map "\M-~" 'dired-backup-diff)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
742 (define-key dired-mode-map "+" 'dired-create-directory)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
743 ;; moving
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
744 (define-key dired-mode-map "<" 'dired-prev-dirline)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
745 (define-key dired-mode-map ">" 'dired-next-dirline)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
746 (define-key dired-mode-map "^" 'dired-up-directory)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
747 (define-key dired-mode-map " " 'dired-next-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
748 (define-key dired-mode-map "\C-n" 'dired-next-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
749 (define-key dired-mode-map "\C-p" 'dired-previous-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
750 ;; hiding
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
751 (define-key dired-mode-map "$" 'dired-hide-subdir)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
752 (define-key dired-mode-map "=" 'dired-hide-all)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
753 ;; misc
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
754 (define-key dired-mode-map "?" 'dired-summary)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
755 (define-key dired-mode-map "\177" 'dired-backup-unflag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
756 (define-key dired-mode-map "\C-_" 'dired-undo)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
757 (define-key dired-mode-map "\C-xu" 'dired-undo)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
758 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
759
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
760 (or (equal (assq 'dired-sort-mode minor-mode-alist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
761 '(dired-sort-mode dired-sort-mode))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
762 ;; Test whether this has already been done in case dired is reloaded
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
763 ;; There may be several elements with dired-sort-mode as car.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
764 (setq minor-mode-alist
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
765 (cons '(dired-sort-mode dired-sort-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
766 ;; dired-sort-mode is nil outside dired
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
767 minor-mode-alist)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
768
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
769 ;; Dired mode is suitable only for specially formatted data.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
770 (put 'dired-mode 'mode-class 'special)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
771
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
772 (defun dired-mode (&optional dirname switches)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
773 "\
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
774 Mode for \"editing\" directory listings.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
775 In dired, you are \"editing\" a list of the files in a directory and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
776 \(optionally) its subdirectories, in the format of `ls -lR'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
777 Each directory is a page: use \\[backward-page] and \\[forward-page] to move pagewise.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
778 \"Editing\" means that you can run shell commands on files, visit,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
779 compress, load or byte-compile them, change their file attributes
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
780 and insert subdirectories into the same buffer. You can \"mark\"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
781 files for later commands or \"flag\" them for deletion, either file
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
782 by file or all files matching certain criteria.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
783 You can move using the usual cursor motion commands.\\<dired-mode-map>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
784 Letters no longer insert themselves. Digits are prefix arguments.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
785 Instead, type \\[dired-flag-file-deleted] to flag a file for Deletion.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
786 Type \\[dired-mark-subdir-or-file] to Mark a file or subdirectory for later commands.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
787 Most commands operate on the marked files and use the current file
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
788 if no files are marked. Use a numeric prefix argument to operate on
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
789 the next ARG (or previous -ARG if ARG<0) files, or just `1'
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
790 to operate on the current file only. Prefix arguments override marks.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
791 Mark-using commands display a list of failures afterwards. Type \\[dired-why] to see
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
792 why something went wrong.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
793 Type \\[dired-unmark-subdir-or-file] to Unmark a file or all files of a subdirectory.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
794 Type \\[dired-backup-unflag] to back up one line and unflag.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
795 Type \\[dired-do-deletions] to eXecute the deletions requested.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
796 Type \\[dired-advertised-find-file] to Find the current line's file
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
797 (or dired it in another buffer, if it is a directory).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
798 Type \\[dired-find-file-other-window] to find file or dired directory in Other window.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
799 Type \\[dired-maybe-insert-subdir] to Insert a subdirectory in this buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
800 Type \\[dired-do-move] to Rename a file or move the marked files to another directory.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
801 Type \\[dired-do-copy] to Copy files.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
802 Type \\[dired-sort-toggle-or-edit] to toggle sorting by name/date or change the ls switches.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
803 Type \\[revert-buffer] to read all currently expanded directories again.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
804 This retains all marks and hides subdirs again that were hidden before.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
805 SPC and DEL can be used to move down and up by lines.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
806
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
807 If dired ever gets confused, you can either type \\[revert-buffer] \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
808 to read the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
809 directories again, type \\[dired-do-redisplay] \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
810 to relist a single or the marked files or a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
811 subdirectory, or type \\[dired-build-subdir-alist] to parse the buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
812 again for the directory tree.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
813
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
814 Customization variables (rename this buffer and type \\[describe-variable] on each line
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
815 for more info):
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
816
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
817 dired-listing-switches
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
818 dired-trivial-filenames
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
819 dired-shrink-to-fit
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
820 dired-marker-char
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
821 dired-del-marker
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
822 dired-keep-marker-move
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
823 dired-keep-marker-copy
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
824 dired-keep-marker-hardlink
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
825 dired-keep-marker-symlink
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
826
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
827 Hooks (use \\[describe-variable] to see their documentation):
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
828
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
829 dired-before-readin-hook
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
830 dired-after-readin-hook
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
831 dired-mode-hook
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
832 dired-load-hook
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
833
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
834 Keybindings:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
835 \\{dired-mode-map}"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
836 ;; Not to be called interactively (e.g. dired-directory will be set
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
837 ;; to default-directory, which is wrong with wildcards).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
838 (kill-all-local-variables)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
839 (use-local-map dired-mode-map)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
840 (dired-advertise) ; default-directory is already set
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
841 (setq major-mode 'dired-mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
842 mode-name "Dired"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
843 case-fold-search nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
844 buffer-read-only t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
845 selective-display t ; for subdirectory hiding
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
846 modeline-buffer-identification '("Dired: %17b"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
847 (set (make-local-variable 'revert-buffer-function)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
848 (function dired-revert))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
849 (set (make-local-variable 'page-delimiter)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
850 "\n\n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
851 (set (make-local-variable 'dired-directory)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
852 (or dirname default-directory))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
853 (set (make-local-variable 'list-buffers-directory)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
854 dired-directory)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
855 (set (make-local-variable 'dired-actual-switches)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
856 (or switches dired-listing-switches))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
857 (make-local-variable 'dired-sort-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
858 (dired-sort-other dired-actual-switches t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
859 (run-hooks 'dired-mode-hook))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
860
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
861
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
862 (defun dired-check-ls-l ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
863 (let (case-fold-search)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
864 (or (string-match "l" dired-actual-switches)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
865 (error "Dired needs -l in ls switches"))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
866
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
867 (defun dired-repeat-over-lines (arg function)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
868 ;; This version skips non-file lines.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
869 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
870 (while (and (> arg 0) (not (eobp)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
871 (setq arg (1- arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
872 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
873 (while (and (not (eobp)) (dired-between-files)) (forward-line 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
874 (save-excursion (funcall function))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
875 (forward-line 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
876 (while (and (< arg 0) (not (bobp)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
877 (setq arg (1+ arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
878 (forward-line -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
879 (while (and (not (bobp)) (dired-between-files)) (forward-line -1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
880 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
881 (save-excursion (funcall function))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
882 (dired-move-to-filename))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
883 (dired-move-to-filename))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
884
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
885 (defun dired-flag-file-deleted (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
886 "In dired, flag the current line's file for deletion.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
887 With prefix arg, repeat over several lines.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
888
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
889 If on a subdir headerline, mark all its files except `.' and `..'."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
890 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
891 (let ((dired-marker-char dired-del-marker))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
892 (dired-mark-subdir-or-file arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
893
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
894 (defun dired-quit ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
895 "Bury the current dired buffer."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
896 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
897 (bury-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
898
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
899 (defun dired-summary ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
900 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
901 ;>> this should check the key-bindings and use substitute-command-keys if non-standard
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
902 (message
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
903 "d-elete, u-ndelete, x-punge, f-ind, o-ther window, r-ename, c-opy, h-elp"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
904
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
905 (defun dired-create-directory (directory)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
906 "Create a directory called DIRECTORY."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
907 (interactive
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
908 (list (read-file-name "Create directory: " (dired-current-directory))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
909 (let ((expanded (directory-file-name (expand-file-name directory))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
910 (make-directory expanded)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
911 (dired-add-file expanded)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
912 (dired-move-to-filename)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
913
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
914 (defun dired-undo ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
915 "Undo in a dired buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
916 This doesn't recover lost files, it is just normal undo with temporarily
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
917 writeable buffer. You can use it to recover marks, killed lines or subdirs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
918 In the latter case, you have to do \\[dired-build-subdir-alist] to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
919 parse the buffer again."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
920 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
921 (let (buffer-read-only)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
922 (undo)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
923
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
924 (defun dired-unflag (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
925 "In dired, remove the current line's delete flag then move to next line.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
926 Optional prefix ARG says how many lines to unflag."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
927 (interactive "p")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
928 (dired-repeat-over-lines arg
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
929 '(lambda ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
930 (let (buffer-read-only)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
931 (delete-char 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
932 (insert " ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
933 (forward-char -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
934 nil))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
935
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
936 (defun dired-backup-unflag (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
937 "In dired, move up lines and remove deletion flag there.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
938 Optional prefix ARG says how many lines to unflag; default is one line."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
939 (interactive "p")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
940 (dired-unflag (- arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
941
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
942 (defun dired-next-line (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
943 "Move down lines then position at filename.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
944 Optional prefix ARG says how many lines to move; default is one line."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
945 (interactive "_p")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
946 (next-line arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
947 (dired-move-to-filename))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
948
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
949 (defun dired-previous-line (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
950 "Move up lines then position at filename.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
951 Optional prefix ARG says how many lines to move; default is one line."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
952 (interactive "_p")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
953 (previous-line arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
954 (dired-move-to-filename))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
955
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
956 (defun dired-up-directory ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
957 "Run dired on parent directory of current directory.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
958 Find the parent directory either in this buffer or another buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
959 Creates a buffer if necessary."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
960 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
961 (let* ((dir (dired-current-directory))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
962 (up (file-name-directory (directory-file-name dir))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
963 (or (dired-goto-file (directory-file-name dir))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
964 (dired-goto-subdir up)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
965 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
966 (dired up)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
967 (dired-goto-file dir)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
968
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
969 (defun dired-find-file ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
970 "In dired, visit the file or directory named on this line."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
971 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
972 (let ((find-file-run-dired t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
973 (find-file (dired-get-filename))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
974
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
975 (defun dired-view-file ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
976 "In dired, examine a file in view mode, returning to dired when done.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
977 When file is a directory, show it in this buffer if it is inserted;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
978 otherwise, display it in another buffer."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
979 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
980 (if (file-directory-p (dired-get-filename))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
981 (or (dired-goto-subdir (dired-get-filename))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
982 (dired (dired-get-filename)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
983 (view-file (dired-get-filename))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
984
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
985 (defun dired-find-file-other-window ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
986 "In dired, visit this file or directory in another window."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
987 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
988 (let ((find-file-run-dired t)) ;; XEmacs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
989 (find-file-other-window (dired-get-filename))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
990
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
991 (defun dired-get-filename (&optional localp no-error-if-not-filep)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
992 "In dired, return name of file mentioned on this line.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
993 Value returned normally includes the directory name.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
994 Optional arg LOCALP with value `no-dir' means don't include directory
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
995 name in result. A value of t means use path name relative to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
996 `default-directory', which still may contain slashes if in a subdirectory.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
997 Optional arg NO-ERROR-IF-NOT-FILEP means return nil if no filename on
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
998 this line, otherwise an error occurs."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
999 (let (case-fold-search file p1 p2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1000 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1001 (if (setq p1 (dired-move-to-filename (not no-error-if-not-filep)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1002 (setq p2 (dired-move-to-end-of-filename no-error-if-not-filep))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1003 ;; nil if no file on this line, but no-error-if-not-filep is t:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1004 (if (setq file (and p1 p2 (buffer-substring p1 p2)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1005 ;; Check if ls quoted the names, and unquote them.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1006 ;; Using read to unquote is much faster than substituting
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1007 ;; \007 (4 chars) -> ^G (1 char) etc. in a lisp loop.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1008 (cond ((string-match "b" dired-actual-switches) ; System V ls
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1009 ;; This case is about 20% slower than without -b.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1010 (setq file
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1011 (read
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1012 (concat "\""
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1013 ;; some ls -b don't escape quotes, argh!
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1014 ;; This is not needed for GNU ls, though.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1015 (or (dired-string-replace-match
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1016 "\\([^\\]\\)\"" file "\\1\\\\\"")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1017 file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1018 "\""))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1019 ;; If you do this, update dired-insert-subdir-validate too
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1020 ;; ((string-match "Q" dired-actual-switches) ; GNU ls
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1021 ;; (setq file (read file)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1022 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1023 (if (eq localp 'no-dir)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1024 file
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1025 (and file (concat (dired-current-directory localp) file)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1026
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1027 (defun dired-move-to-filename (&optional raise-error eol)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1028 "In dired, move to first char of filename on this line.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1029 Returns position (point) or nil if no filename on this line."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1030 ;; This is the UNIX version.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1031 (or eol (setq eol (progn (end-of-line) (point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1032 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1033 (if (string-match "l" dired-actual-switches)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1034 (if (re-search-forward
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1035 "\\(Jan\\|Feb\\|Mar\\|Apr\\|May\\|Jun\\|Jul\\|Aug\\|Sep\\|Oct\\|Nov\\|Dec\\)[ ]+[0-9]+"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1036 eol t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1037 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1038 (skip-chars-forward " ") ; there is one SPC after day of month
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1039 (skip-chars-forward "^ " eol) ; move after time of day (or year)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1040 (skip-chars-forward " " eol) ; there is space before the file name
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1041 ;; Actually, if the year instead of clock time is displayed,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1042 ;; there are (only for some ls programs?) two spaces instead
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1043 ;; of one before the name.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1044 ;; If we could depend on ls inserting exactly one SPC we
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1045 ;; would not bomb on names _starting_ with SPC.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1046 (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1047 (if raise-error
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1048 (error "No file on this line")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1049 nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1050 ;; else ls switches don't contain -l.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1051 ;; Note that even if we make dired-move-to-filename and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1052 ;; dired-move-to-end-of-filename (and thus dired-get-filename)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1053 ;; work, all commands that gleaned information from the permission
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1054 ;; bits (like dired-mark-directories) will cease to work properly.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1055 (if (eolp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1056 (if raise-error
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1057 (error "No file on this line")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1058 nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1059 ;; skip marker, if any
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1060 (forward-char))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1061 (skip-chars-forward " ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1062 (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1063
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1064 (defun dired-move-to-end-of-filename (&optional no-error)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1065 ;; Assumes point is at beginning of filename,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1066 ;; thus the rwx bit re-search-backward below will succeed in *this*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1067 ;; line if at all. So, it should be called only after
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1068 ;; (dired-move-to-filename t).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1069 ;; On failure, signals an error (with non-nil NO-ERROR just returns nil).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1070 ;; This is the UNIX version.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1071 (let (opoint file-type executable symlink hidden case-fold-search used-F eol)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1072 ;; case-fold-search is nil now, so we can test for capital F:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1073 (setq used-F (string-match "F" dired-actual-switches)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1074 opoint (point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1075 eol (save-excursion (end-of-line) (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1076 hidden (and selective-display
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1077 (save-excursion (search-forward "\r" eol t))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1078 (if hidden
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1079 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1080 (save-excursion;; Find out what kind of file this is:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1081 ;; Restrict perm bits to be non-blank,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1082 ;; otherwise this matches one char to early (looking backward):
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1083 ;; "l---------" (some systems make symlinks that way)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1084 ;; "----------" (plain file with zero perms)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1085 (if (re-search-backward
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1086 "\\([^ ]\\)[-r][-w]\\([^ ]\\)[-r][-w]\\([^ ]\\)[-r][-w]\\([^ ]\\)"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1087 nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1088 (setq file-type (char-after (match-beginning 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1089 symlink (eq file-type ?l)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1090 ;; Only with -F we need to know whether it's an executable
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1091 executable (and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1092 used-F
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1093 (string-match
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1094 "[xst]";; execute bit set anywhere?
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1095 (concat
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1096 (buffer-substring (match-beginning 2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1097 (match-end 2))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1098 (buffer-substring (match-beginning 3)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1099 (match-end 3))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1100 (buffer-substring (match-beginning 4)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1101 (match-end 4))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1102 (or no-error
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1103 (not (string-match "l" dired-actual-switches))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1104 (error "No file on this line"))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1105 ;; Move point to end of name:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1106 (if symlink
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1107 (if (search-forward " ->" eol t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1108 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1109 (forward-char -3)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1110 (and used-F
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1111 dired-ls-F-marks-symlinks
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1112 (eq (preceding-char) ?@);; did ls really mark the link?
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1113 (forward-char -1))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1114 (goto-char eol);; else not a symbolic link
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1115 ;; ls -lF marks dirs, sockets and executables with exactly one
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1116 ;; trailing character. (Executable bits on symlinks ain't mean
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1117 ;; a thing, even to ls, but we know it's not a symlink.)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1118 (and used-F
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1119 ;; -F may not actually be honored, e.g. by an FTP ls in ange-ftp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1120 (let ((char (preceding-char)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1121 (or (and (eq file-type ?d) (eq char ?/))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1122 (and executable (eq char ?*))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1123 (and (eq file-type ?s) (eq char ?=))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1124 (forward-char -1))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1125 (or no-error
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1126 (not (eq opoint (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1127 (error (if hidden
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1128 (substitute-command-keys
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1129 "File line is hidden, type \\[dired-hide-subdir] to unhide")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1130 "No file on this line")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1131 (if (eq opoint (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1132 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1133 (point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1134
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1135
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1136 ;; Perhaps something could be done to handle VMS' own backups.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1137
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1138 (defun dired-clean-directory (keep)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1139 "Flag numerical backups for deletion.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1140 Spares `dired-kept-versions' latest versions, and `kept-old-versions' oldest.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1141 Positive prefix arg KEEP overrides `dired-kept-versions';
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1142 Negative prefix arg KEEP overrides `kept-old-versions' with KEEP made positive.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1143
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1144 To clear the flags on these files, you can use \\[dired-flag-backup-files]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1145 with a prefix argument."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1146 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1147 (setq keep (if keep (prefix-numeric-value keep) dired-kept-versions))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1148 (let ((early-retention (if (< keep 0) (- keep) kept-old-versions))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1149 (late-retention (if (<= keep 0) dired-kept-versions keep))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1150 (file-version-assoc-list ()))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1151 (message "Cleaning numerical backups (keeping %d late, %d old)..."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1152 late-retention early-retention)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1153 ;; Look at each file.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1154 ;; If the file has numeric backup versions,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1155 ;; put on file-version-assoc-list an element of the form
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1156 ;; (FILENAME . VERSION-NUMBER-LIST)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1157 (dired-map-dired-file-lines (function dired-collect-file-versions))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1158 ;; Sort each VERSION-NUMBER-LIST,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1159 ;; and remove the versions not to be deleted.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1160 (let ((fval file-version-assoc-list))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1161 (while fval
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1162 (let* ((sorted-v-list (cons 'q (sort (cdr (car fval)) '<)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1163 (v-count (length sorted-v-list)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1164 (if (> v-count (+ early-retention late-retention))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1165 (rplacd (nthcdr early-retention sorted-v-list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1166 (nthcdr (- v-count late-retention)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1167 sorted-v-list)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1168 (rplacd (car fval)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1169 (cdr sorted-v-list)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1170 (setq fval (cdr fval))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1171 ;; Look at each file. If it is a numeric backup file,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1172 ;; find it in a VERSION-NUMBER-LIST and maybe flag it for deletion.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1173 (dired-map-dired-file-lines (function dired-trample-file-versions))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1174 (message "Cleaning numerical backups...done")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1175
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1176 ;;; Subroutines of dired-clean-directory.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1177
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1178 (defun dired-map-dired-file-lines (fun)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1179 ;; Perform FUN with point at the end of each non-directory line.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1180 ;; FUN takes one argument, the filename (complete pathname).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1181 (dired-check-ls-l)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1182 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1183 (let (file buffer-read-only)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1184 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1185 (while (not (eobp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1186 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1187 (and (not (looking-at dired-re-dir))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1188 (not (eolp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1189 (setq file (dired-get-filename nil t)) ; nil on non-file
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1190 (progn (end-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1191 (funcall fun file))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1192 (forward-line 1)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1193
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1194 (defun dired-collect-file-versions (fn)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1195 ;; "If it looks like file FN has versions, return a list of the versions.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1196 ;;That is a list of strings which are file names.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1197 ;;The caller may want to flag some of these files for deletion."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1198 (let* ((base-versions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1199 (concat (file-name-nondirectory fn) ".~"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1200 (bv-length (length base-versions))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1201 (possibilities (file-name-all-completions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1202 base-versions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1203 (file-name-directory fn)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1204 (versions (mapcar 'backup-extract-version possibilities)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1205 (if versions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1206 (setq file-version-assoc-list (cons (cons fn versions)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1207 file-version-assoc-list)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1208
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1209 (defun dired-trample-file-versions (fn)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1210 (let* ((start-vn (string-match "\\.~[0-9]+~$" fn))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1211 base-version-list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1212 (and start-vn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1213 (setq base-version-list ; there was a base version to which
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1214 (assoc (substring fn 0 start-vn) ; this looks like a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1215 file-version-assoc-list)) ; subversion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1216 (not (memq (string-to-int (substring fn (+ 2 start-vn)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1217 base-version-list)) ; this one doesn't make the cut
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1218 (progn (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1219 (delete-char 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1220 (insert dired-del-marker)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1221
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1222
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1223 ;; Keeping Dired buffers in sync with the filesystem and with each other
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1224
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1225 (defvar dired-buffers nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1226 ;; Enlarged by dired-advertise
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1227 ;; Queried by function dired-buffers-for-dir. When this detects a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1228 ;; killed buffer, it is removed from this list.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1229 "Alist of directories and their associated dired buffers.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1230
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1231 (defun dired-buffers-for-dir (dir)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1232 ;; Return a list of buffers that dired DIR (top level or in-situ subdir).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1233 ;; The list is in reverse order of buffer creation, most recent last.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1234 ;; As a side effect, killed dired buffers for DIR are removed from
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1235 ;; dired-buffers.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1236 (setq dir (file-name-as-directory dir))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1237 (let ((alist dired-buffers) result elt)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1238 (while alist
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1239 (setq elt (car alist))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1240 (if (dired-in-this-tree dir (car elt))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1241 (let ((buf (cdr elt)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1242 (if (buffer-name buf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1243 (if (assoc dir (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1244 (set-buffer buf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1245 dired-subdir-alist))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1246 (setq result (cons buf result)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1247 ;; else buffer is killed - clean up:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1248 (setq dired-buffers (delq elt dired-buffers)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1249 (setq alist (cdr alist)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1250 result))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1251
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1252 (defun dired-advertise ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1253 ;;"Advertise in variable `dired-buffers' that we dired `default-directory'."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1254 ;; With wildcards we actually advertise too much.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1255 (if (memq (current-buffer) (dired-buffers-for-dir default-directory))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1256 t ; we have already advertised ourselves
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1257 (setq dired-buffers
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1258 (cons (cons default-directory (current-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1259 dired-buffers))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1260
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1261 (defun dired-unadvertise (dir)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1262 ;; Remove DIR from the buffer alist in variable dired-buffers.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1263 ;; This has the effect of removing any buffer whose main directory is DIR.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1264 ;; It does not affect buffers in which DIR is a subdir.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1265 ;; Removing is also done as a side-effect in dired-buffer-for-dir.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1266 (setq dired-buffers
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1267 (delq (assoc dir dired-buffers) dired-buffers)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1268
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1269 (defun dired-fun-in-all-buffers (directory fun &rest args)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1270 ;; In all buffers dired'ing DIRECTORY, run FUN with ARGS.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1271 ;; Return list of buffers where FUN succeeded (i.e., returned non-nil).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1272 (let ((buf-list (dired-buffers-for-dir directory))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1273 (obuf (current-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1274 buf success-list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1275 (while buf-list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1276 (setq buf (car buf-list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1277 buf-list (cdr buf-list))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1278 (unwind-protect
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1279 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1280 (set-buffer buf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1281 (if (apply fun args)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1282 (setq success-list (cons (buffer-name buf) success-list))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1283 (set-buffer obuf)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1284 success-list))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1285
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1286 (defun dired-add-file (filename &optional marker-char)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1287 (dired-fun-in-all-buffers
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1288 (file-name-directory filename)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1289 (function dired-add-entry) filename marker-char))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1290
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1291 (defun dired-add-entry (filename &optional marker-char)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1292 ;; Add a new entry for FILENAME, optionally marking it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1293 ;; with MARKER-CHAR (a character, else dired-marker-char is used).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1294 ;; Note that this adds the entry `out of order' if files sorted by
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1295 ;; time, etc.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1296 ;; At least this version inserts in the right subdirectory (if present).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1297 ;; And it skips "." or ".." (see `dired-trivial-filenames').
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1298 ;; Hidden subdirs are exposed if a file is added there.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1299 (setq filename (directory-file-name filename))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1300 ;; Entry is always for files, even if they happen to also be directories
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1301 (let ((opoint (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1302 (cur-dir (dired-current-directory))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1303 (directory (file-name-directory filename))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1304 reason)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1305 (setq filename (file-name-nondirectory filename)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1306 reason
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1307 (catch 'not-found
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1308 (if (string= directory cur-dir)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1309 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1310 (if (dired-subdir-hidden-p cur-dir)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1311 (dired-unhide-subdir))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1312 ;; We are already where we should be, except when
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1313 ;; point is before the subdir line or its total line.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1314 (let ((p (dired-after-subdir-garbage cur-dir)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1315 (if (< (point) p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1316 (goto-char p))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1317 ;; else try to find correct place to insert
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1318 (if (dired-goto-subdir directory)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1319 (progn;; unhide if necessary
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1320 (if (looking-at "\r");; point is at end of subdir line
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1321 (dired-unhide-subdir))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1322 ;; found - skip subdir and `total' line
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1323 ;; and uninteresting files like . and ..
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1324 ;; This better not moves into the next subdir!
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1325 (dired-goto-next-nontrivial-file))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1326 ;; not found
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1327 (throw 'not-found "Subdir not found")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1328 ;; found and point is at The Right Place:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1329 (let (buffer-read-only)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1330 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1331 (dired-add-entry-do-indentation marker-char)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1332 (dired-ls (dired-make-absolute filename directory);; don't expand `.' !
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1333 (concat dired-actual-switches "d"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1334 (forward-line -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1335 ;; We want to have the non-directory part, only:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1336 (let* ((beg (dired-move-to-filename t)) ; error for strange output
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1337 (end (dired-move-to-end-of-filename)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1338 (setq filename (buffer-substring beg end))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1339 (delete-region beg end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1340 (insert (file-name-nondirectory filename)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1341 (if dired-after-readin-hook;; the subdir-alist is not affected...
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1342 (save-excursion;; ...so we can run it right now:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1343 (save-restriction
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1344 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1345 (narrow-to-region (point) (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1346 (forward-line 1) (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1347 (run-hooks 'dired-after-readin-hook))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1348 (dired-move-to-filename))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1349 ;; return nil if all went well
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1350 nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1351 (if reason ; don't move away on failure
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1352 (goto-char opoint))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1353 (not reason))) ; return t on succes, nil else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1354
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1355 ;; This is a separate function for the sake of nested dired format.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1356 (defun dired-add-entry-do-indentation (marker-char)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1357 ;; two spaces or a marker plus a space:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1358 (insert (if marker-char
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1359 (if (integerp marker-char) marker-char dired-marker-char)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1360 ?\040)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1361 ?\040))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1362
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1363 (defun dired-after-subdir-garbage (dir)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1364 ;; Return pos of first file line of DIR, skipping header and total
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1365 ;; or wildcard lines.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1366 ;; Important: never moves into the next subdir.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1367 ;; DIR is assumed to be unhidden.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1368 ;; Will probably be redefined for VMS etc.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1369 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1370 (or (dired-goto-subdir dir) (error "This cannot happen"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1371 (forward-line 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1372 (while (and (not (eolp)) ; don't cross subdir boundary
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1373 (not (dired-move-to-filename)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1374 (forward-line 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1375 (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1376
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1377 (defun dired-remove-file (file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1378 (dired-fun-in-all-buffers
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1379 (file-name-directory file) (function dired-remove-entry) file))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1380
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1381 (defun dired-remove-entry (file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1382 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1383 (and (dired-goto-file file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1384 (let (buffer-read-only)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1385 (delete-region (progn (beginning-of-line) (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1386 (save-excursion (forward-line 1) (point)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1387
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1388 (defun dired-relist-file (file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1389 (dired-fun-in-all-buffers (file-name-directory file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1390 (function dired-relist-entry) file))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1391
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1392 (defun dired-relist-entry (file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1393 ;; Relist the line for FILE, or just add it if it did not exist.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1394 ;; FILE must be an absolute pathname.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1395 (let (buffer-read-only marker)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1396 ;; If cursor is already on FILE's line delete-region will cause
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1397 ;; save-excursion to fail because of floating makers,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1398 ;; moving point to beginning of line. Sigh.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1399 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1400 (and (dired-goto-file file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1401 (delete-region (progn (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1402 (setq marker (following-char))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1403 (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1404 (save-excursion (forward-line 1) (point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1405 (setq file (directory-file-name file))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1406 (dired-add-entry file (if (eq ?\040 marker) nil marker)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1407
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1408 (defun dired-update-file-line (file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1409 ;; Delete the current line, and insert an entry for FILE.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1410 ;; If FILE is nil, then just delete the current line.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1411 ;; Keeps any marks that may be present in column one (doing this
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1412 ;; here is faster than with dired-add-entry's optional arg).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1413 ;; Does not update other dired buffers. Use dired-relist-entry for that.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1414 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1415 (let ((char (following-char)) (opoint (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1416 (delete-region (point) (progn (forward-line 1) (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1417 (if file
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1418 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1419 (dired-add-entry file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1420 ;; Replace space by old marker without moving point.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1421 ;; Faster than goto+insdel inside a save-excursion?
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1422 (subst-char-in-region opoint (1+ opoint) ?\040 char))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1423 (dired-move-to-filename))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1424
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1425
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1426 ;; Running subprocesses, checking and logging of their errors.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1427
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1428 (defvar dired-log-buf "*Dired log*")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1429
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1430 (defun dired-why ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1431 "Pop up a buffer with error log output from Dired.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1432 A group of errors from a single command ends with a formfeed.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1433 Thus, use \\[backward-page] to find the beginning of a group of errors."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1434 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1435 (let ((obuf (current-buffer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1436 (pop-to-buffer dired-log-buf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1437 (goto-char (point-max))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1438 (recenter -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1439 (switch-to-buffer-other-window obuf)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1440
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1441 (defun dired-log (log &rest args)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1442 ;; Log a message or the contents of a buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1443 ;; If LOG is a string and there are more args, it is formatted with
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1444 ;; those ARGS. Usually the LOG string ends with a \n.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1445 ;; End each bunch of errors with (dired-log t): this inserts
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1446 ;; current time and buffer, and a \f (formfeed).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1447 (let ((obuf (current-buffer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1448 (unwind-protect ; want to move point
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1449 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1450 (set-buffer (get-buffer-create dired-log-buf))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1451 (goto-char (point-max))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1452 (let (buffer-read-only)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1453 (cond ((stringp log)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1454 (insert (if args
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1455 (apply (function format) log args)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1456 log)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1457 ((bufferp log)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1458 (insert-buffer log))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1459 ((eq t log)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1460 (insert "\n\t" (current-time-string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1461 "\tBuffer `" (buffer-name obuf) "'\n\f\n")))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1462 (set-buffer obuf))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1463
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1464 (defun dired-log-summary (log &rest args)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1465 ;; Log a summary describing a bunch of errors.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1466 (apply (function dired-log) (concat "\n" log) args)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1467 (dired-log t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1468
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1469 ;; In Emacs 19 this will return program's exit status.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1470 ;; This is a separate function so that ange-ftp can redefine it.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1471 (defun dired-call-process (program discard &rest arguments)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1472 ; "Run PROGRAM with output to current buffer unless DISCARD is t.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1473 ;Remaining arguments are strings passed as command arguments to PROGRAM."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1474 (apply 'call-process program nil (not discard) nil arguments))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1475
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1476 (defun dired-check-process-checker (exit-status)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1477 ;; In Emacs 19, EXIT-STATUS comes from (dired-)call-process
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1478 ;; Then this function should return (/= 0 exit-status)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1479 ;; In Emacs 18 the exit status is not accessible, so we
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1480 ;; do the following which is not always correct as some compress
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1481 ;; programs are verbose by default or otherwise braindamaged
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1482 (if (and dired-emacs-19-p exit-status)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1483 (/= 0 exit-status);; #### install (does it work in Emacs 19?)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1484 (/= 0 (buffer-size))) ; run in program's output buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1485 ;; If have you one of those compress programs, you might
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1486 ;; want to redefine this function to look closer at compress' output.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1487 ;; This is why it is a separate function.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1488 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1489
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1490 (defun dired-check-process (msg program &rest arguments)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1491 ; "Display MSG while running PROGRAM, and check for output.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1492 ;Remaining arguments are strings passed as command arguments to PROGRAM.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1493 ; On error as determined by dired-check-process-checker, insert output
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1494 ; in a log buffer and return the offending ARGUMENTS or PROGRAM.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1495 ; Caller can cons up a list of failed args.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1496 ;Else returns nil for success."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1497 (let (err-buffer err (dir default-directory))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1498 (message "%s..." msg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1499 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1500 ;; Get a clean buffer for error output:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1501 (setq err-buffer (get-buffer-create " *dired-check-process output*"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1502 (set-buffer err-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1503 (erase-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1504 (setq default-directory dir ; caller's default-directory
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1505 err (dired-check-process-checker
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1506 (apply (function dired-call-process) program nil arguments)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1507 (if err
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1508 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1509 (dired-log (concat program " " (prin1-to-string arguments) "\n"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1510 (dired-log err-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1511 (or arguments program t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1512 (kill-buffer err-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1513 (message "%s...done" msg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1514 nil))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1515
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1516 ;;; 7K
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1517 ;;;###begin dired-cmd.el
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1518 ;; Diffing and compressing
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1519
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1520 (defun dired-diff (file &optional switches)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1521 "Compare file at point with file FILE using `diff'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1522 FILE defaults to the file at the mark.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1523 The prompted-for file is the first file given to `diff'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1524 Prefix arg lets you edit the diff switches. See the command `diff'."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1525 (interactive
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1526 (let ((default (if (mark)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1527 (save-excursion (goto-char (mark))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1528 (dired-get-filename t t)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1529 (list (read-file-name (format "Diff %s with: %s"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1530 (dired-get-filename t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1531 (if default
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1532 (concat "(default " default ") ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1533 ""))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1534 (dired-current-directory) default t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1535 (if (fboundp 'diff-read-switches)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1536 (diff-read-switches "Options for diff: ")))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1537 (if switches ; Emacs 19's diff has but two
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1538 (diff file (dired-get-filename t) switches) ; args (yet ;-)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1539 (diff file (dired-get-filename t))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1540
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1541 (defun dired-backup-diff (&optional switches)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1542 "Diff this file with its backup file or vice versa.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1543 Uses the latest backup, if there are several numerical backups.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1544 If this file is a backup, diff it with its original.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1545 The backup file is the first file given to `diff'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1546 Prefix arg lets you edit the diff switches. See the command `diff'."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1547 (interactive (list (if (fboundp 'diff-read-switches)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1548 (diff-read-switches "Diff with switches: "))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1549 (let (bak ori (file (dired-get-filename)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1550 (if (backup-file-name-p file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1551 (setq bak file
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1552 ori (file-name-sans-versions file))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1553 (setq bak (or (latest-backup-file file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1554 (error "No backup found for %s" file))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1555 ori file))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1556 (if switches
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1557 (diff bak ori switches)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1558 (diff bak ori))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1559
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1560 ;;#### install (move this function into files.el)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1561 (defun latest-backup-file (fn) ; actually belongs into files.el
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1562 "Return the latest existing backup of FILE, or nil."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1563 ;; First try simple backup, then the highest numbered of the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1564 ;; numbered backups.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1565 ;; Ignore the value of version-control because we look for existing
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1566 ;; backups, which maybe were made earlier or by another user with
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1567 ;; a different value of version-control.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1568 (setq fn (expand-file-name fn))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1569 (or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1570 (let ((bak (make-backup-file-name fn)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1571 (if (file-exists-p bak) bak))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1572 (let* ((dir (file-name-directory fn))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1573 (base-versions (concat (file-name-nondirectory fn) ".~"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1574 (bv-length (length base-versions)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1575 (concat dir
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1576 (car (sort
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1577 (file-name-all-completions base-versions dir)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1578 ;; bv-length is a fluid var for backup-extract-version:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1579 (function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1580 (lambda (fn1 fn2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1581 (> (backup-extract-version fn1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1582 (backup-extract-version fn2))))))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1583
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1584 ;; This is a separate function for the sake of ange-ftp.el
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1585 (defun dired-compress-make-compressed-filename (from-file &optional reverse)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1586 ;; "Converts a filename FROM-FILE to the filename of the associated
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1587 ;; compressed file. With an optional argument REVERSE, the reverse
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1588 ;; conversion is done."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1589
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1590 (if reverse
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1591
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1592 ;; uncompress...
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1593 ;; return `nil' if no match found -- better than nothing
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1594 (let (case-fold-search ; case-sensitive search
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1595 (string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1596 (concat "\\.\\(g?z\\|" (regexp-quote dired-gzip-file-extension)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1597 "$\\|Z\\)$")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1598
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1599 (and (string-match string from-file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1600 (substring from-file 0 (match-beginning 0))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1601
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1602 ;; compress...
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1603 ;; note: it could be that `gz' is not the proper extension for gzip
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1604 (concat from-file
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1605 (if dired-use-gzip-instead-of-compress
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1606 dired-gzip-file-extension ".Z"))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1607
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1608
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1609 (defun dired-compress ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1610 ;; Compress current file. Return nil for success, offending filename else.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1611 (dired-check-ls-l)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1612 (let* (buffer-read-only
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1613 (from-file (dired-get-filename))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1614 (to-file (dired-compress-make-compressed-filename from-file)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1615 (cond ((save-excursion (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1616 (looking-at dired-re-sym))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1617 (dired-log (concat "Attempt to compress a symbolic link:\n"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1618 from-file))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1619 (dired-make-relative from-file))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1620 (
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1621
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1622 (if dired-use-gzip-instead-of-compress
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1623 ;; gzip (GNU zip)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1624 ;; use `-q' (quiet) switch for gzip in case GZIP environment
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1625 ;; variable contains `--verbose' - lrd - Feb 18, 1993
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1626 (dired-check-process (concat "Gzip'ing " from-file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1627 "gzip" "--quiet" "--force" "--suffix"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1628 dired-gzip-file-extension from-file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1629
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1630 (dired-check-process (concat "Compressing " from-file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1631 "compress" "-f" from-file))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1632 ;; errors from the process are already logged by dired-check-process
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1633 (dired-make-relative from-file))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1634 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1635 (dired-update-file-line to-file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1636 nil))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1637
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1638 (defun dired-uncompress ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1639 ;; Uncompress current file. Return nil for success, offending filename else.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1640 (let* (buffer-read-only
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1641 (from-file (dired-get-filename))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1642 (to-file (dired-compress-make-compressed-filename from-file t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1643 (if
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1644 (if dired-use-gzip-instead-of-compress
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1645 ;; gzip (GNU zip)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1646 ;; use `-q' (quiet) switch for gzip in case GZIP environment
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1647 ;; variable contains `--verbose' - lrd - Feb 18, 1993
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1648 (dired-check-process (concat "Gunzip'ing " from-file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1649 "gzip" "--decompress" "--quiet" "--suffix"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1650 dired-gzip-file-extension from-file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1651
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1652 (dired-check-process (concat "Uncompressing " from-file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1653 "uncompress" from-file))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1654
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1655 (dired-make-relative from-file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1656 (dired-update-file-line to-file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1657 nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1658
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1659 (defun dired-mark-map-check (fun arg op-symbol &optional show-progress)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1660 ; "Map FUN over marked files (with second ARG like in dired-mark-map)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1661 ; and display failures.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1662
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1663 ; FUN takes zero args. It returns non-nil (the offending object, e.g.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1664 ; the short form of the filename) for a failure and probably logs a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1665 ; detailed error explanation using function `dired-log'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1666
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1667 ; OP-SYMBOL is a symbol describing the operation performed (e.g.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1668 ; `compress'). It is used with `dired-mark-pop-up' to prompt the user
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1669 ; (e.g. with `Compress * [2 files]? ') and to display errors (e.g.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1670 ; `Failed to compress 1 of 2 files - type W to see why ("foo")')
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1671
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1672 ; SHOW-PROGRESS if non-nil means redisplay dired after each file."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1673 (if (dired-mark-confirm op-symbol arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1674 (let* ((total-list;; all of FUN's return values
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1675 (dired-mark-map (funcall fun) arg show-progress))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1676 (total (length total-list))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1677 (failures (delq nil total-list))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1678 (count (length failures)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1679 (if (not failures)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1680 (message "%s: %d file%s."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1681 (capitalize (symbol-name op-symbol))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1682 total (dired-plural-s total))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1683 (message "Failed to %s %d of %d file%s - type W to see why %s"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1684 (symbol-name op-symbol) count total (dired-plural-s total)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1685 ;; this gives a short list of failed files in parens
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1686 ;; which may be sufficient for the user even
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1687 ;; without typing `W' for the process' diagnostics
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1688 failures)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1689 ;; end this bunch of errors:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1690 (dired-log-summary
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1691 "Failed to %s %d of %d file%s"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1692 (symbol-name op-symbol) count total (dired-plural-s total))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1693
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1694 (defun dired-do-compress (&optional arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1695 "Compress marked (or next ARG) files.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1696 Type \\[dired-do-uncompress] to uncompress again."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1697 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1698 (dired-mark-map-check (function dired-compress) arg 'compress t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1699
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1700 (defun dired-do-uncompress (&optional arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1701 "Uncompress marked (or next ARG) files."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1702 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1703 (dired-mark-map-check (function dired-uncompress) arg 'uncompress t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1704
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1705 ;; Commands for Emacs Lisp files - load and byte compile
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1706
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1707 (defun dired-byte-compile ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1708 ;; Return nil for success, offending file name else.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1709 (let* ((filename (dired-get-filename))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1710 (elc-file
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1711 (if (eq system-type 'vax-vms)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1712 (concat (substring filename 0 (string-match ";" filename)) "c")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1713 (concat filename "c")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1714 buffer-read-only failure)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1715 (condition-case err
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1716 (save-excursion (byte-compile-file filename))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1717 (error
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1718 (setq failure err)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1719 (if failure
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1720 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1721 (dired-log "Byte compile error for %s:\n%s\n" filename failure)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1722 (dired-make-relative filename))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1723 (dired-remove-file elc-file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1724 (forward-line) ; insert .elc after its .el file
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1725 (dired-add-file elc-file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1726 nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1727
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1728 (defun dired-do-byte-compile (&optional arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1729 "Byte compile marked (or next ARG) Emacs lisp files."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1730 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1731 (dired-mark-map-check (function dired-byte-compile) arg 'byte-compile t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1732
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1733 (defun dired-load ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1734 ;; Return nil for success, offending file name else.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1735 (let ((file (dired-get-filename)) failure)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1736 (condition-case err
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1737 (load file nil nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1738 (error (setq failure err)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1739 (if (not failure)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1740 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1741 (dired-log "Load error for %s:\n%s\n" file failure)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1742 (dired-make-relative file))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1743
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1744 (defun dired-do-load (&optional arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1745 "Load the marked (or next ARG) Emacs lisp files."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1746 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1747 (dired-mark-map-check (function dired-load) arg 'load t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1748
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1749 (defun dired-do-chxxx (attribute-name program op-symbol arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1750 ;; Change file attributes (mode, group, owner) of marked files and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1751 ;; refresh their file lines.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1752 ;; ATTRIBUTE-NAME is a string describing the attribute to the user.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1753 ;; PROGRAM is the program used to change the attribute.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1754 ;; OP-SYMBOL is the type of operation (for use in dired-mark-pop-up).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1755 ;; ARG describes which files to use, like in dired-mark-get-files.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1756 (let* ((files (dired-mark-get-files t arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1757 (new-attribute
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1758 (dired-mark-read-string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1759 (concat "Change " attribute-name " of %s to: ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1760 nil op-symbol arg files))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1761 (operation (concat program " " new-attribute))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1762 (failure (apply (function dired-check-process)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1763 operation program new-attribute
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1764 files)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1765 (dired-do-redisplay arg);; moves point if ARG is an integer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1766 (if failure
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1767 (dired-log-summary
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1768 (message "%s: error - type W to see why." operation)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1769
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1770 (defun dired-do-chmod (&optional arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1771 "Change the mode of the marked (or next ARG) files.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1772 This calls chmod, thus symbolic modes like `g+w' are allowed."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1773 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1774 (dired-do-chxxx "Mode" "chmod" 'chmod arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1775
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1776 (defun dired-do-chgrp (&optional arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1777 "Change the group of the marked (or next ARG) files."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1778 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1779 (dired-do-chxxx "Group" "chgrp" 'chgrp arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1780
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1781 (defun dired-do-chown (&optional arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1782 "Change the owner of the marked (or next ARG) files."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1783 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1784 (dired-do-chxxx "Owner" dired-chown-program 'chown arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1785
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1786 ;;;###end dired-cmd.el
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1787
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1788
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1789 ;; Deleting files
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1790
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1791 ;; #### called dired-do-flagged-delete in FSF
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1792 (defun dired-do-deletions (&optional nomessage)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1793 "In dired, delete the files flagged for deletion.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1794 If NOMESSAGE is non-nil, we don't display any message
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1795 if there are no flagged files."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1796 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1797 (let* ((dired-marker-char dired-del-marker)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1798 (regexp (dired-marker-regexp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1799 case-fold-search)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1800 (if (save-excursion (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1801 (re-search-forward regexp nil t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1802 (dired-internal-do-deletions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1803 ;; this can't move point since ARG is nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1804 (dired-mark-map (cons (dired-get-filename) (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1805 nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1806 nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1807 (or nomessage
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1808 (message "(No deletions requested)")))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1809
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1810 (defun dired-do-delete (&optional arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1811 "Delete all marked (or next ARG) files."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1812 ;; This is more consistent with the file marking feature than
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1813 ;; dired-do-deletions.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1814 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1815 (dired-internal-do-deletions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1816 ;; this may move point if ARG is an integer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1817 (dired-mark-map (cons (dired-get-filename) (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1818 arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1819 arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1820
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1821 (defvar dired-deletion-confirmer 'yes-or-no-p) ; or y-or-n-p?
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1822
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1823 (defun dired-internal-do-deletions (l arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1824 ;; L is an alist of files to delete, with their buffer positions.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1825 ;; ARG is the prefix arg.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1826 ;; Filenames are absolute (VMS needs this for logical search paths).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1827 ;; (car L) *must* be the *last* (bottommost) file in the dired buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1828 ;; That way as changes are made in the buffer they do not shift the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1829 ;; lines still to be changed, so the (point) values in L stay valid.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1830 ;; Also, for subdirs in natural order, a subdir's files are deleted
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1831 ;; before the subdir itself - the other way around would not work.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1832 (let ((files (mapcar (function car) l))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1833 (count (length l))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1834 (succ 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1835 ;; canonicalize file list for pop up
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1836 (setq files (nreverse (mapcar (function dired-make-relative) files)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1837 (if (dired-mark-pop-up
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1838 " *Deletions*" 'delete files dired-deletion-confirmer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1839 (format "Delete %s " (dired-mark-prompt arg files)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1840 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1841 (let (failures);; files better be in reverse order for this loop!
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1842 (while l
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1843 (goto-char (cdr (car l)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1844 (let (buffer-read-only)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1845 (condition-case err
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1846 (let ((fn (car (car l))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1847 ;; This test is equivalent to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1848 ;; (and (file-directory-p fn) (not (file-symlink-p fn)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1849 ;; but more efficient
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1850 (if (eq t (car (file-attributes fn)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1851 (remove-directory fn)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1852 (delete-file fn))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1853 ;; if we get here, removing worked
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1854 (setq succ (1+ succ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1855 (message "%s of %s deletions" succ count)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1856 (delete-region (progn (beginning-of-line) (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1857 (progn (forward-line 1) (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1858 (dired-clean-up-after-deletion fn))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1859 (error;; catch errors from failed deletions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1860 (dired-log "%s\n" err)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1861 (setq failures (cons (car (car l)) failures)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1862 (setq l (cdr l)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1863 (if (not failures)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1864 (message "%d deletion%s done" count (dired-plural-s count))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1865 (dired-log-summary
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1866 (message "%d of %d deletion%s failed: %s"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1867 (length failures) count
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1868 (dired-plural-s count)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1869 (prin1-to-string failures))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1870 (message "(No deletions performed)")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1871 (dired-move-to-filename))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1872
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1873 ;; This is a separate function for the sake of dired-x.el.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1874 (defun dired-clean-up-after-deletion (fn)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1875 ;; Clean up after a deleted file or directory FN.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1876 (save-excursion (and (dired-goto-subdir fn)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1877 (dired-kill-subdir))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1878
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1879
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1880 (defun dired-replace-in-string (regexp newtext string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1881 ;; Replace REGEXP with NEWTEXT everywhere in STRING and return result.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1882 ;; NEWTEXT is taken literally---no \\DIGIT escapes will be recognized.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1883 (let ((result "") (start 0) mb me)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1884 (while (string-match regexp string start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1885 (setq mb (match-beginning 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1886 me (match-end 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1887 result (concat result (substring string start mb) newtext)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1888 start me))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1889 (concat result (substring string start))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1890
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1891 (defun dired-next-dirline (arg &optional opoint)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1892 "Goto ARG'th next directory file line."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1893 (interactive "_p")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1894 (dired-check-ls-l)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1895 (or opoint (setq opoint (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1896 (if (if (> arg 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1897 (re-search-forward dired-re-dir nil t arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1898 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1899 (re-search-backward dired-re-dir nil t (- arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1900 (dired-move-to-filename) ; user may type `i' or `f'
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1901 (goto-char opoint)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1902 (error "No more subdirectories")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1903
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1904 (defun dired-prev-dirline (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1905 "Goto ARG'th previous directory file line."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1906 (interactive "_p")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1907 (dired-next-dirline (- arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1908
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1909 (defun dired-unflag-all-files (flag &optional arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1910 "Remove a specific or all flags from every file.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1911 With an arg, queries for each marked file.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1912 Type \\[help-command] at that time for help."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1913 (interactive "sRemove flag: (default: all flags) \nP")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1914 (let ((count 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1915 (re (if (zerop (length flag)) dired-re-mark
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1916 (concat "^" (regexp-quote flag)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1917 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1918 (let (buffer-read-only case-fold-search query
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1919 (help-form "\
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1920 Type SPC or `y' to unflag one file, DEL or `n' to skip to next,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1921 `!' to unflag all remaining files with no more questions."))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1922 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1923 (while (re-search-forward re nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1924 (if (or (not arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1925 (dired-query 'query "Unflag file `%s' ? "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1926 (dired-get-filename t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1927 (progn (delete-char -1) (insert " ") (setq count (1+ count))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1928 (forward-line 1))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1929 (message "%s" (format "Flags removed: %d %s" count flag) )))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1930
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1931 ;; pop ups and user input for file marking
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1932
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1933 (defun dired-marker-regexp ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1934 (concat "^" (regexp-quote (char-to-string dired-marker-char))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1935
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1936 (defun dired-plural-s (count)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1937 (if (= 1 count) "" "s"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1938
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1939 (defun dired-mark-prompt (arg files)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1940 ;; Return a string for use in a prompt, either the current file
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1941 ;; name, or the marker and a count of marked files.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1942 (let ((count (length files)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1943 (if (= count 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1944 (car files)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1945 ;; more than 1 file:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1946 (if (integerp arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1947 ;; abs(arg) = count
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1948 ;; Perhaps this is nicer, but it also takes more screen space:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1949 ;;(format "[%s %d files]" (if (> arg 0) "next" "previous")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1950 ;; count)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1951 (format "[next %d files]" arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1952 (format "%c [%d files]" dired-marker-char count)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1953
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1954 (defvar dired-query-alist
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1955 '((?\y . y) (?\040 . y) ; `y' or SPC means accept once
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1956 (?n . n) (?\177 . n) ; `n' or DEL skips once
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1957 (?! . yes) ; `!' accepts rest
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1958 (?q. no) (?\e . no) ; `q' or ESC skips rest
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1959 ;; None of these keys quit - use C-g for that.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1960 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1961
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1962 (defun dired-query (qs-var qs-prompt &rest qs-args)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1963 ;; Query user and return nil or t.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1964 ;; Store answer in symbol VAR (which must initially be bound to nil).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1965 ;; Format PROMPT with ARGS.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1966 ;; Binding variable help-form will help the user who types C-h.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1967 (let* ((char (symbol-value qs-var))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1968 (action (cdr (assoc char dired-query-alist))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1969 (cond ((eq 'yes action)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1970 t) ; accept, and don't ask again
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1971 ((eq 'no action)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1972 nil) ; skip, and don't ask again
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1973 (t;; no lasting effects from last time we asked - ask now
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1974 (let ((qprompt (concat qs-prompt
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1975 (if help-form
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1976 (format " [Type yn!q or %s] "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1977 (key-description
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1978 (char-to-string help-char)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1979 " [Type y, n, q or !] ")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1980 result elt)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1981 ;; Actually it looks nicer without cursor-in-echo-area - you can
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1982 ;; look at the dired buffer instead of at the prompt to decide.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1983 (apply 'message qprompt qs-args)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1984 (setq char (set qs-var (read-char)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1985 (while (not (setq elt (assoc char dired-query-alist)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1986 (message "Invalid char - type %c for help." help-char)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1987 (ding)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1988 (sit-for 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1989 (apply 'message qprompt qs-args)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1990 (setq char (set qs-var (read-char))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1991 (memq (cdr elt) '(t y yes)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1992
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1993 (defun dired-pop-to-buffer (buf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1994 ;; Pop up buffer BUF.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1995 ;; If dired-shrink-to-fit is t, make its window fit its contents.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1996 (if (not dired-shrink-to-fit)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1997 (pop-to-buffer (get-buffer-create buf))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1998 ;; let window shrink to fit:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1999 (let ((window (selected-window))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2000 target-lines w2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2001 (cond ;; if split-window-threshold is enabled, use the largest window
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2002 ((and (> (window-height (setq w2 (get-largest-window)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2003 split-height-threshold)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2004 (= (screen-width) (window-width w2)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2005 (setq window w2))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2006 ;; if the least-recently-used window is big enough, use it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2007 ((and (> (window-height (setq w2 (get-lru-window)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2008 (* 2 window-min-height))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2009 (= (screen-width) (window-width w2)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2010 (setq window w2)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2011 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2012 (set-buffer buf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2013 (goto-char (point-max))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2014 (skip-chars-backward "\n\r\t ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2015 (setq target-lines (count-lines (point-min) (point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2016 (if (<= (window-height window) (* 2 window-min-height))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2017 ;; At this point, every window on the screen is too small to split.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2018 (setq w2 (display-buffer buf))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2019 (setq w2 (split-window window
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2020 (max window-min-height
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2021 (- (window-height window)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2022 (1+ (max window-min-height target-lines)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2023 (set-window-buffer w2 buf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2024 (if (< (1- (window-height w2)) target-lines)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2025 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2026 (select-window w2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2027 (enlarge-window (- target-lines (1- (window-height w2))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2028 (set-window-start w2 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2029 )))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2030
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2031 (defvar dired-no-confirm nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2032 ;; "If non-nil, list of symbols for commands dired should not confirm.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2033 ;;It can be a sublist of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2034 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2035 ;; '(byte-compile chgrp chmod chown compress copy delete hardlink load
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2036 ;; move print shell symlink uncompress)"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2037 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2038
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2039 (defun dired-mark-confirm (op-symbol arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2040 ;; Request confirmation from the user that the operation described
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2041 ;; by OP-SYMBOL is to be performed on the marked files.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2042 ;; Confirmation consists in a y-or-n question with a file list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2043 ;; pop-up unless OP-SYMBOL is a member of `dired-no-confirm'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2044 ;; The files used are determined by ARG (like in dired-mark-get-files).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2045 (or (memq op-symbol dired-no-confirm)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2046 (let ((files (dired-mark-get-files t arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2047 (dired-mark-pop-up nil op-symbol files (function y-or-n-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2048 (concat (capitalize (symbol-name op-symbol)) " "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2049 (dired-mark-prompt arg files) "? ")))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2050
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2051 (defun dired-mark-pop-up (bufname op-symbol files function &rest args)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2052 ;;"Args BUFNAME OP-SYMBOL FILES FUNCTION &rest ARGS.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2053 ;;Return FUNCTION's result on ARGS after popping up a window (in a buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2054 ;;named BUFNAME, nil gives \" *Marked Files*\") showing the marked
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2055 ;;files. Uses function `dired-pop-to-buffer' to do that.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2056 ;; FUNCTION should not manipulate files.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2057 ;; It should only read input (an argument or confirmation).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2058 ;;The window is not shown if there is just one file or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2059 ;; OP-SYMBOL is a member of the list in `dired-no-confirm'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2060 ;;FILES is the list of marked files."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2061 (or bufname (setq bufname " *Marked Files*"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2062 (if (or (memq op-symbol dired-no-confirm)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2063 (= (length files) 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2064 (apply function args)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2065 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2066 (set-buffer (get-buffer-create bufname))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2067 (erase-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2068 (dired-format-columns-of-files files))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2069 (save-window-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2070 (dired-pop-to-buffer bufname)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2071 (apply function args))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2072
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2073 (defun dired-format-columns-of-files (files)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2074 ;; Files should be in forward order for this loop.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2075 ;; i.e., (car files) = first file in buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2076 ;; Returns the number of lines used.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2077 (let* ((maxlen (+ 2 (apply 'max (mapcar 'length files))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2078 (width (- (window-width (selected-window)) 2))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2079 (columns (max 1 (/ width maxlen)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2080 (nfiles (length files))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2081 (rows (+ (/ nfiles columns)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2082 (if (zerop (% nfiles columns)) 0 1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2083 (i 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2084 (j 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2085 (setq files (nconc (copy-sequence files) ; fill up with empty fns
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2086 (make-list (- (* columns rows) nfiles) "")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2087 (setcdr (nthcdr (1- (length files)) files) files) ; make circular
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2088 (while (< j rows)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2089 (while (< i columns)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2090 (indent-to (* i maxlen))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2091 (insert (car files))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2092 (setq files (nthcdr rows files)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2093 i (1+ i)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2094 (insert "\n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2095 (setq i 0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2096 j (1+ j)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2097 files (cdr files)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2098 rows))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2099
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2100 ;; Read arguments for a mark command of type OP-SYMBOL,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2101 ;; perhaps popping up the list of marked files.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2102 ;; ARG is the prefix arg and indicates whether the files came from
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2103 ;; marks (ARG=nil) or a repeat factor (integerp ARG).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2104 ;; If the current file was used, the list has but one element and ARG
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2105 ;; does not matter. (It is non-nil, non-integer in that case, namely '(4)).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2106
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2107 (defun dired-mark-read-string (prompt initial op-symbol arg files)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2108 ;; PROMPT for a string, with INITIAL input.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2109 ;; Other args are used to give user feedback and pop-up:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2110 ;; OP-SYMBOL of command, prefix ARG, marked FILES.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2111 (dired-mark-pop-up
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2112 nil op-symbol files
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2113 (function read-string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2114 (format prompt (dired-mark-prompt arg files)) initial))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2115
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2116 (defun dired-mark-read-file-name (prompt dir op-symbol arg files)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2117 (dired-mark-pop-up
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2118 nil op-symbol files
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2119 (function read-file-name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2120 (format prompt (dired-mark-prompt arg files)) dir))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2121
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2122 (defun dired-mark-file (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2123 "In dired, mark the current line's file for later commands.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2124 With arg, repeat over several lines.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2125 Use \\[dired-unflag-all-files] to remove all flags."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2126 (interactive "p")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2127 (let (buffer-read-only)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2128 (dired-repeat-over-lines
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2129 arg
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2130 (function (lambda () (delete-char 1) (insert dired-marker-char))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2131
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2132 (defun dired-next-marked-file (arg &optional wrap opoint)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2133 "Move to the next marked file, wrapping around the end of the buffer."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2134 (interactive "_p\np")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2135 (or opoint (setq opoint (point)));; return to where interactively started
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2136 (if (if (> arg 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2137 (re-search-forward dired-re-mark nil t arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2138 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2139 (re-search-backward dired-re-mark nil t (- arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2140 (dired-move-to-filename)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2141 (if (null wrap)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2142 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2143 (goto-char opoint)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2144 (error "No next marked file"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2145 (message "(Wraparound for next marked file)")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2146 (goto-char (if (> arg 0) (point-min) (point-max)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2147 (dired-next-marked-file arg nil opoint))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2148
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2149 (defun dired-prev-marked-file (arg &optional wrap)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2150 "Move to the previous marked file, wrapping around the end of the buffer."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2151 (interactive "_p\np")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2152 (dired-next-marked-file (- arg) wrap))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2153
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2154 (defun dired-file-marker (file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2155 ;; Return FILE's marker, or nil if unmarked.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2156 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2157 (and (dired-goto-file file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2158 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2159 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2160 (if (not (equal ?\040 (following-char)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2161 (following-char))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2162
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2163 (defun dired-read-regexp (prompt &optional initial)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2164 ;; This is an extra function so that gmhist can redefine it.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2165 (setq dired-flagging-regexp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2166 (read-string prompt (or initial dired-flagging-regexp))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2167
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2168 (defun dired-mark-files-regexp (regexp &optional marker-char)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2169 "Mark all files matching REGEXP for use in later commands.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2170 A prefix argument means to unmark them instead.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2171 `.' and `..' are never marked.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2172
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2173 REGEXP is an Emacs regexp, not a shell wildcard. Thus, use `\\.o$' for
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2174 object files--just `.o' will mark more than you might think."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2175 (interactive
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2176 (list (dired-read-regexp (concat (if current-prefix-arg "Unmark" "Mark")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2177 " files (regexp): "))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2178 (if current-prefix-arg ?\040)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2179 (let ((dired-marker-char (or marker-char dired-marker-char)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2180 (dired-mark-if
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2181 (and (not (looking-at dired-re-dot))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2182 (not (eolp)) ; empty line
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2183 (let ((fn (dired-get-filename nil t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2184 (and fn (string-match regexp (file-name-nondirectory fn)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2185 "matching file")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2186
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2187 (defun dired-flag-regexp-files (regexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2188 "In dired, flag all files containing the specified REGEXP for deletion.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2189 The match is against the non-directory part of the filename. Use `^'
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2190 and `$' to anchor matches. Exclude subdirs by hiding them.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2191 `.' and `..' are never flagged."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2192 (interactive (list (dired-read-regexp "Flag for deletion (regexp): ")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2193 (dired-mark-files-regexp regexp dired-del-marker))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2194
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2195 (defun dired-mark-symlinks (unflag-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2196 "Mark all symbolic links.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2197 With prefix argument, unflag all those files."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2198 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2199 (dired-check-ls-l)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2200 (let ((dired-marker-char (if unflag-p ?\040 dired-marker-char)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2201 (dired-mark-if (looking-at dired-re-sym) "symbolic link")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2202
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2203 (defun dired-mark-directories (unflag-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2204 "Mark all directory file lines except `.' and `..'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2205 With prefix argument, unflag all those files."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2206 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2207 (dired-check-ls-l)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2208 (let ((dired-marker-char (if unflag-p ?\040 dired-marker-char)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2209 (dired-mark-if (and (looking-at dired-re-dir)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2210 (not (looking-at dired-re-dot)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2211 "directory file")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2212
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2213 (defun dired-mark-executables (unflag-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2214 "Mark all executable files.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2215 With prefix argument, unflag all those files."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2216 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2217 (dired-check-ls-l)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2218 (let ((dired-marker-char (if unflag-p ?\040 dired-marker-char)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2219 (dired-mark-if (looking-at dired-re-exe) "executable file")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2220
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2221 ;; dired-x.el has a dired-mark-sexp interactive command: mark
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2222 ;; files for which PREDICATE returns non-nil.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2223
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2224 (defun dired-flag-auto-save-files (&optional unflag-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2225 "Flag for deletion files whose names suggest they are auto save files.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2226 A prefix argument says to unflag those files instead."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2227 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2228 (dired-check-ls-l)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2229 (let ((dired-marker-char (if unflag-p ?\040 dired-del-marker)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2230 (dired-mark-if
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2231 (and (not (looking-at dired-re-dir))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2232 (let ((fn (dired-get-filename t t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2233 (if fn (auto-save-file-name-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2234 (file-name-nondirectory fn)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2235 "auto save file")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2236
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2237 (defun dired-flag-backup-files (&optional unflag-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2238 "Flag all backup files (names ending with `~') for deletion.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2239 With prefix argument, unflag these files."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2240 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2241 (dired-check-ls-l)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2242 (let ((dired-marker-char (if unflag-p ?\040 dired-del-marker)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2243 (dired-mark-if
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2244 (and (not (looking-at dired-re-dir))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2245 (let ((fn (dired-get-filename t t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2246 (if fn (backup-file-name-p fn))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2247 "backup file")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2248
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2249
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2250 ;;; Shell commands
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2251 ;;#### install (move this function into simple.el)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2252 (defun shell-quote (filename) ; actually belongs into simple.el
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2253 "Quote a file name for inferior shell (see variable shell-file-name)."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2254 ;; Quote everything except POSIX filename characters.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2255 ;; This should be safe enough even for really wierd shells.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2256 (let ((result "") (start 0) end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2257 (while (string-match "[^---0-9a-zA-Z_./]" filename start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2258 (setq end (match-beginning 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2259 result (concat result (substring filename start end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2260 "\\" (substring filename end (1+ end)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2261 start (1+ end)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2262 (concat result (substring filename start))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2263
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2264 (defun dired-read-shell-command (prompt arg files)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2265 ;; "Read a dired shell command prompting with PROMPT (using read-string).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2266 ;;ARG is the prefix arg and may be used to indicate in the prompt which
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2267 ;; files are affected.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2268 ;;This is an extra function so that you can redefine it, e.g., to use gmhist."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2269 (dired-mark-pop-up
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2270 nil 'shell files
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2271 (function read-string) (format prompt (dired-mark-prompt arg files))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2272
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2273 ;; The in-background argument is only needed in Emacs 18 where
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2274 ;; shell-command doesn't understand an appended ampersand `&'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2275 (defun dired-do-shell-command (&optional arg in-background)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2276 "Run a shell command on the marked files.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2277 If there is output, it goes to a separate buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2278 The list of marked files is appended to the command string unless asterisks
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2279 `*' indicate the place(s) where the list should go.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2280 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
2281 next ARG files. As always, a raw arg (\\[universal-argument]) means the current file.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2282 The prompt mentions the file(s) or the marker, as appropriate.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2283 With a zero argument, run command on each marked file separately: `cmd *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2284 foo' results in `cmd F1 foo; ...; cmd Fn foo'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2285 No automatic redisplay is attempted, as the file names may have
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2286 changed. Type \\[dired-do-redisplay] to redisplay the marked files.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2287 The shell command has the top level directory as working directory, so
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2288 output files usually are created there instead of in a subdir."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2289 ;;Functions dired-run-shell-command and dired-shell-stuff-it do the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2290 ;;actual work and can be redefined for customization.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2291 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2292 (let* ((on-each (equal arg 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2293 (prompt (concat (if in-background "& on " "! on ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2294 (if on-each "each " "")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2295 "%s: "))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2296 (file-list (dired-mark-get-files t (if on-each nil arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2297 ;; Want to give feedback whether this file or marked files are used:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2298 (command (dired-read-shell-command
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2299 prompt (if on-each nil arg) file-list))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2300 (result
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2301 (dired-shell-stuff-it command file-list on-each arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2302 ;; execute the shell command
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2303 (dired-run-shell-command result in-background)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2304
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2305 ;; Might use {,} for bash or csh:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2306 (defvar dired-mark-prefix ""
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2307 "Prepended to marked files in dired shell commands.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2308 (defvar dired-mark-postfix ""
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2309 "Appended to marked files in dired shell commands.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2310 (defvar dired-mark-separator " "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2311 "Separates marked files in dired shell commands.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2312
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2313 (defun dired-shell-stuff-it (command file-list on-each &optional raw-arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2314 ;; "Make up a shell command line from COMMAND and FILE-LIST.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2315 ;; If ON-EACH is t, COMMAND should be applied to each file, else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2316 ;; simply concat all files and apply COMMAND to this.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2317 ;; FILE-LIST's elements will be quoted for the shell."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2318 ;; Might be redefined for smarter things and could then use RAW-ARG
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2319 ;; (coming from interactive P and currently ignored) to decide what to do.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2320 ;; Smart would be a way to access basename or extension of file names.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2321 ;; See dired-trns.el for an approach to this.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2322 ;; Bug: There is no way to quote a *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2323 ;; On the other hand, you can never accidentally get a * into your cmd.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2324 (let ((stuff-it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2325 (if (string-match "\\*" command)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2326 (function (lambda (x)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2327 (dired-replace-in-string "\\*" x command)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2328 (function (lambda (x) (concat command " " x))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2329 (if on-each
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2330 (mapconcat stuff-it (mapcar (function shell-quote) file-list) ";")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2331 (let ((fns (mapconcat (function shell-quote)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2332 file-list dired-mark-separator)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2333 (if (> (length file-list) 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2334 (setq fns (concat dired-mark-prefix fns dired-mark-postfix)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2335 (funcall stuff-it fns)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2336
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2337 ;; This is an extra function so that it can be redefined by ange-ftp.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2338 (defun dired-run-shell-command (command &optional in-background)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2339 (if (and in-background (not (string-match "&[ \t]*$" command)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2340 (setq command (concat command " &")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2341 (shell-command command))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2342
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2343 (defun dired-do-print (&optional arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2344 "Print the marked (or next ARG) files.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2345 Uses the shell command coming from variables `lpr-command' and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2346 `lpr-switches' as default."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2347 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2348 (or (listp lpr-switches)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2349 (error "lpr-switches must be a *list* of strings"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2350 (let* ((file-list (dired-mark-get-files t arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2351 (switches (mapconcat (function identity) lpr-switches " "))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2352 (command (dired-mark-read-string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2353 "Print %s with: "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2354 (concat lpr-command " " switches)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2355 'print arg file-list)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2356 (dired-run-shell-command (dired-shell-stuff-it command file-list nil))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2357
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2358
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2359 ;;; 10K
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2360 ;;;###begin dired-cp.el
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2361 ;;; Copy, move/rename, making hard and symbolic links
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2362
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2363 (defvar dired-backup-if-overwrite nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2364 "*Non-nil if Dired should ask about making backups before overwriting files.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2365 Special value 'always suppresses confirmation.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2366
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2367 (defun dired-handle-overwrite (to)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2368 ;; Save old version of a to be overwritten file TO.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2369 ;; `overwrite-confirmed' and `overwrite-backup-query' are fluid vars
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2370 ;; from dired-create-files.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2371 (if (and dired-backup-if-overwrite
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2372 overwrite-confirmed
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2373 (or (eq 'always dired-backup-if-overwrite)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2374 (dired-query 'overwrite-backup-query
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2375 (format "Make backup for existing file `%s'? " to))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2376 (let ((backup (car (find-backup-file-name to))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2377 (rename-file to backup 0) ; confirm overwrite of old backup
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2378 (dired-relist-entry backup))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2379
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2380 (defun dired-copy-file (from to ok-flag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2381 (dired-handle-overwrite to)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2382 (copy-file from to ok-flag dired-copy-preserve-time))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2383
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2384 (defun dired-rename-file (from to ok-flag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2385 (dired-handle-overwrite to)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2386 (rename-file from to ok-flag) ; error is caught in -create-files
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2387 ;; Silently rename the visited file of any buffer visiting this file.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2388 (and (get-file-buffer from)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2389 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2390 (set-buffer (get-file-buffer from))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2391 (let ((modflag (buffer-modified-p)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2392 (set-visited-file-name to) ; kills write-file-hooks
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2393 (set-buffer-modified-p modflag))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2394 (dired-remove-file from)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2395 ;; See if it's an inserted subdir, and rename that, too.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2396 (dired-rename-subdir from to))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2397
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2398 (defun dired-rename-subdir (from-dir to-dir)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2399 (setq from-dir (file-name-as-directory from-dir)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2400 to-dir (file-name-as-directory to-dir))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2401 (dired-fun-in-all-buffers from-dir
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2402 (function dired-rename-subdir-1) from-dir to-dir)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2403 ;; Update visited file name of all affected buffers
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2404 (let ((blist (buffer-list)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2405 (while blist
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2406 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2407 (set-buffer (car blist))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2408 (if (and buffer-file-name
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2409 (dired-in-this-tree buffer-file-name from-dir))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2410 (let ((modflag (buffer-modified-p))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2411 (to-file (dired-replace-in-string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2412 (concat "^" (regexp-quote from-dir))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2413 to-dir
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2414 buffer-file-name)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2415 (set-visited-file-name to-file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2416 (set-buffer-modified-p modflag))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2417 (setq blist (cdr blist)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2418
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2419 (defun dired-rename-subdir-1 (dir to)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2420 ;; Rename DIR to TO in headerlines and dired-subdir-alist, if DIR or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2421 ;; one of its subdirectories is expanded in this buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2422 (let ((alist dired-subdir-alist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2423 (elt nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2424 (while alist
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2425 (setq elt (car alist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2426 alist (cdr alist))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2427 (if (dired-in-this-tree (car elt) dir)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2428 ;; ELT's subdir is affected by the rename
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2429 (dired-rename-subdir-2 elt dir to)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2430 (if (equal dir default-directory)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2431 ;; if top level directory was renamed, lots of things have to be
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2432 ;; updated:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2433 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2434 (dired-unadvertise dir) ; we no longer dired DIR...
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2435 (setq default-directory to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2436 dired-directory (expand-file-name;; this is correct
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2437 ;; with and without wildcards
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2438 (file-name-nondirectory dired-directory)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2439 to))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2440 (let ((new-name (file-name-nondirectory
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2441 (directory-file-name dired-directory))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2442 ;; try to rename buffer, but just leave old name if new
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2443 ;; name would already exist (don't try appending "<%d>")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2444 (or (get-buffer new-name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2445 (rename-buffer new-name)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2446 ;; ... we dired TO now:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2447 (dired-advertise)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2448
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2449 (defun dired-rename-subdir-2 (elt dir to)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2450 ;; Update the headerline and dired-subdir-alist element of directory
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2451 ;; described by alist-element ELT to reflect the moving of DIR to TO.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2452 ;; Thus, ELT describes either DIR itself or a subdir of DIR.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2453
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2454 ;; Bug: If TO is not longer part of the same dired tree as DIR was,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2455 ;; updating the headerline is actually not the right thing---it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2456 ;; should be removed in that case and a completely new entry be
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2457 ;; added for TO. Actually, removing and adding anew would always be
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2458 ;; the right (but slow) way of doing it.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2459
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2460 ;; The consequences are pretty harmless though (no updates since
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2461 ;; dired-buffers-for-dir will not suspect it to be in this dired
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2462 ;; buffer).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2463
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2464 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2465 (let ((regexp (regexp-quote (directory-file-name dir)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2466 (newtext (directory-file-name to))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2467 buffer-read-only)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2468 (goto-char (dired-get-subdir-min elt))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2469 ;; Update subdir headerline in buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2470 (if (not (looking-at dired-subdir-regexp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2471 (error "%s not found where expected - dired-subdir-alist broken?"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2472 dir)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2473 (goto-char (match-beginning 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2474 (if (re-search-forward regexp (match-end 1) t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2475 (replace-match newtext t t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2476 (error "Expected to find `%s' in headerline of %s" dir (car elt))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2477 ;; Update buffer-local dired-subdir-alist
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2478 (setcar elt
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2479 (dired-normalize-subdir
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2480 (dired-replace-in-string regexp newtext (car elt)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2481
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2482 ;; Cloning replace-match to work on strings instead of in buffer:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2483 ;; The FIXEDCASE parameter of replace-match is not implemented.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2484 (defun dired-string-replace-match (regexp string newtext
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2485 &optional literal global)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2486 "Replace first match of REGEXP in STRING with NEWTEXT.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2487 If it does not match, nil is returned instead of the new string.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2488 Optional arg LITERAL means to take NEWTEXT literally.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2489 Optional arg GLOBAL means to replace all matches."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2490 (if global
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2491 (let ((result "") (start 0) mb me)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2492 (while (string-match regexp string start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2493 (setq mb (match-beginning 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2494 me (match-end 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2495 result (concat result
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2496 (substring string start mb)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2497 (if literal
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2498 newtext
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2499 (dired-expand-newtext string newtext)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2500 start me))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2501 (if mb ; matched at least once
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2502 (concat result (substring string start))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2503 nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2504 ;; not GLOBAL
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2505 (if (not (string-match regexp string 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2506 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2507 (concat (substring string 0 (match-beginning 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2508 (if literal newtext (dired-expand-newtext string newtext))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2509 (substring string (match-end 0))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2510
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2511 (defun dired-expand-newtext (string newtext)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2512 ;; Expand \& and \1..\9 (referring to STRING) in NEWTEXT, using match data.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2513 ;; Note that in Emacs 18 match data are clipped to current buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2514 ;; size...so the buffer should better not be smaller than STRING.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2515 (let ((pos 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2516 (len (length newtext))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2517 (expanded-newtext ""))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2518 (while (< pos len)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2519 (setq expanded-newtext
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2520 (concat expanded-newtext
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2521 (let ((c (aref newtext pos)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2522 (if (= ?\\ c)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2523 (cond ((= ?\& (setq c
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2524 (aref newtext
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2525 (setq pos (1+ pos)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2526 (substring string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2527 (match-beginning 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2528 (match-end 0)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2529 ((and (>= c ?1) (<= c ?9))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2530 ;; return empty string if N'th
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2531 ;; sub-regexp did not match:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2532 (let ((n (- c ?0)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2533 (if (match-beginning n)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2534 (substring string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2535 (match-beginning n)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2536 (match-end n))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2537 "")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2538 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2539 (char-to-string c)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2540 (char-to-string c)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2541 (setq pos (1+ pos)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2542 expanded-newtext))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2543
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2544 ;; The basic function for half a dozen variations on cp/mv/ln/ln -s.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2545 (defun dired-create-files (file-creator operation fn-list name-constructor
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2546 &optional marker-char)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2547
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2548 ;; Create a new file for each from a list of existing files. The user
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2549 ;; is queried, dired buffers are updated, and at the end a success or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2550 ;; failure message is displayed
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2551
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2552 ;; FILE-CREATOR must accept three args: oldfile newfile ok-if-already-exists
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2553
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2554 ;; It is called for each file and must create newfile, the entry of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2555 ;; which will be added. The user will be queried if the file already
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2556 ;; exists. If oldfile is removed by FILE-CREATOR (i.e, it is a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2557 ;; rename), it is FILE-CREATOR's responsibility to update dired
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2558 ;; buffers. FILE-CREATOR must abort by signalling a file-error if it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2559 ;; could not create newfile. The error is caught and logged.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2560
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2561 ;; OPERATION (a capitalized string, e.g. `Copy') describes the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2562 ;; operation performed. It is used for error logging.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2563
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2564 ;; FN-LIST is the list of files to copy (full absolute pathnames).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2565
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2566 ;; NAME-CONSTRUCTOR returns a newfile for every oldfile, or nil to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2567 ;; skip. If it skips files for other reasons than a direct user
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2568 ;; query, it is supposed to tell why (using dired-log).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2569
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2570 ;; Optional MARKER-CHAR is a character with which to mark every
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2571 ;; newfile's entry, or t to use the current marker character if the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2572 ;; oldfile was marked.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2573
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2574 (let (failures skipped (success-count 0) (total (length fn-list)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2575 (let (to overwrite-query
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2576 overwrite-backup-query) ; for dired-handle-overwrite
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2577 (mapcar
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2578 (function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2579 (lambda (from)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2580 (setq to (funcall name-constructor from))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2581 (if (equal to from)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2582 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2583 (setq to nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2584 (dired-log "Cannot %s to same file: %s\n"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2585 (downcase operation) from)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2586 (if (not to)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2587 (setq skipped (cons (dired-make-relative from) skipped))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2588 (let* ((overwrite (file-exists-p to))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2589 (overwrite-confirmed ; for dired-handle-overwrite
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2590 (and overwrite
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2591 (let ((help-form '(format "\
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2592 Type SPC or `y' to overwrite file `%s',
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2593 DEL or `n' to skip to next,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2594 ESC or `q' to not overwrite any of the remaining files,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2595 `!' to overwrite all remaining files with no more questions." to)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2596 (dired-query 'overwrite-query
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2597 "Overwrite `%s'?" to))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2598 ;; must determine if FROM is marked before file-creator
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2599 ;; gets a chance to delete it (in case of a move).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2600 (actual-marker-char
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2601 (cond ((integerp marker-char) marker-char)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2602 (marker-char (dired-file-marker from)) ; slow
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2603 (t nil))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2604 (condition-case err
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2605 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2606 (funcall file-creator from to overwrite-confirmed)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2607 (if overwrite
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2608 ;; If we get here, file-creator hasn't been aborted
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2609 ;; and the old entry (if any) has to be deleted
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2610 ;; before adding the new entry.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2611 (dired-remove-file to))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2612 (setq success-count (1+ success-count))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2613 (message "%s: %d of %d" operation success-count total)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2614 (dired-add-file to actual-marker-char))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2615 (file-error ; FILE-CREATOR aborted
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2616 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2617 (setq failures (cons (dired-make-relative from) failures))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2618 (dired-log "%s `%s' to `%s' failed:\n%s\n"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2619 operation from to err))))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2620 fn-list))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2621 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2622 (failures
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2623 (dired-log-summary
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2624 (message "%s failed for %d of %d file%s %s"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2625 operation (length failures) total
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2626 (dired-plural-s total) failures)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2627 (skipped
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2628 (dired-log-summary
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2629 (message "%s: %d of %d file%s skipped %s"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2630 operation (length skipped) total
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2631 (dired-plural-s total) skipped)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2632 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2633 (message "%s: %s file%s."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2634 operation success-count (dired-plural-s success-count)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2635 (dired-move-to-filename))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2636
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2637 (defun dired-do-create-files (op-symbol file-creator operation arg
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2638 &optional marker-char op1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2639 how-to)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2640 ;; Create a new file for each marked file.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2641 ;; Prompts user for target, which is a directory in which to create
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2642 ;; the new files. Target may be a plain file if only one marked
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2643 ;; file exists.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2644 ;; OP-SYMBOL is the symbol for the operation. Function `dired-mark-pop-up'
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2645 ;; will determine wether pop-ups are appropriate for this OP-SYMBOL.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2646 ;; FILE-CREATOR and OPERATION as in dired-create-files.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2647 ;; ARG as in dired-mark-get-files.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2648 ;; Optional arg OP1 is an alternate form for OPERATION if there is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2649 ;; only one file.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2650 ;; Optional arg MARKER-CHAR as in dired-create-files.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2651 ;; Optional arg HOW-TO determines how to treat target:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2652 ;; If HOW-TO is not given (or nil), and target is a directory, the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2653 ;; file(s) are created inside the target directory. If target
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2654 ;; is not a directory, there must be exactly one marked file,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2655 ;; else error.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2656 ;; If HOW-TO is t, then target is not modified. There must be
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2657 ;; exactly one marked file, else error.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2658 ;; Else HOW-TO is assumed to be a function of one argument, target,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2659 ;; that looks at target and returns a value for the into-dir
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2660 ;; variable. The function dired-into-dir-with-symlinks is provided
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2661 ;; for the case (common when creating symlinks) that symbolic
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2662 ;; links to directories are not to be considered as directories
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2663 ;; (as file-directory-p would if HOW-TO had been nil).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2664 (or op1 (setq op1 operation))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2665 (let* ((fn-list (dired-mark-get-files nil arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2666 (fn-count (length fn-list))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2667 (target (expand-file-name
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2668 (dired-mark-read-file-name
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2669 (concat (if (= 1 fn-count) op1 operation) " %s to: ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2670 (dired-dwim-target-directory)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2671 op-symbol arg (mapcar (function dired-make-relative) fn-list))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2672 (into-dir (cond ((null how-to) (file-directory-p target))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2673 ((eq how-to t) nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2674 (t (funcall how-to target)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2675 (if (and (> fn-count 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2676 (not into-dir))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2677 (error "Marked %s: target must be a directory: %s" operation target))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2678 ;; rename-file bombs when moving directories unless we do this:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2679 (or into-dir (setq target (directory-file-name target)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2680 (dired-create-files
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2681 file-creator operation fn-list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2682 (if into-dir ; target is a directory
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2683 ;; This function uses fluid vars into-dir and target when called
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2684 ;; inside dired-create-files:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2685 (function (lambda (from)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2686 (expand-file-name (file-name-nondirectory from) target)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2687 (function (lambda (from) target)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2688 marker-char)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2689
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2690 (defun dired-dwim-target-directory ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2691 ;; Try to guess which target directory the user may want.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2692 ;; If there is a dired buffer displayed in the next window, use
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2693 ;; its current subdir, else use current subdir of this dired buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2694 (let ((this-dir (and (eq major-mode 'dired-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2695 (dired-current-directory))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2696 ;; non-dired buffer may want to profit from this function, e.g. vm-uudecode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2697 (if dired-dwim-target
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2698 (let* ((other-buf (window-buffer (next-window)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2699 (other-dir (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2700 (set-buffer other-buf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2701 (and (eq major-mode 'dired-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2702 (dired-current-directory)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2703 (or other-dir this-dir))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2704 this-dir)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2705
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2706 (defun dired-into-dir-with-symlinks (target)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2707 (and (file-directory-p target)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2708 (not (file-symlink-p target))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2709 ;; This may not always be what you want, especially if target is your
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2710 ;; home directory and it happens to be a symbolic link, as is often the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2711 ;; case with NFS and automounters. Or if you want to make symlinks
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2712 ;; into directories that themselves are only symlinks, also quite
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2713 ;; common.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2714
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2715 ;; So we don't use this function as value for HOW-TO in
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2716 ;; dired-do-symlink, which has the minor disadvantage of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2717 ;; making links *into* a symlinked-dir, when you really wanted to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2718 ;; *overwrite* that symlink. In that (rare, I guess) case, you'll
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2719 ;; just have to remove that symlink by hand before making your marked
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2720 ;; symlinks.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2721
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2722 (defun dired-do-copy (&optional arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2723 "Copy all marked (or next ARG) files, or copy the current file.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2724 Thus, a zero prefix argument copies nothing. But it toggles the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2725 variable `dired-copy-preserve-time' (which see)."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2726 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2727 (if (not (zerop (prefix-numeric-value arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2728 (dired-do-create-files 'copy (function dired-copy-file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2729 (if dired-copy-preserve-time "Copy [-p]" "Copy")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2730 arg dired-keep-marker-copy)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2731 (setq dired-copy-preserve-time (not dired-copy-preserve-time))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2732 (if dired-copy-preserve-time
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2733 (message "Copy will preserve time.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2734 (message "Copied files will get current date."))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2735
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2736 (defun dired-do-symlink (&optional arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2737 "Symlink all marked (or next ARG) files into a directory,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2738 or make a symbolic link to the current file."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2739 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2740 (dired-do-create-files 'symlink (function make-symbolic-link)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2741 "SymLink" arg dired-keep-marker-symlink))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2742
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2743 (defun dired-do-hardlink (&optional arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2744 "Hard-link all marked (or next ARG) files into a directory,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2745 or make a hard link to the current file."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2746 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2747 (dired-do-create-files 'hardlink (function add-name-to-file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2748 "HardLink" arg dired-keep-marker-hardlink))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2749
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2750 (defun dired-do-move (&optional arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2751 "Move all marked (or next ARG) files into a directory,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2752 or rename the current file.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2753 A zero ARG moves no files but toggles `dired-dwim-target' (which see)."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2754 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2755 (if (not (zerop (prefix-numeric-value arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2756 (dired-do-create-files 'move (function dired-rename-file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2757 "Move" arg dired-keep-marker-move "Rename")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2758 (setq dired-dwim-target (not dired-dwim-target))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2759 (message "dired-dwim-target is %s." (if dired-dwim-target "ON" "OFF"))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2760
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2761 ;;;###end dired-cp.el
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2762
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2763 ;;; 5K
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2764 ;;;###begin dired-re.el
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2765 (defun dired-do-create-files-regexp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2766 (file-creator operation arg regexp newname &optional whole-path marker-char)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2767 ;; Create a new file for each marked file using regexps.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2768 ;; FILE-CREATOR and OPERATION as in dired-create-files.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2769 ;; ARG as in dired-mark-get-files.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2770 ;; Matches each marked file against REGEXP and constructs the new
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2771 ;; filename from NEWNAME (like in function replace-match).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2772 ;; Optional arg WHOLE-PATH means match/replace the whole pathname
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2773 ;; instead of only the non-directory part of the file.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2774 ;; Optional arg MARKER-CHAR as in dired-create-files.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2775 (let* ((fn-list (dired-mark-get-files nil arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2776 (fn-count (length fn-list))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2777 (operation-prompt (concat operation " `%s' to `%s'?"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2778 (rename-regexp-help-form (format "\
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2779 Type SPC or `y' to %s one match, DEL or `n' to skip to next,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2780 `!' to %s all remaining matches with no more questions."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2781 (downcase operation)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2782 (downcase operation)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2783 (regexp-name-constructor
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2784 ;; Function to construct new filename using REGEXP and NEWNAME:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2785 (if whole-path ; easy (but rare) case
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2786 (function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2787 (lambda (from)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2788 (let ((to (dired-string-replace-match regexp from newname))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2789 ;; must bind help-form directly around call to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2790 ;; dired-query
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2791 (help-form rename-regexp-help-form))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2792 (if to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2793 (and (dired-query 'rename-regexp-query
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2794 operation-prompt
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2795 from
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2796 to)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2797 to)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2798 (dired-log "%s: %s did not match regexp %s\n"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2799 operation from regexp)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2800 ;; not whole-path, replace non-directory part only
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2801 (function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2802 (lambda (from)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2803 (let* ((new (dired-string-replace-match
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2804 regexp (file-name-nondirectory from) newname))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2805 (to (and new ; nil means there was no match
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2806 (expand-file-name new
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2807 (file-name-directory from))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2808 (help-form rename-regexp-help-form))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2809 (if to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2810 (and (dired-query 'rename-regexp-query
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2811 operation-prompt
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2812 (dired-make-relative from)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2813 (dired-make-relative to))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2814 to)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2815 (dired-log "%s: %s did not match regexp %s\n"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2816 operation (file-name-nondirectory from) regexp)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2817 rename-regexp-query)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2818 (dired-create-files
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2819 file-creator operation fn-list regexp-name-constructor marker-char)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2820
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2821 (defun dired-mark-read-regexp (operation)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2822 ;; Prompt user about performing OPERATION.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2823 ;; Read and return list of: regexp newname arg whole-path.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2824 (let* ((whole-path
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2825 (equal 0 (prefix-numeric-value current-prefix-arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2826 (arg
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2827 (if whole-path nil current-prefix-arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2828 (regexp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2829 (dired-read-regexp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2830 (concat (if whole-path "Path " "") operation " from (regexp): ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2831 dired-flagging-regexp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2832 (newname
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2833 (read-string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2834 (concat (if whole-path "Path " "") operation " " regexp " to: "))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2835 (list regexp newname arg whole-path)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2836
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2837 (defun dired-do-rename-regexp (regexp newname &optional arg whole-path)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2838 "Rename marked files containing REGEXP to NEWNAME.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2839 As each match is found, the user must type a character saying
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2840 what to do with it. For directions, type \\[help-command] at that time.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2841 NEWNAME may contain \\=\\<n> or \\& as in `query-replace-regexp'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2842 REGEXP defaults to the last regexp used.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2843 With a zero prefix arg, renaming by regexp affects the complete
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2844 pathname - usually only the non-directory part of file names is used
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2845 and changed."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2846 (interactive (dired-mark-read-regexp "Rename"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2847 (dired-do-create-files-regexp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2848 (function dired-rename-file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2849 "Rename" arg regexp newname whole-path dired-keep-marker-move))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2850
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2851 (defun dired-do-copy-regexp (regexp newname &optional arg whole-path)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2852 "Copy all marked files containing REGEXP to NEWNAME.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2853 See function `dired-rename-regexp' for more info."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2854 (interactive (dired-mark-read-regexp "Copy"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2855 (dired-do-create-files-regexp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2856 (function dired-copy-file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2857 (if dired-copy-preserve-time "Copy [-p]" "Copy")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2858 arg regexp newname whole-path dired-keep-marker-copy))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2859
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2860 (defun dired-do-hardlink-regexp (regexp newname &optional arg whole-path)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2861 "Hardlink all marked files containing REGEXP to NEWNAME.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2862 See function `dired-rename-regexp' for more info."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2863 (interactive (dired-mark-read-regexp "HardLink"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2864 (dired-do-create-files-regexp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2865 (function add-name-to-file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2866 "HardLink" arg regexp newname whole-path dired-keep-marker-hardlink))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2867
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2868 (defun dired-do-symlink-regexp (regexp newname &optional arg whole-path)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2869 "Symlink all marked files containing REGEXP to NEWNAME.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2870 See function `dired-rename-regexp' for more info."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2871 (interactive (dired-mark-read-regexp "SymLink"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2872 (dired-do-create-files-regexp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2873 (function make-symbolic-link)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2874 "SymLink" arg regexp newname whole-path dired-keep-marker-symlink))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2875
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2876 (defun dired-create-files-non-directory
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2877 (file-creator basename-constructor operation arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2878 ;; Perform FILE-CREATOR on the non-directory part of marked files
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2879 ;; using function BASENAME-CONSTRUCTOR, with query for each file.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2880 ;; OPERATION like in dired-create-files, ARG like in dired-mark-get-files.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2881 (let (rename-non-directory-query)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2882 (dired-create-files
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2883 file-creator
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2884 operation
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2885 (dired-mark-get-files nil arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2886 (function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2887 (lambda (from)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2888 (let ((to (concat (file-name-directory from)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2889 (funcall basename-constructor
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2890 (file-name-nondirectory from)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2891 (and (let ((help-form (format "\
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2892 Type SPC or `y' to %s one file, DEL or `n' to skip to next,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2893 `!' to %s all remaining matches with no more questions."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2894 (downcase operation)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2895 (downcase operation))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2896 (dired-query 'rename-non-directory-query
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2897 (concat operation " `%s' to `%s'")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2898 (dired-make-relative from)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2899 (dired-make-relative to)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2900 to))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2901 dired-keep-marker-move)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2902
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2903 (defun dired-rename-non-directory (basename-constructor operation arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2904 (dired-create-files-non-directory
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2905 (function dired-rename-file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2906 basename-constructor operation arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2907
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2908 (defun dired-upcase (&optional arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2909 "Rename all marked (or next ARG) files to upper case."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2910 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2911 (dired-rename-non-directory (function upcase) "Rename upcase" arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2912
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2913 (defun dired-downcase (&optional arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2914 "Rename all marked (or next ARG) files to lower case."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2915 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2916 (dired-rename-non-directory (function downcase) "Rename downcase" arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2917
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2918 ;;;###end dired-re.el
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2919
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2920
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2921 ;; Tree Dired
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2922
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2923 ;;; utility functions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2924
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2925 (defun dired-in-this-tree (file dir)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2926 ;;"Is FILE part of the directory tree starting at DIR?"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2927 (let (case-fold-search)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2928 (string-match (concat "^" (regexp-quote dir)) file)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2929
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2930 (defun dired-make-absolute (file &optional dir)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2931 ;;"Convert FILE (a pathname relative to DIR) to an absolute pathname."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2932 ;; We can't always use expand-file-name as this would get rid of `.'
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2933 ;; or expand in / instead default-directory if DIR=="".
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2934 ;; This should be good enough for ange-ftp, but might easily be
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2935 ;; redefined (for VMS?).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2936 ;; It should be reasonably fast, though, as it is called in
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2937 ;; dired-get-filename.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2938 (concat (or dir default-directory) file))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2939
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2940 (defun dired-make-relative (file &optional dir no-error)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2941 ;;"Convert FILE (an absolute pathname) to a pathname relative to DIR.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2942 ;; Else error (unless NO-ERROR is non-nil, then FILE is returned unchanged)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2943 ;;DIR defaults to default-directory."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2944 ;; DIR must be file-name-as-directory, as with all directory args in
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2945 ;; elisp code.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2946 (or dir (setq dir default-directory))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2947 (if (string-match (concat "^" (regexp-quote dir)) file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2948 (substring file (match-end 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2949 (if no-error
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2950 file
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2951 (error "%s: not in directory tree growing at %s" file dir))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2952
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2953 (defun dired-normalize-subdir (dir)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2954 ;; Prepend default-directory to DIR if relative path name.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2955 ;; dired-get-filename must be able to make a valid filename from a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2956 ;; file and its directory DIR.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2957 (file-name-as-directory
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2958 (if (file-name-absolute-p dir)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2959 dir
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2960 (expand-file-name dir default-directory))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2961
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2962 (defun dired-between-files ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2963 ;; Point must be at beginning of line
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2964 ;; Should be equivalent to (save-excursion (not (dired-move-to-filename)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2965 ;; but is about 1.5..2.0 times as fast. (Actually that's not worth it)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2966 (or (looking-at "^$\\|^. *$\\|^. total\\|^. wildcard")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2967 (looking-at dired-subdir-regexp)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2968
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2969 (defun dired-get-subdir ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2970 ;;"Return the subdir name on this line, or nil if not on a headerline."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2971 ;; Look up in the alist whether this is a headerline.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2972 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2973 (let ((cur-dir (dired-current-directory)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2974 (beginning-of-line) ; alist stores b-o-l positions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2975 (and (zerop (- (point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2976 (dired-get-subdir-min (assoc cur-dir
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2977 dired-subdir-alist))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2978 cur-dir))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2979
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2980 ;(defun dired-get-subdir-min (elt)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2981 ; (cdr elt))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2982 ;; can't use macro, must be redefinable for other alist format in dired-nstd.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2983 (fset 'dired-get-subdir-min 'cdr)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2984
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2985 (defun dired-get-subdir-max (elt)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2986 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2987 (goto-char (dired-get-subdir-min elt))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2988 (dired-subdir-max)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2989
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2990 (defun dired-clear-alist ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2991 (while dired-subdir-alist
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2992 (set-marker (dired-get-subdir-min (car dired-subdir-alist)) nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2993 (setq dired-subdir-alist (cdr dired-subdir-alist))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2994
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2995 (defun dired-simple-subdir-alist ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2996 ;; Build and return `dired-subdir-alist' assuming just the top level
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2997 ;; directory to be inserted. Don't parse the buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2998 (set (make-local-variable 'dired-subdir-alist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2999 (list (cons default-directory (point-min-marker)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3000
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3001 (defun dired-build-subdir-alist ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3002 "Build `dired-subdir-alist' by parsing the buffer and return it's new value."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3003 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3004 (dired-clear-alist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3005 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3006 (let ((count 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3007 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3008 (setq dired-subdir-alist nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3009 (while (re-search-forward dired-subdir-regexp nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3010 (setq count (1+ count))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3011 (dired-alist-add-1 (buffer-substring (match-beginning 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3012 (match-end 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3013 ;; Put subdir boundary between lines:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3014 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3015 (goto-char (match-beginning 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3016 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3017 (point-marker)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3018 (message "%d" count))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3019 (message "%d director%s." count (if (= 1 count) "y" "ies"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3020 ;; We don't need to sort it because it is in buffer order per
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3021 ;; constructionem. Return new alist:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3022 dired-subdir-alist)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3023
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3024 (defun dired-alist-add (dir new-marker)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3025 ;; Add new DIR at NEW-MARKER. Sort alist.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3026 (dired-alist-add-1 dir new-marker)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3027 (dired-alist-sort))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3028
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3029 (defun dired-alist-add-1 (dir new-marker)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3030 ;; Add new DIR at NEW-MARKER. Don't sort.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3031 (setq dired-subdir-alist
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3032 (cons (cons (dired-normalize-subdir dir) new-marker)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3033 dired-subdir-alist)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3034
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3035 (defun dired-alist-sort ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3036 ;; Keep the alist sorted on buffer position.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3037 (setq dired-subdir-alist
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3038 (sort dired-subdir-alist
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3039 (function (lambda (elt1 elt2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3040 (> (dired-get-subdir-min elt1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3041 (dired-get-subdir-min elt2)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3042
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3043 (defun dired-unsubdir (dir)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3044 ;; Remove DIR from the alist
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3045 (setq dired-subdir-alist
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3046 (delq (assoc dir dired-subdir-alist) dired-subdir-alist)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3047
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3048 (defun dired-goto-next-nontrivial-file ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3049 ;; Position point on first nontrivial file after point.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3050 (dired-goto-next-file);; so there is a file to compare with
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3051 (if (stringp dired-trivial-filenames)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3052 (while (and (not (eobp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3053 (string-match dired-trivial-filenames
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3054 (file-name-nondirectory
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3055 (or (dired-get-filename nil t) ""))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3056 (forward-line 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3057 (dired-move-to-filename))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3058
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3059 (defun dired-goto-next-file ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3060 (let ((max (1- (dired-subdir-max))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3061 (while (and (not (dired-move-to-filename)) (< (point) max))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3062 (forward-line 1))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3063
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3064 (defun dired-goto-subdir (dir)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3065 "Goto end of header line of DIR in this dired buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3066 Return value of point on success, otherwise return nil.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3067 The next char is either \\n, or \\r if DIR is hidden."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3068 (interactive
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3069 (prog1 ; let push-mark display its message
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3070 (list (expand-file-name
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3071 (completing-read "Goto in situ directory: " ; prompt
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3072 dired-subdir-alist ; table
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3073 nil ; predicate
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3074 t ; require-match
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3075 (dired-current-directory))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3076 (push-mark)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3077 (setq dir (file-name-as-directory dir))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3078 (let ((elt (assoc dir dired-subdir-alist)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3079 (and elt
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3080 (goto-char (dired-get-subdir-min elt))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3081 ;; dired-subdir-hidden-p and dired-add-entry depend on point being
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3082 ;; at either \r or \n after this function succeeds.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3083 (progn (skip-chars-forward "^\r\n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3084 (point)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3085
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3086 (defun dired-goto-file (file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3087 "Goto file line of FILE in this dired buffer."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3088 ;; Return value of point on success, else nil.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3089 ;; FILE must be an absolute pathname.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3090 ;; Loses if FILE contains control chars like "\007" for which ls
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3091 ;; either inserts "?" or "\\007" into the buffer, so we won't find
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3092 ;; it in the buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3093 (interactive
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3094 (prog1 ; let push-mark display its message
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3095 (list (expand-file-name
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3096 (read-file-name "Goto file: "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3097 (dired-current-directory))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3098 (push-mark)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3099 (setq file (directory-file-name file)) ; does no harm if no directory
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3100 (let (found case-fold-search)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3101 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3102 (if (dired-goto-subdir (or (file-name-directory file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3103 (error "Need absolute pathname for %s" file)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3104 (let ((base (file-name-nondirectory file))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3105 (boundary (dired-subdir-max)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3106 (while (and (not found)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3107 ;; filenames are preceded by SPC, this makes
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3108 ;; the search faster (e.g. for the filename "-"!).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3109 (search-forward (concat " " base) boundary 'move))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3110 ;; Match could have BASE just as initial substring or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3111 ;; or in permission bits or date or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3112 ;; not be a proper filename at all:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3113 (if (equal base (dired-get-filename 'no-dir t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3114 ;; Must move to filename since an (actually
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3115 ;; correct) match could have been elsewhere on the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3116 ;; ;; line (e.g. "-" would match somewhere in the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3117 ;; permission bits).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3118 (setq found (dired-move-to-filename)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3119 (and found
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3120 ;; return value of point (i.e., FOUND):
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3121 (goto-char found))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3122
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3123 (defun dired-initial-position (dirname)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3124 ;; Where point should go in a new listing of DIRNAME.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3125 ;; Point assumed at beginning of new subdir line.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3126 ;; You may redefine this function as you wish, e.g. like in dired-x.el.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3127 (end-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3128 (if dired-trivial-filenames (dired-goto-next-nontrivial-file)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3129
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3130 ;;; moving by subdirectories
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3131
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3132 (defun dired-subdir-index (dir)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3133 ;; Return an index into alist for use with nth
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3134 ;; for the sake of subdir moving commands.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3135 (let (found (index 0) (alist dired-subdir-alist))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3136 (while alist
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3137 (if (string= dir (car (car alist)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3138 (setq alist nil found t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3139 (setq alist (cdr alist) index (1+ index))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3140 (if found index nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3141
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3142 (defun dired-next-subdir (arg &optional no-error-if-not-found no-skip)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3143 "Go to next subdirectory, regardless of level."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3144 ;; Use 0 arg to go to this directory's header line.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3145 ;; NO-SKIP prevents moving to end of header line, returning whatever
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3146 ;; position was found in dired-subdir-alist.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3147 (interactive "_p")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3148 (let ((this-dir (dired-current-directory))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3149 pos index)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3150 ;; nth with negative arg does not return nil but the first element
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3151 (setq index (- (dired-subdir-index this-dir) arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3152 (setq pos (if (>= index 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3153 (dired-get-subdir-min (nth index dired-subdir-alist))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3154 (if pos
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3155 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3156 (goto-char pos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3157 (or no-skip (skip-chars-forward "^\n\r"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3158 (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3159 (if no-error-if-not-found
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3160 nil ; return nil if not found
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3161 (error "%s directory" (if (> arg 0) "Last" "First"))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3162
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3163 (defun dired-prev-subdir (arg &optional no-error-if-not-found no-skip)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3164 "Go to previous subdirectory, regardless of level.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3165 When called interactively and not on a subdir line, go to this subdir's line."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3166 ;;(interactive "_p")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3167 (interactive
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3168 (list (if current-prefix-arg
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3169 (prefix-numeric-value current-prefix-arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3170 ;; if on subdir start already, don't stay there!
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3171 (if (dired-get-subdir) 1 0))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3172 (dired-next-subdir (- arg) no-error-if-not-found no-skip))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3173
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3174 (defun dired-tree-up (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3175 "Go up ARG levels in the dired tree."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3176 (interactive "_p")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3177 (let ((dir (dired-current-directory)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3178 (while (>= arg 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3179 (setq arg (1- arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3180 dir (file-name-directory (directory-file-name dir))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3181 ;;(setq dir (expand-file-name dir))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3182 (or (dired-goto-subdir dir)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3183 (error "Cannot go up to %s - not in this tree." dir))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3184
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3185 (defun dired-tree-down ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3186 "Go down in the dired tree."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3187 (interactive "_")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3188 (let ((dir (dired-current-directory)) ; has slash
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3189 pos case-fold-search) ; filenames are case sensitive
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3190 (let ((rest (reverse dired-subdir-alist)) elt)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3191 (while rest
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3192 (setq elt (car rest)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3193 rest (cdr rest))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3194 (if (dired-in-this-tree (directory-file-name (car elt)) dir)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3195 (setq rest nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3196 pos (dired-goto-subdir (car elt))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3197 (if pos
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3198 (goto-char pos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3199 (error "At the bottom"))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3200
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3201 ;;; hiding
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3202
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3203 (defun dired-subdir-hidden-p (dir)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3204 (and selective-display
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3205 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3206 (dired-goto-subdir dir)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3207 (looking-at "\r"))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3208
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3209 (defun dired-unhide-subdir ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3210 (let (buffer-read-only)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3211 (subst-char-in-region (dired-subdir-min) (dired-subdir-max) ?\r ?\n)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3212
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3213 (defun dired-hide-check ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3214 (or selective-display
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3215 (error "selective-display must be t for subdir hiding to work!")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3216
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3217 (defun dired-hide-subdir (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3218 "Hide or unhide the current subdirectory and move to next directory.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3219 Optional prefix arg is a repeat factor.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3220 Use \\[dired-hide-all] to (un)hide all directories."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3221 (interactive "p")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3222 (dired-hide-check)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3223 (while (>= (setq arg (1- arg)) 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3224 (let* ((cur-dir (dired-current-directory))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3225 (hidden-p (dired-subdir-hidden-p cur-dir))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3226 (elt (assoc cur-dir dired-subdir-alist))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3227 (end-pos (1- (dired-get-subdir-max elt)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3228 buffer-read-only)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3229 ;; keep header line visible, hide rest
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3230 (goto-char (dired-get-subdir-min elt))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3231 (skip-chars-forward "^\n\r")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3232 (if hidden-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3233 (subst-char-in-region (point) end-pos ?\r ?\n)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3234 (subst-char-in-region (point) end-pos ?\n ?\r)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3235 (dired-next-subdir 1 t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3236
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3237 (defun dired-hide-all (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3238 "Hide all subdirectories, leaving only their header lines.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3239 If there is already something hidden, make everything visible again.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3240 Use \\[dired-hide-subdir] to (un)hide a particular subdirectory."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3241 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3242 (dired-hide-check)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3243 (let (buffer-read-only)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3244 (if (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3245 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3246 (search-forward "\r" nil t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3247 ;; unhide - bombs on \r in filenames
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3248 (subst-char-in-region (point-min) (point-max) ?\r ?\n)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3249 ;; hide
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3250 (let ((pos (point-max)) ; pos of end of last directory
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3251 (alist dired-subdir-alist))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3252 (while alist ; while there are dirs before pos
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3253 (subst-char-in-region (dired-get-subdir-min (car alist)) ; pos of prev dir
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3254 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3255 (goto-char pos) ; current dir
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3256 ;; we're somewhere on current dir's line
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3257 (forward-line -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3258 (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3259 ?\n ?\r)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3260 (setq pos (dired-get-subdir-min (car alist))) ; prev dir gets current dir
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3261 (setq alist (cdr alist)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3262
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3263
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3264 ;; This function is the heart of tree dired.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3265 ;; It is called for each retrieved filename.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3266 ;; It could stand to be faster, though it's mostly function call
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3267 ;; overhead. Avoiding to funcall seems to save about 10% in
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3268 ;; dired-get-filename. Make it a defsubst?
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3269 (defun dired-current-directory (&optional localp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3270 "Return the name of the subdirectory to which this line belongs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3271 This returns a string with trailing slash, like `default-directory'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3272 Optional argument means return a file name relative to `default-directory'."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3273 (let ((here (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3274 (alist (or dired-subdir-alist
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3275 ;; probably because called in a non-dired buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3276 (error "No subdir-alist in %s" (current-buffer))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3277 elt dir)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3278 (while alist
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3279 (setq elt (car alist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3280 dir (car elt)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3281 ;; use `<=' (not `<') as subdir line is part of subdir
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3282 alist (if (<= (dired-get-subdir-min elt) here)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3283 nil ; found
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3284 (cdr alist))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3285 (if localp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3286 (dired-make-relative dir default-directory)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3287 dir)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3288
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3289 ;; Subdirs start at the beginning of their header lines and end just
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3290 ;; before the beginning of the next header line (or end of buffer).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3291
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3292 (defun dired-subdir-min ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3293 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3294 (if (not (dired-prev-subdir 0 t t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3295 (error "Not in a subdir!")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3296 (point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3297
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3298 (defun dired-subdir-max ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3299 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3300 (if (not (dired-next-subdir 1 t t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3301 (point-max)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3302 (point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3303
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3304 (defun dired-kill-line-or-subdir (&optional arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3305 "Kill this line (but not this file).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3306 Optional prefix argument is a repeat factor.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3307 If file is displayed as in situ subdir, kill that as well.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3308 If on a subdir headerline, kill whole subdir."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3309 (interactive "p")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3310 (if (dired-get-subdir)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3311 (dired-kill-subdir)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3312 (dired-kill-line arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3313
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3314 (defun dired-kill-line (&optional arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3315 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3316 (setq arg (prefix-numeric-value arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3317 (let (buffer-read-only file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3318 (while (/= 0 arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3319 (setq file (dired-get-filename nil t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3320 (if (not file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3321 (error "Can only kill file lines.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3322 (save-excursion (and file
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3323 (dired-goto-subdir file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3324 (dired-kill-subdir)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3325 (delete-region (progn (beginning-of-line) (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3326 (progn (forward-line 1) (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3327 (if (> arg 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3328 (setq arg (1- arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3329 (setq arg (1+ arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3330 (forward-line -1))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3331 (dired-move-to-filename)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3332
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3333 (defun dired-kill-subdir (&optional remember-marks)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3334 "Remove all lines of current subdirectory.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3335 Lower levels are unaffected."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3336 ;; With optional REMEMBER-MARKS, return a mark-alist.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3337 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3338 (let ((beg (dired-subdir-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3339 (end (dired-subdir-max))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3340 buffer-read-only cur-dir)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3341 (setq cur-dir (dired-current-directory))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3342 (if (equal cur-dir default-directory)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3343 (error "Attempt to kill top level directory"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3344 (prog1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3345 (if remember-marks (dired-remember-marks beg end))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3346 (delete-region beg end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3347 (if (eobp) ; don't leave final blank line
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3348 (delete-char -1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3349 (dired-unsubdir cur-dir))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3350
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3351 (defun dired-do-kill (&optional arg fmt)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3352 "Kill all marked lines (not files).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3353 With a prefix arg, kill all lines not marked or flagged."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3354 ;; Returns count of killed lines. FMT="" suppresses message.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3355 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3356 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3357 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3358 (let (buffer-read-only (count 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3359 (if (not arg) ; kill marked lines
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3360 (let ((regexp (dired-marker-regexp)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3361 (while (and (not (eobp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3362 (re-search-forward regexp nil t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3363 (setq count (1+ count))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3364 (delete-region (progn (beginning-of-line) (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3365 (progn (forward-line 1) (point)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3366 ;; else kill unmarked lines
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3367 (while (not (eobp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3368 (if (or (dired-between-files)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3369 (not (looking-at "^ ")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3370 (forward-line 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3371 (setq count (1+ count))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3372 (delete-region (point) (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3373 (forward-line 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3374 (point))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3375 (or (equal "" fmt)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3376 (message (or fmt "Killed %d line%s.") count (dired-plural-s count)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3377 count)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3378
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3379 (defun dired-do-redisplay (&optional arg test-for-subdir)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3380 "Redisplay all marked (or next ARG) files.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3381
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3382 If on a subdir line, redisplay that subdirectory. In that case,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3383 a prefix arg lets you edit the ls switches used for the new listing."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3384 ;; Moves point if the next ARG files are redisplayed.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3385 (interactive "P\np")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3386 (if (and test-for-subdir (dired-get-subdir))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3387 (dired-insert-subdir
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3388 (dired-get-subdir)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3389 (if arg (read-string "Switches for listing: " dired-actual-switches)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3390 (message "Redisplaying...")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3391 ;; message instead of making dired-mark-map show-progress is much faster
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3392 (dired-mark-map (let ((fname (dired-get-filename)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3393 (message "Redisplaying... %s" fname)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3394 (dired-update-file-line fname))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3395 arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3396 (dired-move-to-filename)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3397 (message "Redisplaying...done")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3398
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3399 (defun dired-mark-files-in-region (start end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3400 (let (buffer-read-only)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3401 (if (> start end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3402 (error "start > end"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3403 (goto-char start) ; assumed at beginning of line
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3404 (while (< (point) end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3405 ;; Skip subdir line and following garbage like the `total' line:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3406 (while (and (< (point) end) (dired-between-files))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3407 (forward-line 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3408 (if (and (not (looking-at dired-re-dot))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3409 (dired-get-filename nil t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3410 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3411 (delete-char 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3412 (insert dired-marker-char)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3413 (forward-line 1))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3414
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3415 (defun dired-mark-subdir-files ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3416 "Mark all files except `.' and `..'."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3417 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3418 (let ((p-min (dired-subdir-min)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3419 (dired-mark-files-in-region p-min (dired-subdir-max))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3420
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3421 (defun dired-mark-subdir-or-file (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3422 "Mark the current (or next ARG) files.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3423 If on a subdir headerline, mark all its files except `.' and `..'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3424
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3425 Use \\[dired-unflag-all-files] to remove all marks
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3426 and \\[dired-unmark-subdir-or-file] on a subdir to remove the marks in
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3427 this subdir."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3428 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3429 (if (dired-get-subdir)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3430 (save-excursion (dired-mark-subdir-files))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3431 (dired-mark-file (prefix-numeric-value arg))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3432
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3433 (defun dired-unmark-subdir-or-file (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3434 "Unmark the current (or next ARG) files.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3435 If looking at a subdir, unmark all its files except `.' and `..'."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3436 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3437 (let ((dired-marker-char ?\040))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3438 (dired-mark-subdir-or-file arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3439
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3440 ;;; 5K
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3441 ;;;###begin dired-ins.el
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3442
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3443 (defun dired-maybe-insert-subdir (dirname &optional
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3444 switches no-error-if-not-dir-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3445 "Insert this subdirectory into the same dired buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3446 If it is already present, just move to it (type \\[dired-do-redisplay] to refresh),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3447 else inserts it at its natural place (as ls -lR would have done).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3448 With a prefix arg, you may edit the ls switches used for this listing.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3449 You can add `R' to the switches to expand the whole tree starting at
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3450 this subdirectory.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3451 This function takes some pains to conform to ls -lR output."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3452 (interactive
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3453 (list (dired-get-filename)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3454 (if current-prefix-arg
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3455 (read-string "Switches for listing: " dired-actual-switches))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3456 (let ((opoint (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3457 ;; We don't need a marker for opoint as the subdir is always
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3458 ;; inserted *after* opoint.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3459 (setq dirname (file-name-as-directory dirname))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3460 (or (and (not switches)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3461 (dired-goto-subdir dirname))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3462 (dired-insert-subdir dirname switches no-error-if-not-dir-p))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3463 ;; Push mark so that it's easy to find back. Do this after the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3464 ;; insert message so that the user sees the `Mark set' message.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3465 (push-mark opoint)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3466
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3467 (defun dired-insert-subdir (dirname &optional switches no-error-if-not-dir-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3468 "Insert this subdirectory into the same dired buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3469 If it is already present, overwrites previous entry,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3470 else inserts it at its natural place (as ls -lR would have done).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3471 With a prefix arg, you may edit the ls switches used for this listing.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3472 You can add `R' to the switches to expand the whole tree starting at
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3473 this subdirectory.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3474 This function takes some pains to conform to ls -lR output."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3475 ;; NO-ERROR-IF-NOT-DIR-P needed for special filesystems like
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3476 ;; Prospero where dired-ls does the right thing, but
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3477 ;; file-directory-p has not been redefined.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3478 (interactive
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3479 (list (dired-get-filename)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3480 (if current-prefix-arg
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3481 (read-string "Switches for listing: " dired-actual-switches))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3482 (setq dirname (file-name-as-directory (expand-file-name dirname)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3483 (dired-insert-subdir-validate dirname switches)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3484 (or no-error-if-not-dir-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3485 (file-directory-p dirname)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3486 (error "Attempt to insert a non-directory: %s" dirname))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3487 (let ((elt (assoc dirname dired-subdir-alist))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3488 switches-have-R mark-alist case-fold-search buffer-read-only)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3489 ;; case-fold-search is nil now, so we can test for capital `R':
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3490 (if (setq switches-have-R (and switches (string-match "R" switches)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3491 ;; avoid duplicated subdirs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3492 (setq mark-alist (dired-kill-tree dirname t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3493 (if elt
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3494 ;; If subdir is already present, remove it and remember its marks
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3495 (setq mark-alist (nconc (dired-insert-subdir-del elt) mark-alist))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3496 (dired-insert-subdir-newpos dirname)) ; else compute new position
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3497 (dired-insert-subdir-doupdate
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3498 dirname elt (dired-insert-subdir-doinsert dirname switches))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3499 (if switches-have-R (dired-build-subdir-alist))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3500 (dired-initial-position dirname)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3501 (save-excursion (dired-mark-remembered mark-alist))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3502
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3503 ;; This is a separate function for dired-vms.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3504 (defun dired-insert-subdir-validate (dirname &optional switches)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3505 ;; Check that it is valid to insert DIRNAME with SWITCHES.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3506 ;; Signal an error if invalid (e.g. user typed `i' on `..').
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3507 (or (dired-in-this-tree dirname default-directory)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3508 (error "%s: not in this directory tree" dirname))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3509 (if switches
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3510 (let (case-fold-search)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3511 (mapcar
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3512 (function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3513 (lambda (x)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3514 (or (eq (null (string-match x switches))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3515 (null (string-match x dired-actual-switches)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3516 (error "Can't have dirs with and without -%s switches together"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3517 x))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3518 ;; all switches that make a difference to dired-get-filename:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3519 '("F" "b")))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3520
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3521 (defun dired-kill-tree (dirname &optional remember-marks)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3522 ;;"Kill all proper subdirs of DIRNAME, excluding DIRNAME itself.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3523 ;; With optional arg REMEMBER-MARKS, return an alist of marked files."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3524 (interactive "DKill tree below directory: ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3525 (let ((s-alist dired-subdir-alist) dir m-alist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3526 (while s-alist
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3527 (setq dir (car (car s-alist))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3528 s-alist (cdr s-alist))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3529 (if (and (not (string-equal dir dirname))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3530 (dired-in-this-tree dir dirname)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3531 (dired-goto-subdir dir))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3532 (setq m-alist (nconc (dired-kill-subdir remember-marks) m-alist))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3533 m-alist))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3534
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3535 (defun dired-insert-subdir-newpos (new-dir)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3536 ;; Find pos for new subdir, according to tree order.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3537 (let ((alist dired-subdir-alist) elt dir pos new-pos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3538 (while alist
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3539 (setq elt (car alist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3540 alist (cdr alist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3541 dir (car elt)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3542 pos (dired-get-subdir-min elt))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3543 (if (dired-tree-lessp dir new-dir)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3544 ;; Insert NEW-DIR after DIR
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3545 (setq new-pos (dired-get-subdir-max elt)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3546 alist nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3547 (goto-char new-pos))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3548 ;; want a separating newline between subdirs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3549 (or (eobp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3550 (forward-line -1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3551 (insert "\n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3552 (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3553
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3554 (defun dired-insert-subdir-del (element)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3555 ;; Erase an already present subdir (given by ELEMENT) from buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3556 ;; Move to that buffer position. Return a mark-alist.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3557 (let ((begin-marker (dired-get-subdir-min element)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3558 (goto-char begin-marker)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3559 ;; Are at beginning of subdir (and inside it!). Now determine its end:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3560 (goto-char (dired-subdir-max))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3561 (or (eobp);; want a separating newline _between_ subdirs:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3562 (forward-char -1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3563 (prog1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3564 (dired-remember-marks begin-marker (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3565 (delete-region begin-marker (point)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3566
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3567 (defun dired-insert-subdir-doinsert (dirname switches)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3568 ;; Insert ls output after point and put point on the correct
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3569 ;; position for the subdir alist.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3570 ;; Return the boundary of the inserted text (as list of BEG and END).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3571 (let ((begin (point)) end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3572 (message "Reading directory %s..." dirname)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3573 (let ((dired-actual-switches
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3574 (or switches
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3575 (dired-replace-in-string "R" "" dired-actual-switches))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3576 (if (equal dirname (car (car (reverse dired-subdir-alist))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3577 ;; top level directory may contain wildcards:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3578 (dired-readin-insert dired-directory)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3579 (dired-ls dirname dired-actual-switches nil t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3580 (message "Reading directory %s...done" dirname)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3581 (setq end (point-marker))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3582 (dired-indent-rigidly begin end 2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3583 ;; call dired-insert-headerline afterwards, as under VMS dired-ls
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3584 ;; does insert the headerline itself and the insert function just
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3585 ;; moves point.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3586 ;; Need a marker for END as this inserts text.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3587 (goto-char begin)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3588 (dired-insert-headerline dirname)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3589 ;; point is now like in dired-build-subdir-alist
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3590 (prog1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3591 (list begin (marker-position end))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3592 (set-marker end nil))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3593
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3594 (defun dired-insert-subdir-doupdate (dirname elt beg-end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3595 ;; Point is at the correct subdir alist position for ELT,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3596 ;; BEG-END is the subdir-region (as list of begin and end).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3597 (if elt ; subdir was already present
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3598 ;; update its position (should actually be unchanged)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3599 (set-marker (dired-get-subdir-min elt) (point-marker))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3600 (dired-alist-add dirname (point-marker)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3601 ;; The hook may depend on the subdir-alist containing the just
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3602 ;; inserted subdir, so run it after dired-alist-add:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3603 (if dired-after-readin-hook
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3604 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3605 (let ((begin (nth 0 beg-end))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3606 (end (nth 1 beg-end)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3607 (goto-char begin)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3608 (save-restriction
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3609 (narrow-to-region begin end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3610 ;; hook may add or delete lines, but the subdir boundary
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3611 ;; marker floats
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3612 (run-hooks 'dired-after-readin-hook))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3613
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3614 (defun dired-tree-lessp (dir1 dir2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3615 ;; Lexicographic order on pathname components, like `ls -lR':
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3616 ;; DIR1 < DIR2 iff DIR1 comes *before* DIR2 in an `ls -lR' listing,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3617 ;; i.e., iff DIR1 is a (grand)parent dir of DIR2,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3618 ;; or DIR1 and DIR2 are in the same parentdir and their last
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3619 ;; components are string-lessp.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3620 ;; Thus ("/usr/" "/usr/bin") and ("/usr/a/" "/usr/b/") are tree-lessp.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3621 ;; string-lessp could arguably be replaced by file-newer-than-file-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3622 ;; if dired-actual-switches contained `t'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3623 (setq dir1 (file-name-as-directory dir1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3624 dir2 (file-name-as-directory dir2))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3625 (let ((components-1 (dired-split "/" dir1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3626 (components-2 (dired-split "/" dir2)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3627 (while (and components-1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3628 components-2
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3629 (equal (car components-1) (car components-2)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3630 (setq components-1 (cdr components-1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3631 components-2 (cdr components-2)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3632 (let ((c1 (car components-1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3633 (c2 (car components-2)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3634
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3635 (cond ((and c1 c2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3636 (string-lessp c1 c2))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3637 ((and (null c1) (null c2))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3638 nil) ; they are equal, not lessp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3639 ((null c1) ; c2 is a subdir of c1: c1<c2
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3640 t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3641 ((null c2) ; c1 is a subdir of c2: c1>c2
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3642 nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3643 (t (error "This can't happen"))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3644
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3645 ;; There should be a builtin split function - inverse to mapconcat.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3646 (defun dired-split (pat str &optional limit)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3647 "Splitting on regexp PAT, turn string STR into a list of substrings.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3648 Optional third arg LIMIT (>= 1) is a limit to the length of the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3649 resulting list.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3650 Thus, if SEP is a regexp that only matches itself,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3651
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3652 (mapconcat 'identity (dired-split SEP STRING) SEP)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3653
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3654 is always equal to STRING."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3655 (let* ((start (string-match pat str))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3656 (result (list (substring str 0 start)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3657 (count 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3658 (end (if start (match-end 0))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3659 (if end ; else nothing left
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3660 (while (and (or (not (integerp limit))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3661 (< count limit))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3662 (string-match pat str end))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3663 (setq start (match-beginning 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3664 count (1+ count)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3665 result (cons (substring str end start) result)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3666 end (match-end 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3667 start end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3668 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3669 (if (and (or (not (integerp limit))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3670 (< count limit))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3671 end) ; else nothing left
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3672 (setq result
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3673 (cons (substring str end) result)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3674 (nreverse result)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3675
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3676 (defun dired-indent-rigidly (start end arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3677 ;; like indent-rigidly but has more efficient behavior w.r.t. the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3678 ;; after-change-functions (i.e., font-lock-mode.)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3679 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3680 (let ((after-change-functions nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3681 (after-change-function nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3682 (goto-char end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3683 (indent-rigidly start end arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3684 ;; deletion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3685 (run-hook-with-args 'after-change-functions start start (- end start))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3686 (run-hook-with-args 'after-change-function start start (- end start))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3687 ;; insertion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3688 (run-hook-with-args 'after-change-functions start (point) 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3689 (run-hook-with-args 'after-change-function start (point) 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3690 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3691
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3692 (if (string-lessp emacs-version "19")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3693 (fset 'dired-indent-rigidly (symbol-function 'indent-rigidly)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3694
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3695 ;;;###end dired-ins.el
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3696
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3697
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3698 ;;; Sorting
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3699
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3700 ;; Most ls can only sort by name or by date (with -t), nothing else.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3701 ;; GNU ls sorts on size with -S, on extension with -X, and unsorted with -U.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3702 ;; So anything that does not contain these is sort "by name".
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3703
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3704 (defvar dired-ls-sorting-switches "SXU"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3705 "String of ls switches (single letters) except `t' that influence sorting.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3706
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3707 (defvar dired-sort-by-date-regexp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3708 (concat "^-[^" dired-ls-sorting-switches
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3709 "]*t[^" dired-ls-sorting-switches "]*$")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3710 "Regexp recognized by dired to set `by date' mode.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3711
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3712 (defvar dired-sort-by-name-regexp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3713 (concat "^-[^t" dired-ls-sorting-switches "]+$")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3714 "Regexp recognized by dired to set `by name' mode.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3715
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3716 (defvar dired-sort-mode nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3717 "Whether Dired sorts by name, date etc. (buffer-local).")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3718 ;; This is nil outside dired buffers so it can be used in the modeline
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3719
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3720 (defun dired-sort-set-modeline ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3721 ;; Set modeline display according to dired-actual-switches.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3722 ;; Modeline display of "by name" or "by date" guarantees the user a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3723 ;; match with the corresponding regexps. Non-matching switches are
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3724 ;; shown literally.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3725 (setq dired-sort-mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3726 (let (case-fold-search)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3727 (cond ((string-match dired-sort-by-name-regexp dired-actual-switches)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3728 " by name")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3729 ((string-match dired-sort-by-date-regexp dired-actual-switches)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3730 " by date")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3731 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3732 (concat " " dired-actual-switches)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3733 ;; update mode line:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3734 (set-buffer-modified-p (buffer-modified-p)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3735
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3736 (defun dired-sort-toggle-or-edit (&optional arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3737 "Toggle between sort by date/name and refresh the dired buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3738 With a prefix argument you can edit the current listing switches instead."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3739 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3740 (if arg
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3741 (dired-sort-other
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3742 (read-string "ls switches (must contain -l): " dired-actual-switches))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3743 (dired-sort-toggle)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3744
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3745 (defun dired-sort-toggle ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3746 ;; Toggle between sort by date/name. Reverts the buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3747 (setq dired-actual-switches
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3748 (let (case-fold-search)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3749 (concat
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3750 "-l"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3751 (dired-replace-in-string (concat "[---lt"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3752 dired-ls-sorting-switches "]")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3753 ""
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3754 dired-actual-switches)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3755 (if (string-match (concat "[t" dired-ls-sorting-switches "]")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3756 dired-actual-switches)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3757 ""
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3758 "t"))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3759 (dired-sort-set-modeline)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3760 (revert-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3761
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3762 (defun dired-sort-other (switches &optional no-revert)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3763 ;; Specify new ls SWITCHES for current dired buffer. Values matching
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3764 ;; `dired-sort-by-date-regexp' or `dired-sort-by-name-regexp' set the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3765 ;; minor mode accordingly, others appear literally in the mode line.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3766 ;; With optional second arg NO-REVERT, don't refresh the listing afterwards.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3767 (setq dired-actual-switches switches)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3768 (dired-sort-set-modeline)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3769 (or no-revert (revert-buffer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3770
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3771 (if (eq system-type 'vax-vms)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3772 (load "dired-vms"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3773
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3774 (if (string-match "XEmacs" emacs-version)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3775 (load "dired-xemacs-menu"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3776
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3777 (run-hooks 'dired-load-hook) ; for your customizations