annotate lisp/efs/dired.el @ 142:1856695b1fa9 r20-2b5

Import from CVS: tag r20-2b5
author cvs
date Mon, 13 Aug 2007 09:33:18 +0200
parents 6608ceec7cf8
children 43dd3413c7c7
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1 ; -*- Emacs-Lisp -*-
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2 ;; DIRED commands for Emacs.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3 ;; Copyright (C) 1985, 1986, 1991 Free Software Foundation, Inc.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5 ;;
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6 ;; File: dired.el
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
7 ;; RCS:
116
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 114
diff changeset
8 ;; Dired Version: #Revision: 7.9 $
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
9 ;; Description: The DIRectory EDitor is for manipulating, and running
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
10 ;; commands on files in a directory.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
11 ;; Authors: FSF,
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
12 ;; Sebastian Kremer <sk@thp.uni-koeln.de>,
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
13 ;; Sandy Rutherford <sandy@ibm550.sissa.it>
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
14 ;; Cast of thousands...
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
15 ;;
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
16 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
17
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
18 ;; This program is free software; you can redistribute it and/or modify
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
19 ;; it under the terms of the GNU General Public License as published by
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
20 ;; the Free Software Foundation; either version 1, or (at your option)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
21 ;; any later version.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
22
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
23 ;; This program is distributed in the hope that it will be useful,
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
24 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
25 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
26 ;; GNU General Public License for more details.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
27
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
28 ;; You should have received a copy of the GNU General Public License
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
29 ;; along with GNU Emacs; see the file COPYING. If not, write to
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
30 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
31
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
32 ;; Rewritten in 1990/1991 to add tree features, file marking and
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
33 ;; sorting by Sebastian Kremer <sk@thp.uni-koeln.de>.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
34 ;; 7-1993: Added special features for efs interaction and upgraded to Emacs 19.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
35 ;; Sandy Rutherford <sandy@ibm550.sissa.it>
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
36
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
37 ;;; Dired Version
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
38
116
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 114
diff changeset
39 (defconst dired-version (substring "#Revision: 7.9 $" 11 -2)
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
40 "The revision number of Tree Dired (as a string).
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
41
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
42 Don't forget to mention this when reporting bugs to:
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
43
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
44 efs-bugs@cuckoo.hpl.hp.com")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
45
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
46 ;; Global key bindings:
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
47 ;; --------------------
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
48 ;;
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
49 ;; By convention, dired uses the following global key-bindings.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
50 ;; These may or may not already be set up in your local emacs. If not
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
51 ;; then you will need to add them to your .emacs file, or the system
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
52 ;; default.el file. We don't set them automatically here, as users may
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
53 ;; have individual preferences.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
54 ;;
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
55 ;; (define-key ctl-x-map "d" 'dired)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
56 ;; (define-key ctl-x-4-map "d" 'dired-other-window)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
57 ;; (define-key ctl-x-map "\C-j" 'dired-jump-back)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
58 ;; (define-key ctl-x-4-map "\C-j" 'dired-jump-back-other-window)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
59 ;;
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
60 ;; For V19 emacs only. (Make sure that the ctl-x-5-map exists.)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
61 ;; (define-key ctl-x-5-map "d" 'dired-other-frame)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
62 ;; (define-key Ctl-x-5-map "\C-j" 'dired-jump-back-other-frame)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
63
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
64
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
65 ;;; Grok the current emacs version
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
66 ;;
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
67 ;; Hopefully these two variables provide us with enough version sensitivity.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
68
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
69 ;; Make sure that we have a frame-width function
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
70 (or (fboundp 'frame-width) (fset 'frame-width 'screen-width))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
71
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
72 ;;; Requirements and provisions
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
73
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
74 (provide 'dired)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
75 (require 'backquote) ; For macros.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
76
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
77 ;; Compatibility requirements for the file-name-handler-alist.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
78 (let ((lucid-p (string-match "Lucid" emacs-version))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
79 ver subver)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
80 (or (string-match "^\\([0-9]+\\)\\.\\([0-9]+\\)" emacs-version)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
81 (error "dired does not work with emacs version %s" emacs-version))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
82 (setq ver (string-to-int (substring emacs-version (match-beginning 1)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
83 (match-end 1)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
84 subver (string-to-int (substring emacs-version (match-beginning 2)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
85 (match-end 2))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
86 (cond
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
87 ((= ver 18)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
88 (require 'emacs-19)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
89 (require 'fn-handler))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
90 ((and (= ver 19) (if lucid-p (< subver 10) (< subver 23)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
91 (require 'fn-handler))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
92 ((< ver 18)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
93 (error "dired does not work with emacs version %s" emacs-version))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
94
114
8619ce7e4c50 Import from CVS: tag r20-1b9
cvs
parents: 100
diff changeset
95 ;; We duplicate default-dir stuff to avoid its overwrites unless
8619ce7e4c50 Import from CVS: tag r20-1b9
cvs
parents: 100
diff changeset
96 ;; they are explicitly requested.
8619ce7e4c50 Import from CVS: tag r20-1b9
cvs
parents: 100
diff changeset
97
8619ce7e4c50 Import from CVS: tag r20-1b9
cvs
parents: 100
diff changeset
98 (defvar default-directory-function nil
8619ce7e4c50 Import from CVS: tag r20-1b9
cvs
parents: 100
diff changeset
99 "A function to call to compute the default-directory for the current buffer.
8619ce7e4c50 Import from CVS: tag r20-1b9
cvs
parents: 100
diff changeset
100 If this is nil, the function default-directory will return the value of the
8619ce7e4c50 Import from CVS: tag r20-1b9
cvs
parents: 100
diff changeset
101 variable default-directory.
8619ce7e4c50 Import from CVS: tag r20-1b9
cvs
parents: 100
diff changeset
102 Buffer local.")
8619ce7e4c50 Import from CVS: tag r20-1b9
cvs
parents: 100
diff changeset
103 (make-variable-buffer-local 'default-directory-function)
8619ce7e4c50 Import from CVS: tag r20-1b9
cvs
parents: 100
diff changeset
104
8619ce7e4c50 Import from CVS: tag r20-1b9
cvs
parents: 100
diff changeset
105 (defun default-directory ()
8619ce7e4c50 Import from CVS: tag r20-1b9
cvs
parents: 100
diff changeset
106 " Returns the default-directory for the current buffer.
8619ce7e4c50 Import from CVS: tag r20-1b9
cvs
parents: 100
diff changeset
107 Will use the variable default-directory-function if it non-nil."
8619ce7e4c50 Import from CVS: tag r20-1b9
cvs
parents: 100
diff changeset
108 (if default-directory-function
8619ce7e4c50 Import from CVS: tag r20-1b9
cvs
parents: 100
diff changeset
109 (funcall default-directory-function)
8619ce7e4c50 Import from CVS: tag r20-1b9
cvs
parents: 100
diff changeset
110 (if (string-match "Lucid" emacs-version)
8619ce7e4c50 Import from CVS: tag r20-1b9
cvs
parents: 100
diff changeset
111 (abbreviate-file-name default-directory t)
8619ce7e4c50 Import from CVS: tag r20-1b9
cvs
parents: 100
diff changeset
112 (abbreviate-file-name default-directory))))
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
113
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
114 ;;;;----------------------------------------------------------------
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
115 ;;;; Customizable variables
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
116 ;;;;----------------------------------------------------------------
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
117 ;;
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
118 ;; The funny comments are for autoload.el, to automagically update
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
119 ;; loaddefs.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
120
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
121 ;;; Variables for compressing files.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
122
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
123 ;;;###autoload
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
124 (defvar dired-compression-method 'compress
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
125 "*Type of compression program to use.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
126 Give as a symbol.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
127 Currently-recognized methods are: gzip pack compact compress.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
128 To change this variable use \\[dired-do-compress] with a zero prefix.")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
129
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
130 ;;;###autoload
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
131 (defvar dired-compression-method-alist
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
132 '((gzip ".gz" ("gzip") ("gzip" "-d") "-f")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
133 ;; Put compress before pack, so that it wins out if we are using
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
134 ;; efs to work on a case insensitive OS. The -f flag does
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
135 ;; two things in compress. No harm in giving it twice.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
136 (compress ".Z" ("compress" "-f") ("compress" "-d") "-f")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
137 ;; pack support may not work well. pack is too chatty and there is no way
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
138 ;; to force overwrites.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
139 (pack ".z" ("pack" "-f") ("unpack"))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
140 (compact ".C" ("compact") ("uncompact")))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
141
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
142 "*Association list of compression method descriptions.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
143 Each element of the table should be a list of the form
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
144
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
145 \(compress-type extension (compress-args) (decompress-args) force-flag\)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
146
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
147 where
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
148 `compress-type' is a unique symbol in the alist to which
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
149 `dired-compression-method' can be set;
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
150 `extension' is the file extension (as a string) used by files compressed
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
151 by this method;
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
152 `compress-args' is a list of the path of the compression program and
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
153 flags to pass as separate arguments;
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
154 `decompress-args' is a list of the path of the decompression
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
155 program and flags to pass as separate arguments.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
156 `force-flag' is the switch to pass to the command to force overwriting
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
157 of existing files.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
158
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
159 For example:
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
160
114
8619ce7e4c50 Import from CVS: tag r20-1b9
cvs
parents: 100
diff changeset
161 \(setq dired-compression-method-alist
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
162 \(cons '\(frobnicate \".frob\" \(\"frob\"\) \(\"frob\" \"-d\"\) \"-f\"\)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
163 dired-compression-method-alist\)\)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
164 => \(\(frobnicate \".frob\" \(\"frob\"\) \(\"frob\" \"-d\"\)\)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
165 \(gzip \".gz\" \(\"gzip\"\) \(\"gunzip\"\)\)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
166 ...\)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
167
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
168 See also: dired-compression-method <V>")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
169
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
170 ;;; Variables for the ls program.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
171
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
172 ;;;###autoload
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
173 (defvar dired-ls-program "ls"
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
174 "*Absolute or relative name of the ls program used by dired.")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
175
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
176 ;;;###autoload
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
177 (defvar dired-listing-switches "-al"
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
178 "*Switches passed to ls for dired. MUST contain the `l' option.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
179 Can contain even `F', `b', `i' and `s'.")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
180
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
181 (defvar dired-ls-F-marks-symlinks
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
182 (memq system-type '(aix-v3 hpux silicon-graphics-unix))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
183 ;; Both SunOS and Ultrix have system-type berkeley-unix. But
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
184 ;; SunOS doesn't mark symlinks, but Ultrix does. Therefore,
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
185 ;; can't grok this case.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
186 "*Informs dired about how ls -lF marks symbolic links.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
187 Set this to t if `dired-ls-program' with -lF marks the name of the symbolic
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
188 link itself with a trailing @.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
189
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
190 For example: If foo is a link pointing to bar, and \"ls -F bar\" gives
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
191
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
192 ... bar -> foo
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
193
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
194 set this variable to nil. If it gives
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
195
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
196 ... bar@ -> foo
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
197
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
198 set this variable to t.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
199
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
200 Dired checks if there is really a @ appended. Thus, if you have a
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
201 marking ls program on one host and a non-marking on another host, and
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
202 don't care about symbolic links which really end in a @, you can
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
203 always set this variable to t.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
204
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
205 If you use efs, it will make this variable buffer-local, and control
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
206 it according to its assessment of how the remote host marks symbolic
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
207 links.")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
208
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
209 (defvar dired-show-ls-switches nil
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
210 "*If non-nil dired will show the dired ls switches on the modeline.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
211 If nil, it will indicate how the files are sorted by either \"by name\" or
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
212 \"by date\". If it is unable to recognize the sorting defined by the switches,
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
213 then the switches will be shown explicitly on the modeline, regardless of the
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
214 setting of this variable.")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
215
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
216 ;;; Variables for other unix utility programs.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
217
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
218 ;; For most program names, don't use absolute paths so that dired
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
219 ;; uses the user's value of the environment variable PATH. chown is
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
220 ;; an exception as it is not always in the PATH.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
221
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
222 ;;;###autoload
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
223 (defvar dired-chown-program
142
1856695b1fa9 Import from CVS: tag r20-2b5
cvs
parents: 138
diff changeset
224 (if (memq system-type '(hpux dgux usg-unix-v linux)) "chown" "/etc/chown")
114
8619ce7e4c50 Import from CVS: tag r20-1b9
cvs
parents: 100
diff changeset
225 "*Name of chown command (usually `chown' or `/etc/chown').")
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
226
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
227 ;;;###autoload
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
228 (defvar dired-gnutar-program nil
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
229 "*If non-nil, name of the GNU tar executable (e.g. \"tar\" or \"gnutar\").
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
230 GNU tar's `z' switch is used for compressed tar files.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
231 If you don't have GNU tar, set this to nil: a pipe using `zcat' is then used.")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
232
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
233 ;;;###autoload
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
234 (defvar dired-unshar-program nil
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
235 "*Set to the name of the unshar program, if you have it.")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
236
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
237 ;;; Markers
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
238
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
239 (defvar dired-keep-marker-rename t
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
240 ;; Use t as default so that moved files `take their markers with them'
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
241 "*Controls marking of renamed files.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
242 If t, files keep their previous marks when they are renamed.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
243 If a character, renamed files (whether previously marked or not)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
244 are afterward marked with that character.")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
245
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
246 (defvar dired-keep-marker-compress t
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
247 "*Controls marking of compressed or uncompressed files.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
248 If t, files keep their previous marks when they are compressed.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
249 If a character, compressed or uncompressed files (whether previously
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
250 marked or not) are afterward marked with that character.")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
251
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
252 (defvar dired-keep-marker-uucode ?U
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
253 "*Controls marking of uuencoded or uudecoded files.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
254 If t, files keep their previous marks when they are uuencoded.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
255 If a character, uuencoded or uudecoded files (whether previously
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
256 marked or not) are afterward marked with that character.")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
257
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
258 (defvar dired-keep-marker-copy ?C
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
259 "*Controls marking of copied files.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
260 If t, copied files are marked if and as the corresponding original files were.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
261 If a character, copied files are unconditionally marked with that character.")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
262
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
263 (defvar dired-keep-marker-hardlink ?H
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
264 "*Controls marking of newly made hard links.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
265 If t, they are marked if and as the files linked to were marked.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
266 If a character, new links are unconditionally marked with that character.")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
267
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
268 (defvar dired-keep-marker-symlink ?S
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
269 "*Controls marking of newly made symbolic links.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
270 If t, they are marked if and as the files linked to were marked.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
271 If a character, new links are unconditionally marked with that character.")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
272
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
273 (defvar dired-keep-marker-kill ?K
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
274 "*When killed file lines are redisplayed, they will have this marker.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
275 Setting this to nil means that they will not have any marker.")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
276
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
277 (defvar dired-failed-marker-shell ?!
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
278 "*If non-nil, a character with which to mark files of failed shell commands.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
279 Applies to the command `dired-do-shell-command'. Files for which the shell
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
280 command has a nonzero exit status will be marked with this character")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
281
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
282 ;;; Behavioral Variables
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
283
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
284 ;;;###autoload
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
285 (defvar dired-local-variables-file ".dired"
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
286 "*If non-nil, filename for local variables for Dired.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
287 If Dired finds a file with that name in the current directory, it will
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
288 temporarily insert it into the dired buffer and run `hack-local-variables'.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
289
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
290 Type \\[info] and `g' `(emacs)File Variables' `RET' for more info on
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
291 local variables.")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
292
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
293 ;; Usually defined in files.el. Define here anyway, to be safe.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
294 ;;;###autoload
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
295 (defvar dired-kept-versions 2
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
296 "*When cleaning directory, number of versions to keep.")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
297
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
298 ;;;###autoload
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
299 (defvar dired-find-subdir nil
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
300 "*Determines whether dired tries to lookup a subdir in existing buffers.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
301 If non-nil, dired does not make a new buffer for a directory if it can be
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
302 found (perhaps as subdir) in some existing dired buffer. If there are several
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
303 dired buffers for a directory, then the most recently used one is chosen.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
304
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
305 Dired avoids switching to the current buffer, so that if you have
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
306 a normal and a wildcard buffer for the same directory, C-x d RET will
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
307 toggle between those two.")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
308
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
309 ;;;###autoload
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
310 (defvar dired-use-file-transformers t
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
311 "*Determines whether dired uses file transformers.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
312 If non-nil `dired-do-shell-command' will apply file transformers to file names.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
313 See \\[describe-function] for dired-do-shell-command for more information.")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
314
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
315 ;;;###autoload
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
316 (defvar dired-dwim-target nil
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
317 "*If non-nil, dired tries to guess a default target directory.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
318 This means that if there is a dired buffer displayed in the next window,
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
319 use its current subdir, instead of the current subdir of this dired buffer.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
320 The target is put in the prompt for file copy, rename, etc.")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
321
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
322 ;;;###autoload
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
323 (defvar dired-copy-preserve-time nil
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
324 "*If non-nil, Dired preserves the last-modified time in a file copy.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
325 \(This works on only some systems.)\\<dired-mode-map>
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
326 Use `\\[dired-do-copy]' with a zero prefix argument to toggle its value.")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
327
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
328 ;;;###autoload
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
329 (defvar dired-no-confirm nil
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
330 "*If non-nil, a list of symbols for commands dired should not confirm.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
331 It can be a sublist of
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
332
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
333 '(byte-compile chgrp chmod chown compress copy delete hardlink load
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
334 move print shell symlink uncompress recursive-delete kill-file-buffer
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
335 kill-dired-buffer patch create-top-dir revert-subdirs)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
336
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
337 The meanings of most of the symbols are obvious. A few exceptions:
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
338
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
339 'compress applies to compression or decompression by any of the
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
340 compression program in `dired-compression-method-alist'.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
341
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
342 'kill-dired-buffer applies to offering to kill dired buffers for
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
343 directories which have been deleted.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
344
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
345 'kill-file-buffer applies to offering to kill buffers visiting files
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
346 which have been deleted.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
347
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
348 'recursive-delete applies to recursively deleting non-empty
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
349 directories, and all of their contents.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
350
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
351 'create-top-dir applies to `dired-up-directory' creating a new top level
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
352 directory for the dired buffer.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
353
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
354 'revert-subdirs applies to re-reading subdirectories which have
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
355 been modified on disk.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
356
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
357 Note that this list also applies to remote files accessed with efs
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
358 or ange-ftp.")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
359
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
360 ;;;###autoload
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
361 (defvar dired-backup-if-overwrite nil
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
362 "*Non-nil if Dired should ask about making backups before overwriting files.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
363 Special value 'always suppresses confirmation.")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
364
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
365 ;;;###autoload
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
366 (defvar dired-omit-files nil
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
367 "*If non-nil un-interesting files will be omitted from this dired buffer.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
368 Use \\[dired-omit-toggle] to see these files. (buffer local)")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
369 (make-variable-buffer-local 'dired-omit-files)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
370
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
371 ;;;###autoload
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
372 (defvar dired-mail-reader 'rmail
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
373 "*Mail reader used by dired for dired-read-mail \(\\[dired-read-mail]\).
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
374 The symbols 'rmail and 'vm are the only two allowed values.")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
375
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
376 (defvar dired-verify-modtimes t
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
377 "*If non-nil dired will revert dired buffers for modified subdirectories.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
378 See also dired-no-confirm <V>.")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
379
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 116
diff changeset
380 ;;;###autoload
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 116
diff changeset
381 (defvar dired-refresh-automatically t
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 116
diff changeset
382 "*If non-nil, refresh dired buffers automatically after file operations.")
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 116
diff changeset
383
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
384 ;;; File name regular expressions and extensions.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
385
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
386 (defvar dired-trivial-filenames "^\\.\\.?$\\|^#"
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
387 "*Regexp of files to skip when finding first file of a directory listing.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
388 A value of nil means move to the subdir line.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
389 A value of t means move to first file.")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
390
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
391 (defvar dired-cleanup-alist
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
392 (list
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
393 '("tex" ".toc" ".log" ".aux" ".dvi")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
394 '("latex" ".toc" ".log" ".aux" ".idx" ".lof" ".lot" ".glo" ".dvi")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
395 '("bibtex" ".blg" ".bbl")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
396 '("texinfo" ".cp" ".cps" ".fn" ".fns" ".ky" ".kys" ".pg" ".pgs"
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
397 ".tp" ".tps" ".vr" ".vrs")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
398 '("patch" ".rej" ".orig")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
399 '("backups" "~")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
400 (cons "completion-ignored-extensions" completion-ignored-extensions))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
401 "*Alist of extensions for temporary files created by various programs.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
402 Used by `dired-cleanup'.")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
403
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
404 (defvar dired-omit-extensions
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
405 (let ((alist dired-cleanup-alist)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
406 x result)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
407 (while alist
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
408 (setq x (cdr (car alist))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
409 alist (cdr alist))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
410 (while x
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
411 (or (member (car x) result)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
412 (setq result (cons (car x) result)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
413 (setq x (cdr x))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
414 result)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
415 "*List of extensions for file names that will be omitted (buffer-local).
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
416 This only has effect when the subdirectory is in omission mode.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
417 To make omission mode the default, set `dired-omit-files' to t.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
418 See also `dired-omit-extensions'.")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
419 (make-variable-buffer-local 'dired-omit-extensions)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
420
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
421 (defvar dired-omit-regexps '("^#" "^\\.")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
422 "*File names matching these regexp may be omitted (buffer-local).
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
423 This only has effect when the subdirectory is in omission mode.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
424 To make omission mode the default, set `dired-omit-files' to t.
138
6608ceec7cf8 Import from CVS: tag r20-2b3
cvs
parents: 118
diff changeset
425 This only has effect when `dired-omit-files' is t.
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
426 See also `dired-omit-extensions'.")
138
6608ceec7cf8 Import from CVS: tag r20-2b3
cvs
parents: 118
diff changeset
427 (make-variable-buffer-local 'dired-omit-regexps)
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
428
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
429 (defvar dired-filename-re-ext "\\..+$" ; start from the first dot. last dot?
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
430 "*Defines what is the extension of a file name.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
431 \(match-beginning 0\) for this regexp in the file name without directory will
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
432 be taken to be the start of the extension.")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
433
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
434 ;;; Hook variables
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
435
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
436 (defvar dired-load-hook nil
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
437 "Run after loading dired.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
438 You can customize key bindings or load extensions with this.")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
439
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
440 (defvar dired-grep-load-hook nil
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
441 "Run after loading dired-grep.")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
442
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
443 (defvar dired-mode-hook nil
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
444 "Run at the very end of dired-mode.")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
445
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
446 (defvar dired-before-readin-hook nil
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
447 "Hook run before a dired buffer is newly read in, created,or reverted.")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
448
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
449 (defvar dired-after-readin-hook nil
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
450 "Hook run after each listing of a file or directory.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
451 The buffer is narrowed to the new listing.")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
452
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
453 (defvar dired-setup-keys-hook nil
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
454 "Hook run when dired sets up its keymap.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
455 This happens the first time that `dired-mode' is called, and runs after
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
456 `dired-mode-hook'. This hook can be used to make alterations to the
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
457 dired keymap.")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
458
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
459 ;;; Internal variables
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
460 ;;
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
461 ;; If you set these, know what you are doing.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
462
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
463 ;;; Marker chars.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
464
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
465 (defvar dired-marker-char ?* ; the answer is 42
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
466 ; life the universe and everything
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
467 ;; so that you can write things like
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
468 ;; (let ((dired-marker-char ?X))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
469 ;; ;; great code using X markers ...
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
470 ;; )
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
471 ;; For example, commands operating on two sets of files, A and B.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
472 ;; Or marking files with digits 0-9. This could implicate
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
473 ;; concentric sets or an order for the marked files.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
474 ;; The code depends on dynamic scoping on the marker char.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
475 "In dired, character used to mark files for later commands.")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
476 (make-variable-buffer-local 'dired-marker-char)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
477
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
478 (defconst dired-default-marker dired-marker-char)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
479 ;; Stores the default value of dired-marker-char when dynamic markers
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
480 ;; are being used.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
481
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
482 (defvar dired-del-marker ?D
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
483 "Character used to flag files for deletion.")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
484
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
485 ;; \017=^O for Omit - other packages can chose other control characters.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
486 (defvar dired-omit-marker-char ?\017)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
487 ;; Marker used for omitted files. Shouldn't be used by anything else.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
488
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
489 (defvar dired-kill-marker-char ?\C-k)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
490 ;; Marker used by dired-do-kill. Shouldn't be used by anything else.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
491
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
492 ;;; State variables
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
493
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
494 (defvar dired-mode-line-modified "-%s%s%s-"
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
495 "*Format string to show the modification status of the buffer.")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
496
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
497 (defvar dired-del-flags-number 0)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
498 (make-variable-buffer-local 'dired-del-flags-number)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
499 (defvar dired-marks-number 0)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
500 (make-variable-buffer-local 'dired-marks-number)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
501 (defvar dired-other-marks-number 0)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
502 (make-variable-buffer-local 'dired-other-marks-number)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
503
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
504 (defvar dired-marked-files nil
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
505 "List of filenames from last `dired-copy-filename-as-kill' call.")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
506
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
507 (defvar dired-directory nil
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
508 "The directory name or shell wildcard that was used as argument to `ls'.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
509 Local to each dired buffer. May be a list, in which case the car is the
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
510 directory name and the cdr is the actual files to list.")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
511 (make-variable-buffer-local 'dired-directory)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
512
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
513 (defvar dired-internal-switches nil
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
514 "The actual (buffer-local) value of `dired-listing-switches'.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
515 The switches are represented as a list of characters.")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
516 (make-variable-buffer-local 'dired-internal-switches)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
517
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
518 (defvar dired-subdir-alist nil
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
519 "Association list of subdirectories and their buffer positions.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
520 Each subdirectory has an element: (DIRNAME . STARTMARKER).
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
521 The order of elements is the reverse of the order in the buffer.")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
522 (make-variable-buffer-local 'dired-subdir-alist)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
523
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
524 (defvar dired-curr-subdir-min 0)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
525 ;; Cache for modeline tracking of the cursor
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
526 (make-variable-buffer-local 'dired-curr-subdir-min)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
527
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
528 (defvar dired-curr-subdir-max 0)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
529 ;; Cache for modeline tracking of the cursor
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
530 (make-variable-buffer-local 'dired-curr-subdir-max)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
531
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
532 (defvar dired-subdir-omit nil)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
533 ;; Controls whether the modeline shows Omit.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
534 (make-variable-buffer-local 'dired-subdir-omit)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
535
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
536 (defvar dired-in-query nil)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
537 ;; let-bound to t when dired is in the process of querying the user.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
538 ;; This is to keep asynch messaging from clobbering the query prompt.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
539
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
540 (defvar dired-overwrite-confirmed nil)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
541 ;; Fluid variable used to remember if a bunch of overwrites have been
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
542 ;; confirmed.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
543
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
544 (defvar dired-overwrite-backup-query nil)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
545 ;; Fluid var used to remember if backups have been requested for overwrites.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
546
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
547 (defvar dired-file-creator-query nil)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
548 ;; Fluid var to remember responses to file-creator queries.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
549
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
550 (defvar dired-omit-silent nil)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
551 ;; This is sometimes let-bound to t if messages would be annoying,
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
552 ;; e.g., in dired-awrh.el. Binding to 0, only suppresses
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
553 ;; \"(Nothing to omit)\" message.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
554
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
555 (defvar dired-buffers nil
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
556 ;; Enlarged by dired-advertise
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
557 ;; Queried by function dired-buffers-for-dir. When this detects a
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
558 ;; killed buffer, it is removed from this list.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
559 "Alist of directories and their associated dired buffers.")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
560
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
561 (defvar dired-sort-mode nil
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
562 "Whether Dired sorts by name, date, etc.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
563 \(buffer-local\)")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
564 ;; This is nil outside dired buffers so it can be used in the modeline
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
565 (make-variable-buffer-local 'dired-sort-mode)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
566
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
567 (defvar dired-marker-stack nil
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
568 "List of previously used dired marker characters.")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
569 (make-variable-buffer-local 'dired-marker-stack)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
570
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
571 (defvar dired-marker-stack-pointer 0)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
572 ;; Points to the current marker in the stack
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
573 (make-variable-buffer-local 'dired-marker-stack-pointer)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
574
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
575 (defvar dired-marker-stack-cursor ?\ ; space
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
576 "Character to use as a cursor in the dired marker stack.")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
577
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
578 (defconst dired-marker-string ""
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
579 "String version of `dired-marker-stack'.")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
580 (make-variable-buffer-local 'dired-marker-string)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
581
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
582 (defvar dired-modeline-tracking-cmds nil)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
583 ;; List of commands after which the modeline gets updated.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
584
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
585 ;;; Config. variables not usually considered fair game for the user.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
586
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
587 (defvar dired-deletion-confirmer 'yes-or-no-p) ; or y-or-n-p?
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
588
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
589 (defvar dired-log-buffer "*Dired log*")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
590 ;; Name of buffer used to log dired messages and errors.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
591
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
592 ;;; Assoc. lists
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
593
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
594 ;; For pop ups and user input for file marking
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
595 (defvar dired-query-alist
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
596 '((?\y . y) (?\040 . y) ; `y' or SPC means accept once
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
597 (?n . n) (?\177 . n) ; `n' or DEL skips once
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
598 (?! . yes) ; `!' accepts rest
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
599 (?q. no) (?\e . no) ; `q' or ESC skips rest
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
600 ;; None of these keys quit - use C-g for that.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
601 ))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
602
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
603 (defvar dired-sort-type-alist
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
604 ;; alist of sort flags, and the sort type, as a symbol.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
605 ;; Don't put ?r in here. It's handled separately.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
606 '((?t . date) (?S . size) (?U . unsort) (?X . ext)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
607
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
608 ;;; Internal regexps for examining ls listings.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
609 ;;
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
610 ;; Many of these regexps must be tested at beginning-of-line, but are also
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
611 ;; used to search for next matches, so neither omitting "^" nor
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
612 ;; replacing "^" by "\n" (to make it slightly faster) will work.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
613
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
614 (defvar dired-re-inode-size "[ \t0-9]*")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
615 ;; Regexp for optional initial inode and file size.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
616 ;; Must match output produced by ls' -i and -s flags.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
617
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
618 (defvar dired-re-mark "^[^ \n\r]")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
619 ;; Regexp matching a marked line.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
620 ;; Important: the match ends just after the marker.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
621
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
622 (defvar dired-re-maybe-mark "^. ")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
623
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
624 (defvar dired-re-dir (concat dired-re-maybe-mark dired-re-inode-size "d"))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
625 ;; Matches directory lines
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
626
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
627 (defvar dired-re-sym (concat dired-re-maybe-mark dired-re-inode-size "l"))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
628 ;; Matches symlink lines
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
629
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
630 (defvar dired-re-exe;; match ls permission string of an executable file
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
631 (mapconcat (function
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
632 (lambda (x)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
633 (concat dired-re-maybe-mark dired-re-inode-size x)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
634 '("-[-r][-w][xs][-r][-w].[-r][-w]."
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
635 "-[-r][-w].[-r][-w][xs][-r][-w]."
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
636 "-[-r][-w].[-r][-w].[-r][-w][xst]")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
637 "\\|"))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
638
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
639 (defvar dired-re-dot "^.* \\.\\.?/?$") ; with -F, might end in `/'
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
640 ;; . and .. files
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
641
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
642 (defvar dired-re-month-and-time
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
643 (concat
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
644 " \\(Jan\\|Feb\\|Mar\\|Apr\\|May\\|June?\\|July?\\|Aug\\|Sep\\|Oct\\|Nov\\|"
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
645 ; June and July are for HP-UX 9.0
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
646 "Dec\\) [ 0-3][0-9]\\("
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
647 " [012][0-9]:[0-6][0-9] \\|" ; time
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
648 " [12][90][0-9][0-9] \\|" ; year on IRIX, NeXT, SunOS, ULTRIX, Apollo,
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
649 ; HP-UX, A/UX
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
650 " [12][90][0-9][0-9] \\)" ; year on AIX
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
651 ))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
652 ;; This regexp MUST match all the way to first character of the filename.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
653 ;; You can loosen it to taste, but then you might bomb on filenames starting
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
654 ;; with a space. This will have to be modified for non-english month names.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
655
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
656 (defvar dired-subdir-regexp
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
657 "\\([\n\r]\n\\|\\`\\). \\([^\n\r]+\\)\\(:\\)\\(\\.\\.\\.\r\\|[\n\r]\\)")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
658 ;; Regexp matching a maybe hidden subdirectory line in ls -lR output.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
659 ;; Subexpression 2 is the subdirectory proper, no trailing colon.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
660 ;; Subexpression 3 must end right before the \n or \r at the end of
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
661 ;; the subdir heading. Matches headings after indentation has been done.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
662
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
663 (defvar dired-unhandle-add-files nil)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
664 ;; List of files that the dired handler function need not add to dired buffers.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
665 ;; This is because they have already been added, most likely in
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
666 ;; dired-create-files. This is because dired-create-files add files with
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
667 ;; special markers.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
668
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
669 ;;; history variables
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
670
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
671 (defvar dired-regexp-history nil
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
672 "History list of regular expressions used in Dired commands.")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
673
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
674 (defvar dired-chmod-history nil
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
675 "History of arguments to chmod in dired.")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
676
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
677 (defvar dired-chown-history nil
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
678 "History of arguments to chown in dired.")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
679
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
680 (defvar dired-chgrp-history nil
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
681 "History of arguments to chgrp in dired.")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
682
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
683 (defvar dired-cleanup-history nil
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
684 "History of arguments to dired-cleanup.")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
685
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
686 (defvar dired-goto-file-history nil)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
687 ;; History for dired-goto-file and dired-goto-subdir
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
688 (put 'dired-goto-file-history 'cursor-end t) ; for gmhist
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
689
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
690 (defvar dired-history nil)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
691 ;; Catch-all history variable for dired file ops without
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
692 ;; their own history.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
693
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
694 (defvar dired-op-history-alist
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
695 ;; alist of dired file operations and history symbols
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
696 '((chgrp . dired-chgrp-history) (chown . dired-chown-history)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
697 (chmod . dired-chmod-history) ))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
698
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
699 ;;; Tell the byte-compiler that we know what we're doing.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
700 ;;; Do we?
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
701
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
702 (defvar file-name-handler-alist)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
703 (defvar inhibit-file-name-operation)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
704 (defvar inhibit-file-name-handlers)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
705 (defvar efs-dired-host-type)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
706
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
707
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
708 ;;;;------------------------------------------------------------------
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
709 ;;;; Utilities
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
710 ;;;;------------------------------------------------------------------
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
711
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
712 ;;; Macros
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
713 ;;
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
714 ;; Macros must be defined before they are used - for the byte compiler.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
715
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
716 (defmacro dired-get-subdir-min (elt)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
717 ;; Returns the value of the subdir minumum for subdir with entry ELT in
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
718 ;; dired-subdir-alist.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
719 (list 'nth 1 elt))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
720
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
721 (defmacro dired-save-excursion (&rest body)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
722 ;; Saves excursions of the point (not buffer) in dired buffers.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
723 ;; It tries to be robust against deletion of the region about the point.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
724 ;; Note that this assumes only dired-style deletions.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
725 (let ((temp-bolm (make-symbol "bolm"))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
726 (temp-fnlp (make-symbol "fnlp"))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
727 (temp-offset-bol (make-symbol "offset-bol")))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
728 (` (let (((, temp-bolm) (make-marker))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
729 (, temp-fnlp) (, temp-offset-bol))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
730 (let ((bol (save-excursion (skip-chars-backward "^\n\r") (point))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
731 (set-marker (, temp-bolm) bol)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
732 (setq (, temp-offset-bol) (- (point) bol)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
733 (, temp-fnlp) (memq (char-after bol) '(?\n\ ?\r))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
734 (unwind-protect
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
735 (progn
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
736 (,@ body))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
737 ;; Use the marker to try to find the right line, then move to
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
738 ;; the proper column.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
739 (goto-char (, temp-bolm))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
740 (and (not (, temp-fnlp))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
741 (not (eq (following-char) 0)) (memq (following-char) '(?\n ?\r))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
742 ;; The line containing the point got deleted. Note that this
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
743 ;; logic only works if we don't delete null lines, but we never
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
744 ;; do.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
745 (forward-line 1)) ; don't move into a hidden line.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
746 (skip-chars-forward "^\n\r" (+ (point) (, temp-offset-bol))))))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
747
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
748 (put 'dired-save-excursion 'lisp-indent-hook 0)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
749
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
750 (defun dired-substitute-marker (pos old new)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
751 ;; Change marker, re-fontify
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
752 (subst-char-in-region pos (1+ pos) old new)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
753 (dired-move-to-filename))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
754
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
755 (defmacro dired-mark-if (predicate msg)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
756 ;; Mark all files for which CONDITION evals to non-nil.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
757 ;; CONDITION is evaluated on each line, with point at beginning of line.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
758 ;; MSG is a noun phrase for the type of files being marked.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
759 ;; It should end with a noun that can be pluralized by adding `s'.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
760 ;; Return value is the number of files marked, or nil if none were marked.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
761 (let ((temp-pt (make-symbol "pt"))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
762 (temp-count (make-symbol "count"))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
763 (temp-msg (make-symbol "msg")))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
764 (` (let (((, temp-msg) (, msg))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
765 ((, temp-count) 0)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
766 (, temp-pt) buffer-read-only)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
767 (save-excursion
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
768 (if (, temp-msg) (message "Marking %ss..." (, temp-msg)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
769 (goto-char (point-min))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
770 (while (not (eobp))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
771 (if (and (, predicate)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
772 (not (char-equal (following-char) dired-marker-char)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
773 (progn
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
774 ;; Doing this rather than delete-char, insert
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
775 ;; avoids re-computing markers
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
776 (setq (, temp-pt) (point))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
777 (dired-substitute-marker
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
778 (, temp-pt)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
779 (following-char) dired-marker-char)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
780 (setq (, temp-count) (1+ (, temp-count)))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
781 (forward-line 1))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
782 (if (, temp-msg)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
783 (message "%s %s%s %s%s."
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
784 (, temp-count)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
785 (, temp-msg)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
786 (dired-plural-s (, temp-count))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
787 (if (eq dired-marker-char ?\040) "un" "")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
788 (if (eq dired-marker-char dired-del-marker)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
789 "flagged" "marked"))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
790 (and (> (, temp-count) 0) (, temp-count))))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
791
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
792 (defmacro dired-map-over-marks (body arg &optional show-progress)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
793 ;; Perform BODY with point somewhere on each marked line
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
794 ;; and return a list of BODY's results.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
795 ;; If no marked file could be found, execute BODY on the current line.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
796 ;; If ARG is an integer, use the next ARG (or previous -ARG, if ARG<0)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
797 ;; files instead of the marked files.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
798 ;; If ARG is t, only apply to marked files. If there are no marked files,
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
799 ;; the result is a noop.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
800 ;; If ARG is otherwise non-nil, use current file instead.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
801 ;; If optional third arg SHOW-PROGRESS evaluates to non-nil,
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
802 ;; redisplay the dired buffer after each file is processed.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
803 ;; No guarantee is made about the position on the marked line.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
804 ;; BODY must ensure this itself if it depends on this.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
805 ;; Search starts at the beginning of the buffer, thus the car of the list
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
806 ;; corresponds to the line nearest to the buffer's bottom. This
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
807 ;; is also true for (positive and negative) integer values of ARG.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
808 ;; To avoid code explosion, BODY should not be too long as it is
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
809 ;; expanded four times.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
810 ;;
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
811 ;; Warning: BODY must not add new lines before point - this may cause an
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
812 ;; endless loop.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
813 ;; This warning should not apply any longer, sk 2-Sep-1991 14:10.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
814 (let ((temp-found (make-symbol "found"))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
815 (temp-results (make-symbol "results"))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
816 (temp-regexp (make-symbol "regexp"))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
817 (temp-curr-pt (make-symbol "curr-pt"))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
818 (temp-next-position (make-symbol "next-position")))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
819 (` (let (buffer-read-only case-fold-search (, temp-found) (, temp-results))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
820 (dired-save-excursion
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
821 (if (and (, arg) (not (eq (, arg) t)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
822 (if (integerp (, arg))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
823 (and (not (zerop (, arg)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
824 (progn;; no save-excursion, want to move point.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
825 (dired-repeat-over-lines
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
826 arg
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
827 (function (lambda ()
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
828 (if (, show-progress) (sit-for 0))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
829 (setq (, temp-results)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
830 (cons (, body)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
831 (, temp-results))))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
832 (if (< (, arg) 0)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
833 (nreverse (, temp-results))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
834 (, temp-results))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
835 ;; non-nil, non-integer ARG means use current file:
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
836 (list (, body)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
837 (let (((, temp-regexp)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
838 (concat "^" (regexp-quote (char-to-string
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
839 dired-marker-char))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
840 (, temp-curr-pt) (, temp-next-position))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
841 (save-excursion
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
842 (goto-char (point-min))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
843 ;; remember position of next marked file before BODY
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
844 ;; can insert lines before the just found file,
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
845 ;; confusing us by finding the same marked file again
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
846 ;; and again and...
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
847 (setq (, temp-next-position)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
848 (and (re-search-forward (, temp-regexp) nil t)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
849 (point-marker))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
850 (, temp-found) (not (null (, temp-next-position))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
851 (while (, temp-next-position)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
852 (setq (, temp-curr-pt) (goto-char (, temp-next-position))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
853 ;; need to get next position BEFORE body
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
854 (, temp-next-position)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
855 (and (re-search-forward (, temp-regexp) nil t)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
856 (point-marker)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
857 (goto-char (, temp-curr-pt))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
858 (if (, show-progress) (sit-for 0))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
859 (setq (, temp-results) (cons (, body) (, temp-results)))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
860 (if (, temp-found)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
861 (, temp-results)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
862 ;; Do current file, unless arg is t
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
863 (and (not (eq (, arg) t))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
864 (list (, body)))))))))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
865
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
866 ;;; General utility functions
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
867
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
868 (defun dired-buffer-more-recently-used-p (buffer1 buffer2)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
869 "Return t if BUFFER1 is more recently used than BUFFER2."
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
870 (if (equal buffer1 buffer2)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
871 nil
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
872 (let ((more-recent nil)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
873 (list (buffer-list)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
874 (while (and list
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
875 (not (setq more-recent (equal buffer1 (car list))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
876 (not (equal buffer2 (car list))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
877 (setq list (cdr list)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
878 more-recent)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
879
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
880 (defun dired-file-modtime (file)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
881 ;; Return the modtime of FILE, which is assumed to be already expanded
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
882 ;; by expand-file-name.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
883 (let ((handler (find-file-name-handler file 'dired-file-modtime)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
884 (if handler
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
885 (funcall handler 'dired-file-modtime file)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
886 (nth 5 (file-attributes file)))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
887
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
888 (defun dired-set-file-modtime (file alist)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
889 ;; Set the modtime for FILE in the subdir alist ALIST.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
890 (let ((handler (find-file-name-handler file 'dired-set-file-modtime)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
891 (if handler
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
892 (funcall handler 'dired-set-file-modtime file alist)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
893 (let ((elt (assoc file alist)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
894 (if elt
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
895 (setcar (nthcdr 4 elt) (nth 5 (file-attributes file))))))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
896
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
897 (defun dired-map-over-marks-check (fun arg op-symbol operation
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
898 &optional show-progress no-confirm)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
899 ;; Map FUN over marked files (with second ARG like in dired-map-over-marks)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
900 ;; and display failures.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
901
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
902 ;; FUN takes zero args. It returns non-nil (the offending object, e.g.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
903 ;; the short form of the filename) for a failure and probably logs a
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
904 ;; detailed error explanation using function `dired-log'.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
905
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
906 ;; OP-SYMBOL is s symbol representing the operation.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
907 ;; eg. 'compress
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
908
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
909 ;; OPERATION is a string describing the operation performed (e.g.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
910 ;; "Compress"). It is used with `dired-mark-pop-up' to prompt the user
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
911 ;; (e.g. with `Compress * [2 files]? ') and to display errors (e.g.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
912 ;; `Failed to compress 1 of 2 files - type y to see why ("foo")')
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
913
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
914 ;; SHOW-PROGRESS if non-nil means redisplay dired after each file.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
915
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
916 (if (or no-confirm (dired-mark-confirm op-symbol operation arg))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
917 (let* ((total-list;; all of FUN's return values
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
918 (dired-map-over-marks (funcall fun) arg show-progress))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
919 (total (length total-list))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
920 (failures (delq nil total-list))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
921 (count (length failures)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
922 (if (not failures)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
923 (message "%s: %d file%s." operation total (dired-plural-s total))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
924 (message "Failed to %s %d of %d file%s - type y to see why %s"
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
925 operation count total (dired-plural-s total)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
926 ;; this gives a short list of failed files in parens
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
927 ;; which may be sufficient for the user even
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
928 ;; without typing `W' for the process' diagnostics
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
929 failures)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
930 ;; end this bunch of errors:
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
931 (dired-log-summary
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
932 (buffer-name (current-buffer))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
933 (format
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
934 "Failed to %s %d of %d file%s"
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
935 operation count total (dired-plural-s total))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
936 failures)))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
937
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
938 (defun dired-make-switches-string (list)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
939 ;; Converts a list of cracters to a string suitable for passing to ls.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
940 (concat "-" (mapconcat 'char-to-string list "")))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
941
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
942 (defun dired-make-switches-list (string)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
943 ;; Converts a string of ls switches to a list of characters.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
944 (delq ?- (mapcar 'identity string)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
945
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
946 ;; Cloning replace-match to work on strings instead of in buffer:
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
947 ;; The FIXEDCASE parameter of replace-match is not implemented.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
948 (defun dired-string-replace-match (regexp string newtext
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
949 &optional literal global)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
950 ;; Replace first match of REGEXP in STRING with NEWTEXT.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
951 ;; If it does not match, nil is returned instead of the new string.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
952 ;; Optional arg LITERAL means to take NEWTEXT literally.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
953 ;; Optional arg GLOBAL means to replace all matches.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
954 (if global
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
955 (let ((result "") (start 0) mb me)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
956 (while (string-match regexp string start)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
957 (setq mb (match-beginning 0)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
958 me (match-end 0)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
959 result (concat result
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
960 (substring string start mb)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
961 (if literal
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
962 newtext
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
963 (dired-expand-newtext string newtext)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
964 start me))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
965 (if mb ; matched at least once
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
966 (concat result (substring string start))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
967 nil))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
968 ;; not GLOBAL
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
969 (if (not (string-match regexp string 0))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
970 nil
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
971 (concat (substring string 0 (match-beginning 0))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
972 (if literal newtext (dired-expand-newtext string newtext))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
973 (substring string (match-end 0))))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
974
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
975 (defun dired-expand-newtext (string newtext)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
976 ;; Expand \& and \1..\9 (referring to STRING) in NEWTEXT, using match data.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
977 ;; Note that in Emacs 18 match data are clipped to current buffer
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
978 ;; size...so the buffer should better not be smaller than STRING.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
979 (let ((pos 0)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
980 (len (length newtext))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
981 (expanded-newtext ""))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
982 (while (< pos len)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
983 (setq expanded-newtext
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
984 (concat expanded-newtext
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
985 (let ((c (aref newtext pos)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
986 (if (= ?\\ c)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
987 (cond ((= ?\& (setq c
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
988 (aref newtext
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
989 (setq pos (1+ pos)))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
990 (substring string
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
991 (match-beginning 0)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
992 (match-end 0)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
993 ((and (>= c ?1) (<= c ?9))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
994 ;; return empty string if N'th
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
995 ;; sub-regexp did not match:
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
996 (let ((n (- c ?0)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
997 (if (match-beginning n)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
998 (substring string
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
999 (match-beginning n)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1000 (match-end n))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1001 "")))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1002 (t
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1003 (char-to-string c)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1004 (char-to-string c)))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1005 (setq pos (1+ pos)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1006 expanded-newtext))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1007
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1008 (defun dired-in-this-tree (file dir)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1009 ;;Is FILE part of the directory tree starting at DIR?
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1010 (let ((len (length dir)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1011 (and (>= (length file) len)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1012 (string-equal (substring file 0 len) dir))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1013
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1014 (defun dired-tree-lessp (dir1 dir2)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1015 ;; Lexicographic order on pathname components, like `ls -lR':
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1016 ;; DIR1 < DIR2 iff DIR1 comes *before* DIR2 in an `ls -lR' listing,
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1017 ;; i.e., iff DIR1 is a (grand)parent dir of DIR2,
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1018 ;; or DIR1 and DIR2 are in the same parentdir and their last
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1019 ;; components are string-lessp.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1020 ;; Thus ("/usr/" "/usr/bin") and ("/usr/a/" "/usr/b/") are tree-lessp.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1021 ;; string-lessp could arguably be replaced by file-newer-than-file-p
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1022 ;; if dired-internal-switches contained `t'.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1023 (let ((dir1 (file-name-as-directory dir1))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1024 (dir2 (file-name-as-directory dir2))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1025 (start1 1)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1026 (start2 1)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1027 comp1 comp2 end1 end2)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1028 (while (progn
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1029 (setq end1 (string-match "/" dir1 start1)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1030 comp1 (substring dir1 start1 end1)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1031 end2 (string-match "/" dir2 start2)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1032 comp2 (substring dir2 start2 end2))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1033 (and end1 end2 (string-equal comp1 comp2)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1034 (setq start1 (1+ end1)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1035 start2 (1+ end2)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1036 (if (eq (null end1) (null end2))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1037 (string-lessp comp1 comp2)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1038 (null end1))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1039
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1040 ;; So that we can support case-insensitive systems.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1041 (fset 'dired-file-name-lessp 'string-lessp)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1042
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1043
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1044 ;;;; ------------------------------------------------------------------
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1045 ;;;; Initializing Dired
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1046 ;;;; ------------------------------------------------------------------
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1047
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1048 ;;; Set the minor mode alist
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1049
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1050 (or (equal (assq 'dired-sort-mode minor-mode-alist)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1051 '(dired-sort-mode dired-sort-mode))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1052 ;; Test whether this has already been done in case dired is reloaded
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1053 ;; There may be several elements with dired-sort-mode as car.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1054 (setq minor-mode-alist
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1055 ;; cons " Omit" in first, so that it doesn't
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1056 ;; get stuck between the directory and sort mode on the
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1057 ;; mode line.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1058 (cons '(dired-sort-mode dired-sort-mode)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1059 (cons '(dired-subdir-omit " Omit")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1060 (cons '(dired-marker-stack dired-marker-string)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1061 minor-mode-alist)))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1062
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1063 ;;; Keymaps
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1064
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1065 (defvar dired-mode-map nil
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1066 "Local keymap for dired-mode buffers.")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1067 (defvar dired-regexp-map nil
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1068 "Dired keymap for commands that use regular expressions.")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1069 (defvar dired-diff-map nil
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1070 "Dired keymap for diff and related commands.")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1071 (defvar dired-subdir-map nil
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1072 "Dired keymap for commands that act on subdirs, or the files within them.")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1073
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1074 (defvar dired-keymap-grokked nil
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1075 "Set to t after dired has grokked the global keymap.")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1076
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1077 (defun dired-key-description (cmd &rest prefixes)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1078 ;; Return a key description string for a menu. If prefixes are given,
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1079 ;; they should be either strings, integers, or 'universal-argument.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1080 (let ((key (where-is-internal cmd dired-mode-map t)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1081 (if key
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1082 (key-description
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1083 (apply 'vconcat
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1084 (append
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1085 (mapcar
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1086 (function
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1087 (lambda (x)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1088 (cond ((eq x 'universal-argument)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1089 (where-is-internal 'universal-argument
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1090 dired-mode-map t))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1091 ((integerp x) (int-to-string x))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1092 (t x))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1093 prefixes)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1094 (list key))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1095 "")))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1096
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1097 (defun dired-grok-keys (to-command from-command)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1098 ;; Assigns to TO-COMMAND the keys for the global binding of FROM-COMMAND.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1099 ;; Does not clobber anything in the local keymap. In emacs 19 should
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1100 ;; use substitute-key-definition, but I believe that this will
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1101 ;; clobber things in the local map.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1102 (let ((keys (where-is-internal from-command)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1103 (while keys
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1104 (condition-case nil
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1105 (if (eq (global-key-binding (car keys)) (key-binding (car keys)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1106 (local-set-key (car keys) to-command))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1107 (error nil))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1108 (setq keys (cdr keys)))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1109
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1110 (defun dired-grok-keymap ()
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1111 ;; Initialize the dired keymaps.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1112 ;; This is actually done the first time that dired-mode runs.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1113 ;; We do it this late, to be sure that the user's global-keymap has
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1114 ;; stabilized.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1115 (if dired-keymap-grokked
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1116 () ; we've done it
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1117 ;; Watch out for dired being invoked from the command line.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1118 ;; This is a bit kludgy, but so is the emacs startup sequence IMHO.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1119 (if (and term-setup-hook (boundp 'command-line-args-left))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1120 (progn
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1121 (if (string-equal "18." (substring emacs-version 0 3))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1122 (funcall term-setup-hook)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1123 (run-hooks 'term-setup-hook))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1124 (setq term-setup-hook nil)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1125 (setq dired-keymap-grokked t)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1126 (run-hooks 'dired-setup-keys-hook)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1127 (dired-grok-keys 'dired-next-line 'next-line)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1128 (dired-grok-keys 'dired-previous-line 'previous-line)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1129 (dired-grok-keys 'dired-undo 'undo)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1130 (dired-grok-keys 'dired-undo 'advertised-undo)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1131 (dired-grok-keys 'dired-scroll-up 'scroll-up)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1132 (dired-grok-keys 'dired-scroll-down 'scroll-down)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1133 (dired-grok-keys 'dired-beginning-of-buffer 'beginning-of-buffer)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1134 (dired-grok-keys 'dired-end-of-buffer 'end-of-buffer)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1135 (dired-grok-keys 'dired-next-subdir 'forward-paragraph)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1136 (dired-grok-keys 'dired-prev-subdir 'backward-paragraph)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1137
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1138 ;; The regexp-map is used for commands using regexp's.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1139 (if dired-regexp-map
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1140 ()
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1141 (setq dired-regexp-map (make-sparse-keymap))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1142 (define-key dired-regexp-map "C" 'dired-do-copy-regexp)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1143 ;; Not really a regexp, but does transform file names.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1144 (define-key dired-regexp-map "D" 'dired-downcase)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1145 (define-key dired-regexp-map "H" 'dired-do-hardlink-regexp)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1146 (define-key dired-regexp-map "R" 'dired-do-rename-regexp)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1147 (define-key dired-regexp-map "S" 'dired-do-symlink-regexp)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1148 (define-key dired-regexp-map "U" 'dired-upcase)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1149 (define-key dired-regexp-map "Y" 'dired-do-relsymlink-regexp)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1150 (define-key dired-regexp-map "c" 'dired-cleanup)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1151 (define-key dired-regexp-map "d" 'dired-flag-files-regexp)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1152 (define-key dired-regexp-map "e" 'dired-mark-extension)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1153 (define-key dired-regexp-map "m" 'dired-mark-files-regexp)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1154 (define-key dired-regexp-map "o" 'dired-add-omit-regexp)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1155 (define-key dired-regexp-map "x" 'dired-flag-extension)) ; a string, rather
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1156 ; than a regexp.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1157
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1158 (if dired-diff-map
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1159 ()
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1160 (setq dired-diff-map (make-sparse-keymap))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1161 (define-key dired-diff-map "d" 'dired-diff)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1162 (define-key dired-diff-map "b" 'dired-backup-diff)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1163 (define-key dired-diff-map "m" 'dired-emerge)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1164 (define-key dired-diff-map "a" 'dired-emerge-with-ancestor)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1165 (define-key dired-diff-map "e" 'dired-ediff)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1166 (define-key dired-diff-map "p" 'dired-epatch))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1167
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1168 (if dired-subdir-map
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1169 ()
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1170 (setq dired-subdir-map (make-sparse-keymap))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1171 (define-key dired-subdir-map "n" 'dired-redisplay-subdir)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1172 (define-key dired-subdir-map "m" 'dired-mark-subdir-files)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1173 (define-key dired-subdir-map "d" 'dired-flag-subdir-files)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1174 (define-key dired-subdir-map "z" 'dired-compress-subdir-files))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1175
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1176 (fset 'dired-regexp-prefix dired-regexp-map)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1177 (fset 'dired-diff-prefix dired-diff-map)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1178 (fset 'dired-subdir-prefix dired-subdir-map)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1179 (fset 'efs-dired-prefix (function (lambda ()
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1180 (interactive)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1181 (error "efs-dired not loaded yet"))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1182
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1183 ;; the main map
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1184 (if dired-mode-map
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1185 nil
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1186 ;; Force `f' rather than `e' in the mode doc:
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1187 (fset 'dired-advertised-find-file 'dired-find-file)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1188 (fset 'dired-advertised-next-subdir 'dired-next-subdir)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1189 (fset 'dired-advertised-prev-subdir 'dired-prev-subdir)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1190 (setq dired-mode-map (make-keymap))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1191 (suppress-keymap dired-mode-map)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1192 ;; Commands to mark certain categories of files
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1193 (define-key dired-mode-map "~" 'dired-flag-backup-files)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1194 (define-key dired-mode-map "#" 'dired-flag-auto-save-files)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1195 (define-key dired-mode-map "*" 'dired-mark-executables)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1196 (define-key dired-mode-map "." 'dired-clean-directory)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1197 (define-key dired-mode-map "/" 'dired-mark-directories)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1198 (define-key dired-mode-map "@" 'dired-mark-symlinks)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1199 (define-key dired-mode-map "," 'dired-mark-rcs-files)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1200 (define-key dired-mode-map "\M-(" 'dired-mark-sexp)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1201 (define-key dired-mode-map "\M-d" 'dired-mark-files-from-other-dired-buffer)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1202 (define-key dired-mode-map "\M-c" 'dired-mark-files-compilation-buffer)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1203 ;; Upper case keys (except ! and &) for operating on the marked files
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1204 (define-key dired-mode-map "A" 'dired-do-tags-search)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1205 (define-key dired-mode-map "B" 'dired-do-byte-compile)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1206 (define-key dired-mode-map "C" 'dired-do-copy)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1207 (define-key dired-mode-map "E" 'dired-do-grep)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1208 (define-key dired-mode-map "F" 'dired-do-find-file)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1209 (define-key dired-mode-map "G" 'dired-do-chgrp)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1210 (define-key dired-mode-map "H" 'dired-do-hardlink)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1211 (define-key dired-mode-map "I" 'dired-do-insert-subdir)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1212 (define-key dired-mode-map "K" 'dired-do-kill-file-lines)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1213 (define-key dired-mode-map "L" 'dired-do-load)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1214 (define-key dired-mode-map "M" 'dired-do-chmod)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1215 (define-key dired-mode-map "N" 'dired-do-redisplay)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1216 (define-key dired-mode-map "O" 'dired-do-chown)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1217 (define-key dired-mode-map "P" 'dired-do-print)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1218 (define-key dired-mode-map "Q" 'dired-do-tags-query-replace)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1219 (define-key dired-mode-map "R" 'dired-do-rename)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1220 (define-key dired-mode-map "S" 'dired-do-symlink)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1221 (define-key dired-mode-map "T" 'dired-do-total-size)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1222 (define-key dired-mode-map "U" 'dired-do-uucode)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1223 (define-key dired-mode-map "W" 'dired-copy-filenames-as-kill)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1224 (define-key dired-mode-map "X" 'dired-do-delete)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1225 (define-key dired-mode-map "Y" 'dired-do-relsymlink)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1226 (define-key dired-mode-map "Z" 'dired-do-compress)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1227 (define-key dired-mode-map "!" 'dired-do-shell-command)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1228 (define-key dired-mode-map "&" 'dired-do-background-shell-command)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1229 ;; Make all regexp commands share a `%' prefix:
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1230 (define-key dired-mode-map "%" 'dired-regexp-prefix)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1231 ;; Lower keys for commands not operating on all the marked files
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1232 (define-key dired-mode-map "a" 'dired-apropos)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1233 (define-key dired-mode-map "c" 'dired-change-marks)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1234 (define-key dired-mode-map "d" 'dired-flag-file-deletion)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1235 (define-key dired-mode-map "\C-d" 'dired-flag-file-deletion-backup)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1236 (define-key dired-mode-map "e" 'dired-find-file)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1237 (define-key dired-mode-map "f" 'dired-advertised-find-file)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1238 (define-key dired-mode-map "g" 'revert-buffer)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1239 (define-key dired-mode-map "h" 'dired-describe-mode)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1240 (define-key dired-mode-map "i" 'dired-maybe-insert-subdir)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1241 (define-key dired-mode-map "k" 'dired-kill-subdir)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1242 (define-key dired-mode-map "m" 'dired-mark)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1243 (define-key dired-mode-map "o" 'dired-find-file-other-window)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1244 (define-key dired-mode-map "q" 'dired-quit)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1245 (define-key dired-mode-map "r" 'dired-read-mail)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1246 (define-key dired-mode-map "s" 'dired-sort-toggle-or-edit)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1247 (define-key dired-mode-map "t" 'dired-get-target-directory)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1248 (define-key dired-mode-map "u" 'dired-unmark)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1249 (define-key dired-mode-map "v" 'dired-view-file)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1250 (define-key dired-mode-map "w" (if (fboundp 'find-file-other-frame)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1251 'dired-find-file-other-frame
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1252 'dired-find-file-other-window))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1253 (define-key dired-mode-map "x" 'dired-expunge-deletions)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1254 (define-key dired-mode-map "y" 'dired-why)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1255 (define-key dired-mode-map "+" 'dired-create-directory)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1256 (define-key dired-mode-map "`" 'dired-recover-file)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1257 ;; dired-jump-back Should be in the global map, but put them here
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1258 ;; too anyway.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1259 (define-key dired-mode-map "\C-x\C-j" 'dired-jump-back)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1260 (define-key dired-mode-map "\C-x4\C-j" 'dired-jump-back-other-window)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1261 (define-key dired-mode-map "\C-x5\C-j" 'dired-jump-back-other-frame)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1262 ;; Comparison commands
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1263 (define-key dired-mode-map "=" 'dired-diff-prefix)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1264 ;; moving
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1265 (define-key dired-mode-map "<" 'dired-prev-dirline)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1266 (define-key dired-mode-map ">" 'dired-next-dirline)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1267 (define-key dired-mode-map " " 'dired-next-line)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1268 (define-key dired-mode-map "n" 'dired-next-line)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1269 (define-key dired-mode-map "\C-n" 'dired-next-line)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1270 (define-key dired-mode-map "p" 'dired-previous-line)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1271 (define-key dired-mode-map "\C-p" 'dired-previous-line)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1272 (define-key dired-mode-map "\C-v" 'dired-scroll-up)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1273 (define-key dired-mode-map "\M-v" 'dired-scroll-down)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1274 (define-key dired-mode-map "\M-<" 'dired-beginning-of-buffer)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1275 (define-key dired-mode-map "\M->" 'dired-end-of-buffer)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1276 (define-key dired-mode-map "\C-m" 'dired-advertised-find-file)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1277 ;; motion by subdirectories
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1278 (define-key dired-mode-map "^" 'dired-up-directory)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1279 (define-key dired-mode-map "\M-\C-u" 'dired-up-directory)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1280 (define-key dired-mode-map "\M-\C-d" 'dired-down-directory)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1281 (define-key dired-mode-map "\M-\C-n" 'dired-advertised-next-subdir)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1282 (define-key dired-mode-map "\M-\C-p" 'dired-advertised-prev-subdir)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1283 (define-key dired-mode-map "\C-j" 'dired-goto-subdir)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1284 ;; move to marked files
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1285 (define-key dired-mode-map "\M-p" 'dired-prev-marked-file)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1286 (define-key dired-mode-map "\M-n" 'dired-next-marked-file)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1287 ;; hiding
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1288 (define-key dired-mode-map "$" 'dired-hide-subdir)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1289 (define-key dired-mode-map "\M-$" 'dired-hide-all)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1290 ;; omitting
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1291 (define-key dired-mode-map "\C-o" 'dired-omit-toggle)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1292 ;; markers
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1293 (define-key dired-mode-map "\(" 'dired-set-marker-char)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1294 (define-key dired-mode-map "\)" 'dired-restore-marker-char)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1295 (define-key dired-mode-map "'" 'dired-marker-stack-left)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1296 (define-key dired-mode-map "\\" 'dired-marker-stack-right)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1297 ;; misc
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1298 (define-key dired-mode-map "\C-i" 'dired-mark-prefix)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1299 (define-key dired-mode-map "?" 'dired-summary)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1300 (define-key dired-mode-map "\177" 'dired-backup-unflag)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1301 (define-key dired-mode-map "\C-_" 'dired-undo)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1302 (define-key dired-mode-map "\C-xu" 'dired-undo)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1303 (define-key dired-mode-map "\M-\C-?" 'dired-unmark-all-files)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1304 ;; The subdir map
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1305 (define-key dired-mode-map "|" 'dired-subdir-prefix)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1306 ;; efs submap
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1307 (define-key dired-mode-map "\M-e" 'efs-dired-prefix))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1308
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1309
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1310
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1311 ;;;;------------------------------------------------------------------
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1312 ;;;; The dired command
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1313 ;;;;------------------------------------------------------------------
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1314
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1315 ;;; User commands:
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1316 ;;; All of these commands should have a binding in the global keymap.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1317
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1318 ;;;###autoload (define-key ctl-x-map "d" 'dired)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1319 ;;;###autoload
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1320 (defun dired (dirname &optional switches)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1321 "\"Edit\" directory DIRNAME--delete, rename, print, etc. some files in it.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1322 Optional second argument SWITCHES specifies the `ls' options used.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1323 \(Interactively, use a prefix argument to be able to specify SWITCHES.)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1324 Dired displays a list of files in DIRNAME (which may also have
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1325 shell wildcards appended to select certain files). If DIRNAME is a cons,
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1326 its first element is taken as the directory name and the resr as an explicit
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1327 list of files to make directory entries for.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1328 \\<dired-mode-map>\
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1329 You can move around in it with the usual commands.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1330 You can flag files for deletion with \\[dired-flag-file-deletion] and then
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1331 delete them by typing \\[dired-expunge-deletions].
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1332 Type \\[dired-describe-mode] after entering dired for more info.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1333
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1334 If DIRNAME is already in a dired buffer, that buffer is used without refresh."
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1335 ;; Cannot use (interactive "D") because of wildcards.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1336 (interactive (dired-read-dir-and-switches ""))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1337 (switch-to-buffer (dired-noselect dirname switches)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1338
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1339 ;;;###autoload (define-key ctl-x-4-map "d" 'dired-other-window)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1340 ;;;###autoload
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1341 (defun dired-other-window (dirname &optional switches)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1342 "\"Edit\" directory DIRNAME. Like `dired' but selects in another window."
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1343 (interactive (dired-read-dir-and-switches "in other window "))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1344 (switch-to-buffer-other-window (dired-noselect dirname switches)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1345
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1346 ;;;###autoload (define-key ctl-x-5-map "d" 'dired-other-frame)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1347 ;;;###autoload
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1348 (defun dired-other-frame (dirname &optional switches)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1349 "\"Edit\" directory DIRNAME. Like `dired' but makes a new frame."
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1350 (interactive (dired-read-dir-and-switches "in other frame "))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1351 (switch-to-buffer-other-frame (dired-noselect dirname switches)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1352
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1353 ;;;###autoload
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1354 (defun dired-noselect (dir-or-list &optional switches)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1355 "Like `dired' but returns the dired buffer as value, does not select it."
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1356 (or dir-or-list (setq dir-or-list (expand-file-name default-directory)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1357 ;; This loses the distinction between "/foo/*/" and "/foo/*" that
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1358 ;; some shells make:
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1359 (let (dirname)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1360 (if (consp dir-or-list)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1361 (setq dirname (car dir-or-list))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1362 (setq dirname dir-or-list))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1363 (setq dirname (expand-file-name (directory-file-name dirname)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1364 (if (file-directory-p dirname)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1365 (setq dirname (file-name-as-directory dirname)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1366 (if (consp dir-or-list)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1367 (setq dir-or-list (cons dirname (cdr dir-or-list)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1368 (setq dir-or-list dirname))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1369 (dired-internal-noselect dir-or-list switches)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1370
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1371 ;; Adapted from code by wurgler@zippysun.math.uakron.edu (Tom Wurgler).
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1372 ;;;###autoload (define-key ctl-x-map "\C-j" 'dired-jump-back)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1373 ;;;###autoload
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1374 (defun dired-jump-back ()
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1375 "Jump back to dired.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1376 If in a file, dired the current directory and move to file's line.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1377 If in dired already, pop up a level and goto old directory's line.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1378 In case the proper dired file line cannot be found, refresh the dired
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1379 buffer and try again."
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1380 (interactive)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1381 (let* ((file (if (eq major-mode 'dired-mode)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1382 (directory-file-name (dired-current-directory))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1383 buffer-file-name))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1384 (dir (if file
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1385 (file-name-directory file)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1386 default-directory)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1387 (dired dir)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1388 (if file (dired-really-goto-file file))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1389
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1390 ;;;###autoload (define-key ctl-x-4-map "\C-j" 'dired-jump-back-other-window)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1391 ;;;###autoload
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1392 (defun dired-jump-back-other-window ()
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1393 "Like \\[dired-jump-back], but to other window."
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1394 (interactive)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1395 (let* ((file (if (eq major-mode 'dired-mode)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1396 (directory-file-name (dired-current-directory))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1397 buffer-file-name))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1398 (dir (if file
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1399 (file-name-directory file)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1400 default-directory)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1401 (dired-other-window dir)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1402 (if file (dired-really-goto-file file))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1403
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1404 ;;;###autoload (define-key ctl-x-5-map "\C-j" 'dired-jump-back-other-frame)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1405 ;;;###autoload
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1406 (defun dired-jump-back-other-frame ()
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1407 "Like \\[dired-jump-back], but in another frame."
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1408 (interactive)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1409 (let* ((file (if (eq major-mode 'dired-mode)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1410 (directory-file-name (dired-current-directory))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1411 buffer-file-name))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1412 (dir (if file
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1413 (file-name-directory file)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1414 default-directory)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1415 (dired-other-frame dir)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1416 (if file (dired-really-goto-file file))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1417
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1418 ;;; Dired mode
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1419
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1420 ;; Dired mode is suitable only for specially formatted data.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1421 (put 'dired-mode 'mode-class 'special)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1422
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1423 (defun dired-mode (&optional dirname switches)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1424 "\\<dired-mode-map>Dired mode is for \"editing\" directory trees.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1425
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1426 For a simple one-line help message, type \\[dired-summary]
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1427 For a moderately detailed description of dired mode, type \\[dired-describe-mode]
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1428 For the full dired info tree, type \\[universal-argument] \\[dired-describe-mode]"
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1429 ;; Not to be called interactively (e.g. dired-directory will be set
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1430 ;; to default-directory, which is wrong with wildcards).
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1431 (kill-all-local-variables)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1432 (use-local-map dired-mode-map)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1433 (setq major-mode 'dired-mode
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1434 mode-name "Dired"
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1435 case-fold-search nil
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1436 buffer-read-only t
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1437 selective-display t ; for subdirectory hiding
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1438 selective-display-ellipses nil ; for omit toggling
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1439 mode-line-buffer-identification '("Dired: %12b")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1440 mode-line-modified (format dired-mode-line-modified "--" "--" "-")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1441 dired-directory (expand-file-name (or dirname default-directory))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1442 dired-internal-switches (dired-make-switches-list
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1443 (or switches dired-listing-switches)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1444 (dired-advertise) ; default-directory is already set
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1445 (set (make-local-variable 'revert-buffer-function)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1446 (function dired-revert))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1447 (set (make-local-variable 'default-directory-function)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1448 'dired-current-directory)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1449 (set (make-local-variable 'page-delimiter)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1450 "\n\n")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1451 (set (make-local-variable 'list-buffers-directory)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1452 dired-directory)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1453 ;; Will only do something in Emacs 19.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1454 (add-hook (make-local-variable 'kill-buffer-hook)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1455 'dired-unadvertise-current-buffer)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1456 ;; Same here
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1457 (if window-system
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1458 (add-hook (make-local-variable 'post-command-hook)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1459 (function
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1460 (lambda ()
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1461 (if (memq this-command dired-modeline-tracking-cmds)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1462 (dired-update-mode-line t))))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1463 (dired-sort-other dired-internal-switches t)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1464 (dired-hack-local-variables)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1465 (run-hooks 'dired-mode-hook)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1466 ;; Run this after dired-mode-hook, in case that hook makes changes to
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1467 ;; the keymap.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1468 (dired-grok-keymap))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1469
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1470 ;;; Internal functions for starting dired
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1471
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1472 (defun dired-read-dir-and-switches (str)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1473 ;; For use in interactive.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1474 (reverse (list
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1475 (if current-prefix-arg
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1476 (read-string "Dired listing switches: "
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1477 dired-listing-switches))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1478 (let ((default-directory (default-directory)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1479 (read-file-name (format "Dired %s(directory): " str)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1480 nil default-directory nil)))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1481
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1482 (defun dired-hack-local-variables ()
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1483 "Parse, bind or evaluate any local variables for current dired buffer.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1484 See variable `dired-local-variables-file'."
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1485 (if (and dired-local-variables-file
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1486 (file-exists-p dired-local-variables-file))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1487 (let (buffer-read-only opoint )
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1488 (save-excursion
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1489 (goto-char (point-max))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1490 (setq opoint (point-marker))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1491 (insert "\^L\n")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1492 (insert-file-contents dired-local-variables-file))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1493 (let ((buffer-file-name dired-local-variables-file))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1494 (condition-case err
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1495 (hack-local-variables)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1496 (error (message "Error in dired-local-variables-file: %s" err)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1497 (sit-for 1))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1498 ;; Must delete it as (eobp) is often used as test for last
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1499 ;; subdir in dired.el.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1500 (delete-region opoint (point-max))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1501 (set-marker opoint nil))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1502
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1503 ;; Separate function from dired-noselect for the sake of dired-vms.el.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1504 (defun dired-internal-noselect (dir-or-list &optional switches mode)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1505 ;; If there is an existing dired buffer for DIRNAME, just leave
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1506 ;; buffer as it is (don't even call dired-revert).
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1507 ;; This saves time especially for deep trees or with efs.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1508 ;; The user can type `g'easily, and it is more consistent with find-file.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1509 ;; But if SWITCHES are given they are probably different from the
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1510 ;; buffer's old value, so call dired-sort-other, which does
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1511 ;; revert the buffer.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1512 ;; If the user specifies a directory with emacs startup, eg.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1513 ;; emacs ~, dir-or-list may be unexpanded at this point.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1514
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1515 (let* ((dirname (expand-file-name (if (consp dir-or-list)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1516 (car dir-or-list)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1517 dir-or-list)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1518 (buffer (dired-find-buffer-nocreate dir-or-list mode))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1519 ;; note that buffer already is in dired-mode, if found
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1520 (new-buffer-p (not buffer))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1521 (old-buf (current-buffer))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1522 wildcard)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1523 (or buffer
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1524 (let ((default-major-mode 'fundamental-mode))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1525 ;; We don't want default-major-mode to run hooks and set auto-fill
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1526 ;; or whatever, now that dired-mode does not
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1527 ;; kill-all-local-variables any longer.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1528 (setq buffer (create-file-buffer (directory-file-name dirname)))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1529 (set-buffer buffer)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1530 (if (not new-buffer-p) ; existing buffer ...
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1531 (progn
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1532 (if switches
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1533 (dired-sort-other
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1534 (if (stringp switches)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1535 (dired-make-switches-list switches)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1536 switches)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1537 (if dired-verify-modtimes (dired-verify-modtimes))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1538 (if (and dired-find-subdir
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1539 (not (string-equal (dired-current-directory)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1540 (file-name-as-directory dirname))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1541 (dired-initial-position dirname)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1542 ;; Else a new buffer
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1543 (if (file-directory-p dirname)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1544 (setq default-directory dirname
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1545 wildcard (consp dir-or-list))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1546 (setq default-directory (file-name-directory dirname)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1547 wildcard t))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1548 (or switches (setq switches dired-listing-switches))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1549 (dired-mode dirname switches)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1550 ;; default-directory and dired-internal-switches are set now
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1551 ;; (buffer-local), so we can call dired-readin:
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1552 (let ((failed t))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1553 (unwind-protect
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1554 (progn (dired-readin dir-or-list buffer wildcard)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1555 (setq failed nil))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1556 ;; dired-readin can fail if parent directories are inaccessible.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1557 ;; Don't leave an empty buffer around in that case.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1558 (if failed (kill-buffer buffer))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1559 ;; No need to narrow since the whole buffer contains just
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1560 ;; dired-readin's output, nothing else. The hook can
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1561 ;; successfully use dired functions (e.g. dired-get-filename)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1562 ;; as the subdir-alist has been built in dired-readin.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1563 (run-hooks 'dired-after-readin-hook)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1564 ;; I put omit-expunge after the dired-after-readin-hook
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1565 ;; in case that hook marks files. Does this make sense? Also, users
138
6608ceec7cf8 Import from CVS: tag r20-2b3
cvs
parents: 118
diff changeset
1566 ;; might want to set dired-omit-files in some incredibly clever
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1567 ;; way depending on the contents of the directory... I don't know...
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1568 (if dired-omit-files
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1569 (dired-omit-expunge nil t))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1570 (goto-char (point-min))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1571 (dired-initial-position dirname))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1572 (set-buffer old-buf)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1573 buffer))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1574
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1575 (defun dired-find-buffer-nocreate (dir-or-list &optional mode)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1576 ;; Returns a dired buffer for DIR-OR-LIST. DIR-OR-LIST may be wildcard,
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1577 ;; or a directory and alist of files.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1578 ;; If dired-find-subdir is non-nil, is satisfied with a dired
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1579 ;; buffer containing DIR-OR-LIST as a subdirectory. If there is more
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1580 ;; than one candidate, returns the most recently used.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1581 (if dired-find-subdir
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1582 (let ((buffers (sort (delq (current-buffer)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1583 (dired-buffers-for-dir dir-or-list t))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1584 (function dired-buffer-more-recently-used-p))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1585 (or (car buffers)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1586 ;; Couldn't find another buffer. Will the current one do?
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1587 ;; It is up dired-initial-position to actually go to the subdir.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1588 (and (or (equal dir-or-list dired-directory) ; covers wildcards
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1589 (and (stringp dir-or-list)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1590 (not (string-equal
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1591 dir-or-list
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1592 (expand-file-name default-directory)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1593 (assoc (file-name-as-directory dir-or-list)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1594 dired-subdir-alist)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1595 (current-buffer))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1596 ;; Else just look through the buffer list.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1597 (let (found (blist (buffer-list)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1598 (or mode (setq mode 'dired-mode))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1599 (save-excursion
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1600 (while blist
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1601 (set-buffer (car blist))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1602 (if (and (eq major-mode mode)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1603 (equal dired-directory dir-or-list))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1604 (setq found (car blist)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1605 blist nil)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1606 (setq blist (cdr blist)))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1607 found)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1608
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1609 (defun dired-initial-position (dirname)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1610 ;; Where point should go in a new listing of DIRNAME.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1611 ;; Point assumed at beginning of new subdir line.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1612 (end-of-line)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1613 (if dired-find-subdir (dired-goto-subdir dirname))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1614 (if dired-trivial-filenames (dired-goto-next-nontrivial-file))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1615 (dired-update-mode-line t))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1616
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1617 (defun dired-readin (dir-or-list buffer &optional wildcard)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1618 ;; Read in a new dired buffer
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1619 ;; dired-readin differs from dired-insert-subdir in that it accepts
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1620 ;; wildcards, erases the buffer, and builds the subdir-alist anew
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1621 ;; (including making it buffer-local and clearing it first).
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1622 ;; default-directory and dired-internal-switches must be buffer-local
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1623 ;; and initialized by now.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1624 ;; Thus we can test (equal default-directory dirname) instead of
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1625 ;; (file-directory-p dirname) and save a filesystem transaction.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1626 ;; This is wrong, if dired-before-readin-hook changes default-directory
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1627 ;; Also, we can run this hook which may want to modify the switches
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1628 ;; based on default-directory, e.g. with efs to a SysV host
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1629 ;; where ls won't understand -Al switches.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1630 (let (dirname other-dirs)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1631 (if (consp dir-or-list)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1632 (setq dir-or-list (dired-frob-dir-list dir-or-list)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1633 other-dirs (cdr dir-or-list)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1634 dir-or-list (car dir-or-list)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1635 dirname (car dir-or-list))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1636 (setq dirname dir-or-list))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1637 (setq dirname (expand-file-name dirname))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1638 (if (consp dir-or-list)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1639 (setq dir-or-list (cons dirname (cdr dir-or-list))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1640 (save-excursion
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1641 (set-buffer buffer)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1642 (run-hooks 'dired-before-readin-hook)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1643 (message "Reading directory %s..." dirname)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1644 (let (buffer-read-only)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1645 (widen)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1646 (erase-buffer)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1647 (dired-readin-insert dir-or-list wildcard)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1648 (dired-indent-listing (point-min) (point-max))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1649 ;; We need this to make the root dir have a header line as all
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1650 ;; other subdirs have:
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1651 (goto-char (point-min))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1652 (dired-insert-headerline (expand-file-name default-directory)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1653 (message "Reading directory %s...done" dirname)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1654 (set-buffer-modified-p nil)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1655 ;; Must first make alist buffer local and set it to nil because
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1656 ;; dired-build-subdir-alist will call dired-clear-alist first
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1657 (setq dired-subdir-alist nil)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1658 (if (memq ?R dired-internal-switches)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1659 (dired-build-subdir-alist)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1660 ;; no need to parse the buffer if listing is not recursive
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1661 (dired-simple-subdir-alist))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1662 (if other-dirs
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1663 (mapcar
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1664 (function
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1665 (lambda (x)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1666 (if (dired-in-this-tree (car x) dirname)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1667 (dired-insert-subdir x))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1668 other-dirs)))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1669
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1670 ;;; Subroutines of dired-readin
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1671
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1672 (defun dired-readin-insert (dir-or-list &optional wildcard)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1673 ;; Just insert listing for the passed-in directory or
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1674 ;; directory-and-file list, assuming a clean buffer.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1675 (let* ((switches (dired-make-switches-string dired-internal-switches))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1676 (dir-is-list (consp dir-or-list))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1677 (dirname (if dir-is-list (car dir-or-list) dir-or-list)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1678 (if wildcard
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1679 (progn
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1680 (or (file-readable-p
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1681 (if dir-is-list
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1682 dirname
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1683 (directory-file-name (file-name-directory dirname))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1684 (error "Directory %s inaccessible or nonexistent" dirname))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1685 ;; else assume it contains wildcards
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1686 (dired-insert-directory dir-or-list switches t)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1687 (save-excursion
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1688 ;; insert wildcard instead of total line:
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1689 (goto-char (point-min))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1690 (if dir-is-list
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1691 (insert "list wildcard\n")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1692 (insert "wildcard " (file-name-nondirectory dirname) "\n"))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1693 (dired-insert-directory dir-or-list switches nil t))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1694
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1695 (defun dired-insert-directory (dir-or-list switches &optional wildcard full-p)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1696 ;; Do the right thing whether dir-or-list is atomic or not. If it is,
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1697 ;; insert all files listed in the cdr -- the car is the passed-in directory
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1698 ;; list.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1699 (let ((opoint (point))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1700 (insert-directory-program dired-ls-program))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1701 (if (consp dir-or-list)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1702 (mapcar
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1703 (function
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1704 (lambda (x)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1705 (insert-directory x switches wildcard)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1706 (cdr dir-or-list))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1707 (insert-directory dir-or-list switches wildcard full-p))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1708 (dired-insert-set-properties opoint (point)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1709 (setq dired-directory dir-or-list))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1710
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1711 (defun dired-frob-dir-list (dir-list)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1712 (let* ((top (file-name-as-directory (expand-file-name (car dir-list))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1713 (tail (cdr dir-list))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1714 (result (list (list top)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1715 elt dir)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1716 (setq tail
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1717 (mapcar
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1718 (function
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1719 (lambda (x)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1720 (directory-file-name (expand-file-name x top))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1721 tail))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1722 (while tail
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1723 (setq dir (file-name-directory (car tail)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1724 (if (setq elt (assoc dir result))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1725 (nconc elt (list (car tail)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1726 (nconc result (list (list dir (car tail)))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1727 (setq tail (cdr tail)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1728 result))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1729
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1730 (defun dired-insert-headerline (dir);; also used by dired-insert-subdir
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1731 ;; Insert DIR's headerline with no trailing slash, exactly like ls
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1732 ;; would, and put cursor where dired-build-subdir-alist puts subdir
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1733 ;; boundaries.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1734 (save-excursion (insert " " (directory-file-name dir) ":\n")))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1735
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1736 (defun dired-verify-modtimes ()
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1737 ;; Check the modtimes of all subdirs.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1738 (let ((alist dired-subdir-alist)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1739 on-disk in-mem badies)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1740 (while alist
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1741 (and (setq in-mem (nth 4 (car alist)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1742 (setq on-disk (dired-file-modtime (car (car alist))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1743 (not (equal in-mem on-disk))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1744 (setq badies (cons (cons (car (car alist))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1745 (nth 3 (car alist)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1746 badies)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1747 (setq alist (cdr alist)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1748 (and badies
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1749 (let* ((ofile (dired-get-filename nil t))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1750 (osub (and (null ofile) (dired-get-subdir)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1751 (opoint (point))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1752 (ocol (current-column)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1753 (unwind-protect
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1754 (and
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1755 (or (memq 'revert-subdirs dired-no-confirm)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1756 (save-window-excursion
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1757 (let ((flist (mapcar
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1758 (function
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1759 (lambda (f)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1760 (dired-abbreviate-file-name (car f))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1761 badies)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1762 (switch-to-buffer (current-buffer))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1763 (dired-mark-pop-up
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1764 "*Stale Subdirectories*" 'revert-subdirs
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1765 flist 'y-or-n-p
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1766 (if (= (length flist) 1)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1767 (concat "Subdirectory " (car flist)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1768 " has changed on disk. Re-list? ")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1769 "Subdirectories have changed on disk. Re-list? "))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1770 )))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1771 (while badies
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1772 (dired-insert-subdir (car (car badies))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1773 (cdr (car badies)) nil t)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1774 (setq badies (cdr badies))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1775 ;; We can't use dired-save-excursion here, because we are
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1776 ;; rewriting the entire listing, and not just changing a single
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1777 ;; file line.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1778 (or (if ofile
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1779 (dired-goto-file ofile)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1780 (if osub
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1781 (dired-goto-subdir osub)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1782 (progn
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1783 (goto-char opoint)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1784 (beginning-of-line)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1785 (skip-chars-forward "^\n\r" (+ (point) ocol))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1786 (dired-update-mode-line t)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1787 (dired-update-mode-line-modified t))))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1788
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1789 (defun dired-indent-listing (start end)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1790 ;; Indent a dired listing.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1791 (let (indent-tabs-mode)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1792 (indent-rigidly start end 2)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1793 ;; Quote any null lines that shouldn't be.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1794 (save-excursion
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1795 (goto-char start)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1796 (while (search-forward "\n\n" end t)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1797 (forward-char -2)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1798 (if (looking-at dired-subdir-regexp)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1799 (goto-char (match-end 3))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1800 (progn
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1801 (forward-char 1)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1802 (insert " ")))))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1803
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1804
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1805 ;;;; ------------------------------------------------------------
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1806 ;;;; Reverting a dired buffer, or specific file lines within it.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1807 ;;;; ------------------------------------------------------------
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1808
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1809 (defun dired-revert (&optional arg noconfirm)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1810 ;; Reread the dired buffer. Must also be called after
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1811 ;; dired-internal-switches have changed.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1812 ;; Should not fail even on completely garbaged buffers.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1813 ;; Preserves old cursor, marks/flags, hidden-p.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1814 (widen) ; just in case user narrowed
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1815 (let ((opoint (point))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1816 (ofile (dired-get-filename nil t))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1817 (hidden-subdirs (dired-remember-hidden))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1818 ;; switches for top-level dir
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1819 (oswitches (or (nth 3 (nth (1- (length dired-subdir-alist))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1820 dired-subdir-alist))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1821 (delq ?R (copy-sequence dired-internal-switches))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1822 ;; all other subdirs
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1823 (old-subdir-alist (cdr (reverse dired-subdir-alist)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1824 (omitted-subdirs (dired-remember-omitted))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1825 ;; do this after dired-remember-hidden, since this unhides
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1826 (mark-alist (dired-remember-marks (point-min) (point-max)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1827 (kill-files-p (save-excursion
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1828 (goto-char (point))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1829 (search-forward
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1830 (concat (char-to-string ?\r)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1831 (regexp-quote
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1832 (char-to-string
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1833 dired-kill-marker-char)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1834 nil t)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1835 buffer-read-only)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1836 ;; This is bogus, as it will not handle all the ways that efs uses cache.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1837 ;; Better to just use the fact that revert-buffer-function is a
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1838 ;; buffer-local variable, and reset it to something that knows about
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1839 ;; cache.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1840 ;; (dired-uncache
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1841 ;; (if (consp dired-directory) (car dired-directory) dired-directory))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1842 ;; treat top level dir extra (it may contain wildcards)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1843 (let ((dired-after-readin-hook nil)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1844 ;; don't run that hook for each subdir...
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1845 (dired-omit-files nil)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1846 (dired-internal-switches oswitches))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1847 (dired-readin dired-directory (current-buffer)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1848 ;; Don't test for wildcards by checking string=
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1849 ;; default-directory and dired-directory
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1850 ;; in case default-directory got munged.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1851 (or (consp dired-directory)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1852 (null (file-directory-p dired-directory))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1853 ;; The R-switch will clobber sorting of subdirs.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1854 ;; What is the right thing to do here?
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1855 (dired-insert-old-subdirs old-subdir-alist))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1856 (dired-mark-remembered mark-alist) ; mark files that were marked
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1857 (if kill-files-p (dired-do-hide dired-kill-marker-char))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1858 (run-hooks 'dired-after-readin-hook) ; no need to narrow
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1859 ;; omit-expunge after the readin hook
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1860 (save-excursion
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1861 (mapcar (function (lambda (dir)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1862 (if (dired-goto-subdir dir)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1863 (dired-omit-expunge))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1864 omitted-subdirs))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1865 ;; hide subdirs that were hidden
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1866 (save-excursion
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1867 (mapcar (function (lambda (dir)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1868 (if (dired-goto-subdir dir)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1869 (dired-hide-subdir 1))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1870 hidden-subdirs))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1871 ;; Try to get back to where we were
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1872 (or (and ofile (dired-goto-file ofile))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1873 (goto-char opoint))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1874 (dired-move-to-filename)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1875 (dired-update-mode-line t)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1876 (dired-update-mode-line-modified t)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1877
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1878 (defun dired-do-redisplay (&optional arg)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1879 "Redisplay all marked (or next ARG) files."
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1880 (interactive "P")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1881 ;; message instead of making dired-map-over-marks show-progress is
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1882 ;; much faster
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1883 (dired-map-over-marks (let ((fname (dired-get-filename)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1884 (dired-uncache fname nil)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1885 (message "Redisplaying %s..." fname)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1886 (dired-update-file-line fname))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1887 arg)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1888 (dired-update-mode-line-modified t)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1889 (message "Redisplaying...done"))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1890
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1891 (defun dired-redisplay-subdir (&optional arg)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1892 "Redisplay the current subdirectory.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1893 With a prefix prompts for listing switches."
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1894 (interactive "P")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1895 (let ((switches (and arg (dired-make-switches-list
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1896 (read-string "Switches for listing: "
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1897 (dired-make-switches-string
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1898 dired-internal-switches)))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1899 (dir (dired-current-directory))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1900 (opoint (point))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1901 (ofile (dired-get-filename nil t)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1902 (or switches
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1903 (setq switches (nth 3 (assoc dir dired-subdir-alist))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1904 (or switches
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1905 (setq switches (delq ?R (copy-sequence dired-internal-switches))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1906 (message "Redisplaying %s..." dir)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1907 (dired-uncache dir t)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1908 (dired-insert-subdir dir switches)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1909 (dired-update-mode-line-modified t)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1910 (or (and ofile (dired-goto-file ofile)) (goto-char opoint))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1911 (message "Redisplaying %s... done" dir)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1912
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1913 (defun dired-update-file-line (file)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1914 ;; Delete the current line, and insert an entry for FILE.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1915 ;; Does not update other dired buffers. Use dired-relist-file for that.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1916 (let* ((start (save-excursion (skip-chars-backward "^\n\r") (point)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1917 (char (char-after start)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1918 (dired-save-excursion
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1919 ;; don't remember omit marks
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1920 (if (memq char (list ?\040 dired-omit-marker-char))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1921 (setq char nil))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1922 ;; Delete the current-line. Even though dired-add-entry will not
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1923 ;; insert duplicates, the file for the current line may not be the same as
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1924 ;; FILE. eg. dired-do-compress
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1925 (delete-region (save-excursion (skip-chars-backward "^\n\r") (1- (point)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1926 (progn (skip-chars-forward "^\n\r") (point)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1927 ;; dired-add-entry inserts at the end of the previous line.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1928 (forward-char 1)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1929 (dired-add-entry file char t))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1930
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1931 ;;; Subroutines of dired-revert
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1932 ;;; Some of these are also used when inserting subdirs.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1933
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1934 ;; Don't want to remember omit marks, in case omission regexps
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1935 ;; were changed, before the dired-revert. If we don't unhide
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1936 ;; omitted files, we won't see their marks. Therefore we use
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1937 ;; dired-omit-unhide-region.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1938
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1939 (defun dired-remember-marks (beg end)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1940 ;; Return alist of files and their marks, from BEG to END.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1941 (if selective-display ; must unhide to make this work.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1942 (let (buffer-read-only)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1943 (subst-char-in-region (point-min) (point-max) ?\r ?\n)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1944 (dired-do-hide dired-omit-marker-char)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1945 (let (fil chr alist)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1946 (save-excursion
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1947 (goto-char beg)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1948 (while (re-search-forward dired-re-mark end t)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1949 (if (setq fil (dired-get-filename nil t))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1950 (setq chr (preceding-char)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1951 alist (cons (cons fil chr) alist)))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1952 alist))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1953
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1954 (defun dired-mark-remembered (alist)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1955 ;; Mark all files remembered in ALIST.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1956 (let (elt fil chr)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1957 (while alist
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1958 (setq elt (car alist)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1959 alist (cdr alist)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1960 fil (car elt)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1961 chr (cdr elt))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1962 (if (dired-goto-file fil)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1963 (save-excursion
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1964 (beginning-of-line)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1965 (dired-substitute-marker (point) (following-char) chr))))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1966
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1967 (defun dired-remember-hidden ()
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1968 ;; Return a list of all hidden subdirs.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1969 (let ((l dired-subdir-alist) dir result min)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1970 (while l
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1971 (setq dir (car (car l))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1972 min (dired-get-subdir-min (car l))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1973 l (cdr l))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1974 (if (and (>= min (point-min)) (<= min (point-max))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1975 (dired-subdir-hidden-p dir))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1976 (setq result (cons dir result))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1977 result))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1978
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1979 (defun dired-insert-old-subdirs (old-subdir-alist)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1980 ;; Try to insert all subdirs that were displayed before
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1981 (let (elt dir switches)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1982 (while old-subdir-alist
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1983 (setq elt (car old-subdir-alist)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1984 old-subdir-alist (cdr old-subdir-alist)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1985 dir (car elt)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1986 switches (or (nth 3 elt) dired-internal-switches))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1987 (condition-case ()
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1988 (dired-insert-subdir dir switches)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1989 (error nil)))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1990
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1991 (defun dired-uncache (file dir-p)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1992 ;; Remove directory DIR from any directory cache.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1993 ;; If DIR-P is non-nil, then FILE is a directory
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1994 (let ((handler (find-file-name-handler file 'dired-uncache)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1995 (if handler
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1996 (funcall handler 'dired-uncache file dir-p))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1997
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1998
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
1999 ;;;; -------------------------------------------------------------
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2000 ;;;; Inserting subdirectories
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2001 ;;;; -------------------------------------------------------------
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2002
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2003 (defun dired-maybe-insert-subdir (dirname &optional
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2004 switches no-error-if-not-dir-p)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2005 "Insert this subdirectory into the same dired buffer.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2006 If it is already present, just move to it (type \\[dired-do-redisplay] to
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2007 refresh), else inserts it at its natural place (as ls -lR would have done).
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2008 With a prefix arg, you may edit the ls switches used for this listing.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2009 You can add `R' to the switches to expand the whole tree starting at
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2010 this subdirectory.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2011 This function takes some pains to conform to ls -lR output."
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2012 (interactive
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2013 (list (dired-get-filename)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2014 (if current-prefix-arg
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2015 (dired-make-switches-list
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2016 (read-string "Switches for listing: "
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2017 (dired-make-switches-string
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2018 dired-internal-switches))))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2019 (let ((opoint (point)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2020 ;; We don't need a marker for opoint as the subdir is always
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2021 ;; inserted *after* opoint.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2022 (setq dirname (file-name-as-directory dirname))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2023 (or (and (not switches)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2024 (dired-goto-subdir dirname))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2025 (dired-insert-subdir dirname switches no-error-if-not-dir-p))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2026 ;; Push mark so that it's easy to find back. Do this after the
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2027 ;; insert message so that the user sees the `Mark set' message.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2028 (push-mark opoint)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2029
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2030 (defun dired-insert-subdir (dir-or-list &optional
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2031 switches no-error-if-not-dir-p no-posn)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2032 "Insert this subdirectory into the same dired buffer.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2033 If it is already present, overwrites previous entry,
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2034 else inserts it at its natural place (as ls -lR would have done).
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2035 With a prefix arg, you may edit the ls switches used for this listing.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2036 You can add `R' to the switches to expand the whole tree starting at
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2037 this subdirectory.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2038 This function takes some pains to conform to ls -lR output."
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2039 ;; NO-ERROR-IF-NOT-DIR-P needed for special filesystems like
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2040 ;; Prospero where dired-ls does the right thing, but
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2041 ;; file-directory-p has not been redefined.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2042 ;; SWITCHES should be a list.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2043 ;; If NO-POSN is non-nil, doesn't bother position the point at
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2044 ;; the first nontrivial file line. This can be used as an efficiency
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2045 ;; hack when calling this from a program.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2046 (interactive
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2047 (list (dired-get-filename)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2048 (if current-prefix-arg
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2049 (dired-make-switches-list
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2050 (read-string "Switches for listing: "
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2051 (dired-make-switches-string
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2052 dired-internal-switches))))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2053 (let ((dirname (if (consp dir-or-list) (car dir-or-list) dir-or-list)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2054 (setq dirname (file-name-as-directory (expand-file-name dirname)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2055 (or (dired-in-this-tree dirname (expand-file-name default-directory))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2056 (error "%s: not in this directory tree" dirname))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2057 (or no-error-if-not-dir-p
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2058 (file-directory-p dirname)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2059 (error "Attempt to insert a non-directory: %s" dirname))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2060 (if switches
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2061 (or (dired-compatible-switches-p dired-internal-switches switches)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2062 (error "Cannot have subdirs with %s and %s switches together."
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2063 (dired-make-switches-string dired-internal-switches)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2064 (dired-make-switches-string switches)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2065 (setq switches dired-internal-switches))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2066 (let ((elt (assoc dirname dired-subdir-alist))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2067 mark-alist opoint-max buffer-read-only)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2068 (if (memq ?R switches)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2069 ;; avoid duplicated subdirs
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2070 (progn
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2071 (setq mark-alist (dired-kill-tree dirname t))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2072 (dired-insert-subdir-newpos dirname))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2073 (if elt
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2074 ;; If subdir is already present, remove it and remember its marks
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2075 (setq mark-alist (dired-insert-subdir-del elt))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2076 ;; else move to new position
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2077 (dired-insert-subdir-newpos dirname)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2078 (setq opoint-max (point-max))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2079 (condition-case nil
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2080 (dired-insert-subdir-doupdate
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2081 dirname (dired-insert-subdir-doinsert dir-or-list switches)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2082 switches elt mark-alist)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2083 (quit ; watch out for aborted inserts
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2084 (and (= opoint-max (point-max))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2085 (null elt)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2086 (= (preceding-char) ?\n)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2087 (delete-char -1))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2088 (signal 'quit nil))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2089 (or no-posn (dired-initial-position dirname))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2090
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2091 (defun dired-do-insert-subdir ()
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2092 "Insert all marked subdirectories in situ that are not yet inserted.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2093 Non-directories are silently ignored."
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2094 (interactive)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2095 (let ((files (or (dired-get-marked-files)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2096 (error "No files marked."))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2097 (while files
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2098 (if (file-directory-p (car files))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2099 (save-excursion (dired-maybe-insert-subdir (car files))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2100 (setq files (cdr files)))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2101
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2102 ;;; Utilities for inserting subdirectories
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2103
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2104 (defun dired-insert-subdir-newpos (new-dir)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2105 ;; Find pos for new subdir, according to tree order.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2106 (let ((alist dired-subdir-alist) elt dir new-pos)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2107 (while alist
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2108 (setq elt (car alist)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2109 alist (cdr alist)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2110 dir (car elt))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2111 (if (dired-tree-lessp dir new-dir)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2112 ;; Insert NEW-DIR after DIR
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2113 (setq new-pos (dired-get-subdir-max elt)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2114 alist nil)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2115 (goto-char new-pos))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2116 (insert "\n")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2117 (point))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2118
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2119 (defun dired-insert-subdir-del (element)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2120 ;; Erase an already present subdir (given by ELEMENT) from buffer.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2121 ;; Move to that buffer position. Return a mark-alist.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2122 (let ((begin-marker (dired-get-subdir-min element)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2123 (goto-char begin-marker)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2124 ;; Are at beginning of subdir (and inside it!). Now determine its end:
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2125 (goto-char (dired-subdir-max))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2126 (prog1
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2127 (dired-remember-marks begin-marker (point))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2128 (delete-region begin-marker (point)))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2129
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2130 (defun dired-insert-subdir-doinsert (dir-or-list switches)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2131 ;; Insert ls output after point and put point on the correct
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2132 ;; position for the subdir alist.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2133 ;; Return the boundary of the inserted text (as list of BEG and END).
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2134 ;; SWITCHES should be a non-nil list.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2135 (let ((begin (point))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2136 (dirname (if (consp dir-or-list) (car dir-or-list) dir-or-list))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2137 end)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2138 (message "Reading directory %s..." dirname)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2139 (if (string-equal dirname (car (car (reverse dired-subdir-alist))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2140 ;; top level directory may contain wildcards:
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2141 (let ((dired-internal-switches switches))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2142 (dired-readin-insert dired-directory
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2143 (null (file-directory-p dired-directory))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2144 (let ((switches (dired-make-switches-string switches))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2145 (insert-directory-program dired-ls-program))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2146 (if (consp dir-or-list)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2147 (progn
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2148 (insert "list wildcard\n")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2149 (mapcar
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2150 (function
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2151 (lambda (x)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2152 (insert-directory x switches t)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2153 (cdr dir-or-list)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2154 (insert-directory dirname switches nil t))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2155 (message "Reading directory %s...done" dirname)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2156 (setq end (point-marker))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2157 (dired-indent-listing begin end)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2158 (dired-insert-set-properties begin end)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2159 ;; call dired-insert-headerline afterwards, as under VMS dired-ls
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2160 ;; does insert the headerline itself and the insert function just
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2161 ;; moves point.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2162 ;; Need a marker for END as this inserts text.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2163 (goto-char begin)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2164 (dired-insert-headerline dirname)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2165 ;; point is now like in dired-build-subdir-alist
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2166 (prog1
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2167 (list begin (marker-position end))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2168 (set-marker end nil))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2169
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2170 (defun dired-insert-subdir-doupdate (dirname beg-end switches elt mark-alist)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2171 ;; Point is at the correct subdir alist position for ELT,
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2172 ;; BEG-END is the subdir-region (as list of begin and end).
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2173 ;; SWITCHES must be a non-nil list.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2174 (if (memq ?R switches)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2175 ;; This will remove ?R from switches on purpose.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2176 (let ((dired-internal-switches (delq ?R switches)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2177 (dired-build-subdir-alist))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2178 (if elt
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2179 (progn
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2180 (set-marker (dired-get-subdir-min elt) (point-marker))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2181 (setcar (nthcdr 3 elt) switches)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2182 (if dired-verify-modtimes
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2183 (dired-set-file-modtime dirname dired-subdir-alist)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2184 (dired-alist-add dirname (point-marker) dired-omit-files switches)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2185 (save-excursion
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2186 (let ((begin (nth 0 beg-end))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2187 (end (nth 1 beg-end)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2188 (goto-char begin)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2189 (save-restriction
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2190 (narrow-to-region begin end)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2191 ;; hook may add or delete lines, but the subdir boundary
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2192 ;; marker floats
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2193 (run-hooks 'dired-after-readin-hook)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2194 (if mark-alist (dired-mark-remembered mark-alist))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2195 (dired-do-hide dired-kill-marker-char)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2196 (if (if elt (nth 2 elt) dired-omit-files)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2197 (dired-omit-expunge nil t))))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2198
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2199
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2200 ;;;; --------------------------------------------------------------
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2201 ;;;; Dired motion commands -- moving around in the dired buffer.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2202 ;;;; --------------------------------------------------------------
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2203
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2204 (defun dired-next-line (arg)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2205 "Move down lines then position at filename.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2206 Optional prefix ARG says how many lines to move; default is one line."
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2207 (interactive "p")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2208 (condition-case err
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2209 (next-line arg)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2210 (error
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2211 (if (eobp)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2212 (error "End of buffer")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2213 (error "%s" err))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2214 (dired-move-to-filename)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2215 (dired-update-mode-line))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2216
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2217 (defun dired-previous-line (arg)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2218 "Move up lines then position at filename.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2219 Optional prefix ARG says how many lines to move; default is one line."
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2220 (interactive "p")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2221 (previous-line arg)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2222 (dired-move-to-filename)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2223 (dired-update-mode-line))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2224
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2225 (defun dired-scroll-up (arg)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2226 "Dired version of scroll up.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2227 Scroll text of current window upward ARG lines; or near full screen if no ARG.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2228 When calling from a program, supply a number as argument or nil."
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2229 (interactive "P")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2230 (scroll-up arg)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2231 (dired-move-to-filename)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2232 (dired-update-mode-line))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2233
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2234 (defun dired-scroll-down (arg)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2235 "Dired version of scroll-down.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2236 Scroll text of current window down ARG lines; or near full screen if no ARG.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2237 When calling from a program, supply a number as argument or nil."
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2238 (interactive "P")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2239 (scroll-down arg)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2240 (dired-move-to-filename)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2241 (dired-update-mode-line))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2242
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2243 (defun dired-beginning-of-buffer (arg)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2244 "Dired version of `beginning of buffer'."
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2245 (interactive "P")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2246 (beginning-of-buffer arg)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2247 (dired-update-mode-line))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2248
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2249 (defun dired-end-of-buffer (arg)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2250 "Dired version of `end-of-buffer'."
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2251 (interactive "P")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2252 (end-of-buffer arg)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2253 (while (not (or (dired-move-to-filename) (dired-get-subdir) (bobp)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2254 (forward-line -1))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2255 (dired-update-mode-line t))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2256
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2257 (defun dired-next-dirline (arg &optional opoint)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2258 "Goto ARG'th next directory file line."
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2259 (interactive "p")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2260 (if dired-re-dir
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2261 (progn
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2262 (dired-check-ls-l)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2263 (or opoint (setq opoint (point)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2264 (if (if (> arg 0)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2265 (re-search-forward dired-re-dir nil t arg)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2266 (beginning-of-line)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2267 (re-search-backward dired-re-dir nil t (- arg)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2268 (progn
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2269 (dired-move-to-filename) ; user may type `i' or `f'
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2270 (dired-update-mode-line))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2271 (goto-char opoint)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2272 (error "No more subdirectories")))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2273
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2274 (defun dired-prev-dirline (arg)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2275 "Goto ARG'th previous directory file line."
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2276 (interactive "p")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2277 (dired-next-dirline (- arg)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2278
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2279 (defun dired-next-marked-file (arg &optional wrap opoint)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2280 "Move to the next marked file, wrapping around the end of the buffer."
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2281 (interactive "p\np")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2282 (or opoint (setq opoint (point))) ; return to where interactively started
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2283 (if (if (> arg 0)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2284 (re-search-forward dired-re-mark nil t arg)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2285 (beginning-of-line)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2286 (re-search-backward dired-re-mark nil t (- arg)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2287 (dired-move-to-filename)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2288 (if (null wrap)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2289 (progn
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2290 (goto-char opoint)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2291 (error "No next marked file"))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2292 (message "(Wraparound for next marked file)")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2293 (goto-char (if (> arg 0) (point-min) (point-max)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2294 (dired-next-marked-file arg nil opoint)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2295 (dired-update-mode-line))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2296
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2297 (defun dired-prev-marked-file (arg &optional wrap)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2298 "Move to the previous marked file, wrapping around the end of the buffer."
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2299 (interactive "p\np")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2300 (dired-next-marked-file (- arg) wrap)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2301 (dired-update-mode-line))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2302
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2303 (defun dired-goto-file (file)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2304 "Goto file line of FILE in this dired buffer."
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2305 ;; Return value of point on success, else nil.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2306 ;; FILE must be an absolute pathname.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2307 ;; Loses if FILE contains control chars like "\007" for which ls
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2308 ;; either inserts "?" or "\\007" into the buffer, so we won't find
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2309 ;; it in the buffer.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2310 (interactive
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2311 (prog1 ; let push-mark display its message
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2312 (list
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2313 (let* ((dired-completer-buffer (current-buffer))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2314 (dired-completer-switches dired-internal-switches)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2315 (stack (reverse
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2316 (mapcar (function
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2317 (lambda (x)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2318 (dired-abbreviate-file-name (car x))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2319 dired-subdir-alist)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2320 (initial (car stack))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2321 (dired-goto-file-history (cdr stack))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2322 dired-completer-cache)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2323 (expand-file-name
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2324 (dired-completing-read "Goto file: "
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2325 'dired-goto-file-completer
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2326 nil t initial 'dired-goto-file-history))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2327 (push-mark)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2328 (setq file (directory-file-name file)) ; does no harm if no directory
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2329 (let (found case-fold-search)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2330 (save-excursion
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2331 (if (dired-goto-subdir (or (file-name-directory file)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2332 (error "Need absolute pathname for %s"
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2333 file)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2334 (let* ((base (file-name-nondirectory file))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2335 ;; filenames are preceded by SPC, this makes
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2336 ;; the search faster (e.g. for the filename "-"!).
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2337 (search (concat " " (dired-make-filename-string base t)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2338 (boundary (dired-subdir-max))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2339 fn)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2340 (while (and (not found) (search-forward search boundary 'move))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2341 ;; Match could have BASE just as initial substring or
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2342 ;; or in permission bits or date or
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2343 ;; not be a proper filename at all:
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2344 (if (and (setq fn (dired-get-filename 'no-dir t))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2345 (string-equal fn base))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2346 ;; Must move to filename since an (actually
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2347 ;; correct) match could have been elsewhere on the
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2348 ;; line (e.g. "-" would match somewhere in the
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2349 ;; permission bits).
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2350 (setq found (dired-move-to-filename)))))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2351 (and found
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2352 ;; return value of point (i.e., FOUND):
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2353 (prog1
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2354 (goto-char found)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2355 (dired-update-mode-line)))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2356
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2357 ;;; Moving by subdirectories
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2358
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2359 (defun dired-up-directory (arg)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2360 "Move to the ARG'th (prefix arg) parent directory of current directory.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2361 Always stays within the current tree dired buffer. Will insert new
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2362 subdirectories if necessary."
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2363 (interactive "p")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2364 (if (< arg 0) (error "Can't go up a negative number of directories!"))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2365 (or (zerop arg)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2366 (let* ((dir (dired-current-directory))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2367 (n arg)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2368 (up dir))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2369 (while (> n 0)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2370 (setq up (file-name-directory (directory-file-name up))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2371 n (1- n)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2372 (if (and (< (length up) (length dired-directory))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2373 (dired-in-this-tree dired-directory up))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2374 (if (or (memq 'create-top-dir dired-no-confirm)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2375 (y-or-n-p
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2376 (format "Insert new top dir %s and rename buffer? "
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2377 (dired-abbreviate-file-name up))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2378 (let ((newname (let (buff)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2379 (unwind-protect
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2380 (buffer-name
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2381 (setq buff
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2382 (create-file-buffer
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2383 (directory-file-name up))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2384 (kill-buffer buff))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2385 (buffer-read-only nil))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2386 (push-mark)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2387 (widen)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2388 (goto-char (point-min))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2389 (insert-before-markers "\n")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2390 (forward-char -1)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2391 (dired-insert-subdir-doupdate
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2392 up (dired-insert-subdir-doinsert up dired-internal-switches)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2393 dired-internal-switches nil nil)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2394 (dired-initial-position up)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2395 (rename-buffer newname)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2396 (dired-unadvertise default-directory)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2397 (setq default-directory up
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2398 dired-directory up)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2399 (dired-advertise)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2400 (dired-maybe-insert-subdir up)))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2401
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2402 (defun dired-down-directory ()
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2403 "Go down in the dired tree.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2404 Moves to the first subdirectory of the current directory, which exists in
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2405 the dired buffer. Does not take a prefix argument."
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2406 ;; What would a prefix mean here?
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2407 (interactive)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2408 (let ((dir (dired-current-directory)) ; has slash
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2409 (rest (reverse dired-subdir-alist))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2410 pos elt)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2411 (while rest
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2412 (setq elt (car rest))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2413 (if (dired-in-this-tree (directory-file-name (car elt)) dir)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2414 (setq rest nil
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2415 pos (dired-goto-subdir (car elt)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2416 (setq rest (cdr rest))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2417 (prog1
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2418 (if pos
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2419 (progn
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2420 (push-mark)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2421 (goto-char pos))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2422 (error "At the bottom"))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2423 (dired-update-mode-line t))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2424
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2425 (defun dired-next-subdir (arg &optional no-error-if-not-found no-skip)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2426 "Go to next subdirectory, regardless of level."
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2427 ;; Use 0 arg to go to this directory's header line.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2428 ;; NO-SKIP prevents moving to end of header line, returning whatever
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2429 ;; position was found in dired-subdir-alist.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2430 (interactive "p")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2431 (let ((this-dir (dired-current-directory))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2432 pos index)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2433 ;; nth with negative arg does not return nil but the first element
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2434 (setq index (- (length dired-subdir-alist)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2435 (length (memq (assoc this-dir dired-subdir-alist)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2436 dired-subdir-alist))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2437 arg))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2438 (setq pos (if (>= index 0)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2439 (dired-get-subdir-min (nth index dired-subdir-alist))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2440 (if pos
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2441 (if no-skip
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2442 (goto-char pos)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2443 (goto-char pos)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2444 (skip-chars-forward "^\r\n")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2445 (if (= (following-char) ?\r)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2446 (skip-chars-backward "." (- (point) 3)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2447 (dired-update-mode-line t)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2448 (point))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2449 (if no-error-if-not-found
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2450 nil ; return nil if not found
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2451 (error "%s directory" (if (> arg 0) "Last" "First"))))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2452
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2453 (defun dired-prev-subdir (arg &optional no-error-if-not-found no-skip)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2454 "Go to previous subdirectory, regardless of level.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2455 When called interactively and not on a subdir line, go to this subdir's line."
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2456 (interactive
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2457 (list (if current-prefix-arg
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2458 (prefix-numeric-value current-prefix-arg)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2459 ;; if on subdir start already, don't stay there!
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2460 (if (dired-get-subdir) 1 0))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2461 (dired-next-subdir (- arg) no-error-if-not-found no-skip))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2462
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2463 (defun dired-goto-subdir (dir)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2464 "Goto end of header line of DIR in this dired buffer.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2465 Return value of point on success, otherwise return nil.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2466 The next char is either \\n, or \\r if DIR is hidden."
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2467 (interactive
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2468 (prog1 ; let push-mark display its message
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2469 (list
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2470 (let* ((table (mapcar
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2471 (function
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2472 (lambda (x)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2473 (list (dired-abbreviate-file-name
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2474 (car x)))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2475 dired-subdir-alist))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2476 (stack (reverse (mapcar 'car table)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2477 (initial (car stack))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2478 (dired-goto-file-history (cdr stack)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2479 (expand-file-name
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2480 (dired-completing-read "Goto subdirectory " table nil t
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2481 initial 'dired-goto-file-history))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2482 (push-mark)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2483 (setq dir (file-name-as-directory dir))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2484 (let ((elt (assoc dir dired-subdir-alist)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2485 (and elt
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2486 ;; need to make sure that we get where we're going.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2487 ;; beware: narrowing might be in effect
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2488 (eq (goto-char (dired-get-subdir-min elt)) (point))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2489 (progn
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2490 ;; dired-subdir-hidden-p and dired-add-entry depend on point being
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2491 ;; at either \n or looking-at ...\r after this function succeeds.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2492 (skip-chars-forward "^\r\n")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2493 (if (= (preceding-char) ?.)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2494 (skip-chars-backward "." (- (point) 3)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2495 (if (interactive-p) (dired-update-mode-line))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2496 (point)))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2497
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2498 ;;; Internals for motion commands
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2499
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2500 (defun dired-update-mode-line (&optional force)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2501 "Updates the mode line in dired according to the position of the point.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2502 Normally this uses a cache of the boundaries of the current subdirectory,
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2503 but if the optional argument FORCE is non-nil, then modeline is always
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2504 updated and the cache is recomputed."
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2505 (if (or force
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2506 (>= (point) dired-curr-subdir-max)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2507 (< (point) dired-curr-subdir-min))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2508 (let ((alist dired-subdir-alist)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2509 min max)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2510 (while (and alist (< (point)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2511 (setq min (dired-get-subdir-min (car alist)))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2512 (setq alist (cdr alist)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2513 max min))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2514 (setq dired-curr-subdir-max (or max (point-max-marker))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2515 dired-curr-subdir-min (or min (point-min-marker))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2516 dired-subdir-omit (nth 2 (car alist)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2517 (dired-sort-set-modeline (nth 3 (car alist))))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2518
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2519 (defun dired-manual-move-to-filename (&optional raise-error bol eol)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2520 "In dired, move to first char of filename on this line.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2521 Returns position (point) or nil if no filename on this line."
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2522 ;; This is the UNIX version.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2523 ;; have to be careful that we don't move to omitted files
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2524 (let (case-fold-search)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2525
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2526 (or eol (setq eol (save-excursion (skip-chars-forward "^\r\n") (point))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2527 (or bol (setq bol (progn (skip-chars-backward "^\r\n") (point))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2528
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2529 (if (or (memq ?l dired-internal-switches)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2530 (memq ?g dired-internal-switches))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2531 (if (and
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2532 (> (- eol bol) 17) ; a valid file line must have at least
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2533 ; 17 chars. 2 leading, 10 perms,
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2534 ; separator, node #, separator, owner,
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2535 ; separator
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2536 (goto-char (+ bol 17))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2537 (re-search-forward dired-re-month-and-time eol t))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2538 (point)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2539 (goto-char bol)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2540 (if raise-error
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2541 (error "No file on this line")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2542 nil))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2543 ;; else ls switches don't contain -l.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2544 ;; Note that even if we make dired-move-to-filename and
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2545 ;; dired-move-to-end-of-filename (and thus dired-get-filename)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2546 ;; work, all commands that gleaned information from the permission
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2547 ;; bits (like dired-mark-directories) will cease to work properly.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2548 (if (= bol eol)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2549 (if raise-error
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2550 (error "No file on this line")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2551 nil)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2552 ;; skip marker, if any
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2553 (goto-char bol)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2554 (forward-char))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2555 ;; If we not going to use the l switch, and use nstd listings,
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2556 ;; then we must bomb on files starting with spaces.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2557 (skip-chars-forward " \t")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2558 (point))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2559
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2560 (defun dired-manual-move-to-end-of-filename (&optional no-error bol eol)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2561 ;; Assumes point is at beginning of filename,
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2562 ;; thus the rwx bit re-search-backward below will succeed in *this*
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2563 ;; line if at all. So, it should be called only after
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2564 ;; (dired-move-to-filename t).
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2565 ;; On failure, signals an error (with non-nil NO-ERROR just returns nil).
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2566 ;; This is the UNIX version.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2567 (let ((bof (point))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2568 file-type modes-start case-fold-search)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2569 (or eol (setq eol (save-excursion (skip-chars-forward "^\r\n") (point))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2570 (or bol (setq bol (save-excursion (skip-chars-backward "^\r\n") (point))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2571 (and
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2572 (null no-error)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2573 selective-display
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2574 (eq (char-after (1- bol)) ?\r)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2575 (cond
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2576 ((dired-subdir-hidden-p (dired-current-directory))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2577 (error
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2578 (substitute-command-keys
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2579 "File line is hidden. Type \\[dired-hide-subdir] to unhide.")))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2580 ((error
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2581 (substitute-command-keys
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2582 "File line is omitted. Type \\[dired-omit-toggle] to un-omit.")))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2583 (if (or (memq ?l dired-internal-switches)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2584 (memq ?g dired-internal-switches))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2585 (if (save-excursion
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2586 (goto-char bol)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2587 (re-search-forward
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2588 "[^ ][-r][-w][^ ][-r][-w][^ ][-r][-w][^ ][-+ 0-9+]"
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2589 bof t))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2590 (progn
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2591 (setq modes-start (match-beginning 0)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2592 file-type (char-after modes-start))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2593 ;; Move point to end of name:
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2594 (if (eq file-type ?l) ; symlink
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2595 (progn
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2596 (if (search-forward " -> " eol t)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2597 (goto-char (match-beginning 0))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2598 (goto-char eol))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2599 (and dired-ls-F-marks-symlinks
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2600 (eq (preceding-char) ?@) ; link really marked?
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2601 (memq ?F dired-internal-switches)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2602 (forward-char -1))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2603 (point))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2604 ;; else not a symbolic link
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2605 (goto-char eol)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2606 ;; ls -lF marks dirs, sockets and executables with exactly
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2607 ;; one trailing character. -F may not actually be honored,
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2608 ;; e.g. by an FTP ls in efs
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2609 (and
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2610 (memq ?F dired-internal-switches)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2611 (let ((char (preceding-char)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2612 (or (and (eq char ?*) (or
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2613 (memq
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2614 (char-after (+ modes-start 3))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2615 '(?x ?s ?t))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2616 (memq
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2617 (char-after (+ modes-start 6))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2618 '(?x ?s ?t))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2619 (memq
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2620 (char-after (+ modes-start 9))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2621 '(?x ?s ?t))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2622 (and (eq char ?=) (eq file-type ?s))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2623 (forward-char -1))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2624 ;; Skip back over /'s unconditionally. It's not a valid
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2625 ;; file name character.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2626 (skip-chars-backward "/")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2627 (point)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2628 (and (null no-error)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2629 (error "No file on this line")))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2630
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2631 ;; A brief listing
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2632 (if (eq (point) eol)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2633 (and (null no-error)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2634 (error "No file on this line"))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2635 (goto-char eol)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2636 (if (and (memq (preceding-char) '(?@ ?* ?=))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2637 (memq ?F dired-internal-switches))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2638 ;; A guess, since without a long listing, we can't be sure.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2639 (forward-char -1))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2640 (skip-chars-backward "/")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2641 (point)))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2642
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2643 (defun dired-goto-next-nontrivial-file ()
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2644 ;; Position point on first nontrivial file after point.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2645 ;; Does not move into the next sudir.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2646 ;; If point is on a file line, moves to that file.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2647 ;; This does not move to omitted files.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2648 (skip-chars-backward "^\n\r")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2649 (if (= (preceding-char) ?\r)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2650 (forward-line 1))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2651 (let ((max (dired-subdir-max))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2652 file)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2653 (while (and (or (not (setq file (dired-get-filename 'no-dir t)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2654 (string-match dired-trivial-filenames file))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2655 (< (point) max))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2656 (forward-line 1)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2657 (dired-move-to-filename))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2658
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2659 (defun dired-goto-next-file ()
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2660 ;; Doesn't move out of current subdir. Does go to omitted files.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2661 ;; Returns the starting position of the file, or nil if none found.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2662 (let ((max (dired-subdir-max))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2663 found)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2664 (while (and (null (setq found (dired-move-to-filename))) (< (point) max))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2665 (skip-chars-forward "^\n\r")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2666 (forward-char 1))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2667 found))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2668
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2669 ;; fluid vars used by dired-goto-file-completer
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2670 (defvar dired-completer-buffer nil)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2671 (defvar dired-completer-switches nil)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2672 (defvar dired-completer-cache nil)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2673
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2674 (defun dired-goto-file-completer (string pred action)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2675 (save-excursion
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2676 (set-buffer dired-completer-buffer)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2677 (let* ((saved-md (match-data))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2678 (file (file-name-nondirectory string))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2679 (dir (file-name-directory string))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2680 (xstring (expand-file-name string))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2681 (xdir (file-name-directory xstring))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2682 (exact (dired-goto-file xstring)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2683 (unwind-protect
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2684 (if (dired-goto-subdir xdir)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2685 (let ((table (cdr (assoc xdir dired-completer-cache)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2686 fn result max)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2687 (or table
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2688 (progn
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2689 (setq table (make-vector 37 0))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2690 (mapcar (function
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2691 (lambda (ent)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2692 (setq ent (directory-file-name
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2693 (car ent)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2694 (if (string-equal
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2695 (file-name-directory ent) xdir)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2696 (intern
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2697 (concat
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2698 (file-name-nondirectory ent) "/")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2699 table))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2700 dired-subdir-alist)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2701 (or (looking-at "\\.\\.\\.\n\r")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2702 (progn
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2703 (setq max (dired-subdir-max))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2704 (while (and
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2705 (< (point) max)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2706 (not
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2707 (setq fn
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2708 (dired-get-filename 'no-dir t))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2709 (forward-line 1))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2710 (if fn
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2711 (progn
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2712 (or (intern-soft (concat fn "/") table)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2713 (intern fn table))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2714 (forward-line 1)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2715 (while (setq fn
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2716 (dired-get-filename 'no-dir t))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2717 (or (intern-soft (concat fn "/") table)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2718 (intern fn table))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2719 (forward-line 1))))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2720 (setq dired-completer-cache (cons
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2721 (cons xdir table)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2722 dired-completer-cache))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2723 (cond
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2724 ((null action)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2725 (setq result (try-completion file table))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2726 (if exact
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2727 (if (stringp result)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2728 string
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2729 t)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2730 (if (stringp result)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2731 (concat dir result)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2732 result)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2733 ((eq action t)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2734 (setq result (all-completions file table))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2735 (if exact (cons "." result) result))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2736 ((eq 'lambda action)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2737 (and (or exact (intern-soft file table)))))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2738 (store-match-data saved-md)))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2739
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2740 (defun dired-really-goto-file (file)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2741 ;; Goes to a file, even if it needs to insert it parent directory.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2742 (or (dired-goto-file file)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2743 (progn ; refresh and try again
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2744 (dired-insert-subdir (file-name-directory file))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2745 (dired-goto-file file))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2746
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2747 (defun dired-between-files ()
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2748 ;; Point must be at beginning of line
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2749 (save-excursion (not (dired-move-to-filename nil (point)))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2750
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2751 (defun dired-repeat-over-lines (arg function)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2752 ;; This version skips non-file lines.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2753 ;; Skips file lines hidden with selective display.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2754 ;; BACKWARDS means move backwards after each action. This is not the same
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2755 ;; as a negative arg, as that skips the current line.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2756 (beginning-of-line)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2757 (let* ((advance (cond ((> arg 0) 1) ((< arg 0) -1) (t nil)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2758 (check-fun (if (eq advance 1) 'eobp 'bobp))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2759 (n (if (< arg 0) (- arg) arg))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2760 (wall (funcall check-fun))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2761 (done wall))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2762 (while (not done)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2763 (if advance
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2764 (progn
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2765 (while (not (or (save-excursion (dired-move-to-filename))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2766 (setq wall (funcall check-fun))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2767 (forward-line advance))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2768 (or wall
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2769 (progn
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2770 (save-excursion (funcall function))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2771 (forward-line advance)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2772 (while (not (or (save-excursion (dired-move-to-filename))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2773 (setq wall (funcall check-fun))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2774 (forward-line advance))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2775 (setq done (or (zerop (setq n (1- n))) wall)))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2776 (if (save-excursion (dired-move-to-filename))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2777 (save-excursion (funcall function)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2778 (setq done t))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2779 (dired-move-to-filename)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2780 ;; Note that if possible the point has now been moved to the beginning of
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2781 ;; the file name.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2782 (dired-update-mode-line))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2783
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2784
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2785 ;;;; ----------------------------------------------------------------
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2786 ;;;; Miscellaneous dired commands
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2787 ;;;; ----------------------------------------------------------------
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2788
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2789 (defun dired-quit ()
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2790 "Bury the current dired buffer."
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2791 (interactive)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2792 (bury-buffer))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2793
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2794 (defun dired-undo ()
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2795 "Undo in a dired buffer.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2796 This doesn't recover lost files, it is just normal undo with temporarily
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2797 writeable buffer. You can use it to recover marks, killed lines or subdirs."
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2798 (interactive)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2799 (let ((lines (count-lines (point-min) (point-max)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2800 buffer-read-only)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2801 (undo)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2802 ;; reset dired-subdir-alist, if a dir may have been affected
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2803 ;; Is there a better way to guess this?
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2804 (setq lines (- (count-lines (point-min) (point-max)) lines))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2805 (if (or (>= lines 2) (<= lines -2))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2806 (dired-build-subdir-alist)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2807 (dired-update-mode-line-modified t)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2808 (dired-update-mode-line t))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2809
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2810
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2811 ;;;; --------------------------------------------------------
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2812 ;;;; Immediate actions on files: visiting, viewing, etc.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2813 ;;;; --------------------------------------------------------
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2814
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2815 (defun dired-find-file ()
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2816 "In dired, visit the file or directory named on this line."
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2817 (interactive)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2818 (find-file (dired-get-filename)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2819
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2820 (defun dired-view-file ()
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2821 "In dired, examine a file in view mode, returning to dired when done.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2822 When file is a directory, show it in this buffer if it is inserted;
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2823 otherwise, display it in another buffer."
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2824 (interactive)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2825 (let ((file (dired-get-filename)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2826 (if (file-directory-p file)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2827 (or (dired-goto-subdir file)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2828 (dired file))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2829 (view-file file))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2830
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2831 (defun dired-find-file-other-window (&optional display)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2832 "In dired, visit this file or directory in another window.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2833 With a prefix, the file is displayed, but the window is not selected."
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2834 (interactive "P")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2835 (if display
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2836 (dired-display-file)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2837 (find-file-other-window (dired-get-filename))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2838
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2839 ;; Only for Emacs 19
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2840 (defun dired-find-file-other-frame ()
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2841 "In dired, visit this file or directory in another frame."
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2842 (interactive)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2843 (find-file-other-frame (dired-get-filename)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2844
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2845 (defun dired-display-file ()
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2846 "In dired, displays this file or directory in the other window."
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2847 (interactive)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2848 (display-buffer (find-file-noselect (dired-get-filename))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2849
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2850 ;; After an idea by wurgler@zippysun.math.uakron.edu (Tom Wurgler).
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2851 (defun dired-do-find-file (&optional arg)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2852 "Visit all marked files at once, and display them simultaneously.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2853 See also function `simultaneous-find-file'.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2854 If you want to keep the dired buffer displayed, type \\[split-window-vertically] first.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2855 If you want just the marked files displayed and nothing else, type \\[delete-other-windows] first."
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2856 (interactive "P")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2857 (dired-simultaneous-find-file (dired-get-marked-files nil arg)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2858
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2859 (defun dired-simultaneous-find-file (file-list)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2860 "Visit all files in FILE-LIST and display them simultaneously.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2861
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2862 The current window is split across all files in FILE-LIST, as evenly
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2863 as possible. Remaining lines go to the bottommost window.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2864
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2865 The number of files that can be displayed this way is restricted by
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2866 the height of the current window and the variable `window-min-height'."
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2867 ;; It is usually too clumsy to specify FILE-LIST interactively
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2868 ;; unless via dired (dired-do-find-file).
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2869 (let ((size (/ (window-height) (length file-list))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2870 (or (<= window-min-height size)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2871 (error "Too many files to visit simultaneously"))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2872 (find-file (car file-list))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2873 (setq file-list (cdr file-list))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2874 (while file-list
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2875 ;; Split off vertically a window of the desired size
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2876 ;; The upper window will have SIZE lines. We select the lower
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2877 ;; (larger) window because we want to split that again.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2878 (select-window (split-window nil size))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2879 (find-file (car file-list))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2880 (setq file-list (cdr file-list)))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2881
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2882 (defun dired-create-directory (directory)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2883 "Create a directory called DIRECTORY."
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2884 (interactive
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2885 (list (read-file-name "Create directory: "
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2886 (dired-abbreviate-file-name
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2887 (dired-current-directory)))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2888 (let ((expanded (expand-file-name directory)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2889 (make-directory expanded)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2890 ;; Because this function is meant to be called interactively, it moves
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2891 ;; the point.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2892 (dired-goto-file expanded)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2893
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2894 (defun dired-recover-file ()
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2895 "Recovers file from its autosave file.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2896 If the file is an autosave file, then recovers its associated file instead."
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2897 (interactive)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2898 (let* ((file (dired-get-filename))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2899 (name (file-name-nondirectory file))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2900 (asp (auto-save-file-name-p name))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2901 (orig (and
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2902 asp
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2903 (if (fboundp 'auto-save-original-name)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2904 (auto-save-original-name file)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2905 (error
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2906 "Need auto-save package to compute original file name."))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2907 (buff (if asp
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2908 (and orig (get-file-buffer orig))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2909 (get-file-buffer file))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2910 (and
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2911 buff
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2912 (buffer-modified-p buff)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2913 (or
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2914 (yes-or-no-p
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2915 (format
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2916 "Recover file will erase the modified buffer %s. Do it? "
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2917 (buffer-name buff)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2918 (error "Recover file aborted.")))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2919 (if asp
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2920 (if orig
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2921 (recover-file orig)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2922 (find-file file))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2923 (recover-file file))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2924
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2925
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2926 ;;;; --------------------------------------------------------------------
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2927 ;;;; Functions for extracting and manipulating file names
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2928 ;;;; --------------------------------------------------------------------
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2929
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2930 (defun dired-make-filename-string (filename &optional reverse)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2931 ;; Translates the way that a file name appears in a buffer, to
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2932 ;; how it is used in a path name. This is useful for non-unix
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2933 ;; support in efs.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2934 filename)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2935
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2936 (defun dired-get-filename (&optional localp no-error-if-not-filep)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2937 "In dired, return name of file mentioned on this line.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2938 Value returned normally includes the directory name.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2939 Optional arg LOCALP with value `no-dir' means don't include directory
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2940 name in result. A value of t means use path name relative to
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2941 `default-directory', which still may contain slashes if in a subdirectory.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2942 Optional arg NO-ERROR-IF-NOT-FILEP means return nil if no filename on
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2943 this line, otherwise an error occurs."
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2944
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2945 ;; Compute bol & eol once, rather than twice inside move-to-filename
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2946 ;; and move-to-end-of-filename
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2947 (let ((eol (save-excursion (skip-chars-forward "^\n\r") (point)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2948 (bol (save-excursion (skip-chars-backward "^\r\n") (point)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2949 case-fold-search file p1 p2)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2950 (save-excursion
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2951 (and
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2952 (setq p1 (dired-move-to-filename (not no-error-if-not-filep) bol eol))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2953 (setq p2 (dired-move-to-end-of-filename no-error-if-not-filep bol eol))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2954 (setq file (buffer-substring p1 p2))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2955 ;; Check if ls quoted the names, and unquote them.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2956 ;; Using read to unquote is much faster than substituting
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2957 ;; \007 (4 chars) -> ^G (1 char) etc. in a lisp loop.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2958 (cond ((memq ?b dired-internal-switches) ; System V ls
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2959 ;; This case is about 20% slower than without -b.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2960 (setq file
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2961 (read
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2962 (concat "\""
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2963 ;; some ls -b don't escape quotes, argh!
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2964 ;; This is not needed for GNU ls, though.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2965 (or (dired-string-replace-match
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2966 "\\([^\\]\\)\"" file "\\1\\\\\"")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2967 file)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2968 "\""))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2969 ;; If you do this, update dired-compatible-switches-p
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2970 ;; ((memq ?Q dired-internal-switches) ; GNU ls
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2971 ;; (setq file (read file)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2972 )))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2973 (and file
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2974 (if (eq localp 'no-dir)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2975 (dired-make-filename-string file)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2976 (concat (dired-current-directory localp)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2977 (dired-make-filename-string file))))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2978
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2979 (defun dired-make-relative (file &optional dir no-error)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2980 ;; Convert FILE (an *absolute* pathname) to a pathname relative to DIR.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2981 ;; FILE must be absolute, or this function will return nonsense.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2982 ;; If FILE is not in a subdir of DIR, an error is signalled,
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2983 ;; unless NO-ERROR is t. Then, ".."'s are inserted to give
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2984 ;; a relative representation of FILE wrto DIR
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2985 ;; eg. FILE = /vol/tex/bin/foo DIR = /vol/local/bin/
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2986 ;; results in ../../tex/bin/foo
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2987 ;; DIR must be expanded.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2988 ;; DIR defaults to default-directory.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2989 ;; DIR must be file-name-as-directory, as with all directory args in
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2990 ;; elisp code.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2991 (or dir (setq dir (expand-file-name default-directory)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2992 (let ((flen (length file))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2993 (dlen (length dir)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2994 (if (and (> flen dlen)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2995 (string-equal (substring file 0 dlen) dir))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2996 (substring file dlen)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2997 ;; Need to insert ..'s
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2998 (or no-error (error "%s: not in directory tree growing at %s" file dir))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
2999 (if (string-equal file dir)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3000 "./"
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3001 (let ((index 1)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3002 (count 0))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3003 (while (and (string-match "/" dir index)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3004 (<= (match-end 0) flen)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3005 (string-equal (substring file index (match-end 0))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3006 (substring dir index (match-end 0))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3007 (setq index (match-end 0)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3008 (setq file (substring file index))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3009 (if (and (/= flen index)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3010 (not (string-match "/" file))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3011 (< flen dlen)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3012 (string-equal file (substring dir index flen))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3013 (= (aref dir flen) ?/))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3014 (setq file "."
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3015 count -1))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3016 ;; count how many slashes remain in dir.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3017 (while (string-match "/" dir index)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3018 (setq index (match-end 0)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3019 count (1+ count)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3020 (apply 'concat (nconc (make-list count "../") (list file))))))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3021
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3022 ;;; Functions for manipulating file names.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3023 ;;
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3024 ;; Used by file tranformers.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3025 ;; Define here rather than in dired-shell.el, as it wouldn't be
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3026 ;; unreasonable to use these elsewhere.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3027
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3028 (defun dired-file-name-base (fn)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3029 "Returns the base name of FN.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3030 This is the file without directory part, and extension. See the variable
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3031 `dired-filename-re-ext'."
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3032 (setq fn (file-name-nondirectory fn))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3033 (if (string-match dired-filename-re-ext fn 1)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3034 (substring fn 0 (match-beginning 0))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3035 fn))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3036
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3037 (defun dired-file-name-extension (fn)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3038 "Returns the extension for file name FN.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3039 See the variable dired-filename-re-ext'."
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3040 (setq fn (file-name-nondirectory fn))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3041 (if (string-match dired-filename-re-ext fn 1)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3042 (substring fn (match-beginning 0))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3043 ""))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3044
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3045 (defun dired-file-name-sans-rcs-extension (fn)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3046 "Returns the file name FN without its RCS extension \",v\"."
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3047 (setq fn (file-name-nondirectory fn))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3048 (if (string-match ",v$" fn 1)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3049 (substring fn 0 (match-beginning 0))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3050 fn))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3051
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3052 (defun dired-file-name-sans-compress-extension (fn)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3053 "Returns the file name FN without the extension from compress or gzip."
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3054 (setq fn (file-name-nondirectory fn))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3055 (if (string-match "\\.\\([zZ]\\|gz\\)$" fn 1)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3056 (substring fn (match-beginning 0))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3057 fn))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3058
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3059
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3060 ;;;; ---------------------------------------------------------------------
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3061 ;;;; Working with directory trees.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3062 ;;;; ---------------------------------------------------------------------
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3063 ;;;
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3064 ;;; This where code for the dired-subdir-alist is.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3065
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3066 ;;; Utility functions for dired-subdir-alist
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3067
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3068 (defun dired-normalize-subdir (dir)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3069 ;; Prepend default-directory to DIR if relative path name.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3070 ;; dired-get-filename must be able to make a valid filename from a
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3071 ;; file and its directory DIR.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3072 ;; Fully expand everything.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3073 (file-name-as-directory
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3074 (if (file-name-absolute-p dir)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3075 (expand-file-name dir)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3076 (expand-file-name dir (expand-file-name default-directory)))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3077
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3078 (defun dired-get-subdir ()
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3079 ;;"Return the subdir name on this line, or nil if not on a headerline."
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3080 ;; Look up in the alist whether this is a headerline.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3081 (save-excursion
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3082 (let ((cur-dir (dired-current-directory)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3083 (beginning-of-line) ; alist stores b-o-l positions
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3084 (and (zerop (- (point)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3085 (dired-get-subdir-min (assoc cur-dir
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3086 dired-subdir-alist))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3087 cur-dir))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3088
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3089 (defun dired-get-subdir-max (elt)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3090 ;; returns subdir max.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3091 (let ((pos (- (length dired-subdir-alist)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3092 (length (member elt dired-subdir-alist)))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3093 (if (zerop pos)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3094 (point-max)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3095 (1- (dired-get-subdir-min (nth (1- pos) dired-subdir-alist))))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3096
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3097 (defun dired-clear-alist ()
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3098 ;; Set all markers in dired-subdir-alist to nil. Set the alist to nil too.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3099 (while dired-subdir-alist
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3100 (set-marker (dired-get-subdir-min (car dired-subdir-alist)) nil)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3101 (setq dired-subdir-alist (cdr dired-subdir-alist))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3102
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3103 (defun dired-unsubdir (dir)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3104 ;; Remove DIR from the alist
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3105 (setq dired-subdir-alist
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3106 (delq (assoc dir dired-subdir-alist) dired-subdir-alist)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3107
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3108 (defun dired-simple-subdir-alist ()
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3109 ;; Build and return `dired-subdir-alist' assuming just the top level
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3110 ;; directory to be inserted. Don't parse the buffer.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3111 (setq dired-subdir-alist
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3112 (list (list (expand-file-name default-directory)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3113 (point-min-marker) dired-omit-files
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3114 dired-internal-switches nil)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3115 (if dired-verify-modtimes
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3116 (dired-set-file-modtime (expand-file-name default-directory)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3117 dired-subdir-alist)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3118
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3119 (defun dired-build-subdir-alist ()
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3120 "Build `dired-subdir-alist' by parsing the buffer and return its new value."
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3121 (interactive)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3122 (let ((o-alist dired-subdir-alist)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3123 (count 0)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3124 subdir)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3125 (dired-clear-alist)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3126 (save-excursion
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3127 (goto-char (point-min))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3128 (while (re-search-forward dired-subdir-regexp nil t)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3129 (setq count (1+ count))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3130 (apply 'dired-alist-add-1
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3131 (setq subdir (buffer-substring (match-beginning 2)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3132 (match-end 2)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3133 ;; Put subdir boundary between lines.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3134 (set-marker (make-marker) (match-end 1))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3135 (let ((elt (assoc subdir o-alist)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3136 (if elt
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3137 (list (nth 2 elt) (nth 3 elt))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3138 (list dired-omit-files dired-internal-switches)))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3139 (if (interactive-p)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3140 (message "%d director%s." count (if (= 1 count) "y" "ies")))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3141 ;; We don't need to sort it because it is in buffer order per
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3142 ;; constructionem. Return new alist:
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3143 ;; pointers for current-subdir may be stale
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3144 dired-subdir-alist)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3145
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3146 (defun dired-alist-add (dir new-marker &optional omit switches)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3147 ;; Add new DIR at NEW-MARKER. Sort alist.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3148 (dired-alist-add-1 dir new-marker omit switches)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3149 (dired-alist-sort))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3150
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3151 (defun dired-alist-add-1 (dir new-marker &optional omit switches)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3152 ;; Add new DIR at NEW-MARKER. Don't sort.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3153 (let ((dir (dired-normalize-subdir dir)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3154 (setq dired-subdir-alist
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3155 (cons (list dir new-marker omit switches nil) dired-subdir-alist))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3156 (if dired-verify-modtimes
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3157 (dired-set-file-modtime dir dired-subdir-alist))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3158
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3159 (defun dired-alist-sort ()
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3160 ;; Keep the alist sorted on buffer position.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3161 (setq dired-subdir-alist
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3162 (sort dired-subdir-alist
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3163 (function (lambda (elt1 elt2)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3164 (> (dired-get-subdir-min elt1)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3165 (dired-get-subdir-min elt2)))))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3166
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3167 ;;; Utilities for working with subdirs in the dired buffer
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3168
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3169 ;; This function is the heart of tree dired.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3170 ;; It is called for each retrieved filename.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3171 ;; It could stand to be faster, though it's mostly function call
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3172 ;; overhead. Avoiding to funcall seems to save about 10% in
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3173 ;; dired-get-filename. Make it a defsubst?
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3174 (defun dired-current-directory (&optional localp)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3175 "Return the name of the subdirectory to which this line belongs.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3176 This returns a string with trailing slash, like `default-directory'.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3177 Optional argument means return a file name relative to `default-directory'.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3178 In this it returns \"\" for the top directory."
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3179 (let* ((here (point))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3180 (dir (catch 'done
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3181 (mapcar (function
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3182 (lambda (x)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3183 (if (<= (dired-get-subdir-min x) here)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3184 (throw 'done (car x)))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3185 dired-subdir-alist))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3186 (if (listp dir) (error "dired-subdir-alist seems to be mangled"))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3187 (if localp
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3188 (let ((def-dir (expand-file-name default-directory)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3189 (if (string-equal dir def-dir)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3190 ""
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3191 (dired-make-relative dir def-dir)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3192 dir)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3193
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3194 ;; Subdirs start at the beginning of their header lines and end just
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3195 ;; before the beginning of the next header line (or end of buffer).
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3196
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3197 (defun dired-subdir-min ()
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3198 ;; Returns the minimum position of the current subdir
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3199 (save-excursion
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3200 (if (not (dired-prev-subdir 0 t t))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3201 (error "Not in a subdir!")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3202 (point))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3203
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3204 (defun dired-subdir-max ()
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3205 ;; Returns the maximum position of the current subdir
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3206 (save-excursion
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3207 (if (dired-next-subdir 1 t t)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3208 (1- (point)) ; Do not include separating empty line.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3209 (point-max))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3210
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3211
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3212 ;;;; --------------------------------------------------------
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3213 ;;;; Deleting files
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3214 ;;;; --------------------------------------------------------
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3215
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3216 (defun dired-flag-file-deletion (arg)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3217 "In dired, flag the current line's file for deletion.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3218 With prefix arg, repeat over several lines.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3219
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3220 If on a subdir headerline, mark all its files except `.' and `..'."
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3221 (interactive "p")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3222 (dired-mark arg dired-del-marker))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3223
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3224 (defun dired-flag-file-deletion-backup (arg)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3225 "Flag current file for deletion, and move to previous line.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3226 With a prefix ARG, repeats this ARG times."
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3227 (interactive "p")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3228 ;; Use dired-mark-file and not dired-mark, as this function
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3229 ;; should do nothing special on subdir headers.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3230 (dired-mark-file (- arg) dired-del-marker))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3231
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3232 (defun dired-flag-subdir-files ()
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3233 "Flag all the files in the current subdirectory for deletion."
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3234 (interactive)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3235 (dired-mark-subdir-files dired-del-marker))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3236
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3237 (defun dired-unflag (arg)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3238 "In dired, remove a deletion flag from the current line's file.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3239 Optional prefix ARG says how many lines to unflag."
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3240 (interactive "p")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3241 (let (buffer-read-only)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3242 (dired-repeat-over-lines
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3243 arg
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3244 (function
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3245 (lambda ()
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3246 (if (char-equal (following-char) dired-del-marker)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3247 (progn
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3248 (setq dired-del-flags-number (max (1- dired-del-flags-number) 0))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3249 (dired-substitute-marker (point) dired-del-marker ?\ )))))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3250 (dired-update-mode-line-modified))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3251
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3252 (defun dired-backup-unflag (arg)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3253 "In dired, move up lines and remove deletion flag there.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3254 Optional prefix ARG says how many lines to unflag; default is one line."
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3255 (interactive "p")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3256 (dired-unflag (- arg)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3257
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3258 (defun dired-update-marker-counters (char &optional remove)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3259 (or (memq char '(?\ ?\n ?\r))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3260 (let ((counter (cond
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3261 ((char-equal char dired-del-marker)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3262 'dired-del-flags-number)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3263 ((char-equal char dired-marker-char)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3264 'dired-marks-number)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3265 ('dired-other-marks-number))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3266 (if remove
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3267 (set counter (max (1- (symbol-value counter)) 0))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3268 (set counter (1+ (symbol-value counter)))))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3269
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3270 (defun dired-update-mode-line-modified (&optional check)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3271 ;; Updates the value of mode-line-modified in dired.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3272 ;; Currently assumes that it's of the form "-%%-", where % sometimes
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3273 ;; gets replaced by %. Should allow some sort of config flag.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3274 ;; SET is t to set to -DD-, nil to set to -%%-, and 'check means
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3275 ;; examine the buffer to find out.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3276 (if check
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3277 (save-excursion
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3278 (let (char)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3279 (goto-char (point-min))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3280 (setq dired-del-flags-number 0
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3281 dired-marks-number 0
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3282 dired-other-marks-number 0)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3283 (while (not (eobp))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3284 (setq char (following-char))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3285 (cond
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3286 ((char-equal char dired-del-marker)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3287 (setq dired-del-flags-number (1+ dired-del-flags-number)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3288 ((char-equal char dired-marker-char)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3289 (setq dired-marks-number (1+ dired-marks-number)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3290 ((memq char '(?\ ?\n ?\r))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3291 nil)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3292 ((setq dired-other-marks-number (1+ dired-other-marks-number))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3293 (forward-line 1)))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3294 (setq mode-line-modified
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3295 (format dired-mode-line-modified
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3296 (if (zerop dired-del-flags-number)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3297 "--"
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3298 (format "%d%c" dired-del-flags-number dired-del-marker))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3299 (if (zerop dired-marks-number)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3300 "--"
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3301 (format "%d%c" dired-marks-number dired-marker-char))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3302 (if (zerop dired-other-marks-number)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3303 "-"
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3304 (int-to-string dired-other-marks-number))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3305 (set-buffer-modified-p (buffer-modified-p)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3306
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3307 (defun dired-do-deletions (&optional nomessage)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3308 (dired-expunge-deletions))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3309
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3310 (defun dired-expunge-deletions ()
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3311 "In dired, delete the files flagged for deletion."
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3312 (interactive)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3313 (let ((files (let ((dired-marker-char dired-del-marker))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3314 (dired-map-over-marks (cons (dired-get-filename) (point))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3315 t))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3316 (if files
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3317 (progn
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3318 (dired-internal-do-deletions files nil dired-del-marker)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3319 ;; In case the point gets left somewhere strange -- hope that
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3320 ;; this doesn't cause asynch troubles later.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3321 (beginning-of-line)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3322 (dired-goto-next-nontrivial-file)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3323 (dired-update-mode-line-modified t)) ; play safe, it's cheap
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3324 (message "(No deletions requested)"))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3325
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3326 (defun dired-do-delete (&optional arg)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3327 "Delete all marked (or next ARG) files."
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3328 ;; This is more consistent with the file marking feature than
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3329 ;; dired-expunge-deletions.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3330 (interactive "P")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3331 (dired-internal-do-deletions
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3332 ;; this may move point if ARG is an integer
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3333 (dired-map-over-marks (cons (dired-get-filename) (point))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3334 arg)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3335 arg)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3336 (beginning-of-line)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3337 (dired-goto-next-nontrivial-file))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3338
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3339 (defun dired-internal-do-deletions (l arg &optional marker-char)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3340 ;; L is an alist of files to delete, with their buffer positions.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3341 ;; ARG is the prefix arg.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3342 ;; Filenames are absolute (VMS needs this for logical search paths).
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3343 ;; (car L) *must* be the *last* (bottommost) file in the dired buffer.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3344 ;; That way as changes are made in the buffer they do not shift the
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3345 ;; lines still to be changed, so the (point) values in L stay valid.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3346 ;; Also, for subdirs in natural order, a subdir's files are deleted
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3347 ;; before the subdir itself - the other way around would not work.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3348 (save-excursion
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3349 (let ((files (mapcar (function car) l))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3350 (count (length l))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3351 (succ 0)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3352 (cdir (dired-current-directory))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3353 failures)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3354 ;; canonicalize file list for pop up
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3355 (setq files (nreverse (mapcar (function
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3356 (lambda (fn)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3357 (dired-make-relative fn cdir t)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3358 files)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3359 (if (or (memq 'delete dired-no-confirm)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3360 (dired-mark-pop-up
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3361 " *Files Flagged for Deletion*" 'delete files
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3362 dired-deletion-confirmer
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3363 (format "Delete %s "
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3364 (dired-mark-prompt arg files marker-char))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3365 (save-excursion
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3366 ;; files better be in reverse order for this loop!
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3367 (while l
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3368 (goto-char (cdr (car l)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3369 (condition-case err
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3370 (let ((fn (car (car l))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3371 ;; This test is equivalent to
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3372 ;; (and (file-directory-p fn)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3373 ;; (not (file-symlink-p fn)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3374 ;; but more efficient
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3375 (if (if (eq t (car (file-attributes fn)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3376 (if (<= (length (directory-files fn)) 2)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3377 (progn (delete-directory fn) t)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3378 (and (or
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3379 (memq 'recursive-delete dired-no-confirm)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3380 (funcall
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3381 dired-deletion-confirmer
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3382 (format "\
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3383 Recursively delete directory and files within %s? "
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3384 (dired-make-relative fn))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3385 (progn
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3386 (dired-recursive-delete-directory fn)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3387 t)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3388 (progn (delete-file fn) t))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3389 (progn
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3390 (setq succ (1+ succ))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3391 (message "%s of %s deletions" succ count)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3392 (dired-clean-up-after-deletion fn))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3393 (error;; catch errors from failed deletions
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3394 (dired-log (buffer-name (current-buffer)) "%s\n" err)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3395 (setq failures (cons (car (car l)) failures))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3396 (setq l (cdr l)))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3397 (if failures
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3398 (dired-log-summary
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3399 (buffer-name (current-buffer))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3400 (format "%d of %d deletion%s failed:" (length failures) count
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3401 (dired-plural-s count))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3402 failures)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3403 (if (zerop succ)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3404 (message "(No deletions performed)")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3405 (message "%d deletion%s done" succ (dired-plural-s succ)))))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3406
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3407 (defun dired-recursive-delete-directory (fn)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3408 ;; Recursively deletes directory FN, and all of its contents.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3409 (let* ((fn (expand-file-name fn))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3410 (handler (find-file-name-handler
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3411 fn 'dired-recursive-delete-directory)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3412 (if handler
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3413 (funcall handler 'dired-recursive-delete-directory fn)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3414 (progn
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3415 (or (file-exists-p fn)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3416 (signal
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3417 'file-error
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3418 (list "Removing old file name" "no such directory" fn)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3419 ;; Which is better, -r or -R?
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3420 (call-process "rm" nil nil nil "-r" (directory-file-name fn))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3421 (and (file-exists-p fn)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3422 (error "Failed to recusively delete %s" fn))))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3423
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3424 (defun dired-clean-up-after-deletion (fn)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3425 ;; Offer to kill buffer of deleted file FN.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3426 (let ((buf (get-file-buffer fn)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3427 (and buf
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3428 (or (memq 'kill-file-buffer dired-no-confirm)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3429 (funcall (function yes-or-no-p)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3430 (format "Kill buffer of %s, too? "
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3431 (file-name-nondirectory fn))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3432 (save-excursion ; you never know where kill-buffer leaves you
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3433 (kill-buffer buf)))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3434
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3435 ;;; Cleaning a directory -- flagging backups for deletion
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3436
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3437 (defun dired-clean-directory (keep &optional marker msg)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3438 "Flag numerical backups for deletion.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3439 Spares `dired-kept-versions' latest versions, and `kept-old-versions' oldest.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3440 Positive prefix arg KEEP overrides `dired-kept-versions';
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3441 Negative prefix arg KEEP overrides `kept-old-versions' with KEEP made positive.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3442
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3443 To clear the flags on these files, you can use \\[dired-flag-backup-files]
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3444 with a prefix argument."
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3445 (interactive "P")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3446 (setq keep (if keep (prefix-numeric-value keep) dired-kept-versions))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3447 (let* ((early-retention (if (< keep 0) (- keep) kept-old-versions))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3448 (late-retention (if (<= keep 0) dired-kept-versions keep))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3449 (msg (or msg
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3450 (format
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3451 "Cleaning numerical backups (keeping %d late, %d old)"
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3452 late-retention early-retention)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3453 (trample-marker (or marker dired-del-marker))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3454 (file-version-assoc-list))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3455 (message "%s..." msg)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3456 ;; Do this after messaging, as it may take a while.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3457 (setq file-version-assoc-list (dired-collect-file-versions))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3458 ;; Sort each VERSION-NUMBER-LIST,
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3459 ;; and remove the versions to be deleted.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3460 (let ((fval file-version-assoc-list))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3461 (while fval
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3462 (let* ((sorted-v-list (cons 'q (sort (cdr (car fval)) '<)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3463 (v-count (length sorted-v-list)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3464 (if (> v-count (+ early-retention late-retention))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3465 (rplacd (nthcdr early-retention sorted-v-list)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3466 (nthcdr (- v-count late-retention)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3467 sorted-v-list)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3468 (rplacd (car fval)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3469 (cdr sorted-v-list)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3470 (setq fval (cdr fval))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3471 ;; Look at each file. If it is a numeric backup file,
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3472 ;; find it in a VERSION-NUMBER-LIST and maybe flag it for deletion.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3473 (dired-map-dired-file-lines (function
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3474 (lambda (fn)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3475 (dired-trample-file-versions
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3476 fn file-version-assoc-list
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3477 trample-marker))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3478 (message "%s...done" msg)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3479
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3480 (defun dired-collect-file-versions ()
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3481 ;; If it looks like a file has versions, return a list of the versions.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3482 ;; The return value is ((FILENAME . (VERSION1 VERSION2 ...)) ...)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3483 (let (result)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3484 (dired-map-dired-file-lines
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3485 (function
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3486 (lambda (fn)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3487 (let* ((base-versions
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3488 (concat (file-name-nondirectory fn) ".~"))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3489 (bv-length (length base-versions))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3490 (possibilities (file-name-all-completions
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3491 base-versions
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3492 (file-name-directory fn))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3493 (if possibilities
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3494 (setq result (cons (cons fn
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3495 (mapcar 'backup-extract-version
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3496 possibilities)) result)))))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3497 result))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3498
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3499 (defun dired-trample-file-versions (fn alist marker)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3500 ;; ALIST is an alist of filenames and versions used to determine
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3501 ;; if each file should be flagged for deletion.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3502 ;; This version using file-name-sans-versions is probably a lot slower
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3503 ;; than Sebastian's original, but it is more easily adaptable to non-unix.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3504 (let ((base (file-name-sans-versions fn))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3505 base-version-list bv-length)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3506 (and (not (string-equal base fn))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3507 (setq base-version-list (assoc base alist))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3508 (setq bv-length (string-match "[0-9]" fn (length base)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3509 (not (memq (backup-extract-version fn) base-version-list))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3510 (progn (skip-chars-backward "^\n\r")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3511 (bolp)) ; make sure the preceding char isn't \r.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3512 (dired-substitute-marker (point) (following-char) marker))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3513
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3514 (defun dired-map-dired-file-lines (fun)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3515 ;; Perform FUN with point at the end of each non-directory line.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3516 ;; FUN takes one argument, the filename (complete pathname).
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3517 (dired-check-ls-l)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3518 (save-excursion
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3519 (let (file buffer-read-only)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3520 (goto-char (point-min))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3521 (while (not (eobp))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3522 (save-excursion
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3523 (and (not (and dired-re-dir (looking-at dired-re-dir)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3524 (not (memq (following-char) '(?\n ?\n)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3525 (setq file (dired-get-filename nil t)) ; nil on non-file
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3526 (progn (skip-chars-forward "^\n\r")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3527 (funcall fun file))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3528 (forward-line 1))))) ; this guarantees that we don't
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3529 ; operate on omitted files.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3530
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3531
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3532 ;;;; -----------------------------------------------------------
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3533 ;;;; Confirmations and prompting the user.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3534 ;;;; -----------------------------------------------------------
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3535
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3536 (defun dired-plural-s (count)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3537 (if (= 1 count) "" "s"))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3538
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3539 (defun dired-mark-prompt (arg files &optional marker-char)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3540 ;; Return a string for use in a prompt, either the current file
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3541 ;; name, or the marker and a count of marked files.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3542 (let ((count (length files)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3543 (if (= count 1)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3544 (car files)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3545 ;; more than 1 file:
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3546 (if (integerp arg)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3547 (cond ((zerop arg) "[no files]")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3548 ((> arg 0) "[following]")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3549 ((< arg 0) "[preceding]"))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3550 (char-to-string (or marker-char dired-marker-char))))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3551
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3552 (defun dired-pop-to-buffer (buf)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3553 ;; Pop up buffer BUF.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3554 ;; Make its window fit its contents.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3555 (let ((window (selected-window))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3556 target-lines w2)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3557 (cond ;; if split-window-threshold is enabled, use the largest window
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3558 ((and (> (window-height (setq w2 (get-largest-window)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3559 split-height-threshold)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3560 (= (frame-width) (window-width w2)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3561 (setq window w2))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3562 ;; if the least-recently-used window is big enough, use it
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3563 ((and (> (window-height (setq w2 (get-lru-window)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3564 (* 2 window-min-height))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3565 (= (frame-width) (window-width w2)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3566 (setq window w2)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3567 (save-excursion
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3568 (set-buffer buf)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3569 (goto-char (point-max))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3570 (skip-chars-backward "\n\r\t ")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3571 (setq target-lines (count-lines (point-min) (point)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3572 ;; Don't forget to count the last line.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3573 (if (not (bolp))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3574 (setq target-lines (1+ target-lines))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3575 (if (<= (window-height window) (* 2 window-min-height))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3576 ;; At this point, every window on the frame is too small to split.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3577 (setq w2 (display-buffer buf))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3578 (setq w2 (split-window
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3579 window
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3580 (max window-min-height
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3581 (- (window-height window)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3582 (1+ (max window-min-height target-lines)))))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3583 (set-window-buffer w2 buf)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3584 (if (< (1- (window-height w2)) target-lines)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3585 (progn
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3586 (select-window w2)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3587 (enlarge-window (- target-lines (1- (window-height w2))))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3588 (set-window-start w2 1)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3589
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3590 (defun dired-mark-pop-up (bufname op-symbol files function &rest args)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3591 ;; Args BUFNAME OP-SYMBOL FILES FUNCTION &rest ARGS.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3592 ;; Return FUNCTION's result on ARGS after popping up a window (in a buffer
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3593 ;; named BUFNAME, nil gives \" *Marked Files*\") showing the marked
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3594 ;; files. Uses function `dired-pop-to-buffer' to do that.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3595 ;; FUNCTION should not manipulate files.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3596 ;; It should only read input (an argument or confirmation).
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3597 ;; The window is not shown if there is just one file or
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3598 ;; OP-SYMBOL is a member of the list in `dired-no-confirm'.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3599 ;; FILES is the list of marked files.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3600 (if (memq op-symbol dired-no-confirm)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3601 (apply function args)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3602 (or bufname (setq bufname " *Marked Files*"))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3603 (if (<= (length files) 1)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3604 (apply function args)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3605 (save-excursion
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3606 (let ((standard-output (set-buffer (get-buffer-create bufname))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3607 (erase-buffer)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3608 (dired-format-columns-of-files files)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3609 (dired-remove-text-properties (point-min) (point-max))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3610 (setq mode-line-format (format " %s [%d files]"
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3611 bufname (length files)))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3612 (save-window-excursion
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3613 (dired-pop-to-buffer bufname)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3614 (apply function args)))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3615
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3616 (defun dired-column-widths (columns list &optional across)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3617 ;; Returns the column widths for breaking LIST into
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3618 ;; COLUMNS number of columns.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3619 (cond
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3620 ((null list)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3621 nil)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3622 ((= columns 1)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3623 (list (apply 'max (mapcar 'length list))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3624 ((let* ((len (length list))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3625 (col-length (/ len columns))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3626 (remainder (% len columns))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3627 (i 0)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3628 (j 0)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3629 (max-width 0)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3630 widths padding)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3631 (if (zerop remainder)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3632 (setq padding 0)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3633 (setq col-length (1+ col-length)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3634 padding (- columns remainder)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3635 (setq list (nconc (copy-sequence list) (make-list padding nil)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3636 (setcdr (nthcdr (1- (+ len padding)) list) list)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3637 (while (< i columns)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3638 (while (< j col-length)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3639 (setq max-width (max max-width (length (car list)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3640 list (if across (nthcdr columns list) (cdr list))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3641 j (1+ j)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3642 (setq widths (cons (+ max-width 2) widths)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3643 max-width 0
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3644 j 0
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3645 i (1+ i))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3646 (if across (setq list (cdr list))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3647 (setcar widths (- (car widths) 2))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3648 (nreverse widths)))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3649
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3650 (defun dired-calculate-columns (list &optional across)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3651 ;; Returns a list of integers which are the column widths that best pack
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3652 ;; LIST, a list of strings, onto the screen.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3653 (and list
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3654 (let* ((width (1- (window-width)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3655 (columns (max 1 (/ width
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3656 (+ 2 (apply 'max (mapcar 'length list))))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3657 col-list last-col-list)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3658 (while (<= (apply '+ (setq col-list
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3659 (dired-column-widths columns list across)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3660 width)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3661 (setq columns (1+ columns)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3662 last-col-list col-list))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3663 (or last-col-list col-list))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3664
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3665 (defun dired-format-columns-of-files (files &optional across)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3666 ;; Returns the number of lines used.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3667 ;; If ACROSS is non-nil, sorts across rather than down the buffer, like
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3668 ;; ls -x
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3669 (and files
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3670 (let* ((columns (dired-calculate-columns files across))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3671 (ncols (length columns))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3672 (ncols1 (1- ncols))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3673 (nfiles (length files))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3674 (nrows (+ (/ nfiles ncols)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3675 (if (zerop (% nfiles ncols)) 0 1)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3676 (space-left (- (window-width) (apply '+ columns) 1))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3677 (i 0)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3678 (j 0)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3679 file padding stretch float-stretch)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3680 (if (zerop ncols1)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3681 (setq stretch 0
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3682 float-stretch 0)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3683 (setq stretch (/ space-left ncols1)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3684 float-stretch (% space-left ncols1)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3685 (setq files (nconc (copy-sequence files) ; fill up with empty fns
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3686 (make-list (- (* ncols nrows) nfiles) "")))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3687 (setcdr (nthcdr (1- (length files)) files) files) ; make circular
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3688 (while (< j nrows)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3689 (while (< i ncols)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3690 (princ (setq file (car files)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3691 (setq padding (- (nth i columns) (length file)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3692 (or (= i ncols1)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3693 (progn
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3694 (setq padding (+ padding stretch))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3695 (if (< i float-stretch) (setq padding (1+ padding)))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3696 (princ (make-string padding ?\ ))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3697 (setq files (if across (cdr files) (nthcdr nrows files))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3698 i (1+ i)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3699 (princ "\n")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3700 (setq i 0
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3701 j (1+ j))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3702 (or across (setq files (cdr files))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3703 nrows)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3704
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3705 (defun dired-query (qs-var qs-prompt &rest qs-args)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3706 ;; Query user and return nil or t.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3707 ;; Store answer in symbol VAR (which must initially be bound to nil).
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3708 ;; Format PROMPT with ARGS.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3709 ;; Binding variable help-form will help the user who types C-h.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3710 (let* ((char (symbol-value qs-var))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3711 (action (cdr (assoc char dired-query-alist))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3712 (cond ((eq 'yes action)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3713 t) ; accept, and don't ask again
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3714 ((eq 'no action)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3715 nil) ; skip, and don't ask again
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3716 (t;; no lasting effects from last time we asked - ask now
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3717 (let ((qprompt (concat qs-prompt
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3718 (if help-form
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3719 (format " [yn!q or %s] "
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3720 (key-description
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3721 (char-to-string help-char)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3722 " [ynq or !] ")))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3723 (dired-in-query t)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3724 elt)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3725 ;; Actually it looks nicer without cursor-in-echo-area - you can
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3726 ;; look at the dired buffer instead of at the prompt to decide.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3727 (apply 'message qprompt qs-args)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3728 (setq char (set qs-var (read-char)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3729 (while (not (setq elt (assoc char dired-query-alist)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3730 (message "Invalid char - type %c for help." help-char)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3731 (ding)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3732 (sit-for 1)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3733 (apply 'message qprompt qs-args)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3734 (setq char (set qs-var (read-char))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3735 (memq (cdr elt) '(t y yes)))))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3736
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3737 (defun dired-mark-confirm (op-symbol operation arg)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3738 ;; Request confirmation from the user that the operation described
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3739 ;; by OP-SYMBOL is to be performed on the marked files.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3740 ;; Confirmation consists in a y-or-n question with a file list
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3741 ;; pop-up unless OP-SYMBOL is a member of `dired-no-confirm'.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3742 ;; OPERATION is a string describing the operation. Used for prompting
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3743 ;; the user.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3744 ;; The files used are determined by ARG (like in dired-get-marked-files).
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3745 (or (memq op-symbol dired-no-confirm)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3746 (let ((files (dired-get-marked-files t arg)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3747 (dired-mark-pop-up nil op-symbol files (function y-or-n-p)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3748 (concat operation " "
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3749 (dired-mark-prompt arg files) "? ")))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3750
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3751 (defun dired-mark-read-file-name (prompt dir op-symbol arg files)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3752 (dired-mark-pop-up
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3753 nil op-symbol files
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3754 (function read-file-name)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3755 (format prompt (dired-mark-prompt arg files)) dir))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3756
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3757 (defun dired-mark-read-string (prompt initial op-symbol arg files
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3758 &optional history-sym)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3759 ;; Reading arguments with history.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3760 ;; Read arguments for a mark command of type OP-SYMBOL,
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3761 ;; perhaps popping up the list of marked files.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3762 ;; ARG is the prefix arg and indicates whether the files came from
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3763 ;; marks (ARG=nil) or a repeat factor (integerp ARG).
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3764 ;; If the current file was used, the list has but one element and ARG
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3765 ;; does not matter. (It is non-nil, non-integer in that case, namely '(4)).
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3766 ;; PROMPT for a string, with INITIAL input.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3767 (dired-mark-pop-up
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3768 nil op-symbol files
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3769 (function
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3770 (lambda (prompt initial)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3771 (let ((hist (or history-sym
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3772 (cdr (assq op-symbol dired-op-history-alist))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3773 'dired-history)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3774 (dired-read-with-history prompt initial hist))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3775 (format prompt (dired-mark-prompt arg files)) initial))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3776
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3777
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3778 ;;;; ----------------------------------------------------------
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3779 ;;;; Marking files.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3780 ;;;; ----------------------------------------------------------
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3781
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3782 (defun dired-mark (arg &optional char)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3783 "Mark the current (or next ARG) files.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3784 If on a subdir headerline, mark all its files except `.' and `..'.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3785
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3786 Use \\[dired-unmark-all-files] to remove all marks,
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3787 and \\[dired-unmark] to remove the mark of the current file."
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3788 (interactive "p")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3789 (if (dired-get-subdir)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3790 (dired-mark-subdir-files char)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3791 (dired-mark-file arg char)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3792
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3793 (defun dired-mark-file (arg &optional char)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3794 "Mark ARG files starting from the current file line.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3795 Optional CHAR indicates a marker character to use."
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3796 (let (buffer-read-only)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3797 (if (memq (or char dired-marker-char) '(?\ ?\n ?\r))
114
8619ce7e4c50 Import from CVS: tag r20-1b9
cvs
parents: 100
diff changeset
3798 (error "Invalid marker character %c" dired-marker-char))
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3799 (or char (setq char dired-marker-char))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3800 (dired-repeat-over-lines
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3801 arg
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3802 (function
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3803 (lambda ()
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3804 (dired-update-marker-counters (following-char) t)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3805 (dired-substitute-marker (point) (following-char) char)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3806 (dired-update-marker-counters char))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3807 (dired-update-mode-line-modified)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3808
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3809 (defun dired-mark-subdir-files (&optional char)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3810 "Mark all files except `.' and `..'."
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3811 (interactive)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3812 (save-excursion
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3813 (dired-mark-files-in-region (dired-subdir-min) (dired-subdir-max) char)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3814
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3815 (defun dired-unmark (arg)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3816 "Unmark the current (or next ARG) files.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3817 If looking at a subdir, unmark all its files except `.' and `..'."
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3818 (interactive "p")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3819 (let (buffer-read-only)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3820 (dired-repeat-over-lines
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3821 arg
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3822 (function
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3823 (lambda ()
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3824 (let ((char (following-char)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3825 (or (memq char '(?\ ?\n ?\r))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3826 (progn
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3827 (cond
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3828 ((char-equal char dired-marker-char)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3829 (setq dired-marks-number (max (1- dired-marks-number) 0)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3830 ((char-equal char dired-del-marker)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3831 (setq dired-del-flags-number
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3832 (max (1- dired-del-flags-number) 0)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3833 ((setq dired-other-marks-number
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3834 (max (1- dired-other-marks-number) 0))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3835 (dired-substitute-marker (point) char ?\ )))))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3836 (dired-update-mode-line-modified)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3837
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3838 (defun dired-mark-prefix (&optional arg)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3839 "Mark the next ARG files with the next character typed.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3840 If ARG is negative, marks the previous files."
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3841 (interactive "p")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3842 (if (sit-for echo-keystrokes)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3843 (cond
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3844 ((or (= arg 1) (zerop arg))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3845 (message "Mark with character?"))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3846 ((< arg 0)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3847 (message "Mark %d file%s moving backwards?"
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3848 (- arg) (dired-plural-s (- arg))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3849 ((> arg 1)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3850 (message "Mark %d following files with character?" arg))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3851 (dired-mark arg (read-char)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3852
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3853 (defun dired-change-marks (old new)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3854 "Change all OLD marks to NEW marks.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3855 OLD and NEW are both characters used to mark files.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3856 With a prefix, prompts for a mark to toggle. In other words, all unmarked
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3857 files receive that mark, and all files currently marked with that mark become
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3858 unmarked."
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3859 ;; When used in a lisp program, setting NEW to nil means toggle the mark OLD.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3860 (interactive
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3861 (let* ((cursor-in-echo-area t)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3862 (old nil)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3863 (new nil)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3864 (markers (dired-mark-list))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3865 (default (cond ((null markers)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3866 (error "No markers in buffer"))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3867 ((= (length markers) 1)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3868 (setq old (car markers)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3869 ((memq dired-marker-char markers)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3870 dired-marker-char)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3871 ;; picks the last one in the buffer. reasonable?
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3872 ((car markers)))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3873 (or old (setq old
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3874 (progn
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3875 (if current-prefix-arg
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3876 (message "Toggle mark (default %c): " default)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3877 (message "Change old mark (default %c): " default))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3878 (read-char))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3879 (if (memq old '(?\ ?\n ?\r)) (setq old default))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3880 (or current-prefix-arg
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3881 (setq new (progn
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3882 (message
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3883 "Change %c marks to new mark (RET means abort): " old)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3884 (read-char))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3885 (list old new)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3886 (let ((old-count (cond
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3887 ((char-equal old dired-marker-char)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3888 'dired-marks-number)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3889 ((char-equal old dired-del-marker)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3890 'dired-del-flags-number)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3891 ('dired-other-marks-number))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3892 (if new
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3893 (or (memq new '(?\ ?\n ?\r))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3894 ;; \n and \r aren't valid marker chars. Assume that if the
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3895 ;; user hits return, he meant to abort the command.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3896 (let ((string (format "\n%c" old))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3897 (new-count (cond
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3898 ((char-equal new dired-marker-char)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3899 'dired-marks-number)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3900 ((char-equal new dired-del-marker)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3901 'dired-del-flags-number)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3902 ('dired-other-marks-number)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3903 (buffer-read-only nil))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3904 (save-excursion
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3905 (goto-char (point-min))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3906 (while (search-forward string nil t)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3907 (if (char-equal (preceding-char) old)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3908 (progn
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3909 (dired-substitute-marker (1- (point)) old new)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3910 (set new-count (1+ (symbol-value new-count)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3911 (set old-count (max (1- (symbol-value old-count)) 0))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3912 ))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3913 (save-excursion
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3914 (let ((ucount 0)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3915 (mcount 0)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3916 (buffer-read-only nil))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3917 (goto-char (point-min))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3918 (while (not (eobp))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3919 (or (dired-between-files)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3920 (looking-at dired-re-dot)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3921 (cond
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3922 ((= (following-char) ?\ )
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3923 (setq mcount (1+ mcount))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3924 (set old-count (1+ (symbol-value old-count)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3925 (dired-substitute-marker (point) ?\ old))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3926 ((= (following-char) old)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3927 (setq ucount (1+ ucount))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3928 (set old-count (max (1- (symbol-value old-count)) 0))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3929 (dired-substitute-marker (point) old ?\ ))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3930 (forward-line 1))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3931 (message "Unmarked %d file%s; marked %d file%s with %c."
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3932 ucount (dired-plural-s ucount) mcount
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3933 (dired-plural-s mcount) old)))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3934 (dired-update-mode-line-modified))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3935
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3936 (defun dired-unmark-all-files (flag &optional arg)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3937 "Remove a specific mark or any mark from every file.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3938 With prefix arg, query for each marked file.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3939 Type \\[help-command] at that time for help.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3940 With a zero prefix, only counts the number of marks."
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3941 (interactive
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3942 (let* ((cursor-in-echo-area t)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3943 executing-kbd-macro) ; for XEmacs
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3944 (list (and (not (eq current-prefix-arg 0))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3945 (progn (message "Remove marks (RET means all): ") (read-char)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3946 current-prefix-arg)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3947 (save-excursion
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3948 (let* ((help-form "\
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3949 Type SPC or `y' to unflag one file, DEL or `n' to skip to next,
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3950 `!' to unflag all remaining files with no more questions.")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3951 (allp (memq flag '(?\n ?\r)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3952 (count-p (eq arg 0))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3953 (count (if (or allp count-p)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3954 (mapcar
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3955 (function
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3956 (lambda (elt)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3957 (cons elt 0)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3958 (nreverse (dired-mark-list)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3959 0))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3960 (msg "")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3961 (no-query (or (not arg) count-p))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3962 buffer-read-only case-fold-search query)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3963 (goto-char (point-min))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3964 (if (or allp count-p)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3965 (while (re-search-forward dired-re-mark nil t)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3966 (if (or no-query
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3967 (dired-query 'query "Unmark file `%s'? "
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3968 (dired-get-filename t)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3969 (let ((ent (assq (preceding-char) count)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3970 (if ent (setcdr ent (1+ (cdr ent))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3971 (or count-p (dired-substitute-marker
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3972 (- (point) 1) (preceding-char) ?\ ))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3973 (forward-line 1))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3974 (while (search-forward (format "\n%c" flag) nil t)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3975 (if (or no-query
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3976 (dired-query 'query "Unmark file `%s'? "
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3977 (dired-get-filename t)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3978 (progn
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3979 (dired-substitute-marker (match-beginning 0) flag ?\ )
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3980 (setq count (1+ count))))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3981 (if (or allp count-p)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3982 (mapcar
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3983 (function
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3984 (lambda (elt)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3985 (or (zerop (cdr elt))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3986 (setq msg (format "%s%s%d %c%s"
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3987 msg
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3988 (if (zerop (length msg))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3989 " "
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3990 ", ")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3991 (cdr elt)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3992 (car elt)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3993 (if (= 1 (cdr elt)) "" "'s"))))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3994 count)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3995 (or (zerop count)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3996 (setq msg (format " %d %c%s"
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3997 count flag (if (= 1 count) "" "'s")))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3998 (if (zerop (length msg))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
3999 (setq msg " none")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4000 (or count-p (dired-update-mode-line-modified t)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4001 (message "%s:%s" (if count-p "Number of marks" "Marks removed") msg))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4002
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4003 (defun dired-get-marked-files (&optional localp arg)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4004 "Return the marked files' names as list of strings.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4005 The list is in the same order as the buffer, that is, the car is the
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4006 first marked file.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4007 Values returned are normally absolute pathnames.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4008 Optional arg LOCALP as in `dired-get-filename'.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4009 Optional second argument ARG forces to use other files. If ARG is an
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4010 integer, use the next ARG files. If ARG is otherwise non-nil, use
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4011 current file. Usually ARG comes from the current prefix arg."
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4012 (save-excursion
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4013 (nreverse (dired-map-over-marks (dired-get-filename localp) arg))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4014
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4015 ;;; Utility functions for marking files
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4016
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4017 (defun dired-mark-files-in-region (start end &optional char)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4018 (let (buffer-read-only)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4019 (if (> start end)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4020 (error "start > end"))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4021 (goto-char start) ; assumed at beginning of line
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4022 (or char (setq char dired-marker-char))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4023 (while (< (point) end)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4024 ;; Skip subdir line and following garbage like the `total' line:
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4025 (while (and (< (point) end) (dired-between-files))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4026 (forward-line 1))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4027 (if (and (/= (following-char) char)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4028 (not (looking-at dired-re-dot))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4029 (save-excursion
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4030 (dired-move-to-filename nil (point))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4031 (progn
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4032 (dired-update-marker-counters (following-char) t)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4033 (dired-substitute-marker (point) (following-char) char)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4034 (dired-update-marker-counters char)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4035 (forward-line 1)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4036 (dired-update-mode-line-modified))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4037
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4038 (defun dired-mark-list ()
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4039 ;; Returns a list of all marks currently used in the buffer.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4040 (let ((result nil)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4041 char)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4042 (save-excursion
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4043 (goto-char (point-min))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4044 (while (not (eobp))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4045 (and (not (memq (setq char (following-char)) '(?\ ?\n ?\r)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4046 (not (memq char result))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4047 (setq result (cons char result)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4048 (forward-line 1)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4049 result))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4050
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4051 ;;; Dynamic markers
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4052
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4053 (defun dired-set-current-marker-string ()
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4054 "Computes and returns `dired-marker-string'."
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4055 (prog1
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4056 (setq dired-marker-string
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4057 (if dired-marker-stack
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4058 (let* ((n (+ (length dired-marker-stack) 5))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4059 (str (make-string n ?\ ))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4060 (list dired-marker-stack)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4061 (pointer dired-marker-stack-pointer))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4062 (setq n (1- n))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4063 (aset str n ?\])
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4064 (setq n (1- n))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4065 (while list
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4066 (aset str n (car list))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4067 (if (zerop pointer)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4068 (progn
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4069 (setq n (1- n))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4070 (aset str n dired-marker-stack-cursor)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4071 (setq n (1- n)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4072 pointer (1- pointer)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4073 list (cdr list)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4074 (aset str n dired-default-marker)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4075 (if (zerop pointer)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4076 (aset str 2 dired-marker-stack-cursor))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4077 (aset str 1 ?\[)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4078 str)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4079 ""))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4080 (set-buffer-modified-p (buffer-modified-p))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4081
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4082 (defun dired-set-marker-char (c)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4083 "Set the marker character to something else.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4084 Use \\[dired-restore-marker-char] to restore the previous value."
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4085 (interactive "cNew marker character: ")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4086 (and (memq c '(?\ ?\n ?\r)) (error "invalid marker char %c" c))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4087 (setq dired-marker-stack (cons c dired-marker-stack)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4088 dired-marker-stack-pointer 0
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4089 dired-marker-char c)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4090 (dired-update-mode-line-modified t)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4091 (dired-set-current-marker-string))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4092
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4093 (defun dired-restore-marker-char ()
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4094 "Restore the marker character to its previous value.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4095 Uses `dired-default-marker' if the marker stack is empty."
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4096 (interactive)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4097 (setq dired-marker-stack (cdr dired-marker-stack)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4098 dired-marker-char (car dired-marker-stack)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4099 dired-marker-stack-pointer (min dired-marker-stack-pointer
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4100 (length dired-marker-stack)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4101 (or dired-marker-char
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4102 (setq dired-marker-char dired-default-marker))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4103 (dired-set-current-marker-string)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4104 (dired-update-mode-line-modified t)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4105 (or dired-marker-stack (message "Marker is %c" dired-marker-char)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4106
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4107 (defun dired-marker-stack-left (n)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4108 "Moves the marker stack cursor to the left."
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4109 (interactive "p")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4110 (let ((len (1+ (length dired-marker-stack))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4111 (or dired-marker-stack (error "Dired marker stack is empty."))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4112 (setq dired-marker-stack-pointer
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4113 (% (+ dired-marker-stack-pointer n) len))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4114 (if (< dired-marker-stack-pointer 0)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4115 (setq dired-marker-stack-pointer (+ dired-marker-stack-pointer
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4116 len)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4117 (dired-set-current-marker-string)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4118 (setq dired-marker-char
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4119 (if (= dired-marker-stack-pointer (1- len))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4120 dired-default-marker
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4121 (nth dired-marker-stack-pointer dired-marker-stack))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4122 (dired-update-mode-line-modified t))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4123
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4124 (defun dired-marker-stack-right (n)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4125 "Moves the marker stack cursor to the right."
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4126 (interactive "p")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4127 (dired-marker-stack-left (- n)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4128
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4129 ;;; Commands to mark or flag files based on their characteristics or names.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4130
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4131 (defun dired-mark-symlinks (&optional unflag-p)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4132 "Mark all symbolic links.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4133 With prefix argument, unflag all those files."
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4134 (interactive "P")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4135 (dired-check-ls-l)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4136 (let ((dired-marker-char (if unflag-p ?\040 dired-marker-char)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4137 (dired-mark-if (looking-at dired-re-sym) "symbolic link"))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4138 (dired-update-mode-line-modified t))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4139
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4140 (defun dired-mark-directories (&optional unflag-p)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4141 "Mark all directory file lines except `.' and `..'.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4142 With prefix argument, unflag all those files."
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4143 (interactive "P")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4144 (if dired-re-dir
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4145 (progn
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4146 (dired-check-ls-l)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4147 (let ((dired-marker-char (if unflag-p ?\040 dired-marker-char)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4148 (dired-mark-if (and (looking-at dired-re-dir)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4149 (not (looking-at dired-re-dot)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4150 "directory file"))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4151 (dired-update-mode-line-modified t))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4152
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4153 (defun dired-mark-executables (&optional unflag-p)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4154 "Mark all executable files.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4155 With prefix argument, unflag all those files."
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4156 (interactive "P")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4157 (if dired-re-exe
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4158 (progn
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4159 (dired-check-ls-l)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4160 (let ((dired-marker-char (if unflag-p ?\040 dired-marker-char)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4161 (dired-mark-if (looking-at dired-re-exe) "executable file"))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4162 (dired-update-mode-line-modified t))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4163
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4164 (defun dired-flag-backup-files (&optional unflag-p)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4165 "Flag all backup files (names ending with `~') for deletion.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4166 With prefix argument, unflag these files."
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4167 (interactive "P")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4168 (dired-check-ls-l)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4169 (let ((dired-marker-char (if unflag-p ?\040 dired-del-marker)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4170 (dired-mark-if
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4171 (and (not (and dired-re-dir (looking-at dired-re-dir)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4172 (let ((fn (dired-get-filename t t)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4173 (if fn (backup-file-name-p fn))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4174 "backup file"))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4175 (dired-update-mode-line-modified t))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4176
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4177 (defun dired-flag-auto-save-files (&optional unflag-p)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4178 "Flag for deletion files whose names suggest they are auto save files.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4179 A prefix argument says to unflag those files instead."
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4180 (interactive "P")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4181 (let ((dired-marker-char (if unflag-p ?\040 dired-del-marker)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4182 (dired-mark-if
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4183 ;; It is less than general to check for ~ here,
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4184 ;; but it's the only way this runs fast enough.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4185 (and (save-excursion (end-of-line)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4186 (eq (preceding-char) ?#))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4187 (not (and dired-re-dir (looking-at dired-re-dir)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4188 (let ((fn (dired-get-filename t t)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4189 (if fn (auto-save-file-name-p
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4190 (file-name-nondirectory fn)))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4191 "auto save file"))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4192 (dired-update-mode-line-modified t))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4193
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4194 (defun dired-mark-rcs-files (&optional unflag-p)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4195 "Mark all files that are under RCS control.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4196 With prefix argument, unflag all those files.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4197 Mentions RCS files for which a working file was not found in this buffer.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4198 Type \\[dired-why] to see them again."
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4199 ;; Returns failures, or nil on success.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4200 ;; Finding those with locks would require to peek into the ,v file,
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4201 ;; depends slightly on the RCS version used and should be done
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4202 ;; together with the Emacs RCS interface.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4203 ;; Unfortunately, there is no definitive RCS interface yet.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4204 (interactive "P")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4205 (message "%sarking RCS controlled files..." (if unflag-p "Unm" "M"))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4206 (let ((dired-marker-char (if unflag-p ?\ dired-marker-char))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4207 rcs-files wf failures count total)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4208 (mapcar ; loop over subdirs
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4209 (function
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4210 (lambda (dir)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4211 (or (equal (file-name-nondirectory (directory-file-name dir))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4212 "RCS")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4213 ;; skip inserted RCS subdirs
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4214 (setq rcs-files
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4215 (append (directory-files dir t ",v$") ; *,v and RCS/*,v
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4216 (let ((rcs-dir (expand-file-name "RCS" dir)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4217 (if (file-directory-p rcs-dir)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4218 (mapcar ; working files from ./RCS are in ./
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4219 (function
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4220 (lambda (x)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4221 (expand-file-name x dir)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4222 (directory-files
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4223 (file-name-as-directory rcs-dir)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4224 nil ",v$"))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4225 rcs-files)))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4226 (mapcar (function car) dired-subdir-alist))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4227 (setq total (length rcs-files))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4228 (while rcs-files
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4229 (setq wf (substring (car rcs-files) 0 -2)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4230 rcs-files (cdr rcs-files))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4231 (save-excursion (if (dired-goto-file wf)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4232 (dired-mark 1) ; giving a prefix avoids checking
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4233 ; for subdir line.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4234 (setq failures (cons wf failures)))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4235 (dired-update-mode-line-modified t)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4236 (if (null failures)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4237 (message "%d RCS file%s %smarked."
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4238 total (dired-plural-s total) (if unflag-p "un" ""))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4239 (setq count (length failures))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4240 (dired-log-summary (buffer-name (current-buffer))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4241 "RCS working file not found %s" failures)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4242 (message "%d RCS file%s: %d %smarked - %d not found %s."
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4243 total (dired-plural-s total) (- total count)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4244 (if unflag-p "un" "") count failures))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4245 failures))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4246
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4247
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4248 ;;;; ------------------------------------------------------------
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4249 ;;;; Logging failures
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4250 ;;;; ------------------------------------------------------------
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4251
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4252 (defun dired-why ()
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4253 "Pop up a buffer with error log output from Dired.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4254 A group of errors from a single command ends with a formfeed.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4255 Thus, use \\[backward-page] to find the beginning of a group of errors."
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4256 (interactive)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4257 (if (get-buffer dired-log-buffer)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4258 (let ((owindow (selected-window))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4259 (window (display-buffer (get-buffer dired-log-buffer))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4260 (unwind-protect
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4261 (progn
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4262 (select-window window)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4263 (goto-char (point-max))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4264 (recenter -1))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4265 (select-window owindow)))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4266
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4267 (defun dired-log (buffer-name log &rest args)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4268 ;; Log a message or the contents of a buffer.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4269 ;; BUFFER-NAME is the name of the dired buffer to which the message applies.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4270 ;; If LOG is a string and there are more args, it is formatted with
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4271 ;; those ARGS. Usually the LOG string ends with a \n.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4272 ;; End each bunch of errors with (dired-log t): this inserts
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4273 ;; current time and buffer, and a \f (formfeed).
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4274 (or (stringp buffer-name) (setq buffer-name (buffer-name buffer-name)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4275 (let ((obuf (current-buffer)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4276 (unwind-protect ; want to move point
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4277 (progn
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4278 (set-buffer (get-buffer-create dired-log-buffer))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4279 (goto-char (point-max))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4280 (let (buffer-read-only)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4281 (cond ((stringp log)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4282 (insert (if args
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4283 (apply (function format) log args)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4284 log)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4285 ((bufferp log)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4286 (insert-buffer log))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4287 ((eq t log)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4288 (insert "\n\t" (current-time-string)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4289 "\tBuffer `" buffer-name "'\n\f\n")))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4290 (set-buffer obuf))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4291
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4292 (defun dired-log-summary (buffer-name string failures)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4293 (message (if failures "%s--type y for details %s"
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4294 "%s--type y for details")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4295 string failures)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4296 ;; Log a summary describing a bunch of errors.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4297 (dired-log buffer-name (concat "\n" string))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4298 (if failures (dired-log buffer-name "\n%s" failures))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4299 (dired-log buffer-name t))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4300
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4301
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4302 ;;;; -------------------------------------------------------
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4303 ;;;; Sort mode of dired buffers.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4304 ;;;; -------------------------------------------------------
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4305
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4306 (defun dired-sort-type (list)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4307 ;; Returns the sort type of LIST, as a symbol.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4308 (let* ((list (reverse list))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4309 (alist (sort
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4310 (mapcar (function
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4311 (lambda (x)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4312 (cons (length (memq (car x) list)) (cdr x))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4313 dired-sort-type-alist)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4314 (function
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4315 (lambda (x y)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4316 (> (car x) (car y))))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4317 (winner (car alist)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4318 (if (zerop (car winner))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4319 'name
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4320 (cdr winner))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4321
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4322 (defun dired-sort-set-modeline (&optional switches)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4323 ;; Set modeline display according to dired-internal-switches.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4324 ;; Modeline display of "by name" or "by date" guarantees the user a
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4325 ;; match with the corresponding regexps. Non-matching switches are
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4326 ;; shown literally.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4327 (or switches (setq switches dired-internal-switches))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4328 (setq dired-sort-mode
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4329 (if dired-show-ls-switches
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4330 (concat " " (dired-make-switches-string
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4331 (or switches dired-internal-switches)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4332 (concat " by " (and (memq ?r switches) "rev-")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4333 (symbol-name (dired-sort-type switches)))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4334 ;; update mode line
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4335 (set-buffer-modified-p (buffer-modified-p)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4336
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4337 (defun dired-sort-toggle-or-edit (&optional arg)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4338 "Toggle between sort by date/name for the current subdirectory.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4339
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4340 With a 0 prefix argument, simply reports on the current switches.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4341
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4342 With a prefix 1 allows the ls switches for the current subdirectory to be
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4343 edited.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4344
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4345 With a prefix 2 allows the default ls switches for newly inserted
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4346 subdirectories to be edited.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4347
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4348 With a prefix \\[universal-argument] allows you to sort the entire
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4349 buffer by either name or date.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4350
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4351 With a prefix \\[universal-argument] \\[universal-argument] allows the default switches
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4352 for the entire buffer to be edited, and then reverts the buffer so that all
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4353 subdirectories are sorted according to these switches.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4354
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4355 Note that although dired allows different ls switches to be used for
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4356 different subdirectories, certain combinations of ls switches are incompatible.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4357 If incompatible switches are detected, dired will offer to revert the buffer
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4358 to force the ls switches for all subdirectories to a single value. If you
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4359 refuse to revert the buffer, any change of ls switches will be aborted."
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4360 (interactive "P")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4361 (cond
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4362 ((eq arg 0)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4363 ;; Report on switches
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4364 (message "Switches for current subdir: %s. Default for buffer: %s."
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4365 (dired-make-switches-string
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4366 (nth 3 (assoc (dired-current-directory) dired-subdir-alist)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4367 (dired-make-switches-string dired-internal-switches)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4368 ((null arg)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4369 ;; Toggle between sort by date/name.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4370 (let* ((dir (dired-current-directory))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4371 (curr (nth 3 (assoc dir dired-subdir-alist))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4372 (dired-sort-other
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4373 (if (eq (dired-sort-type curr) 'name)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4374 (cons ?t curr)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4375 (mapcar (function
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4376 (lambda (x)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4377 (setq curr
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4378 (delq (car x) curr))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4379 dired-sort-type-alist)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4380 curr)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4381 nil dir)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4382 ((eq arg 1)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4383 ;; Edit switches for current subdir.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4384 (let* ((dir (dired-current-directory))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4385 (switch-string
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4386 (read-string
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4387 "New ls switches for current subdir (must contain -l): "
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4388 (dired-make-switches-string
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4389 (nth 3 (assoc dir dired-subdir-alist)))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4390 (switches (dired-make-switches-list switch-string)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4391 (if (dired-compatible-switches-p switches dired-internal-switches)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4392 (dired-sort-other switches nil dir)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4393 (if (or
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4394 (memq 'sort-revert dired-no-confirm)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4395 (y-or-n-p
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4396 (format
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4397 "Switches %s incompatible with default %s. Revert buffer? "
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4398 switch-string
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4399 (dired-make-switches-string dired-internal-switches))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4400 (dired-sort-other switches nil nil)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4401 (error "Switches unchanged. Remain as %s." switch-string)))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4402 ((eq arg 2)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4403 ;; Set new defaults for subdirs inserted in the future.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4404 (let* ((switch-string
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4405 (read-string
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4406 "Default ls switches for new subdirs (must contain -l): "
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4407 (dired-make-switches-string dired-internal-switches)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4408 (switches (dired-make-switches-list switch-string))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4409 (alist dired-subdir-alist)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4410 x bad-switches)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4411 (while alist
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4412 (setq x (nth 3 (car alist))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4413 alist (cdr alist))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4414 (or (dired-compatible-switches-p x switches)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4415 (member x bad-switches)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4416 (setq bad-switches (cons x bad-switches))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4417 (if bad-switches
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4418 (if (or (memq 'sort-revert dired-no-confirm)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4419 (y-or-n-p
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4420 (format
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4421 "Switches %s incompatible with %s. Revert buffer? "
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4422 switch-string (mapconcat 'dired-make-switches-string
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4423 bad-switches ", "))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4424 (dired-sort-other switches nil nil)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4425 (error "Default switches unchanged. Remain as %s."
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4426 (dired-make-switches-string dired-internal-switches)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4427 (dired-sort-other switches t nil))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4428 ((or (equal arg '(4)) (eq arg 'date) (eq arg 'name))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4429 ;; Toggle the entire buffer name/data.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4430 (let ((cursor-in-echo-area t)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4431 (switches (copy-sequence dired-internal-switches))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4432 (type (and (symbolp arg) arg))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4433 char)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4434 (while (null type)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4435 (message "Sort entire buffer according to (n)ame or (d)ate? ")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4436 (setq char (read-char)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4437 type (cond
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4438 ((char-equal char ?d) 'date)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4439 ((char-equal char ?n) 'name)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4440 (t (message "Type one of n or d.") (sit-for 1) nil))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4441 (mapcar (function
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4442 (lambda (x)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4443 (setq switches
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4444 (delq (car x) switches))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4445 dired-sort-type-alist)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4446 (dired-sort-other
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4447 (if (eq type 'date) (cons ?t switches) switches) nil nil)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4448 ((equal arg '(16))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4449 ;; Edit the switches for the entire buffer.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4450 (dired-sort-other
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4451 (dired-make-switches-list
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4452 (read-string
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4453 "Change ls switches for entire buffer to (must contain -l): "
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4454 (dired-make-switches-string dired-internal-switches)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4455 nil nil))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4456 (t
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4457 ;; No idea what's going on.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4458 (error
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4459 "Invalid prefix. See %s dired-sort-toggle-or-edit."
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4460 (substitute-command-keys
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4461 (if (featurep 'ehelp)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4462 "\\[electric-describe-function]"
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4463 "\\[describe-function]"))))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4464
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4465 (defun dired-sort-other (switches &optional no-revert subdir)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4466 ;; Specify new ls SWITCHES for current dired buffer.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4467 ;; With optional second arg NO-REVERT, don't refresh the listing afterwards.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4468 ;; If subdir is non-nil, only changes the switches for the
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4469 ;; sudirectory.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4470 (if subdir
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4471 (let ((elt (assoc subdir dired-subdir-alist)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4472 (if elt (setcar (nthcdr 3 elt) switches)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4473 (setq dired-internal-switches switches))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4474 (or no-revert
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4475 (cond
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4476
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4477 (subdir
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4478 (let ((ofile (dired-get-filename nil t))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4479 (opoint (point)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4480 (message "Relisting %s..." subdir)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4481 (dired-insert-subdir subdir switches)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4482 (message "Relisting %s... done" subdir)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4483 (or (and ofile (dired-goto-file ofile)) (goto-char opoint))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4484
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4485 ((memq ?R switches)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4486 ;; We are replacing a buffer with a giant recursive listing.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4487 (let ((opoint (point))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4488 (ofile (dired-get-filename nil t))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4489 (hidden-subdirs (dired-remember-hidden))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4490 (mark-alist (dired-remember-marks (point-min) (point-max)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4491 (kill-files-p (save-excursion
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4492 (goto-char (point))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4493 (search-forward
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4494 (concat (char-to-string ?\r)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4495 (regexp-quote
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4496 (char-to-string
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4497 dired-kill-marker-char)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4498 nil t)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4499 (omit-files (nth 2 (nth (1- (length dired-subdir-alist))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4500 dired-subdir-alist)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4501 buffer-read-only)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4502 (dired-readin dired-directory (current-buffer)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4503 (or (consp dired-directory)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4504 (null (file-directory-p dired-directory))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4505 (dired-mark-remembered mark-alist) ; mark files that were marked
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4506 (if kill-files-p (dired-do-hide dired-kill-marker-char))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4507 (if omit-files
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4508 (dired-omit-expunge nil t))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4509 ;; hide subdirs that were hidden
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4510 (save-excursion
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4511 (mapcar (function (lambda (dir)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4512 (if (dired-goto-subdir dir)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4513 (dired-hide-subdir 1))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4514 hidden-subdirs))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4515 ;; Try to get back to where we were
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4516 (or (and ofile (dired-goto-file ofile))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4517 (goto-char opoint))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4518 (dired-move-to-filename)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4519
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4520 (t
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4521 ;; Clear all switches in the subdir alist
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4522 (setq dired-subdir-alist
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4523 (mapcar (function
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4524 (lambda (x)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4525 (setcar (nthcdr 3 x) nil)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4526 x))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4527 dired-subdir-alist))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4528 (revert-buffer nil t))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4529 (dired-update-mode-line t))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4530
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4531 (defun dired-compatible-switches-p (list1 list2)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4532 ;; Returns t if list1 and list2 are allowed as switches in the same
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4533 ;; dired buffer.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4534 (and (eq (null (or (memq ?l list1) (memq ?o list1) (memq ?g list1)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4535 (null (or (memq ?l list2) (memq ?o list2) (memq ?g list2))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4536 (eq (null (memq ?F list1)) (null (memq ?F list2)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4537 (eq (null (memq ?p list1)) (null (memq ?p list2)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4538 (eq (null (memq ?b list1)) (null (memq ?b list2)))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4539
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4540 (defun dired-check-ls-l (&optional switches)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4541 ;; Check for long-style listings
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4542 (let ((switches (or switches dired-internal-switches)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4543 (or (memq ?l switches) (memq ?o switches) (memq ?g switches)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4544 (error "Dired needs -l, -o, or -g in ls switches"))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4545
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4546
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4547 ;;;; --------------------------------------------------------------
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4548 ;;;; Creating new files.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4549 ;;;; --------------------------------------------------------------
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4550 ;;;
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4551 ;;; The dired-create-files paradigm is used for copying, renaming,
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4552 ;;; compressing, and making hard and soft links.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4553
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4554 (defun dired-file-marker (file)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4555 ;; Return FILE's marker, or nil if unmarked.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4556 (save-excursion
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4557 (and (dired-goto-file file)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4558 (progn
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4559 (skip-chars-backward "^\n\r")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4560 (and (not (= ?\040 (following-char)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4561 (following-char))))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4562
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4563 ;; The basic function for half a dozen variations on cp/mv/ln/ln -s.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4564 (defun dired-create-files (file-creator operation fn-list name-constructor
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4565 &optional marker-char query
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4566 implicit-to)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4567 ;; Create a new file for each from a list of existing files. The user
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4568 ;; is queried, dired buffers are updated, and at the end a success or
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4569 ;; failure message is displayed
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4570
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4571 ;; FILE-CREATOR must accept three args: oldfile newfile ok-if-already-exists
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4572 ;; It is called for each file and must create newfile, the entry of
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4573 ;; which will be added. The user will be queried if the file already
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4574 ;; exists. If oldfile is removed by FILE-CREATOR (i.e, it is a
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4575 ;; rename), it is FILE-CREATOR's responsibility to update dired
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4576 ;; buffers. FILE-CREATOR must abort by signalling a file-error if it
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4577 ;; could not create newfile. The error is caught and logged.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4578
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4579 ;; OPERATION (a capitalized string, e.g. `Copy') describes the
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4580 ;; operation performed. It is used for error logging.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4581
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4582 ;; FN-LIST is the list of files to copy (full absolute pathnames).
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4583
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4584 ;; NAME-CONSTRUCTOR returns a newfile for every oldfile, or nil to
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4585 ;; skip. If it skips files, it is supposed to tell why (using dired-log).
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4586
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4587 ;; Optional MARKER-CHAR is a character with which to mark every
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4588 ;; newfile's entry, or t to use the current marker character if the
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4589 ;; oldfile was marked.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4590
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4591 ;; QUERY is a function to use to prompt the user about creating a file.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4592 ;; It accepts two args, the from and to files,
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4593 ;; and must return nil or t. If QUERY is nil, then no user
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4594 ;; confirmation will be requested.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4595
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4596 ;; If IMPLICIT-TO is non-nil, then the file constructor does not take
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4597 ;; a to-file arg. e.g. compress.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4598
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4599 (let ((success-count 0)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4600 (total (length fn-list))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4601 failures skipped overwrite-query)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4602 ;; Fluid vars used for storing responses of previous queries must be
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4603 ;; initialized.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4604 (dired-save-excursion
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4605 (setq dired-overwrite-backup-query nil
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4606 dired-file-creator-query nil)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4607 (mapcar
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4608 (function
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4609 (lambda (from)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4610 (let ((to (funcall name-constructor from)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4611 (if to
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4612 (if (equal to from)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4613 (progn
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4614 (dired-log (buffer-name (current-buffer))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4615 "Cannot %s to same file: %s\n"
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4616 (downcase operation) from)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4617 (setq skipped (cons (dired-make-relative from) skipped)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4618 (if (or (null query)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4619 (funcall query from to))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4620 (let* ((overwrite (let (jka-compr-enabled)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4621 ;; Don't let jka-compr fool us.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4622 (file-exists-p to)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4623 ;; for dired-handle-overwrite
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4624 (dired-overwrite-confirmed
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4625 (and overwrite
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4626 (let ((help-form '(format "\
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4627 Type SPC or `y' to overwrite file `%s',
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4628 DEL or `n' to skip to next,
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4629 ESC or `q' to not overwrite any of the remaining files,
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4630 `!' to overwrite all remaining files with no more questions." to)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4631 (dired-query 'overwrite-query
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4632 "Overwrite %s?" to))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4633 ;; must determine if FROM is marked before
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4634 ;; file-creator gets a chance to delete it
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4635 ;; (in case of a move).
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4636 (actual-marker-char
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4637 (cond ((integerp marker-char) marker-char)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4638 (marker-char (dired-file-marker from))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4639 (t nil))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4640 (if (and overwrite (null dired-overwrite-confirmed))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4641 (setq skipped (cons (dired-make-relative from)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4642 skipped))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4643 (condition-case err
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4644 (let ((dired-unhandle-add-files
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4645 (cons to dired-unhandle-add-files)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4646 (if implicit-to
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4647 (funcall file-creator from
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4648 dired-overwrite-confirmed)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4649 (funcall file-creator from to
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4650 dired-overwrite-confirmed))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4651 (setq success-count (1+ success-count))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4652 (message "%s: %d of %d"
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4653 operation success-count total)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4654 (dired-add-file to actual-marker-char))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4655 (file-error ; FILE-CREATOR aborted
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4656 (progn
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4657 (setq failures (cons (dired-make-relative from)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4658 failures))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4659 (dired-log (buffer-name (current-buffer))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4660 "%s `%s' to `%s' failed:\n%s\n"
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4661 operation from to err))))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4662 (setq skipped (cons (dired-make-relative from) skipped))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4663 (setq skipped (cons (dired-make-relative from) skipped))))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4664 fn-list)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4665 (cond
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4666 (failures
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4667 (dired-log-summary
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4668 (buffer-name (current-buffer))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4669 (format "%s failed for %d of %d file%s"
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4670 operation (length failures) total
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4671 (dired-plural-s total)) failures))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4672 (skipped
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4673 (dired-log-summary
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4674 (buffer-name (current-buffer))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4675 (format "%s: %d of %d file%s skipped"
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4676 operation (length skipped) total
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4677 (dired-plural-s total)) skipped))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4678 (t
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4679 (message "%s: %s file%s."
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4680 operation success-count (dired-plural-s success-count)))))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4681
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4682 (defun dired-do-create-files (op-symbol file-creator operation arg
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4683 &optional marker-char
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4684 prompter how-to)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4685 ;; Create a new file for each marked file.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4686 ;; Prompts user for target, which is a directory in which to create
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4687 ;; the new files. Target may be a plain file if only one marked
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4688 ;; file exists.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4689 ;; OP-SYMBOL is the symbol for the operation. Function `dired-mark-pop-up'
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4690 ;; will determine wether pop-ups are appropriate for this OP-SYMBOL.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4691 ;; FILE-CREATOR and OPERATION as in dired-create-files.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4692 ;; ARG as in dired-get-marked-files.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4693 ;; PROMPTER is a function of one-arg, the list of files, to return a prompt
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4694 ;; to use for dired-read-file-name. If it is nil, then a default prompt
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4695 ;; will be used.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4696 ;; Optional arg MARKER-CHAR as in dired-create-files.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4697 ;; Optional arg HOW-TO determines how to treat target:
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4698 ;; If HOW-TO is not given (or nil), and target is a directory, the
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4699 ;; file(s) are created inside the target directory. If target
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4700 ;; is not a directory, there must be exactly one marked file,
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4701 ;; else error.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4702 ;; If HOW-TO is t, then target is not modified. There must be
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4703 ;; exactly one marked file, else error.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4704 ;; Else HOW-TO is assumed to be a function of one argument, target,
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4705 ;; that looks at target and returns a value for the into-dir
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4706 ;; variable. The function dired-into-dir-with-symlinks is provided
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4707 ;; for the case (common when creating symlinks) that symbolic
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4708 ;; links to directories are not to be considered as directories
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4709 ;; (as file-directory-p would if HOW-TO had been nil).
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4710
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4711 (let* ((fn-list (dired-get-marked-files nil arg))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4712 (fn-count (length fn-list))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4713 (cdir (dired-current-directory))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4714 (target (expand-file-name
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4715 (dired-mark-read-file-name
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4716 (if prompter
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4717 (funcall prompter fn-list)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4718 (concat operation " %s to: "))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4719 (dired-dwim-target-directory)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4720 op-symbol arg (mapcar (function
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4721 (lambda (fn)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4722 (dired-make-relative fn cdir t)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4723 fn-list))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4724 (into-dir (cond ((null how-to) (file-directory-p target))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4725 ((eq how-to t) nil)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4726 (t (funcall how-to target)))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4727 (if (and (> fn-count 1)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4728 (not into-dir))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4729 (error "Marked %s: target must be a directory: %s" operation target))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4730 ;; rename-file bombs when moving directories unless we do this:
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4731 (or into-dir (setq target (directory-file-name target)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4732 (dired-create-files
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4733 file-creator operation fn-list
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4734 (if into-dir ; target is a directory
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4735 (list 'lambda '(from)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4736 (list 'expand-file-name '(file-name-nondirectory from) target))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4737 (list 'lambda '(from) target))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4738 marker-char)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4739
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4740 (defun dired-into-dir-with-symlinks (target)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4741 (and (file-directory-p target)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4742 (not (file-symlink-p target))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4743 ;; This may not always be what you want, especially if target is your
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4744 ;; home directory and it happens to be a symbolic link, as is often the
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4745 ;; case with NFS and automounters. Or if you want to make symlinks
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4746 ;; into directories that themselves are only symlinks, also quite
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4747 ;; common.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4748 ;; So we don't use this function as value for HOW-TO in
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4749 ;; dired-do-symlink, which has the minor disadvantage of
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4750 ;; making links *into* a symlinked-dir, when you really wanted to
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4751 ;; *overwrite* that symlink. In that (rare, I guess) case, you'll
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4752 ;; just have to remove that symlink by hand before making your marked
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4753 ;; symlinks.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4754
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4755 (defun dired-handle-overwrite (to)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4756 ;; Save old version of a to be overwritten file TO.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4757 ;; `dired-overwrite-confirmed' and `dired-overwrite-backup-query'
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4758 ;; are fluid vars from dired-create-files.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4759 (if (and dired-backup-if-overwrite
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4760 dired-overwrite-confirmed
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4761 (or (eq 'always dired-backup-if-overwrite)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4762 (dired-query 'dired-overwrite-backup-query
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4763 (format "Make backup for existing file `%s'? " to))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4764 (let ((backup (car (find-backup-file-name to))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4765 (rename-file to backup 0)))) ; confirm overwrite of old backup
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4766
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4767 (defun dired-dwim-target-directory ()
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4768 ;; Try to guess which target directory the user may want.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4769 ;; If there is a dired buffer displayed in the next window, use
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4770 ;; its current subdir, else use current subdir of this dired buffer.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4771 ;; non-dired buffer may want to profit from this function, e.g. vm-uudecode
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4772 (let* ((this-dir (and (eq major-mode 'dired-mode)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4773 (dired-current-directory)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4774 (dwimmed
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4775 (if dired-dwim-target
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4776 (let* ((other-buf (window-buffer (next-window)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4777 (other-dir (save-excursion
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4778 (set-buffer other-buf)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4779 (and (eq major-mode 'dired-mode)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4780 (dired-current-directory)))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4781 (or other-dir this-dir))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4782 this-dir)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4783 (and dwimmed (dired-abbreviate-file-name dwimmed))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4784
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4785 (defun dired-get-target-directory ()
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4786 "Writes a copy of the current subdirectory into an active minibuffer."
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4787 (interactive)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4788 (let ((mb (dired-get-active-minibuffer-window)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4789 (if mb
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4790 (let ((dir (dired-current-directory)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4791 (select-window mb)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4792 (set-buffer (window-buffer mb))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4793 (erase-buffer)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4794 (insert dir))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4795 (error "No active minibuffer"))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4796
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4797 ;;; Copying files
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4798
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4799 (defun dired-do-copy (&optional arg)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4800 "Copy all marked (or next ARG) files, or copy the current file.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4801 When operating on just the current file, you specify the new name.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4802 When operating on multiple or marked files, you specify a directory
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4803 and the files are copied into that directory, retaining the same file names.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4804
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4805 A zero prefix argument copies nothing. But it toggles the
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4806 variable `dired-copy-preserve-time' (which see)."
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4807 (interactive "P")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4808 (if (not (zerop (prefix-numeric-value arg)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4809 (dired-do-create-files 'copy (function dired-copy-file)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4810 (if dired-copy-preserve-time "Copy [-p]" "Copy")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4811 arg dired-keep-marker-copy)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4812 (setq dired-copy-preserve-time (not dired-copy-preserve-time))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4813 (if dired-copy-preserve-time
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4814 (message "Copy will preserve time.")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4815 (message "Copied files will get current date."))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4816
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4817 (defun dired-copy-file (from to ok-flag)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4818 (dired-handle-overwrite to)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4819 (copy-file from to ok-flag dired-copy-preserve-time))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4820
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4821 ;;; Renaming/moving files
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4822
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4823 (defun dired-do-rename (&optional arg)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4824 "Rename current file or all marked (or next ARG) files.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4825 When renaming just the current file, you specify the new name.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4826 When renaming multiple or marked files, you specify a directory.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4827
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4828 A zero ARG moves no files but toggles `dired-dwim-target' (which see)."
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4829 (interactive "P")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4830 (if (not (zerop (prefix-numeric-value arg)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4831 (dired-do-create-files 'move (function dired-rename-file)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4832 "Move" arg dired-keep-marker-rename
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4833 (function
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4834 (lambda (list)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4835 (if (= (length list) 1)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4836 "Rename %s to: "
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4837 "Move %s to: "))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4838 (setq dired-dwim-target (not dired-dwim-target))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4839 (message "dired-dwim-target is %s." (if dired-dwim-target "ON" "OFF"))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4840
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4841 (defun dired-rename-file (from to ok-flag)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4842 (dired-handle-overwrite to)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4843 (let ((insert (assoc (file-name-as-directory from) dired-subdir-alist)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4844 (rename-file from to ok-flag) ; error is caught in -create-files
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4845 ;; Silently rename the visited file of any buffer visiting this file.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4846 (dired-rename-update-buffers from to insert)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4847
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4848 (defun dired-rename-update-buffers (from to &optional insert)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4849 (if (get-file-buffer from)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4850 (save-excursion
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4851 (set-buffer (get-file-buffer from))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4852 (let ((modflag (buffer-modified-p)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4853 (set-visited-file-name to) ; kills write-file-hooks
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4854 (set-buffer-modified-p modflag)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4855 ;; It's a directory. More work to do.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4856 (let ((blist (buffer-list))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4857 (from-dir (file-name-as-directory from))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4858 (to-dir (file-name-as-directory to)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4859 (save-excursion
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4860 (while blist
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4861 (set-buffer (car blist))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4862 (setq blist (cdr blist))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4863 (cond
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4864 (buffer-file-name
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4865 (if (dired-in-this-tree buffer-file-name from-dir)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4866 (let ((modflag (buffer-modified-p)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4867 (unwind-protect
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4868 (set-visited-file-name
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4869 (concat to-dir (substring buffer-file-name
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4870 (length from-dir))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4871 (set-buffer-modified-p modflag)))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4872 (dired-directory
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4873 (if (string-equal from-dir (expand-file-name default-directory))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4874 ;; If top level directory was renamed, lots of things
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4875 ;; have to be updated.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4876 (progn
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4877 (dired-unadvertise from-dir)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4878 (setq default-directory to-dir
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4879 dired-directory
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4880 ;; Need to beware of wildcards.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4881 (expand-file-name
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4882 (file-name-nondirectory dired-directory)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4883 to-dir))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4884 (let ((new-name (file-name-nondirectory
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4885 (directory-file-name dired-directory))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4886 ;; Try to rename buffer, but just leave old name if new
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4887 ;; name would already exist (don't try appending "<%d>")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4888 ;; Why? --sandy 19-8-94
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4889 (or (get-buffer new-name)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4890 (rename-buffer new-name)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4891 (dired-advertise))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4892 (and insert
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4893 (assoc (file-name-directory (directory-file-name to))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4894 dired-subdir-alist)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4895 (dired-insert-subdir to))))))))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4896
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4897 ;;; Making symbolic links
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4898
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4899 (defun dired-do-symlink (&optional arg)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4900 "Make symbolic links to current file or all marked (or next ARG) files.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4901 When operating on just the current file, you specify the new name.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4902 When operating on multiple or marked files, you specify a directory
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4903 and new symbolic links are made in that directory
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4904 with the same names that the files currently have."
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4905 (interactive "P")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4906 (dired-do-create-files 'symlink (function make-symbolic-link)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4907 "SymLink" arg dired-keep-marker-symlink))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4908
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4909 ;; Relative symlinks:
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4910 ;; make-symbolic no longer expands targets (as of at least 18.57),
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4911 ;; so the code to call ln has been removed.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4912
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4913 (defun dired-do-relsymlink (&optional arg)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4914 "Symlink all marked (or next ARG) files into a directory,
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4915 or make a symbolic link to the current file.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4916 This creates relative symbolic links like
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4917
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4918 foo -> ../bar/foo
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4919
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4920 not absolute ones like
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4921
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4922 foo -> /ugly/path/that/may/change/any/day/bar/foo"
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4923 (interactive "P")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4924 (dired-do-create-files 'relsymlink (function dired-make-relative-symlink)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4925 "RelSymLink" arg dired-keep-marker-symlink))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4926
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4927 (defun dired-make-relative-symlink (target linkname
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4928 &optional ok-if-already-exists)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4929 "Make a relative symbolic link pointing to TARGET with name LINKNAME.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4930 Three arguments: FILE1 FILE2 &optional OK-IF-ALREADY-EXISTS
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4931 The link is relative (if possible), for example
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4932
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4933 \"/vol/tex/bin/foo\" \"/vol/local/bin/foo\"
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4934
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4935 results in
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4936
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4937 \"../../tex/bin/foo\" \"/vol/local/bin/foo\""
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4938 (interactive
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4939 (let ((target (read-string "Make relative symbolic link to file: ")))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4940 (list
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4941 target
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4942 (read-file-name (format "Make relsymlink to file %s: " target))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4943 0)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4944 (let* ((target (expand-file-name target))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4945 (linkname (expand-file-name linkname))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4946 (handler (or (find-file-name-handler
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4947 linkname 'dired-make-relative-symlink)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4948 (find-file-name-handler
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4949 target 'dired-make-relative-symlink))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4950 (if handler
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4951 (funcall handler 'dired-make-relative-symlink target linkname
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4952 ok-if-already-exists)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4953 (setq target (directory-file-name target)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4954 linkname (directory-file-name linkname))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4955 (make-symbolic-link
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4956 (dired-make-relative target (file-name-directory linkname) t)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4957 linkname ok-if-already-exists))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4958
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4959 ;;; Hard links -- adding names to files
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4960
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4961 (defun dired-do-hardlink (&optional arg)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4962 "Add names (hard links) current file or all marked (or next ARG) files.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4963 When operating on just the current file, you specify the new name.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4964 When operating on multiple or marked files, you specify a directory
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4965 and new hard links are made in that directory
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4966 with the same names that the files currently have."
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4967 (interactive "P")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4968 (dired-do-create-files 'hardlink (function add-name-to-file)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4969 "HardLink" arg dired-keep-marker-hardlink))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4970
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4971
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4972 ;;;; ---------------------------------------------------------------
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4973 ;;;; Running process on marked files
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4974 ;;;; ---------------------------------------------------------------
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4975 ;;;
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4976 ;;; Commands for shell processes are in dired-shell.el.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4977
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4978 ;;; Internal functions for running subprocesses,
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4979 ;;; checking and logging of their errors.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4980
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4981 (defun dired-call-process (program discard &rest arguments)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4982 ;; Run PROGRAM with output to current buffer unless DISCARD is t.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4983 ;; Remaining arguments are strings passed as command arguments to PROGRAM.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4984 ;; Returns program's exit status, as an integer.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4985 ;; This is a separate function so that efs can redefine it.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4986 (let ((return
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4987 (apply 'call-process program nil (not discard) nil arguments)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4988 (if (and (not (equal shell-file-name program))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4989 (integerp return))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4990 return
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4991 ;; Fudge return code by looking for errors in current buffer.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4992 (if (zerop (buffer-size)) 0 1))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4993
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4994 (defun dired-check-process (msg program &rest arguments)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4995 ;; Display MSG while running PROGRAM, and check for output.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4996 ;; Remaining arguments are strings passed as command arguments to PROGRAM.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4997 ;; On error, insert output in a log buffer and return the
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4998 ;; offending ARGUMENTS or PROGRAM.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
4999 ;; Caller can cons up a list of failed args.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5000 ;; Else returns nil for success.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5001 (let ((err-buffer (get-buffer-create " *dired-check-process output*"))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5002 (dir default-directory))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5003 (message "%s..." msg)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5004 (save-excursion
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5005 ;; Get a clean buffer for error output:
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5006 (set-buffer err-buffer)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5007 (erase-buffer)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5008 (setq default-directory dir) ; caller's default-directory
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5009 (if (not
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5010 (eq 0 (apply (function dired-call-process) program nil arguments)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5011 (progn
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5012 (dired-log (buffer-name (current-buffer))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5013 (concat program " " (prin1-to-string arguments) "\n"))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5014 (dired-log (buffer-name (current-buffer)) err-buffer)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5015 (or arguments program t))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5016 (kill-buffer err-buffer)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5017 (message "%s...done" msg)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5018 nil))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5019
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5020 ;;; Changing file attributes
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5021
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5022 (defun dired-do-chxxx (attribute-name program op-symbol arg)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5023 ;; Change file attributes (mode, group, owner) of marked files and
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5024 ;; refresh their file lines.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5025 ;; ATTRIBUTE-NAME is a string describing the attribute to the user.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5026 ;; PROGRAM is the program used to change the attribute.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5027 ;; OP-SYMBOL is the type of operation (for use in dired-mark-pop-up).
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5028 ;; ARG describes which files to use, like in dired-get-marked-files.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5029 (let* ((files (dired-get-marked-files t arg))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5030 (new-attribute
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5031 (dired-mark-read-string
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5032 (concat "Change " attribute-name " of %s to: ")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5033 nil op-symbol arg files))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5034 (operation (concat program " " new-attribute))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5035 (failures
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5036 (dired-bunch-files 10000 (function dired-check-process)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5037 (list operation program new-attribute)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5038 files)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5039 (dired-do-redisplay arg);; moves point if ARG is an integer
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5040 (if failures
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5041 (dired-log-summary (buffer-name (current-buffer))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5042 (format "%s: error" operation) nil))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5043
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5044 (defun dired-do-chmod (&optional arg)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5045 "Change the mode of the marked (or next ARG) files.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5046 This calls chmod, thus symbolic modes like `g+w' are allowed."
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5047 (interactive "P")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5048 (dired-do-chxxx "Mode" "chmod" 'chmod arg))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5049
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5050 (defun dired-do-chgrp (&optional arg)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5051 "Change the group of the marked (or next ARG) files."
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5052 (interactive "P")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5053 (dired-do-chxxx "Group" "chgrp" 'chgrp arg))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5054
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5055 (defun dired-do-chown (&optional arg)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5056 "Change the owner of the marked (or next ARG) files."
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5057 (interactive "P")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5058 (dired-do-chxxx "Owner" dired-chown-program 'chown arg))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5059
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5060 ;;; Utilities for running processes on marked files.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5061
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5062 ;; Process all the files in FILES in batches of a convenient size,
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5063 ;; by means of (FUNCALL FUNCTION ARGS... SOME-FILES...).
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5064 ;; Batches are chosen to need less than MAX chars for the file names,
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5065 ;; allowing 3 extra characters of separator per file name.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5066 (defun dired-bunch-files (max function args files)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5067 (let (pending
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5068 (pending-length 0)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5069 failures)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5070 ;; Accumulate files as long as they fit in MAX chars,
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5071 ;; then process the ones accumulated so far.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5072 (while files
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5073 (let* ((thisfile (car files))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5074 (thislength (+ (length thisfile) 3))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5075 (rest (cdr files)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5076 ;; If we have at least 1 pending file
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5077 ;; and this file won't fit in the length limit, process now.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5078 (if (and pending (> (+ thislength pending-length) max))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5079 (setq failures
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5080 (nconc (apply function (append args pending))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5081 failures)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5082 pending nil
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5083 pending-length 0))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5084 ;; Do (setq pending (cons thisfile pending))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5085 ;; but reuse the cons that was in `files'.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5086 (setcdr files pending)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5087 (setq pending files)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5088 (setq pending-length (+ thislength pending-length))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5089 (setq files rest)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5090 (nconc (apply function (append args pending))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5091 failures)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5092
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5093
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5094 ;;;; ---------------------------------------------------------------
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5095 ;;;; Calculating data or properties for marked files.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5096 ;;;; ---------------------------------------------------------------
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5097
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5098 (defun dired-do-total-size (&optional arg)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5099 "Show total size of all marked (or next ARG) files."
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5100 (interactive "P")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5101 (let* ((result (dired-map-over-marks (dired-get-file-size) arg))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5102 (total (apply (function +) result))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5103 (num (length result)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5104 (message "%d bytes (%d kB) in %s file%s"
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5105 total (/ total 1024) num (dired-plural-s num))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5106 total))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5107
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5108 (defun dired-get-file-size ()
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5109 ;; Returns the file size in bytes of the current file, as an integer.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5110 ;; Assumes that it is on a valid file line. It's the caller's responsibility
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5111 ;; to ensure this. Assumes that match 0 for dired-re-month-and-time is
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5112 ;; at the end of the file size.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5113 (dired-move-to-filename t)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5114 ;; dired-move-to-filename must leave match-beginning 0 at the start of
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5115 ;; the date.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5116 (goto-char (match-beginning 0))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5117 (skip-chars-backward " ")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5118 (string-to-int (buffer-substring (point)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5119 (progn (skip-chars-backward "0-9")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5120 (point)))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5121
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5122 (defun dired-copy-filenames-as-kill (&optional arg)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5123 "Copy names of marked (or next ARG) files into the kill ring.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5124 The names are separated by a space, and may be copied into other buffers
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5125 with \\[yank]. The list of names is also stored in the variable
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5126 `dired-marked-files' for possible manipulation in the *scratch* buffer.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5127
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5128 With a 0 prefix argument, use the pathname relative to the top-level dired
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5129 directory for each marked file.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5130
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5131 With a prefix \\[universal-argument], use the complete pathname of each
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5132 marked file.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5133
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5134 With a prefix \\[universal-argument] \\[universal-argument], copy the complete
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5135 file line. In this case, the lines are separated by newlines.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5136
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5137 If on a subdirectory headerline and no prefix argument given, use the
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5138 subdirectory name instead."
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5139 (interactive "P")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5140 (let (res)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5141 (cond
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5142 ((and (null arg) (setq res (dired-get-subdir)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5143 (kill-new res)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5144 (message "Copied %s into kill ring." res))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5145 ((equal arg '(16))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5146 (setq dired-marked-files
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5147 (dired-map-over-marks
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5148 (concat " " ; Don't copy the mark.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5149 (buffer-substring
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5150 (progn (beginning-of-line) (1+ (point)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5151 (progn (skip-chars-forward "^\n\r") (point))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5152 nil))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5153 (let ((len (length dired-marked-files)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5154 (kill-new (concat
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5155 (mapconcat 'identity dired-marked-files "\n")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5156 "\n"))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5157 (message "Copied %d file line%s into kill ring."
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5158 len (dired-plural-s len))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5159 (t
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5160 (setq dired-marked-files
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5161 (cond
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5162 ((null arg)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5163 (dired-get-marked-files 'no-dir))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5164 ((eq arg 0)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5165 (dired-get-marked-files t))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5166 ((integerp arg)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5167 (dired-get-marked-files 'no-dir arg))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5168 ((equal arg '(4))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5169 (dired-get-marked-files))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5170 (t (error "Invalid prefix %s" arg))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5171 (let ((len (length dired-marked-files)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5172 (kill-new (mapconcat 'identity dired-marked-files " "))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5173 (message "Copied %d file name%s into kill ring."
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5174 len (dired-plural-s len)))))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5175
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5176
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5177 ;;;; -----------------------------------------------------------
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5178 ;;;; Killing subdirectories
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5179 ;;;; -----------------------------------------------------------
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5180 ;;;
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5181 ;;; These commands actually remove text from the dired buffer.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5182
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5183 (defun dired-kill-subdir (&optional remember-marks tree)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5184 "Remove all lines of current subdirectory.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5185 Lower levels are unaffected. If given a prefix when called interactively,
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5186 kills the entire directory tree below the current subdirectory."
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5187 ;; With optional REMEMBER-MARKS, return a mark-alist.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5188 (interactive (list nil current-prefix-arg))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5189 (let ((cur-dir (dired-current-directory)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5190 (if (string-equal cur-dir (expand-file-name default-directory))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5191 (error "Attempt to kill top level directory"))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5192 (if tree
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5193 (dired-kill-tree cur-dir remember-marks)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5194 (let ((beg (dired-subdir-min))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5195 (end (dired-subdir-max))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5196 buffer-read-only)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5197 (prog1
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5198 (if remember-marks (dired-remember-marks beg end))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5199 (goto-char beg)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5200 (or (bobp) (forward-char -1)) ; gobble separator
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5201 (delete-region (point) end)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5202 (dired-unsubdir cur-dir)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5203 (dired-update-mode-line)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5204 (dired-update-mode-line-modified t))))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5205
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5206 (defun dired-kill-tree (dirname &optional remember-marks)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5207 "Kill all proper subdirs of DIRNAME, excluding DIRNAME itself.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5208 With optional arg REMEMBER-MARKS, return an alist of marked files."
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5209 (interactive "DKill tree below directory: ")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5210 (let ((s-alist dired-subdir-alist) dir m-alist)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5211 (while s-alist
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5212 (setq dir (car (car s-alist))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5213 s-alist (cdr s-alist))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5214 (if (and (not (string-equal dir dirname))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5215 (dired-in-this-tree dir dirname)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5216 (dired-goto-subdir dir))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5217 (setq m-alist (nconc (dired-kill-subdir remember-marks) m-alist))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5218 (dired-update-mode-line)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5219 (dired-update-mode-line-modified t)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5220 m-alist))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5221
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5222
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5223 ;;;; ------------------------------------------------------------
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5224 ;;;; Killing file lines
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5225 ;;;; ------------------------------------------------------------
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5226 ;;;
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5227 ;;; Uses selective diplay, rather than removing lines from the buffer.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5228
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5229 (defun dired-do-kill-file-lines (&optional arg)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5230 "Kill all marked file lines, or those indicated by the prefix argument.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5231 Killing file lines means hiding them with selective display. Giving
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5232 a zero prefix redisplays all killed file lines."
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5233 (interactive "P")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5234 (or selective-display
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5235 (error "selective-display must be t for file line killing to work!"))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5236 (if (eq arg 0)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5237 (dired-do-unhide dired-kill-marker-char
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5238 "Successfully resuscitated %d file line%s."
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5239 dired-keep-marker-kill)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5240 (let ((files
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5241 (length
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5242 (dired-map-over-marks
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5243 (progn
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5244 (beginning-of-line)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5245 (subst-char-in-region (1- (point)) (point) ?\n ?\r)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5246 (dired-substitute-marker (point) (following-char)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5247 dired-kill-marker-char)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5248 (dired-update-marker-counters dired-marker-char t)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5249 t)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5250 arg))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5251 ;; Beware of extreme apparent save-excursion lossage here.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5252 (let ((opoint (point)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5253 (skip-chars-backward "^\n\r")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5254 (if (= (preceding-char) ?\n)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5255 (goto-char opoint)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5256 (setq opoint (- opoint (point)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5257 (beginning-of-line)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5258 (skip-chars-forward "^\n\r" (+ (point) opoint))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5259 (dired-update-mode-line-modified)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5260 (message "Killed %d file line%s." files (dired-plural-s files)))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5261
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5262
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5263 ;;;; ----------------------------------------------------------------
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5264 ;;;; Omitting files.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5265 ;;;; ----------------------------------------------------------------
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5266
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5267 ;; Marked files are never omitted.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5268 ;; Adapted from code submitted by:
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5269 ;; Michael D. Ernst, mernst@theory.lcs.mit.edu, 1/11/91
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5270 ;; Changed to work with selective display by Sandy Rutherford, 13/12/92.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5271 ;; For historical reasons, we still use the term expunge, although nothing
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5272 ;; is expunged from the buffer.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5273
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5274 (defun dired-omit-toggle (&optional arg)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5275 "Toggle between displaying and omitting files matching
138
6608ceec7cf8 Import from CVS: tag r20-2b3
cvs
parents: 118
diff changeset
5276 `dired-omit-regexps' in the current subdirectory.
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5277 With a positive prefix, omits files in the entire tree dired buffer.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5278 With a negative prefix, forces all files in the tree dired buffer to be
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5279 displayed."
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5280 (interactive "P")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5281 (if arg
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5282 (let ((arg (prefix-numeric-value arg)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5283 (if (>= arg 0)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5284 (dired-omit-expunge nil t)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5285 (dired-do-unhide dired-omit-marker-char "")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5286 (mapcar
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5287 (function
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5288 (lambda (elt)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5289 (setcar (nthcdr 2 elt) nil)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5290 dired-subdir-alist)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5291 (if (dired-current-subdir-omitted-p)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5292 (save-restriction
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5293 (narrow-to-region (dired-subdir-min) (dired-subdir-max))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5294 (dired-do-unhide dired-omit-marker-char "")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5295 (setcar (nthcdr 2 (assoc
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5296 (dired-current-directory) dired-subdir-alist))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5297 nil)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5298 (setq dired-subdir-omit nil))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5299 (dired-omit-expunge)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5300 (setq dired-subdir-omit t)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5301 (dired-update-mode-line t))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5302
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5303 (defun dired-current-subdir-omitted-p ()
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5304 ;; Returns t if the current subdirectory is omited.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5305 (nth 2 (assoc (dired-current-directory) dired-subdir-alist)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5306
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5307 (defun dired-remember-omitted ()
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5308 ;; Returns a list of omitted subdirs.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5309 (let ((alist dired-subdir-alist)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5310 result elt)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5311 (while alist
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5312 (setq elt (car alist)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5313 alist (cdr alist))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5314 (if (nth 2 elt)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5315 (setq result (cons (car elt) result))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5316 result))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5317
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5318 (defun dired-omit-expunge (&optional regexp full-buffer)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5319 ;; Hides all unmarked files matching REGEXP.
138
6608ceec7cf8 Import from CVS: tag r20-2b3
cvs
parents: 118
diff changeset
5320 ;; If REGEXP is nil or not specified, uses `dired-omit-regexps',
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5321 ;; and also omits filenames ending in `dired-omit-extensions'.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5322 ;; If REGEXP is the empty string, this function is a no-op.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5323 (let ((omit-re (or regexp (dired-omit-regexp)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5324 (alist dired-subdir-alist)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5325 elt min)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5326 (if (null omit-re)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5327 0
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5328 (if full-buffer
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5329 (prog1
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5330 (dired-omit-region (point-min) (point-max) omit-re)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5331 ;; Set omit property in dired-subdir-alist
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5332 (while alist
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5333 (setq elt (car alist)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5334 min (dired-get-subdir-min elt)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5335 alist (cdr alist))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5336 (if (and (<= (point-min) min) (>= (point-max) min))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5337 (setcar (nthcdr 2 elt) t))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5338 (prog1
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5339 (dired-omit-region (dired-subdir-min) (dired-subdir-max) omit-re)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5340 (setcar
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5341 (nthcdr 2 (assoc (dired-current-directory)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5342 dired-subdir-alist))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5343 t))))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5344
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5345 (defun dired-omit-region (start end regexp)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5346 ;; Omits files matching regexp in region. Returns count.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5347 (save-restriction
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5348 (narrow-to-region start end)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5349 (let ((hidden-subdirs (dired-remember-hidden))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5350 buffer-read-only count)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5351 (or selective-display
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5352 (error "selective-display must be t for file omission to work!"))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5353 (dired-omit-unhide-region start end)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5354 (let ((dired-marker-char dired-omit-marker-char)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5355 ;; since all subdirs are now unhidden, this fakes
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5356 ;; dired-move-to-end-of-filename into working faster
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5357 (selective-display nil))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5358 (or dired-omit-silent
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5359 dired-in-query (message "Omitting..."))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5360 (if (dired-mark-unmarked-files regexp nil nil 'no-dir)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5361 (setq count (dired-do-hide
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5362 dired-marker-char
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5363 (and (memq dired-omit-silent '(nil 0))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5364 (not dired-in-query)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5365 "Omitted %d line%s.")))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5366 (or dired-omit-silent dired-in-query
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5367 (message "(Nothing to omit)"))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5368 (save-excursion ;hide subdirs that were hidden
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5369 (mapcar (function (lambda (dir)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5370 (if (dired-goto-subdir dir)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5371 (dired-hide-subdir 1))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5372 hidden-subdirs))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5373 count)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5374
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5375 (defun dired-omit-unhide-region (beg end)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5376 ;; Unhides hidden, but not marked files in the region.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5377 (save-excursion
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5378 (save-restriction
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5379 (narrow-to-region beg end)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5380 (goto-char (point-min))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5381 (while (search-forward "\r" nil t)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5382 (and (char-equal (following-char) ?\ )
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5383 (subst-char-in-region (1- (point)) (point) ?\r ?\n))))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5384
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5385 (defun dired-do-unhide (char &optional fmt marker)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5386 ;; Unhides files marked with CHAR. Optional FMT is a message
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5387 ;; to be displayed. Note that after unhiding, we will need to re-hide
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5388 ;; files belonging to hidden subdirs.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5389 (save-excursion
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5390 (goto-char (point-min))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5391 (let ((count 0)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5392 (string (concat "\r" (char-to-string char)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5393 (hidden-subdirs (dired-remember-hidden))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5394 (new (if marker (concat "\n" (char-to-string marker)) "\n "))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5395 buffer-read-only)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5396 (while (search-forward string nil t)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5397 (replace-match new)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5398 (setq count (1+ count)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5399 (or (equal "" fmt)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5400 (message (or fmt "Unhid %d line%s.") count (dired-plural-s count)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5401 (goto-char (point-min))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5402 (mapcar (function (lambda (dir)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5403 (if (dired-goto-subdir dir)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5404 (dired-hide-subdir 1 t))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5405 hidden-subdirs)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5406 (if marker (dired-update-mode-line-modified t))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5407 count)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5408
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5409 (defun dired-do-hide (char &optional fmt)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5410 ;; Hides files marked with CHAR. Otional FMT is a message
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5411 ;; to be displayed. FMT is a format string taking args the number
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5412 ;; of hidden file lines, and dired-plural-s.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5413 (save-excursion
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5414 (goto-char (point-min))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5415 (let ((count 0)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5416 (string (concat "\n" (char-to-string char)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5417 buffer-read-only)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5418 (while (search-forward string nil t)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5419 (subst-char-in-region (match-beginning 0)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5420 (1+ (match-beginning 0)) ?\n ?\r t)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5421 (setq count (1+ count)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5422 (if fmt
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5423 (message fmt count (dired-plural-s count)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5424 count)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5425
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5426 (defun dired-omit-regexp ()
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5427 (let (rgxp)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5428 (if dired-omit-extensions
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5429 (setq rgxp (concat
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5430 ".\\("
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5431 (mapconcat 'regexp-quote dired-omit-extensions "\\|")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5432 "\\)$")))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5433 (if dired-omit-regexps
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5434 (setq rgxp
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5435 (concat
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5436 rgxp
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5437 (and rgxp "\\|")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5438 (mapconcat 'identity dired-omit-regexps "\\|"))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5439 rgxp))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5440
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5441 (defun dired-mark-unmarked-files (regexp msg &optional unflag-p localp)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5442 ;; Marks unmarked files matching REGEXP, displaying MSG.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5443 ;; REGEXP is matched against the complete pathname, unless localp is
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5444 ;; specified.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5445 ;; Does not re-mark files which already have a mark.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5446 ;; Returns t if any work was done, nil otherwise.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5447 (let ((dired-marker-char (if unflag-p ?\ dired-marker-char))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5448 fn)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5449 (dired-mark-if
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5450 (and
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5451 ;; not already marked
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5452 (eq (following-char) ?\ )
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5453 ;; uninteresting
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5454 (setq fn (dired-get-filename localp t))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5455 (string-match regexp fn))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5456 msg)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5457
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5458 (defun dired-add-omit-regexp (rgxp &optional how)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5459 "Adds a new regular expression to the list of omit regular expresions.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5460 With a non-zero numeric prefix argument, deletes a regular expresion from
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5461 the list.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5462
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5463 With a prefix argument \\[universal-argument], adds a new extension to
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5464 the list of file name extensions omitted.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5465 With a prefix argument \\[universal-argument] \\[universal-argument], deletes
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5466 a file name extension from the list.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5467
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5468 With a prefix 0, reports on the current omit regular expressions and
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5469 extensions."
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5470 (interactive
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5471 (list
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5472 (cond
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5473 ((null current-prefix-arg)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5474 (read-string "New omit regular expression: "))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5475 ((equal '(4) current-prefix-arg)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5476 (read-string "New omit extension (\".\" is not implicit): "))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5477 ((equal '(16) current-prefix-arg)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5478 (completing-read
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5479 "Remove from omit extensions (type SPACE for options): "
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5480 (mapcar 'list dired-omit-extensions) nil t))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5481 ((eq 0 current-prefix-arg)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5482 nil)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5483 (t
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5484 (completing-read
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5485 "Remove from omit regexps (type SPACE for options): "
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5486 (mapcar 'list dired-omit-regexps) nil t)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5487 current-prefix-arg))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5488 (let (remove)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5489 (cond
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5490 ((null how)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5491 (if (member rgxp dired-omit-regexps)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5492 (progn
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5493 (describe-variable 'dired-omit-regexps)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5494 (error "%s is already included in the list." rgxp))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5495 (setq dired-omit-regexps (cons rgxp dired-omit-regexps))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5496 ((equal how '(4))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5497 (if (member rgxp dired-omit-extensions)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5498 (progn
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5499 (describe-variable 'dired-omit-extensions)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5500 (error "%s is already included in list." rgxp))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5501 (setq dired-omit-extensions (cons rgxp dired-omit-extensions))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5502 ((equal how '(16))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5503 (let ((tail (member rgxp dired-omit-extensions)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5504 (if tail
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5505 (setq dired-omit-extensions
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5506 (delq (car tail) dired-omit-extensions)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5507 remove t)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5508 (setq remove 'ignore))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5509 ((eq 0 how)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5510 (setq remove 'ignore)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5511 (if (featurep 'ehelp)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5512 (with-electric-help
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5513 (function
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5514 (lambda ()
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5515 (princ "Omit extensions (dired-omit-extensions <V>):\n")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5516 (dired-format-columns-of-files dired-omit-extensions)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5517 (princ "\n")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5518 (princ "Omit regular expressions (dired-omit-regexps <V>):\n")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5519 (dired-format-columns-of-files dired-omit-regexps)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5520 nil)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5521 (with-output-to-temp-buffer "*Help*"
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5522 (princ "Omit extensions (dired-omit-extensions <V>):\n")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5523 (dired-format-columns-of-files dired-omit-extensions)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5524 (princ "\n")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5525 (princ "Omit regular expressions (dired-omit-regexps <V>):\n")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5526 (dired-format-columns-of-files dired-omit-regexps)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5527 (print-help-return-message))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5528 (t
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5529 (let ((tail (member rgxp dired-omit-regexps)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5530 (if tail
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5531 (setq dired-omit-regexps (delq (car tail) dired-omit-regexps)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5532 remove t)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5533 (setq remove 'ignore)))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5534 (or (eq remove 'ignore)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5535 (save-excursion
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5536 (mapcar
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5537 (function
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5538 (lambda (dir)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5539 (if (dired-goto-subdir dir)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5540 (progn
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5541 (if remove
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5542 (save-restriction
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5543 (narrow-to-region
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5544 (dired-subdir-min) (dired-subdir-max))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5545 (dired-do-unhide dired-omit-marker-char "")))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5546 (dired-omit-expunge)))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5547 (dired-remember-omitted))))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5548
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5549
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5550
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5551 ;;;; ----------------------------------------------------------------
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5552 ;;;; Directory hiding.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5553 ;;;; ----------------------------------------------------------------
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5554 ;;;
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5555 ;;; To indicate a hidden subdir, we actually insert "..." in the buffer.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5556 ;;; Aside from giving the look of ellipses (even though
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5557 ;;; selective-display-ellipses is nil), it allows us to tell the difference
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5558 ;;; between a dir with a single omitted file, and a hidden subdir with one
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5559 ;;; file.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5560
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5561 (defun dired-subdir-hidden-p (dir)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5562 (save-excursion
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5563 (and selective-display
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5564 (dired-goto-subdir dir)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5565 (looking-at "\\.\\.\\.\r"))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5566
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5567 (defun dired-unhide-subdir ()
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5568 (let (buffer-read-only)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5569 (goto-char (dired-subdir-min))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5570 (skip-chars-forward "^\n\r")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5571 (skip-chars-backward "." (- (point) 3))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5572 (if (looking-at "\\.\\.\\.\r") (delete-char 4))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5573 (dired-omit-unhide-region (point) (dired-subdir-max))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5574
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5575 (defun dired-hide-check ()
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5576 (or selective-display
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5577 (error "selective-display must be t for subdir hiding to work!")))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5578
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5579 (defun dired-hide-subdir (arg &optional really)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5580 "Hide or unhide the current subdirectory and move to next directory.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5581 Optional prefix arg is a repeat factor.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5582 Use \\[dired-hide-all] to (un)hide all directories.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5583 With the optional argument REALLY, we always hide
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5584 the subdir, regardless of dired-subdir-hidden-p."
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5585 ;; The arg REALLY is needed because when we unhide
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5586 ;; omitted files in a hidden subdir, we want to
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5587 ;; re-hide the subdir, regardless of whether dired
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5588 ;; thinks it's already hidden.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5589 (interactive "p")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5590 (dired-hide-check)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5591 (dired-save-excursion
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5592 (while (>= (setq arg (1- arg)) 0)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5593 (let* ((cur-dir (dired-current-directory))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5594 (hidden-p (and (null really)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5595 (dired-subdir-hidden-p cur-dir)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5596 (elt (assoc cur-dir dired-subdir-alist))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5597 (end-pos (1- (dired-get-subdir-max elt)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5598 buffer-read-only)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5599 ;; keep header line visible, hide rest
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5600 (goto-char (dired-get-subdir-min elt))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5601 (skip-chars-forward "^\n\r")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5602 (skip-chars-backward "." (- (point) 3))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5603 (if hidden-p
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5604 (progn
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5605 (if (looking-at "\\.\\.\\.\r")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5606 (progn
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5607 (delete-char 3)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5608 (setq end-pos (- end-pos 3))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5609 (dired-omit-unhide-region (point) end-pos))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5610 (if (looking-at "\\.\\.\\.\r")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5611 (goto-char (match-end 0))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5612 (insert "...")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5613 (setq end-pos (+ end-pos 3)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5614 (subst-char-in-region (point) end-pos ?\n ?\r)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5615 (dired-next-subdir 1 t))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5616
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5617 (defun dired-hide-all (arg)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5618 "Hide all subdirectories, leaving only their header lines.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5619 If there is already something hidden, make everything visible again.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5620 Use \\[dired-hide-subdir] to (un)hide a particular subdirectory."
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5621 (interactive "P")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5622 (dired-hide-check)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5623 (let (buffer-read-only)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5624 (dired-save-excursion
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5625 (if (let ((alist dired-subdir-alist)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5626 (hidden nil))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5627 (while (and alist (null hidden))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5628 (setq hidden (dired-subdir-hidden-p (car (car alist)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5629 alist (cdr alist)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5630 hidden)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5631 ;; unhide
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5632 (let ((alist dired-subdir-alist))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5633 (while alist
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5634 (goto-char (dired-get-subdir-min (car alist)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5635 (skip-chars-forward "^\n\r")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5636 (delete-region (point) (progn (skip-chars-backward ".") (point)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5637 (setq alist (cdr alist)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5638 (dired-omit-unhide-region (point-min) (point-max)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5639 ;; hide
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5640 (let ((alist dired-subdir-alist))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5641 (while alist
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5642 (dired-goto-subdir (car (car alist)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5643 (dired-hide-subdir 1 t)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5644 (setq alist (cdr alist))))))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5645
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5646
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5647 ;;;; -----------------------------------------------------------------
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5648 ;;;; Automatic dired buffer maintenance.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5649 ;;;; -----------------------------------------------------------------
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5650 ;;;
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5651 ;;; Keeping Dired buffers in sync with the filesystem and with each
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5652 ;;; other.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5653 ;;; When used with efs on remote directories, buffer maintainence is
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5654 ;;; done asynch.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5655
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5656 (defun dired-buffers-for-dir (dir-or-list &optional check-wildcard)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5657 ;; Return a list of buffers that dired DIR-OR-LIST
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5658 ;; (top level or in-situ subdir).
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5659 ;; The list is in reverse order of buffer creation, most recent last.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5660 ;; As a side effect, killed dired buffers for DIR are removed from
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5661 ;; dired-buffers. If DIR-OR-LIST is a wildcard or list, returns any
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5662 ;; dired buffers for which DIR-OR-LIST is equal to `dired-directory'.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5663 ;; If check-wildcard is non-nil, only returns buffers which contain dir-or-list
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5664 ;; exactly, including the wildcard part.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5665 (let ((alist dired-buffers)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5666 (as-dir (and (stringp dir-or-list)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5667 (file-name-as-directory dir-or-list)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5668 result buff elt)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5669 (while alist
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5670 (setq buff (cdr (setq elt (car alist)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5671 alist (cdr alist))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5672 ;; dired-in-this-tree is not fast. It doesn't pay to use this to check
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5673 ;; whether the buffer is a good candidate.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5674 (if (buffer-name buff)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5675 (save-excursion
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5676 (set-buffer buff)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5677 (if (or (equal dir-or-list dired-directory) ; the wildcard case.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5678 (and as-dir
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5679 (not (and check-wildcard
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5680 (string-equal
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5681 as-dir
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5682 (expand-file-name default-directory))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5683 (assoc as-dir dired-subdir-alist)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5684 (setq result (cons buff result))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5685 ;; else buffer is killed - clean up:
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5686 (setq dired-buffers (delq elt dired-buffers))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5687 (or dired-buffers (dired-remove-from-file-name-handler-alist))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5688 result))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5689
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5690 (defun dired-advertise ()
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5691 ;; Advertise in variable `dired-buffers' that we dired `default-directory'.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5692 ;; With wildcards we actually advertise too much.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5693 ;; Also makes sure that we are installed in the file-name-handler-alist
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5694 (prog1
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5695 (let ((ddir (expand-file-name default-directory)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5696 (if (memq (current-buffer) (dired-buffers-for-dir ddir))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5697 t ; we have already advertised ourselves
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5698 (setq dired-buffers
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5699 (cons (cons ddir (current-buffer))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5700 dired-buffers))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5701 ;; Do this last, otherwise the call to dired-buffers-for-dir will
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5702 ;; remove dired-handler-fn from the file-name-handler-alist.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5703 ;; Strictly speaking, we only need to do this in th else branch of
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5704 ;; the if statement. We do it unconditionally as a sanity check.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5705 (dired-check-file-name-handler-alist)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5706
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5707 (defun dired-unadvertise (dir)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5708 ;; Remove DIR from the buffer alist in variable dired-buffers.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5709 ;; This has the effect of removing any buffer whose main directory is DIR.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5710 ;; It does not affect buffers in which DIR is a subdir.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5711 ;; Removing is also done as a side-effect in dired-buffer-for-dir.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5712 (setq dired-buffers
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5713 (delq (assoc dir dired-buffers) dired-buffers))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5714 ;; If there are no more dired buffers, we are no longer needed in the
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5715 ;; file-name-handler-alist.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5716 (or dired-buffers (dired-remove-from-file-name-handler-alist)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5717
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5718 (defun dired-unadvertise-current-buffer ()
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5719 ;; Remove all references to the current buffer in dired-buffers.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5720 (setq dired-buffers
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5721 (delq nil
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5722 (mapcar
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5723 (function
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5724 (lambda (x)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5725 (and (not (eq (current-buffer) (cdr x))) x)))
116
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 114
diff changeset
5726 dired-buffers)))
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 114
diff changeset
5727 ;; If there are no more dired buffers, we are no longer needed in the
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 114
diff changeset
5728 ;; file-name-handler-alist.
9f59509498e1 Import from CVS: tag r20-1b10
cvs
parents: 114
diff changeset
5729 (or dired-buffers (dired-remove-from-file-name-handler-alist)))
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5730
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5731 (defun dired-fun-in-all-buffers (directory fun &rest args)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5732 ;; In all buffers dired'ing DIRECTORY, run FUN with ARGS.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5733 ;; Return list of buffers where FUN succeeded (i.e., returned non-nil).
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5734 (let* ((buf-list (dired-buffers-for-dir directory))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5735 (obuf (current-buffer))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5736 (owin (selected-window))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5737 (win owin)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5738 buf windows success-list)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5739 (if buf-list
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5740 (unwind-protect
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5741 (progn
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5742 (while (not (eq (setq win (next-window win)) owin))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5743 (and (memq (setq buf (window-buffer win)) buf-list)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5744 (progn
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5745 (set-buffer buf)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5746 (= (point) (window-point win)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5747 (setq windows (cons win windows))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5748 (while buf-list
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5749 (setq buf (car buf-list)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5750 buf-list (cdr buf-list))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5751 (set-buffer buf)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5752 (if (apply fun args)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5753 (setq success-list (cons (buffer-name buf) success-list))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5754 ;; dired-save-excursion prevents lossage of save-excursion
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5755 ;; for point. However, if dired buffers are displayed in
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5756 ;; other windows, the setting of window-point loses, and
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5757 ;; drags the point with it. This should fix this.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5758 (while windows
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5759 (condition-case nil
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5760 (progn
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5761 (set-buffer (window-buffer (setq win (car windows))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5762 (set-window-point win (point)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5763 (error nil))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5764 (setq windows (cdr windows))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5765 (set-buffer obuf)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5766 success-list))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5767
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5768 (defun dired-find-file-place (subdir file)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5769 ;; Finds a position to insert in SUBDIR FILE. If it can't find SUBDIR,
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5770 ;; returns nil.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5771 (let ((sort (dired-sort-type dired-internal-switches))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5772 (rev (memq ?r (nth 3 (assoc subdir dired-subdir-alist)))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5773 (cond
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5774 ((eq sort 'name)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5775 (if (dired-goto-subdir subdir)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5776 (let ((max (dired-subdir-max))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5777 start end found)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5778 (if (dired-goto-next-file)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5779 (progn
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5780 (skip-chars-forward "^\n\r")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5781 (setq start (point))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5782 (goto-char (setq end max))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5783 (forward-char -1)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5784 (skip-chars-backward "^\n\r")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5785 ;; This loop must find a file. At the very least, it will
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5786 ;; find the one found previously.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5787 (while (not found)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5788 (if (save-excursion (dired-move-to-filename nil (point)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5789 (setq found t)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5790 (setq end (point))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5791 (forward-char -1)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5792 (skip-chars-backward "^\n\r")))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5793 (if rev
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5794 (while (< start end)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5795 (goto-char (/ (+ start end) 2))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5796 (if (dired-file-name-lessp
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5797 (or (dired-get-filename 'no-dir t)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5798 (error
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5799 "Error in dired-find-file-place"))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5800 file)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5801 (setq end (progn
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5802 (skip-chars-backward "^\n\r")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5803 (point)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5804 (setq start (progn
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5805 (skip-chars-forward "^\n\r")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5806 (forward-char 1)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5807 (skip-chars-forward "^\n\r")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5808 (point)))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5809 (while (< start end)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5810 (goto-char (/ (+ start end) 2))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5811 (if (dired-file-name-lessp
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5812 file
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5813 (or (dired-get-filename 'no-dir t)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5814 (error
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5815 "Error in dired-find-file-place")))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5816 (setq end (progn
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5817 (skip-chars-backward "^\n\r")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5818 (point)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5819 (setq start (progn
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5820 (skip-chars-forward "^\n\r")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5821 (forward-char 1)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5822 (skip-chars-forward "^\n\r")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5823 (point))))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5824 (goto-char end))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5825 (goto-char max))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5826 t)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5827 ((eq sort 'date)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5828 (if (dired-goto-subdir subdir)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5829 (if rev
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5830 (goto-char (dired-subdir-max))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5831 (dired-goto-next-file)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5832 t)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5833 ;; Put in support for other sorting types.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5834 (t
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5835 (if (string-equal (dired-current-directory) subdir)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5836 (progn
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5837 ;; We are already where we should be, except when
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5838 ;; point is before the subdir line or its total line.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5839 (or (save-excursion (beginning-of-line) (dired-move-to-filename))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5840 (dired-goto-next-nontrivial-file)) ; in the header somewhere
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5841 t) ; return t, for found.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5842 (if (dired-goto-subdir subdir)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5843 (progn
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5844 (dired-goto-next-nontrivial-file)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5845 t)))))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5846
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5847 (defun dired-add-entry (filename &optional marker-char inplace)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5848 ;; Add a new entry for FILENAME, optionally marking it
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5849 ;; with MARKER-CHAR (a character, else dired-marker-char is used).
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5850 ;; Hidden subdirs are exposed if a file is added there.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5851 ;;
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5852 ;; This function now adds the new entry at the END of the previous line,
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5853 ;; not the beginning of the current line.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5854 ;; Logically, we now think of the `newline' associated
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5855 ;; with a fileline, as the one at the beginning of the line, not the end.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5856 ;; This makes it easier to keep track of omitted files.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5857 ;;
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5858 ;; Uses dired-save-excursion, so that it doesn't move the
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5859 ;; point around. Especially important when it runs asynch.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5860 ;;
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5861 ;; If there is already an entry, delete the existing one before adding a
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5862 ;; new one. In this case, doesn't remember its mark. Use
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5863 ;; dired-update-file-line for that.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5864 ;;
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5865 ;; If INPLACE eq 'relist, then the new entry is put in the
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5866 ;; same place as the old, if there was an old entry.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5867 ;; If INPLACE is t, then the file entry is put on the line
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5868 ;; currently containing the point. Otherwise, dired-find-file-place
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5869 ;; attempts to determine where to put the file.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5870
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5871 (setq filename (directory-file-name filename))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5872 (dired-save-excursion
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5873 (let ((oentry (save-excursion (dired-goto-file filename)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5874 (directory (file-name-directory filename))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5875 (file-nodir (file-name-nondirectory filename))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5876 buffer-read-only)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5877 (if oentry
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5878 ;; Remove old entry
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5879 (let ((opoint (point)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5880 (goto-char oentry)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5881 (delete-region (save-excursion
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5882 (skip-chars-backward "^\r\n")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5883 (dired-update-marker-counters (following-char) t)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5884 (1- (point)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5885 (progn
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5886 (skip-chars-forward "^\r\n")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5887 (point)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5888 ;; Move to right place to replace deleted line.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5889 (cond ((eq inplace 'relist) (forward-char 1))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5890 ((eq inplace t) (goto-char opoint)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5891 (dired-update-mode-line-modified)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5892 (if (or (eq inplace t)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5893 (and oentry (eq inplace 'relist))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5894 ;; Tries to move the point to the right place.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5895 ;; Returns t on success.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5896 (dired-find-file-place directory file-nodir))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5897 (let ((switches (dired-make-switches-string
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5898 (cons ?d dired-internal-switches)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5899 b-of-l)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5900 ;; Bind marker-char now, in case we are working asynch and
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5901 ;; dired-marker-char changes in the meantime.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5902 (if (and marker-char (not (integerp marker-char)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5903 (setq marker-char dired-marker-char))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5904 ;; since we insert at the end of a line,
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5905 ;; backup to the end of the previous line.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5906 (skip-chars-backward "^\n\r")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5907 (forward-char -1)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5908 (setq b-of-l (point))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5909 (if (and (featurep 'efs-dired) efs-dired-host-type)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5910 ;; insert asynch
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5911 ;; we call the efs version explicitly here,
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5912 ;; rather than let the handler-alist work for us
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5913 ;; because we want to pass extra args.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5914 ;; Is there a cleaner way to do this?
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5915 (efs-insert-directory filename ; don't expand `.' !
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5916 switches nil nil
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5917 t ; nowait
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5918 marker-char)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5919 (let ((insert-directory-program dired-ls-program))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5920 (insert-directory filename switches nil nil))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5921 (dired-after-add-entry b-of-l marker-char))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5922 (if dired-verify-modtimes
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5923 (dired-set-file-modtime directory dired-subdir-alist))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5924 t))))) ; return t on success, else nil.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5925
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5926 (defun dired-after-add-entry (start marker-char)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5927 ;; Does the cleanup of a dired entry after listing it.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5928 ;; START is the start of the new listing-line.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5929 ;; This is a separate function for the sake of efs.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5930 (save-excursion
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5931 (goto-char start)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5932 ;; we make sure that the new line is bracketted by new-lines
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5933 ;; so the user doesn't need to use voodoo in the
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5934 ;; after-readin-hook.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5935 (insert ?\n)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5936 (dired-add-entry-do-indentation marker-char)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5937 (let* ((beg (dired-manual-move-to-filename t))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5938 ;; error for strange output
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5939 (end (dired-manual-move-to-end-of-filename))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5940 (filename (buffer-substring beg end)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5941 ;; We want to have the non-directory part only.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5942 (delete-region beg end)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5943 ;; Any markers pointing to the beginning of the filename, will
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5944 ;; still point there after this insertion. Should keep
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5945 ;; save-excursion from losing.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5946 (setq beg (point))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5947 (insert (file-name-nondirectory filename))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5948 (dired-insert-set-properties beg (point))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5949 (dired-move-to-filename))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5950 ;; The subdir-alist is not affected so we can run it right now.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5951 (let ((omit (dired-current-subdir-omitted-p))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5952 (hide (dired-subdir-hidden-p (dired-current-directory))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5953 (if (or dired-after-readin-hook omit hide)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5954 (save-excursion
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5955 (save-restriction
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5956 ;; Use start so that we get the new-line at
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5957 ;; the beginning of the line in case we want
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5958 ;; to hide the file. Don't need to test (bobp)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5959 ;; here, since we never add a file at
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5960 ;; the beginning of the buffer.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5961 (narrow-to-region start
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5962 (save-excursion (forward-line 1) (point)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5963 (run-hooks 'dired-after-readin-hook)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5964 (if omit
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5965 (let ((dired-omit-silent (or dired-omit-silent 0)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5966 (dired-omit-region (point-min) (point-max)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5967 (dired-omit-regexp))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5968 (if hide
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5969 (subst-char-in-region (point-min) (1- (point-max))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5970 ?\n ?\r))))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5971 ;; clobber the extra newline at the end of the line
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5972 (end-of-line)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5973 (delete-char 1)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5974
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5975 ;; This is a separate function for the sake of nested dired format.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5976 (defun dired-add-entry-do-indentation (marker-char)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5977 ;; two spaces or a marker plus a space:
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5978 (insert (if marker-char
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5979 (let ((char (if (integerp marker-char)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5980 marker-char
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5981 dired-marker-char)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5982 (dired-update-marker-counters char)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5983 (dired-update-mode-line-modified)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5984 char)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5985 ?\040)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5986 ?\040))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5987
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5988 (defun dired-remove-file (file)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5989 (let ((alist dired-buffers)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5990 buff)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5991 (save-excursion
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5992 (while alist
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5993 (setq buff (cdr (car alist)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5994 (if (buffer-name buff)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5995 (progn
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5996 (set-buffer buff)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5997 (dired-remove-entry file))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5998 (setq dired-buffers (delq (car alist) dired-buffers)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
5999 (setq alist (cdr alist))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6000 (or dired-buffers (dired-remove-from-file-name-handler-alist))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6001
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6002 (defun dired-remove-entry (file)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6003 (let ((ddir (expand-file-name default-directory))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6004 (dirname (file-name-as-directory file)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6005 (if (dired-in-this-tree ddir dirname)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6006 (if (or (memq 'kill-dired-buffer dired-no-confirm)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6007 (y-or-n-p (format "Kill dired buffer %s for %s, too? "
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6008 (buffer-name) dired-directory)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6009 (kill-buffer (current-buffer)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6010 (if (dired-in-this-tree file ddir)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6011 (let ((alist dired-subdir-alist))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6012 (while alist
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6013 (if (dired-in-this-tree (car (car alist)) dirname)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6014 (save-excursion
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6015 (goto-char (dired-get-subdir-min (car alist)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6016 (dired-kill-subdir)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6017 (setq alist (cdr alist)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6018 (dired-save-excursion
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6019 (and (dired-goto-file file)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6020 (let (buffer-read-only)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6021 (delete-region
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6022 (progn (skip-chars-backward "^\n\r")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6023 (or (memq (following-char) '(\n \r ?\ ))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6024 (progn
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6025 (dired-update-marker-counters
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6026 (following-char) t)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6027 (dired-update-mode-line-modified)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6028 (1- (point)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6029 (progn (skip-chars-forward "^\n\r") (point)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6030 (if dired-verify-modtimes
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6031 (dired-set-file-modtime
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6032 (file-name-directory (directory-file-name file))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6033 dired-subdir-alist))))))))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6034
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6035 (defun dired-add-file (filename &optional marker-char)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6036 (dired-fun-in-all-buffers
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6037 (file-name-directory filename)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6038 (function dired-add-entry) filename marker-char))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6039
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6040 (defun dired-relist-file (file)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6041 (dired-uncache file nil)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6042 (dired-fun-in-all-buffers (file-name-directory file)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6043 (function dired-relist-entry) file))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6044
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6045 (defun dired-relist-entry (file)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6046 ;; Relist the line for FILE, or just add it if it did not exist.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6047 ;; FILE must be an absolute pathname.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6048 (let* ((file (directory-file-name file))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6049 (directory (file-name-directory file))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6050 (dd (expand-file-name default-directory)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6051 (if (assoc directory dired-subdir-alist)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6052 (if (or
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6053 ;; Not a wildcard
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6054 (equal dd dired-directory)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6055 ;; Not top-level
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6056 (not (string-equal directory dd))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6057 (and (string-equal directory
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6058 (if (consp dired-directory)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6059 (file-name-as-directory
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6060 (car dired-directory))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6061 (file-name-directory dired-directory)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6062 (dired-file-in-wildcard-p dired-directory file)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6063 (let ((marker (save-excursion
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6064 (and (dired-goto-file file)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6065 (dired-file-marker file)))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6066 ;; recompute omission
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6067 (if (eq marker dired-omit-marker-char)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6068 (setq marker nil))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6069 (dired-add-entry file marker 'relist))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6070 ;; At least tell dired that we considered updating the buffer.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6071 (if dired-verify-modtimes
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6072 (dired-set-file-modtime directory dired-subdir-alist))))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6073
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6074 (defun dired-file-in-wildcard-p (wildcard file)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6075 ;; Return t if a file is part of the listing for wildcard.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6076 ;; File should be the non-directory part only.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6077 ;; This version is slow, but meticulously correct. Is it worth it?
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6078 (if (consp wildcard)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6079 (let ((files (cdr wildcard))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6080 (dir (car wildcard))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6081 yep)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6082 (while (and files (not yep))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6083 (setq yep (string-equal file (expand-file-name (car files) dir))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6084 files (cdr files)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6085 yep)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6086 (let ((err-buff
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6087 (let ((default-major-mode 'fundamental-mode))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6088 (get-buffer-create " *dired-check-process output*")))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6089 (dir default-directory)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6090 (process-connection-type nil))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6091 (save-excursion
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6092 (set-buffer err-buff)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6093 (erase-buffer)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6094 (setq default-directory dir)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6095 (call-process shell-file-name nil t nil "-c"
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6096 (concat dired-ls-program " -d " wildcard " | "
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6097 "egrep '(^|/)" file "$'"))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6098 (/= (buffer-size) 0)))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6099
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6100 ;; The difference between dired-add-file and dired-relist-file is that
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6101 ;; the former creates the entry with a specific marker. The later preserves
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6102 ;; existing markers on a per buffer basis. This is not the same as
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6103 ;; giving dired-create-files a marker of t, which uses a marker in a specific
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6104 ;; buffer to determine the marker for file line creation in all buffers.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6105
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6106
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6107 ;;;; ----------------------------------------------------------------
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6108 ;;;; Applying Lisp functions to marked files.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6109 ;;;; ----------------------------------------------------------------
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6110
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6111 ;;; Running tags commands on marked files.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6112 ;;
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6113 ;; Written 8/30/93 by Roland McGrath <roland@gnu.ai.mit.edu>.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6114 ;; Requires tags.el as distributed with GNU Emacs 19.23, or later.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6115
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6116 (defun dired-do-tags-search (regexp)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6117 "Search through all marked files for a match for REGEXP.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6118 Stops when a match is found.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6119 To continue searching for next match, use command \\[tags-loop-continue]."
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6120 (interactive "sSearch marked files (regexp): ")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6121 (tags-search regexp '(dired-get-marked-files)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6122
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6123 (defun dired-do-tags-query-replace (from to &optional delimited)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6124 "Query-replace-regexp FROM with TO through all marked files.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6125 Third arg DELIMITED (prefix arg) means replace only word-delimited matches.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6126 If you exit (\\[keyboard-quit] or ESC), you can resume the query-replace
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6127 with the command \\[tags-loop-continue]."
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6128 (interactive
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6129 "sQuery replace in marked files (regexp): \nsQuery replace %s by: \nP")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6130 (tags-query-replace from to delimited '(dired-get-marked-files)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6131
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6132 ;;; byte compiling
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6133
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6134 (defun dired-byte-compile ()
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6135 ;; Return nil for success, offending file name else.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6136 (let* ((filename (dired-get-filename))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6137 buffer-read-only failure)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6138 (condition-case err
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6139 (save-excursion (byte-compile-file filename))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6140 (error
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6141 (setq failure err)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6142 ;; We should not need to update any file lines, as this will have
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6143 ;; already been done by after-write-region-hook.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6144 (and failure
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6145 (progn
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6146 (dired-log (buffer-name (current-buffer))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6147 "Byte compile error for %s:\n%s\n" filename failure)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6148 (dired-make-relative filename)))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6149
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6150 (defun dired-do-byte-compile (&optional arg)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6151 "Byte compile marked (or next ARG) Emacs lisp files."
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6152 (interactive "P")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6153 (dired-map-over-marks-check (function dired-byte-compile) arg
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6154 'byte-compile "byte-compile" t))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6155
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6156 ;;; loading
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6157
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6158 (defun dired-load ()
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6159 ;; Return nil for success, offending file name else.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6160 (let ((file (dired-get-filename)) failure)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6161 (condition-case err
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6162 (load file nil nil t)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6163 (error (setq failure err)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6164 (if (not failure)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6165 nil
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6166 (dired-log (buffer-name (current-buffer))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6167 "Load error for %s:\n%s\n" file failure)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6168 (dired-make-relative file))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6169
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6170 (defun dired-do-load (&optional arg)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6171 "Load the marked (or next ARG) Emacs lisp files."
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6172 (interactive "P")
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6173 (dired-map-over-marks-check (function dired-load) arg 'load "load" t))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6174
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6175
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6176 ;;;; ----------------------------------------------------------------
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6177 ;;;; File Name Handler Alist
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6178 ;;;; ----------------------------------------------------------------
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6179 ;;;
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6180 ;;; Make sure that I/O functions maintain dired buffers.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6181
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6182 (defun dired-remove-from-file-name-handler-alist ()
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6183 ;; Remove dired from the file-name-handler-alist
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6184 (setq file-name-handler-alist
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6185 (delq nil
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6186 (mapcar
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6187 (function
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6188 (lambda (x)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6189 (and (not (eq (cdr x) 'dired-handler-fn))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6190 x)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6191 file-name-handler-alist))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6192
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6193 (defun dired-check-file-name-handler-alist ()
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6194 ;; Verify that dired is installed as the first item in the alist
118
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 116
diff changeset
6195 (and dired-refresh-automatically
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 116
diff changeset
6196 (or (eq (cdr (car file-name-handler-alist)) 'dired-handler-fn)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 116
diff changeset
6197 (setq file-name-handler-alist
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 116
diff changeset
6198 (cons
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 116
diff changeset
6199 '("." . dired-handler-fn)
7d55a9ba150c Import from CVS: tag r20-1b11
cvs
parents: 116
diff changeset
6200 (dired-remove-from-file-name-handler-alist))))))
98
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6201
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6202 (defun dired-handler-fn (op &rest args)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6203 ;; Function to update dired buffers after I/O.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6204 (prog1
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6205 (let ((inhibit-file-name-handlers
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6206 (cons 'dired-handler-fn
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6207 (and (eq inhibit-file-name-operation op)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6208 inhibit-file-name-handlers)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6209 (inhibit-file-name-operation op))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6210 (apply op args))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6211 (let ((dired-omit-silent t)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6212 (hf (get op 'dired)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6213 (and hf (funcall hf args)))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6214
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6215 (defun dired-handler-fn-1 (args)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6216 (let ((to (expand-file-name (nth 1 args))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6217 (or (member to dired-unhandle-add-files)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6218 (dired-relist-file to))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6219
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6220 (defun dired-handler-fn-2 (args)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6221 (let ((from (expand-file-name (car args)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6222 (to (expand-file-name (nth 1 args))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6223 ;; Don't remove the original entry if making backups.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6224 ;; Otherwise we lose marks. I'm not completely happy with the
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6225 ;; logic here.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6226 (or (and
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6227 (eq (nth 2 args) t) ; backups always have OK-IF-OVERWRITE t
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6228 (string-equal (car (find-backup-file-name from)) to))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6229 (dired-remove-file from))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6230 (or (member to dired-unhandle-add-files)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6231 (dired-relist-file to))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6232
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6233 (defun dired-handler-fn-3 (args)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6234 (let ((to (expand-file-name (nth 2 args))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6235 (or (member to dired-unhandle-add-files)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6236 (dired-relist-file to))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6237
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6238 (defun dired-handler-fn-4 (args)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6239 (dired-remove-file (expand-file-name (car args))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6240
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6241 (defun dired-handler-fn-5 (args)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6242 (let ((to (expand-file-name (car args))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6243 (or (member to dired-unhandle-add-files)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6244 (dired-relist-file to))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6245
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6246 (defun dired-handler-fn-6 (args)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6247 (let ((to (expand-file-name (nth 1 args)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6248 (old (expand-file-name (car args))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6249 (or (member to dired-unhandle-add-files)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6250 (dired-relist-file to))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6251 (dired-relist-file old)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6252
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6253 (put 'copy-file 'dired 'dired-handler-fn-1)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6254 (put 'dired-make-relative-symlink 'dired 'dired-handler-fn-1)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6255 (put 'make-symbolic-link 'dired 'dired-handler-fn-1)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6256 (put 'add-name-to-file 'dired 'dired-handler-fn-6)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6257 (put 'rename-file 'dired 'dired-handler-fn-2)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6258 (put 'write-region 'dired 'dired-handler-fn-3)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6259 (put 'delete-file 'dired 'dired-handler-fn-4)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6260 (put 'delete-directory 'dired 'dired-handler-fn-4)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6261 (put 'dired-recursive-delete-directory 'dired 'dired-handler-fn-4)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6262 (put 'make-directory-internal 'dired 'dired-handler-fn-5)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6263 (put 'set-file-modes 'dired 'dired-handler-fn-5)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6264
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6265 ;;;; ------------------------------------------------------------
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6266 ;;;; Autoload land.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6267 ;;;; ------------------------------------------------------------
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6268
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6269 ;;; Reading mail (dired-xy)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6270
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6271 (autoload 'dired-read-mail "dired-xy"
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6272 "Reads the current file as a mail folder." t)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6273 (autoload 'dired-vm "dired-xy" "Run VM on this file." t)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6274 (autoload 'dired-rmail "dired-xy" "Run RMAIL on this file." t)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6275
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6276 ;;; Virtual dired (dired-vir)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6277
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6278 (autoload 'dired-virtual "dired-vir"
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6279 "Put this buffer into virtual dired mode." t)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6280
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6281 ;;; Grep (dired-grep)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6282
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6283 (autoload 'dired-do-grep "dired-grep" "Grep marked files for a pattern." t)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6284
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6285 ;;; Doing diffs (dired-diff)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6286
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6287 (autoload 'dired-diff "dired-diff"
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6288 "Compare file at point with FILE using `diff'." t)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6289 (autoload 'dired-backup-diff "dired-diff"
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6290 "Diff this file with its backup file or vice versa." t)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6291 (autoload 'dired-emerge "dired-diff"
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6292 "Merge file at point with FILE using `emerge'." t)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6293 (autoload 'dired-emerge-with-ancestor "dired-diff"
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6294 "Merge file at point with FILE, using a common ANCESTOR file." t)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6295 (autoload 'dired-ediff "dired-diff" "Ediff file at point with FILE." t)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6296 (autoload 'dired-epatch "dired-diff" "Patch file at point using `epatch'." t)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6297
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6298 ;;; Shell commands (dired-shell)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6299
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6300 (autoload 'dired-do-print "dired-shell" "Print the marked (next ARG) files." t)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6301 (autoload 'dired-run-shell-command "dired-shell" nil)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6302 (autoload 'dired-do-shell-command "dired-shell"
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6303 "Run a shell command on the marked (or next ARG) files." t)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6304 (autoload 'dired-do-background-shell-command "dired-shell"
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6305 "Run a background shell command on marked (or next ARG) files." t)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6306
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6307 ;;; Commands using regular expressions (dired-rgxp)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6308
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6309 (autoload 'dired-mark-files-regexp "dired-rgxp"
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6310 "Mark all files whose names match REGEXP." t)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6311 (autoload 'dired-flag-files-regexp "dired-rgxp"
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6312 "Flag for deletion all files whose names match REGEXP." t)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6313 (autoload 'dired-mark-extension "dired-rgxp"
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6314 "Mark all files whose names have a given extension." t)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6315 (autoload 'dired-flag-extension "dired-rgxp"
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6316 "Flag for deletion all files whose names have a given extension." t)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6317 (autoload 'dired-cleanup "dired-rgxp"
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6318 "Flag for deletion dispensable files files created by PROGRAM." t)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6319 (autoload 'dired-do-rename-regexp "dired-rgxp"
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6320 "Rename marked files whose names match a given regexp." t)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6321 (autoload 'dired-do-copy-regexp "dired-rgxp"
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6322 "Copy marked files whose names match a given regexp." t)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6323 (autoload 'dired-do-hardlink-regexp "dired-rgxp"
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6324 "Hardlink all marked files whose names match a regexp." t)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6325 (autoload 'dired-do-symlink "dired-rgxp"
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6326 "Make a symbolic link to all files whose names match a regexp." t)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6327 (autoload
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6328 'dired-do-relsymlink-regexp "dired-rgxp"
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6329 "Make a relative symbolic link to all files whose names match a regexp." t)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6330 (autoload 'dired-upcase "dired-rgxp"
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6331 "Rename all marked (or next ARG) files to upper case." t)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6332 (autoload 'dired-downcase "dired-rgxp"
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6333 "Rename all marked (or next ARG) files to lower case." t)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6334
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6335 ;;; Marking files from other buffers (dired-mob)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6336
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6337 (autoload 'dired-mark-files-from-other-dired-buffer "dired-mob"
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6338 "Mark files which are marked in another dired buffer." t)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6339 (autoload 'dired-mark-files-compilation-buffer "dired-mob"
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6340 "Mark the files mentioned in the compilation buffer." t)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6341
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6342 ;;; uuencoding (dired-uu)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6343
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6344 (autoload 'dired-do-uucode "dired-uu" "Uuencode or uudecode marked files." t)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6345
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6346 ;;; Compressing (dired-cmpr)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6347
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6348 (autoload 'dired-do-compress "dired-cmpr"
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6349 "Compress or uncompress marked files." t)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6350 (autoload 'dired-compress-subdir-files "dired-cmpr"
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6351 "Compress uncompressed files in the current subdirectory." t)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6352
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6353
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6354 ;;; Marking files according to sexps
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6355
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6356 (autoload 'dired-mark-sexp "dired-sex"
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6357 "Mark files according to an sexpression." t)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6358
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6359 ;;; Help!
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6360
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6361 (autoload 'dired-summary "dired-help"
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6362 "Display summary of basic dired commands in the minibuffer." t)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6363 (autoload 'dired-describe-mode "dired-help"
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6364 "Detailed description of dired mode.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6365 With a prefix, runs the info documentation browser for dired." t)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6366 (autoload 'dired-apropos "dired-help"
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6367 "Do command apropos help for dired commands.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6368 With prefix does apropos help for dired variables." t)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6369 (autoload 'dired-report-bug "dired-help" "Report a bug for dired." t)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6370
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6371 ;;;; --------------------------------------------------------------
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6372 ;;;; Multi-flavour Emacs support
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6373 ;;;; --------------------------------------------------------------
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6374
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6375 (let ((lucid-p (string-match "Lucid" emacs-version))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6376 ver)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6377 (or (string-match "^\\([0-9]+\\)\\." emacs-version)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6378 (error "Weird emacs version %s" emacs-version))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6379 (setq ver (string-to-int (substring emacs-version (match-beginning 1)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6380 (match-end 1))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6381
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6382 ;; Reading with history.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6383 (if (>= ver 19)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6384
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6385 (defun dired-read-with-history (prompt initial history)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6386 (read-from-minibuffer prompt initial nil nil history))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6387
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6388 (defun dired-read-with-history (prompt initial history)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6389 (let ((minibuffer-history-symbol history)) ; for gmhist
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6390 (read-string prompt initial))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6391
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6392 ;; Completing read with history.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6393 (if (>= ver 19)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6394
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6395 (fset 'dired-completing-read 'completing-read)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6396
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6397 (defun dired-completing-read (prompt table &optional predicate
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6398 require-match initial-input history)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6399 (let ((minibuffer-history-symbol history)) ; for gmhist
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6400 (completing-read prompt table predicate require-match
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6401 initial-input))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6402
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6403 ;; Abbreviating file names.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6404 (if lucid-p
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6405 (fset 'dired-abbreviate-file-name
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6406 ;; Lemacs has this extra hack-homedir arg
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6407 (function
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6408 (lambda (fn)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6409 (abbreviate-file-name fn t))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6410 (fset 'dired-abbreviate-file-name 'abbreviate-file-name))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6411
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6412 ;; Deleting directories
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6413 ;; Check for pre 19.8 versions of lucid emacs.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6414 (if lucid-p
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6415 (or (fboundp 'delete-directory)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6416 (fset 'delete-directory 'remove-directory)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6417
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6418 ;; Minibuffers
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6419 (if (= ver 18)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6420
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6421 (defun dired-get-active-minibuffer-window ()
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6422 (and (> (minibuffer-depth) 0)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6423 (minibuffer-window)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6424
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6425 (defun dired-get-active-minibuffer-window ()
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6426 (let ((frames (frame-list))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6427 win found)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6428 (while frames
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6429 (if (and (setq win (minibuffer-window (car frames)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6430 (minibuffer-window-active-p win))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6431 (setq found win
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6432 frames nil)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6433 (setq frames (cdr frames))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6434 found)))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6435
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6436 ;; Text properties and menus.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6437
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6438 (cond
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6439 (lucid-p
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6440 (require 'dired-xemacs))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6441 ((>= ver 19)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6442 (require 'dired-fsf))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6443 (t
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6444 ;; text property stuff doesn't work in V18
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6445 (fset 'dired-insert-set-properties 'ignore)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6446 (fset 'dired-remove-text-properties 'ignore)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6447 (fset 'dired-set-text-properties 'ignore)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6448 (fset 'dired-move-to-filename 'dired-manual-move-to-filename)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6449 (fset 'dired-move-to-end-of-filename
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6450 'dired-manual-move-to-end-of-filename))))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6451
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6452 ;;; MULE
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6453
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6454 (if (or (boundp 'MULE) (featurep 'mule)) (load "dired-mule"))
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6455
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6456
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6457 ;; Run load hook for user customization.
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6458 (run-hooks 'dired-load-hook)
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6459
0d2f883870bc Import from CVS: tag r20-1b1
cvs
parents:
diff changeset
6460 ;;; end of dired.el