annotate lisp/dired/dired.el @ 2:ac2d302a0011 r19-15b2

Import from CVS: tag r19-15b2
author cvs
date Mon, 13 Aug 2007 08:46:35 +0200
parents 376386a54a3c
children 0293115a14e9
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.
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
459 (let ((buffer-read-only nil))
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
460 (run-hooks 'dired-after-readin-hook))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
461 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
462 (dired-initial-position dirname))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
463 (set-buffer old-buf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
464 buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
465
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
466 ;; This differs from dired-buffers-for-dir in that it does not consider
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
467 ;; subdirs of default-directory and searches for the first match only
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
468 (defun dired-find-buffer-nocreate (dirname)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
469 (let (found (blist (buffer-list)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
470 (while blist
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
471 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
472 (set-buffer (car blist))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
473 (if (and (eq major-mode 'dired-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
474 (equal dired-directory dirname))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
475 (setq found (car blist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
476 blist nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
477 (setq blist (cdr blist)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
478 found))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
479
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
480
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
481 ;; Read in a new dired buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
482
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
483 ;; dired-readin differs from dired-insert-subdir in that it accepts
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
484 ;; wildcards, erases the buffer, and builds the subdir-alist anew
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
485 ;; (including making it buffer-local and clearing it first).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
486 (defun dired-readin (dirname buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
487 ;; default-directory and dired-actual-switches must be buffer-local
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
488 ;; and initialized by now.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
489 ;; Thus we can test (equal default-directory dirname) instead of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
490 ;; (file-directory-p dirname) and save a filesystem transaction.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
491 ;; Also, we can run this hook which may want to modify the switches
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
492 ;; based on default-directory, e.g. with ange-ftp to a SysV host
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
493 ;; where ls won't understand -Al switches.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
494 (setq dirname (expand-file-name dirname))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
495 (run-hooks 'dired-before-readin-hook)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
496 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
497 (message "Reading directory %s..." dirname)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
498 (set-buffer buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
499 (let (buffer-read-only)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
500 (widen)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
501 (erase-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
502 (dired-readin-insert dirname)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
503 (dired-indent-rigidly (point-min) (point-max) 2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
504 ;; 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
505 ;; other subdirs have:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
506 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
507 (dired-insert-headerline default-directory)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
508 ;; 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
509 ;; alist to be OK.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
510 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
511 (message "Reading directory %s...done" dirname)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
512 (set-buffer-modified-p nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
513 ;; Must first make alist buffer local and set it to nil because
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
514 ;; dired-build-subdir-alist will call dired-clear-alist first
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
515 (set (make-local-variable 'dired-subdir-alist) nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
516 (let (case-fold-search)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
517 (if (string-match "R" dired-actual-switches)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
518 (dired-build-subdir-alist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
519 ;; no need to parse the buffer if listing is not recursive
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
520 (dired-simple-subdir-alist)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
521
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
522 ;; Subroutines of dired-readin
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
523
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
524 (defun dired-readin-insert (dirname)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
525 ;; Just insert listing for DIRNAME, assuming a clean buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
526 (let ((font-lock-mode nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
527 (if (equal default-directory dirname);; i.e., (file-directory-p dirname)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
528 (dired-ls (if (or (let (case-fold-search)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
529 (string-match "R" dired-actual-switches))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
530 (eq system-type 'vax-vms))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
531 dirname
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
532 ;; On SysV derived system, symbolic links to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
533 ;; directories are not resolved, while on BSD
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
534 ;; derived it suffices to let DIRNAME end in slash.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
535 ;; We always let it end in "/." since it does no
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
536 ;; harm on BSD and makes Dired work on such links on
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
537 ;; SysV.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
538 ;; Cannot do this with -R since "dir/./subdir"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
539 ;; headerlines would result, utterly confusing dired.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
540 (concat dirname "."))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
541 dired-actual-switches nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
542 (if (not (file-readable-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
543 (directory-file-name (file-name-directory dirname))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
544 (error "Directory %s inaccessible or nonexistent" dirname)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
545 ;; else assume it contains wildcards:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
546 (dired-ls dirname dired-actual-switches t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
547 (save-excursion;; insert wildcard instead of total line:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
548 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
549 (insert "wildcard " (file-name-nondirectory dirname) "\n"))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
550
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
551 (defun dired-insert-headerline (dir);; also used by dired-insert-subdir
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
552 ;; Insert DIR's headerline with no trailing slash, exactly like ls
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
553 ;; would, and put cursor where dired-build-subdir-alist puts subdir
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
554 ;; boundaries.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
555 (save-excursion (insert " " (directory-file-name dir) ":\n")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
556
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
557 ;; Make the file names highlight when the mouse is on them.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
558 ;; from FSF 19.30.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
559 (defun dired-insert-set-properties (beg end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
560 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
561 (goto-char beg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
562 (while (< (point) end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
563 (condition-case nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
564 (if (dired-move-to-filename)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
565 (put-text-property (point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
566 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
567 (dired-move-to-end-of-filename)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
568 (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
569 'highlight t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
570 (error nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
571 (forward-line 1))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
572
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
573
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
574 ;; Reverting a dired buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
575
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
576 (defun dired-revert (&optional arg noconfirm)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
577 ;; Reread the dired buffer. Must also be called after
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
578 ;; dired-actual-switches have changed.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
579 ;; Should not fail even on completely garbaged buffers.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
580 ;; Preserves old cursor, marks/flags, hidden-p.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
581 (widen) ; just in case user narrowed
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
582 (let ((opoint (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
583 (ofile (dired-get-filename nil t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
584 (mark-alist nil) ; save marked files
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
585 (hidden-subdirs (dired-remember-hidden))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
586 (old-subdir-alist (cdr (reverse dired-subdir-alist))) ; except pwd
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
587 case-fold-search ; we check for upper case ls flags
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
588 buffer-read-only)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
589 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
590 (setq mark-alist;; only after dired-remember-hidden since this unhides:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
591 (dired-remember-marks (point-min) (point-max)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
592 ;; treat top level dir extra (it may contain wildcards)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
593 (dired-readin dired-directory (current-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
594 (let ((dired-after-readin-hook nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
595 ;; don't run that hook for each subdir...
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
596 (dired-insert-old-subdirs old-subdir-alist))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
597 (dired-mark-remembered mark-alist) ; mark files that were marked
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
598 ;; ... run the hook for the whole buffer, and only after markers
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
599 ;; have been reinserted (else omitting in dired-x would omit marked files)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
600 (run-hooks 'dired-after-readin-hook) ; no need to narrow
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
601 (or (and ofile (dired-goto-file ofile)) ; move cursor to where it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
602 (goto-char opoint)) ; was before
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
603 (dired-move-to-filename)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
604 (save-excursion ; hide subdirs that were hidden
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
605 (mapcar (function (lambda (dir)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
606 (if (dired-goto-subdir dir)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
607 (dired-hide-subdir 1))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
608 hidden-subdirs)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
609 ;; outside of the let scope
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
610 (setq buffer-read-only t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
611
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
612 ;; Subroutines of dired-revert
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
613 ;; Some of these are also used when inserting subdirs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
614
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
615 (defun dired-remember-marks (beg end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
616 ;; Return alist of files and their marks, from BEG to END.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
617 (if selective-display ; must unhide to make this work.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
618 (let (buffer-read-only)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
619 (subst-char-in-region beg end ?\r ?\n)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
620 (let (fil chr alist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
621 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
622 (goto-char beg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
623 (while (re-search-forward dired-re-mark end t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
624 (if (setq fil (dired-get-filename nil t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
625 (setq chr (preceding-char)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
626 alist (cons (cons fil chr) alist)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
627 alist))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
628
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
629 (defun dired-mark-remembered (alist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
630 ;; Mark all files remembered in ALIST.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
631 (let (elt fil chr)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
632 (while alist
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
633 (setq elt (car alist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
634 alist (cdr alist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
635 fil (car elt)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
636 chr (cdr elt))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
637 (if (dired-goto-file fil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
638 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
639 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
640 (delete-char 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
641 (insert chr))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
642
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
643 (defun dired-remember-hidden ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
644 (let ((l dired-subdir-alist) dir result)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
645 (while l
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
646 (setq dir (car (car l))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
647 l (cdr l))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
648 (if (dired-subdir-hidden-p dir)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
649 (setq result (cons dir result))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
650 result))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
651
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
652 (defun dired-insert-old-subdirs (old-subdir-alist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
653 ;; Try to insert all subdirs that were displayed before
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
654 (or (string-match "R" dired-actual-switches)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
655 (let (elt dir)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
656 (while old-subdir-alist
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
657 (setq elt (car old-subdir-alist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
658 old-subdir-alist (cdr old-subdir-alist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
659 dir (car elt))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
660 (condition-case ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
661 (dired-insert-subdir dir)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
662 (error nil))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
663
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
664
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
665 ;; dired mode key bindings and initialization
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
666
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
667 (defvar dired-mode-map nil "Local keymap for dired-mode buffers.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
668 (if dired-mode-map
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
669 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
670 ;; Force `f' rather than `e' in the mode doc:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
671 (fset 'dired-advertised-find-file 'dired-find-file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
672 ;; This looks ugly when substitute-command-keys uses C-d instead d:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
673 ;; (define-key dired-mode-map "\C-d" 'dired-flag-file-deleted)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
674
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
675 (setq dired-mode-map (make-keymap))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
676 (suppress-keymap dired-mode-map)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
677 ;; Commands to mark certain categories of files
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
678 (define-key dired-mode-map "#" 'dired-flag-auto-save-files)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
679 (define-key dired-mode-map "*" 'dired-mark-executables)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
680 (define-key dired-mode-map "." 'dired-clean-directory)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
681 (define-key dired-mode-map "/" 'dired-mark-directories)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
682 (define-key dired-mode-map "@" 'dired-mark-symlinks)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
683 ;; Upper case keys (except !, c, r) for operating on the marked files
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
684 (define-key dired-mode-map "c" 'dired-do-copy)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
685 (define-key dired-mode-map "r" 'dired-do-move)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
686 (define-key dired-mode-map "!" 'dired-do-shell-command)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
687 (define-key dired-mode-map "B" 'dired-do-byte-compile)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
688 (define-key dired-mode-map "C" 'dired-do-compress)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
689 (define-key dired-mode-map "G" 'dired-do-chgrp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
690 (define-key dired-mode-map "H" 'dired-do-hardlink)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
691 (define-key dired-mode-map "L" 'dired-do-load)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
692 (define-key dired-mode-map "M" 'dired-do-chmod)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
693 (define-key dired-mode-map "O" 'dired-do-chown)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
694 (define-key dired-mode-map "P" 'dired-do-print)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
695 (define-key dired-mode-map "U" 'dired-do-uncompress)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
696 (define-key dired-mode-map "X" 'dired-do-delete)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
697 (define-key dired-mode-map "Y" 'dired-do-symlink)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
698 ;; exceptions to the upper key rule
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
699 (define-key dired-mode-map "D" 'dired-diff)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
700 (define-key dired-mode-map "W" 'dired-why)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
701 ;; Tree Dired commands
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
702 (define-key dired-mode-map "\M-\C-?" 'dired-unflag-all-files)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
703 (define-key dired-mode-map "\M-\C-d" 'dired-tree-down)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
704 (define-key dired-mode-map "\M-\C-u" 'dired-tree-up)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
705 (define-key dired-mode-map "\M-\C-n" 'dired-next-subdir)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
706 (define-key dired-mode-map "\M-\C-p" 'dired-prev-subdir)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
707 ;; move to marked files
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
708 (define-key dired-mode-map "\M-{" 'dired-prev-marked-file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
709 (define-key dired-mode-map "\M-}" 'dired-next-marked-file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
710 ;; kill marked files
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
711 (define-key dired-mode-map "\M-k" 'dired-do-kill)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
712 ;; Make all regexp commands share a `%' prefix:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
713 (fset 'dired-regexp-prefix (make-sparse-keymap))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
714 (define-key dired-mode-map "%" 'dired-regexp-prefix)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
715 (define-key dired-mode-map "%u" 'dired-upcase)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
716 (define-key dired-mode-map "%l" 'dired-downcase)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
717 (define-key dired-mode-map "%d" 'dired-flag-regexp-files)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
718 (define-key dired-mode-map "%m" 'dired-mark-files-regexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
719 (define-key dired-mode-map "%r" 'dired-do-rename-regexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
720 (define-key dired-mode-map "%c" 'dired-do-copy-regexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
721 (define-key dired-mode-map "%H" 'dired-do-hardlink-regexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
722 (define-key dired-mode-map "%Y" 'dired-do-symlink-regexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
723 ;; Lower keys for commands not operating on all the marked files
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
724 (define-key dired-mode-map "d" 'dired-flag-file-deleted)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
725 (define-key dired-mode-map "e" 'dired-find-file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
726 (define-key dired-mode-map "f" 'dired-advertised-find-file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
727 (define-key dired-mode-map "g" 'revert-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
728 (define-key dired-mode-map "h" 'describe-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
729 (define-key dired-mode-map "i" 'dired-maybe-insert-subdir)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
730 (define-key dired-mode-map "k" 'dired-kill-line-or-subdir)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
731 (define-key dired-mode-map "l" 'dired-do-redisplay)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
732 (define-key dired-mode-map "m" 'dired-mark-subdir-or-file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
733 (define-key dired-mode-map "n" 'dired-next-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
734 (define-key dired-mode-map "o" 'dired-find-file-other-window)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
735 (define-key dired-mode-map "p" 'dired-previous-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
736 (define-key dired-mode-map "q" 'dired-quit)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
737 (define-key dired-mode-map "s" 'dired-sort-toggle-or-edit)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
738 (define-key dired-mode-map "u" 'dired-unmark-subdir-or-file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
739 (define-key dired-mode-map "v" 'dired-view-file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
740 (define-key dired-mode-map "x" 'dired-do-deletions)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
741 (define-key dired-mode-map "~" 'dired-flag-backup-files)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
742 (define-key dired-mode-map "\M-~" 'dired-backup-diff)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
743 (define-key dired-mode-map "+" 'dired-create-directory)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
744 ;; moving
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
745 (define-key dired-mode-map "<" 'dired-prev-dirline)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
746 (define-key dired-mode-map ">" 'dired-next-dirline)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
747 (define-key dired-mode-map "^" 'dired-up-directory)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
748 (define-key dired-mode-map " " 'dired-next-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
749 (define-key dired-mode-map "\C-n" 'dired-next-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
750 (define-key dired-mode-map "\C-p" 'dired-previous-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
751 ;; hiding
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
752 (define-key dired-mode-map "$" 'dired-hide-subdir)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
753 (define-key dired-mode-map "=" 'dired-hide-all)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
754 ;; misc
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
755 (define-key dired-mode-map "?" 'dired-summary)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
756 (define-key dired-mode-map "\177" 'dired-backup-unflag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
757 (define-key dired-mode-map "\C-_" 'dired-undo)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
758 (define-key dired-mode-map "\C-xu" 'dired-undo)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
759 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
760
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
761 (or (equal (assq 'dired-sort-mode minor-mode-alist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
762 '(dired-sort-mode dired-sort-mode))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
763 ;; Test whether this has already been done in case dired is reloaded
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
764 ;; There may be several elements with dired-sort-mode as car.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
765 (setq minor-mode-alist
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
766 (cons '(dired-sort-mode dired-sort-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
767 ;; dired-sort-mode is nil outside dired
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
768 minor-mode-alist)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
769
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
770 ;; Dired mode is suitable only for specially formatted data.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
771 (put 'dired-mode 'mode-class 'special)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
772
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
773 (defun dired-mode (&optional dirname switches)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
774 "\
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
775 Mode for \"editing\" directory listings.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
776 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
777 \(optionally) its subdirectories, in the format of `ls -lR'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
778 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
779 \"Editing\" means that you can run shell commands on files, visit,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
780 compress, load or byte-compile them, change their file attributes
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
781 and insert subdirectories into the same buffer. You can \"mark\"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
782 files for later commands or \"flag\" them for deletion, either file
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
783 by file or all files matching certain criteria.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
784 You can move using the usual cursor motion commands.\\<dired-mode-map>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
785 Letters no longer insert themselves. Digits are prefix arguments.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
786 Instead, type \\[dired-flag-file-deleted] to flag a file for Deletion.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
787 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
788 Most commands operate on the marked files and use the current file
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
789 if no files are marked. Use a numeric prefix argument to operate on
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
790 the next ARG (or previous -ARG if ARG<0) files, or just `1'
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
791 to operate on the current file only. Prefix arguments override marks.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
792 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
793 why something went wrong.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
794 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
795 Type \\[dired-backup-unflag] to back up one line and unflag.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
796 Type \\[dired-do-deletions] to eXecute the deletions requested.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
797 Type \\[dired-advertised-find-file] to Find the current line's file
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
798 (or dired it in another buffer, if it is a directory).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
799 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
800 Type \\[dired-maybe-insert-subdir] to Insert a subdirectory in this buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
801 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
802 Type \\[dired-do-copy] to Copy files.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
803 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
804 Type \\[revert-buffer] to read all currently expanded directories again.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
805 This retains all marks and hides subdirs again that were hidden before.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
806 SPC and DEL can be used to move down and up by lines.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
807
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
808 If dired ever gets confused, you can either type \\[revert-buffer] \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
809 to read the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
810 directories again, type \\[dired-do-redisplay] \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
811 to relist a single or the marked files or a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
812 subdirectory, or type \\[dired-build-subdir-alist] to parse the buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
813 again for the directory tree.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
814
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
815 Customization variables (rename this buffer and type \\[describe-variable] on each line
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
816 for more info):
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
817
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
818 dired-listing-switches
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
819 dired-trivial-filenames
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
820 dired-shrink-to-fit
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
821 dired-marker-char
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
822 dired-del-marker
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
823 dired-keep-marker-move
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
824 dired-keep-marker-copy
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
825 dired-keep-marker-hardlink
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
826 dired-keep-marker-symlink
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
827
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
828 Hooks (use \\[describe-variable] to see their documentation):
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
829
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
830 dired-before-readin-hook
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
831 dired-after-readin-hook
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
832 dired-mode-hook
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
833 dired-load-hook
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
834
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
835 Keybindings:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
836 \\{dired-mode-map}"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
837 ;; Not to be called interactively (e.g. dired-directory will be set
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
838 ;; to default-directory, which is wrong with wildcards).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
839 (kill-all-local-variables)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
840 (use-local-map dired-mode-map)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
841 (dired-advertise) ; default-directory is already set
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
842 (setq major-mode 'dired-mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
843 mode-name "Dired"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
844 case-fold-search nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
845 buffer-read-only t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
846 selective-display t ; for subdirectory hiding
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
847 modeline-buffer-identification '("Dired: %17b"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
848 (set (make-local-variable 'revert-buffer-function)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
849 (function dired-revert))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
850 (set (make-local-variable 'page-delimiter)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
851 "\n\n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
852 (set (make-local-variable 'dired-directory)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
853 (or dirname default-directory))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
854 (set (make-local-variable 'list-buffers-directory)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
855 dired-directory)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
856 (set (make-local-variable 'dired-actual-switches)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
857 (or switches dired-listing-switches))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
858 (make-local-variable 'dired-sort-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
859 (dired-sort-other dired-actual-switches t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
860 (run-hooks 'dired-mode-hook))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
861
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
862
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
863 (defun dired-check-ls-l ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
864 (let (case-fold-search)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
865 (or (string-match "l" dired-actual-switches)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
866 (error "Dired needs -l in ls switches"))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
867
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
868 (defun dired-repeat-over-lines (arg function)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
869 ;; This version skips non-file lines.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
870 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
871 (while (and (> arg 0) (not (eobp)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
872 (setq arg (1- arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
873 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
874 (while (and (not (eobp)) (dired-between-files)) (forward-line 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
875 (save-excursion (funcall function))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
876 (forward-line 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
877 (while (and (< arg 0) (not (bobp)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
878 (setq arg (1+ arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
879 (forward-line -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
880 (while (and (not (bobp)) (dired-between-files)) (forward-line -1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
881 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
882 (save-excursion (funcall function))
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 (dired-move-to-filename))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
885
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
886 (defun dired-flag-file-deleted (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
887 "In dired, flag the current line's file for deletion.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
888 With prefix arg, repeat over several lines.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
889
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
890 If on a subdir headerline, mark all its files except `.' and `..'."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
891 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
892 (let ((dired-marker-char dired-del-marker))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
893 (dired-mark-subdir-or-file arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
894
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
895 (defun dired-quit ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
896 "Bury the current dired buffer."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
897 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
898 (bury-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
899
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
900 (defun dired-summary ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
901 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
902 ;>> 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
903 (message
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
904 "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
905
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
906 (defun dired-create-directory (directory)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
907 "Create a directory called DIRECTORY."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
908 (interactive
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
909 (list (read-file-name "Create directory: " (dired-current-directory))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
910 (let ((expanded (directory-file-name (expand-file-name directory))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
911 (make-directory expanded)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
912 (dired-add-file expanded)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
913 (dired-move-to-filename)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
914
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
915 (defun dired-undo ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
916 "Undo in a dired buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
917 This doesn't recover lost files, it is just normal undo with temporarily
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
918 writeable buffer. You can use it to recover marks, killed lines or subdirs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
919 In the latter case, you have to do \\[dired-build-subdir-alist] to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
920 parse the buffer again."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
921 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
922 (let (buffer-read-only)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
923 (undo)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
924
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
925 (defun dired-unflag (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
926 "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
927 Optional prefix ARG says how many lines to unflag."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
928 (interactive "p")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
929 (dired-repeat-over-lines arg
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
930 '(lambda ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
931 (let (buffer-read-only)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
932 (delete-char 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
933 (insert " ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
934 (forward-char -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
935 nil))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
936
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
937 (defun dired-backup-unflag (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
938 "In dired, move up lines and remove deletion flag there.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
939 Optional prefix ARG says how many lines to unflag; default is one line."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
940 (interactive "p")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
941 (dired-unflag (- arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
942
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
943 (defun dired-next-line (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
944 "Move down lines then position at filename.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
945 Optional prefix ARG says how many lines to move; default is one line."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
946 (interactive "_p")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
947 (next-line arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
948 (dired-move-to-filename))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
949
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
950 (defun dired-previous-line (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
951 "Move up lines then position at filename.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
952 Optional prefix ARG says how many lines to move; default is one line."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
953 (interactive "_p")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
954 (previous-line arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
955 (dired-move-to-filename))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
956
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
957 (defun dired-up-directory ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
958 "Run dired on parent directory of current directory.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
959 Find the parent directory either in this buffer or another buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
960 Creates a buffer if necessary."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
961 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
962 (let* ((dir (dired-current-directory))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
963 (up (file-name-directory (directory-file-name dir))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
964 (or (dired-goto-file (directory-file-name dir))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
965 (dired-goto-subdir up)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
966 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
967 (dired up)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
968 (dired-goto-file dir)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
969
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
970 (defun dired-find-file ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
971 "In dired, visit the file or directory named on this line."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
972 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
973 (let ((find-file-run-dired t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
974 (find-file (dired-get-filename))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
975
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
976 (defun dired-view-file ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
977 "In dired, examine a file in view mode, returning to dired when done.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
978 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
979 otherwise, display it in another buffer."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
980 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
981 (if (file-directory-p (dired-get-filename))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
982 (or (dired-goto-subdir (dired-get-filename))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
983 (dired (dired-get-filename)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
984 (view-file (dired-get-filename))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
985
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
986 (defun dired-find-file-other-window ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
987 "In dired, visit this file or directory in another window."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
988 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
989 (let ((find-file-run-dired t)) ;; XEmacs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
990 (find-file-other-window (dired-get-filename))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
991
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
992 (defun dired-get-filename (&optional localp no-error-if-not-filep)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
993 "In dired, return name of file mentioned on this line.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
994 Value returned normally includes the directory name.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
995 Optional arg LOCALP with value `no-dir' means don't include directory
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
996 name in result. A value of t means use path name relative to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
997 `default-directory', which still may contain slashes if in a subdirectory.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
998 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
999 this line, otherwise an error occurs."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1000 (let (case-fold-search file p1 p2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1001 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1002 (if (setq p1 (dired-move-to-filename (not no-error-if-not-filep)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1003 (setq p2 (dired-move-to-end-of-filename no-error-if-not-filep))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1004 ;; 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
1005 (if (setq file (and p1 p2 (buffer-substring p1 p2)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1006 ;; Check if ls quoted the names, and unquote them.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1007 ;; Using read to unquote is much faster than substituting
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1008 ;; \007 (4 chars) -> ^G (1 char) etc. in a lisp loop.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1009 (cond ((string-match "b" dired-actual-switches) ; System V ls
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1010 ;; This case is about 20% slower than without -b.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1011 (setq file
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1012 (read
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1013 (concat "\""
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1014 ;; some ls -b don't escape quotes, argh!
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1015 ;; This is not needed for GNU ls, though.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1016 (or (dired-string-replace-match
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1017 "\\([^\\]\\)\"" file "\\1\\\\\"")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1018 file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1019 "\""))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1020 ;; If you do this, update dired-insert-subdir-validate too
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1021 ;; ((string-match "Q" dired-actual-switches) ; GNU ls
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1022 ;; (setq file (read file)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1023 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1024 (if (eq localp 'no-dir)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1025 file
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1026 (and file (concat (dired-current-directory localp) file)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1027
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1028 (defun dired-move-to-filename (&optional raise-error eol)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1029 "In dired, move to first char of filename on this line.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1030 Returns position (point) or nil if no filename on this line."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1031 ;; This is the UNIX version.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1032 (or eol (setq eol (progn (end-of-line) (point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1033 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1034 (if (string-match "l" dired-actual-switches)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1035 (if (re-search-forward
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1036 "\\(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
1037 eol t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1038 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1039 (skip-chars-forward " ") ; there is one SPC after day of month
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1040 (skip-chars-forward "^ " eol) ; move after time of day (or year)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1041 (skip-chars-forward " " eol) ; there is space before the file name
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1042 ;; Actually, if the year instead of clock time is displayed,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1043 ;; there are (only for some ls programs?) two spaces instead
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1044 ;; of one before the name.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1045 ;; If we could depend on ls inserting exactly one SPC we
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1046 ;; would not bomb on names _starting_ with SPC.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1047 (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1048 (if raise-error
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1049 (error "No file on this line")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1050 nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1051 ;; else ls switches don't contain -l.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1052 ;; Note that even if we make dired-move-to-filename and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1053 ;; dired-move-to-end-of-filename (and thus dired-get-filename)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1054 ;; work, all commands that gleaned information from the permission
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1055 ;; bits (like dired-mark-directories) will cease to work properly.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1056 (if (eolp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1057 (if raise-error
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1058 (error "No file on this line")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1059 nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1060 ;; skip marker, if any
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1061 (forward-char))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1062 (skip-chars-forward " ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1063 (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1064
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1065 (defun dired-move-to-end-of-filename (&optional no-error)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1066 ;; Assumes point is at beginning of filename,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1067 ;; thus the rwx bit re-search-backward below will succeed in *this*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1068 ;; line if at all. So, it should be called only after
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1069 ;; (dired-move-to-filename t).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1070 ;; On failure, signals an error (with non-nil NO-ERROR just returns nil).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1071 ;; This is the UNIX version.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1072 (let (opoint file-type executable symlink hidden case-fold-search used-F eol)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1073 ;; case-fold-search is nil now, so we can test for capital F:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1074 (setq used-F (string-match "F" dired-actual-switches)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1075 opoint (point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1076 eol (save-excursion (end-of-line) (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1077 hidden (and selective-display
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1078 (save-excursion (search-forward "\r" eol t))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1079 (if hidden
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1080 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1081 (save-excursion;; Find out what kind of file this is:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1082 ;; Restrict perm bits to be non-blank,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1083 ;; otherwise this matches one char to early (looking backward):
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1084 ;; "l---------" (some systems make symlinks that way)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1085 ;; "----------" (plain file with zero perms)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1086 (if (re-search-backward
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1087 "\\([^ ]\\)[-r][-w]\\([^ ]\\)[-r][-w]\\([^ ]\\)[-r][-w]\\([^ ]\\)"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1088 nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1089 (setq file-type (char-after (match-beginning 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1090 symlink (eq file-type ?l)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1091 ;; Only with -F we need to know whether it's an executable
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1092 executable (and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1093 used-F
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1094 (string-match
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1095 "[xst]";; execute bit set anywhere?
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1096 (concat
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1097 (buffer-substring (match-beginning 2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1098 (match-end 2))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1099 (buffer-substring (match-beginning 3)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1100 (match-end 3))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1101 (buffer-substring (match-beginning 4)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1102 (match-end 4))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1103 (or no-error
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1104 (not (string-match "l" dired-actual-switches))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1105 (error "No file on this line"))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1106 ;; Move point to end of name:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1107 (if symlink
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1108 (if (search-forward " ->" eol t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1109 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1110 (forward-char -3)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1111 (and used-F
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1112 dired-ls-F-marks-symlinks
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1113 (eq (preceding-char) ?@);; did ls really mark the link?
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1114 (forward-char -1))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1115 (goto-char eol);; else not a symbolic link
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1116 ;; ls -lF marks dirs, sockets and executables with exactly one
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1117 ;; trailing character. (Executable bits on symlinks ain't mean
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1118 ;; a thing, even to ls, but we know it's not a symlink.)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1119 (and used-F
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1120 ;; -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
1121 (let ((char (preceding-char)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1122 (or (and (eq file-type ?d) (eq char ?/))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1123 (and executable (eq char ?*))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1124 (and (eq file-type ?s) (eq char ?=))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1125 (forward-char -1))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1126 (or no-error
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1127 (not (eq opoint (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1128 (error (if hidden
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1129 (substitute-command-keys
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1130 "File line is hidden, type \\[dired-hide-subdir] to unhide")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1131 "No file on this line")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1132 (if (eq opoint (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1133 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1134 (point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1135
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1136
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1137 ;; Perhaps something could be done to handle VMS' own backups.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1138
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1139 (defun dired-clean-directory (keep)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1140 "Flag numerical backups for deletion.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1141 Spares `dired-kept-versions' latest versions, and `kept-old-versions' oldest.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1142 Positive prefix arg KEEP overrides `dired-kept-versions';
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1143 Negative prefix arg KEEP overrides `kept-old-versions' with KEEP made positive.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1144
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1145 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
1146 with a prefix argument."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1147 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1148 (setq keep (if keep (prefix-numeric-value keep) dired-kept-versions))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1149 (let ((early-retention (if (< keep 0) (- keep) kept-old-versions))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1150 (late-retention (if (<= keep 0) dired-kept-versions keep))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1151 (file-version-assoc-list ()))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1152 (message "Cleaning numerical backups (keeping %d late, %d old)..."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1153 late-retention early-retention)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1154 ;; Look at each file.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1155 ;; If the file has numeric backup versions,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1156 ;; put on file-version-assoc-list an element of the form
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1157 ;; (FILENAME . VERSION-NUMBER-LIST)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1158 (dired-map-dired-file-lines (function dired-collect-file-versions))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1159 ;; Sort each VERSION-NUMBER-LIST,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1160 ;; and remove the versions not to be deleted.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1161 (let ((fval file-version-assoc-list))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1162 (while fval
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1163 (let* ((sorted-v-list (cons 'q (sort (cdr (car fval)) '<)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1164 (v-count (length sorted-v-list)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1165 (if (> v-count (+ early-retention late-retention))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1166 (rplacd (nthcdr early-retention sorted-v-list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1167 (nthcdr (- v-count late-retention)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1168 sorted-v-list)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1169 (rplacd (car fval)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1170 (cdr sorted-v-list)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1171 (setq fval (cdr fval))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1172 ;; Look at each file. If it is a numeric backup file,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1173 ;; find it in a VERSION-NUMBER-LIST and maybe flag it for deletion.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1174 (dired-map-dired-file-lines (function dired-trample-file-versions))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1175 (message "Cleaning numerical backups...done")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1176
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1177 ;;; Subroutines of dired-clean-directory.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1178
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1179 (defun dired-map-dired-file-lines (fun)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1180 ;; Perform FUN with point at the end of each non-directory line.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1181 ;; FUN takes one argument, the filename (complete pathname).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1182 (dired-check-ls-l)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1183 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1184 (let (file buffer-read-only)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1185 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1186 (while (not (eobp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1187 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1188 (and (not (looking-at dired-re-dir))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1189 (not (eolp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1190 (setq file (dired-get-filename nil t)) ; nil on non-file
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1191 (progn (end-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1192 (funcall fun file))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1193 (forward-line 1)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1194
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1195 (defun dired-collect-file-versions (fn)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1196 ;; "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
1197 ;;That is a list of strings which are file names.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1198 ;;The caller may want to flag some of these files for deletion."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1199 (let* ((base-versions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1200 (concat (file-name-nondirectory fn) ".~"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1201 (bv-length (length base-versions))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1202 (possibilities (file-name-all-completions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1203 base-versions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1204 (file-name-directory fn)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1205 (versions (mapcar 'backup-extract-version possibilities)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1206 (if versions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1207 (setq file-version-assoc-list (cons (cons fn versions)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1208 file-version-assoc-list)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1209
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1210 (defun dired-trample-file-versions (fn)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1211 (let* ((start-vn (string-match "\\.~[0-9]+~$" fn))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1212 base-version-list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1213 (and start-vn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1214 (setq base-version-list ; there was a base version to which
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1215 (assoc (substring fn 0 start-vn) ; this looks like a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1216 file-version-assoc-list)) ; subversion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1217 (not (memq (string-to-int (substring fn (+ 2 start-vn)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1218 base-version-list)) ; this one doesn't make the cut
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1219 (progn (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1220 (delete-char 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1221 (insert dired-del-marker)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1222
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1223
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1224 ;; Keeping Dired buffers in sync with the filesystem and with each other
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1225
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1226 (defvar dired-buffers nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1227 ;; Enlarged by dired-advertise
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1228 ;; Queried by function dired-buffers-for-dir. When this detects a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1229 ;; killed buffer, it is removed from this list.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1230 "Alist of directories and their associated dired buffers.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1231
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1232 (defun dired-buffers-for-dir (dir)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1233 ;; 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
1234 ;; The list is in reverse order of buffer creation, most recent last.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1235 ;; As a side effect, killed dired buffers for DIR are removed from
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1236 ;; dired-buffers.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1237 (setq dir (file-name-as-directory dir))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1238 (let ((alist dired-buffers) result elt)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1239 (while alist
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1240 (setq elt (car alist))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1241 (if (dired-in-this-tree dir (car elt))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1242 (let ((buf (cdr elt)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1243 (if (buffer-name buf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1244 (if (assoc dir (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1245 (set-buffer buf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1246 dired-subdir-alist))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1247 (setq result (cons buf result)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1248 ;; else buffer is killed - clean up:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1249 (setq dired-buffers (delq elt dired-buffers)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1250 (setq alist (cdr alist)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1251 result))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1252
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1253 (defun dired-advertise ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1254 ;;"Advertise in variable `dired-buffers' that we dired `default-directory'."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1255 ;; With wildcards we actually advertise too much.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1256 (if (memq (current-buffer) (dired-buffers-for-dir default-directory))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1257 t ; we have already advertised ourselves
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1258 (setq dired-buffers
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1259 (cons (cons default-directory (current-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1260 dired-buffers))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1261
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1262 (defun dired-unadvertise (dir)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1263 ;; Remove DIR from the buffer alist in variable dired-buffers.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1264 ;; This has the effect of removing any buffer whose main directory is DIR.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1265 ;; It does not affect buffers in which DIR is a subdir.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1266 ;; Removing is also done as a side-effect in dired-buffer-for-dir.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1267 (setq dired-buffers
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1268 (delq (assoc dir dired-buffers) dired-buffers)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1269
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1270 (defun dired-fun-in-all-buffers (directory fun &rest args)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1271 ;; In all buffers dired'ing DIRECTORY, run FUN with ARGS.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1272 ;; Return list of buffers where FUN succeeded (i.e., returned non-nil).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1273 (let ((buf-list (dired-buffers-for-dir directory))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1274 (obuf (current-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1275 buf success-list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1276 (while buf-list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1277 (setq buf (car buf-list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1278 buf-list (cdr buf-list))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1279 (unwind-protect
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1280 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1281 (set-buffer buf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1282 (if (apply fun args)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1283 (setq success-list (cons (buffer-name buf) success-list))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1284 (set-buffer obuf)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1285 success-list))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1286
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1287 (defun dired-add-file (filename &optional marker-char)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1288 (dired-fun-in-all-buffers
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1289 (file-name-directory filename)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1290 (function dired-add-entry) filename marker-char))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1291
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1292 (defun dired-add-entry (filename &optional marker-char)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1293 ;; Add a new entry for FILENAME, optionally marking it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1294 ;; with MARKER-CHAR (a character, else dired-marker-char is used).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1295 ;; Note that this adds the entry `out of order' if files sorted by
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1296 ;; time, etc.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1297 ;; At least this version inserts in the right subdirectory (if present).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1298 ;; And it skips "." or ".." (see `dired-trivial-filenames').
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1299 ;; Hidden subdirs are exposed if a file is added there.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1300 (setq filename (directory-file-name filename))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1301 ;; Entry is always for files, even if they happen to also be directories
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1302 (let ((opoint (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1303 (cur-dir (dired-current-directory))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1304 (directory (file-name-directory filename))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1305 reason)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1306 (setq filename (file-name-nondirectory filename)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1307 reason
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1308 (catch 'not-found
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1309 (if (string= directory cur-dir)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1310 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1311 (if (dired-subdir-hidden-p cur-dir)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1312 (dired-unhide-subdir))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1313 ;; We are already where we should be, except when
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1314 ;; point is before the subdir line or its total line.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1315 (let ((p (dired-after-subdir-garbage cur-dir)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1316 (if (< (point) p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1317 (goto-char p))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1318 ;; else try to find correct place to insert
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1319 (if (dired-goto-subdir directory)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1320 (progn;; unhide if necessary
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1321 (if (looking-at "\r");; point is at end of subdir line
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1322 (dired-unhide-subdir))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1323 ;; found - skip subdir and `total' line
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1324 ;; and uninteresting files like . and ..
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1325 ;; This better not moves into the next subdir!
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1326 (dired-goto-next-nontrivial-file))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1327 ;; not found
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1328 (throw 'not-found "Subdir not found")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1329 ;; found and point is at The Right Place:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1330 (let (buffer-read-only)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1331 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1332 (dired-add-entry-do-indentation marker-char)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1333 (dired-ls (dired-make-absolute filename directory);; don't expand `.' !
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1334 (concat dired-actual-switches "d"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1335 (forward-line -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1336 ;; We want to have the non-directory part, only:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1337 (let* ((beg (dired-move-to-filename t)) ; error for strange output
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1338 (end (dired-move-to-end-of-filename)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1339 (setq filename (buffer-substring beg end))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1340 (delete-region beg end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1341 (insert (file-name-nondirectory filename)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1342 (if dired-after-readin-hook;; the subdir-alist is not affected...
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1343 (save-excursion;; ...so we can run it right now:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1344 (save-restriction
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1345 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1346 (narrow-to-region (point) (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1347 (forward-line 1) (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1348 (run-hooks 'dired-after-readin-hook))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1349 (dired-move-to-filename))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1350 ;; return nil if all went well
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1351 nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1352 (if reason ; don't move away on failure
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1353 (goto-char opoint))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1354 (not reason))) ; return t on succes, nil else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1355
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1356 ;; This is a separate function for the sake of nested dired format.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1357 (defun dired-add-entry-do-indentation (marker-char)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1358 ;; two spaces or a marker plus a space:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1359 (insert (if marker-char
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1360 (if (integerp marker-char) marker-char dired-marker-char)
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 ?\040))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1363
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1364 (defun dired-after-subdir-garbage (dir)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1365 ;; Return pos of first file line of DIR, skipping header and total
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1366 ;; or wildcard lines.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1367 ;; Important: never moves into the next subdir.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1368 ;; DIR is assumed to be unhidden.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1369 ;; Will probably be redefined for VMS etc.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1370 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1371 (or (dired-goto-subdir dir) (error "This cannot happen"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1372 (forward-line 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1373 (while (and (not (eolp)) ; don't cross subdir boundary
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1374 (not (dired-move-to-filename)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1375 (forward-line 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1376 (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1377
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1378 (defun dired-remove-file (file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1379 (dired-fun-in-all-buffers
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1380 (file-name-directory file) (function dired-remove-entry) file))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1381
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1382 (defun dired-remove-entry (file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1383 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1384 (and (dired-goto-file file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1385 (let (buffer-read-only)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1386 (delete-region (progn (beginning-of-line) (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1387 (save-excursion (forward-line 1) (point)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1388
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1389 (defun dired-relist-file (file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1390 (dired-fun-in-all-buffers (file-name-directory file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1391 (function dired-relist-entry) file))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1392
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1393 (defun dired-relist-entry (file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1394 ;; 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
1395 ;; FILE must be an absolute pathname.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1396 (let (buffer-read-only marker)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1397 ;; If cursor is already on FILE's line delete-region will cause
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1398 ;; save-excursion to fail because of floating makers,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1399 ;; moving point to beginning of line. Sigh.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1400 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1401 (and (dired-goto-file file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1402 (delete-region (progn (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1403 (setq marker (following-char))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1404 (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1405 (save-excursion (forward-line 1) (point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1406 (setq file (directory-file-name file))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1407 (dired-add-entry file (if (eq ?\040 marker) nil marker)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1408
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1409 (defun dired-update-file-line (file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1410 ;; Delete the current line, and insert an entry for FILE.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1411 ;; If FILE is nil, then just delete the current line.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1412 ;; Keeps any marks that may be present in column one (doing this
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1413 ;; here is faster than with dired-add-entry's optional arg).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1414 ;; Does not update other dired buffers. Use dired-relist-entry for that.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1415 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1416 (let ((char (following-char)) (opoint (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1417 (delete-region (point) (progn (forward-line 1) (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1418 (if file
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1419 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1420 (dired-add-entry file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1421 ;; Replace space by old marker without moving point.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1422 ;; Faster than goto+insdel inside a save-excursion?
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1423 (subst-char-in-region opoint (1+ opoint) ?\040 char))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1424 (dired-move-to-filename))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1425
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1426
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1427 ;; Running subprocesses, checking and logging of their errors.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1428
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1429 (defvar dired-log-buf "*Dired log*")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1430
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1431 (defun dired-why ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1432 "Pop up a buffer with error log output from Dired.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1433 A group of errors from a single command ends with a formfeed.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1434 Thus, use \\[backward-page] to find the beginning of a group of errors."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1435 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1436 (let ((obuf (current-buffer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1437 (pop-to-buffer dired-log-buf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1438 (goto-char (point-max))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1439 (recenter -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1440 (switch-to-buffer-other-window obuf)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1441
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1442 (defun dired-log (log &rest args)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1443 ;; Log a message or the contents of a buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1444 ;; 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
1445 ;; those ARGS. Usually the LOG string ends with a \n.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1446 ;; End each bunch of errors with (dired-log t): this inserts
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1447 ;; current time and buffer, and a \f (formfeed).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1448 (let ((obuf (current-buffer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1449 (unwind-protect ; want to move point
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1450 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1451 (set-buffer (get-buffer-create dired-log-buf))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1452 (goto-char (point-max))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1453 (let (buffer-read-only)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1454 (cond ((stringp log)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1455 (insert (if args
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1456 (apply (function format) log args)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1457 log)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1458 ((bufferp log)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1459 (insert-buffer log))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1460 ((eq t log)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1461 (insert "\n\t" (current-time-string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1462 "\tBuffer `" (buffer-name obuf) "'\n\f\n")))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1463 (set-buffer obuf))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1464
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1465 (defun dired-log-summary (log &rest args)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1466 ;; Log a summary describing a bunch of errors.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1467 (apply (function dired-log) (concat "\n" log) args)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1468 (dired-log t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1469
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1470 ;; In Emacs 19 this will return program's exit status.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1471 ;; This is a separate function so that ange-ftp can redefine it.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1472 (defun dired-call-process (program discard &rest arguments)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1473 ; "Run PROGRAM with output to current buffer unless DISCARD is t.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1474 ;Remaining arguments are strings passed as command arguments to PROGRAM."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1475 (apply 'call-process program nil (not discard) nil arguments))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1476
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1477 (defun dired-check-process-checker (exit-status)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1478 ;; In Emacs 19, EXIT-STATUS comes from (dired-)call-process
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1479 ;; Then this function should return (/= 0 exit-status)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1480 ;; In Emacs 18 the exit status is not accessible, so we
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1481 ;; do the following which is not always correct as some compress
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1482 ;; programs are verbose by default or otherwise braindamaged
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1483 (if (and dired-emacs-19-p exit-status)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1484 (/= 0 exit-status);; #### install (does it work in Emacs 19?)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1485 (/= 0 (buffer-size))) ; run in program's output buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1486 ;; If have you one of those compress programs, you might
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1487 ;; want to redefine this function to look closer at compress' output.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1488 ;; This is why it is a separate function.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1489 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1490
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1491 (defun dired-check-process (msg program &rest arguments)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1492 ; "Display MSG while running PROGRAM, and check for output.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1493 ;Remaining arguments are strings passed as command arguments to PROGRAM.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1494 ; On error as determined by dired-check-process-checker, insert output
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1495 ; in a log buffer and return the offending ARGUMENTS or PROGRAM.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1496 ; Caller can cons up a list of failed args.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1497 ;Else returns nil for success."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1498 (let (err-buffer err (dir default-directory))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1499 (message "%s..." msg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1500 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1501 ;; Get a clean buffer for error output:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1502 (setq err-buffer (get-buffer-create " *dired-check-process output*"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1503 (set-buffer err-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1504 (erase-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1505 (setq default-directory dir ; caller's default-directory
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1506 err (dired-check-process-checker
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1507 (apply (function dired-call-process) program nil arguments)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1508 (if err
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1509 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1510 (dired-log (concat program " " (prin1-to-string arguments) "\n"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1511 (dired-log err-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1512 (or arguments program t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1513 (kill-buffer err-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1514 (message "%s...done" msg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1515 nil))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1516
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1517 ;;; 7K
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1518 ;;;###begin dired-cmd.el
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1519 ;; Diffing and compressing
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1520
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1521 (defun dired-diff (file &optional switches)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1522 "Compare file at point with file FILE using `diff'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1523 FILE defaults to the file at the mark.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1524 The prompted-for file is the first file given to `diff'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1525 Prefix arg lets you edit the diff switches. See the command `diff'."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1526 (interactive
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1527 (let ((default (if (mark)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1528 (save-excursion (goto-char (mark))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1529 (dired-get-filename t t)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1530 (list (read-file-name (format "Diff %s with: %s"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1531 (dired-get-filename t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1532 (if default
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1533 (concat "(default " default ") ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1534 ""))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1535 (dired-current-directory) default t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1536 (if (fboundp 'diff-read-switches)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1537 (diff-read-switches "Options for diff: ")))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1538 (if switches ; Emacs 19's diff has but two
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1539 (diff file (dired-get-filename t) switches) ; args (yet ;-)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1540 (diff file (dired-get-filename t))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1541
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1542 (defun dired-backup-diff (&optional switches)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1543 "Diff this file with its backup file or vice versa.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1544 Uses the latest backup, if there are several numerical backups.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1545 If this file is a backup, diff it with its original.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1546 The backup file is the first file given to `diff'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1547 Prefix arg lets you edit the diff switches. See the command `diff'."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1548 (interactive (list (if (fboundp 'diff-read-switches)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1549 (diff-read-switches "Diff with switches: "))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1550 (let (bak ori (file (dired-get-filename)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1551 (if (backup-file-name-p file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1552 (setq bak file
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1553 ori (file-name-sans-versions file))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1554 (setq bak (or (latest-backup-file file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1555 (error "No backup found for %s" file))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1556 ori file))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1557 (if switches
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1558 (diff bak ori switches)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1559 (diff bak ori))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1560
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1561 ;;#### install (move this function into files.el)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1562 (defun latest-backup-file (fn) ; actually belongs into files.el
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1563 "Return the latest existing backup of FILE, or nil."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1564 ;; First try simple backup, then the highest numbered of the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1565 ;; numbered backups.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1566 ;; Ignore the value of version-control because we look for existing
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1567 ;; backups, which maybe were made earlier or by another user with
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1568 ;; a different value of version-control.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1569 (setq fn (expand-file-name fn))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1570 (or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1571 (let ((bak (make-backup-file-name fn)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1572 (if (file-exists-p bak) bak))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1573 (let* ((dir (file-name-directory fn))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1574 (base-versions (concat (file-name-nondirectory fn) ".~"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1575 (bv-length (length base-versions)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1576 (concat dir
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1577 (car (sort
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1578 (file-name-all-completions base-versions dir)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1579 ;; bv-length is a fluid var for backup-extract-version:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1580 (function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1581 (lambda (fn1 fn2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1582 (> (backup-extract-version fn1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1583 (backup-extract-version fn2))))))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1584
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1585 ;; This is a separate function for the sake of ange-ftp.el
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1586 (defun dired-compress-make-compressed-filename (from-file &optional reverse)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1587 ;; "Converts a filename FROM-FILE to the filename of the associated
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1588 ;; compressed file. With an optional argument REVERSE, the reverse
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1589 ;; conversion is done."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1590
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1591 (if reverse
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1592
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1593 ;; uncompress...
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1594 ;; return `nil' if no match found -- better than nothing
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1595 (let (case-fold-search ; case-sensitive search
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1596 (string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1597 (concat "\\.\\(g?z\\|" (regexp-quote dired-gzip-file-extension)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1598 "$\\|Z\\)$")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1599
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1600 (and (string-match string from-file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1601 (substring from-file 0 (match-beginning 0))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1602
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1603 ;; compress...
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1604 ;; note: it could be that `gz' is not the proper extension for gzip
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1605 (concat from-file
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1606 (if dired-use-gzip-instead-of-compress
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1607 dired-gzip-file-extension ".Z"))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1608
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1609
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1610 (defun dired-compress ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1611 ;; Compress current file. Return nil for success, offending filename else.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1612 (dired-check-ls-l)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1613 (let* (buffer-read-only
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1614 (from-file (dired-get-filename))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1615 (to-file (dired-compress-make-compressed-filename from-file)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1616 (cond ((save-excursion (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1617 (looking-at dired-re-sym))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1618 (dired-log (concat "Attempt to compress a symbolic link:\n"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1619 from-file))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1620 (dired-make-relative from-file))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1621 (
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1622
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1623 (if dired-use-gzip-instead-of-compress
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1624 ;; gzip (GNU zip)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1625 ;; use `-q' (quiet) switch for gzip in case GZIP environment
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1626 ;; variable contains `--verbose' - lrd - Feb 18, 1993
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1627 (dired-check-process (concat "Gzip'ing " from-file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1628 "gzip" "--quiet" "--force" "--suffix"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1629 dired-gzip-file-extension from-file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1630
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1631 (dired-check-process (concat "Compressing " from-file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1632 "compress" "-f" from-file))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1633 ;; errors from the process are already logged by dired-check-process
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1634 (dired-make-relative from-file))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1635 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1636 (dired-update-file-line to-file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1637 nil))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1638
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1639 (defun dired-uncompress ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1640 ;; Uncompress current file. Return nil for success, offending filename else.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1641 (let* (buffer-read-only
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1642 (from-file (dired-get-filename))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1643 (to-file (dired-compress-make-compressed-filename from-file t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1644 (if
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1645 (if dired-use-gzip-instead-of-compress
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1646 ;; gzip (GNU zip)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1647 ;; use `-q' (quiet) switch for gzip in case GZIP environment
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1648 ;; variable contains `--verbose' - lrd - Feb 18, 1993
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1649 (dired-check-process (concat "Gunzip'ing " from-file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1650 "gzip" "--decompress" "--quiet" "--suffix"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1651 dired-gzip-file-extension from-file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1652
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1653 (dired-check-process (concat "Uncompressing " from-file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1654 "uncompress" from-file))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1655
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1656 (dired-make-relative from-file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1657 (dired-update-file-line to-file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1658 nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1659
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1660 (defun dired-mark-map-check (fun arg op-symbol &optional show-progress)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1661 ; "Map FUN over marked files (with second ARG like in dired-mark-map)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1662 ; and display failures.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1663
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1664 ; FUN takes zero args. It returns non-nil (the offending object, e.g.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1665 ; the short form of the filename) for a failure and probably logs a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1666 ; detailed error explanation using function `dired-log'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1667
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1668 ; OP-SYMBOL is a symbol describing the operation performed (e.g.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1669 ; `compress'). It is used with `dired-mark-pop-up' to prompt the user
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1670 ; (e.g. with `Compress * [2 files]? ') and to display errors (e.g.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1671 ; `Failed to compress 1 of 2 files - type W to see why ("foo")')
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1672
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1673 ; SHOW-PROGRESS if non-nil means redisplay dired after each file."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1674 (if (dired-mark-confirm op-symbol arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1675 (let* ((total-list;; all of FUN's return values
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1676 (dired-mark-map (funcall fun) arg show-progress))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1677 (total (length total-list))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1678 (failures (delq nil total-list))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1679 (count (length failures)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1680 (if (not failures)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1681 (message "%s: %d file%s."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1682 (capitalize (symbol-name op-symbol))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1683 total (dired-plural-s total))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1684 (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
1685 (symbol-name op-symbol) count total (dired-plural-s total)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1686 ;; this gives a short list of failed files in parens
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1687 ;; which may be sufficient for the user even
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1688 ;; without typing `W' for the process' diagnostics
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1689 failures)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1690 ;; end this bunch of errors:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1691 (dired-log-summary
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1692 "Failed to %s %d of %d file%s"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1693 (symbol-name op-symbol) count total (dired-plural-s total))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1694
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1695 (defun dired-do-compress (&optional arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1696 "Compress marked (or next ARG) files.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1697 Type \\[dired-do-uncompress] to uncompress again."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1698 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1699 (dired-mark-map-check (function dired-compress) arg 'compress t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1700
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1701 (defun dired-do-uncompress (&optional arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1702 "Uncompress marked (or next ARG) files."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1703 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1704 (dired-mark-map-check (function dired-uncompress) arg 'uncompress t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1705
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1706 ;; Commands for Emacs Lisp files - load and byte compile
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1707
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1708 (defun dired-byte-compile ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1709 ;; Return nil for success, offending file name else.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1710 (let* ((filename (dired-get-filename))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1711 (elc-file
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1712 (if (eq system-type 'vax-vms)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1713 (concat (substring filename 0 (string-match ";" filename)) "c")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1714 (concat filename "c")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1715 buffer-read-only failure)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1716 (condition-case err
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1717 (save-excursion (byte-compile-file filename))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1718 (error
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1719 (setq failure err)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1720 (if failure
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1721 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1722 (dired-log "Byte compile error for %s:\n%s\n" filename failure)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1723 (dired-make-relative filename))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1724 (dired-remove-file elc-file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1725 (forward-line) ; insert .elc after its .el file
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1726 (dired-add-file elc-file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1727 nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1728
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1729 (defun dired-do-byte-compile (&optional arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1730 "Byte compile marked (or next ARG) Emacs lisp files."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1731 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1732 (dired-mark-map-check (function dired-byte-compile) arg 'byte-compile t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1733
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1734 (defun dired-load ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1735 ;; Return nil for success, offending file name else.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1736 (let ((file (dired-get-filename)) failure)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1737 (condition-case err
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1738 (load file nil nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1739 (error (setq failure err)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1740 (if (not failure)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1741 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1742 (dired-log "Load error for %s:\n%s\n" file failure)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1743 (dired-make-relative file))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1744
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1745 (defun dired-do-load (&optional arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1746 "Load the marked (or next ARG) Emacs lisp files."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1747 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1748 (dired-mark-map-check (function dired-load) arg 'load t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1749
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1750 (defun dired-do-chxxx (attribute-name program op-symbol arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1751 ;; Change file attributes (mode, group, owner) of marked files and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1752 ;; refresh their file lines.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1753 ;; ATTRIBUTE-NAME is a string describing the attribute to the user.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1754 ;; PROGRAM is the program used to change the attribute.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1755 ;; 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
1756 ;; ARG describes which files to use, like in dired-mark-get-files.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1757 (let* ((files (dired-mark-get-files t arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1758 (new-attribute
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1759 (dired-mark-read-string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1760 (concat "Change " attribute-name " of %s to: ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1761 nil op-symbol arg files))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1762 (operation (concat program " " new-attribute))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1763 (failure (apply (function dired-check-process)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1764 operation program new-attribute
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1765 files)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1766 (dired-do-redisplay arg);; moves point if ARG is an integer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1767 (if failure
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1768 (dired-log-summary
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1769 (message "%s: error - type W to see why." operation)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1770
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1771 (defun dired-do-chmod (&optional arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1772 "Change the mode of the marked (or next ARG) files.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1773 This calls chmod, thus symbolic modes like `g+w' are allowed."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1774 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1775 (dired-do-chxxx "Mode" "chmod" 'chmod arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1776
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1777 (defun dired-do-chgrp (&optional arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1778 "Change the group of the marked (or next ARG) files."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1779 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1780 (dired-do-chxxx "Group" "chgrp" 'chgrp arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1781
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1782 (defun dired-do-chown (&optional arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1783 "Change the owner of the marked (or next ARG) files."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1784 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1785 (dired-do-chxxx "Owner" dired-chown-program 'chown arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1786
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1787 ;;;###end dired-cmd.el
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1788
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1789
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1790 ;; Deleting files
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1791
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1792 ;; #### called dired-do-flagged-delete in FSF
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1793 (defun dired-do-deletions (&optional nomessage)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1794 "In dired, delete the files flagged for deletion.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1795 If NOMESSAGE is non-nil, we don't display any message
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1796 if there are no flagged files."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1797 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1798 (let* ((dired-marker-char dired-del-marker)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1799 (regexp (dired-marker-regexp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1800 case-fold-search)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1801 (if (save-excursion (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1802 (re-search-forward regexp nil t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1803 (dired-internal-do-deletions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1804 ;; this can't move point since ARG is nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1805 (dired-mark-map (cons (dired-get-filename) (point))
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 nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1808 (or nomessage
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1809 (message "(No deletions requested)")))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1810
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1811 (defun dired-do-delete (&optional arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1812 "Delete all marked (or next ARG) files."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1813 ;; This is more consistent with the file marking feature than
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1814 ;; dired-do-deletions.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1815 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1816 (dired-internal-do-deletions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1817 ;; this may move point if ARG is an integer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1818 (dired-mark-map (cons (dired-get-filename) (point))
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 arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1821
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1822 (defvar dired-deletion-confirmer 'yes-or-no-p) ; or y-or-n-p?
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1823
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1824 (defun dired-internal-do-deletions (l arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1825 ;; L is an alist of files to delete, with their buffer positions.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1826 ;; ARG is the prefix arg.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1827 ;; Filenames are absolute (VMS needs this for logical search paths).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1828 ;; (car L) *must* be the *last* (bottommost) file in the dired buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1829 ;; 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
1830 ;; lines still to be changed, so the (point) values in L stay valid.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1831 ;; Also, for subdirs in natural order, a subdir's files are deleted
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1832 ;; before the subdir itself - the other way around would not work.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1833 (let ((files (mapcar (function car) l))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1834 (count (length l))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1835 (succ 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1836 ;; canonicalize file list for pop up
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1837 (setq files (nreverse (mapcar (function dired-make-relative) files)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1838 (if (dired-mark-pop-up
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1839 " *Deletions*" 'delete files dired-deletion-confirmer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1840 (format "Delete %s " (dired-mark-prompt arg files)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1841 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1842 (let (failures);; files better be in reverse order for this loop!
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1843 (while l
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1844 (goto-char (cdr (car l)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1845 (let (buffer-read-only)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1846 (condition-case err
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1847 (let ((fn (car (car l))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1848 ;; This test is equivalent to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1849 ;; (and (file-directory-p fn) (not (file-symlink-p fn)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1850 ;; but more efficient
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1851 (if (eq t (car (file-attributes fn)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1852 (remove-directory fn)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1853 (delete-file fn))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1854 ;; if we get here, removing worked
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1855 (setq succ (1+ succ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1856 (message "%s of %s deletions" succ count)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1857 (delete-region (progn (beginning-of-line) (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1858 (progn (forward-line 1) (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1859 (dired-clean-up-after-deletion fn))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1860 (error;; catch errors from failed deletions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1861 (dired-log "%s\n" err)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1862 (setq failures (cons (car (car l)) failures)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1863 (setq l (cdr l)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1864 (if (not failures)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1865 (message "%d deletion%s done" count (dired-plural-s count))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1866 (dired-log-summary
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1867 (message "%d of %d deletion%s failed: %s"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1868 (length failures) count
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1869 (dired-plural-s count)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1870 (prin1-to-string failures))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1871 (message "(No deletions performed)")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1872 (dired-move-to-filename))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1873
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1874 ;; This is a separate function for the sake of dired-x.el.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1875 (defun dired-clean-up-after-deletion (fn)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1876 ;; Clean up after a deleted file or directory FN.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1877 (save-excursion (and (dired-goto-subdir fn)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1878 (dired-kill-subdir))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1879
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1880
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1881 (defun dired-replace-in-string (regexp newtext string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1882 ;; Replace REGEXP with NEWTEXT everywhere in STRING and return result.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1883 ;; NEWTEXT is taken literally---no \\DIGIT escapes will be recognized.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1884 (let ((result "") (start 0) mb me)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1885 (while (string-match regexp string start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1886 (setq mb (match-beginning 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1887 me (match-end 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1888 result (concat result (substring string start mb) newtext)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1889 start me))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1890 (concat result (substring string start))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1891
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1892 (defun dired-next-dirline (arg &optional opoint)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1893 "Goto ARG'th next directory file line."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1894 (interactive "_p")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1895 (dired-check-ls-l)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1896 (or opoint (setq opoint (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1897 (if (if (> arg 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1898 (re-search-forward dired-re-dir nil t arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1899 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1900 (re-search-backward dired-re-dir nil t (- arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1901 (dired-move-to-filename) ; user may type `i' or `f'
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1902 (goto-char opoint)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1903 (error "No more subdirectories")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1904
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1905 (defun dired-prev-dirline (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1906 "Goto ARG'th previous directory file line."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1907 (interactive "_p")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1908 (dired-next-dirline (- arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1909
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1910 (defun dired-unflag-all-files (flag &optional arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1911 "Remove a specific or all flags from every file.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1912 With an arg, queries for each marked file.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1913 Type \\[help-command] at that time for help."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1914 (interactive "sRemove flag: (default: all flags) \nP")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1915 (let ((count 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1916 (re (if (zerop (length flag)) dired-re-mark
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1917 (concat "^" (regexp-quote flag)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1918 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1919 (let (buffer-read-only case-fold-search query
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1920 (help-form "\
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1921 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
1922 `!' to unflag all remaining files with no more questions."))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1923 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1924 (while (re-search-forward re nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1925 (if (or (not arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1926 (dired-query 'query "Unflag file `%s' ? "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1927 (dired-get-filename t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1928 (progn (delete-char -1) (insert " ") (setq count (1+ count))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1929 (forward-line 1))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1930 (message "%s" (format "Flags removed: %d %s" count flag) )))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1931
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1932 ;; pop ups and user input for file marking
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1933
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1934 (defun dired-marker-regexp ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1935 (concat "^" (regexp-quote (char-to-string dired-marker-char))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1936
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1937 (defun dired-plural-s (count)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1938 (if (= 1 count) "" "s"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1939
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1940 (defun dired-mark-prompt (arg files)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1941 ;; Return a string for use in a prompt, either the current file
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1942 ;; name, or the marker and a count of marked files.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1943 (let ((count (length files)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1944 (if (= count 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1945 (car files)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1946 ;; more than 1 file:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1947 (if (integerp arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1948 ;; abs(arg) = count
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1949 ;; Perhaps this is nicer, but it also takes more screen space:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1950 ;;(format "[%s %d files]" (if (> arg 0) "next" "previous")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1951 ;; count)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1952 (format "[next %d files]" arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1953 (format "%c [%d files]" dired-marker-char count)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1954
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1955 (defvar dired-query-alist
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1956 '((?\y . y) (?\040 . y) ; `y' or SPC means accept once
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1957 (?n . n) (?\177 . n) ; `n' or DEL skips once
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1958 (?! . yes) ; `!' accepts rest
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1959 (?q. no) (?\e . no) ; `q' or ESC skips rest
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1960 ;; None of these keys quit - use C-g for that.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1961 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1962
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1963 (defun dired-query (qs-var qs-prompt &rest qs-args)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1964 ;; Query user and return nil or t.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1965 ;; Store answer in symbol VAR (which must initially be bound to nil).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1966 ;; Format PROMPT with ARGS.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1967 ;; Binding variable help-form will help the user who types C-h.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1968 (let* ((char (symbol-value qs-var))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1969 (action (cdr (assoc char dired-query-alist))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1970 (cond ((eq 'yes action)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1971 t) ; accept, and don't ask again
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1972 ((eq 'no action)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1973 nil) ; skip, and don't ask again
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1974 (t;; no lasting effects from last time we asked - ask now
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1975 (let ((qprompt (concat qs-prompt
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1976 (if help-form
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1977 (format " [Type yn!q or %s] "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1978 (key-description
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1979 (char-to-string help-char)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1980 " [Type y, n, q or !] ")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1981 result elt)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1982 ;; Actually it looks nicer without cursor-in-echo-area - you can
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1983 ;; look at the dired buffer instead of at the prompt to decide.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1984 (apply 'message qprompt qs-args)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1985 (setq char (set qs-var (read-char)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1986 (while (not (setq elt (assoc char dired-query-alist)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1987 (message "Invalid char - type %c for help." help-char)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1988 (ding)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1989 (sit-for 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1990 (apply 'message qprompt qs-args)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1991 (setq char (set qs-var (read-char))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1992 (memq (cdr elt) '(t y yes)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1993
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1994 (defun dired-pop-to-buffer (buf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1995 ;; Pop up buffer BUF.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1996 ;; If dired-shrink-to-fit is t, make its window fit its contents.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1997 (if (not dired-shrink-to-fit)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1998 (pop-to-buffer (get-buffer-create buf))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1999 ;; let window shrink to fit:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2000 (let ((window (selected-window))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2001 target-lines w2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2002 (cond ;; if split-window-threshold is enabled, use the largest window
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2003 ((and (> (window-height (setq w2 (get-largest-window)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2004 split-height-threshold)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2005 (= (screen-width) (window-width w2)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2006 (setq window w2))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2007 ;; if the least-recently-used window is big enough, use it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2008 ((and (> (window-height (setq w2 (get-lru-window)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2009 (* 2 window-min-height))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2010 (= (screen-width) (window-width w2)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2011 (setq window w2)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2012 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2013 (set-buffer buf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2014 (goto-char (point-max))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2015 (skip-chars-backward "\n\r\t ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2016 (setq target-lines (count-lines (point-min) (point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2017 (if (<= (window-height window) (* 2 window-min-height))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2018 ;; At this point, every window on the screen is too small to split.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2019 (setq w2 (display-buffer buf))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2020 (setq w2 (split-window window
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2021 (max window-min-height
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2022 (- (window-height window)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2023 (1+ (max window-min-height target-lines)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2024 (set-window-buffer w2 buf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2025 (if (< (1- (window-height w2)) target-lines)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2026 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2027 (select-window w2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2028 (enlarge-window (- target-lines (1- (window-height w2))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2029 (set-window-start w2 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2030 )))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2031
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2032 (defvar dired-no-confirm nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2033 ;; "If non-nil, list of symbols for commands dired should not confirm.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2034 ;;It can be a sublist of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2035 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2036 ;; '(byte-compile chgrp chmod chown compress copy delete hardlink load
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2037 ;; move print shell symlink uncompress)"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2038 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2039
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2040 (defun dired-mark-confirm (op-symbol arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2041 ;; Request confirmation from the user that the operation described
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2042 ;; by OP-SYMBOL is to be performed on the marked files.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2043 ;; Confirmation consists in a y-or-n question with a file list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2044 ;; pop-up unless OP-SYMBOL is a member of `dired-no-confirm'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2045 ;; The files used are determined by ARG (like in dired-mark-get-files).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2046 (or (memq op-symbol dired-no-confirm)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2047 (let ((files (dired-mark-get-files t arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2048 (dired-mark-pop-up nil op-symbol files (function y-or-n-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2049 (concat (capitalize (symbol-name op-symbol)) " "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2050 (dired-mark-prompt arg files) "? ")))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2051
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2052 (defun dired-mark-pop-up (bufname op-symbol files function &rest args)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2053 ;;"Args BUFNAME OP-SYMBOL FILES FUNCTION &rest ARGS.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2054 ;;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
2055 ;;named BUFNAME, nil gives \" *Marked Files*\") showing the marked
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2056 ;;files. Uses function `dired-pop-to-buffer' to do that.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2057 ;; FUNCTION should not manipulate files.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2058 ;; It should only read input (an argument or confirmation).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2059 ;;The window is not shown if there is just one file or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2060 ;; OP-SYMBOL is a member of the list in `dired-no-confirm'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2061 ;;FILES is the list of marked files."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2062 (or bufname (setq bufname " *Marked Files*"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2063 (if (or (memq op-symbol dired-no-confirm)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2064 (= (length files) 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2065 (apply function args)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2066 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2067 (set-buffer (get-buffer-create bufname))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2068 (erase-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2069 (dired-format-columns-of-files files))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2070 (save-window-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2071 (dired-pop-to-buffer bufname)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2072 (apply function args))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2073
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2074 (defun dired-format-columns-of-files (files)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2075 ;; Files should be in forward order for this loop.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2076 ;; i.e., (car files) = first file in buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2077 ;; Returns the number of lines used.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2078 (let* ((maxlen (+ 2 (apply 'max (mapcar 'length files))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2079 (width (- (window-width (selected-window)) 2))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2080 (columns (max 1 (/ width maxlen)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2081 (nfiles (length files))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2082 (rows (+ (/ nfiles columns)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2083 (if (zerop (% nfiles columns)) 0 1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2084 (i 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2085 (j 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2086 (setq files (nconc (copy-sequence files) ; fill up with empty fns
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2087 (make-list (- (* columns rows) nfiles) "")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2088 (setcdr (nthcdr (1- (length files)) files) files) ; make circular
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2089 (while (< j rows)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2090 (while (< i columns)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2091 (indent-to (* i maxlen))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2092 (insert (car files))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2093 (setq files (nthcdr rows files)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2094 i (1+ i)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2095 (insert "\n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2096 (setq i 0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2097 j (1+ j)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2098 files (cdr files)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2099 rows))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2100
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2101 ;; Read arguments for a mark command of type OP-SYMBOL,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2102 ;; perhaps popping up the list of marked files.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2103 ;; ARG is the prefix arg and indicates whether the files came from
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2104 ;; marks (ARG=nil) or a repeat factor (integerp ARG).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2105 ;; 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
2106 ;; 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
2107
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2108 (defun dired-mark-read-string (prompt initial op-symbol arg files)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2109 ;; PROMPT for a string, with INITIAL input.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2110 ;; Other args are used to give user feedback and pop-up:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2111 ;; OP-SYMBOL of command, prefix ARG, marked FILES.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2112 (dired-mark-pop-up
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2113 nil op-symbol files
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2114 (function read-string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2115 (format prompt (dired-mark-prompt arg files)) initial))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2116
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2117 (defun dired-mark-read-file-name (prompt dir op-symbol arg files)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2118 (dired-mark-pop-up
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2119 nil op-symbol files
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2120 (function read-file-name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2121 (format prompt (dired-mark-prompt arg files)) dir))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2122
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2123 (defun dired-mark-file (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2124 "In dired, mark the current line's file for later commands.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2125 With arg, repeat over several lines.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2126 Use \\[dired-unflag-all-files] to remove all flags."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2127 (interactive "p")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2128 (let (buffer-read-only)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2129 (dired-repeat-over-lines
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2130 arg
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2131 (function (lambda () (delete-char 1) (insert dired-marker-char))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2132
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2133 (defun dired-next-marked-file (arg &optional wrap opoint)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2134 "Move to the next marked file, wrapping around the end of the buffer."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2135 (interactive "_p\np")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2136 (or opoint (setq opoint (point)));; return to where interactively started
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2137 (if (if (> arg 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2138 (re-search-forward dired-re-mark nil t arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2139 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2140 (re-search-backward dired-re-mark nil t (- arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2141 (dired-move-to-filename)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2142 (if (null wrap)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2143 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2144 (goto-char opoint)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2145 (error "No next marked file"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2146 (message "(Wraparound for next marked file)")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2147 (goto-char (if (> arg 0) (point-min) (point-max)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2148 (dired-next-marked-file arg nil opoint))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2149
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2150 (defun dired-prev-marked-file (arg &optional wrap)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2151 "Move to the previous marked file, wrapping around the end of the buffer."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2152 (interactive "_p\np")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2153 (dired-next-marked-file (- arg) wrap))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2154
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2155 (defun dired-file-marker (file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2156 ;; Return FILE's marker, or nil if unmarked.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2157 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2158 (and (dired-goto-file file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2159 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2160 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2161 (if (not (equal ?\040 (following-char)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2162 (following-char))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2163
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2164 (defun dired-read-regexp (prompt &optional initial)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2165 ;; This is an extra function so that gmhist can redefine it.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2166 (setq dired-flagging-regexp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2167 (read-string prompt (or initial dired-flagging-regexp))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2168
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2169 (defun dired-mark-files-regexp (regexp &optional marker-char)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2170 "Mark all files matching REGEXP for use in later commands.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2171 A prefix argument means to unmark them instead.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2172 `.' and `..' are never marked.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2173
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2174 REGEXP is an Emacs regexp, not a shell wildcard. Thus, use `\\.o$' for
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2175 object files--just `.o' will mark more than you might think."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2176 (interactive
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2177 (list (dired-read-regexp (concat (if current-prefix-arg "Unmark" "Mark")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2178 " files (regexp): "))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2179 (if current-prefix-arg ?\040)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2180 (let ((dired-marker-char (or marker-char dired-marker-char)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2181 (dired-mark-if
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2182 (and (not (looking-at dired-re-dot))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2183 (not (eolp)) ; empty line
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2184 (let ((fn (dired-get-filename nil t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2185 (and fn (string-match regexp (file-name-nondirectory fn)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2186 "matching file")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2187
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2188 (defun dired-flag-regexp-files (regexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2189 "In dired, flag all files containing the specified REGEXP for deletion.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2190 The match is against the non-directory part of the filename. Use `^'
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2191 and `$' to anchor matches. Exclude subdirs by hiding them.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2192 `.' and `..' are never flagged."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2193 (interactive (list (dired-read-regexp "Flag for deletion (regexp): ")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2194 (dired-mark-files-regexp regexp dired-del-marker))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2195
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2196 (defun dired-mark-symlinks (unflag-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2197 "Mark all symbolic links.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2198 With prefix argument, unflag all those files."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2199 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2200 (dired-check-ls-l)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2201 (let ((dired-marker-char (if unflag-p ?\040 dired-marker-char)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2202 (dired-mark-if (looking-at dired-re-sym) "symbolic link")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2203
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2204 (defun dired-mark-directories (unflag-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2205 "Mark all directory file lines except `.' and `..'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2206 With prefix argument, unflag all those files."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2207 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2208 (dired-check-ls-l)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2209 (let ((dired-marker-char (if unflag-p ?\040 dired-marker-char)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2210 (dired-mark-if (and (looking-at dired-re-dir)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2211 (not (looking-at dired-re-dot)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2212 "directory file")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2213
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2214 (defun dired-mark-executables (unflag-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2215 "Mark all executable files.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2216 With prefix argument, unflag all those files."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2217 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2218 (dired-check-ls-l)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2219 (let ((dired-marker-char (if unflag-p ?\040 dired-marker-char)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2220 (dired-mark-if (looking-at dired-re-exe) "executable file")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2221
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2222 ;; dired-x.el has a dired-mark-sexp interactive command: mark
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2223 ;; files for which PREDICATE returns non-nil.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2224
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2225 (defun dired-flag-auto-save-files (&optional unflag-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2226 "Flag for deletion files whose names suggest they are auto save files.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2227 A prefix argument says to unflag those files instead."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2228 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2229 (dired-check-ls-l)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2230 (let ((dired-marker-char (if unflag-p ?\040 dired-del-marker)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2231 (dired-mark-if
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2232 (and (not (looking-at dired-re-dir))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2233 (let ((fn (dired-get-filename t t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2234 (if fn (auto-save-file-name-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2235 (file-name-nondirectory fn)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2236 "auto save file")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2237
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2238 (defun dired-flag-backup-files (&optional unflag-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2239 "Flag all backup files (names ending with `~') for deletion.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2240 With prefix argument, unflag these files."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2241 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2242 (dired-check-ls-l)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2243 (let ((dired-marker-char (if unflag-p ?\040 dired-del-marker)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2244 (dired-mark-if
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2245 (and (not (looking-at dired-re-dir))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2246 (let ((fn (dired-get-filename t t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2247 (if fn (backup-file-name-p fn))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2248 "backup file")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2249
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2250
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2251 ;;; Shell commands
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2252 ;;#### install (move this function into simple.el)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2253 (defun shell-quote (filename) ; actually belongs into simple.el
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2254 "Quote a file name for inferior shell (see variable shell-file-name)."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2255 ;; Quote everything except POSIX filename characters.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2256 ;; This should be safe enough even for really wierd shells.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2257 (let ((result "") (start 0) end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2258 (while (string-match "[^---0-9a-zA-Z_./]" filename start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2259 (setq end (match-beginning 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2260 result (concat result (substring filename start end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2261 "\\" (substring filename end (1+ end)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2262 start (1+ end)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2263 (concat result (substring filename start))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2264
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2265 (defun dired-read-shell-command (prompt arg files)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2266 ;; "Read a dired shell command prompting with PROMPT (using read-string).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2267 ;;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
2268 ;; files are affected.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2269 ;;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
2270 (dired-mark-pop-up
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2271 nil 'shell files
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2272 (function read-string) (format prompt (dired-mark-prompt arg files))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2273
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2274 ;; The in-background argument is only needed in Emacs 18 where
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2275 ;; shell-command doesn't understand an appended ampersand `&'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2276 (defun dired-do-shell-command (&optional arg in-background)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2277 "Run a shell command on the marked files.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2278 If there is output, it goes to a separate buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2279 The list of marked files is appended to the command string unless asterisks
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2280 `*' indicate the place(s) where the list should go.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2281 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
2282 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
2283 The prompt mentions the file(s) or the marker, as appropriate.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2284 With a zero argument, run command on each marked file separately: `cmd *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2285 foo' results in `cmd F1 foo; ...; cmd Fn foo'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2286 No automatic redisplay is attempted, as the file names may have
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2287 changed. Type \\[dired-do-redisplay] to redisplay the marked files.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2288 The shell command has the top level directory as working directory, so
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2289 output files usually are created there instead of in a subdir."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2290 ;;Functions dired-run-shell-command and dired-shell-stuff-it do the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2291 ;;actual work and can be redefined for customization.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2292 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2293 (let* ((on-each (equal arg 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2294 (prompt (concat (if in-background "& on " "! on ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2295 (if on-each "each " "")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2296 "%s: "))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2297 (file-list (dired-mark-get-files t (if on-each nil arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2298 ;; Want to give feedback whether this file or marked files are used:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2299 (command (dired-read-shell-command
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2300 prompt (if on-each nil arg) file-list))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2301 (result
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2302 (dired-shell-stuff-it command file-list on-each arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2303 ;; execute the shell command
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2304 (dired-run-shell-command result in-background)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2305
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2306 ;; Might use {,} for bash or csh:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2307 (defvar dired-mark-prefix ""
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2308 "Prepended to marked files in dired shell commands.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2309 (defvar dired-mark-postfix ""
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2310 "Appended to marked files in dired shell commands.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2311 (defvar dired-mark-separator " "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2312 "Separates marked files in dired shell commands.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2313
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2314 (defun dired-shell-stuff-it (command file-list on-each &optional raw-arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2315 ;; "Make up a shell command line from COMMAND and FILE-LIST.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2316 ;; If ON-EACH is t, COMMAND should be applied to each file, else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2317 ;; simply concat all files and apply COMMAND to this.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2318 ;; FILE-LIST's elements will be quoted for the shell."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2319 ;; Might be redefined for smarter things and could then use RAW-ARG
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2320 ;; (coming from interactive P and currently ignored) to decide what to do.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2321 ;; Smart would be a way to access basename or extension of file names.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2322 ;; See dired-trns.el for an approach to this.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2323 ;; Bug: There is no way to quote a *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2324 ;; On the other hand, you can never accidentally get a * into your cmd.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2325 (let ((stuff-it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2326 (if (string-match "\\*" command)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2327 (function (lambda (x)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2328 (dired-replace-in-string "\\*" x command)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2329 (function (lambda (x) (concat command " " x))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2330 (if on-each
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2331 (mapconcat stuff-it (mapcar (function shell-quote) file-list) ";")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2332 (let ((fns (mapconcat (function shell-quote)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2333 file-list dired-mark-separator)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2334 (if (> (length file-list) 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2335 (setq fns (concat dired-mark-prefix fns dired-mark-postfix)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2336 (funcall stuff-it fns)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2337
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2338 ;; 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
2339 (defun dired-run-shell-command (command &optional in-background)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2340 (if (and in-background (not (string-match "&[ \t]*$" command)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2341 (setq command (concat command " &")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2342 (shell-command command))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2343
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2344 (defun dired-do-print (&optional arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2345 "Print the marked (or next ARG) files.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2346 Uses the shell command coming from variables `lpr-command' and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2347 `lpr-switches' as default."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2348 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2349 (or (listp lpr-switches)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2350 (error "lpr-switches must be a *list* of strings"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2351 (let* ((file-list (dired-mark-get-files t arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2352 (switches (mapconcat (function identity) lpr-switches " "))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2353 (command (dired-mark-read-string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2354 "Print %s with: "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2355 (concat lpr-command " " switches)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2356 'print arg file-list)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2357 (dired-run-shell-command (dired-shell-stuff-it command file-list nil))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2358
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2359
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2360 ;;; 10K
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2361 ;;;###begin dired-cp.el
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2362 ;;; Copy, move/rename, making hard and symbolic links
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2363
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2364 (defvar dired-backup-if-overwrite nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2365 "*Non-nil if Dired should ask about making backups before overwriting files.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2366 Special value 'always suppresses confirmation.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2367
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2368 (defun dired-handle-overwrite (to)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2369 ;; Save old version of a to be overwritten file TO.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2370 ;; `overwrite-confirmed' and `overwrite-backup-query' are fluid vars
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2371 ;; from dired-create-files.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2372 (if (and dired-backup-if-overwrite
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2373 overwrite-confirmed
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2374 (or (eq 'always dired-backup-if-overwrite)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2375 (dired-query 'overwrite-backup-query
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2376 (format "Make backup for existing file `%s'? " to))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2377 (let ((backup (car (find-backup-file-name to))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2378 (rename-file to backup 0) ; confirm overwrite of old backup
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2379 (dired-relist-entry backup))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2380
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2381 (defun dired-copy-file (from to ok-flag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2382 (dired-handle-overwrite to)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2383 (copy-file from to ok-flag dired-copy-preserve-time))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2384
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2385 (defun dired-rename-file (from to ok-flag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2386 (dired-handle-overwrite to)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2387 (rename-file from to ok-flag) ; error is caught in -create-files
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2388 ;; Silently rename the visited file of any buffer visiting this file.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2389 (and (get-file-buffer from)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2390 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2391 (set-buffer (get-file-buffer from))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2392 (let ((modflag (buffer-modified-p)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2393 (set-visited-file-name to) ; kills write-file-hooks
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2394 (set-buffer-modified-p modflag))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2395 (dired-remove-file from)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2396 ;; See if it's an inserted subdir, and rename that, too.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2397 (dired-rename-subdir from to))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2398
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2399 (defun dired-rename-subdir (from-dir to-dir)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2400 (setq from-dir (file-name-as-directory from-dir)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2401 to-dir (file-name-as-directory to-dir))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2402 (dired-fun-in-all-buffers from-dir
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2403 (function dired-rename-subdir-1) from-dir to-dir)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2404 ;; Update visited file name of all affected buffers
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2405 (let ((blist (buffer-list)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2406 (while blist
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2407 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2408 (set-buffer (car blist))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2409 (if (and buffer-file-name
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2410 (dired-in-this-tree buffer-file-name from-dir))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2411 (let ((modflag (buffer-modified-p))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2412 (to-file (dired-replace-in-string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2413 (concat "^" (regexp-quote from-dir))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2414 to-dir
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2415 buffer-file-name)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2416 (set-visited-file-name to-file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2417 (set-buffer-modified-p modflag))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2418 (setq blist (cdr blist)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2419
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2420 (defun dired-rename-subdir-1 (dir to)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2421 ;; Rename DIR to TO in headerlines and dired-subdir-alist, if DIR or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2422 ;; one of its subdirectories is expanded in this buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2423 (let ((alist dired-subdir-alist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2424 (elt nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2425 (while alist
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2426 (setq elt (car alist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2427 alist (cdr alist))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2428 (if (dired-in-this-tree (car elt) dir)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2429 ;; ELT's subdir is affected by the rename
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2430 (dired-rename-subdir-2 elt dir to)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2431 (if (equal dir default-directory)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2432 ;; if top level directory was renamed, lots of things have to be
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2433 ;; updated:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2434 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2435 (dired-unadvertise dir) ; we no longer dired DIR...
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2436 (setq default-directory to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2437 dired-directory (expand-file-name;; this is correct
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2438 ;; with and without wildcards
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2439 (file-name-nondirectory dired-directory)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2440 to))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2441 (let ((new-name (file-name-nondirectory
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2442 (directory-file-name dired-directory))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2443 ;; try to rename buffer, but just leave old name if new
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2444 ;; name would already exist (don't try appending "<%d>")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2445 (or (get-buffer new-name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2446 (rename-buffer new-name)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2447 ;; ... we dired TO now:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2448 (dired-advertise)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2449
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2450 (defun dired-rename-subdir-2 (elt dir to)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2451 ;; Update the headerline and dired-subdir-alist element of directory
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2452 ;; described by alist-element ELT to reflect the moving of DIR to TO.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2453 ;; Thus, ELT describes either DIR itself or a subdir of DIR.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2454
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2455 ;; 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
2456 ;; updating the headerline is actually not the right thing---it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2457 ;; should be removed in that case and a completely new entry be
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2458 ;; added for TO. Actually, removing and adding anew would always be
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2459 ;; the right (but slow) way of doing it.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2460
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2461 ;; The consequences are pretty harmless though (no updates since
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2462 ;; dired-buffers-for-dir will not suspect it to be in this dired
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2463 ;; buffer).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2464
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2465 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2466 (let ((regexp (regexp-quote (directory-file-name dir)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2467 (newtext (directory-file-name to))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2468 buffer-read-only)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2469 (goto-char (dired-get-subdir-min elt))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2470 ;; Update subdir headerline in buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2471 (if (not (looking-at dired-subdir-regexp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2472 (error "%s not found where expected - dired-subdir-alist broken?"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2473 dir)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2474 (goto-char (match-beginning 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2475 (if (re-search-forward regexp (match-end 1) t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2476 (replace-match newtext t t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2477 (error "Expected to find `%s' in headerline of %s" dir (car elt))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2478 ;; Update buffer-local dired-subdir-alist
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2479 (setcar elt
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2480 (dired-normalize-subdir
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2481 (dired-replace-in-string regexp newtext (car elt)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2482
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2483 ;; Cloning replace-match to work on strings instead of in buffer:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2484 ;; The FIXEDCASE parameter of replace-match is not implemented.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2485 (defun dired-string-replace-match (regexp string newtext
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2486 &optional literal global)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2487 "Replace first match of REGEXP in STRING with NEWTEXT.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2488 If it does not match, nil is returned instead of the new string.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2489 Optional arg LITERAL means to take NEWTEXT literally.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2490 Optional arg GLOBAL means to replace all matches."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2491 (if global
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2492 (let ((result "") (start 0) mb me)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2493 (while (string-match regexp string start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2494 (setq mb (match-beginning 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2495 me (match-end 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2496 result (concat result
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2497 (substring string start mb)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2498 (if literal
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2499 newtext
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2500 (dired-expand-newtext string newtext)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2501 start me))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2502 (if mb ; matched at least once
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2503 (concat result (substring string start))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2504 nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2505 ;; not GLOBAL
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2506 (if (not (string-match regexp string 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2507 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2508 (concat (substring string 0 (match-beginning 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2509 (if literal newtext (dired-expand-newtext string newtext))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2510 (substring string (match-end 0))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2511
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2512 (defun dired-expand-newtext (string newtext)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2513 ;; Expand \& and \1..\9 (referring to STRING) in NEWTEXT, using match data.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2514 ;; Note that in Emacs 18 match data are clipped to current buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2515 ;; size...so the buffer should better not be smaller than STRING.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2516 (let ((pos 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2517 (len (length newtext))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2518 (expanded-newtext ""))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2519 (while (< pos len)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2520 (setq expanded-newtext
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2521 (concat expanded-newtext
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2522 (let ((c (aref newtext pos)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2523 (if (= ?\\ c)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2524 (cond ((= ?\& (setq c
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2525 (aref newtext
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2526 (setq pos (1+ pos)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2527 (substring string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2528 (match-beginning 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2529 (match-end 0)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2530 ((and (>= c ?1) (<= c ?9))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2531 ;; return empty string if N'th
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2532 ;; sub-regexp did not match:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2533 (let ((n (- c ?0)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2534 (if (match-beginning n)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2535 (substring string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2536 (match-beginning n)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2537 (match-end n))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2538 "")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2539 (t
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 (char-to-string c)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2542 (setq pos (1+ pos)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2543 expanded-newtext))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2544
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2545 ;; 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
2546 (defun dired-create-files (file-creator operation fn-list name-constructor
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2547 &optional marker-char)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2548
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2549 ;; 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
2550 ;; is queried, dired buffers are updated, and at the end a success or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2551 ;; failure message is displayed
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2552
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2553 ;; FILE-CREATOR must accept three args: oldfile newfile ok-if-already-exists
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2554
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2555 ;; It is called for each file and must create newfile, the entry of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2556 ;; which will be added. The user will be queried if the file already
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2557 ;; exists. If oldfile is removed by FILE-CREATOR (i.e, it is a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2558 ;; rename), it is FILE-CREATOR's responsibility to update dired
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2559 ;; buffers. FILE-CREATOR must abort by signalling a file-error if it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2560 ;; could not create newfile. The error is caught and logged.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2561
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2562 ;; OPERATION (a capitalized string, e.g. `Copy') describes the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2563 ;; operation performed. It is used for error logging.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2564
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2565 ;; FN-LIST is the list of files to copy (full absolute pathnames).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2566
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2567 ;; NAME-CONSTRUCTOR returns a newfile for every oldfile, or nil to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2568 ;; skip. If it skips files for other reasons than a direct user
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2569 ;; query, it is supposed to tell why (using dired-log).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2570
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2571 ;; Optional MARKER-CHAR is a character with which to mark every
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2572 ;; newfile's entry, or t to use the current marker character if the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2573 ;; oldfile was marked.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2574
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2575 (let (failures skipped (success-count 0) (total (length fn-list)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2576 (let (to overwrite-query
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2577 overwrite-backup-query) ; for dired-handle-overwrite
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2578 (mapcar
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2579 (function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2580 (lambda (from)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2581 (setq to (funcall name-constructor from))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2582 (if (equal to from)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2583 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2584 (setq to nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2585 (dired-log "Cannot %s to same file: %s\n"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2586 (downcase operation) from)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2587 (if (not to)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2588 (setq skipped (cons (dired-make-relative from) skipped))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2589 (let* ((overwrite (file-exists-p to))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2590 (overwrite-confirmed ; for dired-handle-overwrite
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2591 (and overwrite
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2592 (let ((help-form '(format "\
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2593 Type SPC or `y' to overwrite file `%s',
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2594 DEL or `n' to skip to next,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2595 ESC or `q' to not overwrite any of the remaining files,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2596 `!' to overwrite all remaining files with no more questions." to)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2597 (dired-query 'overwrite-query
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2598 "Overwrite `%s'?" to))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2599 ;; must determine if FROM is marked before file-creator
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2600 ;; gets a chance to delete it (in case of a move).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2601 (actual-marker-char
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2602 (cond ((integerp marker-char) marker-char)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2603 (marker-char (dired-file-marker from)) ; slow
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2604 (t nil))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2605 (condition-case err
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2606 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2607 (funcall file-creator from to overwrite-confirmed)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2608 (if overwrite
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2609 ;; If we get here, file-creator hasn't been aborted
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2610 ;; and the old entry (if any) has to be deleted
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2611 ;; before adding the new entry.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2612 (dired-remove-file to))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2613 (setq success-count (1+ success-count))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2614 (message "%s: %d of %d" operation success-count total)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2615 (dired-add-file to actual-marker-char))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2616 (file-error ; FILE-CREATOR aborted
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2617 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2618 (setq failures (cons (dired-make-relative from) failures))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2619 (dired-log "%s `%s' to `%s' failed:\n%s\n"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2620 operation from to err))))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2621 fn-list))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2622 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2623 (failures
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2624 (dired-log-summary
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2625 (message "%s failed for %d of %d file%s %s"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2626 operation (length failures) total
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2627 (dired-plural-s total) failures)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2628 (skipped
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2629 (dired-log-summary
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2630 (message "%s: %d of %d file%s skipped %s"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2631 operation (length skipped) total
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2632 (dired-plural-s total) skipped)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2633 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2634 (message "%s: %s file%s."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2635 operation success-count (dired-plural-s success-count)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2636 (dired-move-to-filename))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2637
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2638 (defun dired-do-create-files (op-symbol file-creator operation arg
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2639 &optional marker-char op1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2640 how-to)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2641 ;; Create a new file for each marked file.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2642 ;; Prompts user for target, which is a directory in which to create
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2643 ;; the new files. Target may be a plain file if only one marked
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2644 ;; file exists.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2645 ;; OP-SYMBOL is the symbol for the operation. Function `dired-mark-pop-up'
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2646 ;; will determine wether pop-ups are appropriate for this OP-SYMBOL.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2647 ;; FILE-CREATOR and OPERATION as in dired-create-files.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2648 ;; ARG as in dired-mark-get-files.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2649 ;; Optional arg OP1 is an alternate form for OPERATION if there is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2650 ;; only one file.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2651 ;; Optional arg MARKER-CHAR as in dired-create-files.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2652 ;; Optional arg HOW-TO determines how to treat target:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2653 ;; 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
2654 ;; file(s) are created inside the target directory. If target
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2655 ;; is not a directory, there must be exactly one marked file,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2656 ;; else error.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2657 ;; If HOW-TO is t, then target is not modified. There must be
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2658 ;; exactly one marked file, else error.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2659 ;; Else HOW-TO is assumed to be a function of one argument, target,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2660 ;; that looks at target and returns a value for the into-dir
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2661 ;; variable. The function dired-into-dir-with-symlinks is provided
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2662 ;; for the case (common when creating symlinks) that symbolic
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2663 ;; links to directories are not to be considered as directories
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2664 ;; (as file-directory-p would if HOW-TO had been nil).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2665 (or op1 (setq op1 operation))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2666 (let* ((fn-list (dired-mark-get-files nil arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2667 (fn-count (length fn-list))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2668 (target (expand-file-name
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2669 (dired-mark-read-file-name
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2670 (concat (if (= 1 fn-count) op1 operation) " %s to: ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2671 (dired-dwim-target-directory)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2672 op-symbol arg (mapcar (function dired-make-relative) fn-list))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2673 (into-dir (cond ((null how-to) (file-directory-p target))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2674 ((eq how-to t) nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2675 (t (funcall how-to target)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2676 (if (and (> fn-count 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2677 (not into-dir))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2678 (error "Marked %s: target must be a directory: %s" operation target))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2679 ;; rename-file bombs when moving directories unless we do this:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2680 (or into-dir (setq target (directory-file-name target)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2681 (dired-create-files
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2682 file-creator operation fn-list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2683 (if into-dir ; target is a directory
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2684 ;; This function uses fluid vars into-dir and target when called
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2685 ;; inside dired-create-files:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2686 (function (lambda (from)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2687 (expand-file-name (file-name-nondirectory from) target)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2688 (function (lambda (from) target)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2689 marker-char)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2690
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2691 (defun dired-dwim-target-directory ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2692 ;; Try to guess which target directory the user may want.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2693 ;; If there is a dired buffer displayed in the next window, use
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2694 ;; its current subdir, else use current subdir of this dired buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2695 (let ((this-dir (and (eq major-mode 'dired-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2696 (dired-current-directory))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2697 ;; 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
2698 (if dired-dwim-target
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2699 (let* ((other-buf (window-buffer (next-window)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2700 (other-dir (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2701 (set-buffer other-buf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2702 (and (eq major-mode 'dired-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2703 (dired-current-directory)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2704 (or other-dir this-dir))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2705 this-dir)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2706
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2707 (defun dired-into-dir-with-symlinks (target)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2708 (and (file-directory-p target)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2709 (not (file-symlink-p target))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2710 ;; This may not always be what you want, especially if target is your
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2711 ;; 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
2712 ;; case with NFS and automounters. Or if you want to make symlinks
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2713 ;; into directories that themselves are only symlinks, also quite
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2714 ;; common.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2715
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2716 ;; So we don't use this function as value for HOW-TO in
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2717 ;; dired-do-symlink, which has the minor disadvantage of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2718 ;; making links *into* a symlinked-dir, when you really wanted to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2719 ;; *overwrite* that symlink. In that (rare, I guess) case, you'll
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2720 ;; just have to remove that symlink by hand before making your marked
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2721 ;; symlinks.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2722
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2723 (defun dired-do-copy (&optional arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2724 "Copy all marked (or next ARG) files, or copy the current file.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2725 Thus, a zero prefix argument copies nothing. But it toggles the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2726 variable `dired-copy-preserve-time' (which see)."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2727 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2728 (if (not (zerop (prefix-numeric-value arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2729 (dired-do-create-files 'copy (function dired-copy-file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2730 (if dired-copy-preserve-time "Copy [-p]" "Copy")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2731 arg dired-keep-marker-copy)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2732 (setq dired-copy-preserve-time (not dired-copy-preserve-time))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2733 (if dired-copy-preserve-time
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2734 (message "Copy will preserve time.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2735 (message "Copied files will get current date."))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2736
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2737 (defun dired-do-symlink (&optional arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2738 "Symlink all marked (or next ARG) files into a directory,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2739 or make a symbolic link to the current file."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2740 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2741 (dired-do-create-files 'symlink (function make-symbolic-link)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2742 "SymLink" arg dired-keep-marker-symlink))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2743
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2744 (defun dired-do-hardlink (&optional arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2745 "Hard-link all marked (or next ARG) files into a directory,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2746 or make a hard link to the current file."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2747 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2748 (dired-do-create-files 'hardlink (function add-name-to-file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2749 "HardLink" arg dired-keep-marker-hardlink))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2750
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2751 (defun dired-do-move (&optional arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2752 "Move all marked (or next ARG) files into a directory,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2753 or rename the current file.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2754 A zero ARG moves no files but toggles `dired-dwim-target' (which see)."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2755 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2756 (if (not (zerop (prefix-numeric-value arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2757 (dired-do-create-files 'move (function dired-rename-file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2758 "Move" arg dired-keep-marker-move "Rename")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2759 (setq dired-dwim-target (not dired-dwim-target))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2760 (message "dired-dwim-target is %s." (if dired-dwim-target "ON" "OFF"))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2761
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2762 ;;;###end dired-cp.el
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2763
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2764 ;;; 5K
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2765 ;;;###begin dired-re.el
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2766 (defun dired-do-create-files-regexp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2767 (file-creator operation arg regexp newname &optional whole-path marker-char)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2768 ;; Create a new file for each marked file using regexps.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2769 ;; FILE-CREATOR and OPERATION as in dired-create-files.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2770 ;; ARG as in dired-mark-get-files.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2771 ;; Matches each marked file against REGEXP and constructs the new
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2772 ;; filename from NEWNAME (like in function replace-match).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2773 ;; Optional arg WHOLE-PATH means match/replace the whole pathname
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2774 ;; instead of only the non-directory part of the file.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2775 ;; Optional arg MARKER-CHAR as in dired-create-files.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2776 (let* ((fn-list (dired-mark-get-files nil arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2777 (fn-count (length fn-list))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2778 (operation-prompt (concat operation " `%s' to `%s'?"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2779 (rename-regexp-help-form (format "\
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2780 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
2781 `!' to %s all remaining matches with no more questions."
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 (downcase operation)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2784 (regexp-name-constructor
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2785 ;; Function to construct new filename using REGEXP and NEWNAME:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2786 (if whole-path ; easy (but rare) case
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2787 (function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2788 (lambda (from)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2789 (let ((to (dired-string-replace-match regexp from newname))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2790 ;; must bind help-form directly around call to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2791 ;; dired-query
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2792 (help-form rename-regexp-help-form))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2793 (if to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2794 (and (dired-query 'rename-regexp-query
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2795 operation-prompt
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2796 from
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 to)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2799 (dired-log "%s: %s did not match regexp %s\n"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2800 operation from regexp)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2801 ;; not whole-path, replace non-directory part only
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2802 (function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2803 (lambda (from)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2804 (let* ((new (dired-string-replace-match
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2805 regexp (file-name-nondirectory from) newname))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2806 (to (and new ; nil means there was no match
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2807 (expand-file-name new
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2808 (file-name-directory from))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2809 (help-form rename-regexp-help-form))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2810 (if to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2811 (and (dired-query 'rename-regexp-query
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2812 operation-prompt
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2813 (dired-make-relative from)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2814 (dired-make-relative to))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2815 to)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2816 (dired-log "%s: %s did not match regexp %s\n"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2817 operation (file-name-nondirectory from) regexp)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2818 rename-regexp-query)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2819 (dired-create-files
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2820 file-creator operation fn-list regexp-name-constructor marker-char)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2821
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2822 (defun dired-mark-read-regexp (operation)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2823 ;; Prompt user about performing OPERATION.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2824 ;; Read and return list of: regexp newname arg whole-path.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2825 (let* ((whole-path
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2826 (equal 0 (prefix-numeric-value current-prefix-arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2827 (arg
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2828 (if whole-path nil current-prefix-arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2829 (regexp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2830 (dired-read-regexp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2831 (concat (if whole-path "Path " "") operation " from (regexp): ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2832 dired-flagging-regexp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2833 (newname
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2834 (read-string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2835 (concat (if whole-path "Path " "") operation " " regexp " to: "))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2836 (list regexp newname arg whole-path)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2837
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2838 (defun dired-do-rename-regexp (regexp newname &optional arg whole-path)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2839 "Rename marked files containing REGEXP to NEWNAME.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2840 As each match is found, the user must type a character saying
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2841 what to do with it. For directions, type \\[help-command] at that time.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2842 NEWNAME may contain \\=\\<n> or \\& as in `query-replace-regexp'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2843 REGEXP defaults to the last regexp used.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2844 With a zero prefix arg, renaming by regexp affects the complete
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2845 pathname - usually only the non-directory part of file names is used
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2846 and changed."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2847 (interactive (dired-mark-read-regexp "Rename"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2848 (dired-do-create-files-regexp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2849 (function dired-rename-file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2850 "Rename" arg regexp newname whole-path dired-keep-marker-move))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2851
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2852 (defun dired-do-copy-regexp (regexp newname &optional arg whole-path)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2853 "Copy all marked files containing REGEXP to NEWNAME.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2854 See function `dired-rename-regexp' for more info."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2855 (interactive (dired-mark-read-regexp "Copy"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2856 (dired-do-create-files-regexp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2857 (function dired-copy-file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2858 (if dired-copy-preserve-time "Copy [-p]" "Copy")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2859 arg regexp newname whole-path dired-keep-marker-copy))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2860
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2861 (defun dired-do-hardlink-regexp (regexp newname &optional arg whole-path)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2862 "Hardlink all marked files containing REGEXP to NEWNAME.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2863 See function `dired-rename-regexp' for more info."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2864 (interactive (dired-mark-read-regexp "HardLink"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2865 (dired-do-create-files-regexp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2866 (function add-name-to-file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2867 "HardLink" arg regexp newname whole-path dired-keep-marker-hardlink))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2868
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2869 (defun dired-do-symlink-regexp (regexp newname &optional arg whole-path)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2870 "Symlink all marked files containing REGEXP to NEWNAME.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2871 See function `dired-rename-regexp' for more info."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2872 (interactive (dired-mark-read-regexp "SymLink"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2873 (dired-do-create-files-regexp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2874 (function make-symbolic-link)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2875 "SymLink" arg regexp newname whole-path dired-keep-marker-symlink))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2876
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2877 (defun dired-create-files-non-directory
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2878 (file-creator basename-constructor operation arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2879 ;; Perform FILE-CREATOR on the non-directory part of marked files
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2880 ;; using function BASENAME-CONSTRUCTOR, with query for each file.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2881 ;; OPERATION like in dired-create-files, ARG like in dired-mark-get-files.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2882 (let (rename-non-directory-query)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2883 (dired-create-files
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2884 file-creator
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2885 operation
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2886 (dired-mark-get-files nil arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2887 (function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2888 (lambda (from)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2889 (let ((to (concat (file-name-directory from)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2890 (funcall basename-constructor
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2891 (file-name-nondirectory from)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2892 (and (let ((help-form (format "\
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2893 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
2894 `!' to %s all remaining matches with no more questions."
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 (downcase operation))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2897 (dired-query 'rename-non-directory-query
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2898 (concat operation " `%s' to `%s'")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2899 (dired-make-relative from)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2900 (dired-make-relative to)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2901 to))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2902 dired-keep-marker-move)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2903
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2904 (defun dired-rename-non-directory (basename-constructor operation arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2905 (dired-create-files-non-directory
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2906 (function dired-rename-file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2907 basename-constructor operation arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2908
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2909 (defun dired-upcase (&optional arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2910 "Rename all marked (or next ARG) files to upper case."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2911 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2912 (dired-rename-non-directory (function upcase) "Rename upcase" arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2913
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2914 (defun dired-downcase (&optional arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2915 "Rename all marked (or next ARG) files to lower case."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2916 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2917 (dired-rename-non-directory (function downcase) "Rename downcase" arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2918
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2919 ;;;###end dired-re.el
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2920
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2921
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2922 ;; Tree Dired
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2923
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2924 ;;; utility functions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2925
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2926 (defun dired-in-this-tree (file dir)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2927 ;;"Is FILE part of the directory tree starting at DIR?"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2928 (let (case-fold-search)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2929 (string-match (concat "^" (regexp-quote dir)) file)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2930
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2931 (defun dired-make-absolute (file &optional dir)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2932 ;;"Convert FILE (a pathname relative to DIR) to an absolute pathname."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2933 ;; 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
2934 ;; or expand in / instead default-directory if DIR=="".
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2935 ;; This should be good enough for ange-ftp, but might easily be
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2936 ;; redefined (for VMS?).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2937 ;; It should be reasonably fast, though, as it is called in
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2938 ;; dired-get-filename.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2939 (concat (or dir default-directory) file))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2940
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2941 (defun dired-make-relative (file &optional dir no-error)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2942 ;;"Convert FILE (an absolute pathname) to a pathname relative to DIR.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2943 ;; Else error (unless NO-ERROR is non-nil, then FILE is returned unchanged)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2944 ;;DIR defaults to default-directory."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2945 ;; DIR must be file-name-as-directory, as with all directory args in
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2946 ;; elisp code.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2947 (or dir (setq dir default-directory))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2948 (if (string-match (concat "^" (regexp-quote dir)) file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2949 (substring file (match-end 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2950 (if no-error
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2951 file
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2952 (error "%s: not in directory tree growing at %s" file dir))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2953
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2954 (defun dired-normalize-subdir (dir)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2955 ;; Prepend default-directory to DIR if relative path name.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2956 ;; dired-get-filename must be able to make a valid filename from a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2957 ;; file and its directory DIR.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2958 (file-name-as-directory
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2959 (if (file-name-absolute-p dir)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2960 dir
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2961 (expand-file-name dir default-directory))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2962
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2963 (defun dired-between-files ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2964 ;; Point must be at beginning of line
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2965 ;; Should be equivalent to (save-excursion (not (dired-move-to-filename)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2966 ;; 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
2967 (or (looking-at "^$\\|^. *$\\|^. total\\|^. wildcard")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2968 (looking-at dired-subdir-regexp)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2969
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2970 (defun dired-get-subdir ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2971 ;;"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
2972 ;; Look up in the alist whether this is a headerline.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2973 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2974 (let ((cur-dir (dired-current-directory)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2975 (beginning-of-line) ; alist stores b-o-l positions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2976 (and (zerop (- (point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2977 (dired-get-subdir-min (assoc cur-dir
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2978 dired-subdir-alist))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2979 cur-dir))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2980
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2981 ;(defun dired-get-subdir-min (elt)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2982 ; (cdr elt))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2983 ;; 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
2984 (fset 'dired-get-subdir-min 'cdr)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2985
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2986 (defun dired-get-subdir-max (elt)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2987 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2988 (goto-char (dired-get-subdir-min elt))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2989 (dired-subdir-max)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2990
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2991 (defun dired-clear-alist ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2992 (while dired-subdir-alist
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2993 (set-marker (dired-get-subdir-min (car dired-subdir-alist)) nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2994 (setq dired-subdir-alist (cdr dired-subdir-alist))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2995
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2996 (defun dired-simple-subdir-alist ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2997 ;; Build and return `dired-subdir-alist' assuming just the top level
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2998 ;; directory to be inserted. Don't parse the buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2999 (set (make-local-variable 'dired-subdir-alist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3000 (list (cons default-directory (point-min-marker)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3001
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3002 (defun dired-build-subdir-alist ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3003 "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
3004 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3005 (dired-clear-alist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3006 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3007 (let ((count 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3008 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3009 (setq dired-subdir-alist nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3010 (while (re-search-forward dired-subdir-regexp nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3011 (setq count (1+ count))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3012 (dired-alist-add-1 (buffer-substring (match-beginning 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3013 (match-end 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3014 ;; Put subdir boundary between lines:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3015 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3016 (goto-char (match-beginning 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3017 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3018 (point-marker)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3019 (message "%d" count))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3020 (message "%d director%s." count (if (= 1 count) "y" "ies"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3021 ;; 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
3022 ;; constructionem. Return new alist:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3023 dired-subdir-alist)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3024
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3025 (defun dired-alist-add (dir new-marker)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3026 ;; Add new DIR at NEW-MARKER. Sort alist.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3027 (dired-alist-add-1 dir new-marker)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3028 (dired-alist-sort))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3029
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3030 (defun dired-alist-add-1 (dir new-marker)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3031 ;; Add new DIR at NEW-MARKER. Don't sort.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3032 (setq dired-subdir-alist
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3033 (cons (cons (dired-normalize-subdir dir) new-marker)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3034 dired-subdir-alist)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3035
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3036 (defun dired-alist-sort ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3037 ;; Keep the alist sorted on buffer position.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3038 (setq dired-subdir-alist
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3039 (sort dired-subdir-alist
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3040 (function (lambda (elt1 elt2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3041 (> (dired-get-subdir-min elt1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3042 (dired-get-subdir-min elt2)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3043
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3044 (defun dired-unsubdir (dir)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3045 ;; Remove DIR from the alist
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3046 (setq dired-subdir-alist
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3047 (delq (assoc dir dired-subdir-alist) dired-subdir-alist)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3048
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3049 (defun dired-goto-next-nontrivial-file ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3050 ;; Position point on first nontrivial file after point.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3051 (dired-goto-next-file);; so there is a file to compare with
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3052 (if (stringp dired-trivial-filenames)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3053 (while (and (not (eobp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3054 (string-match dired-trivial-filenames
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3055 (file-name-nondirectory
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3056 (or (dired-get-filename nil t) ""))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3057 (forward-line 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3058 (dired-move-to-filename))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3059
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3060 (defun dired-goto-next-file ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3061 (let ((max (1- (dired-subdir-max))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3062 (while (and (not (dired-move-to-filename)) (< (point) max))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3063 (forward-line 1))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3064
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3065 (defun dired-goto-subdir (dir)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3066 "Goto end of header line of DIR in this dired buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3067 Return value of point on success, otherwise return nil.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3068 The next char is either \\n, or \\r if DIR is hidden."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3069 (interactive
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3070 (prog1 ; let push-mark display its message
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3071 (list (expand-file-name
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3072 (completing-read "Goto in situ directory: " ; prompt
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3073 dired-subdir-alist ; table
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3074 nil ; predicate
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3075 t ; require-match
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3076 (dired-current-directory))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3077 (push-mark)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3078 (setq dir (file-name-as-directory dir))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3079 (let ((elt (assoc dir dired-subdir-alist)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3080 (and elt
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3081 (goto-char (dired-get-subdir-min elt))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3082 ;; dired-subdir-hidden-p and dired-add-entry depend on point being
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3083 ;; at either \r or \n after this function succeeds.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3084 (progn (skip-chars-forward "^\r\n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3085 (point)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3086
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3087 (defun dired-goto-file (file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3088 "Goto file line of FILE in this dired buffer."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3089 ;; Return value of point on success, else nil.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3090 ;; FILE must be an absolute pathname.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3091 ;; Loses if FILE contains control chars like "\007" for which ls
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3092 ;; either inserts "?" or "\\007" into the buffer, so we won't find
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3093 ;; it in the buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3094 (interactive
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3095 (prog1 ; let push-mark display its message
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3096 (list (expand-file-name
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3097 (read-file-name "Goto file: "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3098 (dired-current-directory))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3099 (push-mark)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3100 (setq file (directory-file-name file)) ; does no harm if no directory
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3101 (let (found case-fold-search)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3102 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3103 (if (dired-goto-subdir (or (file-name-directory file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3104 (error "Need absolute pathname for %s" file)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3105 (let ((base (file-name-nondirectory file))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3106 (boundary (dired-subdir-max)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3107 (while (and (not found)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3108 ;; filenames are preceded by SPC, this makes
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3109 ;; the search faster (e.g. for the filename "-"!).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3110 (search-forward (concat " " base) boundary 'move))
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
3111 ;; Match could have BASE just as initial substring
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3112 ;; or in permission bits or date or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3113 ;; not be a proper filename at all:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3114 (if (equal base (dired-get-filename 'no-dir t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3115 ;; Must move to filename since an (actually
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3116 ;; correct) match could have been elsewhere on the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3117 ;; ;; line (e.g. "-" would match somewhere in the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3118 ;; permission bits).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3119 (setq found (dired-move-to-filename)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3120 (and found
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3121 ;; return value of point (i.e., FOUND):
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3122 (goto-char found))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3123
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3124 (defun dired-initial-position (dirname)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3125 ;; Where point should go in a new listing of DIRNAME.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3126 ;; Point assumed at beginning of new subdir line.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3127 ;; 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
3128 (end-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3129 (if dired-trivial-filenames (dired-goto-next-nontrivial-file)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3130
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3131 ;;; moving by subdirectories
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3132
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3133 (defun dired-subdir-index (dir)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3134 ;; Return an index into alist for use with nth
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3135 ;; for the sake of subdir moving commands.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3136 (let (found (index 0) (alist dired-subdir-alist))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3137 (while alist
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3138 (if (string= dir (car (car alist)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3139 (setq alist nil found t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3140 (setq alist (cdr alist) index (1+ index))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3141 (if found index nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3142
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3143 (defun dired-next-subdir (arg &optional no-error-if-not-found no-skip)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3144 "Go to next subdirectory, regardless of level."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3145 ;; Use 0 arg to go to this directory's header line.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3146 ;; NO-SKIP prevents moving to end of header line, returning whatever
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3147 ;; position was found in dired-subdir-alist.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3148 (interactive "_p")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3149 (let ((this-dir (dired-current-directory))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3150 pos index)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3151 ;; nth with negative arg does not return nil but the first element
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3152 (setq index (- (dired-subdir-index this-dir) arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3153 (setq pos (if (>= index 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3154 (dired-get-subdir-min (nth index dired-subdir-alist))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3155 (if pos
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3156 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3157 (goto-char pos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3158 (or no-skip (skip-chars-forward "^\n\r"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3159 (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3160 (if no-error-if-not-found
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3161 nil ; return nil if not found
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3162 (error "%s directory" (if (> arg 0) "Last" "First"))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3163
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3164 (defun dired-prev-subdir (arg &optional no-error-if-not-found no-skip)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3165 "Go to previous subdirectory, regardless of level.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3166 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
3167 ;;(interactive "_p")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3168 (interactive
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3169 (list (if current-prefix-arg
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3170 (prefix-numeric-value current-prefix-arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3171 ;; if on subdir start already, don't stay there!
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3172 (if (dired-get-subdir) 1 0))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3173 (dired-next-subdir (- arg) no-error-if-not-found no-skip))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3174
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3175 (defun dired-tree-up (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3176 "Go up ARG levels in the dired tree."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3177 (interactive "_p")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3178 (let ((dir (dired-current-directory)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3179 (while (>= arg 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3180 (setq arg (1- arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3181 dir (file-name-directory (directory-file-name dir))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3182 ;;(setq dir (expand-file-name dir))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3183 (or (dired-goto-subdir dir)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3184 (error "Cannot go up to %s - not in this tree." dir))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3185
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3186 (defun dired-tree-down ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3187 "Go down in the dired tree."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3188 (interactive "_")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3189 (let ((dir (dired-current-directory)) ; has slash
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3190 pos case-fold-search) ; filenames are case sensitive
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3191 (let ((rest (reverse dired-subdir-alist)) elt)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3192 (while rest
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3193 (setq elt (car rest)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3194 rest (cdr rest))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3195 (if (dired-in-this-tree (directory-file-name (car elt)) dir)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3196 (setq rest nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3197 pos (dired-goto-subdir (car elt))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3198 (if pos
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3199 (goto-char pos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3200 (error "At the bottom"))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3201
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3202 ;;; hiding
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3203
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3204 (defun dired-subdir-hidden-p (dir)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3205 (and selective-display
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3206 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3207 (dired-goto-subdir dir)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3208 (looking-at "\r"))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3209
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3210 (defun dired-unhide-subdir ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3211 (let (buffer-read-only)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3212 (subst-char-in-region (dired-subdir-min) (dired-subdir-max) ?\r ?\n)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3213
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3214 (defun dired-hide-check ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3215 (or selective-display
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3216 (error "selective-display must be t for subdir hiding to work!")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3217
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3218 (defun dired-hide-subdir (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3219 "Hide or unhide the current subdirectory and move to next directory.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3220 Optional prefix arg is a repeat factor.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3221 Use \\[dired-hide-all] to (un)hide all directories."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3222 (interactive "p")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3223 (dired-hide-check)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3224 (while (>= (setq arg (1- arg)) 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3225 (let* ((cur-dir (dired-current-directory))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3226 (hidden-p (dired-subdir-hidden-p cur-dir))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3227 (elt (assoc cur-dir dired-subdir-alist))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3228 (end-pos (1- (dired-get-subdir-max elt)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3229 buffer-read-only)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3230 ;; keep header line visible, hide rest
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3231 (goto-char (dired-get-subdir-min elt))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3232 (skip-chars-forward "^\n\r")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3233 (if hidden-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3234 (subst-char-in-region (point) end-pos ?\r ?\n)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3235 (subst-char-in-region (point) end-pos ?\n ?\r)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3236 (dired-next-subdir 1 t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3237
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3238 (defun dired-hide-all (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3239 "Hide all subdirectories, leaving only their header lines.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3240 If there is already something hidden, make everything visible again.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3241 Use \\[dired-hide-subdir] to (un)hide a particular subdirectory."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3242 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3243 (dired-hide-check)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3244 (let (buffer-read-only)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3245 (if (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3246 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3247 (search-forward "\r" nil t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3248 ;; unhide - bombs on \r in filenames
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3249 (subst-char-in-region (point-min) (point-max) ?\r ?\n)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3250 ;; hide
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3251 (let ((pos (point-max)) ; pos of end of last directory
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3252 (alist dired-subdir-alist))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3253 (while alist ; while there are dirs before pos
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3254 (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
3255 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3256 (goto-char pos) ; current dir
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3257 ;; we're somewhere on current dir's line
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3258 (forward-line -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3259 (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3260 ?\n ?\r)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3261 (setq pos (dired-get-subdir-min (car alist))) ; prev dir gets current dir
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3262 (setq alist (cdr alist)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3263
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3264
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3265 ;; This function is the heart of tree dired.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3266 ;; It is called for each retrieved filename.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3267 ;; It could stand to be faster, though it's mostly function call
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3268 ;; overhead. Avoiding to funcall seems to save about 10% in
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3269 ;; dired-get-filename. Make it a defsubst?
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3270 (defun dired-current-directory (&optional localp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3271 "Return the name of the subdirectory to which this line belongs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3272 This returns a string with trailing slash, like `default-directory'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3273 Optional argument means return a file name relative to `default-directory'."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3274 (let ((here (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3275 (alist (or dired-subdir-alist
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3276 ;; probably because called in a non-dired buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3277 (error "No subdir-alist in %s" (current-buffer))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3278 elt dir)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3279 (while alist
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3280 (setq elt (car alist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3281 dir (car elt)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3282 ;; use `<=' (not `<') as subdir line is part of subdir
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3283 alist (if (<= (dired-get-subdir-min elt) here)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3284 nil ; found
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3285 (cdr alist))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3286 (if localp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3287 (dired-make-relative dir default-directory)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3288 dir)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3289
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3290 ;; Subdirs start at the beginning of their header lines and end just
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3291 ;; before the beginning of the next header line (or end of buffer).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3292
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3293 (defun dired-subdir-min ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3294 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3295 (if (not (dired-prev-subdir 0 t t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3296 (error "Not in a subdir!")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3297 (point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3298
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3299 (defun dired-subdir-max ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3300 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3301 (if (not (dired-next-subdir 1 t t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3302 (point-max)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3303 (point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3304
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3305 (defun dired-kill-line-or-subdir (&optional arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3306 "Kill this line (but not this file).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3307 Optional prefix argument is a repeat factor.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3308 If file is displayed as in situ subdir, kill that as well.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3309 If on a subdir headerline, kill whole subdir."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3310 (interactive "p")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3311 (if (dired-get-subdir)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3312 (dired-kill-subdir)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3313 (dired-kill-line arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3314
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3315 (defun dired-kill-line (&optional arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3316 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3317 (setq arg (prefix-numeric-value arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3318 (let (buffer-read-only file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3319 (while (/= 0 arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3320 (setq file (dired-get-filename nil t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3321 (if (not file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3322 (error "Can only kill file lines.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3323 (save-excursion (and file
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3324 (dired-goto-subdir file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3325 (dired-kill-subdir)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3326 (delete-region (progn (beginning-of-line) (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3327 (progn (forward-line 1) (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3328 (if (> arg 0)
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 (setq arg (1+ arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3331 (forward-line -1))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3332 (dired-move-to-filename)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3333
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3334 (defun dired-kill-subdir (&optional remember-marks)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3335 "Remove all lines of current subdirectory.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3336 Lower levels are unaffected."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3337 ;; With optional REMEMBER-MARKS, return a mark-alist.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3338 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3339 (let ((beg (dired-subdir-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3340 (end (dired-subdir-max))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3341 buffer-read-only cur-dir)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3342 (setq cur-dir (dired-current-directory))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3343 (if (equal cur-dir default-directory)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3344 (error "Attempt to kill top level directory"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3345 (prog1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3346 (if remember-marks (dired-remember-marks beg end))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3347 (delete-region beg end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3348 (if (eobp) ; don't leave final blank line
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3349 (delete-char -1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3350 (dired-unsubdir cur-dir))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3351
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3352 (defun dired-do-kill (&optional arg fmt)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3353 "Kill all marked lines (not files).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3354 With a prefix arg, kill all lines not marked or flagged."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3355 ;; Returns count of killed lines. FMT="" suppresses message.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3356 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3357 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3358 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3359 (let (buffer-read-only (count 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3360 (if (not arg) ; kill marked lines
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3361 (let ((regexp (dired-marker-regexp)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3362 (while (and (not (eobp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3363 (re-search-forward regexp nil t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3364 (setq count (1+ count))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3365 (delete-region (progn (beginning-of-line) (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3366 (progn (forward-line 1) (point)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3367 ;; else kill unmarked lines
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3368 (while (not (eobp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3369 (if (or (dired-between-files)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3370 (not (looking-at "^ ")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3371 (forward-line 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3372 (setq count (1+ count))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3373 (delete-region (point) (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3374 (forward-line 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3375 (point))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3376 (or (equal "" fmt)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3377 (message (or fmt "Killed %d line%s.") count (dired-plural-s count)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3378 count)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3379
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3380 (defun dired-do-redisplay (&optional arg test-for-subdir)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3381 "Redisplay all marked (or next ARG) files.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3382
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3383 If on a subdir line, redisplay that subdirectory. In that case,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3384 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
3385 ;; Moves point if the next ARG files are redisplayed.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3386 (interactive "P\np")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3387 (if (and test-for-subdir (dired-get-subdir))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3388 (dired-insert-subdir
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3389 (dired-get-subdir)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3390 (if arg (read-string "Switches for listing: " dired-actual-switches)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3391 (message "Redisplaying...")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3392 ;; message instead of making dired-mark-map show-progress is much faster
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3393 (dired-mark-map (let ((fname (dired-get-filename)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3394 (message "Redisplaying... %s" fname)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3395 (dired-update-file-line fname))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3396 arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3397 (dired-move-to-filename)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3398 (message "Redisplaying...done")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3399
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3400 (defun dired-mark-files-in-region (start end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3401 (let (buffer-read-only)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3402 (if (> start end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3403 (error "start > end"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3404 (goto-char start) ; assumed at beginning of line
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3405 (while (< (point) end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3406 ;; Skip subdir line and following garbage like the `total' line:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3407 (while (and (< (point) end) (dired-between-files))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3408 (forward-line 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3409 (if (and (not (looking-at dired-re-dot))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3410 (dired-get-filename nil t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3411 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3412 (delete-char 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3413 (insert dired-marker-char)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3414 (forward-line 1))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3415
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3416 (defun dired-mark-subdir-files ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3417 "Mark all files except `.' and `..'."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3418 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3419 (let ((p-min (dired-subdir-min)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3420 (dired-mark-files-in-region p-min (dired-subdir-max))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3421
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3422 (defun dired-mark-subdir-or-file (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3423 "Mark the current (or next ARG) files.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3424 If on a subdir headerline, mark all its files except `.' and `..'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3425
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3426 Use \\[dired-unflag-all-files] to remove all marks
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3427 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
3428 this subdir."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3429 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3430 (if (dired-get-subdir)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3431 (save-excursion (dired-mark-subdir-files))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3432 (dired-mark-file (prefix-numeric-value arg))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3433
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3434 (defun dired-unmark-subdir-or-file (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3435 "Unmark the current (or next ARG) files.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3436 If looking at a subdir, unmark all its files except `.' and `..'."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3437 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3438 (let ((dired-marker-char ?\040))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3439 (dired-mark-subdir-or-file arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3440
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3441 ;;; 5K
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3442 ;;;###begin dired-ins.el
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3443
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3444 (defun dired-maybe-insert-subdir (dirname &optional
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3445 switches no-error-if-not-dir-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3446 "Insert this subdirectory into the same dired buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3447 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
3448 else inserts it at its natural place (as ls -lR would have done).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3449 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
3450 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
3451 this subdirectory.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3452 This function takes some pains to conform to ls -lR output."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3453 (interactive
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3454 (list (dired-get-filename)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3455 (if current-prefix-arg
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3456 (read-string "Switches for listing: " dired-actual-switches))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3457 (let ((opoint (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3458 ;; We don't need a marker for opoint as the subdir is always
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3459 ;; inserted *after* opoint.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3460 (setq dirname (file-name-as-directory dirname))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3461 (or (and (not switches)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3462 (dired-goto-subdir dirname))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3463 (dired-insert-subdir dirname switches no-error-if-not-dir-p))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3464 ;; 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
3465 ;; insert message so that the user sees the `Mark set' message.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3466 (push-mark opoint)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3467
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3468 (defun dired-insert-subdir (dirname &optional switches no-error-if-not-dir-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3469 "Insert this subdirectory into the same dired buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3470 If it is already present, overwrites previous entry,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3471 else inserts it at its natural place (as ls -lR would have done).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3472 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
3473 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
3474 this subdirectory.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3475 This function takes some pains to conform to ls -lR output."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3476 ;; NO-ERROR-IF-NOT-DIR-P needed for special filesystems like
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3477 ;; Prospero where dired-ls does the right thing, but
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3478 ;; file-directory-p has not been redefined.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3479 (interactive
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3480 (list (dired-get-filename)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3481 (if current-prefix-arg
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3482 (read-string "Switches for listing: " dired-actual-switches))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3483 (setq dirname (file-name-as-directory (expand-file-name dirname)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3484 (dired-insert-subdir-validate dirname switches)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3485 (or no-error-if-not-dir-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3486 (file-directory-p dirname)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3487 (error "Attempt to insert a non-directory: %s" dirname))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3488 (let ((elt (assoc dirname dired-subdir-alist))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3489 switches-have-R mark-alist case-fold-search buffer-read-only)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3490 ;; case-fold-search is nil now, so we can test for capital `R':
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3491 (if (setq switches-have-R (and switches (string-match "R" switches)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3492 ;; avoid duplicated subdirs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3493 (setq mark-alist (dired-kill-tree dirname t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3494 (if elt
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3495 ;; If subdir is already present, remove it and remember its marks
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3496 (setq mark-alist (nconc (dired-insert-subdir-del elt) mark-alist))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3497 (dired-insert-subdir-newpos dirname)) ; else compute new position
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3498 (dired-insert-subdir-doupdate
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3499 dirname elt (dired-insert-subdir-doinsert dirname switches))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3500 (if switches-have-R (dired-build-subdir-alist))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3501 (dired-initial-position dirname)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3502 (save-excursion (dired-mark-remembered mark-alist))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3503
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3504 ;; This is a separate function for dired-vms.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3505 (defun dired-insert-subdir-validate (dirname &optional switches)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3506 ;; Check that it is valid to insert DIRNAME with SWITCHES.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3507 ;; Signal an error if invalid (e.g. user typed `i' on `..').
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3508 (or (dired-in-this-tree dirname default-directory)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3509 (error "%s: not in this directory tree" dirname))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3510 (if switches
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3511 (let (case-fold-search)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3512 (mapcar
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3513 (function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3514 (lambda (x)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3515 (or (eq (null (string-match x switches))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3516 (null (string-match x dired-actual-switches)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3517 (error "Can't have dirs with and without -%s switches together"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3518 x))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3519 ;; all switches that make a difference to dired-get-filename:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3520 '("F" "b")))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3521
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3522 (defun dired-kill-tree (dirname &optional remember-marks)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3523 ;;"Kill all proper subdirs of DIRNAME, excluding DIRNAME itself.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3524 ;; With optional arg REMEMBER-MARKS, return an alist of marked files."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3525 (interactive "DKill tree below directory: ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3526 (let ((s-alist dired-subdir-alist) dir m-alist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3527 (while s-alist
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3528 (setq dir (car (car s-alist))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3529 s-alist (cdr s-alist))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3530 (if (and (not (string-equal dir dirname))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3531 (dired-in-this-tree dir dirname)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3532 (dired-goto-subdir dir))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3533 (setq m-alist (nconc (dired-kill-subdir remember-marks) m-alist))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3534 m-alist))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3535
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3536 (defun dired-insert-subdir-newpos (new-dir)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3537 ;; Find pos for new subdir, according to tree order.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3538 (let ((alist dired-subdir-alist) elt dir pos new-pos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3539 (while alist
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3540 (setq elt (car alist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3541 alist (cdr alist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3542 dir (car elt)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3543 pos (dired-get-subdir-min elt))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3544 (if (dired-tree-lessp dir new-dir)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3545 ;; Insert NEW-DIR after DIR
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3546 (setq new-pos (dired-get-subdir-max elt)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3547 alist nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3548 (goto-char new-pos))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3549 ;; want a separating newline between subdirs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3550 (or (eobp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3551 (forward-line -1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3552 (insert "\n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3553 (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3554
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3555 (defun dired-insert-subdir-del (element)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3556 ;; Erase an already present subdir (given by ELEMENT) from buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3557 ;; Move to that buffer position. Return a mark-alist.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3558 (let ((begin-marker (dired-get-subdir-min element)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3559 (goto-char begin-marker)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3560 ;; Are at beginning of subdir (and inside it!). Now determine its end:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3561 (goto-char (dired-subdir-max))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3562 (or (eobp);; want a separating newline _between_ subdirs:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3563 (forward-char -1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3564 (prog1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3565 (dired-remember-marks begin-marker (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3566 (delete-region begin-marker (point)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3567
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3568 (defun dired-insert-subdir-doinsert (dirname switches)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3569 ;; Insert ls output after point and put point on the correct
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3570 ;; position for the subdir alist.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3571 ;; Return the boundary of the inserted text (as list of BEG and END).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3572 (let ((begin (point)) end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3573 (message "Reading directory %s..." dirname)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3574 (let ((dired-actual-switches
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3575 (or switches
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3576 (dired-replace-in-string "R" "" dired-actual-switches))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3577 (if (equal dirname (car (car (reverse dired-subdir-alist))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3578 ;; top level directory may contain wildcards:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3579 (dired-readin-insert dired-directory)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3580 (dired-ls dirname dired-actual-switches nil t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3581 (message "Reading directory %s...done" dirname)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3582 (setq end (point-marker))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3583 (dired-indent-rigidly begin end 2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3584 ;; call dired-insert-headerline afterwards, as under VMS dired-ls
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3585 ;; does insert the headerline itself and the insert function just
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3586 ;; moves point.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3587 ;; Need a marker for END as this inserts text.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3588 (goto-char begin)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3589 (dired-insert-headerline dirname)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3590 ;; point is now like in dired-build-subdir-alist
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3591 (prog1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3592 (list begin (marker-position end))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3593 (set-marker end nil))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3594
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3595 (defun dired-insert-subdir-doupdate (dirname elt beg-end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3596 ;; Point is at the correct subdir alist position for ELT,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3597 ;; BEG-END is the subdir-region (as list of begin and end).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3598 (if elt ; subdir was already present
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3599 ;; update its position (should actually be unchanged)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3600 (set-marker (dired-get-subdir-min elt) (point-marker))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3601 (dired-alist-add dirname (point-marker)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3602 ;; The hook may depend on the subdir-alist containing the just
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3603 ;; inserted subdir, so run it after dired-alist-add:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3604 (if dired-after-readin-hook
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3605 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3606 (let ((begin (nth 0 beg-end))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3607 (end (nth 1 beg-end)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3608 (goto-char begin)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3609 (save-restriction
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3610 (narrow-to-region begin end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3611 ;; hook may add or delete lines, but the subdir boundary
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3612 ;; marker floats
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3613 (run-hooks 'dired-after-readin-hook))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3614
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3615 (defun dired-tree-lessp (dir1 dir2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3616 ;; Lexicographic order on pathname components, like `ls -lR':
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3617 ;; DIR1 < DIR2 iff DIR1 comes *before* DIR2 in an `ls -lR' listing,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3618 ;; i.e., iff DIR1 is a (grand)parent dir of DIR2,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3619 ;; or DIR1 and DIR2 are in the same parentdir and their last
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3620 ;; components are string-lessp.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3621 ;; Thus ("/usr/" "/usr/bin") and ("/usr/a/" "/usr/b/") are tree-lessp.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3622 ;; string-lessp could arguably be replaced by file-newer-than-file-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3623 ;; if dired-actual-switches contained `t'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3624 (setq dir1 (file-name-as-directory dir1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3625 dir2 (file-name-as-directory dir2))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3626 (let ((components-1 (dired-split "/" dir1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3627 (components-2 (dired-split "/" dir2)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3628 (while (and components-1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3629 components-2
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3630 (equal (car components-1) (car components-2)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3631 (setq components-1 (cdr components-1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3632 components-2 (cdr components-2)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3633 (let ((c1 (car components-1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3634 (c2 (car components-2)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3635
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3636 (cond ((and c1 c2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3637 (string-lessp c1 c2))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3638 ((and (null c1) (null c2))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3639 nil) ; they are equal, not lessp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3640 ((null c1) ; c2 is a subdir of c1: c1<c2
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3641 t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3642 ((null c2) ; c1 is a subdir of c2: c1>c2
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3643 nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3644 (t (error "This can't happen"))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3645
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3646 ;; There should be a builtin split function - inverse to mapconcat.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3647 (defun dired-split (pat str &optional limit)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3648 "Splitting on regexp PAT, turn string STR into a list of substrings.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3649 Optional third arg LIMIT (>= 1) is a limit to the length of the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3650 resulting list.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3651 Thus, if SEP is a regexp that only matches itself,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3652
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3653 (mapconcat 'identity (dired-split SEP STRING) SEP)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3654
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3655 is always equal to STRING."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3656 (let* ((start (string-match pat str))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3657 (result (list (substring str 0 start)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3658 (count 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3659 (end (if start (match-end 0))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3660 (if end ; else nothing left
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3661 (while (and (or (not (integerp limit))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3662 (< count limit))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3663 (string-match pat str end))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3664 (setq start (match-beginning 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3665 count (1+ count)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3666 result (cons (substring str end start) result)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3667 end (match-end 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3668 start end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3669 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3670 (if (and (or (not (integerp limit))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3671 (< count limit))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3672 end) ; else nothing left
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3673 (setq result
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3674 (cons (substring str end) result)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3675 (nreverse result)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3676
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3677 (defun dired-indent-rigidly (start end arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3678 ;; like indent-rigidly but has more efficient behavior w.r.t. the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3679 ;; after-change-functions (i.e., font-lock-mode.)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3680 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3681 (let ((after-change-functions nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3682 (after-change-function nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3683 (goto-char end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3684 (indent-rigidly start end arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3685 ;; deletion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3686 (run-hook-with-args 'after-change-functions start start (- end start))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3687 (run-hook-with-args 'after-change-function start start (- end start))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3688 ;; insertion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3689 (run-hook-with-args 'after-change-functions start (point) 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3690 (run-hook-with-args 'after-change-function start (point) 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3691 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3692
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3693 (if (string-lessp emacs-version "19")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3694 (fset 'dired-indent-rigidly (symbol-function 'indent-rigidly)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3695
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3696 ;;;###end dired-ins.el
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3697
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3698
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3699 ;;; Sorting
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3700
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3701 ;; 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
3702 ;; 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
3703 ;; So anything that does not contain these is sort "by name".
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3704
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3705 (defvar dired-ls-sorting-switches "SXU"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3706 "String of ls switches (single letters) except `t' that influence sorting.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3707
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3708 (defvar dired-sort-by-date-regexp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3709 (concat "^-[^" dired-ls-sorting-switches
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3710 "]*t[^" dired-ls-sorting-switches "]*$")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3711 "Regexp recognized by dired to set `by date' mode.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3712
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3713 (defvar dired-sort-by-name-regexp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3714 (concat "^-[^t" dired-ls-sorting-switches "]+$")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3715 "Regexp recognized by dired to set `by name' mode.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3716
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3717 (defvar dired-sort-mode nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3718 "Whether Dired sorts by name, date etc. (buffer-local).")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3719 ;; 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
3720
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3721 (defun dired-sort-set-modeline ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3722 ;; Set modeline display according to dired-actual-switches.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3723 ;; Modeline display of "by name" or "by date" guarantees the user a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3724 ;; match with the corresponding regexps. Non-matching switches are
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3725 ;; shown literally.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3726 (setq dired-sort-mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3727 (let (case-fold-search)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3728 (cond ((string-match dired-sort-by-name-regexp dired-actual-switches)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3729 " by name")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3730 ((string-match dired-sort-by-date-regexp dired-actual-switches)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3731 " by date")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3732 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3733 (concat " " dired-actual-switches)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3734 ;; update mode line:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3735 (set-buffer-modified-p (buffer-modified-p)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3736
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3737 (defun dired-sort-toggle-or-edit (&optional arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3738 "Toggle between sort by date/name and refresh the dired buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3739 With a prefix argument you can edit the current listing switches instead."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3740 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3741 (if arg
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3742 (dired-sort-other
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3743 (read-string "ls switches (must contain -l): " dired-actual-switches))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3744 (dired-sort-toggle)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3745
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3746 (defun dired-sort-toggle ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3747 ;; Toggle between sort by date/name. Reverts the buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3748 (setq dired-actual-switches
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3749 (let (case-fold-search)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3750 (concat
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3751 "-l"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3752 (dired-replace-in-string (concat "[---lt"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3753 dired-ls-sorting-switches "]")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3754 ""
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3755 dired-actual-switches)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3756 (if (string-match (concat "[t" dired-ls-sorting-switches "]")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3757 dired-actual-switches)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3758 ""
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3759 "t"))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3760 (dired-sort-set-modeline)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3761 (revert-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3762
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3763 (defun dired-sort-other (switches &optional no-revert)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3764 ;; Specify new ls SWITCHES for current dired buffer. Values matching
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3765 ;; `dired-sort-by-date-regexp' or `dired-sort-by-name-regexp' set the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3766 ;; minor mode accordingly, others appear literally in the mode line.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3767 ;; With optional second arg NO-REVERT, don't refresh the listing afterwards.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3768 (setq dired-actual-switches switches)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3769 (dired-sort-set-modeline)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3770 (or no-revert (revert-buffer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3771
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3772 (if (eq system-type 'vax-vms)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3773 (load "dired-vms"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3774
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3775 (if (string-match "XEmacs" emacs-version)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3776 (load "dired-xemacs-menu"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3777
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3778 (run-hooks 'dired-load-hook) ; for your customizations