annotate lisp/efs/dired.el @ 42:8b8b7f3559a2 r19-15b104

Import from CVS: tag r19-15b104
author cvs
date Mon, 13 Aug 2007 08:54:51 +0200
parents 7e54bd776075
children 56c54cf7c5b6
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
22
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1 ; -*- Emacs-Lisp -*-
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2 ;; DIRED commands for Emacs.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3 ;; Copyright (C) 1985, 1986, 1991 Free Software Foundation, Inc.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5 ;;
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6 ;; File: dired.el
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
7 ;; RCS:
42
8b8b7f3559a2 Import from CVS: tag r19-15b104
cvs
parents: 40
diff changeset
8 ;; Dired Version: #Revision: 7.9 $
22
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
9 ;; Description: The DIRectory EDitor is for manipulating, and running
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
10 ;; commands on files in a directory.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
11 ;; Authors: FSF,
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
12 ;; Sebastian Kremer <sk@thp.uni-koeln.de>,
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
13 ;; Sandy Rutherford <sandy@ibm550.sissa.it>
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
14 ;; Cast of thousands...
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
15 ;;
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
16 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
17
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
18 ;; This program is free software; you can redistribute it and/or modify
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
19 ;; it under the terms of the GNU General Public License as published by
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
20 ;; the Free Software Foundation; either version 1, or (at your option)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
21 ;; any later version.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
22
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
23 ;; This program is distributed in the hope that it will be useful,
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
24 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
25 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
26 ;; GNU General Public License for more details.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
27
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
28 ;; You should have received a copy of the GNU General Public License
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
29 ;; along with GNU Emacs; see the file COPYING. If not, write to
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
30 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
31
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
32 ;; Rewritten in 1990/1991 to add tree features, file marking and
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
33 ;; sorting by Sebastian Kremer <sk@thp.uni-koeln.de>.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
34 ;; 7-1993: Added special features for efs interaction and upgraded to Emacs 19.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
35 ;; Sandy Rutherford <sandy@ibm550.sissa.it>
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
36
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
37 ;;; Dired Version
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
38
42
8b8b7f3559a2 Import from CVS: tag r19-15b104
cvs
parents: 40
diff changeset
39 (defconst dired-version (substring "#Revision: 7.9 $" 11 -2)
22
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
40 "The revision number of Tree Dired (as a string).
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
41
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
42 Don't forget to mention this when reporting bugs to:
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
43
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
44 efs-bugs@cuckoo.hpl.hp.com")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
45
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
46 ;; Global key bindings:
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
47 ;; --------------------
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
48 ;;
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
49 ;; By convention, dired uses the following global key-bindings.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
50 ;; These may or may not already be set up in your local emacs. If not
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
51 ;; then you will need to add them to your .emacs file, or the system
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
52 ;; default.el file. We don't set them automatically here, as users may
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
53 ;; have individual preferences.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
54 ;;
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
55 ;; (define-key ctl-x-map "d" 'dired)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
56 ;; (define-key ctl-x-4-map "d" 'dired-other-window)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
57 ;; (define-key ctl-x-map "\C-j" 'dired-jump-back)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
58 ;; (define-key ctl-x-4-map "\C-j" 'dired-jump-back-other-window)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
59 ;;
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
60 ;; For V19 emacs only. (Make sure that the ctl-x-5-map exists.)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
61 ;; (define-key ctl-x-5-map "d" 'dired-other-frame)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
62 ;; (define-key Ctl-x-5-map "\C-j" 'dired-jump-back-other-frame)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
63
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
64
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
65 ;;; Grok the current emacs version
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
66 ;;
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
67 ;; Hopefully these two variables provide us with enough version sensitivity.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
68
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
69 ;; Make sure that we have a frame-width function
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
70 (or (fboundp 'frame-width) (fset 'frame-width 'screen-width))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
71
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
72 ;;; Requirements and provisions
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
73
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
74 (provide 'dired)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
75 (require 'backquote) ; For macros.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
76
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
77 ;; Compatibility requirements for the file-name-handler-alist.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
78 (let ((lucid-p (string-match "Lucid" emacs-version))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
79 ver subver)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
80 (or (string-match "^\\([0-9]+\\)\\.\\([0-9]+\\)" emacs-version)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
81 (error "dired does not work with emacs version %s" emacs-version))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
82 (setq ver (string-to-int (substring emacs-version (match-beginning 1)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
83 (match-end 1)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
84 subver (string-to-int (substring emacs-version (match-beginning 2)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
85 (match-end 2))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
86 (cond
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
87 ((= ver 18)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
88 (require 'emacs-19)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
89 (require 'fn-handler))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
90 ((and (= ver 19) (if lucid-p (< subver 10) (< subver 23)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
91 (require 'fn-handler))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
92 ((< ver 18)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
93 (error "dired does not work with emacs version %s" emacs-version))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
94
40
7e54bd776075 Import from CVS: tag r19-15b103
cvs
parents: 24
diff changeset
95 ;; We duplicate default-dir stuff to avoid its overwrites unless
7e54bd776075 Import from CVS: tag r19-15b103
cvs
parents: 24
diff changeset
96 ;; they are explicitly requested.
7e54bd776075 Import from CVS: tag r19-15b103
cvs
parents: 24
diff changeset
97
7e54bd776075 Import from CVS: tag r19-15b103
cvs
parents: 24
diff changeset
98 (defvar default-directory-function nil
7e54bd776075 Import from CVS: tag r19-15b103
cvs
parents: 24
diff changeset
99 "A function to call to compute the default-directory for the current buffer.
7e54bd776075 Import from CVS: tag r19-15b103
cvs
parents: 24
diff changeset
100 If this is nil, the function default-directory will return the value of the
7e54bd776075 Import from CVS: tag r19-15b103
cvs
parents: 24
diff changeset
101 variable default-directory.
7e54bd776075 Import from CVS: tag r19-15b103
cvs
parents: 24
diff changeset
102 Buffer local.")
7e54bd776075 Import from CVS: tag r19-15b103
cvs
parents: 24
diff changeset
103 (make-variable-buffer-local 'default-directory-function)
7e54bd776075 Import from CVS: tag r19-15b103
cvs
parents: 24
diff changeset
104
7e54bd776075 Import from CVS: tag r19-15b103
cvs
parents: 24
diff changeset
105 (defun default-directory ()
7e54bd776075 Import from CVS: tag r19-15b103
cvs
parents: 24
diff changeset
106 " Returns the default-directory for the current buffer.
7e54bd776075 Import from CVS: tag r19-15b103
cvs
parents: 24
diff changeset
107 Will use the variable default-directory-function if it non-nil."
7e54bd776075 Import from CVS: tag r19-15b103
cvs
parents: 24
diff changeset
108 (if default-directory-function
7e54bd776075 Import from CVS: tag r19-15b103
cvs
parents: 24
diff changeset
109 (funcall default-directory-function)
7e54bd776075 Import from CVS: tag r19-15b103
cvs
parents: 24
diff changeset
110 (if (string-match "Lucid" emacs-version)
7e54bd776075 Import from CVS: tag r19-15b103
cvs
parents: 24
diff changeset
111 (abbreviate-file-name default-directory t)
7e54bd776075 Import from CVS: tag r19-15b103
cvs
parents: 24
diff changeset
112 (abbreviate-file-name default-directory))))
22
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
113
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
114 ;;;;----------------------------------------------------------------
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
115 ;;;; Customizable variables
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
116 ;;;;----------------------------------------------------------------
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
117 ;;
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
118 ;; The funny comments are for autoload.el, to automagically update
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
119 ;; loaddefs.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
120
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
121 ;;; Variables for compressing files.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
122
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
123 ;;;###autoload
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
124 (defvar dired-compression-method 'compress
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
125 "*Type of compression program to use.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
126 Give as a symbol.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
127 Currently-recognized methods are: gzip pack compact compress.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
128 To change this variable use \\[dired-do-compress] with a zero prefix.")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
129
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
130 ;;;###autoload
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
131 (defvar dired-compression-method-alist
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
132 '((gzip ".gz" ("gzip") ("gzip" "-d") "-f")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
133 ;; Put compress before pack, so that it wins out if we are using
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
134 ;; efs to work on a case insensitive OS. The -f flag does
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
135 ;; two things in compress. No harm in giving it twice.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
136 (compress ".Z" ("compress" "-f") ("compress" "-d") "-f")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
137 ;; pack support may not work well. pack is too chatty and there is no way
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
138 ;; to force overwrites.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
139 (pack ".z" ("pack" "-f") ("unpack"))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
140 (compact ".C" ("compact") ("uncompact")))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
141
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
142 "*Association list of compression method descriptions.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
143 Each element of the table should be a list of the form
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
144
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
145 \(compress-type extension (compress-args) (decompress-args) force-flag\)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
146
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
147 where
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
148 `compress-type' is a unique symbol in the alist to which
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
149 `dired-compression-method' can be set;
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
150 `extension' is the file extension (as a string) used by files compressed
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
151 by this method;
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
152 `compress-args' is a list of the path of the compression program and
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
153 flags to pass as separate arguments;
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
154 `decompress-args' is a list of the path of the decompression
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
155 program and flags to pass as separate arguments.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
156 `force-flag' is the switch to pass to the command to force overwriting
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
157 of existing files.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
158
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
159 For example:
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
160
40
7e54bd776075 Import from CVS: tag r19-15b103
cvs
parents: 24
diff changeset
161 \(setq dired-compression-method-alist
22
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
162 \(cons '\(frobnicate \".frob\" \(\"frob\"\) \(\"frob\" \"-d\"\) \"-f\"\)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
163 dired-compression-method-alist\)\)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
164 => \(\(frobnicate \".frob\" \(\"frob\"\) \(\"frob\" \"-d\"\)\)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
165 \(gzip \".gz\" \(\"gzip\"\) \(\"gunzip\"\)\)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
166 ...\)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
167
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
168 See also: dired-compression-method <V>")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
169
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
170 ;;; Variables for the ls program.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
171
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
172 ;;;###autoload
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
173 (defvar dired-ls-program "ls"
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
174 "*Absolute or relative name of the ls program used by dired.")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
175
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
176 ;;;###autoload
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
177 (defvar dired-listing-switches "-al"
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
178 "*Switches passed to ls for dired. MUST contain the `l' option.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
179 Can contain even `F', `b', `i' and `s'.")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
180
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
181 (defvar dired-ls-F-marks-symlinks
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
182 (memq system-type '(aix-v3 hpux silicon-graphics-unix))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
183 ;; Both SunOS and Ultrix have system-type berkeley-unix. But
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
184 ;; SunOS doesn't mark symlinks, but Ultrix does. Therefore,
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
185 ;; can't grok this case.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
186 "*Informs dired about how ls -lF marks symbolic links.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
187 Set this to t if `dired-ls-program' with -lF marks the name of the symbolic
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
188 link itself with a trailing @.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
189
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
190 For example: If foo is a link pointing to bar, and \"ls -F bar\" gives
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
191
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
192 ... bar -> foo
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
193
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
194 set this variable to nil. If it gives
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
195
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
196 ... bar@ -> foo
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
197
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
198 set this variable to t.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
199
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
200 Dired checks if there is really a @ appended. Thus, if you have a
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
201 marking ls program on one host and a non-marking on another host, and
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
202 don't care about symbolic links which really end in a @, you can
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
203 always set this variable to t.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
204
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
205 If you use efs, it will make this variable buffer-local, and control
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
206 it according to its assessment of how the remote host marks symbolic
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
207 links.")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
208
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
209 (defvar dired-show-ls-switches nil
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
210 "*If non-nil dired will show the dired ls switches on the modeline.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
211 If nil, it will indicate how the files are sorted by either \"by name\" or
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
212 \"by date\". If it is unable to recognize the sorting defined by the switches,
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
213 then the switches will be shown explicitly on the modeline, regardless of the
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
214 setting of this variable.")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
215
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
216 ;;; Variables for other unix utility programs.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
217
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
218 ;; For most program names, don't use absolute paths so that dired
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
219 ;; uses the user's value of the environment variable PATH. chown is
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
220 ;; an exception as it is not always in the PATH.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
221
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
222 ;;;###autoload
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
223 (defvar dired-chown-program
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
224 (if (memq system-type '(hpux dgux usg-unix-v)) "chown" "/etc/chown")
40
7e54bd776075 Import from CVS: tag r19-15b103
cvs
parents: 24
diff changeset
225 "*Name of chown command (usually `chown' or `/etc/chown').")
22
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
226
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
227 ;;;###autoload
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
228 (defvar dired-gnutar-program nil
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
229 "*If non-nil, name of the GNU tar executable (e.g. \"tar\" or \"gnutar\").
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
230 GNU tar's `z' switch is used for compressed tar files.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
231 If you don't have GNU tar, set this to nil: a pipe using `zcat' is then used.")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
232
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
233 ;;;###autoload
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
234 (defvar dired-unshar-program nil
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
235 "*Set to the name of the unshar program, if you have it.")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
236
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
237 ;;; Markers
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
238
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
239 (defvar dired-keep-marker-rename t
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
240 ;; Use t as default so that moved files `take their markers with them'
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
241 "*Controls marking of renamed files.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
242 If t, files keep their previous marks when they are renamed.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
243 If a character, renamed files (whether previously marked or not)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
244 are afterward marked with that character.")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
245
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
246 (defvar dired-keep-marker-compress t
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
247 "*Controls marking of compressed or uncompressed files.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
248 If t, files keep their previous marks when they are compressed.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
249 If a character, compressed or uncompressed files (whether previously
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
250 marked or not) are afterward marked with that character.")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
251
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
252 (defvar dired-keep-marker-uucode ?U
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
253 "*Controls marking of uuencoded or uudecoded files.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
254 If t, files keep their previous marks when they are uuencoded.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
255 If a character, uuencoded or uudecoded files (whether previously
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
256 marked or not) are afterward marked with that character.")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
257
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
258 (defvar dired-keep-marker-copy ?C
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
259 "*Controls marking of copied files.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
260 If t, copied files are marked if and as the corresponding original files were.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
261 If a character, copied files are unconditionally marked with that character.")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
262
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
263 (defvar dired-keep-marker-hardlink ?H
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
264 "*Controls marking of newly made hard links.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
265 If t, they are marked if and as the files linked to were marked.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
266 If a character, new links are unconditionally marked with that character.")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
267
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
268 (defvar dired-keep-marker-symlink ?S
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
269 "*Controls marking of newly made symbolic links.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
270 If t, they are marked if and as the files linked to were marked.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
271 If a character, new links are unconditionally marked with that character.")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
272
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
273 (defvar dired-keep-marker-kill ?K
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
274 "*When killed file lines are redisplayed, they will have this marker.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
275 Setting this to nil means that they will not have any marker.")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
276
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
277 (defvar dired-failed-marker-shell ?!
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
278 "*If non-nil, a character with which to mark files of failed shell commands.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
279 Applies to the command `dired-do-shell-command'. Files for which the shell
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
280 command has a nonzero exit status will be marked with this character")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
281
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
282 ;;; Behavioral Variables
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
283
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
284 ;;;###autoload
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
285 (defvar dired-local-variables-file ".dired"
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
286 "*If non-nil, filename for local variables for Dired.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
287 If Dired finds a file with that name in the current directory, it will
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
288 temporarily insert it into the dired buffer and run `hack-local-variables'.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
289
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
290 Type \\[info] and `g' `(emacs)File Variables' `RET' for more info on
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
291 local variables.")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
292
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
293 ;; Usually defined in files.el. Define here anyway, to be safe.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
294 ;;;###autoload
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
295 (defvar dired-kept-versions 2
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
296 "*When cleaning directory, number of versions to keep.")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
297
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
298 ;;;###autoload
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
299 (defvar dired-find-subdir nil
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
300 "*Determines whether dired tries to lookup a subdir in existing buffers.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
301 If non-nil, dired does not make a new buffer for a directory if it can be
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
302 found (perhaps as subdir) in some existing dired buffer. If there are several
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
303 dired buffers for a directory, then the most recently used one is chosen.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
304
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
305 Dired avoids switching to the current buffer, so that if you have
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
306 a normal and a wildcard buffer for the same directory, C-x d RET will
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
307 toggle between those two.")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
308
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
309 ;;;###autoload
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
310 (defvar dired-use-file-transformers t
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
311 "*Determines whether dired uses file transformers.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
312 If non-nil `dired-do-shell-command' will apply file transformers to file names.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
313 See \\[describe-function] for dired-do-shell-command for more information.")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
314
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
315 ;;;###autoload
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
316 (defvar dired-dwim-target nil
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
317 "*If non-nil, dired tries to guess a default target directory.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
318 This means that if there is a dired buffer displayed in the next window,
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
319 use its current subdir, instead of the current subdir of this dired buffer.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
320 The target is put in the prompt for file copy, rename, etc.")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
321
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
322 ;;;###autoload
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
323 (defvar dired-copy-preserve-time nil
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
324 "*If non-nil, Dired preserves the last-modified time in a file copy.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
325 \(This works on only some systems.)\\<dired-mode-map>
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
326 Use `\\[dired-do-copy]' with a zero prefix argument to toggle its value.")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
327
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
328 ;;;###autoload
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
329 (defvar dired-no-confirm nil
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
330 "*If non-nil, a list of symbols for commands dired should not confirm.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
331 It can be a sublist of
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
332
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
333 '(byte-compile chgrp chmod chown compress copy delete hardlink load
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
334 move print shell symlink uncompress recursive-delete kill-file-buffer
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
335 kill-dired-buffer patch create-top-dir revert-subdirs)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
336
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
337 The meanings of most of the symbols are obvious. A few exceptions:
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
338
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
339 'compress applies to compression or decompression by any of the
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
340 compression program in `dired-compression-method-alist'.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
341
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
342 'kill-dired-buffer applies to offering to kill dired buffers for
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
343 directories which have been deleted.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
344
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
345 'kill-file-buffer applies to offering to kill buffers visiting files
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
346 which have been deleted.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
347
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
348 'recursive-delete applies to recursively deleting non-empty
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
349 directories, and all of their contents.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
350
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
351 'create-top-dir applies to `dired-up-directory' creating a new top level
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
352 directory for the dired buffer.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
353
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
354 'revert-subdirs applies to re-reading subdirectories which have
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
355 been modified on disk.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
356
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
357 Note that this list also applies to remote files accessed with efs
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
358 or ange-ftp.")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
359
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
360 ;;;###autoload
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
361 (defvar dired-backup-if-overwrite nil
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
362 "*Non-nil if Dired should ask about making backups before overwriting files.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
363 Special value 'always suppresses confirmation.")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
364
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
365 ;;;###autoload
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
366 (defvar dired-omit-files nil
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
367 "*If non-nil un-interesting files will be omitted from this dired buffer.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
368 Use \\[dired-omit-toggle] to see these files. (buffer local)")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
369 (make-variable-buffer-local 'dired-omit-files)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
370
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
371 ;;;###autoload
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
372 (defvar dired-mail-reader 'rmail
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
373 "*Mail reader used by dired for dired-read-mail \(\\[dired-read-mail]\).
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
374 The symbols 'rmail and 'vm are the only two allowed values.")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
375
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
376 (defvar dired-verify-modtimes t
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
377 "*If non-nil dired will revert dired buffers for modified subdirectories.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
378 See also dired-no-confirm <V>.")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
379
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
380 ;;; File name regular expressions and extensions.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
381
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
382 (defvar dired-trivial-filenames "^\\.\\.?$\\|^#"
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
383 "*Regexp of files to skip when finding first file of a directory listing.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
384 A value of nil means move to the subdir line.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
385 A value of t means move to first file.")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
386
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
387 (defvar dired-cleanup-alist
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
388 (list
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
389 '("tex" ".toc" ".log" ".aux" ".dvi")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
390 '("latex" ".toc" ".log" ".aux" ".idx" ".lof" ".lot" ".glo" ".dvi")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
391 '("bibtex" ".blg" ".bbl")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
392 '("texinfo" ".cp" ".cps" ".fn" ".fns" ".ky" ".kys" ".pg" ".pgs"
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
393 ".tp" ".tps" ".vr" ".vrs")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
394 '("patch" ".rej" ".orig")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
395 '("backups" "~")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
396 (cons "completion-ignored-extensions" completion-ignored-extensions))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
397 "*Alist of extensions for temporary files created by various programs.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
398 Used by `dired-cleanup'.")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
399
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
400 (defvar dired-omit-extensions
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
401 (let ((alist dired-cleanup-alist)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
402 x result)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
403 (while alist
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
404 (setq x (cdr (car alist))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
405 alist (cdr alist))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
406 (while x
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
407 (or (member (car x) result)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
408 (setq result (cons (car x) result)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
409 (setq x (cdr x))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
410 result)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
411 "*List of extensions for file names that will be omitted (buffer-local).
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
412 This only has effect when the subdirectory is in omission mode.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
413 To make omission mode the default, set `dired-omit-files' to t.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
414 See also `dired-omit-extensions'.")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
415 (make-variable-buffer-local 'dired-omit-extensions)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
416
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
417 (defvar dired-omit-regexps '("^#" "^\\.")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
418 "*File names matching these regexp may be omitted (buffer-local).
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
419 This only has effect when the subdirectory is in omission mode.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
420 To make omission mode the default, set `dired-omit-files' to t.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
421 This only has effect when `dired-omit-files-p' is t.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
422 See also `dired-omit-extensions'.")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
423 (make-variable-buffer-local 'dired-omit-files-regexp)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
424
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
425 (defvar dired-filename-re-ext "\\..+$" ; start from the first dot. last dot?
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
426 "*Defines what is the extension of a file name.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
427 \(match-beginning 0\) for this regexp in the file name without directory will
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
428 be taken to be the start of the extension.")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
429
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
430 ;;; Hook variables
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
431
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
432 (defvar dired-load-hook nil
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
433 "Run after loading dired.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
434 You can customize key bindings or load extensions with this.")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
435
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
436 (defvar dired-grep-load-hook nil
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
437 "Run after loading dired-grep.")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
438
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
439 (defvar dired-mode-hook nil
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
440 "Run at the very end of dired-mode.")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
441
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
442 (defvar dired-before-readin-hook nil
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
443 "Hook run before a dired buffer is newly read in, created,or reverted.")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
444
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
445 (defvar dired-after-readin-hook nil
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
446 "Hook run after each listing of a file or directory.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
447 The buffer is narrowed to the new listing.")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
448
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
449 (defvar dired-setup-keys-hook nil
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
450 "Hook run when dired sets up its keymap.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
451 This happens the first time that `dired-mode' is called, and runs after
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
452 `dired-mode-hook'. This hook can be used to make alterations to the
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
453 dired keymap.")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
454
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
455 ;;; Internal variables
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
456 ;;
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
457 ;; If you set these, know what you are doing.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
458
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
459 ;;; Marker chars.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
460
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
461 (defvar dired-marker-char ?* ; the answer is 42
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
462 ; life the universe and everything
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
463 ;; so that you can write things like
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
464 ;; (let ((dired-marker-char ?X))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
465 ;; ;; great code using X markers ...
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
466 ;; )
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
467 ;; For example, commands operating on two sets of files, A and B.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
468 ;; Or marking files with digits 0-9. This could implicate
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
469 ;; concentric sets or an order for the marked files.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
470 ;; The code depends on dynamic scoping on the marker char.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
471 "In dired, character used to mark files for later commands.")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
472 (make-variable-buffer-local 'dired-marker-char)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
473
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
474 (defconst dired-default-marker dired-marker-char)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
475 ;; Stores the default value of dired-marker-char when dynamic markers
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
476 ;; are being used.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
477
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
478 (defvar dired-del-marker ?D
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
479 "Character used to flag files for deletion.")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
480
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
481 ;; \017=^O for Omit - other packages can chose other control characters.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
482 (defvar dired-omit-marker-char ?\017)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
483 ;; Marker used for omitted files. Shouldn't be used by anything else.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
484
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
485 (defvar dired-kill-marker-char ?\C-k)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
486 ;; Marker used by dired-do-kill. Shouldn't be used by anything else.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
487
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
488 ;;; State variables
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
489
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
490 (defvar dired-mode-line-modified "-%s%s%s-"
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
491 "*Format string to show the modification status of the buffer.")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
492
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
493 (defvar dired-del-flags-number 0)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
494 (make-variable-buffer-local 'dired-del-flags-number)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
495 (defvar dired-marks-number 0)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
496 (make-variable-buffer-local 'dired-marks-number)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
497 (defvar dired-other-marks-number 0)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
498 (make-variable-buffer-local 'dired-other-marks-number)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
499
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
500 (defvar dired-marked-files nil
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
501 "List of filenames from last `dired-copy-filename-as-kill' call.")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
502
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
503 (defvar dired-directory nil
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
504 "The directory name or shell wildcard that was used as argument to `ls'.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
505 Local to each dired buffer. May be a list, in which case the car is the
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
506 directory name and the cdr is the actual files to list.")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
507 (make-variable-buffer-local 'dired-directory)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
508
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
509 (defvar dired-internal-switches nil
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
510 "The actual (buffer-local) value of `dired-listing-switches'.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
511 The switches are represented as a list of characters.")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
512 (make-variable-buffer-local 'dired-internal-switches)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
513
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
514 (defvar dired-subdir-alist nil
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
515 "Association list of subdirectories and their buffer positions.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
516 Each subdirectory has an element: (DIRNAME . STARTMARKER).
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
517 The order of elements is the reverse of the order in the buffer.")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
518 (make-variable-buffer-local 'dired-subdir-alist)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
519
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
520 (defvar dired-curr-subdir-min 0)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
521 ;; Cache for modeline tracking of the cursor
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
522 (make-variable-buffer-local 'dired-curr-subdir-min)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
523
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
524 (defvar dired-curr-subdir-max 0)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
525 ;; Cache for modeline tracking of the cursor
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
526 (make-variable-buffer-local 'dired-curr-subdir-max)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
527
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
528 (defvar dired-subdir-omit nil)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
529 ;; Controls whether the modeline shows Omit.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
530 (make-variable-buffer-local 'dired-subdir-omit)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
531
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
532 (defvar dired-in-query nil)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
533 ;; let-bound to t when dired is in the process of querying the user.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
534 ;; This is to keep asynch messaging from clobbering the query prompt.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
535
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
536 (defvar dired-overwrite-confirmed nil)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
537 ;; Fluid variable used to remember if a bunch of overwrites have been
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
538 ;; confirmed.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
539
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
540 (defvar dired-overwrite-backup-query nil)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
541 ;; Fluid var used to remember if backups have been requested for overwrites.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
542
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
543 (defvar dired-file-creator-query nil)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
544 ;; Fluid var to remember responses to file-creator queries.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
545
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
546 (defvar dired-omit-silent nil)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
547 ;; This is sometimes let-bound to t if messages would be annoying,
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
548 ;; e.g., in dired-awrh.el. Binding to 0, only suppresses
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
549 ;; \"(Nothing to omit)\" message.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
550
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
551 (defvar dired-buffers nil
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
552 ;; Enlarged by dired-advertise
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
553 ;; Queried by function dired-buffers-for-dir. When this detects a
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
554 ;; killed buffer, it is removed from this list.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
555 "Alist of directories and their associated dired buffers.")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
556
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
557 (defvar dired-sort-mode nil
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
558 "Whether Dired sorts by name, date, etc.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
559 \(buffer-local\)")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
560 ;; This is nil outside dired buffers so it can be used in the modeline
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
561 (make-variable-buffer-local 'dired-sort-mode)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
562
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
563 (defvar dired-marker-stack nil
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
564 "List of previously used dired marker characters.")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
565 (make-variable-buffer-local 'dired-marker-stack)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
566
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
567 (defvar dired-marker-stack-pointer 0)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
568 ;; Points to the current marker in the stack
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
569 (make-variable-buffer-local 'dired-marker-stack-pointer)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
570
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
571 (defvar dired-marker-stack-cursor ?\ ; space
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
572 "Character to use as a cursor in the dired marker stack.")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
573
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
574 (defconst dired-marker-string ""
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
575 "String version of `dired-marker-stack'.")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
576 (make-variable-buffer-local 'dired-marker-string)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
577
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
578 (defvar dired-modeline-tracking-cmds nil)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
579 ;; List of commands after which the modeline gets updated.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
580
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
581 ;;; Config. variables not usually considered fair game for the user.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
582
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
583 (defvar dired-deletion-confirmer 'yes-or-no-p) ; or y-or-n-p?
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
584
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
585 (defvar dired-log-buffer "*Dired log*")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
586 ;; Name of buffer used to log dired messages and errors.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
587
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
588 ;;; Assoc. lists
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
589
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
590 ;; For pop ups and user input for file marking
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
591 (defvar dired-query-alist
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
592 '((?\y . y) (?\040 . y) ; `y' or SPC means accept once
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
593 (?n . n) (?\177 . n) ; `n' or DEL skips once
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
594 (?! . yes) ; `!' accepts rest
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
595 (?q. no) (?\e . no) ; `q' or ESC skips rest
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
596 ;; None of these keys quit - use C-g for that.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
597 ))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
598
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
599 (defvar dired-sort-type-alist
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
600 ;; alist of sort flags, and the sort type, as a symbol.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
601 ;; Don't put ?r in here. It's handled separately.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
602 '((?t . date) (?S . size) (?U . unsort) (?X . ext)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
603
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
604 ;;; Internal regexps for examining ls listings.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
605 ;;
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
606 ;; Many of these regexps must be tested at beginning-of-line, but are also
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
607 ;; used to search for next matches, so neither omitting "^" nor
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
608 ;; replacing "^" by "\n" (to make it slightly faster) will work.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
609
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
610 (defvar dired-re-inode-size "[ \t0-9]*")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
611 ;; Regexp for optional initial inode and file size.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
612 ;; Must match output produced by ls' -i and -s flags.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
613
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
614 (defvar dired-re-mark "^[^ \n\r]")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
615 ;; Regexp matching a marked line.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
616 ;; Important: the match ends just after the marker.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
617
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
618 (defvar dired-re-maybe-mark "^. ")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
619
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
620 (defvar dired-re-dir (concat dired-re-maybe-mark dired-re-inode-size "d"))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
621 ;; Matches directory lines
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
622
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
623 (defvar dired-re-sym (concat dired-re-maybe-mark dired-re-inode-size "l"))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
624 ;; Matches symlink lines
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
625
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
626 (defvar dired-re-exe;; match ls permission string of an executable file
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
627 (mapconcat (function
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
628 (lambda (x)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
629 (concat dired-re-maybe-mark dired-re-inode-size x)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
630 '("-[-r][-w][xs][-r][-w].[-r][-w]."
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
631 "-[-r][-w].[-r][-w][xs][-r][-w]."
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
632 "-[-r][-w].[-r][-w].[-r][-w][xst]")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
633 "\\|"))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
634
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
635 (defvar dired-re-dot "^.* \\.\\.?/?$") ; with -F, might end in `/'
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
636 ;; . and .. files
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
637
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
638 (defvar dired-re-month-and-time
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
639 (concat
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
640 " \\(Jan\\|Feb\\|Mar\\|Apr\\|May\\|June?\\|July?\\|Aug\\|Sep\\|Oct\\|Nov\\|"
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
641 ; June and July are for HP-UX 9.0
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
642 "Dec\\) [ 0-3][0-9]\\("
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
643 " [012][0-9]:[0-6][0-9] \\|" ; time
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
644 " [12][90][0-9][0-9] \\|" ; year on IRIX, NeXT, SunOS, ULTRIX, Apollo,
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
645 ; HP-UX, A/UX
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
646 " [12][90][0-9][0-9] \\)" ; year on AIX
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
647 ))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
648 ;; This regexp MUST match all the way to first character of the filename.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
649 ;; You can loosen it to taste, but then you might bomb on filenames starting
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
650 ;; with a space. This will have to be modified for non-english month names.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
651
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
652 (defvar dired-subdir-regexp
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
653 "\\([\n\r]\n\\|\\`\\). \\([^\n\r]+\\)\\(:\\)\\(\\.\\.\\.\r\\|[\n\r]\\)")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
654 ;; Regexp matching a maybe hidden subdirectory line in ls -lR output.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
655 ;; Subexpression 2 is the subdirectory proper, no trailing colon.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
656 ;; Subexpression 3 must end right before the \n or \r at the end of
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
657 ;; the subdir heading. Matches headings after indentation has been done.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
658
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
659 (defvar dired-unhandle-add-files nil)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
660 ;; List of files that the dired handler function need not add to dired buffers.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
661 ;; This is because they have already been added, most likely in
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
662 ;; dired-create-files. This is because dired-create-files add files with
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
663 ;; special markers.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
664
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
665 ;;; history variables
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
666
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
667 (defvar dired-regexp-history nil
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
668 "History list of regular expressions used in Dired commands.")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
669
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
670 (defvar dired-chmod-history nil
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
671 "History of arguments to chmod in dired.")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
672
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
673 (defvar dired-chown-history nil
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
674 "History of arguments to chown in dired.")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
675
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
676 (defvar dired-chgrp-history nil
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
677 "History of arguments to chgrp in dired.")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
678
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
679 (defvar dired-cleanup-history nil
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
680 "History of arguments to dired-cleanup.")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
681
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
682 (defvar dired-goto-file-history nil)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
683 ;; History for dired-goto-file and dired-goto-subdir
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
684 (put 'dired-goto-file-history 'cursor-end t) ; for gmhist
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
685
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
686 (defvar dired-history nil)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
687 ;; Catch-all history variable for dired file ops without
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
688 ;; their own history.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
689
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
690 (defvar dired-op-history-alist
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
691 ;; alist of dired file operations and history symbols
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
692 '((chgrp . dired-chgrp-history) (chown . dired-chown-history)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
693 (chmod . dired-chmod-history) ))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
694
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
695 ;;; Tell the byte-compiler that we know what we're doing.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
696 ;;; Do we?
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
697
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
698 (defvar file-name-handler-alist)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
699 (defvar inhibit-file-name-operation)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
700 (defvar inhibit-file-name-handlers)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
701 (defvar efs-dired-host-type)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
702
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
703
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
704 ;;;;------------------------------------------------------------------
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
705 ;;;; Utilities
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
706 ;;;;------------------------------------------------------------------
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
707
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
708 ;;; Macros
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
709 ;;
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
710 ;; Macros must be defined before they are used - for the byte compiler.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
711
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
712 (defmacro dired-get-subdir-min (elt)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
713 ;; Returns the value of the subdir minumum for subdir with entry ELT in
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
714 ;; dired-subdir-alist.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
715 (list 'nth 1 elt))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
716
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
717 (defmacro dired-save-excursion (&rest body)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
718 ;; Saves excursions of the point (not buffer) in dired buffers.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
719 ;; It tries to be robust against deletion of the region about the point.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
720 ;; Note that this assumes only dired-style deletions.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
721 (let ((temp-bolm (make-symbol "bolm"))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
722 (temp-fnlp (make-symbol "fnlp"))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
723 (temp-offset-bol (make-symbol "offset-bol")))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
724 (` (let (((, temp-bolm) (make-marker))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
725 (, temp-fnlp) (, temp-offset-bol))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
726 (let ((bol (save-excursion (skip-chars-backward "^\n\r") (point))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
727 (set-marker (, temp-bolm) bol)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
728 (setq (, temp-offset-bol) (- (point) bol)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
729 (, temp-fnlp) (memq (char-after bol) '(?\n\ ?\r))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
730 (unwind-protect
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
731 (progn
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
732 (,@ body))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
733 ;; Use the marker to try to find the right line, then move to
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
734 ;; the proper column.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
735 (goto-char (, temp-bolm))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
736 (and (not (, temp-fnlp))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
737 (not (eq (following-char) 0)) (memq (following-char) '(?\n ?\r))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
738 ;; The line containing the point got deleted. Note that this
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
739 ;; logic only works if we don't delete null lines, but we never
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
740 ;; do.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
741 (forward-line 1)) ; don't move into a hidden line.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
742 (skip-chars-forward "^\n\r" (+ (point) (, temp-offset-bol))))))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
743
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
744 (put 'dired-save-excursion 'lisp-indent-hook 0)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
745
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
746 (defun dired-substitute-marker (pos old new)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
747 ;; Change marker, re-fontify
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
748 (subst-char-in-region pos (1+ pos) old new)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
749 (dired-move-to-filename))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
750
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
751 (defmacro dired-mark-if (predicate msg)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
752 ;; Mark all files for which CONDITION evals to non-nil.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
753 ;; CONDITION is evaluated on each line, with point at beginning of line.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
754 ;; MSG is a noun phrase for the type of files being marked.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
755 ;; It should end with a noun that can be pluralized by adding `s'.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
756 ;; Return value is the number of files marked, or nil if none were marked.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
757 (let ((temp-pt (make-symbol "pt"))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
758 (temp-count (make-symbol "count"))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
759 (temp-msg (make-symbol "msg")))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
760 (` (let (((, temp-msg) (, msg))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
761 ((, temp-count) 0)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
762 (, temp-pt) buffer-read-only)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
763 (save-excursion
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
764 (if (, temp-msg) (message "Marking %ss..." (, temp-msg)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
765 (goto-char (point-min))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
766 (while (not (eobp))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
767 (if (and (, predicate)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
768 (not (char-equal (following-char) dired-marker-char)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
769 (progn
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
770 ;; Doing this rather than delete-char, insert
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
771 ;; avoids re-computing markers
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
772 (setq (, temp-pt) (point))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
773 (dired-substitute-marker
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
774 (, temp-pt)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
775 (following-char) dired-marker-char)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
776 (setq (, temp-count) (1+ (, temp-count)))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
777 (forward-line 1))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
778 (if (, temp-msg)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
779 (message "%s %s%s %s%s."
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
780 (, temp-count)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
781 (, temp-msg)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
782 (dired-plural-s (, temp-count))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
783 (if (eq dired-marker-char ?\040) "un" "")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
784 (if (eq dired-marker-char dired-del-marker)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
785 "flagged" "marked"))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
786 (and (> (, temp-count) 0) (, temp-count))))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
787
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
788 (defmacro dired-map-over-marks (body arg &optional show-progress)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
789 ;; Perform BODY with point somewhere on each marked line
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
790 ;; and return a list of BODY's results.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
791 ;; If no marked file could be found, execute BODY on the current line.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
792 ;; If ARG is an integer, use the next ARG (or previous -ARG, if ARG<0)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
793 ;; files instead of the marked files.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
794 ;; If ARG is t, only apply to marked files. If there are no marked files,
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
795 ;; the result is a noop.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
796 ;; If ARG is otherwise non-nil, use current file instead.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
797 ;; If optional third arg SHOW-PROGRESS evaluates to non-nil,
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
798 ;; redisplay the dired buffer after each file is processed.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
799 ;; No guarantee is made about the position on the marked line.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
800 ;; BODY must ensure this itself if it depends on this.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
801 ;; Search starts at the beginning of the buffer, thus the car of the list
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
802 ;; corresponds to the line nearest to the buffer's bottom. This
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
803 ;; is also true for (positive and negative) integer values of ARG.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
804 ;; To avoid code explosion, BODY should not be too long as it is
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
805 ;; expanded four times.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
806 ;;
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
807 ;; Warning: BODY must not add new lines before point - this may cause an
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
808 ;; endless loop.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
809 ;; This warning should not apply any longer, sk 2-Sep-1991 14:10.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
810 (let ((temp-found (make-symbol "found"))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
811 (temp-results (make-symbol "results"))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
812 (temp-regexp (make-symbol "regexp"))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
813 (temp-curr-pt (make-symbol "curr-pt"))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
814 (temp-next-position (make-symbol "next-position")))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
815 (` (let (buffer-read-only case-fold-search (, temp-found) (, temp-results))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
816 (dired-save-excursion
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
817 (if (and (, arg) (not (eq (, arg) t)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
818 (if (integerp (, arg))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
819 (and (not (zerop (, arg)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
820 (progn;; no save-excursion, want to move point.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
821 (dired-repeat-over-lines
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
822 arg
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
823 (function (lambda ()
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
824 (if (, show-progress) (sit-for 0))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
825 (setq (, temp-results)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
826 (cons (, body)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
827 (, temp-results))))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
828 (if (< (, arg) 0)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
829 (nreverse (, temp-results))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
830 (, temp-results))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
831 ;; non-nil, non-integer ARG means use current file:
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
832 (list (, body)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
833 (let (((, temp-regexp)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
834 (concat "^" (regexp-quote (char-to-string
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
835 dired-marker-char))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
836 (, temp-curr-pt) (, temp-next-position))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
837 (save-excursion
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
838 (goto-char (point-min))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
839 ;; remember position of next marked file before BODY
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
840 ;; can insert lines before the just found file,
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
841 ;; confusing us by finding the same marked file again
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
842 ;; and again and...
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
843 (setq (, temp-next-position)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
844 (and (re-search-forward (, temp-regexp) nil t)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
845 (point-marker))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
846 (, temp-found) (not (null (, temp-next-position))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
847 (while (, temp-next-position)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
848 (setq (, temp-curr-pt) (goto-char (, temp-next-position))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
849 ;; need to get next position BEFORE body
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
850 (, temp-next-position)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
851 (and (re-search-forward (, temp-regexp) nil t)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
852 (point-marker)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
853 (goto-char (, temp-curr-pt))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
854 (if (, show-progress) (sit-for 0))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
855 (setq (, temp-results) (cons (, body) (, temp-results)))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
856 (if (, temp-found)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
857 (, temp-results)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
858 ;; Do current file, unless arg is t
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
859 (and (not (eq (, arg) t))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
860 (list (, body)))))))))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
861
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
862 ;;; General utility functions
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
863
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
864 (defun dired-buffer-more-recently-used-p (buffer1 buffer2)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
865 "Return t if BUFFER1 is more recently used than BUFFER2."
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
866 (if (equal buffer1 buffer2)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
867 nil
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
868 (let ((more-recent nil)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
869 (list (buffer-list)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
870 (while (and list
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
871 (not (setq more-recent (equal buffer1 (car list))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
872 (not (equal buffer2 (car list))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
873 (setq list (cdr list)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
874 more-recent)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
875
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
876 (defun dired-file-modtime (file)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
877 ;; Return the modtime of FILE, which is assumed to be already expanded
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
878 ;; by expand-file-name.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
879 (let ((handler (find-file-name-handler file 'dired-file-modtime)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
880 (if handler
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
881 (funcall handler 'dired-file-modtime file)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
882 (nth 5 (file-attributes file)))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
883
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
884 (defun dired-set-file-modtime (file alist)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
885 ;; Set the modtime for FILE in the subdir alist ALIST.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
886 (let ((handler (find-file-name-handler file 'dired-set-file-modtime)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
887 (if handler
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
888 (funcall handler 'dired-set-file-modtime file alist)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
889 (let ((elt (assoc file alist)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
890 (if elt
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
891 (setcar (nthcdr 4 elt) (nth 5 (file-attributes file))))))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
892
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
893 (defun dired-map-over-marks-check (fun arg op-symbol operation
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
894 &optional show-progress no-confirm)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
895 ;; Map FUN over marked files (with second ARG like in dired-map-over-marks)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
896 ;; and display failures.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
897
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
898 ;; FUN takes zero args. It returns non-nil (the offending object, e.g.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
899 ;; the short form of the filename) for a failure and probably logs a
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
900 ;; detailed error explanation using function `dired-log'.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
901
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
902 ;; OP-SYMBOL is s symbol representing the operation.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
903 ;; eg. 'compress
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
904
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
905 ;; OPERATION is a string describing the operation performed (e.g.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
906 ;; "Compress"). It is used with `dired-mark-pop-up' to prompt the user
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
907 ;; (e.g. with `Compress * [2 files]? ') and to display errors (e.g.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
908 ;; `Failed to compress 1 of 2 files - type y to see why ("foo")')
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
909
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
910 ;; SHOW-PROGRESS if non-nil means redisplay dired after each file.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
911
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
912 (if (or no-confirm (dired-mark-confirm op-symbol operation arg))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
913 (let* ((total-list;; all of FUN's return values
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
914 (dired-map-over-marks (funcall fun) arg show-progress))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
915 (total (length total-list))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
916 (failures (delq nil total-list))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
917 (count (length failures)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
918 (if (not failures)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
919 (message "%s: %d file%s." operation total (dired-plural-s total))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
920 (message "Failed to %s %d of %d file%s - type y to see why %s"
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
921 operation count total (dired-plural-s total)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
922 ;; this gives a short list of failed files in parens
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
923 ;; which may be sufficient for the user even
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
924 ;; without typing `W' for the process' diagnostics
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
925 failures)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
926 ;; end this bunch of errors:
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
927 (dired-log-summary
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
928 (buffer-name (current-buffer))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
929 (format
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
930 "Failed to %s %d of %d file%s"
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
931 operation count total (dired-plural-s total))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
932 failures)))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
933
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
934 (defun dired-make-switches-string (list)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
935 ;; Converts a list of cracters to a string suitable for passing to ls.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
936 (concat "-" (mapconcat 'char-to-string list "")))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
937
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
938 (defun dired-make-switches-list (string)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
939 ;; Converts a string of ls switches to a list of characters.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
940 (delq ?- (mapcar 'identity string)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
941
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
942 ;; Cloning replace-match to work on strings instead of in buffer:
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
943 ;; The FIXEDCASE parameter of replace-match is not implemented.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
944 (defun dired-string-replace-match (regexp string newtext
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
945 &optional literal global)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
946 ;; Replace first match of REGEXP in STRING with NEWTEXT.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
947 ;; If it does not match, nil is returned instead of the new string.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
948 ;; Optional arg LITERAL means to take NEWTEXT literally.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
949 ;; Optional arg GLOBAL means to replace all matches.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
950 (if global
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
951 (let ((result "") (start 0) mb me)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
952 (while (string-match regexp string start)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
953 (setq mb (match-beginning 0)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
954 me (match-end 0)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
955 result (concat result
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
956 (substring string start mb)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
957 (if literal
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
958 newtext
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
959 (dired-expand-newtext string newtext)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
960 start me))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
961 (if mb ; matched at least once
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
962 (concat result (substring string start))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
963 nil))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
964 ;; not GLOBAL
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
965 (if (not (string-match regexp string 0))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
966 nil
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
967 (concat (substring string 0 (match-beginning 0))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
968 (if literal newtext (dired-expand-newtext string newtext))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
969 (substring string (match-end 0))))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
970
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
971 (defun dired-expand-newtext (string newtext)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
972 ;; Expand \& and \1..\9 (referring to STRING) in NEWTEXT, using match data.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
973 ;; Note that in Emacs 18 match data are clipped to current buffer
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
974 ;; size...so the buffer should better not be smaller than STRING.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
975 (let ((pos 0)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
976 (len (length newtext))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
977 (expanded-newtext ""))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
978 (while (< pos len)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
979 (setq expanded-newtext
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
980 (concat expanded-newtext
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
981 (let ((c (aref newtext pos)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
982 (if (= ?\\ c)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
983 (cond ((= ?\& (setq c
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
984 (aref newtext
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
985 (setq pos (1+ pos)))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
986 (substring string
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
987 (match-beginning 0)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
988 (match-end 0)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
989 ((and (>= c ?1) (<= c ?9))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
990 ;; return empty string if N'th
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
991 ;; sub-regexp did not match:
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
992 (let ((n (- c ?0)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
993 (if (match-beginning n)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
994 (substring string
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
995 (match-beginning n)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
996 (match-end n))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
997 "")))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
998 (t
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
999 (char-to-string c)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1000 (char-to-string c)))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1001 (setq pos (1+ pos)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1002 expanded-newtext))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1003
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1004 (defun dired-in-this-tree (file dir)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1005 ;;Is FILE part of the directory tree starting at DIR?
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1006 (let ((len (length dir)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1007 (and (>= (length file) len)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1008 (string-equal (substring file 0 len) dir))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1009
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1010 (defun dired-tree-lessp (dir1 dir2)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1011 ;; Lexicographic order on pathname components, like `ls -lR':
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1012 ;; DIR1 < DIR2 iff DIR1 comes *before* DIR2 in an `ls -lR' listing,
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1013 ;; i.e., iff DIR1 is a (grand)parent dir of DIR2,
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1014 ;; or DIR1 and DIR2 are in the same parentdir and their last
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1015 ;; components are string-lessp.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1016 ;; Thus ("/usr/" "/usr/bin") and ("/usr/a/" "/usr/b/") are tree-lessp.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1017 ;; string-lessp could arguably be replaced by file-newer-than-file-p
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1018 ;; if dired-internal-switches contained `t'.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1019 (let ((dir1 (file-name-as-directory dir1))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1020 (dir2 (file-name-as-directory dir2))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1021 (start1 1)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1022 (start2 1)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1023 comp1 comp2 end1 end2)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1024 (while (progn
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1025 (setq end1 (string-match "/" dir1 start1)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1026 comp1 (substring dir1 start1 end1)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1027 end2 (string-match "/" dir2 start2)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1028 comp2 (substring dir2 start2 end2))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1029 (and end1 end2 (string-equal comp1 comp2)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1030 (setq start1 (1+ end1)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1031 start2 (1+ end2)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1032 (if (eq (null end1) (null end2))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1033 (string-lessp comp1 comp2)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1034 (null end1))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1035
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1036 ;; So that we can support case-insensitive systems.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1037 (fset 'dired-file-name-lessp 'string-lessp)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1038
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1039
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1040 ;;;; ------------------------------------------------------------------
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1041 ;;;; Initializing Dired
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1042 ;;;; ------------------------------------------------------------------
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1043
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1044 ;;; Set the minor mode alist
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1045
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1046 (or (equal (assq 'dired-sort-mode minor-mode-alist)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1047 '(dired-sort-mode dired-sort-mode))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1048 ;; Test whether this has already been done in case dired is reloaded
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1049 ;; There may be several elements with dired-sort-mode as car.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1050 (setq minor-mode-alist
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1051 ;; cons " Omit" in first, so that it doesn't
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1052 ;; get stuck between the directory and sort mode on the
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1053 ;; mode line.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1054 (cons '(dired-sort-mode dired-sort-mode)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1055 (cons '(dired-subdir-omit " Omit")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1056 (cons '(dired-marker-stack dired-marker-string)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1057 minor-mode-alist)))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1058
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1059 ;;; Keymaps
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1060
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1061 (defvar dired-mode-map nil
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1062 "Local keymap for dired-mode buffers.")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1063 (defvar dired-regexp-map nil
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1064 "Dired keymap for commands that use regular expressions.")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1065 (defvar dired-diff-map nil
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1066 "Dired keymap for diff and related commands.")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1067 (defvar dired-subdir-map nil
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1068 "Dired keymap for commands that act on subdirs, or the files within them.")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1069
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1070 (defvar dired-keymap-grokked nil
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1071 "Set to t after dired has grokked the global keymap.")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1072
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1073 (defun dired-key-description (cmd &rest prefixes)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1074 ;; Return a key description string for a menu. If prefixes are given,
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1075 ;; they should be either strings, integers, or 'universal-argument.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1076 (let ((key (where-is-internal cmd dired-mode-map t)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1077 (if key
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1078 (key-description
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1079 (apply 'vconcat
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1080 (append
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1081 (mapcar
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1082 (function
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1083 (lambda (x)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1084 (cond ((eq x 'universal-argument)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1085 (where-is-internal 'universal-argument
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1086 dired-mode-map t))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1087 ((integerp x) (int-to-string x))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1088 (t x))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1089 prefixes)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1090 (list key))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1091 "")))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1092
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1093 (defun dired-grok-keys (to-command from-command)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1094 ;; Assigns to TO-COMMAND the keys for the global binding of FROM-COMMAND.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1095 ;; Does not clobber anything in the local keymap. In emacs 19 should
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1096 ;; use substitute-key-definition, but I believe that this will
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1097 ;; clobber things in the local map.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1098 (let ((keys (where-is-internal from-command)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1099 (while keys
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1100 (condition-case nil
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1101 (if (eq (global-key-binding (car keys)) (key-binding (car keys)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1102 (local-set-key (car keys) to-command))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1103 (error nil))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1104 (setq keys (cdr keys)))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1105
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1106 (defun dired-grok-keymap ()
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1107 ;; Initialize the dired keymaps.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1108 ;; This is actually done the first time that dired-mode runs.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1109 ;; We do it this late, to be sure that the user's global-keymap has
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1110 ;; stabilized.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1111 (if dired-keymap-grokked
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1112 () ; we've done it
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1113 ;; Watch out for dired being invoked from the command line.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1114 ;; This is a bit kludgy, but so is the emacs startup sequence IMHO.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1115 (if (and term-setup-hook (boundp 'command-line-args-left))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1116 (progn
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1117 (if (string-equal "18." (substring emacs-version 0 3))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1118 (funcall term-setup-hook)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1119 (run-hooks 'term-setup-hook))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1120 (setq term-setup-hook nil)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1121 (setq dired-keymap-grokked t)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1122 (run-hooks 'dired-setup-keys-hook)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1123 (dired-grok-keys 'dired-next-line 'next-line)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1124 (dired-grok-keys 'dired-previous-line 'previous-line)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1125 (dired-grok-keys 'dired-undo 'undo)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1126 (dired-grok-keys 'dired-undo 'advertised-undo)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1127 (dired-grok-keys 'dired-scroll-up 'scroll-up)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1128 (dired-grok-keys 'dired-scroll-down 'scroll-down)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1129 (dired-grok-keys 'dired-beginning-of-buffer 'beginning-of-buffer)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1130 (dired-grok-keys 'dired-end-of-buffer 'end-of-buffer)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1131 (dired-grok-keys 'dired-next-subdir 'forward-paragraph)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1132 (dired-grok-keys 'dired-prev-subdir 'backward-paragraph)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1133
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1134 ;; The regexp-map is used for commands using regexp's.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1135 (if dired-regexp-map
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1136 ()
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1137 (setq dired-regexp-map (make-sparse-keymap))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1138 (define-key dired-regexp-map "C" 'dired-do-copy-regexp)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1139 ;; Not really a regexp, but does transform file names.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1140 (define-key dired-regexp-map "D" 'dired-downcase)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1141 (define-key dired-regexp-map "H" 'dired-do-hardlink-regexp)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1142 (define-key dired-regexp-map "R" 'dired-do-rename-regexp)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1143 (define-key dired-regexp-map "S" 'dired-do-symlink-regexp)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1144 (define-key dired-regexp-map "U" 'dired-upcase)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1145 (define-key dired-regexp-map "Y" 'dired-do-relsymlink-regexp)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1146 (define-key dired-regexp-map "c" 'dired-cleanup)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1147 (define-key dired-regexp-map "d" 'dired-flag-files-regexp)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1148 (define-key dired-regexp-map "e" 'dired-mark-extension)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1149 (define-key dired-regexp-map "m" 'dired-mark-files-regexp)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1150 (define-key dired-regexp-map "o" 'dired-add-omit-regexp)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1151 (define-key dired-regexp-map "x" 'dired-flag-extension)) ; a string, rather
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1152 ; than a regexp.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1153
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1154 (if dired-diff-map
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1155 ()
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1156 (setq dired-diff-map (make-sparse-keymap))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1157 (define-key dired-diff-map "d" 'dired-diff)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1158 (define-key dired-diff-map "b" 'dired-backup-diff)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1159 (define-key dired-diff-map "m" 'dired-emerge)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1160 (define-key dired-diff-map "a" 'dired-emerge-with-ancestor)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1161 (define-key dired-diff-map "e" 'dired-ediff)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1162 (define-key dired-diff-map "p" 'dired-epatch))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1163
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1164 (if dired-subdir-map
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1165 ()
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1166 (setq dired-subdir-map (make-sparse-keymap))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1167 (define-key dired-subdir-map "n" 'dired-redisplay-subdir)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1168 (define-key dired-subdir-map "m" 'dired-mark-subdir-files)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1169 (define-key dired-subdir-map "d" 'dired-flag-subdir-files)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1170 (define-key dired-subdir-map "z" 'dired-compress-subdir-files))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1171
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1172 (fset 'dired-regexp-prefix dired-regexp-map)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1173 (fset 'dired-diff-prefix dired-diff-map)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1174 (fset 'dired-subdir-prefix dired-subdir-map)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1175 (fset 'efs-dired-prefix (function (lambda ()
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1176 (interactive)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1177 (error "efs-dired not loaded yet"))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1178
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1179 ;; the main map
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1180 (if dired-mode-map
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1181 nil
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1182 ;; Force `f' rather than `e' in the mode doc:
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1183 (fset 'dired-advertised-find-file 'dired-find-file)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1184 (fset 'dired-advertised-next-subdir 'dired-next-subdir)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1185 (fset 'dired-advertised-prev-subdir 'dired-prev-subdir)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1186 (setq dired-mode-map (make-keymap))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1187 (suppress-keymap dired-mode-map)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1188 ;; Commands to mark certain categories of files
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1189 (define-key dired-mode-map "~" 'dired-flag-backup-files)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1190 (define-key dired-mode-map "#" 'dired-flag-auto-save-files)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1191 (define-key dired-mode-map "*" 'dired-mark-executables)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1192 (define-key dired-mode-map "." 'dired-clean-directory)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1193 (define-key dired-mode-map "/" 'dired-mark-directories)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1194 (define-key dired-mode-map "@" 'dired-mark-symlinks)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1195 (define-key dired-mode-map "," 'dired-mark-rcs-files)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1196 (define-key dired-mode-map "\M-(" 'dired-mark-sexp)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1197 (define-key dired-mode-map "\M-d" 'dired-mark-files-from-other-dired-buffer)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1198 (define-key dired-mode-map "\M-c" 'dired-mark-files-compilation-buffer)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1199 ;; Upper case keys (except ! and &) for operating on the marked files
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1200 (define-key dired-mode-map "A" 'dired-do-tags-search)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1201 (define-key dired-mode-map "B" 'dired-do-byte-compile)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1202 (define-key dired-mode-map "C" 'dired-do-copy)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1203 (define-key dired-mode-map "E" 'dired-do-grep)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1204 (define-key dired-mode-map "F" 'dired-do-find-file)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1205 (define-key dired-mode-map "G" 'dired-do-chgrp)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1206 (define-key dired-mode-map "H" 'dired-do-hardlink)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1207 (define-key dired-mode-map "I" 'dired-do-insert-subdir)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1208 (define-key dired-mode-map "K" 'dired-do-kill-file-lines)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1209 (define-key dired-mode-map "L" 'dired-do-load)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1210 (define-key dired-mode-map "M" 'dired-do-chmod)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1211 (define-key dired-mode-map "N" 'dired-do-redisplay)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1212 (define-key dired-mode-map "O" 'dired-do-chown)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1213 (define-key dired-mode-map "P" 'dired-do-print)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1214 (define-key dired-mode-map "Q" 'dired-do-tags-query-replace)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1215 (define-key dired-mode-map "R" 'dired-do-rename)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1216 (define-key dired-mode-map "S" 'dired-do-symlink)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1217 (define-key dired-mode-map "T" 'dired-do-total-size)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1218 (define-key dired-mode-map "U" 'dired-do-uucode)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1219 (define-key dired-mode-map "W" 'dired-copy-filenames-as-kill)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1220 (define-key dired-mode-map "X" 'dired-do-delete)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1221 (define-key dired-mode-map "Y" 'dired-do-relsymlink)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1222 (define-key dired-mode-map "Z" 'dired-do-compress)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1223 (define-key dired-mode-map "!" 'dired-do-shell-command)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1224 (define-key dired-mode-map "&" 'dired-do-background-shell-command)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1225 ;; Make all regexp commands share a `%' prefix:
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1226 (define-key dired-mode-map "%" 'dired-regexp-prefix)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1227 ;; Lower keys for commands not operating on all the marked files
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1228 (define-key dired-mode-map "a" 'dired-apropos)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1229 (define-key dired-mode-map "c" 'dired-change-marks)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1230 (define-key dired-mode-map "d" 'dired-flag-file-deletion)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1231 (define-key dired-mode-map "\C-d" 'dired-flag-file-deletion-backup)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1232 (define-key dired-mode-map "e" 'dired-find-file)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1233 (define-key dired-mode-map "f" 'dired-advertised-find-file)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1234 (define-key dired-mode-map "g" 'revert-buffer)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1235 (define-key dired-mode-map "h" 'dired-describe-mode)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1236 (define-key dired-mode-map "i" 'dired-maybe-insert-subdir)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1237 (define-key dired-mode-map "k" 'dired-kill-subdir)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1238 (define-key dired-mode-map "m" 'dired-mark)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1239 (define-key dired-mode-map "o" 'dired-find-file-other-window)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1240 (define-key dired-mode-map "q" 'dired-quit)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1241 (define-key dired-mode-map "r" 'dired-read-mail)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1242 (define-key dired-mode-map "s" 'dired-sort-toggle-or-edit)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1243 (define-key dired-mode-map "t" 'dired-get-target-directory)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1244 (define-key dired-mode-map "u" 'dired-unmark)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1245 (define-key dired-mode-map "v" 'dired-view-file)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1246 (define-key dired-mode-map "w" (if (fboundp 'find-file-other-frame)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1247 'dired-find-file-other-frame
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1248 'dired-find-file-other-window))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1249 (define-key dired-mode-map "x" 'dired-expunge-deletions)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1250 (define-key dired-mode-map "y" 'dired-why)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1251 (define-key dired-mode-map "+" 'dired-create-directory)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1252 (define-key dired-mode-map "`" 'dired-recover-file)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1253 ;; dired-jump-back Should be in the global map, but put them here
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1254 ;; too anyway.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1255 (define-key dired-mode-map "\C-x\C-j" 'dired-jump-back)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1256 (define-key dired-mode-map "\C-x4\C-j" 'dired-jump-back-other-window)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1257 (define-key dired-mode-map "\C-x5\C-j" 'dired-jump-back-other-frame)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1258 ;; Comparison commands
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1259 (define-key dired-mode-map "=" 'dired-diff-prefix)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1260 ;; moving
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1261 (define-key dired-mode-map "<" 'dired-prev-dirline)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1262 (define-key dired-mode-map ">" 'dired-next-dirline)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1263 (define-key dired-mode-map " " 'dired-next-line)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1264 (define-key dired-mode-map "n" 'dired-next-line)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1265 (define-key dired-mode-map "\C-n" 'dired-next-line)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1266 (define-key dired-mode-map "p" 'dired-previous-line)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1267 (define-key dired-mode-map "\C-p" 'dired-previous-line)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1268 (define-key dired-mode-map "\C-v" 'dired-scroll-up)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1269 (define-key dired-mode-map "\M-v" 'dired-scroll-down)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1270 (define-key dired-mode-map "\M-<" 'dired-beginning-of-buffer)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1271 (define-key dired-mode-map "\M->" 'dired-end-of-buffer)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1272 (define-key dired-mode-map "\C-m" 'dired-advertised-find-file)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1273 ;; motion by subdirectories
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1274 (define-key dired-mode-map "^" 'dired-up-directory)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1275 (define-key dired-mode-map "\M-\C-u" 'dired-up-directory)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1276 (define-key dired-mode-map "\M-\C-d" 'dired-down-directory)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1277 (define-key dired-mode-map "\M-\C-n" 'dired-advertised-next-subdir)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1278 (define-key dired-mode-map "\M-\C-p" 'dired-advertised-prev-subdir)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1279 (define-key dired-mode-map "\C-j" 'dired-goto-subdir)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1280 ;; move to marked files
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1281 (define-key dired-mode-map "\M-p" 'dired-prev-marked-file)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1282 (define-key dired-mode-map "\M-n" 'dired-next-marked-file)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1283 ;; hiding
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1284 (define-key dired-mode-map "$" 'dired-hide-subdir)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1285 (define-key dired-mode-map "\M-$" 'dired-hide-all)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1286 ;; omitting
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1287 (define-key dired-mode-map "\C-o" 'dired-omit-toggle)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1288 ;; markers
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1289 (define-key dired-mode-map "\(" 'dired-set-marker-char)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1290 (define-key dired-mode-map "\)" 'dired-restore-marker-char)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1291 (define-key dired-mode-map "'" 'dired-marker-stack-left)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1292 (define-key dired-mode-map "\\" 'dired-marker-stack-right)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1293 ;; misc
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1294 (define-key dired-mode-map "\C-i" 'dired-mark-prefix)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1295 (define-key dired-mode-map "?" 'dired-summary)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1296 (define-key dired-mode-map "\177" 'dired-backup-unflag)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1297 (define-key dired-mode-map "\C-_" 'dired-undo)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1298 (define-key dired-mode-map "\C-xu" 'dired-undo)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1299 (define-key dired-mode-map "\M-\C-?" 'dired-unmark-all-files)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1300 ;; The subdir map
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1301 (define-key dired-mode-map "|" 'dired-subdir-prefix)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1302 ;; efs submap
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1303 (define-key dired-mode-map "\M-e" 'efs-dired-prefix))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1304
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1305
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1306
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1307 ;;;;------------------------------------------------------------------
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1308 ;;;; The dired command
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1309 ;;;;------------------------------------------------------------------
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1310
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1311 ;;; User commands:
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1312 ;;; All of these commands should have a binding in the global keymap.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1313
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1314 ;;;###autoload (define-key ctl-x-map "d" 'dired)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1315 ;;;###autoload
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1316 (defun dired (dirname &optional switches)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1317 "\"Edit\" directory DIRNAME--delete, rename, print, etc. some files in it.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1318 Optional second argument SWITCHES specifies the `ls' options used.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1319 \(Interactively, use a prefix argument to be able to specify SWITCHES.)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1320 Dired displays a list of files in DIRNAME (which may also have
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1321 shell wildcards appended to select certain files). If DIRNAME is a cons,
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1322 its first element is taken as the directory name and the resr as an explicit
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1323 list of files to make directory entries for.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1324 \\<dired-mode-map>\
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1325 You can move around in it with the usual commands.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1326 You can flag files for deletion with \\[dired-flag-file-deletion] and then
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1327 delete them by typing \\[dired-expunge-deletions].
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1328 Type \\[dired-describe-mode] after entering dired for more info.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1329
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1330 If DIRNAME is already in a dired buffer, that buffer is used without refresh."
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1331 ;; Cannot use (interactive "D") because of wildcards.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1332 (interactive (dired-read-dir-and-switches ""))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1333 (switch-to-buffer (dired-noselect dirname switches)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1334
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1335 ;;;###autoload (define-key ctl-x-4-map "d" 'dired-other-window)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1336 ;;;###autoload
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1337 (defun dired-other-window (dirname &optional switches)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1338 "\"Edit\" directory DIRNAME. Like `dired' but selects in another window."
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1339 (interactive (dired-read-dir-and-switches "in other window "))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1340 (switch-to-buffer-other-window (dired-noselect dirname switches)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1341
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1342 ;;;###autoload (define-key ctl-x-5-map "d" 'dired-other-frame)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1343 ;;;###autoload
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1344 (defun dired-other-frame (dirname &optional switches)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1345 "\"Edit\" directory DIRNAME. Like `dired' but makes a new frame."
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1346 (interactive (dired-read-dir-and-switches "in other frame "))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1347 (switch-to-buffer-other-frame (dired-noselect dirname switches)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1348
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1349 ;;;###autoload
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1350 (defun dired-noselect (dir-or-list &optional switches)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1351 "Like `dired' but returns the dired buffer as value, does not select it."
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1352 (or dir-or-list (setq dir-or-list (expand-file-name default-directory)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1353 ;; This loses the distinction between "/foo/*/" and "/foo/*" that
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1354 ;; some shells make:
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1355 (let (dirname)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1356 (if (consp dir-or-list)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1357 (setq dirname (car dir-or-list))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1358 (setq dirname dir-or-list))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1359 (setq dirname (expand-file-name (directory-file-name dirname)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1360 (if (file-directory-p dirname)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1361 (setq dirname (file-name-as-directory dirname)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1362 (if (consp dir-or-list)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1363 (setq dir-or-list (cons dirname (cdr dir-or-list)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1364 (setq dir-or-list dirname))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1365 (dired-internal-noselect dir-or-list switches)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1366
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1367 ;; Adapted from code by wurgler@zippysun.math.uakron.edu (Tom Wurgler).
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1368 ;;;###autoload (define-key ctl-x-map "\C-j" 'dired-jump-back)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1369 ;;;###autoload
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1370 (defun dired-jump-back ()
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1371 "Jump back to dired.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1372 If in a file, dired the current directory and move to file's line.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1373 If in dired already, pop up a level and goto old directory's line.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1374 In case the proper dired file line cannot be found, refresh the dired
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1375 buffer and try again."
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1376 (interactive)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1377 (let* ((file (if (eq major-mode 'dired-mode)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1378 (directory-file-name (dired-current-directory))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1379 buffer-file-name))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1380 (dir (if file
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1381 (file-name-directory file)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1382 default-directory)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1383 (dired dir)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1384 (if file (dired-really-goto-file file))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1385
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1386 ;;;###autoload (define-key ctl-x-4-map "\C-j" 'dired-jump-back-other-window)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1387 ;;;###autoload
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1388 (defun dired-jump-back-other-window ()
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1389 "Like \\[dired-jump-back], but to other window."
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1390 (interactive)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1391 (let* ((file (if (eq major-mode 'dired-mode)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1392 (directory-file-name (dired-current-directory))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1393 buffer-file-name))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1394 (dir (if file
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1395 (file-name-directory file)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1396 default-directory)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1397 (dired-other-window dir)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1398 (if file (dired-really-goto-file file))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1399
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1400 ;;;###autoload (define-key ctl-x-5-map "\C-j" 'dired-jump-back-other-frame)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1401 ;;;###autoload
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1402 (defun dired-jump-back-other-frame ()
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1403 "Like \\[dired-jump-back], but in another frame."
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1404 (interactive)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1405 (let* ((file (if (eq major-mode 'dired-mode)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1406 (directory-file-name (dired-current-directory))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1407 buffer-file-name))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1408 (dir (if file
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1409 (file-name-directory file)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1410 default-directory)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1411 (dired-other-frame dir)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1412 (if file (dired-really-goto-file file))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1413
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1414 ;;; Dired mode
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1415
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1416 ;; Dired mode is suitable only for specially formatted data.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1417 (put 'dired-mode 'mode-class 'special)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1418
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1419 (defun dired-mode (&optional dirname switches)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1420 "\\<dired-mode-map>Dired mode is for \"editing\" directory trees.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1421
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1422 For a simple one-line help message, type \\[dired-summary]
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1423 For a moderately detailed description of dired mode, type \\[dired-describe-mode]
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1424 For the full dired info tree, type \\[universal-argument] \\[dired-describe-mode]"
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1425 ;; Not to be called interactively (e.g. dired-directory will be set
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1426 ;; to default-directory, which is wrong with wildcards).
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1427 (kill-all-local-variables)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1428 (use-local-map dired-mode-map)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1429 (setq major-mode 'dired-mode
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1430 mode-name "Dired"
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1431 case-fold-search nil
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1432 buffer-read-only t
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1433 selective-display t ; for subdirectory hiding
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1434 selective-display-ellipses nil ; for omit toggling
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1435 mode-line-buffer-identification '("Dired: %12b")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1436 mode-line-modified (format dired-mode-line-modified "--" "--" "-")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1437 dired-directory (expand-file-name (or dirname default-directory))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1438 dired-internal-switches (dired-make-switches-list
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1439 (or switches dired-listing-switches)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1440 (dired-advertise) ; default-directory is already set
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1441 (set (make-local-variable 'revert-buffer-function)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1442 (function dired-revert))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1443 (set (make-local-variable 'default-directory-function)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1444 'dired-current-directory)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1445 (set (make-local-variable 'page-delimiter)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1446 "\n\n")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1447 (set (make-local-variable 'list-buffers-directory)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1448 dired-directory)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1449 ;; Will only do something in Emacs 19.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1450 (add-hook (make-local-variable 'kill-buffer-hook)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1451 'dired-unadvertise-current-buffer)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1452 ;; Same here
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1453 (if window-system
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1454 (add-hook (make-local-variable 'post-command-hook)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1455 (function
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1456 (lambda ()
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1457 (if (memq this-command dired-modeline-tracking-cmds)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1458 (dired-update-mode-line t))))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1459 (dired-sort-other dired-internal-switches t)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1460 (dired-hack-local-variables)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1461 (run-hooks 'dired-mode-hook)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1462 ;; Run this after dired-mode-hook, in case that hook makes changes to
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1463 ;; the keymap.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1464 (dired-grok-keymap))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1465
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1466 ;;; Internal functions for starting dired
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1467
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1468 (defun dired-read-dir-and-switches (str)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1469 ;; For use in interactive.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1470 (reverse (list
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1471 (if current-prefix-arg
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1472 (read-string "Dired listing switches: "
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1473 dired-listing-switches))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1474 (let ((default-directory (default-directory)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1475 (read-file-name (format "Dired %s(directory): " str)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1476 nil default-directory nil)))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1477
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1478 (defun dired-hack-local-variables ()
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1479 "Parse, bind or evaluate any local variables for current dired buffer.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1480 See variable `dired-local-variables-file'."
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1481 (if (and dired-local-variables-file
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1482 (file-exists-p dired-local-variables-file))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1483 (let (buffer-read-only opoint )
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1484 (save-excursion
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1485 (goto-char (point-max))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1486 (setq opoint (point-marker))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1487 (insert "\^L\n")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1488 (insert-file-contents dired-local-variables-file))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1489 (let ((buffer-file-name dired-local-variables-file))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1490 (condition-case err
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1491 (hack-local-variables)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1492 (error (message "Error in dired-local-variables-file: %s" err)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1493 (sit-for 1))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1494 ;; Must delete it as (eobp) is often used as test for last
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1495 ;; subdir in dired.el.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1496 (delete-region opoint (point-max))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1497 (set-marker opoint nil))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1498
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1499 ;; Separate function from dired-noselect for the sake of dired-vms.el.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1500 (defun dired-internal-noselect (dir-or-list &optional switches mode)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1501 ;; If there is an existing dired buffer for DIRNAME, just leave
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1502 ;; buffer as it is (don't even call dired-revert).
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1503 ;; This saves time especially for deep trees or with efs.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1504 ;; The user can type `g'easily, and it is more consistent with find-file.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1505 ;; But if SWITCHES are given they are probably different from the
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1506 ;; buffer's old value, so call dired-sort-other, which does
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1507 ;; revert the buffer.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1508 ;; If the user specifies a directory with emacs startup, eg.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1509 ;; emacs ~, dir-or-list may be unexpanded at this point.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1510
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1511 (let* ((dirname (expand-file-name (if (consp dir-or-list)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1512 (car dir-or-list)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1513 dir-or-list)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1514 (buffer (dired-find-buffer-nocreate dir-or-list mode))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1515 ;; note that buffer already is in dired-mode, if found
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1516 (new-buffer-p (not buffer))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1517 (old-buf (current-buffer))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1518 wildcard)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1519 (or buffer
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1520 (let ((default-major-mode 'fundamental-mode))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1521 ;; We don't want default-major-mode to run hooks and set auto-fill
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1522 ;; or whatever, now that dired-mode does not
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1523 ;; kill-all-local-variables any longer.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1524 (setq buffer (create-file-buffer (directory-file-name dirname)))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1525 (set-buffer buffer)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1526 (if (not new-buffer-p) ; existing buffer ...
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1527 (progn
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1528 (if switches
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1529 (dired-sort-other
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1530 (if (stringp switches)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1531 (dired-make-switches-list switches)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1532 switches)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1533 (if dired-verify-modtimes (dired-verify-modtimes))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1534 (if (and dired-find-subdir
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1535 (not (string-equal (dired-current-directory)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1536 (file-name-as-directory dirname))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1537 (dired-initial-position dirname)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1538 ;; Else a new buffer
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1539 (if (file-directory-p dirname)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1540 (setq default-directory dirname
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1541 wildcard (consp dir-or-list))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1542 (setq default-directory (file-name-directory dirname)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1543 wildcard t))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1544 (or switches (setq switches dired-listing-switches))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1545 (dired-mode dirname switches)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1546 ;; default-directory and dired-internal-switches are set now
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1547 ;; (buffer-local), so we can call dired-readin:
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1548 (let ((failed t))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1549 (unwind-protect
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1550 (progn (dired-readin dir-or-list buffer wildcard)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1551 (setq failed nil))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1552 ;; dired-readin can fail if parent directories are inaccessible.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1553 ;; Don't leave an empty buffer around in that case.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1554 (if failed (kill-buffer buffer))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1555 ;; No need to narrow since the whole buffer contains just
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1556 ;; dired-readin's output, nothing else. The hook can
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1557 ;; successfully use dired functions (e.g. dired-get-filename)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1558 ;; as the subdir-alist has been built in dired-readin.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1559 (run-hooks 'dired-after-readin-hook)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1560 ;; I put omit-expunge after the dired-after-readin-hook
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1561 ;; in case that hook marks files. Does this make sense? Also, users
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1562 ;; might want to set dired-omit-files-p in some incredibly clever
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1563 ;; way depending on the contents of the directory... I don't know...
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1564 (if dired-omit-files
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1565 (dired-omit-expunge nil t))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1566 (goto-char (point-min))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1567 (dired-initial-position dirname))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1568 (set-buffer old-buf)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1569 buffer))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1570
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1571 (defun dired-find-buffer-nocreate (dir-or-list &optional mode)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1572 ;; Returns a dired buffer for DIR-OR-LIST. DIR-OR-LIST may be wildcard,
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1573 ;; or a directory and alist of files.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1574 ;; If dired-find-subdir is non-nil, is satisfied with a dired
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1575 ;; buffer containing DIR-OR-LIST as a subdirectory. If there is more
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1576 ;; than one candidate, returns the most recently used.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1577 (if dired-find-subdir
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1578 (let ((buffers (sort (delq (current-buffer)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1579 (dired-buffers-for-dir dir-or-list t))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1580 (function dired-buffer-more-recently-used-p))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1581 (or (car buffers)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1582 ;; Couldn't find another buffer. Will the current one do?
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1583 ;; It is up dired-initial-position to actually go to the subdir.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1584 (and (or (equal dir-or-list dired-directory) ; covers wildcards
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1585 (and (stringp dir-or-list)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1586 (not (string-equal
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1587 dir-or-list
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1588 (expand-file-name default-directory)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1589 (assoc (file-name-as-directory dir-or-list)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1590 dired-subdir-alist)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1591 (current-buffer))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1592 ;; Else just look through the buffer list.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1593 (let (found (blist (buffer-list)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1594 (or mode (setq mode 'dired-mode))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1595 (save-excursion
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1596 (while blist
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1597 (set-buffer (car blist))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1598 (if (and (eq major-mode mode)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1599 (equal dired-directory dir-or-list))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1600 (setq found (car blist)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1601 blist nil)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1602 (setq blist (cdr blist)))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1603 found)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1604
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1605 (defun dired-initial-position (dirname)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1606 ;; Where point should go in a new listing of DIRNAME.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1607 ;; Point assumed at beginning of new subdir line.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1608 (end-of-line)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1609 (if dired-find-subdir (dired-goto-subdir dirname))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1610 (if dired-trivial-filenames (dired-goto-next-nontrivial-file))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1611 (dired-update-mode-line t))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1612
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1613 (defun dired-readin (dir-or-list buffer &optional wildcard)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1614 ;; Read in a new dired buffer
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1615 ;; dired-readin differs from dired-insert-subdir in that it accepts
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1616 ;; wildcards, erases the buffer, and builds the subdir-alist anew
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1617 ;; (including making it buffer-local and clearing it first).
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1618 ;; default-directory and dired-internal-switches must be buffer-local
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1619 ;; and initialized by now.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1620 ;; Thus we can test (equal default-directory dirname) instead of
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1621 ;; (file-directory-p dirname) and save a filesystem transaction.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1622 ;; This is wrong, if dired-before-readin-hook changes default-directory
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1623 ;; Also, we can run this hook which may want to modify the switches
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1624 ;; based on default-directory, e.g. with efs to a SysV host
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1625 ;; where ls won't understand -Al switches.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1626 (let (dirname other-dirs)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1627 (if (consp dir-or-list)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1628 (setq dir-or-list (dired-frob-dir-list dir-or-list)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1629 other-dirs (cdr dir-or-list)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1630 dir-or-list (car dir-or-list)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1631 dirname (car dir-or-list))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1632 (setq dirname dir-or-list))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1633 (setq dirname (expand-file-name dirname))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1634 (if (consp dir-or-list)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1635 (setq dir-or-list (cons dirname (cdr dir-or-list))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1636 (save-excursion
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1637 (set-buffer buffer)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1638 (run-hooks 'dired-before-readin-hook)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1639 (message "Reading directory %s..." dirname)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1640 (let (buffer-read-only)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1641 (widen)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1642 (erase-buffer)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1643 (dired-readin-insert dir-or-list wildcard)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1644 (dired-indent-listing (point-min) (point-max))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1645 ;; We need this to make the root dir have a header line as all
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1646 ;; other subdirs have:
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1647 (goto-char (point-min))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1648 (dired-insert-headerline (expand-file-name default-directory)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1649 (message "Reading directory %s...done" dirname)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1650 (set-buffer-modified-p nil)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1651 ;; Must first make alist buffer local and set it to nil because
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1652 ;; dired-build-subdir-alist will call dired-clear-alist first
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1653 (setq dired-subdir-alist nil)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1654 (if (memq ?R dired-internal-switches)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1655 (dired-build-subdir-alist)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1656 ;; no need to parse the buffer if listing is not recursive
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1657 (dired-simple-subdir-alist))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1658 (if other-dirs
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1659 (mapcar
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1660 (function
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1661 (lambda (x)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1662 (if (dired-in-this-tree (car x) dirname)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1663 (dired-insert-subdir x))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1664 other-dirs)))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1665
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1666 ;;; Subroutines of dired-readin
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1667
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1668 (defun dired-readin-insert (dir-or-list &optional wildcard)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1669 ;; Just insert listing for the passed-in directory or
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1670 ;; directory-and-file list, assuming a clean buffer.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1671 (let* ((switches (dired-make-switches-string dired-internal-switches))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1672 (dir-is-list (consp dir-or-list))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1673 (dirname (if dir-is-list (car dir-or-list) dir-or-list)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1674 (if wildcard
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1675 (progn
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1676 (or (file-readable-p
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1677 (if dir-is-list
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1678 dirname
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1679 (directory-file-name (file-name-directory dirname))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1680 (error "Directory %s inaccessible or nonexistent" dirname))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1681 ;; else assume it contains wildcards
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1682 (dired-insert-directory dir-or-list switches t)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1683 (save-excursion
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1684 ;; insert wildcard instead of total line:
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1685 (goto-char (point-min))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1686 (if dir-is-list
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1687 (insert "list wildcard\n")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1688 (insert "wildcard " (file-name-nondirectory dirname) "\n"))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1689 (dired-insert-directory dir-or-list switches nil t))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1690
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1691 (defun dired-insert-directory (dir-or-list switches &optional wildcard full-p)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1692 ;; Do the right thing whether dir-or-list is atomic or not. If it is,
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1693 ;; insert all files listed in the cdr -- the car is the passed-in directory
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1694 ;; list.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1695 (let ((opoint (point))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1696 (insert-directory-program dired-ls-program))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1697 (if (consp dir-or-list)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1698 (mapcar
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1699 (function
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1700 (lambda (x)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1701 (insert-directory x switches wildcard)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1702 (cdr dir-or-list))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1703 (insert-directory dir-or-list switches wildcard full-p))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1704 (dired-insert-set-properties opoint (point)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1705 (setq dired-directory dir-or-list))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1706
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1707 (defun dired-frob-dir-list (dir-list)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1708 (let* ((top (file-name-as-directory (expand-file-name (car dir-list))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1709 (tail (cdr dir-list))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1710 (result (list (list top)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1711 elt dir)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1712 (setq tail
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1713 (mapcar
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1714 (function
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1715 (lambda (x)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1716 (directory-file-name (expand-file-name x top))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1717 tail))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1718 (while tail
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1719 (setq dir (file-name-directory (car tail)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1720 (if (setq elt (assoc dir result))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1721 (nconc elt (list (car tail)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1722 (nconc result (list (list dir (car tail)))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1723 (setq tail (cdr tail)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1724 result))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1725
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1726 (defun dired-insert-headerline (dir);; also used by dired-insert-subdir
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1727 ;; Insert DIR's headerline with no trailing slash, exactly like ls
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1728 ;; would, and put cursor where dired-build-subdir-alist puts subdir
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1729 ;; boundaries.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1730 (save-excursion (insert " " (directory-file-name dir) ":\n")))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1731
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1732 (defun dired-verify-modtimes ()
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1733 ;; Check the modtimes of all subdirs.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1734 (let ((alist dired-subdir-alist)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1735 on-disk in-mem badies)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1736 (while alist
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1737 (and (setq in-mem (nth 4 (car alist)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1738 (setq on-disk (dired-file-modtime (car (car alist))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1739 (not (equal in-mem on-disk))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1740 (setq badies (cons (cons (car (car alist))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1741 (nth 3 (car alist)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1742 badies)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1743 (setq alist (cdr alist)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1744 (and badies
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1745 (let* ((ofile (dired-get-filename nil t))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1746 (osub (and (null ofile) (dired-get-subdir)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1747 (opoint (point))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1748 (ocol (current-column)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1749 (unwind-protect
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1750 (and
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1751 (or (memq 'revert-subdirs dired-no-confirm)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1752 (save-window-excursion
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1753 (let ((flist (mapcar
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1754 (function
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1755 (lambda (f)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1756 (dired-abbreviate-file-name (car f))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1757 badies)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1758 (switch-to-buffer (current-buffer))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1759 (dired-mark-pop-up
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1760 "*Stale Subdirectories*" 'revert-subdirs
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1761 flist 'y-or-n-p
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1762 (if (= (length flist) 1)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1763 (concat "Subdirectory " (car flist)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1764 " has changed on disk. Re-list? ")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1765 "Subdirectories have changed on disk. Re-list? "))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1766 )))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1767 (while badies
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1768 (dired-insert-subdir (car (car badies))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1769 (cdr (car badies)) nil t)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1770 (setq badies (cdr badies))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1771 ;; We can't use dired-save-excursion here, because we are
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1772 ;; rewriting the entire listing, and not just changing a single
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1773 ;; file line.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1774 (or (if ofile
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1775 (dired-goto-file ofile)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1776 (if osub
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1777 (dired-goto-subdir osub)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1778 (progn
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1779 (goto-char opoint)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1780 (beginning-of-line)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1781 (skip-chars-forward "^\n\r" (+ (point) ocol))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1782 (dired-update-mode-line t)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1783 (dired-update-mode-line-modified t))))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1784
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1785 (defun dired-indent-listing (start end)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1786 ;; Indent a dired listing.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1787 (let (indent-tabs-mode)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1788 (indent-rigidly start end 2)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1789 ;; Quote any null lines that shouldn't be.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1790 (save-excursion
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1791 (goto-char start)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1792 (while (search-forward "\n\n" end t)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1793 (forward-char -2)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1794 (if (looking-at dired-subdir-regexp)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1795 (goto-char (match-end 3))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1796 (progn
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1797 (forward-char 1)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1798 (insert " ")))))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1799
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1800
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1801 ;;;; ------------------------------------------------------------
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1802 ;;;; Reverting a dired buffer, or specific file lines within it.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1803 ;;;; ------------------------------------------------------------
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1804
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1805 (defun dired-revert (&optional arg noconfirm)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1806 ;; Reread the dired buffer. Must also be called after
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1807 ;; dired-internal-switches have changed.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1808 ;; Should not fail even on completely garbaged buffers.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1809 ;; Preserves old cursor, marks/flags, hidden-p.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1810 (widen) ; just in case user narrowed
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1811 (let ((opoint (point))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1812 (ofile (dired-get-filename nil t))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1813 (hidden-subdirs (dired-remember-hidden))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1814 ;; switches for top-level dir
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1815 (oswitches (or (nth 3 (nth (1- (length dired-subdir-alist))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1816 dired-subdir-alist))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1817 (delq ?R (copy-sequence dired-internal-switches))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1818 ;; all other subdirs
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1819 (old-subdir-alist (cdr (reverse dired-subdir-alist)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1820 (omitted-subdirs (dired-remember-omitted))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1821 ;; do this after dired-remember-hidden, since this unhides
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1822 (mark-alist (dired-remember-marks (point-min) (point-max)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1823 (kill-files-p (save-excursion
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1824 (goto-char (point))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1825 (search-forward
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1826 (concat (char-to-string ?\r)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1827 (regexp-quote
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1828 (char-to-string
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1829 dired-kill-marker-char)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1830 nil t)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1831 buffer-read-only)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1832 ;; This is bogus, as it will not handle all the ways that efs uses cache.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1833 ;; Better to just use the fact that revert-buffer-function is a
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1834 ;; buffer-local variable, and reset it to something that knows about
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1835 ;; cache.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1836 ;; (dired-uncache
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1837 ;; (if (consp dired-directory) (car dired-directory) dired-directory))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1838 ;; treat top level dir extra (it may contain wildcards)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1839 (let ((dired-after-readin-hook nil)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1840 ;; don't run that hook for each subdir...
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1841 (dired-omit-files nil)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1842 (dired-internal-switches oswitches))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1843 (dired-readin dired-directory (current-buffer)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1844 ;; Don't test for wildcards by checking string=
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1845 ;; default-directory and dired-directory
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1846 ;; in case default-directory got munged.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1847 (or (consp dired-directory)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1848 (null (file-directory-p dired-directory))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1849 ;; The R-switch will clobber sorting of subdirs.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1850 ;; What is the right thing to do here?
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1851 (dired-insert-old-subdirs old-subdir-alist))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1852 (dired-mark-remembered mark-alist) ; mark files that were marked
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1853 (if kill-files-p (dired-do-hide dired-kill-marker-char))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1854 (run-hooks 'dired-after-readin-hook) ; no need to narrow
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1855 ;; omit-expunge after the readin hook
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1856 (save-excursion
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1857 (mapcar (function (lambda (dir)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1858 (if (dired-goto-subdir dir)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1859 (dired-omit-expunge))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1860 omitted-subdirs))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1861 ;; hide subdirs that were hidden
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1862 (save-excursion
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1863 (mapcar (function (lambda (dir)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1864 (if (dired-goto-subdir dir)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1865 (dired-hide-subdir 1))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1866 hidden-subdirs))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1867 ;; Try to get back to where we were
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1868 (or (and ofile (dired-goto-file ofile))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1869 (goto-char opoint))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1870 (dired-move-to-filename)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1871 (dired-update-mode-line t)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1872 (dired-update-mode-line-modified t)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1873
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1874 (defun dired-do-redisplay (&optional arg)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1875 "Redisplay all marked (or next ARG) files."
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1876 (interactive "P")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1877 ;; message instead of making dired-map-over-marks show-progress is
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1878 ;; much faster
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1879 (dired-map-over-marks (let ((fname (dired-get-filename)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1880 (dired-uncache fname nil)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1881 (message "Redisplaying %s..." fname)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1882 (dired-update-file-line fname))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1883 arg)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1884 (dired-update-mode-line-modified t)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1885 (message "Redisplaying...done"))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1886
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1887 (defun dired-redisplay-subdir (&optional arg)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1888 "Redisplay the current subdirectory.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1889 With a prefix prompts for listing switches."
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1890 (interactive "P")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1891 (let ((switches (and arg (dired-make-switches-list
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1892 (read-string "Switches for listing: "
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1893 (dired-make-switches-string
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1894 dired-internal-switches)))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1895 (dir (dired-current-directory))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1896 (opoint (point))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1897 (ofile (dired-get-filename nil t)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1898 (or switches
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1899 (setq switches (nth 3 (assoc dir dired-subdir-alist))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1900 (or switches
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1901 (setq switches (delq ?R (copy-sequence dired-internal-switches))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1902 (message "Redisplaying %s..." dir)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1903 (dired-uncache dir t)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1904 (dired-insert-subdir dir switches)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1905 (dired-update-mode-line-modified t)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1906 (or (and ofile (dired-goto-file ofile)) (goto-char opoint))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1907 (message "Redisplaying %s... done" dir)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1908
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1909 (defun dired-update-file-line (file)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1910 ;; Delete the current line, and insert an entry for FILE.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1911 ;; Does not update other dired buffers. Use dired-relist-file for that.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1912 (let* ((start (save-excursion (skip-chars-backward "^\n\r") (point)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1913 (char (char-after start)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1914 (dired-save-excursion
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1915 ;; don't remember omit marks
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1916 (if (memq char (list ?\040 dired-omit-marker-char))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1917 (setq char nil))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1918 ;; Delete the current-line. Even though dired-add-entry will not
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1919 ;; insert duplicates, the file for the current line may not be the same as
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1920 ;; FILE. eg. dired-do-compress
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1921 (delete-region (save-excursion (skip-chars-backward "^\n\r") (1- (point)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1922 (progn (skip-chars-forward "^\n\r") (point)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1923 ;; dired-add-entry inserts at the end of the previous line.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1924 (forward-char 1)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1925 (dired-add-entry file char t))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1926
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1927 ;;; Subroutines of dired-revert
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1928 ;;; Some of these are also used when inserting subdirs.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1929
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1930 ;; Don't want to remember omit marks, in case omission regexps
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1931 ;; were changed, before the dired-revert. If we don't unhide
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1932 ;; omitted files, we won't see their marks. Therefore we use
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1933 ;; dired-omit-unhide-region.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1934
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1935 (defun dired-remember-marks (beg end)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1936 ;; Return alist of files and their marks, from BEG to END.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1937 (if selective-display ; must unhide to make this work.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1938 (let (buffer-read-only)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1939 (subst-char-in-region (point-min) (point-max) ?\r ?\n)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1940 (dired-do-hide dired-omit-marker-char)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1941 (let (fil chr alist)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1942 (save-excursion
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1943 (goto-char beg)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1944 (while (re-search-forward dired-re-mark end t)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1945 (if (setq fil (dired-get-filename nil t))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1946 (setq chr (preceding-char)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1947 alist (cons (cons fil chr) alist)))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1948 alist))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1949
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1950 (defun dired-mark-remembered (alist)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1951 ;; Mark all files remembered in ALIST.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1952 (let (elt fil chr)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1953 (while alist
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1954 (setq elt (car alist)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1955 alist (cdr alist)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1956 fil (car elt)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1957 chr (cdr elt))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1958 (if (dired-goto-file fil)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1959 (save-excursion
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1960 (beginning-of-line)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1961 (dired-substitute-marker (point) (following-char) chr))))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1962
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1963 (defun dired-remember-hidden ()
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1964 ;; Return a list of all hidden subdirs.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1965 (let ((l dired-subdir-alist) dir result min)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1966 (while l
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1967 (setq dir (car (car l))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1968 min (dired-get-subdir-min (car l))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1969 l (cdr l))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1970 (if (and (>= min (point-min)) (<= min (point-max))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1971 (dired-subdir-hidden-p dir))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1972 (setq result (cons dir result))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1973 result))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1974
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1975 (defun dired-insert-old-subdirs (old-subdir-alist)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1976 ;; Try to insert all subdirs that were displayed before
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1977 (let (elt dir switches)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1978 (while old-subdir-alist
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1979 (setq elt (car old-subdir-alist)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1980 old-subdir-alist (cdr old-subdir-alist)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1981 dir (car elt)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1982 switches (or (nth 3 elt) dired-internal-switches))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1983 (condition-case ()
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1984 (dired-insert-subdir dir switches)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1985 (error nil)))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1986
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1987 (defun dired-uncache (file dir-p)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1988 ;; Remove directory DIR from any directory cache.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1989 ;; If DIR-P is non-nil, then FILE is a directory
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1990 (let ((handler (find-file-name-handler file 'dired-uncache)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1991 (if handler
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1992 (funcall handler 'dired-uncache file dir-p))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1993
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1994
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1995 ;;;; -------------------------------------------------------------
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1996 ;;;; Inserting subdirectories
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1997 ;;;; -------------------------------------------------------------
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1998
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1999 (defun dired-maybe-insert-subdir (dirname &optional
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2000 switches no-error-if-not-dir-p)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2001 "Insert this subdirectory into the same dired buffer.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2002 If it is already present, just move to it (type \\[dired-do-redisplay] to
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2003 refresh), else inserts it at its natural place (as ls -lR would have done).
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2004 With a prefix arg, you may edit the ls switches used for this listing.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2005 You can add `R' to the switches to expand the whole tree starting at
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2006 this subdirectory.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2007 This function takes some pains to conform to ls -lR output."
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2008 (interactive
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2009 (list (dired-get-filename)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2010 (if current-prefix-arg
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2011 (dired-make-switches-list
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2012 (read-string "Switches for listing: "
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2013 (dired-make-switches-string
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2014 dired-internal-switches))))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2015 (let ((opoint (point)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2016 ;; We don't need a marker for opoint as the subdir is always
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2017 ;; inserted *after* opoint.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2018 (setq dirname (file-name-as-directory dirname))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2019 (or (and (not switches)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2020 (dired-goto-subdir dirname))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2021 (dired-insert-subdir dirname switches no-error-if-not-dir-p))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2022 ;; Push mark so that it's easy to find back. Do this after the
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2023 ;; insert message so that the user sees the `Mark set' message.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2024 (push-mark opoint)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2025
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2026 (defun dired-insert-subdir (dir-or-list &optional
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2027 switches no-error-if-not-dir-p no-posn)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2028 "Insert this subdirectory into the same dired buffer.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2029 If it is already present, overwrites previous entry,
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2030 else inserts it at its natural place (as ls -lR would have done).
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2031 With a prefix arg, you may edit the ls switches used for this listing.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2032 You can add `R' to the switches to expand the whole tree starting at
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2033 this subdirectory.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2034 This function takes some pains to conform to ls -lR output."
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2035 ;; NO-ERROR-IF-NOT-DIR-P needed for special filesystems like
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2036 ;; Prospero where dired-ls does the right thing, but
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2037 ;; file-directory-p has not been redefined.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2038 ;; SWITCHES should be a list.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2039 ;; If NO-POSN is non-nil, doesn't bother position the point at
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2040 ;; the first nontrivial file line. This can be used as an efficiency
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2041 ;; hack when calling this from a program.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2042 (interactive
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2043 (list (dired-get-filename)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2044 (if current-prefix-arg
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2045 (dired-make-switches-list
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2046 (read-string "Switches for listing: "
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2047 (dired-make-switches-string
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2048 dired-internal-switches))))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2049 (let ((dirname (if (consp dir-or-list) (car dir-or-list) dir-or-list)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2050 (setq dirname (file-name-as-directory (expand-file-name dirname)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2051 (or (dired-in-this-tree dirname (expand-file-name default-directory))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2052 (error "%s: not in this directory tree" dirname))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2053 (or no-error-if-not-dir-p
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2054 (file-directory-p dirname)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2055 (error "Attempt to insert a non-directory: %s" dirname))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2056 (if switches
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2057 (or (dired-compatible-switches-p dired-internal-switches switches)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2058 (error "Cannot have subdirs with %s and %s switches together."
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2059 (dired-make-switches-string dired-internal-switches)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2060 (dired-make-switches-string switches)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2061 (setq switches dired-internal-switches))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2062 (let ((elt (assoc dirname dired-subdir-alist))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2063 mark-alist opoint-max buffer-read-only)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2064 (if (memq ?R switches)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2065 ;; avoid duplicated subdirs
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2066 (progn
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2067 (setq mark-alist (dired-kill-tree dirname t))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2068 (dired-insert-subdir-newpos dirname))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2069 (if elt
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2070 ;; If subdir is already present, remove it and remember its marks
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2071 (setq mark-alist (dired-insert-subdir-del elt))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2072 ;; else move to new position
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2073 (dired-insert-subdir-newpos dirname)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2074 (setq opoint-max (point-max))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2075 (condition-case nil
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2076 (dired-insert-subdir-doupdate
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2077 dirname (dired-insert-subdir-doinsert dir-or-list switches)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2078 switches elt mark-alist)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2079 (quit ; watch out for aborted inserts
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2080 (and (= opoint-max (point-max))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2081 (null elt)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2082 (= (preceding-char) ?\n)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2083 (delete-char -1))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2084 (signal 'quit nil))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2085 (or no-posn (dired-initial-position dirname))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2086
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2087 (defun dired-do-insert-subdir ()
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2088 "Insert all marked subdirectories in situ that are not yet inserted.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2089 Non-directories are silently ignored."
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2090 (interactive)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2091 (let ((files (or (dired-get-marked-files)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2092 (error "No files marked."))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2093 (while files
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2094 (if (file-directory-p (car files))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2095 (save-excursion (dired-maybe-insert-subdir (car files))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2096 (setq files (cdr files)))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2097
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2098 ;;; Utilities for inserting subdirectories
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2099
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2100 (defun dired-insert-subdir-newpos (new-dir)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2101 ;; Find pos for new subdir, according to tree order.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2102 (let ((alist dired-subdir-alist) elt dir new-pos)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2103 (while alist
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2104 (setq elt (car alist)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2105 alist (cdr alist)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2106 dir (car elt))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2107 (if (dired-tree-lessp dir new-dir)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2108 ;; Insert NEW-DIR after DIR
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2109 (setq new-pos (dired-get-subdir-max elt)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2110 alist nil)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2111 (goto-char new-pos))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2112 (insert "\n")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2113 (point))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2114
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2115 (defun dired-insert-subdir-del (element)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2116 ;; Erase an already present subdir (given by ELEMENT) from buffer.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2117 ;; Move to that buffer position. Return a mark-alist.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2118 (let ((begin-marker (dired-get-subdir-min element)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2119 (goto-char begin-marker)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2120 ;; Are at beginning of subdir (and inside it!). Now determine its end:
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2121 (goto-char (dired-subdir-max))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2122 (prog1
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2123 (dired-remember-marks begin-marker (point))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2124 (delete-region begin-marker (point)))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2125
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2126 (defun dired-insert-subdir-doinsert (dir-or-list switches)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2127 ;; Insert ls output after point and put point on the correct
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2128 ;; position for the subdir alist.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2129 ;; Return the boundary of the inserted text (as list of BEG and END).
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2130 ;; SWITCHES should be a non-nil list.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2131 (let ((begin (point))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2132 (dirname (if (consp dir-or-list) (car dir-or-list) dir-or-list))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2133 end)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2134 (message "Reading directory %s..." dirname)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2135 (if (string-equal dirname (car (car (reverse dired-subdir-alist))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2136 ;; top level directory may contain wildcards:
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2137 (let ((dired-internal-switches switches))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2138 (dired-readin-insert dired-directory
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2139 (null (file-directory-p dired-directory))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2140 (let ((switches (dired-make-switches-string switches))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2141 (insert-directory-program dired-ls-program))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2142 (if (consp dir-or-list)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2143 (progn
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2144 (insert "list wildcard\n")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2145 (mapcar
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2146 (function
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2147 (lambda (x)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2148 (insert-directory x switches t)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2149 (cdr dir-or-list)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2150 (insert-directory dirname switches nil t))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2151 (message "Reading directory %s...done" dirname)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2152 (setq end (point-marker))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2153 (dired-indent-listing begin end)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2154 (dired-insert-set-properties begin end)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2155 ;; call dired-insert-headerline afterwards, as under VMS dired-ls
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2156 ;; does insert the headerline itself and the insert function just
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2157 ;; moves point.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2158 ;; Need a marker for END as this inserts text.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2159 (goto-char begin)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2160 (dired-insert-headerline dirname)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2161 ;; point is now like in dired-build-subdir-alist
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2162 (prog1
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2163 (list begin (marker-position end))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2164 (set-marker end nil))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2165
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2166 (defun dired-insert-subdir-doupdate (dirname beg-end switches elt mark-alist)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2167 ;; Point is at the correct subdir alist position for ELT,
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2168 ;; BEG-END is the subdir-region (as list of begin and end).
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2169 ;; SWITCHES must be a non-nil list.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2170 (if (memq ?R switches)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2171 ;; This will remove ?R from switches on purpose.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2172 (let ((dired-internal-switches (delq ?R switches)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2173 (dired-build-subdir-alist))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2174 (if elt
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2175 (progn
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2176 (set-marker (dired-get-subdir-min elt) (point-marker))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2177 (setcar (nthcdr 3 elt) switches)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2178 (if dired-verify-modtimes
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2179 (dired-set-file-modtime dirname dired-subdir-alist)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2180 (dired-alist-add dirname (point-marker) dired-omit-files switches)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2181 (save-excursion
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2182 (let ((begin (nth 0 beg-end))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2183 (end (nth 1 beg-end)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2184 (goto-char begin)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2185 (save-restriction
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2186 (narrow-to-region begin end)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2187 ;; hook may add or delete lines, but the subdir boundary
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2188 ;; marker floats
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2189 (run-hooks 'dired-after-readin-hook)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2190 (if mark-alist (dired-mark-remembered mark-alist))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2191 (dired-do-hide dired-kill-marker-char)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2192 (if (if elt (nth 2 elt) dired-omit-files)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2193 (dired-omit-expunge nil t))))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2194
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2195
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2196 ;;;; --------------------------------------------------------------
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2197 ;;;; Dired motion commands -- moving around in the dired buffer.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2198 ;;;; --------------------------------------------------------------
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2199
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2200 (defun dired-next-line (arg)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2201 "Move down lines then position at filename.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2202 Optional prefix ARG says how many lines to move; default is one line."
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2203 (interactive "p")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2204 (condition-case err
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2205 (next-line arg)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2206 (error
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2207 (if (eobp)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2208 (error "End of buffer")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2209 (error "%s" err))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2210 (dired-move-to-filename)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2211 (dired-update-mode-line))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2212
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2213 (defun dired-previous-line (arg)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2214 "Move up lines then position at filename.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2215 Optional prefix ARG says how many lines to move; default is one line."
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2216 (interactive "p")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2217 (previous-line arg)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2218 (dired-move-to-filename)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2219 (dired-update-mode-line))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2220
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2221 (defun dired-scroll-up (arg)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2222 "Dired version of scroll up.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2223 Scroll text of current window upward ARG lines; or near full screen if no ARG.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2224 When calling from a program, supply a number as argument or nil."
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2225 (interactive "P")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2226 (scroll-up arg)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2227 (dired-move-to-filename)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2228 (dired-update-mode-line))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2229
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2230 (defun dired-scroll-down (arg)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2231 "Dired version of scroll-down.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2232 Scroll text of current window down ARG lines; or near full screen if no ARG.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2233 When calling from a program, supply a number as argument or nil."
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2234 (interactive "P")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2235 (scroll-down arg)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2236 (dired-move-to-filename)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2237 (dired-update-mode-line))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2238
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2239 (defun dired-beginning-of-buffer (arg)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2240 "Dired version of `beginning of buffer'."
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2241 (interactive "P")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2242 (beginning-of-buffer arg)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2243 (dired-update-mode-line))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2244
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2245 (defun dired-end-of-buffer (arg)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2246 "Dired version of `end-of-buffer'."
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2247 (interactive "P")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2248 (end-of-buffer arg)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2249 (while (not (or (dired-move-to-filename) (dired-get-subdir) (bobp)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2250 (forward-line -1))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2251 (dired-update-mode-line t))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2252
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2253 (defun dired-next-dirline (arg &optional opoint)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2254 "Goto ARG'th next directory file line."
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2255 (interactive "p")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2256 (if dired-re-dir
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2257 (progn
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2258 (dired-check-ls-l)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2259 (or opoint (setq opoint (point)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2260 (if (if (> arg 0)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2261 (re-search-forward dired-re-dir nil t arg)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2262 (beginning-of-line)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2263 (re-search-backward dired-re-dir nil t (- arg)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2264 (progn
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2265 (dired-move-to-filename) ; user may type `i' or `f'
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2266 (dired-update-mode-line))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2267 (goto-char opoint)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2268 (error "No more subdirectories")))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2269
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2270 (defun dired-prev-dirline (arg)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2271 "Goto ARG'th previous directory file line."
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2272 (interactive "p")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2273 (dired-next-dirline (- arg)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2274
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2275 (defun dired-next-marked-file (arg &optional wrap opoint)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2276 "Move to the next marked file, wrapping around the end of the buffer."
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2277 (interactive "p\np")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2278 (or opoint (setq opoint (point))) ; return to where interactively started
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2279 (if (if (> arg 0)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2280 (re-search-forward dired-re-mark nil t arg)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2281 (beginning-of-line)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2282 (re-search-backward dired-re-mark nil t (- arg)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2283 (dired-move-to-filename)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2284 (if (null wrap)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2285 (progn
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2286 (goto-char opoint)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2287 (error "No next marked file"))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2288 (message "(Wraparound for next marked file)")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2289 (goto-char (if (> arg 0) (point-min) (point-max)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2290 (dired-next-marked-file arg nil opoint)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2291 (dired-update-mode-line))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2292
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2293 (defun dired-prev-marked-file (arg &optional wrap)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2294 "Move to the previous marked file, wrapping around the end of the buffer."
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2295 (interactive "p\np")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2296 (dired-next-marked-file (- arg) wrap)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2297 (dired-update-mode-line))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2298
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2299 (defun dired-goto-file (file)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2300 "Goto file line of FILE in this dired buffer."
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2301 ;; Return value of point on success, else nil.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2302 ;; FILE must be an absolute pathname.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2303 ;; Loses if FILE contains control chars like "\007" for which ls
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2304 ;; either inserts "?" or "\\007" into the buffer, so we won't find
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2305 ;; it in the buffer.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2306 (interactive
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2307 (prog1 ; let push-mark display its message
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2308 (list
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2309 (let* ((dired-completer-buffer (current-buffer))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2310 (dired-completer-switches dired-internal-switches)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2311 (stack (reverse
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2312 (mapcar (function
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2313 (lambda (x)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2314 (dired-abbreviate-file-name (car x))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2315 dired-subdir-alist)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2316 (initial (car stack))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2317 (dired-goto-file-history (cdr stack))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2318 dired-completer-cache)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2319 (expand-file-name
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2320 (dired-completing-read "Goto file: "
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2321 'dired-goto-file-completer
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2322 nil t initial 'dired-goto-file-history))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2323 (push-mark)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2324 (setq file (directory-file-name file)) ; does no harm if no directory
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2325 (let (found case-fold-search)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2326 (save-excursion
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2327 (if (dired-goto-subdir (or (file-name-directory file)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2328 (error "Need absolute pathname for %s"
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2329 file)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2330 (let* ((base (file-name-nondirectory file))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2331 ;; filenames are preceded by SPC, this makes
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2332 ;; the search faster (e.g. for the filename "-"!).
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2333 (search (concat " " (dired-make-filename-string base t)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2334 (boundary (dired-subdir-max))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2335 fn)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2336 (while (and (not found) (search-forward search boundary 'move))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2337 ;; Match could have BASE just as initial substring or
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2338 ;; or in permission bits or date or
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2339 ;; not be a proper filename at all:
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2340 (if (and (setq fn (dired-get-filename 'no-dir t))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2341 (string-equal fn base))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2342 ;; Must move to filename since an (actually
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2343 ;; correct) match could have been elsewhere on the
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2344 ;; line (e.g. "-" would match somewhere in the
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2345 ;; permission bits).
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2346 (setq found (dired-move-to-filename)))))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2347 (and found
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2348 ;; return value of point (i.e., FOUND):
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2349 (prog1
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2350 (goto-char found)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2351 (dired-update-mode-line)))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2352
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2353 ;;; Moving by subdirectories
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2354
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2355 (defun dired-up-directory (arg)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2356 "Move to the ARG'th (prefix arg) parent directory of current directory.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2357 Always stays within the current tree dired buffer. Will insert new
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2358 subdirectories if necessary."
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2359 (interactive "p")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2360 (if (< arg 0) (error "Can't go up a negative number of directories!"))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2361 (or (zerop arg)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2362 (let* ((dir (dired-current-directory))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2363 (n arg)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2364 (up dir))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2365 (while (> n 0)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2366 (setq up (file-name-directory (directory-file-name up))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2367 n (1- n)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2368 (if (and (< (length up) (length dired-directory))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2369 (dired-in-this-tree dired-directory up))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2370 (if (or (memq 'create-top-dir dired-no-confirm)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2371 (y-or-n-p
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2372 (format "Insert new top dir %s and rename buffer? "
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2373 (dired-abbreviate-file-name up))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2374 (let ((newname (let (buff)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2375 (unwind-protect
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2376 (buffer-name
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2377 (setq buff
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2378 (create-file-buffer
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2379 (directory-file-name up))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2380 (kill-buffer buff))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2381 (buffer-read-only nil))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2382 (push-mark)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2383 (widen)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2384 (goto-char (point-min))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2385 (insert-before-markers "\n")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2386 (forward-char -1)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2387 (dired-insert-subdir-doupdate
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2388 up (dired-insert-subdir-doinsert up dired-internal-switches)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2389 dired-internal-switches nil nil)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2390 (dired-initial-position up)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2391 (rename-buffer newname)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2392 (dired-unadvertise default-directory)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2393 (setq default-directory up
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2394 dired-directory up)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2395 (dired-advertise)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2396 (dired-maybe-insert-subdir up)))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2397
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2398 (defun dired-down-directory ()
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2399 "Go down in the dired tree.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2400 Moves to the first subdirectory of the current directory, which exists in
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2401 the dired buffer. Does not take a prefix argument."
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2402 ;; What would a prefix mean here?
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2403 (interactive)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2404 (let ((dir (dired-current-directory)) ; has slash
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2405 (rest (reverse dired-subdir-alist))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2406 pos elt)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2407 (while rest
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2408 (setq elt (car rest))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2409 (if (dired-in-this-tree (directory-file-name (car elt)) dir)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2410 (setq rest nil
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2411 pos (dired-goto-subdir (car elt)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2412 (setq rest (cdr rest))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2413 (prog1
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2414 (if pos
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2415 (progn
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2416 (push-mark)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2417 (goto-char pos))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2418 (error "At the bottom"))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2419 (dired-update-mode-line t))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2420
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2421 (defun dired-next-subdir (arg &optional no-error-if-not-found no-skip)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2422 "Go to next subdirectory, regardless of level."
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2423 ;; Use 0 arg to go to this directory's header line.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2424 ;; NO-SKIP prevents moving to end of header line, returning whatever
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2425 ;; position was found in dired-subdir-alist.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2426 (interactive "p")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2427 (let ((this-dir (dired-current-directory))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2428 pos index)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2429 ;; nth with negative arg does not return nil but the first element
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2430 (setq index (- (length dired-subdir-alist)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2431 (length (memq (assoc this-dir dired-subdir-alist)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2432 dired-subdir-alist))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2433 arg))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2434 (setq pos (if (>= index 0)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2435 (dired-get-subdir-min (nth index dired-subdir-alist))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2436 (if pos
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2437 (if no-skip
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2438 (goto-char pos)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2439 (goto-char pos)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2440 (skip-chars-forward "^\r\n")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2441 (if (= (following-char) ?\r)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2442 (skip-chars-backward "." (- (point) 3)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2443 (dired-update-mode-line t)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2444 (point))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2445 (if no-error-if-not-found
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2446 nil ; return nil if not found
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2447 (error "%s directory" (if (> arg 0) "Last" "First"))))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2448
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2449 (defun dired-prev-subdir (arg &optional no-error-if-not-found no-skip)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2450 "Go to previous subdirectory, regardless of level.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2451 When called interactively and not on a subdir line, go to this subdir's line."
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2452 (interactive
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2453 (list (if current-prefix-arg
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2454 (prefix-numeric-value current-prefix-arg)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2455 ;; if on subdir start already, don't stay there!
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2456 (if (dired-get-subdir) 1 0))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2457 (dired-next-subdir (- arg) no-error-if-not-found no-skip))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2458
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2459 (defun dired-goto-subdir (dir)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2460 "Goto end of header line of DIR in this dired buffer.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2461 Return value of point on success, otherwise return nil.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2462 The next char is either \\n, or \\r if DIR is hidden."
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2463 (interactive
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2464 (prog1 ; let push-mark display its message
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2465 (list
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2466 (let* ((table (mapcar
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2467 (function
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2468 (lambda (x)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2469 (list (dired-abbreviate-file-name
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2470 (car x)))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2471 dired-subdir-alist))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2472 (stack (reverse (mapcar 'car table)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2473 (initial (car stack))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2474 (dired-goto-file-history (cdr stack)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2475 (expand-file-name
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2476 (dired-completing-read "Goto subdirectory " table nil t
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2477 initial 'dired-goto-file-history))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2478 (push-mark)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2479 (setq dir (file-name-as-directory dir))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2480 (let ((elt (assoc dir dired-subdir-alist)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2481 (and elt
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2482 ;; need to make sure that we get where we're going.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2483 ;; beware: narrowing might be in effect
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2484 (eq (goto-char (dired-get-subdir-min elt)) (point))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2485 (progn
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2486 ;; dired-subdir-hidden-p and dired-add-entry depend on point being
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2487 ;; at either \n or looking-at ...\r after this function succeeds.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2488 (skip-chars-forward "^\r\n")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2489 (if (= (preceding-char) ?.)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2490 (skip-chars-backward "." (- (point) 3)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2491 (if (interactive-p) (dired-update-mode-line))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2492 (point)))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2493
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2494 ;;; Internals for motion commands
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2495
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2496 (defun dired-update-mode-line (&optional force)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2497 "Updates the mode line in dired according to the position of the point.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2498 Normally this uses a cache of the boundaries of the current subdirectory,
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2499 but if the optional argument FORCE is non-nil, then modeline is always
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2500 updated and the cache is recomputed."
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2501 (if (or force
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2502 (>= (point) dired-curr-subdir-max)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2503 (< (point) dired-curr-subdir-min))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2504 (let ((alist dired-subdir-alist)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2505 min max)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2506 (while (and alist (< (point)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2507 (setq min (dired-get-subdir-min (car alist)))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2508 (setq alist (cdr alist)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2509 max min))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2510 (setq dired-curr-subdir-max (or max (point-max-marker))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2511 dired-curr-subdir-min (or min (point-min-marker))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2512 dired-subdir-omit (nth 2 (car alist)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2513 (dired-sort-set-modeline (nth 3 (car alist))))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2514
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2515 (defun dired-manual-move-to-filename (&optional raise-error bol eol)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2516 "In dired, move to first char of filename on this line.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2517 Returns position (point) or nil if no filename on this line."
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2518 ;; This is the UNIX version.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2519 ;; have to be careful that we don't move to omitted files
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2520 (let (case-fold-search)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2521
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2522 (or eol (setq eol (save-excursion (skip-chars-forward "^\r\n") (point))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2523 (or bol (setq bol (progn (skip-chars-backward "^\r\n") (point))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2524
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2525 (if (or (memq ?l dired-internal-switches)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2526 (memq ?g dired-internal-switches))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2527 (if (and
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2528 (> (- eol bol) 17) ; a valid file line must have at least
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2529 ; 17 chars. 2 leading, 10 perms,
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2530 ; separator, node #, separator, owner,
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2531 ; separator
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2532 (goto-char (+ bol 17))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2533 (re-search-forward dired-re-month-and-time eol t))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2534 (point)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2535 (goto-char bol)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2536 (if raise-error
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2537 (error "No file on this line")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2538 nil))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2539 ;; else ls switches don't contain -l.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2540 ;; Note that even if we make dired-move-to-filename and
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2541 ;; dired-move-to-end-of-filename (and thus dired-get-filename)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2542 ;; work, all commands that gleaned information from the permission
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2543 ;; bits (like dired-mark-directories) will cease to work properly.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2544 (if (= bol eol)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2545 (if raise-error
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2546 (error "No file on this line")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2547 nil)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2548 ;; skip marker, if any
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2549 (goto-char bol)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2550 (forward-char))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2551 ;; If we not going to use the l switch, and use nstd listings,
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2552 ;; then we must bomb on files starting with spaces.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2553 (skip-chars-forward " \t")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2554 (point))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2555
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2556 (defun dired-manual-move-to-end-of-filename (&optional no-error bol eol)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2557 ;; Assumes point is at beginning of filename,
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2558 ;; thus the rwx bit re-search-backward below will succeed in *this*
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2559 ;; line if at all. So, it should be called only after
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2560 ;; (dired-move-to-filename t).
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2561 ;; On failure, signals an error (with non-nil NO-ERROR just returns nil).
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2562 ;; This is the UNIX version.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2563 (let ((bof (point))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2564 file-type modes-start case-fold-search)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2565 (or eol (setq eol (save-excursion (skip-chars-forward "^\r\n") (point))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2566 (or bol (setq bol (save-excursion (skip-chars-backward "^\r\n") (point))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2567 (and
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2568 (null no-error)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2569 selective-display
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2570 (eq (char-after (1- bol)) ?\r)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2571 (cond
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2572 ((dired-subdir-hidden-p (dired-current-directory))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2573 (error
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2574 (substitute-command-keys
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2575 "File line is hidden. Type \\[dired-hide-subdir] to unhide.")))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2576 ((error
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2577 (substitute-command-keys
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2578 "File line is omitted. Type \\[dired-omit-toggle] to un-omit.")))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2579 (if (or (memq ?l dired-internal-switches)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2580 (memq ?g dired-internal-switches))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2581 (if (save-excursion
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2582 (goto-char bol)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2583 (re-search-forward
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2584 "[^ ][-r][-w][^ ][-r][-w][^ ][-r][-w][^ ][-+ 0-9+]"
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2585 bof t))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2586 (progn
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2587 (setq modes-start (match-beginning 0)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2588 file-type (char-after modes-start))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2589 ;; Move point to end of name:
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2590 (if (eq file-type ?l) ; symlink
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2591 (progn
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2592 (if (search-forward " -> " eol t)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2593 (goto-char (match-beginning 0))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2594 (goto-char eol))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2595 (and dired-ls-F-marks-symlinks
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2596 (eq (preceding-char) ?@) ; link really marked?
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2597 (memq ?F dired-internal-switches)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2598 (forward-char -1))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2599 (point))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2600 ;; else not a symbolic link
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2601 (goto-char eol)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2602 ;; ls -lF marks dirs, sockets and executables with exactly
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2603 ;; one trailing character. -F may not actually be honored,
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2604 ;; e.g. by an FTP ls in efs
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2605 (and
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2606 (memq ?F dired-internal-switches)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2607 (let ((char (preceding-char)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2608 (or (and (eq char ?*) (or
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2609 (memq
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2610 (char-after (+ modes-start 3))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2611 '(?x ?s ?t))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2612 (memq
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2613 (char-after (+ modes-start 6))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2614 '(?x ?s ?t))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2615 (memq
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2616 (char-after (+ modes-start 9))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2617 '(?x ?s ?t))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2618 (and (eq char ?=) (eq file-type ?s))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2619 (forward-char -1))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2620 ;; Skip back over /'s unconditionally. It's not a valid
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2621 ;; file name character.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2622 (skip-chars-backward "/")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2623 (point)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2624 (and (null no-error)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2625 (error "No file on this line")))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2626
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2627 ;; A brief listing
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2628 (if (eq (point) eol)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2629 (and (null no-error)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2630 (error "No file on this line"))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2631 (goto-char eol)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2632 (if (and (memq (preceding-char) '(?@ ?* ?=))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2633 (memq ?F dired-internal-switches))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2634 ;; A guess, since without a long listing, we can't be sure.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2635 (forward-char -1))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2636 (skip-chars-backward "/")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2637 (point)))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2638
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2639 (defun dired-goto-next-nontrivial-file ()
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2640 ;; Position point on first nontrivial file after point.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2641 ;; Does not move into the next sudir.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2642 ;; If point is on a file line, moves to that file.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2643 ;; This does not move to omitted files.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2644 (skip-chars-backward "^\n\r")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2645 (if (= (preceding-char) ?\r)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2646 (forward-line 1))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2647 (let ((max (dired-subdir-max))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2648 file)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2649 (while (and (or (not (setq file (dired-get-filename 'no-dir t)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2650 (string-match dired-trivial-filenames file))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2651 (< (point) max))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2652 (forward-line 1)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2653 (dired-move-to-filename))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2654
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2655 (defun dired-goto-next-file ()
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2656 ;; Doesn't move out of current subdir. Does go to omitted files.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2657 ;; Returns the starting position of the file, or nil if none found.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2658 (let ((max (dired-subdir-max))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2659 found)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2660 (while (and (null (setq found (dired-move-to-filename))) (< (point) max))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2661 (skip-chars-forward "^\n\r")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2662 (forward-char 1))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2663 found))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2664
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2665 ;; fluid vars used by dired-goto-file-completer
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2666 (defvar dired-completer-buffer nil)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2667 (defvar dired-completer-switches nil)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2668 (defvar dired-completer-cache nil)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2669
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2670 (defun dired-goto-file-completer (string pred action)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2671 (save-excursion
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2672 (set-buffer dired-completer-buffer)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2673 (let* ((saved-md (match-data))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2674 (file (file-name-nondirectory string))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2675 (dir (file-name-directory string))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2676 (xstring (expand-file-name string))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2677 (xdir (file-name-directory xstring))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2678 (exact (dired-goto-file xstring)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2679 (unwind-protect
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2680 (if (dired-goto-subdir xdir)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2681 (let ((table (cdr (assoc xdir dired-completer-cache)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2682 fn result max)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2683 (or table
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2684 (progn
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2685 (setq table (make-vector 37 0))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2686 (mapcar (function
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2687 (lambda (ent)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2688 (setq ent (directory-file-name
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2689 (car ent)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2690 (if (string-equal
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2691 (file-name-directory ent) xdir)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2692 (intern
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2693 (concat
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2694 (file-name-nondirectory ent) "/")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2695 table))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2696 dired-subdir-alist)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2697 (or (looking-at "\\.\\.\\.\n\r")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2698 (progn
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2699 (setq max (dired-subdir-max))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2700 (while (and
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2701 (< (point) max)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2702 (not
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2703 (setq fn
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2704 (dired-get-filename 'no-dir t))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2705 (forward-line 1))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2706 (if fn
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2707 (progn
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2708 (or (intern-soft (concat fn "/") table)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2709 (intern fn table))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2710 (forward-line 1)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2711 (while (setq fn
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2712 (dired-get-filename 'no-dir t))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2713 (or (intern-soft (concat fn "/") table)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2714 (intern fn table))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2715 (forward-line 1))))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2716 (setq dired-completer-cache (cons
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2717 (cons xdir table)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2718 dired-completer-cache))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2719 (cond
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2720 ((null action)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2721 (setq result (try-completion file table))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2722 (if exact
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2723 (if (stringp result)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2724 string
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2725 t)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2726 (if (stringp result)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2727 (concat dir result)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2728 result)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2729 ((eq action t)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2730 (setq result (all-completions file table))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2731 (if exact (cons "." result) result))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2732 ((eq 'lambda action)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2733 (and (or exact (intern-soft file table)))))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2734 (store-match-data saved-md)))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2735
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2736 (defun dired-really-goto-file (file)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2737 ;; Goes to a file, even if it needs to insert it parent directory.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2738 (or (dired-goto-file file)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2739 (progn ; refresh and try again
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2740 (dired-insert-subdir (file-name-directory file))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2741 (dired-goto-file file))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2742
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2743 (defun dired-between-files ()
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2744 ;; Point must be at beginning of line
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2745 (save-excursion (not (dired-move-to-filename nil (point)))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2746
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2747 (defun dired-repeat-over-lines (arg function)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2748 ;; This version skips non-file lines.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2749 ;; Skips file lines hidden with selective display.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2750 ;; BACKWARDS means move backwards after each action. This is not the same
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2751 ;; as a negative arg, as that skips the current line.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2752 (beginning-of-line)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2753 (let* ((advance (cond ((> arg 0) 1) ((< arg 0) -1) (t nil)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2754 (check-fun (if (eq advance 1) 'eobp 'bobp))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2755 (n (if (< arg 0) (- arg) arg))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2756 (wall (funcall check-fun))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2757 (done wall))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2758 (while (not done)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2759 (if advance
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2760 (progn
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2761 (while (not (or (save-excursion (dired-move-to-filename))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2762 (setq wall (funcall check-fun))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2763 (forward-line advance))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2764 (or wall
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2765 (progn
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2766 (save-excursion (funcall function))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2767 (forward-line advance)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2768 (while (not (or (save-excursion (dired-move-to-filename))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2769 (setq wall (funcall check-fun))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2770 (forward-line advance))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2771 (setq done (or (zerop (setq n (1- n))) wall)))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2772 (if (save-excursion (dired-move-to-filename))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2773 (save-excursion (funcall function)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2774 (setq done t))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2775 (dired-move-to-filename)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2776 ;; Note that if possible the point has now been moved to the beginning of
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2777 ;; the file name.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2778 (dired-update-mode-line))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2779
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2780
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2781 ;;;; ----------------------------------------------------------------
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2782 ;;;; Miscellaneous dired commands
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2783 ;;;; ----------------------------------------------------------------
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2784
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2785 (defun dired-quit ()
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2786 "Bury the current dired buffer."
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2787 (interactive)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2788 (bury-buffer))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2789
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2790 (defun dired-undo ()
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2791 "Undo in a dired buffer.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2792 This doesn't recover lost files, it is just normal undo with temporarily
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2793 writeable buffer. You can use it to recover marks, killed lines or subdirs."
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2794 (interactive)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2795 (let ((lines (count-lines (point-min) (point-max)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2796 buffer-read-only)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2797 (undo)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2798 ;; reset dired-subdir-alist, if a dir may have been affected
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2799 ;; Is there a better way to guess this?
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2800 (setq lines (- (count-lines (point-min) (point-max)) lines))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2801 (if (or (>= lines 2) (<= lines -2))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2802 (dired-build-subdir-alist)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2803 (dired-update-mode-line-modified t)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2804 (dired-update-mode-line t))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2805
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2806
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2807 ;;;; --------------------------------------------------------
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2808 ;;;; Immediate actions on files: visiting, viewing, etc.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2809 ;;;; --------------------------------------------------------
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2810
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2811 (defun dired-find-file ()
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2812 "In dired, visit the file or directory named on this line."
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2813 (interactive)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2814 (find-file (dired-get-filename)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2815
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2816 (defun dired-view-file ()
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2817 "In dired, examine a file in view mode, returning to dired when done.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2818 When file is a directory, show it in this buffer if it is inserted;
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2819 otherwise, display it in another buffer."
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2820 (interactive)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2821 (let ((file (dired-get-filename)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2822 (if (file-directory-p file)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2823 (or (dired-goto-subdir file)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2824 (dired file))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2825 (view-file file))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2826
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2827 (defun dired-find-file-other-window (&optional display)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2828 "In dired, visit this file or directory in another window.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2829 With a prefix, the file is displayed, but the window is not selected."
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2830 (interactive "P")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2831 (if display
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2832 (dired-display-file)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2833 (find-file-other-window (dired-get-filename))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2834
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2835 ;; Only for Emacs 19
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2836 (defun dired-find-file-other-frame ()
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2837 "In dired, visit this file or directory in another frame."
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2838 (interactive)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2839 (find-file-other-frame (dired-get-filename)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2840
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2841 (defun dired-display-file ()
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2842 "In dired, displays this file or directory in the other window."
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2843 (interactive)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2844 (display-buffer (find-file-noselect (dired-get-filename))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2845
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2846 ;; After an idea by wurgler@zippysun.math.uakron.edu (Tom Wurgler).
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2847 (defun dired-do-find-file (&optional arg)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2848 "Visit all marked files at once, and display them simultaneously.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2849 See also function `simultaneous-find-file'.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2850 If you want to keep the dired buffer displayed, type \\[split-window-vertically] first.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2851 If you want just the marked files displayed and nothing else, type \\[delete-other-windows] first."
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2852 (interactive "P")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2853 (dired-simultaneous-find-file (dired-get-marked-files nil arg)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2854
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2855 (defun dired-simultaneous-find-file (file-list)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2856 "Visit all files in FILE-LIST and display them simultaneously.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2857
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2858 The current window is split across all files in FILE-LIST, as evenly
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2859 as possible. Remaining lines go to the bottommost window.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2860
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2861 The number of files that can be displayed this way is restricted by
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2862 the height of the current window and the variable `window-min-height'."
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2863 ;; It is usually too clumsy to specify FILE-LIST interactively
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2864 ;; unless via dired (dired-do-find-file).
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2865 (let ((size (/ (window-height) (length file-list))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2866 (or (<= window-min-height size)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2867 (error "Too many files to visit simultaneously"))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2868 (find-file (car file-list))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2869 (setq file-list (cdr file-list))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2870 (while file-list
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2871 ;; Split off vertically a window of the desired size
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2872 ;; The upper window will have SIZE lines. We select the lower
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2873 ;; (larger) window because we want to split that again.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2874 (select-window (split-window nil size))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2875 (find-file (car file-list))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2876 (setq file-list (cdr file-list)))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2877
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2878 (defun dired-create-directory (directory)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2879 "Create a directory called DIRECTORY."
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2880 (interactive
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2881 (list (read-file-name "Create directory: "
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2882 (dired-abbreviate-file-name
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2883 (dired-current-directory)))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2884 (let ((expanded (expand-file-name directory)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2885 (make-directory expanded)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2886 ;; Because this function is meant to be called interactively, it moves
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2887 ;; the point.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2888 (dired-goto-file expanded)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2889
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2890 (defun dired-recover-file ()
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2891 "Recovers file from its autosave file.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2892 If the file is an autosave file, then recovers its associated file instead."
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2893 (interactive)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2894 (let* ((file (dired-get-filename))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2895 (name (file-name-nondirectory file))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2896 (asp (auto-save-file-name-p name))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2897 (orig (and
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2898 asp
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2899 (if (fboundp 'auto-save-original-name)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2900 (auto-save-original-name file)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2901 (error
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2902 "Need auto-save package to compute original file name."))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2903 (buff (if asp
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2904 (and orig (get-file-buffer orig))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2905 (get-file-buffer file))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2906 (and
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2907 buff
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2908 (buffer-modified-p buff)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2909 (or
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2910 (yes-or-no-p
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2911 (format
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2912 "Recover file will erase the modified buffer %s. Do it? "
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2913 (buffer-name buff)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2914 (error "Recover file aborted.")))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2915 (if asp
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2916 (if orig
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2917 (recover-file orig)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2918 (find-file file))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2919 (recover-file file))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2920
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2921
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2922 ;;;; --------------------------------------------------------------------
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2923 ;;;; Functions for extracting and manipulating file names
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2924 ;;;; --------------------------------------------------------------------
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2925
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2926 (defun dired-make-filename-string (filename &optional reverse)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2927 ;; Translates the way that a file name appears in a buffer, to
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2928 ;; how it is used in a path name. This is useful for non-unix
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2929 ;; support in efs.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2930 filename)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2931
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2932 (defun dired-get-filename (&optional localp no-error-if-not-filep)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2933 "In dired, return name of file mentioned on this line.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2934 Value returned normally includes the directory name.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2935 Optional arg LOCALP with value `no-dir' means don't include directory
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2936 name in result. A value of t means use path name relative to
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2937 `default-directory', which still may contain slashes if in a subdirectory.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2938 Optional arg NO-ERROR-IF-NOT-FILEP means return nil if no filename on
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2939 this line, otherwise an error occurs."
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2940
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2941 ;; Compute bol & eol once, rather than twice inside move-to-filename
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2942 ;; and move-to-end-of-filename
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2943 (let ((eol (save-excursion (skip-chars-forward "^\n\r") (point)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2944 (bol (save-excursion (skip-chars-backward "^\r\n") (point)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2945 case-fold-search file p1 p2)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2946 (save-excursion
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2947 (and
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2948 (setq p1 (dired-move-to-filename (not no-error-if-not-filep) bol eol))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2949 (setq p2 (dired-move-to-end-of-filename no-error-if-not-filep bol eol))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2950 (setq file (buffer-substring p1 p2))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2951 ;; Check if ls quoted the names, and unquote them.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2952 ;; Using read to unquote is much faster than substituting
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2953 ;; \007 (4 chars) -> ^G (1 char) etc. in a lisp loop.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2954 (cond ((memq ?b dired-internal-switches) ; System V ls
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2955 ;; This case is about 20% slower than without -b.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2956 (setq file
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2957 (read
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2958 (concat "\""
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2959 ;; some ls -b don't escape quotes, argh!
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2960 ;; This is not needed for GNU ls, though.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2961 (or (dired-string-replace-match
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2962 "\\([^\\]\\)\"" file "\\1\\\\\"")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2963 file)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2964 "\""))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2965 ;; If you do this, update dired-compatible-switches-p
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2966 ;; ((memq ?Q dired-internal-switches) ; GNU ls
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2967 ;; (setq file (read file)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2968 )))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2969 (and file
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2970 (if (eq localp 'no-dir)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2971 (dired-make-filename-string file)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2972 (concat (dired-current-directory localp)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2973 (dired-make-filename-string file))))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2974
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2975 (defun dired-make-relative (file &optional dir no-error)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2976 ;; Convert FILE (an *absolute* pathname) to a pathname relative to DIR.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2977 ;; FILE must be absolute, or this function will return nonsense.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2978 ;; If FILE is not in a subdir of DIR, an error is signalled,
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2979 ;; unless NO-ERROR is t. Then, ".."'s are inserted to give
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2980 ;; a relative representation of FILE wrto DIR
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2981 ;; eg. FILE = /vol/tex/bin/foo DIR = /vol/local/bin/
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2982 ;; results in ../../tex/bin/foo
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2983 ;; DIR must be expanded.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2984 ;; DIR defaults to default-directory.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2985 ;; DIR must be file-name-as-directory, as with all directory args in
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2986 ;; elisp code.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2987 (or dir (setq dir (expand-file-name default-directory)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2988 (let ((flen (length file))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2989 (dlen (length dir)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2990 (if (and (> flen dlen)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2991 (string-equal (substring file 0 dlen) dir))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2992 (substring file dlen)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2993 ;; Need to insert ..'s
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2994 (or no-error (error "%s: not in directory tree growing at %s" file dir))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2995 (if (string-equal file dir)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2996 "./"
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2997 (let ((index 1)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2998 (count 0))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2999 (while (and (string-match "/" dir index)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3000 (<= (match-end 0) flen)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3001 (string-equal (substring file index (match-end 0))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3002 (substring dir index (match-end 0))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3003 (setq index (match-end 0)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3004 (setq file (substring file index))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3005 (if (and (/= flen index)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3006 (not (string-match "/" file))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3007 (< flen dlen)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3008 (string-equal file (substring dir index flen))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3009 (= (aref dir flen) ?/))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3010 (setq file "."
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3011 count -1))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3012 ;; count how many slashes remain in dir.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3013 (while (string-match "/" dir index)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3014 (setq index (match-end 0)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3015 count (1+ count)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3016 (apply 'concat (nconc (make-list count "../") (list file))))))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3017
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3018 ;;; Functions for manipulating file names.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3019 ;;
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3020 ;; Used by file tranformers.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3021 ;; Define here rather than in dired-shell.el, as it wouldn't be
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3022 ;; unreasonable to use these elsewhere.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3023
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3024 (defun dired-file-name-base (fn)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3025 "Returns the base name of FN.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3026 This is the file without directory part, and extension. See the variable
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3027 `dired-filename-re-ext'."
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3028 (setq fn (file-name-nondirectory fn))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3029 (if (string-match dired-filename-re-ext fn 1)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3030 (substring fn 0 (match-beginning 0))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3031 fn))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3032
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3033 (defun dired-file-name-extension (fn)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3034 "Returns the extension for file name FN.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3035 See the variable dired-filename-re-ext'."
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3036 (setq fn (file-name-nondirectory fn))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3037 (if (string-match dired-filename-re-ext fn 1)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3038 (substring fn (match-beginning 0))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3039 ""))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3040
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3041 (defun dired-file-name-sans-rcs-extension (fn)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3042 "Returns the file name FN without its RCS extension \",v\"."
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3043 (setq fn (file-name-nondirectory fn))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3044 (if (string-match ",v$" fn 1)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3045 (substring fn 0 (match-beginning 0))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3046 fn))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3047
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3048 (defun dired-file-name-sans-compress-extension (fn)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3049 "Returns the file name FN without the extension from compress or gzip."
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3050 (setq fn (file-name-nondirectory fn))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3051 (if (string-match "\\.\\([zZ]\\|gz\\)$" fn 1)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3052 (substring fn (match-beginning 0))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3053 fn))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3054
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3055
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3056 ;;;; ---------------------------------------------------------------------
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3057 ;;;; Working with directory trees.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3058 ;;;; ---------------------------------------------------------------------
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3059 ;;;
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3060 ;;; This where code for the dired-subdir-alist is.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3061
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3062 ;;; Utility functions for dired-subdir-alist
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3063
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3064 (defun dired-normalize-subdir (dir)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3065 ;; Prepend default-directory to DIR if relative path name.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3066 ;; dired-get-filename must be able to make a valid filename from a
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3067 ;; file and its directory DIR.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3068 ;; Fully expand everything.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3069 (file-name-as-directory
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3070 (if (file-name-absolute-p dir)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3071 (expand-file-name dir)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3072 (expand-file-name dir (expand-file-name default-directory)))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3073
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3074 (defun dired-get-subdir ()
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3075 ;;"Return the subdir name on this line, or nil if not on a headerline."
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3076 ;; Look up in the alist whether this is a headerline.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3077 (save-excursion
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3078 (let ((cur-dir (dired-current-directory)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3079 (beginning-of-line) ; alist stores b-o-l positions
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3080 (and (zerop (- (point)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3081 (dired-get-subdir-min (assoc cur-dir
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3082 dired-subdir-alist))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3083 cur-dir))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3084
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3085 (defun dired-get-subdir-max (elt)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3086 ;; returns subdir max.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3087 (let ((pos (- (length dired-subdir-alist)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3088 (length (member elt dired-subdir-alist)))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3089 (if (zerop pos)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3090 (point-max)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3091 (1- (dired-get-subdir-min (nth (1- pos) dired-subdir-alist))))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3092
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3093 (defun dired-clear-alist ()
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3094 ;; Set all markers in dired-subdir-alist to nil. Set the alist to nil too.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3095 (while dired-subdir-alist
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3096 (set-marker (dired-get-subdir-min (car dired-subdir-alist)) nil)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3097 (setq dired-subdir-alist (cdr dired-subdir-alist))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3098
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3099 (defun dired-unsubdir (dir)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3100 ;; Remove DIR from the alist
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3101 (setq dired-subdir-alist
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3102 (delq (assoc dir dired-subdir-alist) dired-subdir-alist)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3103
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3104 (defun dired-simple-subdir-alist ()
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3105 ;; Build and return `dired-subdir-alist' assuming just the top level
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3106 ;; directory to be inserted. Don't parse the buffer.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3107 (setq dired-subdir-alist
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3108 (list (list (expand-file-name default-directory)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3109 (point-min-marker) dired-omit-files
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3110 dired-internal-switches nil)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3111 (if dired-verify-modtimes
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3112 (dired-set-file-modtime (expand-file-name default-directory)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3113 dired-subdir-alist)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3114
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3115 (defun dired-build-subdir-alist ()
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3116 "Build `dired-subdir-alist' by parsing the buffer and return its new value."
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3117 (interactive)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3118 (let ((o-alist dired-subdir-alist)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3119 (count 0)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3120 subdir)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3121 (dired-clear-alist)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3122 (save-excursion
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3123 (goto-char (point-min))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3124 (while (re-search-forward dired-subdir-regexp nil t)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3125 (setq count (1+ count))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3126 (apply 'dired-alist-add-1
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3127 (setq subdir (buffer-substring (match-beginning 2)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3128 (match-end 2)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3129 ;; Put subdir boundary between lines.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3130 (set-marker (make-marker) (match-end 1))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3131 (let ((elt (assoc subdir o-alist)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3132 (if elt
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3133 (list (nth 2 elt) (nth 3 elt))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3134 (list dired-omit-files dired-internal-switches)))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3135 (if (interactive-p)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3136 (message "%d director%s." count (if (= 1 count) "y" "ies")))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3137 ;; We don't need to sort it because it is in buffer order per
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3138 ;; constructionem. Return new alist:
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3139 ;; pointers for current-subdir may be stale
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3140 dired-subdir-alist)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3141
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3142 (defun dired-alist-add (dir new-marker &optional omit switches)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3143 ;; Add new DIR at NEW-MARKER. Sort alist.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3144 (dired-alist-add-1 dir new-marker omit switches)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3145 (dired-alist-sort))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3146
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3147 (defun dired-alist-add-1 (dir new-marker &optional omit switches)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3148 ;; Add new DIR at NEW-MARKER. Don't sort.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3149 (let ((dir (dired-normalize-subdir dir)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3150 (setq dired-subdir-alist
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3151 (cons (list dir new-marker omit switches nil) dired-subdir-alist))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3152 (if dired-verify-modtimes
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3153 (dired-set-file-modtime dir dired-subdir-alist))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3154
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3155 (defun dired-alist-sort ()
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3156 ;; Keep the alist sorted on buffer position.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3157 (setq dired-subdir-alist
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3158 (sort dired-subdir-alist
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3159 (function (lambda (elt1 elt2)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3160 (> (dired-get-subdir-min elt1)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3161 (dired-get-subdir-min elt2)))))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3162
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3163 ;;; Utilities for working with subdirs in the dired buffer
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3164
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3165 ;; This function is the heart of tree dired.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3166 ;; It is called for each retrieved filename.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3167 ;; It could stand to be faster, though it's mostly function call
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3168 ;; overhead. Avoiding to funcall seems to save about 10% in
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3169 ;; dired-get-filename. Make it a defsubst?
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3170 (defun dired-current-directory (&optional localp)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3171 "Return the name of the subdirectory to which this line belongs.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3172 This returns a string with trailing slash, like `default-directory'.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3173 Optional argument means return a file name relative to `default-directory'.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3174 In this it returns \"\" for the top directory."
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3175 (let* ((here (point))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3176 (dir (catch 'done
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3177 (mapcar (function
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3178 (lambda (x)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3179 (if (<= (dired-get-subdir-min x) here)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3180 (throw 'done (car x)))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3181 dired-subdir-alist))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3182 (if (listp dir) (error "dired-subdir-alist seems to be mangled"))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3183 (if localp
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3184 (let ((def-dir (expand-file-name default-directory)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3185 (if (string-equal dir def-dir)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3186 ""
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3187 (dired-make-relative dir def-dir)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3188 dir)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3189
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3190 ;; Subdirs start at the beginning of their header lines and end just
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3191 ;; before the beginning of the next header line (or end of buffer).
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3192
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3193 (defun dired-subdir-min ()
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3194 ;; Returns the minimum position of the current subdir
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3195 (save-excursion
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3196 (if (not (dired-prev-subdir 0 t t))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3197 (error "Not in a subdir!")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3198 (point))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3199
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3200 (defun dired-subdir-max ()
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3201 ;; Returns the maximum position of the current subdir
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3202 (save-excursion
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3203 (if (dired-next-subdir 1 t t)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3204 (1- (point)) ; Do not include separating empty line.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3205 (point-max))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3206
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3207
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3208 ;;;; --------------------------------------------------------
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3209 ;;;; Deleting files
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3210 ;;;; --------------------------------------------------------
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3211
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3212 (defun dired-flag-file-deletion (arg)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3213 "In dired, flag the current line's file for deletion.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3214 With prefix arg, repeat over several lines.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3215
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3216 If on a subdir headerline, mark all its files except `.' and `..'."
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3217 (interactive "p")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3218 (dired-mark arg dired-del-marker))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3219
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3220 (defun dired-flag-file-deletion-backup (arg)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3221 "Flag current file for deletion, and move to previous line.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3222 With a prefix ARG, repeats this ARG times."
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3223 (interactive "p")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3224 ;; Use dired-mark-file and not dired-mark, as this function
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3225 ;; should do nothing special on subdir headers.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3226 (dired-mark-file (- arg) dired-del-marker))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3227
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3228 (defun dired-flag-subdir-files ()
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3229 "Flag all the files in the current subdirectory for deletion."
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3230 (interactive)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3231 (dired-mark-subdir-files dired-del-marker))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3232
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3233 (defun dired-unflag (arg)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3234 "In dired, remove a deletion flag from the current line's file.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3235 Optional prefix ARG says how many lines to unflag."
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3236 (interactive "p")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3237 (let (buffer-read-only)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3238 (dired-repeat-over-lines
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3239 arg
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3240 (function
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3241 (lambda ()
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3242 (if (char-equal (following-char) dired-del-marker)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3243 (progn
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3244 (setq dired-del-flags-number (max (1- dired-del-flags-number) 0))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3245 (dired-substitute-marker (point) dired-del-marker ?\ )))))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3246 (dired-update-mode-line-modified))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3247
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3248 (defun dired-backup-unflag (arg)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3249 "In dired, move up lines and remove deletion flag there.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3250 Optional prefix ARG says how many lines to unflag; default is one line."
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3251 (interactive "p")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3252 (dired-unflag (- arg)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3253
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3254 (defun dired-update-marker-counters (char &optional remove)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3255 (or (memq char '(?\ ?\n ?\r))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3256 (let ((counter (cond
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3257 ((char-equal char dired-del-marker)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3258 'dired-del-flags-number)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3259 ((char-equal char dired-marker-char)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3260 'dired-marks-number)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3261 ('dired-other-marks-number))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3262 (if remove
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3263 (set counter (max (1- (symbol-value counter)) 0))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3264 (set counter (1+ (symbol-value counter)))))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3265
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3266 (defun dired-update-mode-line-modified (&optional check)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3267 ;; Updates the value of mode-line-modified in dired.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3268 ;; Currently assumes that it's of the form "-%%-", where % sometimes
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3269 ;; gets replaced by %. Should allow some sort of config flag.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3270 ;; SET is t to set to -DD-, nil to set to -%%-, and 'check means
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3271 ;; examine the buffer to find out.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3272 (if check
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3273 (save-excursion
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3274 (let (char)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3275 (goto-char (point-min))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3276 (setq dired-del-flags-number 0
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3277 dired-marks-number 0
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3278 dired-other-marks-number 0)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3279 (while (not (eobp))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3280 (setq char (following-char))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3281 (cond
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3282 ((char-equal char dired-del-marker)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3283 (setq dired-del-flags-number (1+ dired-del-flags-number)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3284 ((char-equal char dired-marker-char)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3285 (setq dired-marks-number (1+ dired-marks-number)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3286 ((memq char '(?\ ?\n ?\r))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3287 nil)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3288 ((setq dired-other-marks-number (1+ dired-other-marks-number))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3289 (forward-line 1)))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3290 (setq mode-line-modified
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3291 (format dired-mode-line-modified
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3292 (if (zerop dired-del-flags-number)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3293 "--"
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3294 (format "%d%c" dired-del-flags-number dired-del-marker))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3295 (if (zerop dired-marks-number)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3296 "--"
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3297 (format "%d%c" dired-marks-number dired-marker-char))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3298 (if (zerop dired-other-marks-number)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3299 "-"
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3300 (int-to-string dired-other-marks-number))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3301 (set-buffer-modified-p (buffer-modified-p)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3302
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3303 (defun dired-do-deletions (&optional nomessage)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3304 (dired-expunge-deletions))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3305
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3306 (defun dired-expunge-deletions ()
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3307 "In dired, delete the files flagged for deletion."
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3308 (interactive)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3309 (let ((files (let ((dired-marker-char dired-del-marker))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3310 (dired-map-over-marks (cons (dired-get-filename) (point))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3311 t))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3312 (if files
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3313 (progn
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3314 (dired-internal-do-deletions files nil dired-del-marker)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3315 ;; In case the point gets left somewhere strange -- hope that
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3316 ;; this doesn't cause asynch troubles later.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3317 (beginning-of-line)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3318 (dired-goto-next-nontrivial-file)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3319 (dired-update-mode-line-modified t)) ; play safe, it's cheap
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3320 (message "(No deletions requested)"))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3321
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3322 (defun dired-do-delete (&optional arg)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3323 "Delete all marked (or next ARG) files."
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3324 ;; This is more consistent with the file marking feature than
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3325 ;; dired-expunge-deletions.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3326 (interactive "P")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3327 (dired-internal-do-deletions
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3328 ;; this may move point if ARG is an integer
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3329 (dired-map-over-marks (cons (dired-get-filename) (point))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3330 arg)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3331 arg)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3332 (beginning-of-line)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3333 (dired-goto-next-nontrivial-file))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3334
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3335 (defun dired-internal-do-deletions (l arg &optional marker-char)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3336 ;; L is an alist of files to delete, with their buffer positions.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3337 ;; ARG is the prefix arg.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3338 ;; Filenames are absolute (VMS needs this for logical search paths).
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3339 ;; (car L) *must* be the *last* (bottommost) file in the dired buffer.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3340 ;; That way as changes are made in the buffer they do not shift the
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3341 ;; lines still to be changed, so the (point) values in L stay valid.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3342 ;; Also, for subdirs in natural order, a subdir's files are deleted
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3343 ;; before the subdir itself - the other way around would not work.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3344 (save-excursion
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3345 (let ((files (mapcar (function car) l))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3346 (count (length l))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3347 (succ 0)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3348 (cdir (dired-current-directory))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3349 failures)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3350 ;; canonicalize file list for pop up
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3351 (setq files (nreverse (mapcar (function
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3352 (lambda (fn)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3353 (dired-make-relative fn cdir t)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3354 files)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3355 (if (or (memq 'delete dired-no-confirm)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3356 (dired-mark-pop-up
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3357 " *Files Flagged for Deletion*" 'delete files
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3358 dired-deletion-confirmer
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3359 (format "Delete %s "
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3360 (dired-mark-prompt arg files marker-char))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3361 (save-excursion
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3362 ;; files better be in reverse order for this loop!
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3363 (while l
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3364 (goto-char (cdr (car l)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3365 (condition-case err
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3366 (let ((fn (car (car l))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3367 ;; This test is equivalent to
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3368 ;; (and (file-directory-p fn)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3369 ;; (not (file-symlink-p fn)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3370 ;; but more efficient
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3371 (if (if (eq t (car (file-attributes fn)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3372 (if (<= (length (directory-files fn)) 2)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3373 (progn (delete-directory fn) t)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3374 (and (or
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3375 (memq 'recursive-delete dired-no-confirm)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3376 (funcall
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3377 dired-deletion-confirmer
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3378 (format "\
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3379 Recursively delete directory and files within %s? "
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3380 (dired-make-relative fn))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3381 (progn
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3382 (dired-recursive-delete-directory fn)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3383 t)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3384 (progn (delete-file fn) t))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3385 (progn
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3386 (setq succ (1+ succ))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3387 (message "%s of %s deletions" succ count)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3388 (dired-clean-up-after-deletion fn))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3389 (error;; catch errors from failed deletions
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3390 (dired-log (buffer-name (current-buffer)) "%s\n" err)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3391 (setq failures (cons (car (car l)) failures))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3392 (setq l (cdr l)))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3393 (if failures
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3394 (dired-log-summary
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3395 (buffer-name (current-buffer))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3396 (format "%d of %d deletion%s failed:" (length failures) count
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3397 (dired-plural-s count))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3398 failures)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3399 (if (zerop succ)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3400 (message "(No deletions performed)")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3401 (message "%d deletion%s done" succ (dired-plural-s succ)))))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3402
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3403 (defun dired-recursive-delete-directory (fn)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3404 ;; Recursively deletes directory FN, and all of its contents.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3405 (let* ((fn (expand-file-name fn))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3406 (handler (find-file-name-handler
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3407 fn 'dired-recursive-delete-directory)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3408 (if handler
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3409 (funcall handler 'dired-recursive-delete-directory fn)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3410 (progn
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3411 (or (file-exists-p fn)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3412 (signal
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3413 'file-error
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3414 (list "Removing old file name" "no such directory" fn)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3415 ;; Which is better, -r or -R?
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3416 (call-process "rm" nil nil nil "-r" (directory-file-name fn))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3417 (and (file-exists-p fn)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3418 (error "Failed to recusively delete %s" fn))))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3419
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3420 (defun dired-clean-up-after-deletion (fn)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3421 ;; Offer to kill buffer of deleted file FN.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3422 (let ((buf (get-file-buffer fn)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3423 (and buf
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3424 (or (memq 'kill-file-buffer dired-no-confirm)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3425 (funcall (function yes-or-no-p)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3426 (format "Kill buffer of %s, too? "
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3427 (file-name-nondirectory fn))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3428 (save-excursion ; you never know where kill-buffer leaves you
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3429 (kill-buffer buf)))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3430
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3431 ;;; Cleaning a directory -- flagging backups for deletion
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3432
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3433 (defun dired-clean-directory (keep &optional marker msg)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3434 "Flag numerical backups for deletion.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3435 Spares `dired-kept-versions' latest versions, and `kept-old-versions' oldest.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3436 Positive prefix arg KEEP overrides `dired-kept-versions';
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3437 Negative prefix arg KEEP overrides `kept-old-versions' with KEEP made positive.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3438
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3439 To clear the flags on these files, you can use \\[dired-flag-backup-files]
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3440 with a prefix argument."
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3441 (interactive "P")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3442 (setq keep (if keep (prefix-numeric-value keep) dired-kept-versions))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3443 (let* ((early-retention (if (< keep 0) (- keep) kept-old-versions))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3444 (late-retention (if (<= keep 0) dired-kept-versions keep))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3445 (msg (or msg
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3446 (format
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3447 "Cleaning numerical backups (keeping %d late, %d old)"
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3448 late-retention early-retention)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3449 (trample-marker (or marker dired-del-marker))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3450 (file-version-assoc-list))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3451 (message "%s..." msg)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3452 ;; Do this after messaging, as it may take a while.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3453 (setq file-version-assoc-list (dired-collect-file-versions))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3454 ;; Sort each VERSION-NUMBER-LIST,
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3455 ;; and remove the versions to be deleted.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3456 (let ((fval file-version-assoc-list))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3457 (while fval
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3458 (let* ((sorted-v-list (cons 'q (sort (cdr (car fval)) '<)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3459 (v-count (length sorted-v-list)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3460 (if (> v-count (+ early-retention late-retention))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3461 (rplacd (nthcdr early-retention sorted-v-list)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3462 (nthcdr (- v-count late-retention)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3463 sorted-v-list)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3464 (rplacd (car fval)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3465 (cdr sorted-v-list)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3466 (setq fval (cdr fval))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3467 ;; Look at each file. If it is a numeric backup file,
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3468 ;; find it in a VERSION-NUMBER-LIST and maybe flag it for deletion.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3469 (dired-map-dired-file-lines (function
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3470 (lambda (fn)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3471 (dired-trample-file-versions
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3472 fn file-version-assoc-list
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3473 trample-marker))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3474 (message "%s...done" msg)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3475
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3476 (defun dired-collect-file-versions ()
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3477 ;; If it looks like a file has versions, return a list of the versions.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3478 ;; The return value is ((FILENAME . (VERSION1 VERSION2 ...)) ...)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3479 (let (result)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3480 (dired-map-dired-file-lines
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3481 (function
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3482 (lambda (fn)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3483 (let* ((base-versions
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3484 (concat (file-name-nondirectory fn) ".~"))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3485 (bv-length (length base-versions))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3486 (possibilities (file-name-all-completions
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3487 base-versions
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3488 (file-name-directory fn))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3489 (if possibilities
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3490 (setq result (cons (cons fn
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3491 (mapcar 'backup-extract-version
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3492 possibilities)) result)))))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3493 result))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3494
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3495 (defun dired-trample-file-versions (fn alist marker)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3496 ;; ALIST is an alist of filenames and versions used to determine
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3497 ;; if each file should be flagged for deletion.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3498 ;; This version using file-name-sans-versions is probably a lot slower
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3499 ;; than Sebastian's original, but it is more easily adaptable to non-unix.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3500 (let ((base (file-name-sans-versions fn))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3501 base-version-list bv-length)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3502 (and (not (string-equal base fn))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3503 (setq base-version-list (assoc base alist))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3504 (setq bv-length (string-match "[0-9]" fn (length base)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3505 (not (memq (backup-extract-version fn) base-version-list))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3506 (progn (skip-chars-backward "^\n\r")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3507 (bolp)) ; make sure the preceding char isn't \r.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3508 (dired-substitute-marker (point) (following-char) marker))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3509
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3510 (defun dired-map-dired-file-lines (fun)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3511 ;; Perform FUN with point at the end of each non-directory line.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3512 ;; FUN takes one argument, the filename (complete pathname).
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3513 (dired-check-ls-l)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3514 (save-excursion
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3515 (let (file buffer-read-only)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3516 (goto-char (point-min))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3517 (while (not (eobp))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3518 (save-excursion
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3519 (and (not (and dired-re-dir (looking-at dired-re-dir)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3520 (not (memq (following-char) '(?\n ?\n)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3521 (setq file (dired-get-filename nil t)) ; nil on non-file
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3522 (progn (skip-chars-forward "^\n\r")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3523 (funcall fun file))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3524 (forward-line 1))))) ; this guarantees that we don't
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3525 ; operate on omitted files.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3526
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3527
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3528 ;;;; -----------------------------------------------------------
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3529 ;;;; Confirmations and prompting the user.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3530 ;;;; -----------------------------------------------------------
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3531
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3532 (defun dired-plural-s (count)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3533 (if (= 1 count) "" "s"))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3534
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3535 (defun dired-mark-prompt (arg files &optional marker-char)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3536 ;; Return a string for use in a prompt, either the current file
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3537 ;; name, or the marker and a count of marked files.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3538 (let ((count (length files)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3539 (if (= count 1)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3540 (car files)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3541 ;; more than 1 file:
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3542 (if (integerp arg)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3543 (cond ((zerop arg) "[no files]")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3544 ((> arg 0) "[following]")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3545 ((< arg 0) "[preceding]"))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3546 (char-to-string (or marker-char dired-marker-char))))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3547
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3548 (defun dired-pop-to-buffer (buf)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3549 ;; Pop up buffer BUF.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3550 ;; Make its window fit its contents.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3551 (let ((window (selected-window))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3552 target-lines w2)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3553 (cond ;; if split-window-threshold is enabled, use the largest window
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3554 ((and (> (window-height (setq w2 (get-largest-window)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3555 split-height-threshold)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3556 (= (frame-width) (window-width w2)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3557 (setq window w2))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3558 ;; if the least-recently-used window is big enough, use it
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3559 ((and (> (window-height (setq w2 (get-lru-window)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3560 (* 2 window-min-height))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3561 (= (frame-width) (window-width w2)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3562 (setq window w2)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3563 (save-excursion
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3564 (set-buffer buf)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3565 (goto-char (point-max))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3566 (skip-chars-backward "\n\r\t ")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3567 (setq target-lines (count-lines (point-min) (point)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3568 ;; Don't forget to count the last line.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3569 (if (not (bolp))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3570 (setq target-lines (1+ target-lines))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3571 (if (<= (window-height window) (* 2 window-min-height))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3572 ;; At this point, every window on the frame is too small to split.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3573 (setq w2 (display-buffer buf))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3574 (setq w2 (split-window
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3575 window
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3576 (max window-min-height
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3577 (- (window-height window)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3578 (1+ (max window-min-height target-lines)))))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3579 (set-window-buffer w2 buf)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3580 (if (< (1- (window-height w2)) target-lines)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3581 (progn
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3582 (select-window w2)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3583 (enlarge-window (- target-lines (1- (window-height w2))))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3584 (set-window-start w2 1)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3585
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3586 (defun dired-mark-pop-up (bufname op-symbol files function &rest args)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3587 ;; Args BUFNAME OP-SYMBOL FILES FUNCTION &rest ARGS.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3588 ;; Return FUNCTION's result on ARGS after popping up a window (in a buffer
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3589 ;; named BUFNAME, nil gives \" *Marked Files*\") showing the marked
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3590 ;; files. Uses function `dired-pop-to-buffer' to do that.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3591 ;; FUNCTION should not manipulate files.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3592 ;; It should only read input (an argument or confirmation).
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3593 ;; The window is not shown if there is just one file or
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3594 ;; OP-SYMBOL is a member of the list in `dired-no-confirm'.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3595 ;; FILES is the list of marked files.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3596 (if (memq op-symbol dired-no-confirm)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3597 (apply function args)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3598 (or bufname (setq bufname " *Marked Files*"))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3599 (if (<= (length files) 1)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3600 (apply function args)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3601 (save-excursion
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3602 (let ((standard-output (set-buffer (get-buffer-create bufname))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3603 (erase-buffer)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3604 (dired-format-columns-of-files files)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3605 (dired-remove-text-properties (point-min) (point-max))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3606 (setq mode-line-format (format " %s [%d files]"
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3607 bufname (length files)))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3608 (save-window-excursion
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3609 (dired-pop-to-buffer bufname)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3610 (apply function args)))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3611
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3612 (defun dired-column-widths (columns list &optional across)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3613 ;; Returns the column widths for breaking LIST into
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3614 ;; COLUMNS number of columns.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3615 (cond
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3616 ((null list)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3617 nil)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3618 ((= columns 1)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3619 (list (apply 'max (mapcar 'length list))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3620 ((let* ((len (length list))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3621 (col-length (/ len columns))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3622 (remainder (% len columns))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3623 (i 0)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3624 (j 0)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3625 (max-width 0)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3626 widths padding)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3627 (if (zerop remainder)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3628 (setq padding 0)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3629 (setq col-length (1+ col-length)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3630 padding (- columns remainder)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3631 (setq list (nconc (copy-sequence list) (make-list padding nil)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3632 (setcdr (nthcdr (1- (+ len padding)) list) list)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3633 (while (< i columns)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3634 (while (< j col-length)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3635 (setq max-width (max max-width (length (car list)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3636 list (if across (nthcdr columns list) (cdr list))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3637 j (1+ j)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3638 (setq widths (cons (+ max-width 2) widths)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3639 max-width 0
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3640 j 0
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3641 i (1+ i))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3642 (if across (setq list (cdr list))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3643 (setcar widths (- (car widths) 2))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3644 (nreverse widths)))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3645
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3646 (defun dired-calculate-columns (list &optional across)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3647 ;; Returns a list of integers which are the column widths that best pack
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3648 ;; LIST, a list of strings, onto the screen.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3649 (and list
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3650 (let* ((width (1- (window-width)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3651 (columns (max 1 (/ width
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3652 (+ 2 (apply 'max (mapcar 'length list))))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3653 col-list last-col-list)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3654 (while (<= (apply '+ (setq col-list
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3655 (dired-column-widths columns list across)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3656 width)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3657 (setq columns (1+ columns)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3658 last-col-list col-list))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3659 (or last-col-list col-list))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3660
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3661 (defun dired-format-columns-of-files (files &optional across)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3662 ;; Returns the number of lines used.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3663 ;; If ACROSS is non-nil, sorts across rather than down the buffer, like
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3664 ;; ls -x
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3665 (and files
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3666 (let* ((columns (dired-calculate-columns files across))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3667 (ncols (length columns))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3668 (ncols1 (1- ncols))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3669 (nfiles (length files))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3670 (nrows (+ (/ nfiles ncols)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3671 (if (zerop (% nfiles ncols)) 0 1)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3672 (space-left (- (window-width) (apply '+ columns) 1))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3673 (i 0)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3674 (j 0)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3675 file padding stretch float-stretch)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3676 (if (zerop ncols1)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3677 (setq stretch 0
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3678 float-stretch 0)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3679 (setq stretch (/ space-left ncols1)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3680 float-stretch (% space-left ncols1)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3681 (setq files (nconc (copy-sequence files) ; fill up with empty fns
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3682 (make-list (- (* ncols nrows) nfiles) "")))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3683 (setcdr (nthcdr (1- (length files)) files) files) ; make circular
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3684 (while (< j nrows)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3685 (while (< i ncols)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3686 (princ (setq file (car files)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3687 (setq padding (- (nth i columns) (length file)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3688 (or (= i ncols1)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3689 (progn
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3690 (setq padding (+ padding stretch))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3691 (if (< i float-stretch) (setq padding (1+ padding)))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3692 (princ (make-string padding ?\ ))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3693 (setq files (if across (cdr files) (nthcdr nrows files))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3694 i (1+ i)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3695 (princ "\n")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3696 (setq i 0
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3697 j (1+ j))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3698 (or across (setq files (cdr files))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3699 nrows)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3700
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3701 (defun dired-query (qs-var qs-prompt &rest qs-args)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3702 ;; Query user and return nil or t.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3703 ;; Store answer in symbol VAR (which must initially be bound to nil).
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3704 ;; Format PROMPT with ARGS.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3705 ;; Binding variable help-form will help the user who types C-h.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3706 (let* ((char (symbol-value qs-var))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3707 (action (cdr (assoc char dired-query-alist))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3708 (cond ((eq 'yes action)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3709 t) ; accept, and don't ask again
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3710 ((eq 'no action)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3711 nil) ; skip, and don't ask again
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3712 (t;; no lasting effects from last time we asked - ask now
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3713 (let ((qprompt (concat qs-prompt
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3714 (if help-form
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3715 (format " [yn!q or %s] "
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3716 (key-description
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3717 (char-to-string help-char)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3718 " [ynq or !] ")))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3719 (dired-in-query t)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3720 elt)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3721 ;; Actually it looks nicer without cursor-in-echo-area - you can
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3722 ;; look at the dired buffer instead of at the prompt to decide.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3723 (apply 'message qprompt qs-args)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3724 (setq char (set qs-var (read-char)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3725 (while (not (setq elt (assoc char dired-query-alist)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3726 (message "Invalid char - type %c for help." help-char)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3727 (ding)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3728 (sit-for 1)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3729 (apply 'message qprompt qs-args)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3730 (setq char (set qs-var (read-char))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3731 (memq (cdr elt) '(t y yes)))))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3732
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3733 (defun dired-mark-confirm (op-symbol operation arg)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3734 ;; Request confirmation from the user that the operation described
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3735 ;; by OP-SYMBOL is to be performed on the marked files.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3736 ;; Confirmation consists in a y-or-n question with a file list
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3737 ;; pop-up unless OP-SYMBOL is a member of `dired-no-confirm'.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3738 ;; OPERATION is a string describing the operation. Used for prompting
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3739 ;; the user.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3740 ;; The files used are determined by ARG (like in dired-get-marked-files).
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3741 (or (memq op-symbol dired-no-confirm)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3742 (let ((files (dired-get-marked-files t arg)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3743 (dired-mark-pop-up nil op-symbol files (function y-or-n-p)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3744 (concat operation " "
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3745 (dired-mark-prompt arg files) "? ")))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3746
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3747 (defun dired-mark-read-file-name (prompt dir op-symbol arg files)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3748 (dired-mark-pop-up
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3749 nil op-symbol files
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3750 (function read-file-name)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3751 (format prompt (dired-mark-prompt arg files)) dir))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3752
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3753 (defun dired-mark-read-string (prompt initial op-symbol arg files
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3754 &optional history-sym)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3755 ;; Reading arguments with history.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3756 ;; Read arguments for a mark command of type OP-SYMBOL,
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3757 ;; perhaps popping up the list of marked files.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3758 ;; ARG is the prefix arg and indicates whether the files came from
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3759 ;; marks (ARG=nil) or a repeat factor (integerp ARG).
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3760 ;; If the current file was used, the list has but one element and ARG
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3761 ;; does not matter. (It is non-nil, non-integer in that case, namely '(4)).
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3762 ;; PROMPT for a string, with INITIAL input.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3763 (dired-mark-pop-up
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3764 nil op-symbol files
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3765 (function
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3766 (lambda (prompt initial)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3767 (let ((hist (or history-sym
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3768 (cdr (assq op-symbol dired-op-history-alist))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3769 'dired-history)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3770 (dired-read-with-history prompt initial hist))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3771 (format prompt (dired-mark-prompt arg files)) initial))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3772
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3773
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3774 ;;;; ----------------------------------------------------------
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3775 ;;;; Marking files.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3776 ;;;; ----------------------------------------------------------
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3777
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3778 (defun dired-mark (arg &optional char)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3779 "Mark the current (or next ARG) files.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3780 If on a subdir headerline, mark all its files except `.' and `..'.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3781
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3782 Use \\[dired-unmark-all-files] to remove all marks,
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3783 and \\[dired-unmark] to remove the mark of the current file."
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3784 (interactive "p")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3785 (if (dired-get-subdir)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3786 (dired-mark-subdir-files char)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3787 (dired-mark-file arg char)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3788
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3789 (defun dired-mark-file (arg &optional char)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3790 "Mark ARG files starting from the current file line.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3791 Optional CHAR indicates a marker character to use."
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3792 (let (buffer-read-only)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3793 (if (memq (or char dired-marker-char) '(?\ ?\n ?\r))
40
7e54bd776075 Import from CVS: tag r19-15b103
cvs
parents: 24
diff changeset
3794 (error "Invalid marker character %c" dired-marker-char))
22
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3795 (or char (setq char dired-marker-char))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3796 (dired-repeat-over-lines
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3797 arg
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3798 (function
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3799 (lambda ()
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3800 (dired-update-marker-counters (following-char) t)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3801 (dired-substitute-marker (point) (following-char) char)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3802 (dired-update-marker-counters char))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3803 (dired-update-mode-line-modified)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3804
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3805 (defun dired-mark-subdir-files (&optional char)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3806 "Mark all files except `.' and `..'."
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3807 (interactive)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3808 (save-excursion
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3809 (dired-mark-files-in-region (dired-subdir-min) (dired-subdir-max) char)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3810
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3811 (defun dired-unmark (arg)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3812 "Unmark the current (or next ARG) files.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3813 If looking at a subdir, unmark all its files except `.' and `..'."
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3814 (interactive "p")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3815 (let (buffer-read-only)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3816 (dired-repeat-over-lines
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3817 arg
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3818 (function
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3819 (lambda ()
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3820 (let ((char (following-char)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3821 (or (memq char '(?\ ?\n ?\r))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3822 (progn
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3823 (cond
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3824 ((char-equal char dired-marker-char)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3825 (setq dired-marks-number (max (1- dired-marks-number) 0)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3826 ((char-equal char dired-del-marker)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3827 (setq dired-del-flags-number
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3828 (max (1- dired-del-flags-number) 0)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3829 ((setq dired-other-marks-number
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3830 (max (1- dired-other-marks-number) 0))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3831 (dired-substitute-marker (point) char ?\ )))))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3832 (dired-update-mode-line-modified)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3833
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3834 (defun dired-mark-prefix (&optional arg)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3835 "Mark the next ARG files with the next character typed.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3836 If ARG is negative, marks the previous files."
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3837 (interactive "p")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3838 (if (sit-for echo-keystrokes)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3839 (cond
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3840 ((or (= arg 1) (zerop arg))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3841 (message "Mark with character?"))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3842 ((< arg 0)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3843 (message "Mark %d file%s moving backwards?"
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3844 (- arg) (dired-plural-s (- arg))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3845 ((> arg 1)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3846 (message "Mark %d following files with character?" arg))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3847 (dired-mark arg (read-char)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3848
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3849 (defun dired-change-marks (old new)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3850 "Change all OLD marks to NEW marks.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3851 OLD and NEW are both characters used to mark files.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3852 With a prefix, prompts for a mark to toggle. In other words, all unmarked
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3853 files receive that mark, and all files currently marked with that mark become
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3854 unmarked."
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3855 ;; When used in a lisp program, setting NEW to nil means toggle the mark OLD.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3856 (interactive
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3857 (let* ((cursor-in-echo-area t)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3858 (old nil)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3859 (new nil)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3860 (markers (dired-mark-list))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3861 (default (cond ((null markers)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3862 (error "No markers in buffer"))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3863 ((= (length markers) 1)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3864 (setq old (car markers)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3865 ((memq dired-marker-char markers)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3866 dired-marker-char)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3867 ;; picks the last one in the buffer. reasonable?
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3868 ((car markers)))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3869 (or old (setq old
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3870 (progn
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3871 (if current-prefix-arg
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3872 (message "Toggle mark (default %c): " default)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3873 (message "Change old mark (default %c): " default))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3874 (read-char))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3875 (if (memq old '(?\ ?\n ?\r)) (setq old default))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3876 (or current-prefix-arg
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3877 (setq new (progn
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3878 (message
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3879 "Change %c marks to new mark (RET means abort): " old)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3880 (read-char))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3881 (list old new)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3882 (let ((old-count (cond
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3883 ((char-equal old dired-marker-char)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3884 'dired-marks-number)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3885 ((char-equal old dired-del-marker)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3886 'dired-del-flags-number)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3887 ('dired-other-marks-number))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3888 (if new
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3889 (or (memq new '(?\ ?\n ?\r))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3890 ;; \n and \r aren't valid marker chars. Assume that if the
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3891 ;; user hits return, he meant to abort the command.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3892 (let ((string (format "\n%c" old))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3893 (new-count (cond
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3894 ((char-equal new dired-marker-char)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3895 'dired-marks-number)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3896 ((char-equal new dired-del-marker)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3897 'dired-del-flags-number)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3898 ('dired-other-marks-number)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3899 (buffer-read-only nil))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3900 (save-excursion
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3901 (goto-char (point-min))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3902 (while (search-forward string nil t)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3903 (if (char-equal (preceding-char) old)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3904 (progn
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3905 (dired-substitute-marker (1- (point)) old new)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3906 (set new-count (1+ (symbol-value new-count)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3907 (set old-count (max (1- (symbol-value old-count)) 0))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3908 ))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3909 (save-excursion
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3910 (let ((ucount 0)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3911 (mcount 0)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3912 (buffer-read-only nil))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3913 (goto-char (point-min))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3914 (while (not (eobp))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3915 (or (dired-between-files)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3916 (looking-at dired-re-dot)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3917 (cond
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3918 ((= (following-char) ?\ )
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3919 (setq mcount (1+ mcount))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3920 (set old-count (1+ (symbol-value old-count)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3921 (dired-substitute-marker (point) ?\ old))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3922 ((= (following-char) old)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3923 (setq ucount (1+ ucount))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3924 (set old-count (max (1- (symbol-value old-count)) 0))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3925 (dired-substitute-marker (point) old ?\ ))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3926 (forward-line 1))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3927 (message "Unmarked %d file%s; marked %d file%s with %c."
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3928 ucount (dired-plural-s ucount) mcount
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3929 (dired-plural-s mcount) old)))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3930 (dired-update-mode-line-modified))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3931
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3932 (defun dired-unmark-all-files (flag &optional arg)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3933 "Remove a specific mark or any mark from every file.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3934 With prefix arg, query for each marked file.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3935 Type \\[help-command] at that time for help.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3936 With a zero prefix, only counts the number of marks."
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3937 (interactive
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3938 (let* ((cursor-in-echo-area t)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3939 executing-kbd-macro) ; for XEmacs
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3940 (list (and (not (eq current-prefix-arg 0))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3941 (progn (message "Remove marks (RET means all): ") (read-char)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3942 current-prefix-arg)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3943 (save-excursion
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3944 (let* ((help-form "\
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3945 Type SPC or `y' to unflag one file, DEL or `n' to skip to next,
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3946 `!' to unflag all remaining files with no more questions.")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3947 (allp (memq flag '(?\n ?\r)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3948 (count-p (eq arg 0))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3949 (count (if (or allp count-p)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3950 (mapcar
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3951 (function
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3952 (lambda (elt)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3953 (cons elt 0)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3954 (nreverse (dired-mark-list)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3955 0))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3956 (msg "")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3957 (no-query (or (not arg) count-p))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3958 buffer-read-only case-fold-search query)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3959 (goto-char (point-min))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3960 (if (or allp count-p)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3961 (while (re-search-forward dired-re-mark nil t)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3962 (if (or no-query
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3963 (dired-query 'query "Unmark file `%s'? "
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3964 (dired-get-filename t)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3965 (let ((ent (assq (preceding-char) count)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3966 (if ent (setcdr ent (1+ (cdr ent))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3967 (or count-p (dired-substitute-marker
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3968 (- (point) 1) (preceding-char) ?\ ))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3969 (forward-line 1))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3970 (while (search-forward (format "\n%c" flag) nil t)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3971 (if (or no-query
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3972 (dired-query 'query "Unmark file `%s'? "
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3973 (dired-get-filename t)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3974 (progn
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3975 (dired-substitute-marker (match-beginning 0) flag ?\ )
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3976 (setq count (1+ count))))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3977 (if (or allp count-p)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3978 (mapcar
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3979 (function
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3980 (lambda (elt)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3981 (or (zerop (cdr elt))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3982 (setq msg (format "%s%s%d %c%s"
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3983 msg
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3984 (if (zerop (length msg))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3985 " "
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3986 ", ")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3987 (cdr elt)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3988 (car elt)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3989 (if (= 1 (cdr elt)) "" "'s"))))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3990 count)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3991 (or (zerop count)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3992 (setq msg (format " %d %c%s"
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3993 count flag (if (= 1 count) "" "'s")))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3994 (if (zerop (length msg))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3995 (setq msg " none")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3996 (or count-p (dired-update-mode-line-modified t)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3997 (message "%s:%s" (if count-p "Number of marks" "Marks removed") msg))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3998
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3999 (defun dired-get-marked-files (&optional localp arg)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4000 "Return the marked files' names as list of strings.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4001 The list is in the same order as the buffer, that is, the car is the
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4002 first marked file.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4003 Values returned are normally absolute pathnames.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4004 Optional arg LOCALP as in `dired-get-filename'.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4005 Optional second argument ARG forces to use other files. If ARG is an
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4006 integer, use the next ARG files. If ARG is otherwise non-nil, use
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4007 current file. Usually ARG comes from the current prefix arg."
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4008 (save-excursion
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4009 (nreverse (dired-map-over-marks (dired-get-filename localp) arg))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4010
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4011 ;;; Utility functions for marking files
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4012
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4013 (defun dired-mark-files-in-region (start end &optional char)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4014 (let (buffer-read-only)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4015 (if (> start end)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4016 (error "start > end"))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4017 (goto-char start) ; assumed at beginning of line
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4018 (or char (setq char dired-marker-char))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4019 (while (< (point) end)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4020 ;; Skip subdir line and following garbage like the `total' line:
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4021 (while (and (< (point) end) (dired-between-files))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4022 (forward-line 1))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4023 (if (and (/= (following-char) char)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4024 (not (looking-at dired-re-dot))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4025 (save-excursion
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4026 (dired-move-to-filename nil (point))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4027 (progn
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4028 (dired-update-marker-counters (following-char) t)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4029 (dired-substitute-marker (point) (following-char) char)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4030 (dired-update-marker-counters char)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4031 (forward-line 1)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4032 (dired-update-mode-line-modified))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4033
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4034 (defun dired-mark-list ()
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4035 ;; Returns a list of all marks currently used in the buffer.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4036 (let ((result nil)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4037 char)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4038 (save-excursion
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4039 (goto-char (point-min))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4040 (while (not (eobp))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4041 (and (not (memq (setq char (following-char)) '(?\ ?\n ?\r)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4042 (not (memq char result))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4043 (setq result (cons char result)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4044 (forward-line 1)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4045 result))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4046
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4047 ;;; Dynamic markers
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4048
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4049 (defun dired-set-current-marker-string ()
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4050 "Computes and returns `dired-marker-string'."
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4051 (prog1
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4052 (setq dired-marker-string
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4053 (if dired-marker-stack
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4054 (let* ((n (+ (length dired-marker-stack) 5))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4055 (str (make-string n ?\ ))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4056 (list dired-marker-stack)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4057 (pointer dired-marker-stack-pointer))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4058 (setq n (1- n))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4059 (aset str n ?\])
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4060 (setq n (1- n))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4061 (while list
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4062 (aset str n (car list))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4063 (if (zerop pointer)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4064 (progn
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4065 (setq n (1- n))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4066 (aset str n dired-marker-stack-cursor)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4067 (setq n (1- n)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4068 pointer (1- pointer)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4069 list (cdr list)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4070 (aset str n dired-default-marker)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4071 (if (zerop pointer)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4072 (aset str 2 dired-marker-stack-cursor))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4073 (aset str 1 ?\[)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4074 str)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4075 ""))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4076 (set-buffer-modified-p (buffer-modified-p))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4077
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4078 (defun dired-set-marker-char (c)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4079 "Set the marker character to something else.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4080 Use \\[dired-restore-marker-char] to restore the previous value."
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4081 (interactive "cNew marker character: ")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4082 (and (memq c '(?\ ?\n ?\r)) (error "invalid marker char %c" c))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4083 (setq dired-marker-stack (cons c dired-marker-stack)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4084 dired-marker-stack-pointer 0
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4085 dired-marker-char c)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4086 (dired-update-mode-line-modified t)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4087 (dired-set-current-marker-string))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4088
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4089 (defun dired-restore-marker-char ()
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4090 "Restore the marker character to its previous value.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4091 Uses `dired-default-marker' if the marker stack is empty."
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4092 (interactive)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4093 (setq dired-marker-stack (cdr dired-marker-stack)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4094 dired-marker-char (car dired-marker-stack)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4095 dired-marker-stack-pointer (min dired-marker-stack-pointer
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4096 (length dired-marker-stack)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4097 (or dired-marker-char
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4098 (setq dired-marker-char dired-default-marker))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4099 (dired-set-current-marker-string)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4100 (dired-update-mode-line-modified t)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4101 (or dired-marker-stack (message "Marker is %c" dired-marker-char)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4102
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4103 (defun dired-marker-stack-left (n)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4104 "Moves the marker stack cursor to the left."
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4105 (interactive "p")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4106 (let ((len (1+ (length dired-marker-stack))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4107 (or dired-marker-stack (error "Dired marker stack is empty."))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4108 (setq dired-marker-stack-pointer
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4109 (% (+ dired-marker-stack-pointer n) len))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4110 (if (< dired-marker-stack-pointer 0)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4111 (setq dired-marker-stack-pointer (+ dired-marker-stack-pointer
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4112 len)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4113 (dired-set-current-marker-string)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4114 (setq dired-marker-char
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4115 (if (= dired-marker-stack-pointer (1- len))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4116 dired-default-marker
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4117 (nth dired-marker-stack-pointer dired-marker-stack))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4118 (dired-update-mode-line-modified t))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4119
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4120 (defun dired-marker-stack-right (n)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4121 "Moves the marker stack cursor to the right."
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4122 (interactive "p")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4123 (dired-marker-stack-left (- n)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4124
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4125 ;;; Commands to mark or flag files based on their characteristics or names.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4126
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4127 (defun dired-mark-symlinks (&optional unflag-p)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4128 "Mark all symbolic links.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4129 With prefix argument, unflag all those files."
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4130 (interactive "P")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4131 (dired-check-ls-l)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4132 (let ((dired-marker-char (if unflag-p ?\040 dired-marker-char)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4133 (dired-mark-if (looking-at dired-re-sym) "symbolic link"))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4134 (dired-update-mode-line-modified t))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4135
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4136 (defun dired-mark-directories (&optional unflag-p)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4137 "Mark all directory file lines except `.' and `..'.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4138 With prefix argument, unflag all those files."
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4139 (interactive "P")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4140 (if dired-re-dir
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4141 (progn
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4142 (dired-check-ls-l)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4143 (let ((dired-marker-char (if unflag-p ?\040 dired-marker-char)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4144 (dired-mark-if (and (looking-at dired-re-dir)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4145 (not (looking-at dired-re-dot)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4146 "directory file"))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4147 (dired-update-mode-line-modified t))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4148
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4149 (defun dired-mark-executables (&optional unflag-p)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4150 "Mark all executable files.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4151 With prefix argument, unflag all those files."
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4152 (interactive "P")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4153 (if dired-re-exe
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4154 (progn
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4155 (dired-check-ls-l)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4156 (let ((dired-marker-char (if unflag-p ?\040 dired-marker-char)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4157 (dired-mark-if (looking-at dired-re-exe) "executable file"))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4158 (dired-update-mode-line-modified t))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4159
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4160 (defun dired-flag-backup-files (&optional unflag-p)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4161 "Flag all backup files (names ending with `~') for deletion.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4162 With prefix argument, unflag these files."
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4163 (interactive "P")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4164 (dired-check-ls-l)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4165 (let ((dired-marker-char (if unflag-p ?\040 dired-del-marker)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4166 (dired-mark-if
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4167 (and (not (and dired-re-dir (looking-at dired-re-dir)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4168 (let ((fn (dired-get-filename t t)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4169 (if fn (backup-file-name-p fn))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4170 "backup file"))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4171 (dired-update-mode-line-modified t))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4172
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4173 (defun dired-flag-auto-save-files (&optional unflag-p)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4174 "Flag for deletion files whose names suggest they are auto save files.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4175 A prefix argument says to unflag those files instead."
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4176 (interactive "P")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4177 (let ((dired-marker-char (if unflag-p ?\040 dired-del-marker)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4178 (dired-mark-if
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4179 ;; It is less than general to check for ~ here,
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4180 ;; but it's the only way this runs fast enough.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4181 (and (save-excursion (end-of-line)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4182 (eq (preceding-char) ?#))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4183 (not (and dired-re-dir (looking-at dired-re-dir)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4184 (let ((fn (dired-get-filename t t)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4185 (if fn (auto-save-file-name-p
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4186 (file-name-nondirectory fn)))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4187 "auto save file"))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4188 (dired-update-mode-line-modified t))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4189
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4190 (defun dired-mark-rcs-files (&optional unflag-p)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4191 "Mark all files that are under RCS control.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4192 With prefix argument, unflag all those files.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4193 Mentions RCS files for which a working file was not found in this buffer.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4194 Type \\[dired-why] to see them again."
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4195 ;; Returns failures, or nil on success.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4196 ;; Finding those with locks would require to peek into the ,v file,
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4197 ;; depends slightly on the RCS version used and should be done
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4198 ;; together with the Emacs RCS interface.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4199 ;; Unfortunately, there is no definitive RCS interface yet.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4200 (interactive "P")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4201 (message "%sarking RCS controlled files..." (if unflag-p "Unm" "M"))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4202 (let ((dired-marker-char (if unflag-p ?\ dired-marker-char))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4203 rcs-files wf failures count total)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4204 (mapcar ; loop over subdirs
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4205 (function
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4206 (lambda (dir)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4207 (or (equal (file-name-nondirectory (directory-file-name dir))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4208 "RCS")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4209 ;; skip inserted RCS subdirs
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4210 (setq rcs-files
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4211 (append (directory-files dir t ",v$") ; *,v and RCS/*,v
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4212 (let ((rcs-dir (expand-file-name "RCS" dir)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4213 (if (file-directory-p rcs-dir)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4214 (mapcar ; working files from ./RCS are in ./
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4215 (function
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4216 (lambda (x)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4217 (expand-file-name x dir)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4218 (directory-files
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4219 (file-name-as-directory rcs-dir)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4220 nil ",v$"))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4221 rcs-files)))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4222 (mapcar (function car) dired-subdir-alist))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4223 (setq total (length rcs-files))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4224 (while rcs-files
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4225 (setq wf (substring (car rcs-files) 0 -2)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4226 rcs-files (cdr rcs-files))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4227 (save-excursion (if (dired-goto-file wf)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4228 (dired-mark 1) ; giving a prefix avoids checking
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4229 ; for subdir line.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4230 (setq failures (cons wf failures)))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4231 (dired-update-mode-line-modified t)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4232 (if (null failures)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4233 (message "%d RCS file%s %smarked."
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4234 total (dired-plural-s total) (if unflag-p "un" ""))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4235 (setq count (length failures))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4236 (dired-log-summary (buffer-name (current-buffer))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4237 "RCS working file not found %s" failures)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4238 (message "%d RCS file%s: %d %smarked - %d not found %s."
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4239 total (dired-plural-s total) (- total count)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4240 (if unflag-p "un" "") count failures))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4241 failures))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4242
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4243
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4244 ;;;; ------------------------------------------------------------
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4245 ;;;; Logging failures
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4246 ;;;; ------------------------------------------------------------
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4247
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4248 (defun dired-why ()
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4249 "Pop up a buffer with error log output from Dired.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4250 A group of errors from a single command ends with a formfeed.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4251 Thus, use \\[backward-page] to find the beginning of a group of errors."
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4252 (interactive)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4253 (if (get-buffer dired-log-buffer)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4254 (let ((owindow (selected-window))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4255 (window (display-buffer (get-buffer dired-log-buffer))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4256 (unwind-protect
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4257 (progn
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4258 (select-window window)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4259 (goto-char (point-max))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4260 (recenter -1))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4261 (select-window owindow)))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4262
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4263 (defun dired-log (buffer-name log &rest args)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4264 ;; Log a message or the contents of a buffer.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4265 ;; BUFFER-NAME is the name of the dired buffer to which the message applies.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4266 ;; If LOG is a string and there are more args, it is formatted with
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4267 ;; those ARGS. Usually the LOG string ends with a \n.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4268 ;; End each bunch of errors with (dired-log t): this inserts
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4269 ;; current time and buffer, and a \f (formfeed).
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4270 (or (stringp buffer-name) (setq buffer-name (buffer-name buffer-name)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4271 (let ((obuf (current-buffer)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4272 (unwind-protect ; want to move point
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4273 (progn
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4274 (set-buffer (get-buffer-create dired-log-buffer))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4275 (goto-char (point-max))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4276 (let (buffer-read-only)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4277 (cond ((stringp log)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4278 (insert (if args
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4279 (apply (function format) log args)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4280 log)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4281 ((bufferp log)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4282 (insert-buffer log))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4283 ((eq t log)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4284 (insert "\n\t" (current-time-string)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4285 "\tBuffer `" buffer-name "'\n\f\n")))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4286 (set-buffer obuf))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4287
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4288 (defun dired-log-summary (buffer-name string failures)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4289 (message (if failures "%s--type y for details %s"
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4290 "%s--type y for details")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4291 string failures)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4292 ;; Log a summary describing a bunch of errors.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4293 (dired-log buffer-name (concat "\n" string))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4294 (if failures (dired-log buffer-name "\n%s" failures))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4295 (dired-log buffer-name t))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4296
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4297
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4298 ;;;; -------------------------------------------------------
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4299 ;;;; Sort mode of dired buffers.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4300 ;;;; -------------------------------------------------------
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4301
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4302 (defun dired-sort-type (list)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4303 ;; Returns the sort type of LIST, as a symbol.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4304 (let* ((list (reverse list))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4305 (alist (sort
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4306 (mapcar (function
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4307 (lambda (x)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4308 (cons (length (memq (car x) list)) (cdr x))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4309 dired-sort-type-alist)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4310 (function
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4311 (lambda (x y)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4312 (> (car x) (car y))))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4313 (winner (car alist)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4314 (if (zerop (car winner))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4315 'name
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4316 (cdr winner))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4317
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4318 (defun dired-sort-set-modeline (&optional switches)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4319 ;; Set modeline display according to dired-internal-switches.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4320 ;; Modeline display of "by name" or "by date" guarantees the user a
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4321 ;; match with the corresponding regexps. Non-matching switches are
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4322 ;; shown literally.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4323 (or switches (setq switches dired-internal-switches))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4324 (setq dired-sort-mode
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4325 (if dired-show-ls-switches
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4326 (concat " " (dired-make-switches-string
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4327 (or switches dired-internal-switches)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4328 (concat " by " (and (memq ?r switches) "rev-")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4329 (symbol-name (dired-sort-type switches)))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4330 ;; update mode line
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4331 (set-buffer-modified-p (buffer-modified-p)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4332
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4333 (defun dired-sort-toggle-or-edit (&optional arg)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4334 "Toggle between sort by date/name for the current subdirectory.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4335
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4336 With a 0 prefix argument, simply reports on the current switches.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4337
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4338 With a prefix 1 allows the ls switches for the current subdirectory to be
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4339 edited.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4340
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4341 With a prefix 2 allows the default ls switches for newly inserted
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4342 subdirectories to be edited.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4343
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4344 With a prefix \\[universal-argument] allows you to sort the entire
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4345 buffer by either name or date.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4346
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4347 With a prefix \\[universal-argument] \\[universal-argument] allows the default switches
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4348 for the entire buffer to be edited, and then reverts the buffer so that all
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4349 subdirectories are sorted according to these switches.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4350
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4351 Note that although dired allows different ls switches to be used for
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4352 different subdirectories, certain combinations of ls switches are incompatible.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4353 If incompatible switches are detected, dired will offer to revert the buffer
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4354 to force the ls switches for all subdirectories to a single value. If you
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4355 refuse to revert the buffer, any change of ls switches will be aborted."
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4356 (interactive "P")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4357 (cond
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4358 ((eq arg 0)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4359 ;; Report on switches
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4360 (message "Switches for current subdir: %s. Default for buffer: %s."
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4361 (dired-make-switches-string
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4362 (nth 3 (assoc (dired-current-directory) dired-subdir-alist)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4363 (dired-make-switches-string dired-internal-switches)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4364 ((null arg)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4365 ;; Toggle between sort by date/name.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4366 (let* ((dir (dired-current-directory))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4367 (curr (nth 3 (assoc dir dired-subdir-alist))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4368 (dired-sort-other
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4369 (if (eq (dired-sort-type curr) 'name)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4370 (cons ?t curr)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4371 (mapcar (function
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4372 (lambda (x)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4373 (setq curr
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4374 (delq (car x) curr))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4375 dired-sort-type-alist)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4376 curr)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4377 nil dir)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4378 ((eq arg 1)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4379 ;; Edit switches for current subdir.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4380 (let* ((dir (dired-current-directory))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4381 (switch-string
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4382 (read-string
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4383 "New ls switches for current subdir (must contain -l): "
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4384 (dired-make-switches-string
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4385 (nth 3 (assoc dir dired-subdir-alist)))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4386 (switches (dired-make-switches-list switch-string)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4387 (if (dired-compatible-switches-p switches dired-internal-switches)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4388 (dired-sort-other switches nil dir)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4389 (if (or
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4390 (memq 'sort-revert dired-no-confirm)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4391 (y-or-n-p
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4392 (format
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4393 "Switches %s incompatible with default %s. Revert buffer? "
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4394 switch-string
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4395 (dired-make-switches-string dired-internal-switches))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4396 (dired-sort-other switches nil nil)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4397 (error "Switches unchanged. Remain as %s." switch-string)))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4398 ((eq arg 2)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4399 ;; Set new defaults for subdirs inserted in the future.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4400 (let* ((switch-string
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4401 (read-string
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4402 "Default ls switches for new subdirs (must contain -l): "
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4403 (dired-make-switches-string dired-internal-switches)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4404 (switches (dired-make-switches-list switch-string))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4405 (alist dired-subdir-alist)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4406 x bad-switches)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4407 (while alist
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4408 (setq x (nth 3 (car alist))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4409 alist (cdr alist))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4410 (or (dired-compatible-switches-p x switches)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4411 (member x bad-switches)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4412 (setq bad-switches (cons x bad-switches))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4413 (if bad-switches
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4414 (if (or (memq 'sort-revert dired-no-confirm)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4415 (y-or-n-p
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4416 (format
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4417 "Switches %s incompatible with %s. Revert buffer? "
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4418 switch-string (mapconcat 'dired-make-switches-string
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4419 bad-switches ", "))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4420 (dired-sort-other switches nil nil)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4421 (error "Default switches unchanged. Remain as %s."
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4422 (dired-make-switches-string dired-internal-switches)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4423 (dired-sort-other switches t nil))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4424 ((or (equal arg '(4)) (eq arg 'date) (eq arg 'name))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4425 ;; Toggle the entire buffer name/data.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4426 (let ((cursor-in-echo-area t)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4427 (switches (copy-sequence dired-internal-switches))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4428 (type (and (symbolp arg) arg))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4429 char)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4430 (while (null type)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4431 (message "Sort entire buffer according to (n)ame or (d)ate? ")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4432 (setq char (read-char)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4433 type (cond
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4434 ((char-equal char ?d) 'date)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4435 ((char-equal char ?n) 'name)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4436 (t (message "Type one of n or d.") (sit-for 1) nil))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4437 (mapcar (function
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4438 (lambda (x)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4439 (setq switches
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4440 (delq (car x) switches))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4441 dired-sort-type-alist)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4442 (dired-sort-other
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4443 (if (eq type 'date) (cons ?t switches) switches) nil nil)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4444 ((equal arg '(16))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4445 ;; Edit the switches for the entire buffer.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4446 (dired-sort-other
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4447 (dired-make-switches-list
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4448 (read-string
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4449 "Change ls switches for entire buffer to (must contain -l): "
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4450 (dired-make-switches-string dired-internal-switches)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4451 nil nil))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4452 (t
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4453 ;; No idea what's going on.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4454 (error
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4455 "Invalid prefix. See %s dired-sort-toggle-or-edit."
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4456 (substitute-command-keys
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4457 (if (featurep 'ehelp)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4458 "\\[electric-describe-function]"
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4459 "\\[describe-function]"))))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4460
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4461 (defun dired-sort-other (switches &optional no-revert subdir)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4462 ;; Specify new ls SWITCHES for current dired buffer.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4463 ;; With optional second arg NO-REVERT, don't refresh the listing afterwards.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4464 ;; If subdir is non-nil, only changes the switches for the
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4465 ;; sudirectory.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4466 (if subdir
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4467 (let ((elt (assoc subdir dired-subdir-alist)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4468 (if elt (setcar (nthcdr 3 elt) switches)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4469 (setq dired-internal-switches switches))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4470 (or no-revert
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4471 (cond
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4472
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4473 (subdir
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4474 (let ((ofile (dired-get-filename nil t))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4475 (opoint (point)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4476 (message "Relisting %s..." subdir)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4477 (dired-insert-subdir subdir switches)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4478 (message "Relisting %s... done" subdir)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4479 (or (and ofile (dired-goto-file ofile)) (goto-char opoint))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4480
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4481 ((memq ?R switches)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4482 ;; We are replacing a buffer with a giant recursive listing.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4483 (let ((opoint (point))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4484 (ofile (dired-get-filename nil t))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4485 (hidden-subdirs (dired-remember-hidden))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4486 (mark-alist (dired-remember-marks (point-min) (point-max)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4487 (kill-files-p (save-excursion
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4488 (goto-char (point))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4489 (search-forward
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4490 (concat (char-to-string ?\r)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4491 (regexp-quote
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4492 (char-to-string
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4493 dired-kill-marker-char)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4494 nil t)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4495 (omit-files (nth 2 (nth (1- (length dired-subdir-alist))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4496 dired-subdir-alist)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4497 buffer-read-only)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4498 (dired-readin dired-directory (current-buffer)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4499 (or (consp dired-directory)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4500 (null (file-directory-p dired-directory))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4501 (dired-mark-remembered mark-alist) ; mark files that were marked
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4502 (if kill-files-p (dired-do-hide dired-kill-marker-char))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4503 (if omit-files
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4504 (dired-omit-expunge nil t))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4505 ;; hide subdirs that were hidden
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4506 (save-excursion
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4507 (mapcar (function (lambda (dir)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4508 (if (dired-goto-subdir dir)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4509 (dired-hide-subdir 1))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4510 hidden-subdirs))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4511 ;; Try to get back to where we were
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4512 (or (and ofile (dired-goto-file ofile))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4513 (goto-char opoint))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4514 (dired-move-to-filename)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4515
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4516 (t
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4517 ;; Clear all switches in the subdir alist
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4518 (setq dired-subdir-alist
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4519 (mapcar (function
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4520 (lambda (x)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4521 (setcar (nthcdr 3 x) nil)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4522 x))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4523 dired-subdir-alist))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4524 (revert-buffer nil t))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4525 (dired-update-mode-line t))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4526
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4527 (defun dired-compatible-switches-p (list1 list2)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4528 ;; Returns t if list1 and list2 are allowed as switches in the same
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4529 ;; dired buffer.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4530 (and (eq (null (or (memq ?l list1) (memq ?o list1) (memq ?g list1)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4531 (null (or (memq ?l list2) (memq ?o list2) (memq ?g list2))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4532 (eq (null (memq ?F list1)) (null (memq ?F list2)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4533 (eq (null (memq ?p list1)) (null (memq ?p list2)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4534 (eq (null (memq ?b list1)) (null (memq ?b list2)))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4535
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4536 (defun dired-check-ls-l (&optional switches)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4537 ;; Check for long-style listings
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4538 (let ((switches (or switches dired-internal-switches)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4539 (or (memq ?l switches) (memq ?o switches) (memq ?g switches)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4540 (error "Dired needs -l, -o, or -g in ls switches"))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4541
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4542
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4543 ;;;; --------------------------------------------------------------
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4544 ;;;; Creating new files.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4545 ;;;; --------------------------------------------------------------
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4546 ;;;
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4547 ;;; The dired-create-files paradigm is used for copying, renaming,
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4548 ;;; compressing, and making hard and soft links.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4549
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4550 (defun dired-file-marker (file)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4551 ;; Return FILE's marker, or nil if unmarked.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4552 (save-excursion
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4553 (and (dired-goto-file file)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4554 (progn
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4555 (skip-chars-backward "^\n\r")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4556 (and (not (= ?\040 (following-char)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4557 (following-char))))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4558
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4559 ;; The basic function for half a dozen variations on cp/mv/ln/ln -s.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4560 (defun dired-create-files (file-creator operation fn-list name-constructor
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4561 &optional marker-char query
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4562 implicit-to)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4563 ;; Create a new file for each from a list of existing files. The user
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4564 ;; is queried, dired buffers are updated, and at the end a success or
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4565 ;; failure message is displayed
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4566
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4567 ;; FILE-CREATOR must accept three args: oldfile newfile ok-if-already-exists
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4568 ;; It is called for each file and must create newfile, the entry of
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4569 ;; which will be added. The user will be queried if the file already
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4570 ;; exists. If oldfile is removed by FILE-CREATOR (i.e, it is a
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4571 ;; rename), it is FILE-CREATOR's responsibility to update dired
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4572 ;; buffers. FILE-CREATOR must abort by signalling a file-error if it
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4573 ;; could not create newfile. The error is caught and logged.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4574
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4575 ;; OPERATION (a capitalized string, e.g. `Copy') describes the
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4576 ;; operation performed. It is used for error logging.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4577
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4578 ;; FN-LIST is the list of files to copy (full absolute pathnames).
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4579
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4580 ;; NAME-CONSTRUCTOR returns a newfile for every oldfile, or nil to
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4581 ;; skip. If it skips files, it is supposed to tell why (using dired-log).
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4582
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4583 ;; Optional MARKER-CHAR is a character with which to mark every
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4584 ;; newfile's entry, or t to use the current marker character if the
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4585 ;; oldfile was marked.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4586
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4587 ;; QUERY is a function to use to prompt the user about creating a file.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4588 ;; It accepts two args, the from and to files,
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4589 ;; and must return nil or t. If QUERY is nil, then no user
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4590 ;; confirmation will be requested.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4591
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4592 ;; If IMPLICIT-TO is non-nil, then the file constructor does not take
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4593 ;; a to-file arg. e.g. compress.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4594
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4595 (let ((success-count 0)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4596 (total (length fn-list))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4597 failures skipped overwrite-query)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4598 ;; Fluid vars used for storing responses of previous queries must be
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4599 ;; initialized.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4600 (dired-save-excursion
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4601 (setq dired-overwrite-backup-query nil
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4602 dired-file-creator-query nil)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4603 (mapcar
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4604 (function
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4605 (lambda (from)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4606 (let ((to (funcall name-constructor from)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4607 (if to
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4608 (if (equal to from)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4609 (progn
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4610 (dired-log (buffer-name (current-buffer))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4611 "Cannot %s to same file: %s\n"
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4612 (downcase operation) from)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4613 (setq skipped (cons (dired-make-relative from) skipped)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4614 (if (or (null query)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4615 (funcall query from to))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4616 (let* ((overwrite (let (jka-compr-enabled)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4617 ;; Don't let jka-compr fool us.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4618 (file-exists-p to)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4619 ;; for dired-handle-overwrite
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4620 (dired-overwrite-confirmed
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4621 (and overwrite
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4622 (let ((help-form '(format "\
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4623 Type SPC or `y' to overwrite file `%s',
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4624 DEL or `n' to skip to next,
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4625 ESC or `q' to not overwrite any of the remaining files,
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4626 `!' to overwrite all remaining files with no more questions." to)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4627 (dired-query 'overwrite-query
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4628 "Overwrite %s?" to))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4629 ;; must determine if FROM is marked before
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4630 ;; file-creator gets a chance to delete it
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4631 ;; (in case of a move).
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4632 (actual-marker-char
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4633 (cond ((integerp marker-char) marker-char)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4634 (marker-char (dired-file-marker from))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4635 (t nil))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4636 (if (and overwrite (null dired-overwrite-confirmed))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4637 (setq skipped (cons (dired-make-relative from)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4638 skipped))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4639 (condition-case err
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4640 (let ((dired-unhandle-add-files
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4641 (cons to dired-unhandle-add-files)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4642 (if implicit-to
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4643 (funcall file-creator from
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4644 dired-overwrite-confirmed)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4645 (funcall file-creator from to
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4646 dired-overwrite-confirmed))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4647 (setq success-count (1+ success-count))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4648 (message "%s: %d of %d"
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4649 operation success-count total)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4650 (dired-add-file to actual-marker-char))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4651 (file-error ; FILE-CREATOR aborted
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4652 (progn
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4653 (setq failures (cons (dired-make-relative from)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4654 failures))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4655 (dired-log (buffer-name (current-buffer))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4656 "%s `%s' to `%s' failed:\n%s\n"
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4657 operation from to err))))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4658 (setq skipped (cons (dired-make-relative from) skipped))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4659 (setq skipped (cons (dired-make-relative from) skipped))))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4660 fn-list)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4661 (cond
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4662 (failures
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4663 (dired-log-summary
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4664 (buffer-name (current-buffer))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4665 (format "%s failed for %d of %d file%s"
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4666 operation (length failures) total
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4667 (dired-plural-s total)) failures))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4668 (skipped
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4669 (dired-log-summary
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4670 (buffer-name (current-buffer))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4671 (format "%s: %d of %d file%s skipped"
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4672 operation (length skipped) total
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4673 (dired-plural-s total)) skipped))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4674 (t
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4675 (message "%s: %s file%s."
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4676 operation success-count (dired-plural-s success-count)))))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4677
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4678 (defun dired-do-create-files (op-symbol file-creator operation arg
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4679 &optional marker-char
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4680 prompter how-to)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4681 ;; Create a new file for each marked file.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4682 ;; Prompts user for target, which is a directory in which to create
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4683 ;; the new files. Target may be a plain file if only one marked
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4684 ;; file exists.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4685 ;; OP-SYMBOL is the symbol for the operation. Function `dired-mark-pop-up'
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4686 ;; will determine wether pop-ups are appropriate for this OP-SYMBOL.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4687 ;; FILE-CREATOR and OPERATION as in dired-create-files.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4688 ;; ARG as in dired-get-marked-files.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4689 ;; PROMPTER is a function of one-arg, the list of files, to return a prompt
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4690 ;; to use for dired-read-file-name. If it is nil, then a default prompt
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4691 ;; will be used.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4692 ;; Optional arg MARKER-CHAR as in dired-create-files.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4693 ;; Optional arg HOW-TO determines how to treat target:
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4694 ;; If HOW-TO is not given (or nil), and target is a directory, the
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4695 ;; file(s) are created inside the target directory. If target
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4696 ;; is not a directory, there must be exactly one marked file,
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4697 ;; else error.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4698 ;; If HOW-TO is t, then target is not modified. There must be
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4699 ;; exactly one marked file, else error.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4700 ;; Else HOW-TO is assumed to be a function of one argument, target,
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4701 ;; that looks at target and returns a value for the into-dir
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4702 ;; variable. The function dired-into-dir-with-symlinks is provided
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4703 ;; for the case (common when creating symlinks) that symbolic
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4704 ;; links to directories are not to be considered as directories
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4705 ;; (as file-directory-p would if HOW-TO had been nil).
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4706
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4707 (let* ((fn-list (dired-get-marked-files nil arg))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4708 (fn-count (length fn-list))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4709 (cdir (dired-current-directory))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4710 (target (expand-file-name
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4711 (dired-mark-read-file-name
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4712 (if prompter
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4713 (funcall prompter fn-list)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4714 (concat operation " %s to: "))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4715 (dired-dwim-target-directory)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4716 op-symbol arg (mapcar (function
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4717 (lambda (fn)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4718 (dired-make-relative fn cdir t)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4719 fn-list))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4720 (into-dir (cond ((null how-to) (file-directory-p target))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4721 ((eq how-to t) nil)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4722 (t (funcall how-to target)))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4723 (if (and (> fn-count 1)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4724 (not into-dir))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4725 (error "Marked %s: target must be a directory: %s" operation target))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4726 ;; rename-file bombs when moving directories unless we do this:
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4727 (or into-dir (setq target (directory-file-name target)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4728 (dired-create-files
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4729 file-creator operation fn-list
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4730 (if into-dir ; target is a directory
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4731 (list 'lambda '(from)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4732 (list 'expand-file-name '(file-name-nondirectory from) target))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4733 (list 'lambda '(from) target))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4734 marker-char)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4735
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4736 (defun dired-into-dir-with-symlinks (target)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4737 (and (file-directory-p target)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4738 (not (file-symlink-p target))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4739 ;; This may not always be what you want, especially if target is your
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4740 ;; home directory and it happens to be a symbolic link, as is often the
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4741 ;; case with NFS and automounters. Or if you want to make symlinks
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4742 ;; into directories that themselves are only symlinks, also quite
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4743 ;; common.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4744 ;; So we don't use this function as value for HOW-TO in
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4745 ;; dired-do-symlink, which has the minor disadvantage of
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4746 ;; making links *into* a symlinked-dir, when you really wanted to
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4747 ;; *overwrite* that symlink. In that (rare, I guess) case, you'll
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4748 ;; just have to remove that symlink by hand before making your marked
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4749 ;; symlinks.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4750
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4751 (defun dired-handle-overwrite (to)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4752 ;; Save old version of a to be overwritten file TO.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4753 ;; `dired-overwrite-confirmed' and `dired-overwrite-backup-query'
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4754 ;; are fluid vars from dired-create-files.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4755 (if (and dired-backup-if-overwrite
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4756 dired-overwrite-confirmed
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4757 (or (eq 'always dired-backup-if-overwrite)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4758 (dired-query 'dired-overwrite-backup-query
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4759 (format "Make backup for existing file `%s'? " to))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4760 (let ((backup (car (find-backup-file-name to))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4761 (rename-file to backup 0)))) ; confirm overwrite of old backup
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4762
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4763 (defun dired-dwim-target-directory ()
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4764 ;; Try to guess which target directory the user may want.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4765 ;; If there is a dired buffer displayed in the next window, use
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4766 ;; its current subdir, else use current subdir of this dired buffer.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4767 ;; non-dired buffer may want to profit from this function, e.g. vm-uudecode
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4768 (let* ((this-dir (and (eq major-mode 'dired-mode)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4769 (dired-current-directory)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4770 (dwimmed
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4771 (if dired-dwim-target
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4772 (let* ((other-buf (window-buffer (next-window)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4773 (other-dir (save-excursion
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4774 (set-buffer other-buf)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4775 (and (eq major-mode 'dired-mode)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4776 (dired-current-directory)))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4777 (or other-dir this-dir))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4778 this-dir)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4779 (and dwimmed (dired-abbreviate-file-name dwimmed))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4780
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4781 (defun dired-get-target-directory ()
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4782 "Writes a copy of the current subdirectory into an active minibuffer."
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4783 (interactive)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4784 (let ((mb (dired-get-active-minibuffer-window)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4785 (if mb
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4786 (let ((dir (dired-current-directory)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4787 (select-window mb)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4788 (set-buffer (window-buffer mb))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4789 (erase-buffer)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4790 (insert dir))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4791 (error "No active minibuffer"))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4792
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4793 ;;; Copying files
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4794
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4795 (defun dired-do-copy (&optional arg)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4796 "Copy all marked (or next ARG) files, or copy the current file.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4797 When operating on just the current file, you specify the new name.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4798 When operating on multiple or marked files, you specify a directory
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4799 and the files are copied into that directory, retaining the same file names.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4800
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4801 A zero prefix argument copies nothing. But it toggles the
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4802 variable `dired-copy-preserve-time' (which see)."
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4803 (interactive "P")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4804 (if (not (zerop (prefix-numeric-value arg)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4805 (dired-do-create-files 'copy (function dired-copy-file)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4806 (if dired-copy-preserve-time "Copy [-p]" "Copy")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4807 arg dired-keep-marker-copy)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4808 (setq dired-copy-preserve-time (not dired-copy-preserve-time))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4809 (if dired-copy-preserve-time
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4810 (message "Copy will preserve time.")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4811 (message "Copied files will get current date."))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4812
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4813 (defun dired-copy-file (from to ok-flag)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4814 (dired-handle-overwrite to)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4815 (copy-file from to ok-flag dired-copy-preserve-time))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4816
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4817 ;;; Renaming/moving files
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4818
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4819 (defun dired-do-rename (&optional arg)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4820 "Rename current file or all marked (or next ARG) files.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4821 When renaming just the current file, you specify the new name.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4822 When renaming multiple or marked files, you specify a directory.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4823
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4824 A zero ARG moves no files but toggles `dired-dwim-target' (which see)."
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4825 (interactive "P")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4826 (if (not (zerop (prefix-numeric-value arg)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4827 (dired-do-create-files 'move (function dired-rename-file)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4828 "Move" arg dired-keep-marker-rename
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4829 (function
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4830 (lambda (list)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4831 (if (= (length list) 1)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4832 "Rename %s to: "
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4833 "Move %s to: "))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4834 (setq dired-dwim-target (not dired-dwim-target))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4835 (message "dired-dwim-target is %s." (if dired-dwim-target "ON" "OFF"))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4836
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4837 (defun dired-rename-file (from to ok-flag)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4838 (dired-handle-overwrite to)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4839 (let ((insert (assoc (file-name-as-directory from) dired-subdir-alist)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4840 (rename-file from to ok-flag) ; error is caught in -create-files
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4841 ;; Silently rename the visited file of any buffer visiting this file.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4842 (dired-rename-update-buffers from to insert)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4843
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4844 (defun dired-rename-update-buffers (from to &optional insert)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4845 (if (get-file-buffer from)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4846 (save-excursion
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4847 (set-buffer (get-file-buffer from))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4848 (let ((modflag (buffer-modified-p)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4849 (set-visited-file-name to) ; kills write-file-hooks
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4850 (set-buffer-modified-p modflag)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4851 ;; It's a directory. More work to do.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4852 (let ((blist (buffer-list))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4853 (from-dir (file-name-as-directory from))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4854 (to-dir (file-name-as-directory to)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4855 (save-excursion
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4856 (while blist
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4857 (set-buffer (car blist))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4858 (setq blist (cdr blist))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4859 (cond
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4860 (buffer-file-name
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4861 (if (dired-in-this-tree buffer-file-name from-dir)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4862 (let ((modflag (buffer-modified-p)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4863 (unwind-protect
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4864 (set-visited-file-name
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4865 (concat to-dir (substring buffer-file-name
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4866 (length from-dir))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4867 (set-buffer-modified-p modflag)))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4868 (dired-directory
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4869 (if (string-equal from-dir (expand-file-name default-directory))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4870 ;; If top level directory was renamed, lots of things
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4871 ;; have to be updated.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4872 (progn
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4873 (dired-unadvertise from-dir)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4874 (setq default-directory to-dir
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4875 dired-directory
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4876 ;; Need to beware of wildcards.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4877 (expand-file-name
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4878 (file-name-nondirectory dired-directory)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4879 to-dir))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4880 (let ((new-name (file-name-nondirectory
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4881 (directory-file-name dired-directory))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4882 ;; Try to rename buffer, but just leave old name if new
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4883 ;; name would already exist (don't try appending "<%d>")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4884 ;; Why? --sandy 19-8-94
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4885 (or (get-buffer new-name)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4886 (rename-buffer new-name)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4887 (dired-advertise))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4888 (and insert
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4889 (assoc (file-name-directory (directory-file-name to))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4890 dired-subdir-alist)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4891 (dired-insert-subdir to))))))))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4892
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4893 ;;; Making symbolic links
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4894
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4895 (defun dired-do-symlink (&optional arg)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4896 "Make symbolic links to current file or all marked (or next ARG) files.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4897 When operating on just the current file, you specify the new name.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4898 When operating on multiple or marked files, you specify a directory
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4899 and new symbolic links are made in that directory
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4900 with the same names that the files currently have."
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4901 (interactive "P")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4902 (dired-do-create-files 'symlink (function make-symbolic-link)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4903 "SymLink" arg dired-keep-marker-symlink))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4904
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4905 ;; Relative symlinks:
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4906 ;; make-symbolic no longer expands targets (as of at least 18.57),
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4907 ;; so the code to call ln has been removed.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4908
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4909 (defun dired-do-relsymlink (&optional arg)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4910 "Symlink all marked (or next ARG) files into a directory,
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4911 or make a symbolic link to the current file.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4912 This creates relative symbolic links like
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4913
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4914 foo -> ../bar/foo
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4915
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4916 not absolute ones like
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4917
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4918 foo -> /ugly/path/that/may/change/any/day/bar/foo"
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4919 (interactive "P")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4920 (dired-do-create-files 'relsymlink (function dired-make-relative-symlink)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4921 "RelSymLink" arg dired-keep-marker-symlink))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4922
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4923 (defun dired-make-relative-symlink (target linkname
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4924 &optional ok-if-already-exists)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4925 "Make a relative symbolic link pointing to TARGET with name LINKNAME.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4926 Three arguments: FILE1 FILE2 &optional OK-IF-ALREADY-EXISTS
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4927 The link is relative (if possible), for example
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4928
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4929 \"/vol/tex/bin/foo\" \"/vol/local/bin/foo\"
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4930
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4931 results in
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4932
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4933 \"../../tex/bin/foo\" \"/vol/local/bin/foo\""
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4934 (interactive
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4935 (let ((target (read-string "Make relative symbolic link to file: ")))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4936 (list
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4937 target
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4938 (read-file-name (format "Make relsymlink to file %s: " target))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4939 0)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4940 (let* ((target (expand-file-name target))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4941 (linkname (expand-file-name linkname))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4942 (handler (or (find-file-name-handler
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4943 linkname 'dired-make-relative-symlink)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4944 (find-file-name-handler
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4945 target 'dired-make-relative-symlink))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4946 (if handler
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4947 (funcall handler 'dired-make-relative-symlink target linkname
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4948 ok-if-already-exists)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4949 (setq target (directory-file-name target)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4950 linkname (directory-file-name linkname))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4951 (make-symbolic-link
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4952 (dired-make-relative target (file-name-directory linkname) t)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4953 linkname ok-if-already-exists))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4954
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4955 ;;; Hard links -- adding names to files
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4956
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4957 (defun dired-do-hardlink (&optional arg)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4958 "Add names (hard links) current file or all marked (or next ARG) files.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4959 When operating on just the current file, you specify the new name.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4960 When operating on multiple or marked files, you specify a directory
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4961 and new hard links are made in that directory
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4962 with the same names that the files currently have."
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4963 (interactive "P")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4964 (dired-do-create-files 'hardlink (function add-name-to-file)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4965 "HardLink" arg dired-keep-marker-hardlink))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4966
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4967
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4968 ;;;; ---------------------------------------------------------------
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4969 ;;;; Running process on marked files
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4970 ;;;; ---------------------------------------------------------------
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4971 ;;;
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4972 ;;; Commands for shell processes are in dired-shell.el.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4973
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4974 ;;; Internal functions for running subprocesses,
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4975 ;;; checking and logging of their errors.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4976
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4977 (defun dired-call-process (program discard &rest arguments)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4978 ;; Run PROGRAM with output to current buffer unless DISCARD is t.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4979 ;; Remaining arguments are strings passed as command arguments to PROGRAM.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4980 ;; Returns program's exit status, as an integer.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4981 ;; This is a separate function so that efs can redefine it.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4982 (let ((return
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4983 (apply 'call-process program nil (not discard) nil arguments)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4984 (if (and (not (equal shell-file-name program))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4985 (integerp return))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4986 return
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4987 ;; Fudge return code by looking for errors in current buffer.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4988 (if (zerop (buffer-size)) 0 1))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4989
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4990 (defun dired-check-process (msg program &rest arguments)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4991 ;; Display MSG while running PROGRAM, and check for output.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4992 ;; Remaining arguments are strings passed as command arguments to PROGRAM.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4993 ;; On error, insert output in a log buffer and return the
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4994 ;; offending ARGUMENTS or PROGRAM.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4995 ;; Caller can cons up a list of failed args.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4996 ;; Else returns nil for success.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4997 (let ((err-buffer (get-buffer-create " *dired-check-process output*"))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4998 (dir default-directory))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
4999 (message "%s..." msg)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5000 (save-excursion
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5001 ;; Get a clean buffer for error output:
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5002 (set-buffer err-buffer)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5003 (erase-buffer)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5004 (setq default-directory dir) ; caller's default-directory
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5005 (if (not
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5006 (eq 0 (apply (function dired-call-process) program nil arguments)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5007 (progn
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5008 (dired-log (buffer-name (current-buffer))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5009 (concat program " " (prin1-to-string arguments) "\n"))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5010 (dired-log (buffer-name (current-buffer)) err-buffer)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5011 (or arguments program t))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5012 (kill-buffer err-buffer)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5013 (message "%s...done" msg)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5014 nil))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5015
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5016 ;;; Changing file attributes
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5017
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5018 (defun dired-do-chxxx (attribute-name program op-symbol arg)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5019 ;; Change file attributes (mode, group, owner) of marked files and
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5020 ;; refresh their file lines.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5021 ;; ATTRIBUTE-NAME is a string describing the attribute to the user.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5022 ;; PROGRAM is the program used to change the attribute.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5023 ;; OP-SYMBOL is the type of operation (for use in dired-mark-pop-up).
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5024 ;; ARG describes which files to use, like in dired-get-marked-files.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5025 (let* ((files (dired-get-marked-files t arg))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5026 (new-attribute
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5027 (dired-mark-read-string
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5028 (concat "Change " attribute-name " of %s to: ")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5029 nil op-symbol arg files))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5030 (operation (concat program " " new-attribute))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5031 (failures
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5032 (dired-bunch-files 10000 (function dired-check-process)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5033 (list operation program new-attribute)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5034 files)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5035 (dired-do-redisplay arg);; moves point if ARG is an integer
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5036 (if failures
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5037 (dired-log-summary (buffer-name (current-buffer))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5038 (format "%s: error" operation) nil))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5039
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5040 (defun dired-do-chmod (&optional arg)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5041 "Change the mode of the marked (or next ARG) files.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5042 This calls chmod, thus symbolic modes like `g+w' are allowed."
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5043 (interactive "P")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5044 (dired-do-chxxx "Mode" "chmod" 'chmod arg))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5045
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5046 (defun dired-do-chgrp (&optional arg)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5047 "Change the group of the marked (or next ARG) files."
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5048 (interactive "P")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5049 (dired-do-chxxx "Group" "chgrp" 'chgrp arg))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5050
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5051 (defun dired-do-chown (&optional arg)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5052 "Change the owner of the marked (or next ARG) files."
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5053 (interactive "P")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5054 (dired-do-chxxx "Owner" dired-chown-program 'chown arg))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5055
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5056 ;;; Utilities for running processes on marked files.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5057
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5058 ;; Process all the files in FILES in batches of a convenient size,
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5059 ;; by means of (FUNCALL FUNCTION ARGS... SOME-FILES...).
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5060 ;; Batches are chosen to need less than MAX chars for the file names,
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5061 ;; allowing 3 extra characters of separator per file name.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5062 (defun dired-bunch-files (max function args files)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5063 (let (pending
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5064 (pending-length 0)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5065 failures)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5066 ;; Accumulate files as long as they fit in MAX chars,
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5067 ;; then process the ones accumulated so far.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5068 (while files
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5069 (let* ((thisfile (car files))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5070 (thislength (+ (length thisfile) 3))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5071 (rest (cdr files)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5072 ;; If we have at least 1 pending file
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5073 ;; and this file won't fit in the length limit, process now.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5074 (if (and pending (> (+ thislength pending-length) max))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5075 (setq failures
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5076 (nconc (apply function (append args pending))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5077 failures)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5078 pending nil
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5079 pending-length 0))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5080 ;; Do (setq pending (cons thisfile pending))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5081 ;; but reuse the cons that was in `files'.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5082 (setcdr files pending)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5083 (setq pending files)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5084 (setq pending-length (+ thislength pending-length))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5085 (setq files rest)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5086 (nconc (apply function (append args pending))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5087 failures)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5088
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5089
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5090 ;;;; ---------------------------------------------------------------
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5091 ;;;; Calculating data or properties for marked files.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5092 ;;;; ---------------------------------------------------------------
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5093
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5094 (defun dired-do-total-size (&optional arg)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5095 "Show total size of all marked (or next ARG) files."
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5096 (interactive "P")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5097 (let* ((result (dired-map-over-marks (dired-get-file-size) arg))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5098 (total (apply (function +) result))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5099 (num (length result)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5100 (message "%d bytes (%d kB) in %s file%s"
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5101 total (/ total 1024) num (dired-plural-s num))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5102 total))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5103
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5104 (defun dired-get-file-size ()
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5105 ;; Returns the file size in bytes of the current file, as an integer.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5106 ;; Assumes that it is on a valid file line. It's the caller's responsibility
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5107 ;; to ensure this. Assumes that match 0 for dired-re-month-and-time is
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5108 ;; at the end of the file size.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5109 (dired-move-to-filename t)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5110 ;; dired-move-to-filename must leave match-beginning 0 at the start of
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5111 ;; the date.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5112 (goto-char (match-beginning 0))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5113 (skip-chars-backward " ")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5114 (string-to-int (buffer-substring (point)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5115 (progn (skip-chars-backward "0-9")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5116 (point)))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5117
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5118 (defun dired-copy-filenames-as-kill (&optional arg)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5119 "Copy names of marked (or next ARG) files into the kill ring.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5120 The names are separated by a space, and may be copied into other buffers
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5121 with \\[yank]. The list of names is also stored in the variable
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5122 `dired-marked-files' for possible manipulation in the *scratch* buffer.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5123
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5124 With a 0 prefix argument, use the pathname relative to the top-level dired
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5125 directory for each marked file.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5126
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5127 With a prefix \\[universal-argument], use the complete pathname of each
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5128 marked file.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5129
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5130 With a prefix \\[universal-argument] \\[universal-argument], copy the complete
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5131 file line. In this case, the lines are separated by newlines.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5132
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5133 If on a subdirectory headerline and no prefix argument given, use the
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5134 subdirectory name instead."
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5135 (interactive "P")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5136 (let (res)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5137 (cond
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5138 ((and (null arg) (setq res (dired-get-subdir)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5139 (kill-new res)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5140 (message "Copied %s into kill ring." res))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5141 ((equal arg '(16))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5142 (setq dired-marked-files
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5143 (dired-map-over-marks
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5144 (concat " " ; Don't copy the mark.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5145 (buffer-substring
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5146 (progn (beginning-of-line) (1+ (point)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5147 (progn (skip-chars-forward "^\n\r") (point))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5148 nil))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5149 (let ((len (length dired-marked-files)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5150 (kill-new (concat
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5151 (mapconcat 'identity dired-marked-files "\n")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5152 "\n"))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5153 (message "Copied %d file line%s into kill ring."
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5154 len (dired-plural-s len))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5155 (t
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5156 (setq dired-marked-files
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5157 (cond
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5158 ((null arg)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5159 (dired-get-marked-files 'no-dir))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5160 ((eq arg 0)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5161 (dired-get-marked-files t))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5162 ((integerp arg)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5163 (dired-get-marked-files 'no-dir arg))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5164 ((equal arg '(4))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5165 (dired-get-marked-files))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5166 (t (error "Invalid prefix %s" arg))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5167 (let ((len (length dired-marked-files)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5168 (kill-new (mapconcat 'identity dired-marked-files " "))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5169 (message "Copied %d file name%s into kill ring."
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5170 len (dired-plural-s len)))))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5171
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5172
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5173 ;;;; -----------------------------------------------------------
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5174 ;;;; Killing subdirectories
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5175 ;;;; -----------------------------------------------------------
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5176 ;;;
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5177 ;;; These commands actually remove text from the dired buffer.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5178
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5179 (defun dired-kill-subdir (&optional remember-marks tree)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5180 "Remove all lines of current subdirectory.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5181 Lower levels are unaffected. If given a prefix when called interactively,
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5182 kills the entire directory tree below the current subdirectory."
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5183 ;; With optional REMEMBER-MARKS, return a mark-alist.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5184 (interactive (list nil current-prefix-arg))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5185 (let ((cur-dir (dired-current-directory)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5186 (if (string-equal cur-dir (expand-file-name default-directory))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5187 (error "Attempt to kill top level directory"))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5188 (if tree
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5189 (dired-kill-tree cur-dir remember-marks)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5190 (let ((beg (dired-subdir-min))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5191 (end (dired-subdir-max))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5192 buffer-read-only)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5193 (prog1
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5194 (if remember-marks (dired-remember-marks beg end))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5195 (goto-char beg)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5196 (or (bobp) (forward-char -1)) ; gobble separator
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5197 (delete-region (point) end)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5198 (dired-unsubdir cur-dir)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5199 (dired-update-mode-line)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5200 (dired-update-mode-line-modified t))))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5201
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5202 (defun dired-kill-tree (dirname &optional remember-marks)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5203 "Kill all proper subdirs of DIRNAME, excluding DIRNAME itself.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5204 With optional arg REMEMBER-MARKS, return an alist of marked files."
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5205 (interactive "DKill tree below directory: ")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5206 (let ((s-alist dired-subdir-alist) dir m-alist)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5207 (while s-alist
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5208 (setq dir (car (car s-alist))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5209 s-alist (cdr s-alist))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5210 (if (and (not (string-equal dir dirname))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5211 (dired-in-this-tree dir dirname)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5212 (dired-goto-subdir dir))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5213 (setq m-alist (nconc (dired-kill-subdir remember-marks) m-alist))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5214 (dired-update-mode-line)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5215 (dired-update-mode-line-modified t)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5216 m-alist))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5217
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5218
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5219 ;;;; ------------------------------------------------------------
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5220 ;;;; Killing file lines
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5221 ;;;; ------------------------------------------------------------
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5222 ;;;
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5223 ;;; Uses selective diplay, rather than removing lines from the buffer.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5224
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5225 (defun dired-do-kill-file-lines (&optional arg)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5226 "Kill all marked file lines, or those indicated by the prefix argument.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5227 Killing file lines means hiding them with selective display. Giving
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5228 a zero prefix redisplays all killed file lines."
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5229 (interactive "P")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5230 (or selective-display
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5231 (error "selective-display must be t for file line killing to work!"))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5232 (if (eq arg 0)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5233 (dired-do-unhide dired-kill-marker-char
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5234 "Successfully resuscitated %d file line%s."
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5235 dired-keep-marker-kill)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5236 (let ((files
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5237 (length
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5238 (dired-map-over-marks
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5239 (progn
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5240 (beginning-of-line)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5241 (subst-char-in-region (1- (point)) (point) ?\n ?\r)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5242 (dired-substitute-marker (point) (following-char)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5243 dired-kill-marker-char)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5244 (dired-update-marker-counters dired-marker-char t)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5245 t)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5246 arg))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5247 ;; Beware of extreme apparent save-excursion lossage here.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5248 (let ((opoint (point)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5249 (skip-chars-backward "^\n\r")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5250 (if (= (preceding-char) ?\n)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5251 (goto-char opoint)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5252 (setq opoint (- opoint (point)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5253 (beginning-of-line)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5254 (skip-chars-forward "^\n\r" (+ (point) opoint))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5255 (dired-update-mode-line-modified)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5256 (message "Killed %d file line%s." files (dired-plural-s files)))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5257
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5258
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5259 ;;;; ----------------------------------------------------------------
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5260 ;;;; Omitting files.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5261 ;;;; ----------------------------------------------------------------
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5262
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5263 ;; Marked files are never omitted.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5264 ;; Adapted from code submitted by:
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5265 ;; Michael D. Ernst, mernst@theory.lcs.mit.edu, 1/11/91
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5266 ;; Changed to work with selective display by Sandy Rutherford, 13/12/92.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5267 ;; For historical reasons, we still use the term expunge, although nothing
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5268 ;; is expunged from the buffer.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5269
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5270 (defun dired-omit-toggle (&optional arg)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5271 "Toggle between displaying and omitting files matching
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5272 `dired-omit-files-regexp' in the current subdirectory.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5273 With a positive prefix, omits files in the entire tree dired buffer.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5274 With a negative prefix, forces all files in the tree dired buffer to be
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5275 displayed."
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5276 (interactive "P")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5277 (if arg
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5278 (let ((arg (prefix-numeric-value arg)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5279 (if (>= arg 0)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5280 (dired-omit-expunge nil t)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5281 (dired-do-unhide dired-omit-marker-char "")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5282 (mapcar
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5283 (function
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5284 (lambda (elt)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5285 (setcar (nthcdr 2 elt) nil)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5286 dired-subdir-alist)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5287 (if (dired-current-subdir-omitted-p)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5288 (save-restriction
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5289 (narrow-to-region (dired-subdir-min) (dired-subdir-max))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5290 (dired-do-unhide dired-omit-marker-char "")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5291 (setcar (nthcdr 2 (assoc
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5292 (dired-current-directory) dired-subdir-alist))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5293 nil)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5294 (setq dired-subdir-omit nil))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5295 (dired-omit-expunge)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5296 (setq dired-subdir-omit t)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5297 (dired-update-mode-line t))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5298
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5299 (defun dired-current-subdir-omitted-p ()
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5300 ;; Returns t if the current subdirectory is omited.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5301 (nth 2 (assoc (dired-current-directory) dired-subdir-alist)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5302
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5303 (defun dired-remember-omitted ()
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5304 ;; Returns a list of omitted subdirs.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5305 (let ((alist dired-subdir-alist)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5306 result elt)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5307 (while alist
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5308 (setq elt (car alist)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5309 alist (cdr alist))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5310 (if (nth 2 elt)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5311 (setq result (cons (car elt) result))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5312 result))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5313
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5314 (defun dired-omit-expunge (&optional regexp full-buffer)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5315 ;; Hides all unmarked files matching REGEXP.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5316 ;; If REGEXP is nil or not specified, uses `dired-omit-files-regexp',
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5317 ;; and also omits filenames ending in `dired-omit-extensions'.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5318 ;; If REGEXP is the empty string, this function is a no-op.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5319 (let ((omit-re (or regexp (dired-omit-regexp)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5320 (alist dired-subdir-alist)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5321 elt min)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5322 (if (null omit-re)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5323 0
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5324 (if full-buffer
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5325 (prog1
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5326 (dired-omit-region (point-min) (point-max) omit-re)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5327 ;; Set omit property in dired-subdir-alist
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5328 (while alist
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5329 (setq elt (car alist)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5330 min (dired-get-subdir-min elt)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5331 alist (cdr alist))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5332 (if (and (<= (point-min) min) (>= (point-max) min))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5333 (setcar (nthcdr 2 elt) t))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5334 (prog1
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5335 (dired-omit-region (dired-subdir-min) (dired-subdir-max) omit-re)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5336 (setcar
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5337 (nthcdr 2 (assoc (dired-current-directory)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5338 dired-subdir-alist))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5339 t))))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5340
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5341 (defun dired-omit-region (start end regexp)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5342 ;; Omits files matching regexp in region. Returns count.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5343 (save-restriction
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5344 (narrow-to-region start end)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5345 (let ((hidden-subdirs (dired-remember-hidden))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5346 buffer-read-only count)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5347 (or selective-display
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5348 (error "selective-display must be t for file omission to work!"))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5349 (dired-omit-unhide-region start end)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5350 (let ((dired-marker-char dired-omit-marker-char)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5351 ;; since all subdirs are now unhidden, this fakes
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5352 ;; dired-move-to-end-of-filename into working faster
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5353 (selective-display nil))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5354 (or dired-omit-silent
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5355 dired-in-query (message "Omitting..."))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5356 (if (dired-mark-unmarked-files regexp nil nil 'no-dir)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5357 (setq count (dired-do-hide
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5358 dired-marker-char
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5359 (and (memq dired-omit-silent '(nil 0))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5360 (not dired-in-query)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5361 "Omitted %d line%s.")))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5362 (or dired-omit-silent dired-in-query
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5363 (message "(Nothing to omit)"))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5364 (save-excursion ;hide subdirs that were hidden
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5365 (mapcar (function (lambda (dir)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5366 (if (dired-goto-subdir dir)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5367 (dired-hide-subdir 1))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5368 hidden-subdirs))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5369 count)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5370
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5371 (defun dired-omit-unhide-region (beg end)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5372 ;; Unhides hidden, but not marked files in the region.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5373 (save-excursion
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5374 (save-restriction
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5375 (narrow-to-region beg end)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5376 (goto-char (point-min))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5377 (while (search-forward "\r" nil t)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5378 (and (char-equal (following-char) ?\ )
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5379 (subst-char-in-region (1- (point)) (point) ?\r ?\n))))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5380
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5381 (defun dired-do-unhide (char &optional fmt marker)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5382 ;; Unhides files marked with CHAR. Optional FMT is a message
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5383 ;; to be displayed. Note that after unhiding, we will need to re-hide
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5384 ;; files belonging to hidden subdirs.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5385 (save-excursion
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5386 (goto-char (point-min))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5387 (let ((count 0)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5388 (string (concat "\r" (char-to-string char)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5389 (hidden-subdirs (dired-remember-hidden))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5390 (new (if marker (concat "\n" (char-to-string marker)) "\n "))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5391 buffer-read-only)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5392 (while (search-forward string nil t)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5393 (replace-match new)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5394 (setq count (1+ count)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5395 (or (equal "" fmt)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5396 (message (or fmt "Unhid %d line%s.") count (dired-plural-s count)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5397 (goto-char (point-min))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5398 (mapcar (function (lambda (dir)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5399 (if (dired-goto-subdir dir)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5400 (dired-hide-subdir 1 t))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5401 hidden-subdirs)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5402 (if marker (dired-update-mode-line-modified t))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5403 count)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5404
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5405 (defun dired-do-hide (char &optional fmt)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5406 ;; Hides files marked with CHAR. Otional FMT is a message
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5407 ;; to be displayed. FMT is a format string taking args the number
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5408 ;; of hidden file lines, and dired-plural-s.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5409 (save-excursion
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5410 (goto-char (point-min))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5411 (let ((count 0)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5412 (string (concat "\n" (char-to-string char)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5413 buffer-read-only)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5414 (while (search-forward string nil t)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5415 (subst-char-in-region (match-beginning 0)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5416 (1+ (match-beginning 0)) ?\n ?\r t)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5417 (setq count (1+ count)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5418 (if fmt
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5419 (message fmt count (dired-plural-s count)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5420 count)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5421
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5422 (defun dired-omit-regexp ()
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5423 (let (rgxp)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5424 (if dired-omit-extensions
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5425 (setq rgxp (concat
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5426 ".\\("
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5427 (mapconcat 'regexp-quote dired-omit-extensions "\\|")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5428 "\\)$")))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5429 (if dired-omit-regexps
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5430 (setq rgxp
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5431 (concat
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5432 rgxp
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5433 (and rgxp "\\|")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5434 (mapconcat 'identity dired-omit-regexps "\\|"))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5435 rgxp))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5436
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5437 (defun dired-mark-unmarked-files (regexp msg &optional unflag-p localp)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5438 ;; Marks unmarked files matching REGEXP, displaying MSG.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5439 ;; REGEXP is matched against the complete pathname, unless localp is
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5440 ;; specified.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5441 ;; Does not re-mark files which already have a mark.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5442 ;; Returns t if any work was done, nil otherwise.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5443 (let ((dired-marker-char (if unflag-p ?\ dired-marker-char))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5444 fn)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5445 (dired-mark-if
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5446 (and
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5447 ;; not already marked
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5448 (eq (following-char) ?\ )
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5449 ;; uninteresting
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5450 (setq fn (dired-get-filename localp t))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5451 (string-match regexp fn))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5452 msg)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5453
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5454 (defun dired-add-omit-regexp (rgxp &optional how)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5455 "Adds a new regular expression to the list of omit regular expresions.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5456 With a non-zero numeric prefix argument, deletes a regular expresion from
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5457 the list.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5458
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5459 With a prefix argument \\[universal-argument], adds a new extension to
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5460 the list of file name extensions omitted.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5461 With a prefix argument \\[universal-argument] \\[universal-argument], deletes
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5462 a file name extension from the list.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5463
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5464 With a prefix 0, reports on the current omit regular expressions and
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5465 extensions."
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5466 (interactive
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5467 (list
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5468 (cond
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5469 ((null current-prefix-arg)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5470 (read-string "New omit regular expression: "))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5471 ((equal '(4) current-prefix-arg)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5472 (read-string "New omit extension (\".\" is not implicit): "))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5473 ((equal '(16) current-prefix-arg)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5474 (completing-read
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5475 "Remove from omit extensions (type SPACE for options): "
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5476 (mapcar 'list dired-omit-extensions) nil t))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5477 ((eq 0 current-prefix-arg)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5478 nil)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5479 (t
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5480 (completing-read
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5481 "Remove from omit regexps (type SPACE for options): "
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5482 (mapcar 'list dired-omit-regexps) nil t)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5483 current-prefix-arg))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5484 (let (remove)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5485 (cond
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5486 ((null how)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5487 (if (member rgxp dired-omit-regexps)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5488 (progn
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5489 (describe-variable 'dired-omit-regexps)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5490 (error "%s is already included in the list." rgxp))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5491 (setq dired-omit-regexps (cons rgxp dired-omit-regexps))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5492 ((equal how '(4))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5493 (if (member rgxp dired-omit-extensions)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5494 (progn
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5495 (describe-variable 'dired-omit-extensions)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5496 (error "%s is already included in list." rgxp))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5497 (setq dired-omit-extensions (cons rgxp dired-omit-extensions))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5498 ((equal how '(16))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5499 (let ((tail (member rgxp dired-omit-extensions)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5500 (if tail
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5501 (setq dired-omit-extensions
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5502 (delq (car tail) dired-omit-extensions)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5503 remove t)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5504 (setq remove 'ignore))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5505 ((eq 0 how)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5506 (setq remove 'ignore)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5507 (if (featurep 'ehelp)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5508 (with-electric-help
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5509 (function
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5510 (lambda ()
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5511 (princ "Omit extensions (dired-omit-extensions <V>):\n")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5512 (dired-format-columns-of-files dired-omit-extensions)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5513 (princ "\n")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5514 (princ "Omit regular expressions (dired-omit-regexps <V>):\n")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5515 (dired-format-columns-of-files dired-omit-regexps)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5516 nil)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5517 (with-output-to-temp-buffer "*Help*"
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5518 (princ "Omit extensions (dired-omit-extensions <V>):\n")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5519 (dired-format-columns-of-files dired-omit-extensions)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5520 (princ "\n")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5521 (princ "Omit regular expressions (dired-omit-regexps <V>):\n")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5522 (dired-format-columns-of-files dired-omit-regexps)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5523 (print-help-return-message))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5524 (t
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5525 (let ((tail (member rgxp dired-omit-regexps)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5526 (if tail
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5527 (setq dired-omit-regexps (delq (car tail) dired-omit-regexps)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5528 remove t)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5529 (setq remove 'ignore)))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5530 (or (eq remove 'ignore)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5531 (save-excursion
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5532 (mapcar
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5533 (function
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5534 (lambda (dir)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5535 (if (dired-goto-subdir dir)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5536 (progn
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5537 (if remove
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5538 (save-restriction
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5539 (narrow-to-region
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5540 (dired-subdir-min) (dired-subdir-max))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5541 (dired-do-unhide dired-omit-marker-char "")))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5542 (dired-omit-expunge)))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5543 (dired-remember-omitted))))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5544
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5545
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5546
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5547 ;;;; ----------------------------------------------------------------
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5548 ;;;; Directory hiding.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5549 ;;;; ----------------------------------------------------------------
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5550 ;;;
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5551 ;;; To indicate a hidden subdir, we actually insert "..." in the buffer.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5552 ;;; Aside from giving the look of ellipses (even though
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5553 ;;; selective-display-ellipses is nil), it allows us to tell the difference
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5554 ;;; between a dir with a single omitted file, and a hidden subdir with one
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5555 ;;; file.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5556
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5557 (defun dired-subdir-hidden-p (dir)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5558 (save-excursion
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5559 (and selective-display
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5560 (dired-goto-subdir dir)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5561 (looking-at "\\.\\.\\.\r"))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5562
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5563 (defun dired-unhide-subdir ()
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5564 (let (buffer-read-only)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5565 (goto-char (dired-subdir-min))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5566 (skip-chars-forward "^\n\r")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5567 (skip-chars-backward "." (- (point) 3))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5568 (if (looking-at "\\.\\.\\.\r") (delete-char 4))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5569 (dired-omit-unhide-region (point) (dired-subdir-max))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5570
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5571 (defun dired-hide-check ()
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5572 (or selective-display
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5573 (error "selective-display must be t for subdir hiding to work!")))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5574
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5575 (defun dired-hide-subdir (arg &optional really)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5576 "Hide or unhide the current subdirectory and move to next directory.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5577 Optional prefix arg is a repeat factor.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5578 Use \\[dired-hide-all] to (un)hide all directories.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5579 With the optional argument REALLY, we always hide
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5580 the subdir, regardless of dired-subdir-hidden-p."
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5581 ;; The arg REALLY is needed because when we unhide
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5582 ;; omitted files in a hidden subdir, we want to
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5583 ;; re-hide the subdir, regardless of whether dired
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5584 ;; thinks it's already hidden.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5585 (interactive "p")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5586 (dired-hide-check)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5587 (dired-save-excursion
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5588 (while (>= (setq arg (1- arg)) 0)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5589 (let* ((cur-dir (dired-current-directory))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5590 (hidden-p (and (null really)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5591 (dired-subdir-hidden-p cur-dir)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5592 (elt (assoc cur-dir dired-subdir-alist))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5593 (end-pos (1- (dired-get-subdir-max elt)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5594 buffer-read-only)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5595 ;; keep header line visible, hide rest
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5596 (goto-char (dired-get-subdir-min elt))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5597 (skip-chars-forward "^\n\r")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5598 (skip-chars-backward "." (- (point) 3))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5599 (if hidden-p
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5600 (progn
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5601 (if (looking-at "\\.\\.\\.\r")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5602 (progn
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5603 (delete-char 3)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5604 (setq end-pos (- end-pos 3))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5605 (dired-omit-unhide-region (point) end-pos))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5606 (if (looking-at "\\.\\.\\.\r")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5607 (goto-char (match-end 0))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5608 (insert "...")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5609 (setq end-pos (+ end-pos 3)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5610 (subst-char-in-region (point) end-pos ?\n ?\r)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5611 (dired-next-subdir 1 t))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5612
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5613 (defun dired-hide-all (arg)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5614 "Hide all subdirectories, leaving only their header lines.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5615 If there is already something hidden, make everything visible again.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5616 Use \\[dired-hide-subdir] to (un)hide a particular subdirectory."
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5617 (interactive "P")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5618 (dired-hide-check)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5619 (let (buffer-read-only)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5620 (dired-save-excursion
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5621 (if (let ((alist dired-subdir-alist)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5622 (hidden nil))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5623 (while (and alist (null hidden))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5624 (setq hidden (dired-subdir-hidden-p (car (car alist)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5625 alist (cdr alist)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5626 hidden)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5627 ;; unhide
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5628 (let ((alist dired-subdir-alist))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5629 (while alist
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5630 (goto-char (dired-get-subdir-min (car alist)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5631 (skip-chars-forward "^\n\r")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5632 (delete-region (point) (progn (skip-chars-backward ".") (point)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5633 (setq alist (cdr alist)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5634 (dired-omit-unhide-region (point-min) (point-max)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5635 ;; hide
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5636 (let ((alist dired-subdir-alist))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5637 (while alist
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5638 (dired-goto-subdir (car (car alist)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5639 (dired-hide-subdir 1 t)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5640 (setq alist (cdr alist))))))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5641
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5642
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5643 ;;;; -----------------------------------------------------------------
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5644 ;;;; Automatic dired buffer maintenance.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5645 ;;;; -----------------------------------------------------------------
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5646 ;;;
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5647 ;;; Keeping Dired buffers in sync with the filesystem and with each
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5648 ;;; other.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5649 ;;; When used with efs on remote directories, buffer maintainence is
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5650 ;;; done asynch.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5651
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5652 (defun dired-buffers-for-dir (dir-or-list &optional check-wildcard)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5653 ;; Return a list of buffers that dired DIR-OR-LIST
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5654 ;; (top level or in-situ subdir).
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5655 ;; The list is in reverse order of buffer creation, most recent last.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5656 ;; As a side effect, killed dired buffers for DIR are removed from
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5657 ;; dired-buffers. If DIR-OR-LIST is a wildcard or list, returns any
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5658 ;; dired buffers for which DIR-OR-LIST is equal to `dired-directory'.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5659 ;; If check-wildcard is non-nil, only returns buffers which contain dir-or-list
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5660 ;; exactly, including the wildcard part.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5661 (let ((alist dired-buffers)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5662 (as-dir (and (stringp dir-or-list)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5663 (file-name-as-directory dir-or-list)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5664 result buff elt)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5665 (while alist
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5666 (setq buff (cdr (setq elt (car alist)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5667 alist (cdr alist))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5668 ;; dired-in-this-tree is not fast. It doesn't pay to use this to check
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5669 ;; whether the buffer is a good candidate.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5670 (if (buffer-name buff)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5671 (save-excursion
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5672 (set-buffer buff)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5673 (if (or (equal dir-or-list dired-directory) ; the wildcard case.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5674 (and as-dir
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5675 (not (and check-wildcard
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5676 (string-equal
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5677 as-dir
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5678 (expand-file-name default-directory))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5679 (assoc as-dir dired-subdir-alist)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5680 (setq result (cons buff result))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5681 ;; else buffer is killed - clean up:
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5682 (setq dired-buffers (delq elt dired-buffers))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5683 (or dired-buffers (dired-remove-from-file-name-handler-alist))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5684 result))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5685
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5686 (defun dired-advertise ()
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5687 ;; Advertise in variable `dired-buffers' that we dired `default-directory'.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5688 ;; With wildcards we actually advertise too much.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5689 ;; Also makes sure that we are installed in the file-name-handler-alist
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5690 (prog1
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5691 (let ((ddir (expand-file-name default-directory)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5692 (if (memq (current-buffer) (dired-buffers-for-dir ddir))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5693 t ; we have already advertised ourselves
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5694 (setq dired-buffers
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5695 (cons (cons ddir (current-buffer))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5696 dired-buffers))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5697 ;; Do this last, otherwise the call to dired-buffers-for-dir will
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5698 ;; remove dired-handler-fn from the file-name-handler-alist.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5699 ;; Strictly speaking, we only need to do this in th else branch of
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5700 ;; the if statement. We do it unconditionally as a sanity check.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5701 (dired-check-file-name-handler-alist)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5702
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5703 (defun dired-unadvertise (dir)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5704 ;; Remove DIR from the buffer alist in variable dired-buffers.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5705 ;; This has the effect of removing any buffer whose main directory is DIR.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5706 ;; It does not affect buffers in which DIR is a subdir.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5707 ;; Removing is also done as a side-effect in dired-buffer-for-dir.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5708 (setq dired-buffers
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5709 (delq (assoc dir dired-buffers) dired-buffers))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5710 ;; If there are no more dired buffers, we are no longer needed in the
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5711 ;; file-name-handler-alist.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5712 (or dired-buffers (dired-remove-from-file-name-handler-alist)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5713
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5714 (defun dired-unadvertise-current-buffer ()
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5715 ;; Remove all references to the current buffer in dired-buffers.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5716 (setq dired-buffers
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5717 (delq nil
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5718 (mapcar
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5719 (function
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5720 (lambda (x)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5721 (and (not (eq (current-buffer) (cdr x))) x)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5722 dired-buffers))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5723
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5724 (defun dired-fun-in-all-buffers (directory fun &rest args)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5725 ;; In all buffers dired'ing DIRECTORY, run FUN with ARGS.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5726 ;; Return list of buffers where FUN succeeded (i.e., returned non-nil).
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5727 (let* ((buf-list (dired-buffers-for-dir directory))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5728 (obuf (current-buffer))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5729 (owin (selected-window))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5730 (win owin)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5731 buf windows success-list)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5732 (if buf-list
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5733 (unwind-protect
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5734 (progn
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5735 (while (not (eq (setq win (next-window win)) owin))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5736 (and (memq (setq buf (window-buffer win)) buf-list)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5737 (progn
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5738 (set-buffer buf)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5739 (= (point) (window-point win)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5740 (setq windows (cons win windows))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5741 (while buf-list
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5742 (setq buf (car buf-list)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5743 buf-list (cdr buf-list))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5744 (set-buffer buf)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5745 (if (apply fun args)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5746 (setq success-list (cons (buffer-name buf) success-list))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5747 ;; dired-save-excursion prevents lossage of save-excursion
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5748 ;; for point. However, if dired buffers are displayed in
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5749 ;; other windows, the setting of window-point loses, and
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5750 ;; drags the point with it. This should fix this.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5751 (while windows
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5752 (condition-case nil
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5753 (progn
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5754 (set-buffer (window-buffer (setq win (car windows))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5755 (set-window-point win (point)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5756 (error nil))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5757 (setq windows (cdr windows))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5758 (set-buffer obuf)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5759 success-list))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5760
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5761 (defun dired-find-file-place (subdir file)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5762 ;; Finds a position to insert in SUBDIR FILE. If it can't find SUBDIR,
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5763 ;; returns nil.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5764 (let ((sort (dired-sort-type dired-internal-switches))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5765 (rev (memq ?r (nth 3 (assoc subdir dired-subdir-alist)))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5766 (cond
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5767 ((eq sort 'name)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5768 (if (dired-goto-subdir subdir)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5769 (let ((max (dired-subdir-max))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5770 start end found)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5771 (if (dired-goto-next-file)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5772 (progn
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5773 (skip-chars-forward "^\n\r")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5774 (setq start (point))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5775 (goto-char (setq end max))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5776 (forward-char -1)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5777 (skip-chars-backward "^\n\r")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5778 ;; This loop must find a file. At the very least, it will
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5779 ;; find the one found previously.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5780 (while (not found)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5781 (if (save-excursion (dired-move-to-filename nil (point)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5782 (setq found t)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5783 (setq end (point))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5784 (forward-char -1)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5785 (skip-chars-backward "^\n\r")))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5786 (if rev
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5787 (while (< start end)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5788 (goto-char (/ (+ start end) 2))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5789 (if (dired-file-name-lessp
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5790 (or (dired-get-filename 'no-dir t)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5791 (error
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5792 "Error in dired-find-file-place"))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5793 file)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5794 (setq end (progn
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5795 (skip-chars-backward "^\n\r")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5796 (point)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5797 (setq start (progn
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5798 (skip-chars-forward "^\n\r")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5799 (forward-char 1)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5800 (skip-chars-forward "^\n\r")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5801 (point)))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5802 (while (< start end)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5803 (goto-char (/ (+ start end) 2))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5804 (if (dired-file-name-lessp
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5805 file
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5806 (or (dired-get-filename 'no-dir t)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5807 (error
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5808 "Error in dired-find-file-place")))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5809 (setq end (progn
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5810 (skip-chars-backward "^\n\r")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5811 (point)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5812 (setq start (progn
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5813 (skip-chars-forward "^\n\r")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5814 (forward-char 1)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5815 (skip-chars-forward "^\n\r")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5816 (point))))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5817 (goto-char end))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5818 (goto-char max))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5819 t)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5820 ((eq sort 'date)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5821 (if (dired-goto-subdir subdir)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5822 (if rev
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5823 (goto-char (dired-subdir-max))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5824 (dired-goto-next-file)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5825 t)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5826 ;; Put in support for other sorting types.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5827 (t
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5828 (if (string-equal (dired-current-directory) subdir)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5829 (progn
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5830 ;; We are already where we should be, except when
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5831 ;; point is before the subdir line or its total line.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5832 (or (save-excursion (beginning-of-line) (dired-move-to-filename))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5833 (dired-goto-next-nontrivial-file)) ; in the header somewhere
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5834 t) ; return t, for found.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5835 (if (dired-goto-subdir subdir)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5836 (progn
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5837 (dired-goto-next-nontrivial-file)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5838 t)))))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5839
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5840 (defun dired-add-entry (filename &optional marker-char inplace)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5841 ;; Add a new entry for FILENAME, optionally marking it
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5842 ;; with MARKER-CHAR (a character, else dired-marker-char is used).
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5843 ;; Hidden subdirs are exposed if a file is added there.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5844 ;;
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5845 ;; This function now adds the new entry at the END of the previous line,
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5846 ;; not the beginning of the current line.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5847 ;; Logically, we now think of the `newline' associated
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5848 ;; with a fileline, as the one at the beginning of the line, not the end.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5849 ;; This makes it easier to keep track of omitted files.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5850 ;;
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5851 ;; Uses dired-save-excursion, so that it doesn't move the
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5852 ;; point around. Especially important when it runs asynch.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5853 ;;
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5854 ;; If there is already an entry, delete the existing one before adding a
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5855 ;; new one. In this case, doesn't remember its mark. Use
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5856 ;; dired-update-file-line for that.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5857 ;;
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5858 ;; If INPLACE eq 'relist, then the new entry is put in the
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5859 ;; same place as the old, if there was an old entry.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5860 ;; If INPLACE is t, then the file entry is put on the line
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5861 ;; currently containing the point. Otherwise, dired-find-file-place
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5862 ;; attempts to determine where to put the file.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5863
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5864 (setq filename (directory-file-name filename))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5865 (dired-save-excursion
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5866 (let ((oentry (save-excursion (dired-goto-file filename)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5867 (directory (file-name-directory filename))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5868 (file-nodir (file-name-nondirectory filename))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5869 buffer-read-only)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5870 (if oentry
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5871 ;; Remove old entry
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5872 (let ((opoint (point)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5873 (goto-char oentry)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5874 (delete-region (save-excursion
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5875 (skip-chars-backward "^\r\n")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5876 (dired-update-marker-counters (following-char) t)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5877 (1- (point)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5878 (progn
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5879 (skip-chars-forward "^\r\n")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5880 (point)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5881 ;; Move to right place to replace deleted line.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5882 (cond ((eq inplace 'relist) (forward-char 1))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5883 ((eq inplace t) (goto-char opoint)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5884 (dired-update-mode-line-modified)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5885 (if (or (eq inplace t)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5886 (and oentry (eq inplace 'relist))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5887 ;; Tries to move the point to the right place.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5888 ;; Returns t on success.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5889 (dired-find-file-place directory file-nodir))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5890 (let ((switches (dired-make-switches-string
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5891 (cons ?d dired-internal-switches)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5892 b-of-l)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5893 ;; Bind marker-char now, in case we are working asynch and
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5894 ;; dired-marker-char changes in the meantime.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5895 (if (and marker-char (not (integerp marker-char)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5896 (setq marker-char dired-marker-char))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5897 ;; since we insert at the end of a line,
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5898 ;; backup to the end of the previous line.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5899 (skip-chars-backward "^\n\r")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5900 (forward-char -1)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5901 (setq b-of-l (point))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5902 (if (and (featurep 'efs-dired) efs-dired-host-type)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5903 ;; insert asynch
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5904 ;; we call the efs version explicitly here,
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5905 ;; rather than let the handler-alist work for us
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5906 ;; because we want to pass extra args.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5907 ;; Is there a cleaner way to do this?
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5908 (efs-insert-directory filename ; don't expand `.' !
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5909 switches nil nil
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5910 t ; nowait
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5911 marker-char)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5912 (let ((insert-directory-program dired-ls-program))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5913 (insert-directory filename switches nil nil))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5914 (dired-after-add-entry b-of-l marker-char))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5915 (if dired-verify-modtimes
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5916 (dired-set-file-modtime directory dired-subdir-alist))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5917 t))))) ; return t on success, else nil.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5918
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5919 (defun dired-after-add-entry (start marker-char)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5920 ;; Does the cleanup of a dired entry after listing it.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5921 ;; START is the start of the new listing-line.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5922 ;; This is a separate function for the sake of efs.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5923 (save-excursion
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5924 (goto-char start)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5925 ;; we make sure that the new line is bracketted by new-lines
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5926 ;; so the user doesn't need to use voodoo in the
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5927 ;; after-readin-hook.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5928 (insert ?\n)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5929 (dired-add-entry-do-indentation marker-char)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5930 (let* ((beg (dired-manual-move-to-filename t))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5931 ;; error for strange output
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5932 (end (dired-manual-move-to-end-of-filename))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5933 (filename (buffer-substring beg end)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5934 ;; We want to have the non-directory part only.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5935 (delete-region beg end)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5936 ;; Any markers pointing to the beginning of the filename, will
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5937 ;; still point there after this insertion. Should keep
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5938 ;; save-excursion from losing.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5939 (setq beg (point))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5940 (insert (file-name-nondirectory filename))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5941 (dired-insert-set-properties beg (point))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5942 (dired-move-to-filename))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5943 ;; The subdir-alist is not affected so we can run it right now.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5944 (let ((omit (dired-current-subdir-omitted-p))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5945 (hide (dired-subdir-hidden-p (dired-current-directory))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5946 (if (or dired-after-readin-hook omit hide)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5947 (save-excursion
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5948 (save-restriction
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5949 ;; Use start so that we get the new-line at
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5950 ;; the beginning of the line in case we want
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5951 ;; to hide the file. Don't need to test (bobp)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5952 ;; here, since we never add a file at
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5953 ;; the beginning of the buffer.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5954 (narrow-to-region start
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5955 (save-excursion (forward-line 1) (point)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5956 (run-hooks 'dired-after-readin-hook)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5957 (if omit
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5958 (let ((dired-omit-silent (or dired-omit-silent 0)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5959 (dired-omit-region (point-min) (point-max)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5960 (dired-omit-regexp))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5961 (if hide
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5962 (subst-char-in-region (point-min) (1- (point-max))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5963 ?\n ?\r))))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5964 ;; clobber the extra newline at the end of the line
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5965 (end-of-line)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5966 (delete-char 1)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5967
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5968 ;; This is a separate function for the sake of nested dired format.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5969 (defun dired-add-entry-do-indentation (marker-char)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5970 ;; two spaces or a marker plus a space:
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5971 (insert (if marker-char
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5972 (let ((char (if (integerp marker-char)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5973 marker-char
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5974 dired-marker-char)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5975 (dired-update-marker-counters char)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5976 (dired-update-mode-line-modified)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5977 char)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5978 ?\040)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5979 ?\040))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5980
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5981 (defun dired-remove-file (file)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5982 (let ((alist dired-buffers)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5983 buff)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5984 (save-excursion
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5985 (while alist
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5986 (setq buff (cdr (car alist)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5987 (if (buffer-name buff)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5988 (progn
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5989 (set-buffer buff)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5990 (dired-remove-entry file))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5991 (setq dired-buffers (delq (car alist) dired-buffers)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5992 (setq alist (cdr alist))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5993 (or dired-buffers (dired-remove-from-file-name-handler-alist))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5994
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5995 (defun dired-remove-entry (file)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5996 (let ((ddir (expand-file-name default-directory))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5997 (dirname (file-name-as-directory file)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5998 (if (dired-in-this-tree ddir dirname)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5999 (if (or (memq 'kill-dired-buffer dired-no-confirm)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6000 (y-or-n-p (format "Kill dired buffer %s for %s, too? "
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6001 (buffer-name) dired-directory)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6002 (kill-buffer (current-buffer)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6003 (if (dired-in-this-tree file ddir)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6004 (let ((alist dired-subdir-alist))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6005 (while alist
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6006 (if (dired-in-this-tree (car (car alist)) dirname)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6007 (save-excursion
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6008 (goto-char (dired-get-subdir-min (car alist)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6009 (dired-kill-subdir)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6010 (setq alist (cdr alist)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6011 (dired-save-excursion
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6012 (and (dired-goto-file file)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6013 (let (buffer-read-only)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6014 (delete-region
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6015 (progn (skip-chars-backward "^\n\r")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6016 (or (memq (following-char) '(\n \r ?\ ))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6017 (progn
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6018 (dired-update-marker-counters
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6019 (following-char) t)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6020 (dired-update-mode-line-modified)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6021 (1- (point)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6022 (progn (skip-chars-forward "^\n\r") (point)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6023 (if dired-verify-modtimes
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6024 (dired-set-file-modtime
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6025 (file-name-directory (directory-file-name file))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6026 dired-subdir-alist))))))))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6027
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6028 (defun dired-add-file (filename &optional marker-char)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6029 (dired-fun-in-all-buffers
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6030 (file-name-directory filename)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6031 (function dired-add-entry) filename marker-char))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6032
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6033 (defun dired-relist-file (file)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6034 (dired-uncache file nil)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6035 (dired-fun-in-all-buffers (file-name-directory file)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6036 (function dired-relist-entry) file))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6037
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6038 (defun dired-relist-entry (file)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6039 ;; Relist the line for FILE, or just add it if it did not exist.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6040 ;; FILE must be an absolute pathname.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6041 (let* ((file (directory-file-name file))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6042 (directory (file-name-directory file))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6043 (dd (expand-file-name default-directory)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6044 (if (assoc directory dired-subdir-alist)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6045 (if (or
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6046 ;; Not a wildcard
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6047 (equal dd dired-directory)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6048 ;; Not top-level
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6049 (not (string-equal directory dd))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6050 (and (string-equal directory
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6051 (if (consp dired-directory)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6052 (file-name-as-directory
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6053 (car dired-directory))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6054 (file-name-directory dired-directory)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6055 (dired-file-in-wildcard-p dired-directory file)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6056 (let ((marker (save-excursion
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6057 (and (dired-goto-file file)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6058 (dired-file-marker file)))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6059 ;; recompute omission
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6060 (if (eq marker dired-omit-marker-char)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6061 (setq marker nil))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6062 (dired-add-entry file marker 'relist))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6063 ;; At least tell dired that we considered updating the buffer.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6064 (if dired-verify-modtimes
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6065 (dired-set-file-modtime directory dired-subdir-alist))))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6066
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6067 (defun dired-file-in-wildcard-p (wildcard file)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6068 ;; Return t if a file is part of the listing for wildcard.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6069 ;; File should be the non-directory part only.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6070 ;; This version is slow, but meticulously correct. Is it worth it?
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6071 (if (consp wildcard)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6072 (let ((files (cdr wildcard))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6073 (dir (car wildcard))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6074 yep)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6075 (while (and files (not yep))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6076 (setq yep (string-equal file (expand-file-name (car files) dir))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6077 files (cdr files)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6078 yep)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6079 (let ((err-buff
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6080 (let ((default-major-mode 'fundamental-mode))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6081 (get-buffer-create " *dired-check-process output*")))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6082 (dir default-directory)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6083 (process-connection-type nil))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6084 (save-excursion
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6085 (set-buffer err-buff)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6086 (erase-buffer)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6087 (setq default-directory dir)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6088 (call-process shell-file-name nil t nil "-c"
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6089 (concat dired-ls-program " -d " wildcard " | "
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6090 "egrep '(^|/)" file "$'"))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6091 (/= (buffer-size) 0)))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6092
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6093 ;; The difference between dired-add-file and dired-relist-file is that
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6094 ;; the former creates the entry with a specific marker. The later preserves
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6095 ;; existing markers on a per buffer basis. This is not the same as
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6096 ;; giving dired-create-files a marker of t, which uses a marker in a specific
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6097 ;; buffer to determine the marker for file line creation in all buffers.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6098
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6099
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6100 ;;;; ----------------------------------------------------------------
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6101 ;;;; Applying Lisp functions to marked files.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6102 ;;;; ----------------------------------------------------------------
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6103
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6104 ;;; Running tags commands on marked files.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6105 ;;
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6106 ;; Written 8/30/93 by Roland McGrath <roland@gnu.ai.mit.edu>.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6107 ;; Requires tags.el as distributed with GNU Emacs 19.23, or later.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6108
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6109 (defun dired-do-tags-search (regexp)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6110 "Search through all marked files for a match for REGEXP.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6111 Stops when a match is found.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6112 To continue searching for next match, use command \\[tags-loop-continue]."
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6113 (interactive "sSearch marked files (regexp): ")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6114 (tags-search regexp '(dired-get-marked-files)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6115
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6116 (defun dired-do-tags-query-replace (from to &optional delimited)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6117 "Query-replace-regexp FROM with TO through all marked files.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6118 Third arg DELIMITED (prefix arg) means replace only word-delimited matches.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6119 If you exit (\\[keyboard-quit] or ESC), you can resume the query-replace
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6120 with the command \\[tags-loop-continue]."
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6121 (interactive
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6122 "sQuery replace in marked files (regexp): \nsQuery replace %s by: \nP")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6123 (tags-query-replace from to delimited '(dired-get-marked-files)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6124
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6125 ;;; byte compiling
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6126
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6127 (defun dired-byte-compile ()
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6128 ;; Return nil for success, offending file name else.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6129 (let* ((filename (dired-get-filename))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6130 buffer-read-only failure)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6131 (condition-case err
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6132 (save-excursion (byte-compile-file filename))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6133 (error
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6134 (setq failure err)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6135 ;; We should not need to update any file lines, as this will have
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6136 ;; already been done by after-write-region-hook.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6137 (and failure
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6138 (progn
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6139 (dired-log (buffer-name (current-buffer))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6140 "Byte compile error for %s:\n%s\n" filename failure)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6141 (dired-make-relative filename)))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6142
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6143 (defun dired-do-byte-compile (&optional arg)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6144 "Byte compile marked (or next ARG) Emacs lisp files."
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6145 (interactive "P")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6146 (dired-map-over-marks-check (function dired-byte-compile) arg
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6147 'byte-compile "byte-compile" t))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6148
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6149 ;;; loading
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6150
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6151 (defun dired-load ()
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6152 ;; Return nil for success, offending file name else.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6153 (let ((file (dired-get-filename)) failure)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6154 (condition-case err
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6155 (load file nil nil t)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6156 (error (setq failure err)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6157 (if (not failure)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6158 nil
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6159 (dired-log (buffer-name (current-buffer))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6160 "Load error for %s:\n%s\n" file failure)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6161 (dired-make-relative file))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6162
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6163 (defun dired-do-load (&optional arg)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6164 "Load the marked (or next ARG) Emacs lisp files."
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6165 (interactive "P")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6166 (dired-map-over-marks-check (function dired-load) arg 'load "load" t))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6167
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6168
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6169 ;;;; ----------------------------------------------------------------
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6170 ;;;; File Name Handler Alist
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6171 ;;;; ----------------------------------------------------------------
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6172 ;;;
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6173 ;;; Make sure that I/O functions maintain dired buffers.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6174
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6175 (defun dired-remove-from-file-name-handler-alist ()
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6176 ;; Remove dired from the file-name-handler-alist
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6177 (setq file-name-handler-alist
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6178 (delq nil
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6179 (mapcar
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6180 (function
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6181 (lambda (x)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6182 (and (not (eq (cdr x) 'dired-handler-fn))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6183 x)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6184 file-name-handler-alist))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6185
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6186 (defun dired-check-file-name-handler-alist ()
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6187 ;; Verify that dired is installed as the first item in the alist
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6188 (or (eq (cdr (car file-name-handler-alist)) 'dired-handler-fn)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6189 (setq file-name-handler-alist
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6190 (cons
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6191 '("." . dired-handler-fn)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6192 (dired-remove-from-file-name-handler-alist)))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6193
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6194 (defun dired-handler-fn (op &rest args)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6195 ;; Function to update dired buffers after I/O.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6196 (prog1
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6197 (let ((inhibit-file-name-handlers
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6198 (cons 'dired-handler-fn
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6199 (and (eq inhibit-file-name-operation op)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6200 inhibit-file-name-handlers)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6201 (inhibit-file-name-operation op))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6202 (apply op args))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6203 (let ((dired-omit-silent t)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6204 (hf (get op 'dired)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6205 (and hf (funcall hf args)))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6206
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6207 (defun dired-handler-fn-1 (args)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6208 (let ((to (expand-file-name (nth 1 args))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6209 (or (member to dired-unhandle-add-files)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6210 (dired-relist-file to))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6211
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6212 (defun dired-handler-fn-2 (args)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6213 (let ((from (expand-file-name (car args)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6214 (to (expand-file-name (nth 1 args))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6215 ;; Don't remove the original entry if making backups.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6216 ;; Otherwise we lose marks. I'm not completely happy with the
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6217 ;; logic here.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6218 (or (and
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6219 (eq (nth 2 args) t) ; backups always have OK-IF-OVERWRITE t
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6220 (string-equal (car (find-backup-file-name from)) to))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6221 (dired-remove-file from))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6222 (or (member to dired-unhandle-add-files)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6223 (dired-relist-file to))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6224
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6225 (defun dired-handler-fn-3 (args)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6226 (let ((to (expand-file-name (nth 2 args))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6227 (or (member to dired-unhandle-add-files)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6228 (dired-relist-file to))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6229
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6230 (defun dired-handler-fn-4 (args)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6231 (dired-remove-file (expand-file-name (car args))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6232
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6233 (defun dired-handler-fn-5 (args)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6234 (let ((to (expand-file-name (car args))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6235 (or (member to dired-unhandle-add-files)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6236 (dired-relist-file to))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6237
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6238 (defun dired-handler-fn-6 (args)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6239 (let ((to (expand-file-name (nth 1 args)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6240 (old (expand-file-name (car args))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6241 (or (member to dired-unhandle-add-files)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6242 (dired-relist-file to))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6243 (dired-relist-file old)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6244
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6245 (put 'copy-file 'dired 'dired-handler-fn-1)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6246 (put 'dired-make-relative-symlink 'dired 'dired-handler-fn-1)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6247 (put 'make-symbolic-link 'dired 'dired-handler-fn-1)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6248 (put 'add-name-to-file 'dired 'dired-handler-fn-6)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6249 (put 'rename-file 'dired 'dired-handler-fn-2)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6250 (put 'write-region 'dired 'dired-handler-fn-3)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6251 (put 'delete-file 'dired 'dired-handler-fn-4)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6252 (put 'delete-directory 'dired 'dired-handler-fn-4)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6253 (put 'dired-recursive-delete-directory 'dired 'dired-handler-fn-4)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6254 (put 'make-directory-internal 'dired 'dired-handler-fn-5)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6255 (put 'set-file-modes 'dired 'dired-handler-fn-5)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6256
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6257 ;;;; ------------------------------------------------------------
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6258 ;;;; Autoload land.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6259 ;;;; ------------------------------------------------------------
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6260
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6261 ;;; Reading mail (dired-xy)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6262
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6263 (autoload 'dired-read-mail "dired-xy"
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6264 "Reads the current file as a mail folder." t)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6265 (autoload 'dired-vm "dired-xy" "Run VM on this file." t)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6266 (autoload 'dired-rmail "dired-xy" "Run RMAIL on this file." t)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6267
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6268 ;;; Virtual dired (dired-vir)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6269
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6270 (autoload 'dired-virtual "dired-vir"
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6271 "Put this buffer into virtual dired mode." t)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6272
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6273 ;;; Grep (dired-grep)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6274
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6275 (autoload 'dired-do-grep "dired-grep" "Grep marked files for a pattern." t)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6276
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6277 ;;; Doing diffs (dired-diff)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6278
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6279 (autoload 'dired-diff "dired-diff"
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6280 "Compare file at point with FILE using `diff'." t)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6281 (autoload 'dired-backup-diff "dired-diff"
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6282 "Diff this file with its backup file or vice versa." t)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6283 (autoload 'dired-emerge "dired-diff"
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6284 "Merge file at point with FILE using `emerge'." t)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6285 (autoload 'dired-emerge-with-ancestor "dired-diff"
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6286 "Merge file at point with FILE, using a common ANCESTOR file." t)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6287 (autoload 'dired-ediff "dired-diff" "Ediff file at point with FILE." t)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6288 (autoload 'dired-epatch "dired-diff" "Patch file at point using `epatch'." t)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6289
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6290 ;;; Shell commands (dired-shell)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6291
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6292 (autoload 'dired-do-print "dired-shell" "Print the marked (next ARG) files." t)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6293 (autoload 'dired-run-shell-command "dired-shell" nil)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6294 (autoload 'dired-do-shell-command "dired-shell"
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6295 "Run a shell command on the marked (or next ARG) files." t)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6296 (autoload 'dired-do-background-shell-command "dired-shell"
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6297 "Run a background shell command on marked (or next ARG) files." t)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6298
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6299 ;;; Commands using regular expressions (dired-rgxp)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6300
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6301 (autoload 'dired-mark-files-regexp "dired-rgxp"
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6302 "Mark all files whose names match REGEXP." t)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6303 (autoload 'dired-flag-files-regexp "dired-rgxp"
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6304 "Flag for deletion all files whose names match REGEXP." t)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6305 (autoload 'dired-mark-extension "dired-rgxp"
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6306 "Mark all files whose names have a given extension." t)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6307 (autoload 'dired-flag-extension "dired-rgxp"
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6308 "Flag for deletion all files whose names have a given extension." t)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6309 (autoload 'dired-cleanup "dired-rgxp"
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6310 "Flag for deletion dispensable files files created by PROGRAM." t)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6311 (autoload 'dired-do-rename-regexp "dired-rgxp"
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6312 "Rename marked files whose names match a given regexp." t)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6313 (autoload 'dired-do-copy-regexp "dired-rgxp"
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6314 "Copy marked files whose names match a given regexp." t)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6315 (autoload 'dired-do-hardlink-regexp "dired-rgxp"
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6316 "Hardlink all marked files whose names match a regexp." t)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6317 (autoload 'dired-do-symlink "dired-rgxp"
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6318 "Make a symbolic link to all files whose names match a regexp." t)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6319 (autoload
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6320 'dired-do-relsymlink-regexp "dired-rgxp"
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6321 "Make a relative symbolic link to all files whose names match a regexp." t)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6322 (autoload 'dired-upcase "dired-rgxp"
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6323 "Rename all marked (or next ARG) files to upper case." t)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6324 (autoload 'dired-downcase "dired-rgxp"
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6325 "Rename all marked (or next ARG) files to lower case." t)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6326
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6327 ;;; Marking files from other buffers (dired-mob)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6328
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6329 (autoload 'dired-mark-files-from-other-dired-buffer "dired-mob"
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6330 "Mark files which are marked in another dired buffer." t)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6331 (autoload 'dired-mark-files-compilation-buffer "dired-mob"
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6332 "Mark the files mentioned in the compilation buffer." t)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6333
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6334 ;;; uuencoding (dired-uu)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6335
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6336 (autoload 'dired-do-uucode "dired-uu" "Uuencode or uudecode marked files." t)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6337
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6338 ;;; Compressing (dired-cmpr)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6339
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6340 (autoload 'dired-do-compress "dired-cmpr"
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6341 "Compress or uncompress marked files." t)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6342 (autoload 'dired-compress-subdir-files "dired-cmpr"
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6343 "Compress uncompressed files in the current subdirectory." t)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6344
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6345
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6346 ;;; Marking files according to sexps
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6347
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6348 (autoload 'dired-mark-sexp "dired-sex"
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6349 "Mark files according to an sexpression." t)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6350
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6351 ;;; Help!
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6352
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6353 (autoload 'dired-summary "dired-help"
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6354 "Display summary of basic dired commands in the minibuffer." t)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6355 (autoload 'dired-describe-mode "dired-help"
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6356 "Detailed description of dired mode.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6357 With a prefix, runs the info documentation browser for dired." t)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6358 (autoload 'dired-apropos "dired-help"
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6359 "Do command apropos help for dired commands.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6360 With prefix does apropos help for dired variables." t)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6361 (autoload 'dired-report-bug "dired-help" "Report a bug for dired." t)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6362
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6363 ;;;; --------------------------------------------------------------
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6364 ;;;; Multi-flavour Emacs support
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6365 ;;;; --------------------------------------------------------------
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6366
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6367 (let ((lucid-p (string-match "Lucid" emacs-version))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6368 ver)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6369 (or (string-match "^\\([0-9]+\\)\\." emacs-version)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6370 (error "Weird emacs version %s" emacs-version))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6371 (setq ver (string-to-int (substring emacs-version (match-beginning 1)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6372 (match-end 1))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6373
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6374 ;; Reading with history.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6375 (if (>= ver 19)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6376
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6377 (defun dired-read-with-history (prompt initial history)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6378 (read-from-minibuffer prompt initial nil nil history))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6379
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6380 (defun dired-read-with-history (prompt initial history)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6381 (let ((minibuffer-history-symbol history)) ; for gmhist
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6382 (read-string prompt initial))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6383
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6384 ;; Completing read with history.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6385 (if (>= ver 19)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6386
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6387 (fset 'dired-completing-read 'completing-read)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6388
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6389 (defun dired-completing-read (prompt table &optional predicate
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6390 require-match initial-input history)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6391 (let ((minibuffer-history-symbol history)) ; for gmhist
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6392 (completing-read prompt table predicate require-match
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6393 initial-input))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6394
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6395 ;; Abbreviating file names.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6396 (if lucid-p
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6397 (fset 'dired-abbreviate-file-name
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6398 ;; Lemacs has this extra hack-homedir arg
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6399 (function
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6400 (lambda (fn)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6401 (abbreviate-file-name fn t))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6402 (fset 'dired-abbreviate-file-name 'abbreviate-file-name))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6403
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6404 ;; Deleting directories
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6405 ;; Check for pre 19.8 versions of lucid emacs.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6406 (if lucid-p
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6407 (or (fboundp 'delete-directory)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6408 (fset 'delete-directory 'remove-directory)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6409
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6410 ;; Minibuffers
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6411 (if (= ver 18)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6412
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6413 (defun dired-get-active-minibuffer-window ()
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6414 (and (> (minibuffer-depth) 0)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6415 (minibuffer-window)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6416
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6417 (defun dired-get-active-minibuffer-window ()
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6418 (let ((frames (frame-list))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6419 win found)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6420 (while frames
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6421 (if (and (setq win (minibuffer-window (car frames)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6422 (minibuffer-window-active-p win))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6423 (setq found win
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6424 frames nil)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6425 (setq frames (cdr frames))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6426 found)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6427
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6428 ;; Text properties and menus.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6429
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6430 (cond
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6431 (lucid-p
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6432 (require 'dired-xemacs))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6433 ((>= ver 19)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6434 (require 'dired-fsf))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6435 (t
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6436 ;; text property stuff doesn't work in V18
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6437 (fset 'dired-insert-set-properties 'ignore)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6438 (fset 'dired-remove-text-properties 'ignore)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6439 (fset 'dired-set-text-properties 'ignore)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6440 (fset 'dired-move-to-filename 'dired-manual-move-to-filename)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6441 (fset 'dired-move-to-end-of-filename
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6442 'dired-manual-move-to-end-of-filename))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6443
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6444 ;;; MULE
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6445
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6446 (if (or (boundp 'MULE) (featurep 'mule)) (load "dired-mule"))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6447
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6448
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6449 ;; Run load hook for user customization.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6450 (run-hooks 'dired-load-hook)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6451
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6452 ;;; end of dired.el