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

Import from CVS: tag r19-15b104
author cvs
date Mon, 13 Aug 2007 08:54:51 +0200
parents 7e54bd776075
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
22
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
1 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
2 ;;
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
3 ;; File: dired-rgxp.el
42
8b8b7f3559a2 Import from CVS: tag r19-15b104
cvs
parents: 40
diff changeset
4 ;; Dired Version: #Revision: 7.9 $
22
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
5 ;; RCS:
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
6 ;; Description: Commands for running commands on files whose names
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
7 ;; match a regular expression.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
8 ;;
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
9 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
10
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
11 ;;; Requirements and provisions
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
12 (provide 'dired-rgxp)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
13 (require 'dired)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
14
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
15 ;;; Variables
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
16
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
17 (defvar dired-flagging-regexp nil)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
18 ;; Last regexp used to flag files.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
19
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
20 ;;; Utility functions
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
21
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
22 (defun dired-do-create-files-regexp
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
23 (file-creator operation arg regexp newname &optional whole-path marker-char)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
24 ;; Create a new file for each marked file using regexps.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
25 ;; FILE-CREATOR and OPERATION as in dired-create-files.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
26 ;; ARG as in dired-get-marked-files.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
27 ;; Matches each marked file against REGEXP and constructs the new
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
28 ;; filename from NEWNAME (like in function replace-match).
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
29 ;; Optional arg WHOLE-PATH means match/replace the whole pathname
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
30 ;; instead of only the non-directory part of the file.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
31 ;; Optional arg MARKER-CHAR as in dired-create-files.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
32 (let* ((fn-list (dired-get-marked-files nil arg))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
33 (name-constructor
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
34 (if whole-path
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
35 (list 'lambda '(from)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
36 (list 'let
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
37 (list (list 'to
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
38 (list 'dired-string-replace-match
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
39 regexp 'from newname)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
40 (list 'or 'to
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
41 (list 'dired-log
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
42 '(buffer-name (current-buffer))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
43 "%s: %s did not match regexp %s\n"
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
44 operation 'from regexp))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
45 'to))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
46 (list 'lambda '(from)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
47 (list 'let
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
48 (list (list 'to
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
49 (list 'dired-string-replace-match regexp
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
50 '(file-name-nondirectory from)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
51 newname)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
52 (list 'or 'to
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
53 (list 'dired-log '(buffer-name (current-buffer))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
54 "%s: %s did not match regexp %s\n"
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
55 operation '(file-name-nondirectory from)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
56 regexp))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
57 '(and to
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
58 (expand-file-name
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
59 to (file-name-directory from)))))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
60 (operation-prompt (concat operation " `%s' to `%s'?"))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
61 (rename-regexp-help-form (format "\
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
62 Type SPC or `y' to %s one match, DEL or `n' to skip to next,
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
63 `!' to %s all remaining matches with no more questions."
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
64 (downcase operation)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
65 (downcase operation)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
66 (query (list 'lambda '(from to)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
67 (list 'let
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
68 (list (list 'help-form
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
69 rename-regexp-help-form))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
70 (list 'dired-query
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
71 '(quote dired-file-creator-query)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
72 operation-prompt
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
73 '(dired-abbreviate-file-name from)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
74 '(dired-abbreviate-file-name to))))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
75 (dired-create-files
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
76 file-creator operation fn-list name-constructor marker-char query)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
77
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
78 (defun dired-mark-read-regexp (operation)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
79 ;; Prompt user about performing OPERATION.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
80 ;; Read and return list of: regexp newname arg whole-path.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
81 (let* ((whole-path
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
82 (equal 0 (prefix-numeric-value current-prefix-arg)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
83 (arg
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
84 (if whole-path nil current-prefix-arg))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
85 (regexp
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
86 (dired-read-with-history
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
87 (concat (if whole-path "Path " "") operation " from (regexp): ")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
88 dired-flagging-regexp 'dired-regexp-history))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
89 (newname
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
90 (read-string
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
91 (concat (if whole-path "Path " "") operation " " regexp " to: ")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
92 (and (not whole-path) (dired-dwim-target-directory)))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
93 (list regexp newname arg whole-path)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
94
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
95 ;;; Marking file names matching a regexp.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
96
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
97 (defun dired-mark-files-regexp (regexp &optional marker-char omission-files-p)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
98 "\\<dired-mode-map>Mark all files matching REGEXP for use in later commands.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
99
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
100 A prefix argument \\[universal-argument] means to unmark them instead.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
101
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
102 A prefix argument 0 means to mark the files that would me omitted by \\[dired-omit-toggle].
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
103 A prefix argument 1 means to unmark the files that would be omitted by \\[dired-omit-toggle].
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
104
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
105 REGEXP is an Emacs regexp, not a shell wildcard. Thus, use \"\\.o$\" for
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
106 object files--just `.o' will mark more than you might think. The files \".\"
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
107 and \"..\" are never marked.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
108 "
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
109 (interactive
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
110 (let ((unmark (and (not (eq current-prefix-arg 0)) current-prefix-arg))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
111 (om-files-p (memq current-prefix-arg '(0 1)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
112 regexp)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
113 (if om-files-p
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
114 (setq regexp (dired-omit-regexp))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
115 (setq regexp (dired-read-with-history
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
116 (concat (if unmark "Unmark" "Mark")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
117 " files (regexp): ") nil
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
118 'dired-regexp-history)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
119 (list regexp (if unmark ?\ ) om-files-p)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
120 (let ((dired-marker-char (or marker-char dired-marker-char)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
121 (dired-mark-if
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
122 (and (not (looking-at dired-re-dot))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
123 (not (eolp)) ; empty line
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
124 (let ((fn (dired-get-filename nil t)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
125 (and fn (string-match regexp (file-name-nondirectory fn)))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
126 (if omission-files-p
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
127 "omission candidate file"
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
128 "matching file"))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
129
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
130 (defun dired-flag-files-regexp (regexp)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
131 "In dired, flag all files containing the specified REGEXP for deletion.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
132 The match is against the non-directory part of the filename. Use `^'
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
133 and `$' to anchor matches. Exclude subdirs by hiding them.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
134 `.' and `..' are never flagged."
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
135 (interactive (list (dired-read-with-history
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
136 "Flag for deletion (regexp): " nil
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
137 'dired-regexp-history)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
138 (dired-mark-files-regexp regexp dired-del-marker))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
139
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
140 (defun dired-mark-extension (extension &optional marker-char)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
141 "Mark all files with a certain extension for use in later commands.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
142 A `.' is not prepended to the string entered."
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
143 ;; EXTENSION may also be a list of extensions instead of a single one.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
144 ;; Optional MARKER-CHAR is marker to use.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
145 (interactive "sMark files with extension: \nP")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
146 (or (listp extension)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
147 (setq extension (list extension)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
148 (dired-mark-files-regexp
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
149 (concat ".";; don't match names with nothing but an extension
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
150 "\\("
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
151 (mapconcat 'regexp-quote extension "\\|")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
152 "\\)$")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
153 marker-char))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
154
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
155 (defun dired-flag-extension (extension)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
156 "In dired, flag all files with a certain extension for deletion.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
157 A `.' is not prepended to the string entered."
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
158 (interactive "sFlag files with extension: ")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
159 (dired-mark-extension extension dired-del-marker))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
160
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
161 (defun dired-cleanup (program)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
162 "Flag for deletion dispensable files created by PROGRAM.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
163 See variable `dired-cleanup-alist'."
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
164 (interactive
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
165 (list
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
166 (let ((dired-cleanup-history (append dired-cleanup-history
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
167 (mapcar 'car dired-cleanup-alist))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
168 (dired-completing-read
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
169 "Cleanup files for: " dired-cleanup-alist nil t nil
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
170 'dired-cleanup-history))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
171 (dired-flag-extension (cdr (assoc program dired-cleanup-alist))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
172
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
173 ;;; Commands on marked files whose names also match a regexp.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
174
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
175 (defun dired-do-rename-regexp (regexp newname &optional arg whole-path)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
176 "Rename marked files containing REGEXP to NEWNAME.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
177 As each match is found, the user must type a character saying
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
178 what to do with it. For directions, type \\[help-command] at that time.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
179 NEWNAME may contain \\=\\<n> or \\& as in `query-replace-regexp'.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
180 REGEXP defaults to the last regexp used.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
181 With a zero prefix arg, renaming by regexp affects the complete
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
182 pathname - usually only the non-directory part of file names is used
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
183 and changed."
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
184 (interactive (dired-mark-read-regexp "Rename"))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
185 (dired-do-create-files-regexp
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
186 (function dired-rename-file)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
187 "Rename" arg regexp newname whole-path dired-keep-marker-rename))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
188
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
189 (defun dired-do-copy-regexp (regexp newname &optional arg whole-path)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
190 "Copy all marked files containing REGEXP to NEWNAME.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
191 See function `dired-rename-regexp' for more info."
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
192 (interactive (dired-mark-read-regexp "Copy"))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
193 (dired-do-create-files-regexp
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
194 (function dired-copy-file)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
195 (if dired-copy-preserve-time "Copy [-p]" "Copy")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
196 arg regexp newname whole-path dired-keep-marker-copy))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
197
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
198 (defun dired-do-hardlink-regexp (regexp newname &optional arg whole-path)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
199 "Hardlink all marked files containing REGEXP to NEWNAME.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
200 See function `dired-rename-regexp' for more info."
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
201 (interactive (dired-mark-read-regexp "HardLink"))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
202 (dired-do-create-files-regexp
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
203 (function add-name-to-file)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
204 "HardLink" arg regexp newname whole-path dired-keep-marker-hardlink))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
205
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
206 (defun dired-do-symlink-regexp (regexp newname &optional arg whole-path)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
207 "Symlink all marked files containing REGEXP to NEWNAME.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
208 See function `dired-rename-regexp' for more info."
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
209 (interactive (dired-mark-read-regexp "SymLink"))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
210 (dired-do-create-files-regexp
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
211 (function make-symbolic-link)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
212 "SymLink" arg regexp newname whole-path dired-keep-marker-symlink))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
213
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
214 (defun dired-do-relsymlink-regexp (regexp newname &optional whole-path)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
215 "RelSymlink all marked files containing REGEXP to NEWNAME.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
216 See functions `dired-rename-regexp' and `dired-do-relsymlink'
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
217 for more info."
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
218 (interactive (dired-mark-read-regexp "RelSymLink"))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
219 (dired-do-create-files-regexp
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
220 (function dired-make-relative-symlink)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
221 "RelSymLink" nil regexp newname whole-path dired-keep-marker-symlink))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
222
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
223 ;;;; Modifying the case of file names.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
224
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
225 (defun dired-create-files-non-directory
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
226 (file-creator basename-constructor operation arg)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
227 ;; Perform FILE-CREATOR on the non-directory part of marked files
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
228 ;; using function BASENAME-CONSTRUCTOR, with query for each file.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
229 ;; OPERATION like in dired-create-files, ARG like in dired-get-marked-files.
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
230 (let (rename-non-directory-query)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
231 (dired-create-files
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
232 file-creator
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
233 operation
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
234 (dired-get-marked-files nil arg)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
235 (function
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
236 (lambda (from)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
237 (let ((to (concat (file-name-directory from)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
238 (funcall basename-constructor
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
239 (file-name-nondirectory from)))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
240 (and (let ((help-form (format "\
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
241 Type SPC or `y' to %s one file, DEL or `n' to skip to next,
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
242 `!' to %s all remaining matches with no more questions."
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
243 (downcase operation)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
244 (downcase operation))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
245 (dired-query 'rename-non-directory-query
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
246 (concat operation " `%s' to `%s'")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
247 (dired-make-relative from)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
248 (dired-make-relative to)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
249 to))))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
250 dired-keep-marker-rename)))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
251
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
252 (defun dired-rename-non-directory (basename-constructor operation arg)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
253 (dired-create-files-non-directory
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
254 (function dired-rename-file)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
255 basename-constructor operation arg))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
256
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
257 (defun dired-upcase (&optional arg)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
258 "Rename all marked (or next ARG) files to upper case."
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
259 (interactive "P")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
260 (dired-rename-non-directory (function upcase) "Rename upcase" arg))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
261
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
262 (defun dired-downcase (&optional arg)
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
263 "Rename all marked (or next ARG) files to lower case."
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
264 (interactive "P")
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
265 (dired-rename-non-directory (function downcase) "Rename downcase" arg))
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
266
8fc7fe29b841 Import from CVS: tag r19-15b94
cvs
parents:
diff changeset
267 ;;; end of dired-rgxp.el