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