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

Import from CVS: tag r19-14
author cvs
date Mon, 13 Aug 2007 08:45:50 +0200
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1 ;;;; dired-num.el - Renaming with numbers in Tree Dired.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3 (defconst dired-num-version (substring "!Revision: 1.2 !" 11 -2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4 "Id: dired-num.el,v 1.2 1991/10/15 13:24:10 sk RelBeta ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6 ;; Copyright (C) 1991 by Sebastian Kremer <sk@thp.uni-koeln.de>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
7
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
8 ;; This program is free software; you can redistribute it and/or modify
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
9 ;; it under the terms of the GNU General Public License as published by
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
10 ;; the Free Software Foundation; either version 1, or (at your option)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
11 ;; any later version.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
12 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
13 ;; This program is distributed in the hope that it will be useful,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
14 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
15 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
16 ;; GNU General Public License for more details.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
17 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
18 ;; You should have received a copy of the GNU General Public License
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
19 ;; along with this program; if not, write to the Free Software
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
20 ;; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
21
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
22 ;; LISPDIR ENTRY for the Elisp Archive ===============================
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
23 ;; LCD Archive Entry:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
24 ;; dired-num|Sebastian Kremer|sk@thp.uni-koeln.de
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
25 ;; |Renaming with numbers in Tree Dired.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26 ;; |Date: 1991/10/15 13:24:10 |Revision: 1.2 |
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28 ;; INSTALLATION ======================================================
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30 ;; Put this file into your load-path and the following in your ~/.emacs:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32 ;; (autoload 'dired-do-rename-numeric "dired-num")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33 ;; (autoload 'dired-do-rename-list "dired-num")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35 ;; Do
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37 ;; (define-key dired-mode-map "%#" 'dired-do-rename-numeric)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38 ;; (define-key dired-mode-map "%(" 'dired-do-rename-list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40 ;; inside your dired-load-hook.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42 (require 'dired);; we need its macros when being compiled
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44 (defun dired-number-of-marked-files (&optional arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45 ;; Return the number of marked files in a dired buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46 ;; Optional ARG as in dired-mark-map.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47 (length
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49 ;; this returns a list of ``results'' (i.e. nil's):
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50 (dired-mark-map nil arg))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52 (defun dired-do-create-files-numeric (file-creator operation arg format start
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53 &optional arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54 ;; Create a new file for each marked file using numbers.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55 ;; FILE-CREATOR and OPERATION as in dired-create-files.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56 ;; ARG as in dired-mark-get-files.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57 ;; FORMAT is a format string for use with an integer, assuming
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58 ;; values starting from START, incremented for each marked file.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59 (let ((i (1- start)));; signals an error if START is not a number
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60 (dired-create-files-non-directory
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61 file-creator
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62 (function (lambda (x)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63 (format format (setq i (1+ i)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64 operation arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67 (defun dired-do-rename-numeric (format start &optional arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68 "Rename all marked (or next ARG) files using numbers.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69 You are prompted for a format string, e.g \"part_%d_of_8\", and a starting
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70 number, e.g. 1. If there are 8 marked files, this example will rename them to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72 part_1_of_8
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73 part_2_of_8
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74 ...
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75 part_8_of_8"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76 (interactive
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77 (list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78 (read-string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79 (format "Rename numeric [%d files] (format string using %%d): "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80 (dired-number-of-marked-files current-prefix-arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81 (read-minibuffer "Numbers start at: " "1")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82 current-prefix-arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83 (dired-do-create-files-numeric
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84 (function dired-rename-file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85 "Rename-numeric" arg format start))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87 ;; Copy etc. would be similar to implement.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90 (defun dired-do-create-files-list (file-creator operation arg format list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91 &optional arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92 ;; Create a new file for each marked file by subsituting elements
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93 ;; from LIST in the format string FORMAT.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94 ;; FILE-CREATOR and OPERATION as in dired-create-files.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95 ;; ARG as in dired-mark-get-files.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96 (let ((rest list))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97 (dired-create-files-non-directory
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98 file-creator
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99 (function (lambda (x)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100 (format format (prog1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101 (car rest)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102 (setq rest (cdr rest))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103 operation arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106 (defun dired-do-rename-list (format list &optional arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107 "Rename all marked (or next ARG) files using elements from LIST.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108 You are prompted for a format string, e.g \"x_%s\", and the list,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109 e.g. '(foo bar zod). This example will rename the marked files to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111 x_foo
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112 x_bar
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113 x_zod
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115 It is an error if LIST has not as many elements as there are files."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116 (interactive "sRename list (format using %%s): \nxList: \nP")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117 (or (= (dired-number-of-marked-files arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118 (length list))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119 (error "Must have as many elements as there are files to rename"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120 (dired-do-create-files-list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121 (function dired-rename-file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122 "Rename-list" arg format list))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123