55098
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1 ;;; wdired.el --- Rename files editing their names in dired buffers
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
3 ;; Copyright (C) 2001, 2004 Free Software Foundation, Inc.
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
4
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
5 ;; Filename: wdired.el
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
6 ;; Author: Juan León Lahoz García <juan-leon.lahoz@tecsidel.es>
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
7 ;; Version: 1.91
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
8 ;; Keywords: dired, environment, files, renaming
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
9
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
10 ;; This file is part of GNU Emacs.
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
11
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
12 ;; GNU Emacs is free software; you can redistribute it and/or
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
13 ;; modify it under the terms of the GNU General Public License as
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
14 ;; published by the Free Software Foundation; either version 2, or (at
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
15 ;; your option) any later version.
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
16
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
17 ;; This program is distributed in the hope that it will be useful, but
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
18 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
20 ;; General Public License for more details.
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
21
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
22 ;; You should have received a copy of the GNU General Public License
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
23 ;; along with GNU Emacs; see the file COPYING. If not, write to the
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
24 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
25 ;; Boston, MA 02111-1307, USA.
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
26
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
27 ;;; Commentary:
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
28
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
29 ;; wdired.el (the "w" is for writable) provides an alternative way of
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
30 ;; renaming files.
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
31 ;;
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
32 ;; Have you ever wished to use C-x r t (string-rectangle), M-%
|
55109
043dd9a4d1b4
(wdired-mode-map): Move init into declaration. Fix `return' binding.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
33 ;; (query-replace), M-c (capitalize-word), etc. to change the name of
|
55098
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
34 ;; the files in a "dired" buffer? Now you can do this. All the power
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
35 ;; of emacs commands are available to renaming files!
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
36 ;;
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
37 ;; This package provides a function that makes the filenames of a a
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
38 ;; dired buffer editable, by changing the buffer mode (which inhibits
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
39 ;; all of the commands of dired mode). Here you can edit the names of
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
40 ;; one or more files and directories, and when you press C-c C-c, the
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
41 ;; renaming takes effect and you are back to dired mode.
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
42 ;;
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
43 ;; Another things you can do with wdired:
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
44 ;;
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
45 ;; - To move files to another directory (by typing their path,
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
46 ;; absolute or relative, as a part of the new filename).
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
47 ;;
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
48 ;; - To change the target of symbolic links.
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
49 ;;
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
50 ;; - To change the permission bits of the filenames (in systems with a
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
51 ;; working unix-alike `dired-chmod-program'). See and customize the
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
52 ;; variable `wdired-allow-to-change-permissions'. To change a single
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
53 ;; char (toggling between its two more usual values) you can press
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
54 ;; the space bar over it or left-click the mouse. To set any char to
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
55 ;; an specific value (this includes the SUID, SGID and STI bits) you
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
56 ;; can use the key labeled as the letter you want. Please note that
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
57 ;; permissions of the links cannot be changed in that way, because
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
58 ;; the change would affect to their targets, and this would not be
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
59 ;; WYSIWYG :-).
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
60 ;;
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
61 ;; - To mark files for deletion, by deleting their whole filename.
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
62 ;;
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
63 ;; I do not have a URL to hang wdired, but you can use the one below
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
64 ;; to find the latest version:
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
65 ;;
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
66 ;; http://groups.google.com/groups?as_ugroup=gnu.emacs.sources&as_q=wdired
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
67
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
68 ;;; Installation:
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
69
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
70 ;; Add this file (byte-compiling it is recommended) to your load-path.
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
71 ;; Then add one of these set of lines (or similar ones) to your config:
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
72 ;;
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
73 ;; This is the easy way:
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
74 ;;
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
75 ;; (require 'wdired)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
76 ;; (define-key dired-mode-map "r" 'wdired-change-to-wdired-mode)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
77 ;;
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
78 ;; This is recommended way for faster emacs startup time and lower
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
79 ;; memory consumption, but remind to add these lines before dired.el
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
80 ;; gets loaded (i.e., near the beginning of your .emacs file):
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
81 ;;
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
82 ;; (autoload 'wdired-change-to-wdired-mode "wdired")
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
83 ;; (add-hook 'dired-load-hook
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
84 ;; '(lambda ()
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
85 ;; (define-key dired-mode-map "r" 'wdired-change-to-wdired-mode)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
86 ;; (define-key dired-mode-map
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
87 ;; [menu-bar immediate wdired-change-to-wdired-mode]
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
88 ;; '("Edit File Names" . wdired-change-to-wdired-mode))))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
89 ;;
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
90 ;;
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
91 ;; Type "M-x customize-group RET wdired" if you want make changes to
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
92 ;; the default behavior.
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
93
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
94 ;;; Usage:
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
95
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
96 ;; Then, you can start editing the names of the files by typing "r"
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
97 ;; (or whatever key you choose, or M-x wdired-change-to-wdired-mode).
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
98 ;; Use C-c C-c when finished or C-c C-k to abort. You can use also the
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
99 ;; menu options: in dired mode, "Edit File Names" under "Immediate".
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
100 ;; While editing the names, a new submenu "WDired" is available at top
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
101 ;; level. You can customize the behavior of this package from this
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
102 ;; menu.
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
103
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
104 ;;; Change Log:
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
105
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
106 ;; From 1.9 to 1.91
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
107 ;;
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
108 ;; - Fixed a bug (introduced in 1.9) so now files can be marked for
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
109 ;; deletion again, by deleting their whole filename.
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
110
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
111 ;; From 1.8 to 1.9
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
112 ;;
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
113 ;; - Another alternative way of editing permissions allowed, see
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
114 ;; `wdired-allow-to-change-permissions' for details.
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
115 ;;
|
55109
043dd9a4d1b4
(wdired-mode-map): Move init into declaration. Fix `return' binding.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
116 ;; - Now wdired doesn't rely on regexp so much. As a consequence of
|
55098
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
117 ;; this, you can add newlines to filenames and symlinks targets
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
118 ;; (although this is not very usual, IMHO). Please note that dired
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
119 ;; (at least in Emacs 21.1 and previous) does not work very well
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
120 ;; with filenames with newlines in them, so RET is deactivated in
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
121 ;; wdired mode. But you can activate it if you want.
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
122 ;;
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
123 ;; - Now `upcase-word' `capitalize-word' and `downcase-word' are not
|
55109
043dd9a4d1b4
(wdired-mode-map): Move init into declaration. Fix `return' binding.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
124 ;; advised to work better with wdired mode, but the keys bound to
|
043dd9a4d1b4
(wdired-mode-map): Move init into declaration. Fix `return' binding.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
125 ;; them use wdired versions of those commands.
|
55098
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
126 ;;
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
127 ;; - Now "undo" actions are not inherited from wdired mode when
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
128 ;; changing to dired mode.
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
129 ;;
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
130 ;; - Code and documentation cleanups.
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
131 ;;
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
132 ;; - Fixed a bug that was making wdired to fail on users with
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
133 ;; `dired-backup-overwrite' set to t.
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
134 ;;
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
135 ;; - C-c C-[ now abort changes.
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
136
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
137 ;; From 1.7 to 1.8
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
138 ;;
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
139 ;; - Now permission (access-control) bits of the files can be changed.
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
140 ;; Please see the commentary section and the custom variable
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
141 ;; `wdired-allow-to-change-permissions' for details.
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
142 ;;
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
143 ;; - Added another possible value for the variable
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
144 ;; `wdired-always-move-to-filename-beginning', useful to change
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
145 ;; permission bits of several files without the cursor jumping to
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
146 ;; filenames when changing lines.
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
147
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
148 ;; From 0.1 to 1.7
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
149
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
150 ;; - I've moved the list of changes to another file, because it was
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
151 ;; huge. Ask me for it or search older versions in google.
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
152
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
153 ;;; TODO:
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
154
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
155 ;; - Make it to work in XEmacs. Any volunteer?
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
156
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
157 ;;; Code:
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
158
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
159 (eval-when-compile
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
160 (require 'advice)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
161 (defvar dired-backup-overwrite) ; Only in emacs 20.x this is a custom var
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
162 (set (make-local-variable 'byte-compile-dynamic) t))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
163
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
164 (eval-and-compile
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
165 (require 'dired)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
166 (autoload 'dired-do-create-files-regexp "dired-aux")
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
167 (autoload 'dired-call-process "dired-aux"))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
168
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
169 (defgroup wdired nil
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
170 "Mode to rename files by editing their names in dired buffers."
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
171 :group 'dired)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
172
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
173 (defcustom wdired-use-interactive-rename nil
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
174 "*If t, confirmation is required before actually rename the files.
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
175 Confirmation is required also for overwriting files. If nil, no
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
176 confirmation is required for change the file names, and the variable
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
177 `wdired-is-ok-overwrite' is used to see if it is ok to overwrite files
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
178 without asking."
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
179 :type 'boolean
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
180 :group 'wdired)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
181
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
182 (defcustom wdired-is-ok-overwrite nil
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
183 "*If non-nil the renames can overwrite files without asking.
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
184 This variable is used only if `wdired-use-interactive-rename' is nil."
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
185 :type 'boolean
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
186 :group 'wdired)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
187
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
188 (defcustom wdired-always-move-to-filename-beginning nil
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
189 "*If t the \"up\" and \"down\" movement is done as in dired mode.
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
190 That is, always move the point to the beginning of the filename at line.
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
191
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
192 If `sometimes, only move to the beginning of filename if the point is
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
193 before it, and `track-eol' is honored. This behavior is very handy
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
194 when editing several filenames.
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
195
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
196 If nil, \"up\" and \"down\" movement is done as in any other buffer."
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
197 :type '(choice (const :tag "As in any other mode" nil)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
198 (const :tag "Smart cursor placement" sometimes)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
199 (other :tag "As in dired mode" t))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
200 :group 'wdired)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
201
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
202 (defcustom wdired-advise-functions t
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
203 "*If t some editing commands are advised when wdired is loaded.
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
204 The advice only has effect in wdired mode. These commands are
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
205 `query-replace' `query-replace-regexp' `replace-string', and the
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
206 advice makes them to ignore read-only regions, so no attempts to
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
207 modify these regions are done by them, and so they don't end
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
208 prematurely.
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
209
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
210 Setting this to nil does not unadvise the functions, if they are
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
211 already advised, but new Emacs will not advise them."
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
212 :type 'boolean
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
213 :group 'wdired)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
214
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
215 (defcustom wdired-allow-to-redirect-links t
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
216 "*If non-nil, the target of the symbolic links can be changed also.
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
217 In systems without symbolic links support, this variable has no effect
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
218 at all."
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
219 :type 'boolean
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
220 :group 'wdired)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
221
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
222 (defcustom wdired-allow-to-change-permissions nil
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
223 "*If non-nil, the permissions bits of the files can be changed also.
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
224
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
225 If t, to change a single bit, put the cursor over it and press the
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
226 space bar, or left click over it. You can also hit the letter you want
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
227 to set: if this value is allowed, the character in the buffer will be
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
228 changed. Anyway, the point is advanced one position, so, for example,
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
229 you can keep the \"x\" key pressed to give execution permissions to
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
230 everybody to that file.
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
231
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
232 If `advanced, the bits are freely editable. You can use
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
233 `string-rectangle', `query-replace', etc. You can put any value (even
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
234 newlines), but if you want your changes to be useful, you better put a
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
235 intelligible value.
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
236
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
237 Anyway, the real change of the permissions is done with the external
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
238 program `dired-chmod-program', which must exist."
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
239 :type '(choice (const :tag "Not allowed" nil)
|
55109
043dd9a4d1b4
(wdired-mode-map): Move init into declaration. Fix `return' binding.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
240 (const :tag "Toggle/set bits" t)
|
55098
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
241 (other :tag "Bits freely editable" advanced))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
242 :group 'wdired)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
243
|
55109
043dd9a4d1b4
(wdired-mode-map): Move init into declaration. Fix `return' binding.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
244 (defvar wdired-mode-map
|
043dd9a4d1b4
(wdired-mode-map): Move init into declaration. Fix `return' binding.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
245 (let ((map (make-sparse-keymap)))
|
043dd9a4d1b4
(wdired-mode-map): Move init into declaration. Fix `return' binding.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
246 (define-key map "\C-x\C-s" 'wdired-finish-edit)
|
043dd9a4d1b4
(wdired-mode-map): Move init into declaration. Fix `return' binding.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
247 (define-key map "\C-c\C-c" 'wdired-finish-edit)
|
043dd9a4d1b4
(wdired-mode-map): Move init into declaration. Fix `return' binding.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
248 (define-key map "\C-c\C-k" 'wdired-abort-changes)
|
043dd9a4d1b4
(wdired-mode-map): Move init into declaration. Fix `return' binding.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
249 (define-key map "\C-c\C-[" 'wdired-abort-changes)
|
043dd9a4d1b4
(wdired-mode-map): Move init into declaration. Fix `return' binding.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
250 (define-key map "\C-m" 'wdired-newline)
|
043dd9a4d1b4
(wdired-mode-map): Move init into declaration. Fix `return' binding.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
251 (define-key map "\C-j" 'wdired-newline)
|
043dd9a4d1b4
(wdired-mode-map): Move init into declaration. Fix `return' binding.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
252 (define-key map "\C-o" 'wdired-newline)
|
043dd9a4d1b4
(wdired-mode-map): Move init into declaration. Fix `return' binding.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
253 (define-key map [up] 'wdired-previous-line)
|
043dd9a4d1b4
(wdired-mode-map): Move init into declaration. Fix `return' binding.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
254 (define-key map "\C-p" 'wdired-previous-line)
|
043dd9a4d1b4
(wdired-mode-map): Move init into declaration. Fix `return' binding.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
255 (define-key map [down] 'wdired-next-line)
|
043dd9a4d1b4
(wdired-mode-map): Move init into declaration. Fix `return' binding.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
256 (define-key map "\C-n" 'wdired-next-line)
|
55098
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
257
|
55109
043dd9a4d1b4
(wdired-mode-map): Move init into declaration. Fix `return' binding.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
258 (define-key map [menu-bar wdired]
|
043dd9a4d1b4
(wdired-mode-map): Move init into declaration. Fix `return' binding.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
259 (cons "WDired" (make-sparse-keymap "WDired")))
|
043dd9a4d1b4
(wdired-mode-map): Move init into declaration. Fix `return' binding.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
260 (define-key map [menu-bar wdired wdired-customize]
|
043dd9a4d1b4
(wdired-mode-map): Move init into declaration. Fix `return' binding.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
261 '("Options" . wdired-customize))
|
043dd9a4d1b4
(wdired-mode-map): Move init into declaration. Fix `return' binding.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
262 (define-key map [menu-bar wdired dashes]
|
55098
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
263 '("--"))
|
55109
043dd9a4d1b4
(wdired-mode-map): Move init into declaration. Fix `return' binding.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
264 (define-key map [menu-bar wdired wdired-abort-changes]
|
043dd9a4d1b4
(wdired-mode-map): Move init into declaration. Fix `return' binding.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
265 '("Abort Changes" . wdired-abort-changes))
|
043dd9a4d1b4
(wdired-mode-map): Move init into declaration. Fix `return' binding.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
266 (define-key map [menu-bar wdired wdired-finish-edit]
|
043dd9a4d1b4
(wdired-mode-map): Move init into declaration. Fix `return' binding.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
267 '("Commit Changes" . wdired-finish-edit))
|
043dd9a4d1b4
(wdired-mode-map): Move init into declaration. Fix `return' binding.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
268 ;; FIXME: Use the new remap trick.
|
043dd9a4d1b4
(wdired-mode-map): Move init into declaration. Fix `return' binding.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
269 (substitute-key-definition 'upcase-word 'wdired-upcase-word
|
043dd9a4d1b4
(wdired-mode-map): Move init into declaration. Fix `return' binding.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
270 map global-map)
|
043dd9a4d1b4
(wdired-mode-map): Move init into declaration. Fix `return' binding.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
271 (substitute-key-definition 'capitalize-word 'wdired-capitalize-word
|
043dd9a4d1b4
(wdired-mode-map): Move init into declaration. Fix `return' binding.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
272 map global-map)
|
043dd9a4d1b4
(wdired-mode-map): Move init into declaration. Fix `return' binding.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
273 (substitute-key-definition 'downcase-word 'wdired-downcase-word
|
043dd9a4d1b4
(wdired-mode-map): Move init into declaration. Fix `return' binding.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
274 map global-map)
|
043dd9a4d1b4
(wdired-mode-map): Move init into declaration. Fix `return' binding.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
275 map))
|
55098
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
276
|
55109
043dd9a4d1b4
(wdired-mode-map): Move init into declaration. Fix `return' binding.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
277 (defvar wdired-mode-hook nil
|
043dd9a4d1b4
(wdired-mode-map): Move init into declaration. Fix `return' binding.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
278 "Hook run when changing to wdired mode.")
|
55098
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
279
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
280 ;; Local variables (put here to avoid compilation gripes)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
281 (defvar wdired-col-perm) ;; Column where the permission bits start
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
282 (defvar wdired-old-content)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
283
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
284
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
285 (defun wdired-mode ()
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
286 "\\<wdired-mode-map>File Names Editing mode.
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
287
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
288 Press \\[wdired-finish-edit] to make the changes to take effect and
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
289 exit. To abort the edit, use \\[wdired-abort-changes].
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
290
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
291 In this mode you can edit the names of the files, the target of the
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
292 links and the permission bits of the files. You can `customize-group'
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
293 wdired.
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
294
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
295 Editing things out of the filenames, or adding or deleting lines is
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
296 not allowed, because the rest of the buffer is read-only."
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
297 (interactive)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
298 (error "This mode can be enabled only by `wdired-change-to-wdired-mode'"))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
299 (put 'wdired-mode 'mode-class 'special)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
300
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
301
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
302 ;;;###autoload
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
303 (defun wdired-change-to-wdired-mode ()
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
304 "Put a dired buffer in a mode in which filenames are editable.
|
55109
043dd9a4d1b4
(wdired-mode-map): Move init into declaration. Fix `return' binding.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
305 In this mode the names of the files can be changed, and after
|
55098
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
306 typing C-c C-c the files and directories in disk are renamed.
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
307
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
308 See `wdired-mode'."
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
309 (interactive)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
310 (set (make-local-variable 'wdired-old-content)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
311 (buffer-substring (point-min) (point-max)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
312 (use-local-map wdired-mode-map)
|
55109
043dd9a4d1b4
(wdired-mode-map): Move init into declaration. Fix `return' binding.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
313 (force-mode-line-update)
|
55098
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
314 (setq buffer-read-only nil)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
315 (dired-unadvertise default-directory)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
316 (add-hook 'kill-buffer-hook 'wdired-check-kill-buffer nil t)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
317 (setq major-mode 'wdired-mode)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
318 (setq mode-name "Edit filenames")
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
319 (setq revert-buffer-function 'wdired-revert)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
320 ;; I temp disable undo for performance: since I'm going to clear the
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
321 ;; undo list, it can save more than a 9% of time with big
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
322 ;; directories because setting properties modify the undo-list.
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
323 (buffer-disable-undo)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
324 (wdired-preprocess-files)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
325 (if wdired-allow-to-change-permissions
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
326 (wdired-preprocess-perms))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
327 (if (and wdired-allow-to-redirect-links (fboundp 'make-symbolic-link))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
328 (wdired-preprocess-symlinks))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
329 (buffer-enable-undo) ; Performance hack. See above.
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
330 (set-buffer-modified-p nil)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
331 (setq buffer-undo-list nil)
|
55371
|
332 (run-hooks 'wdired-mode-hook)
|
|
333 (message (substitute-command-keys "Press \\[wdired-finish-edit] when finished")))
|
55098
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
334
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
335
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
336 ;; Protect the buffer so only the filenames can be changed, and put
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
337 ;; properties so filenames (old and new) can be easily found.
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
338 (defun wdired-preprocess-files ()
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
339 (put-text-property 1 2 'front-sticky t)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
340 (save-excursion
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
341 (goto-char (point-min))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
342 (let ((b-protection (point))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
343 filename)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
344 (while (not (eobp))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
345 (setq filename (dired-get-filename nil t))
|
55109
043dd9a4d1b4
(wdired-mode-map): Move init into declaration. Fix `return' binding.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
346 (when (and filename
|
043dd9a4d1b4
(wdired-mode-map): Move init into declaration. Fix `return' binding.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
347 (not (member (file-name-nondirectory filename) '("." ".."))))
|
043dd9a4d1b4
(wdired-mode-map): Move init into declaration. Fix `return' binding.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
348 (dired-move-to-filename)
|
043dd9a4d1b4
(wdired-mode-map): Move init into declaration. Fix `return' binding.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
349 (put-text-property (- (point) 2) (1- (point)) 'old-name filename)
|
043dd9a4d1b4
(wdired-mode-map): Move init into declaration. Fix `return' binding.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
350 (put-text-property b-protection (1- (point)) 'read-only t)
|
043dd9a4d1b4
(wdired-mode-map): Move init into declaration. Fix `return' binding.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
351 (setq b-protection (dired-move-to-end-of-filename t)))
|
043dd9a4d1b4
(wdired-mode-map): Move init into declaration. Fix `return' binding.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
352 (put-text-property (point) (1+ (point)) 'end-name t)
|
55098
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
353 (forward-line))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
354 (put-text-property b-protection (point-max) 'read-only t))))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
355
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
356 ;; This code is a copy of some dired-get-filename lines.
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
357 (defsubst wdired-normalize-filename (file)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
358 (setq file
|
55109
043dd9a4d1b4
(wdired-mode-map): Move init into declaration. Fix `return' binding.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
359 ;; FIXME: shouldn't we check for a `b' argument or somesuch before
|
043dd9a4d1b4
(wdired-mode-map): Move init into declaration. Fix `return' binding.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
360 ;; doing such unquoting? --Stef
|
55098
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
361 (read (concat
|
55109
043dd9a4d1b4
(wdired-mode-map): Move init into declaration. Fix `return' binding.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
362 "\"" (replace-regexp-in-string
|
043dd9a4d1b4
(wdired-mode-map): Move init into declaration. Fix `return' binding.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
363 "\\([^\\]\\|\\`\\)\"" "\\1\\\\\"" file)
|
55098
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
364 "\"")))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
365 (and file buffer-file-coding-system
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
366 (not file-name-coding-system)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
367 (not default-file-name-coding-system)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
368 (setq file (encode-coding-string file buffer-file-coding-system)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
369 file)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
370
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
371 (defun wdired-get-filename (&optional no-dir old)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
372 "Return the filename at line.
|
55109
043dd9a4d1b4
(wdired-mode-map): Move init into declaration. Fix `return' binding.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
373 Similar to `dired-get-filename' but it doesn't rely on regexps. It
|
043dd9a4d1b4
(wdired-mode-map): Move init into declaration. Fix `return' binding.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
374 relies on wdired buffer's properties. Optional arg NO-DIR with value
|
55098
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
375 non-nil means don't include directory. Optional arg OLD with value
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
376 non-nil means return old filename."
|
55109
043dd9a4d1b4
(wdired-mode-map): Move init into declaration. Fix `return' binding.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
377 ;; FIXME: Use dired-get-filename's new properties.
|
55098
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
378 (let (beg end file)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
379 (save-excursion
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
380 (setq end (progn (end-of-line) (point)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
381 (beginning-of-line)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
382 (setq beg (next-single-property-change (point) 'old-name nil end))
|
55109
043dd9a4d1b4
(wdired-mode-map): Move init into declaration. Fix `return' binding.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
383 (unless (eq beg end)
|
043dd9a4d1b4
(wdired-mode-map): Move init into declaration. Fix `return' binding.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
384 (if old
|
043dd9a4d1b4
(wdired-mode-map): Move init into declaration. Fix `return' binding.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
385 (setq file (get-text-property beg 'old-name))
|
043dd9a4d1b4
(wdired-mode-map): Move init into declaration. Fix `return' binding.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
386 (setq end (next-single-property-change (1+ beg) 'end-name))
|
043dd9a4d1b4
(wdired-mode-map): Move init into declaration. Fix `return' binding.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
387 (setq file (buffer-substring-no-properties (+ 2 beg) end)))
|
043dd9a4d1b4
(wdired-mode-map): Move init into declaration. Fix `return' binding.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
388 (and file (setq file (wdired-normalize-filename file))))
|
55098
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
389 (if (or no-dir old)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
390 file
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
391 (and file (> (length file) 0)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
392 (concat (dired-current-directory) file))))))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
393
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
394
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
395 (defun wdired-change-to-dired-mode ()
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
396 "Change the mode back to dired."
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
397 (let ((inhibit-read-only t))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
398 (remove-text-properties (point-min) (point-max)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
399 '(read-only nil local-map nil)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
400 (put-text-property 1 2 'front-sticky nil)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
401 (use-local-map dired-mode-map)
|
55109
043dd9a4d1b4
(wdired-mode-map): Move init into declaration. Fix `return' binding.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
402 (force-mode-line-update)
|
55098
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
403 (setq buffer-read-only t)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
404 (setq major-mode 'dired-mode)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
405 (setq mode-name "Dired")
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
406 (dired-advertise)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
407 (remove-hook 'kill-buffer-hook 'wdired-check-kill-buffer t)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
408 (setq revert-buffer-function 'dired-revert))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
409
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
410
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
411 (defun wdired-abort-changes ()
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
412 "Abort changes and return to dired mode."
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
413 (interactive)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
414 (let ((inhibit-read-only t))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
415 (erase-buffer)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
416 (insert wdired-old-content))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
417 (wdired-change-to-dired-mode)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
418 (set-buffer-modified-p nil)
|
55371
|
419 (setq buffer-undo-list nil)
|
|
420 (message "Changes aborted"))
|
55098
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
421
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
422 (defun wdired-finish-edit ()
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
423 "Actually rename files based on your editing in the Dired buffer."
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
424 (interactive)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
425 (wdired-change-to-dired-mode)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
426 (let ((overwrite (or wdired-is-ok-overwrite 1))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
427 (changes nil)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
428 (files-deleted nil)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
429 (errors 0)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
430 file-ori file-new tmp-value)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
431 (save-excursion
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
432 (if (and wdired-allow-to-redirect-links
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
433 (fboundp 'make-symbolic-link))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
434 (progn
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
435 (setq tmp-value (wdired-do-symlink-changes))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
436 (setq errors (cdr tmp-value))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
437 (setq changes (car tmp-value))))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
438 (if (and wdired-allow-to-change-permissions
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
439 (boundp 'wdired-col-perm)) ; could have been changed
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
440 (progn
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
441 (setq tmp-value (wdired-do-perm-changes))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
442 (setq errors (+ errors (cdr tmp-value)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
443 (setq changes (or changes (car tmp-value)))))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
444 (goto-char (point-max))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
445 (while (not (bobp))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
446 (setq file-ori (wdired-get-filename nil t))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
447 (if file-ori
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
448 (setq file-new (wdired-get-filename)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
449 (if (and file-ori (not (equal file-new file-ori)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
450 (progn
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
451 (setq changes t)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
452 (if (not file-new) ;empty filename!
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
453 (setq files-deleted (cons file-ori files-deleted))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
454 (progn
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
455 (setq file-new (substitute-in-file-name file-new))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
456 (if wdired-use-interactive-rename
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
457 (wdired-search-and-rename file-ori file-new)
|
56545
c3fa830eb56c
(wdired-finish-edit): Require dired-aux before locally binding dired-backup-overwrite.
Lars Hansen <larsh@soem.dk>
diff
changeset
|
458 ;; If dired-rename-file autoloads dired-aux while
|
c3fa830eb56c
(wdired-finish-edit): Require dired-aux before locally binding dired-backup-overwrite.
Lars Hansen <larsh@soem.dk>
diff
changeset
|
459 ;; dired-backup-overwrite is locally bound,
|
c3fa830eb56c
(wdired-finish-edit): Require dired-aux before locally binding dired-backup-overwrite.
Lars Hansen <larsh@soem.dk>
diff
changeset
|
460 ;; dired-backup-overwrite won't be initialized.
|
c3fa830eb56c
(wdired-finish-edit): Require dired-aux before locally binding dired-backup-overwrite.
Lars Hansen <larsh@soem.dk>
diff
changeset
|
461 ;; So we must ensure dired-aux is loaded.
|
c3fa830eb56c
(wdired-finish-edit): Require dired-aux before locally binding dired-backup-overwrite.
Lars Hansen <larsh@soem.dk>
diff
changeset
|
462 (require 'dired-aux)
|
55098
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
463 (condition-case err
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
464 (let ((dired-backup-overwrite nil))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
465 (dired-rename-file file-ori file-new
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
466 overwrite))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
467 (error
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
468 (setq errors (1+ errors))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
469 (dired-log (concat "Rename `" file-ori "' to `"
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
470 file-new "' failed:\n%s\n")
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
471 err))))))))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
472 (forward-line -1)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
473 (if changes
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
474 (revert-buffer) ;The "revert" is necessary to re-sort the buffer
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
475 (let ((buffer-read-only nil))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
476 (remove-text-properties (point-min) (point-max)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
477 '(old-name nil end-name nil old-link nil
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
478 end-link nil end-perm nil
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
479 old-perm nil perm-changed nil))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
480 (message "(No changes to be performed)")))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
481 (if files-deleted
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
482 (wdired-flag-for-deletion files-deleted))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
483 (if (> errors 0)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
484 (dired-log-summary (format "%d rename actions failed" errors) nil)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
485 (set-buffer-modified-p nil)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
486 (setq buffer-undo-list nil))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
487
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
488 ;; Renames a file, searching it in a modified dired buffer, in order
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
489 ;; to be able to use `dired-do-create-files-regexp' and get its
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
490 ;; "benefits"
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
491 (defun wdired-search-and-rename (filename-ori filename-new)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
492 (save-excursion
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
493 (goto-char (point-max))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
494 (forward-line -1)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
495 (let ((exit-while nil)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
496 curr-filename)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
497 (while (not exit-while)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
498 (setq curr-filename (wdired-get-filename))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
499 (if (and curr-filename
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
500 (equal (substitute-in-file-name curr-filename) filename-new))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
501 (progn
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
502 (setq exit-while t)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
503 (let ((inhibit-read-only t))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
504 (dired-move-to-filename)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
505 (search-forward (wdired-get-filename t) nil t)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
506 (replace-match (file-name-nondirectory filename-ori) t t))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
507 (dired-do-create-files-regexp
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
508 (function dired-rename-file)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
509 "Move" 1 ".*" filename-new nil t))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
510 (progn
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
511 (forward-line -1)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
512 (beginning-of-line)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
513 (setq exit-while (= 1 (point)))))))))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
514
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
515 ;; marks a list of files for deletion
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
516 (defun wdired-flag-for-deletion (filenames-ori)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
517 (save-excursion
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
518 (goto-char (point-min))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
519 (while (not (eobp))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
520 (if (member (dired-get-filename nil t) filenames-ori)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
521 (dired-flag-file-deletion 1)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
522 (forward-line)))))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
523
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
524 (defun wdired-customize ()
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
525 "Customize wdired options."
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
526 (interactive)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
527 (customize-apropos "wdired" 'groups))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
528
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
529 (defun wdired-revert (&optional arg noconfirm)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
530 "Discard changes in the buffer and update the changes in the disk."
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
531 (wdired-change-to-dired-mode)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
532 (revert-buffer)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
533 (wdired-change-to-wdired-mode))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
534
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
535 (defun wdired-check-kill-buffer ()
|
55109
043dd9a4d1b4
(wdired-mode-map): Move init into declaration. Fix `return' binding.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
536 ;; FIXME: Can't we use the normal mechanism for that? --Stef
|
55098
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
537 (if (and
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
538 (buffer-modified-p)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
539 (not (y-or-n-p "Buffer changed. Discard changes and kill buffer? ")))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
540 (error nil)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
541
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
542 (defun wdired-next-line (arg)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
543 "Move down lines then position at filename or the current column.
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
544 See `wdired-always-move-to-filename-beginning'. Optional prefix ARG
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
545 says how many lines to move; default is one line."
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
546 (interactive "p")
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
547 (next-line arg)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
548 (if (or (eq wdired-always-move-to-filename-beginning t)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
549 (and wdired-always-move-to-filename-beginning
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
550 (< (current-column)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
551 (save-excursion (dired-move-to-filename)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
552 (current-column)))))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
553 (dired-move-to-filename)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
554
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
555 (defun wdired-previous-line (arg)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
556 "Move up lines then position at filename or the current column.
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
557 See `wdired-always-move-to-filename-beginning'. Optional prefix ARG
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
558 says how many lines to move; default is one line."
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
559 (interactive "p")
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
560 (previous-line arg)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
561 (if (or (eq wdired-always-move-to-filename-beginning t)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
562 (and wdired-always-move-to-filename-beginning
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
563 (< (current-column)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
564 (save-excursion (dired-move-to-filename)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
565 (current-column)))))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
566 (dired-move-to-filename)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
567
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
568 ;; dired doesn't works well with newlines, so ...
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
569 (defun wdired-newline ()
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
570 "Do nothing."
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
571 (interactive))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
572
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
573 ;; Put the needed properties to allow the user to change links' targets
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
574 (defun wdired-preprocess-symlinks ()
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
575 (let ((inhibit-read-only t))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
576 (save-excursion
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
577 (goto-char (point-min))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
578 (while (not (eobp))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
579 (if (looking-at dired-re-sym)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
580 (progn
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
581 (re-search-forward " -> \\(.*\\)$")
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
582 (put-text-property (- (match-beginning 1) 2)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
583 (1- (match-beginning 1)) 'old-link
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
584 (match-string-no-properties 1))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
585 (put-text-property (match-end 1) (1+ (match-end 1)) 'end-link t)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
586 (put-text-property (1- (match-beginning 1))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
587 (match-end 1) 'read-only nil)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
588 (forward-line)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
589 (beginning-of-line)))))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
590
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
591
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
592 (defun wdired-get-previous-link (&optional old move)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
593 "Return the next symlink target.
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
594 If OLD, return the old target. If MOVE, move point before it."
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
595 (let (beg end target)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
596 (setq beg (previous-single-property-change (point) 'old-link nil))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
597 (if beg
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
598 (progn
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
599 (if old
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
600 (setq target (get-text-property (1- beg) 'old-link))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
601 (setq end (next-single-property-change beg 'end-link))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
602 (setq target (buffer-substring-no-properties (1+ beg) end)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
603 (if move (goto-char (1- beg)))))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
604 (and target (wdired-normalize-filename target))))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
605
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
606
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
607
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
608 ;; Perform the changes in the target of the changed links.
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
609 (defun wdired-do-symlink-changes()
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
610 (let ((changes nil)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
611 (errors 0)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
612 link-to-ori link-to-new link-from)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
613 (goto-char (point-max))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
614 (while (setq link-to-new (wdired-get-previous-link))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
615 (setq link-to-ori (wdired-get-previous-link t t))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
616 (setq link-from (wdired-get-filename nil t))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
617 (if (not (equal link-to-new link-to-ori))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
618 (progn
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
619 (setq changes t)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
620 (if (equal link-to-new "") ;empty filename!
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
621 (setq link-to-new "/dev/null"))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
622 (condition-case err
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
623 (progn
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
624 (delete-file link-from)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
625 (make-symbolic-link
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
626 (substitute-in-file-name link-to-new) link-from))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
627 (error
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
628 (setq errors (1+ errors))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
629 (dired-log (concat "Link `" link-from "' to `"
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
630 link-to-new "' failed:\n%s\n")
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
631 err))))))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
632 (cons changes errors)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
633
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
634 ;; Perform a "case command" skipping read-only words.
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
635 (defun wdired-xcase-word (command arg)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
636 (if (< arg 0)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
637 (funcall command arg)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
638 (progn
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
639 (while (> arg 0)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
640 (condition-case err
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
641 (progn
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
642 (funcall command 1)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
643 (setq arg (1- arg)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
644 (error
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
645 (if (not (forward-word 1))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
646 (setq arg 0))))))))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
647
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
648 (defun wdired-downcase-word (arg)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
649 "Wdired version of `downcase-word'.
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
650 Like original function but it skips read-only words."
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
651 (interactive "p")
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
652 (wdired-xcase-word 'downcase-word arg))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
653
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
654 (defun wdired-upcase-word (arg)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
655 "Wdired version of `upcase-word'.
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
656 Like original function but it skips read-only words."
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
657 (interactive "p")
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
658 (wdired-xcase-word 'upcase-word arg))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
659
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
660 (defun wdired-capitalize-word (arg)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
661 "Wdired version of `capitalize-word'.
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
662 Like original function but it skips read-only words."
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
663 (interactive "p")
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
664 (wdired-xcase-word 'capitalize-word arg))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
665
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
666 ;; The following code is related to advice some interactive functions
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
667 ;; to make some editing commands in wdired mode not to fail trying to
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
668 ;; change read-only text. Notice that some advises advice and unadvise
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
669 ;; them-self to another functions: search-forward and
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
670 ;; re-search-forward. This is to keep these functions advised only
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
671 ;; when is necessary. Since they are built-in commands used heavily in
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
672 ;; lots of places, to have it permanently advised would cause some
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
673 ;; performance loss.
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
674
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
675
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
676 (defun wdired-add-skip-in-replace (command)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
677 "Advice COMMAND to skip matches while they have read-only properties.
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
678 This is useful to avoid \"read-only\" errors in search and replace
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
679 commands. This advice only has effect in wdired mode."
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
680 (eval
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
681 `(defadvice ,command (around wdired-discard-read-only activate)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
682 ,(format "Make %s to work better with wdired,\n%s." command
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
683 "skipping read-only matches when invoked without argument")
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
684 ad-do-it
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
685 (if (eq major-mode 'wdired-mode)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
686 (while (and ad-return-value
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
687 (text-property-any
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
688 (max 1 (1- (match-beginning 0))) (match-end 0)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
689 'read-only t))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
690 ad-do-it))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
691 ad-return-value)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
692
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
693
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
694 (defun wdired-add-replace-advice (command)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
695 "Advice COMMAND to skip matches while they have read-only properties.
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
696 This is useful to avoid \"read-only\" errors in search and replace
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
697 commands. This advice only has effect in wdired mode."
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
698 (eval
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
699 `(defadvice ,command (around wdired-grok-read-only activate)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
700 ,(format "Make %s to work better with wdired,\n%s." command
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
701 "skipping read-only matches when invoked without argument")
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
702 (if (eq major-mode 'wdired-mode)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
703 (progn
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
704 (wdired-add-skip-in-replace 'search-forward)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
705 (wdired-add-skip-in-replace 're-search-forward)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
706 (unwind-protect
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
707 ad-do-it
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
708 (progn
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
709 (ad-remove-advice 'search-forward
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
710 'around 'wdired-discard-read-only)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
711 (ad-remove-advice 're-search-forward
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
712 'around 'wdired-discard-read-only)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
713 (ad-update 'search-forward)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
714 (ad-update 're-search-forward))))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
715 ad-do-it)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
716 ad-return-value)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
717
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
718
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
719 (if wdired-advise-functions
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
720 (progn
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
721 (mapcar 'wdired-add-replace-advice
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
722 '(query-replace query-replace-regexp replace-string))))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
723
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
724
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
725 ;; The following code deals with changing the access bits (or
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
726 ;; permissions) of the files.
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
727
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
728 (defvar wdired-perm-mode-map nil)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
729 (unless wdired-perm-mode-map
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
730 (setq wdired-perm-mode-map (copy-keymap wdired-mode-map))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
731 (define-key wdired-perm-mode-map " " 'wdired-toggle-bit)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
732 (define-key wdired-perm-mode-map "r" 'wdired-set-bit)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
733 (define-key wdired-perm-mode-map "w" 'wdired-set-bit)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
734 (define-key wdired-perm-mode-map "x" 'wdired-set-bit)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
735 (define-key wdired-perm-mode-map "-" 'wdired-set-bit)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
736 (define-key wdired-perm-mode-map "S" 'wdired-set-bit)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
737 (define-key wdired-perm-mode-map "s" 'wdired-set-bit)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
738 (define-key wdired-perm-mode-map "T" 'wdired-set-bit)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
739 (define-key wdired-perm-mode-map "t" 'wdired-set-bit)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
740 (define-key wdired-perm-mode-map "s" 'wdired-set-bit)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
741 (define-key wdired-perm-mode-map "l" 'wdired-set-bit)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
742 (define-key wdired-perm-mode-map [down-mouse-1] 'wdired-mouse-toggle-bit))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
743
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
744 ;; Put a local-map to the permission bits of the files, and store the
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
745 ;; original name and permissions as a property
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
746 (defun wdired-preprocess-perms()
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
747 (let ((inhibit-read-only t)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
748 filename)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
749 (set (make-local-variable 'wdired-col-perm) nil)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
750 (save-excursion
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
751 (goto-char (point-min))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
752 (while (not (eobp))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
753 (if (and (not (looking-at dired-re-sym))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
754 (setq filename (wdired-get-filename)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
755 (progn
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
756 (re-search-forward dired-re-perms)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
757 (or wdired-col-perm
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
758 (setq wdired-col-perm (- (current-column) 9)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
759 (if (eq wdired-allow-to-change-permissions 'advanced)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
760 (put-text-property (match-beginning 0) (match-end 0)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
761 'read-only nil)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
762 (put-text-property (1+ (match-beginning 0)) (match-end 0)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
763 'local-map wdired-perm-mode-map))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
764 (put-text-property (match-end 0) (1+ (match-end 0)) 'end-perm t)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
765 (put-text-property (match-beginning 0) (1+ (match-beginning 0))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
766 'old-perm (match-string-no-properties 0))))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
767 (forward-line)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
768 (beginning-of-line)))))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
769
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
770 (defun wdired-perm-allowed-in-pos (char pos)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
771 (cond
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
772 ((= char ?-) t)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
773 ((= char ?r) (= (% pos 3) 0))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
774 ((= char ?w) (= (% pos 3) 1))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
775 ((= char ?x) (= (% pos 3) 2))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
776 ((memq char '(?s ?S)) (memq pos '(2 5)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
777 ((memq char '(?t ?T)) (= pos 8))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
778 ((= char ?l) (= pos 5))))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
779
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
780 (defun wdired-set-bit ()
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
781 "Set a permission bit character."
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
782 (interactive)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
783 (if (wdired-perm-allowed-in-pos last-command-char
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
784 (- (current-column) wdired-col-perm))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
785 (let ((new-bit (char-to-string last-command-char))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
786 (inhibit-read-only t)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
787 (pos-prop (- (point) (- (current-column) wdired-col-perm))))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
788 (put-text-property 0 1 'local-map wdired-perm-mode-map new-bit)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
789 (put-text-property 0 1 'read-only t new-bit)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
790 (insert new-bit)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
791 (delete-char 1)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
792 (put-text-property pos-prop (1- pos-prop) 'perm-changed t))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
793 (forward-char 1)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
794
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
795 (defun wdired-toggle-bit()
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
796 "Toggle the permission bit at point."
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
797 (interactive)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
798 (let ((inhibit-read-only t)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
799 (new-bit "-")
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
800 (pos-prop (- (point) (- (current-column) wdired-col-perm))))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
801 (if (eq (char-after (point)) ?-)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
802 (setq new-bit
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
803 (if (= (% (- (current-column) wdired-col-perm) 3) 0) "r"
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
804 (if (= (% (- (current-column) wdired-col-perm) 3) 1) "w"
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
805 "x"))))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
806 (put-text-property 0 1 'local-map wdired-perm-mode-map new-bit)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
807 (put-text-property 0 1 'read-only t new-bit)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
808 (insert new-bit)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
809 (delete-char 1)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
810 (put-text-property pos-prop (1- pos-prop) 'perm-changed t)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
811
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
812 (defun wdired-mouse-toggle-bit (event)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
813 "Toggle the permission bit that was left clicked."
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
814 (interactive "e")
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
815 (mouse-set-point event)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
816 (wdired-toggle-bit))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
817
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
818 ;; Allowed chars for 4000 bit are Ss in position 3
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
819 ;; Allowed chars for 2000 bit are Ssl in position 6
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
820 ;; Allowed chars for 1000 bit are Tt in position 9
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
821 (defun wdired-perms-to-number (perms)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
822 (let ((nperm 0777))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
823 (if (= (elt perms 1) ?-) (setq nperm (- nperm 400)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
824 (if (= (elt perms 2) ?-) (setq nperm (- nperm 200)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
825 (let ((p-bit (elt perms 3)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
826 (if (memq p-bit '(?- ?S)) (setq nperm (- nperm 100)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
827 (if (memq p-bit '(?s ?S)) (setq nperm (+ nperm 4000))))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
828 (if (= (elt perms 4) ?-) (setq nperm (- nperm 40)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
829 (if (= (elt perms 5) ?-) (setq nperm (- nperm 20)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
830 (let ((p-bit (elt perms 6)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
831 (if (memq p-bit '(?- ?S ?l)) (setq nperm (- nperm 10)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
832 (if (memq p-bit '(?s ?S ?l)) (setq nperm (+ nperm 2000))))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
833 (if (= (elt perms 7) ?-) (setq nperm (- nperm 4)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
834 (if (= (elt perms 8) ?-) (setq nperm (- nperm 2)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
835 (let ((p-bit (elt perms 9)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
836 (if (memq p-bit '(?- ?T)) (setq nperm (- nperm 1)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
837 (if (memq p-bit '(?t ?T)) (setq nperm (+ nperm 1000))))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
838 nperm))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
839
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
840 ;; Perform the changes in the permissions of the files that have
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
841 ;; changed.
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
842 (defun wdired-do-perm-changes ()
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
843 (let ((changes nil)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
844 (errors 0)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
845 (prop-wanted (if (eq wdired-allow-to-change-permissions 'advanced)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
846 'old-perm 'perm-changed))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
847 filename perms-ori perms-new perm-tmp)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
848 (goto-char (next-single-property-change (point-min) prop-wanted
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
849 nil (point-max)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
850 (while (not (eobp))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
851 (setq perms-ori (get-text-property (point) 'old-perm))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
852 (setq perms-new (buffer-substring-no-properties
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
853 (point) (next-single-property-change (point) 'end-perm)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
854 (if (not (equal perms-ori perms-new))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
855 (progn
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
856 (setq changes t)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
857 (setq filename (wdired-get-filename nil t))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
858 (if (= (length perms-new) 10)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
859 (progn
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
860 (setq perm-tmp
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
861 (int-to-string (wdired-perms-to-number perms-new)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
862 (if (not (equal 0 (dired-call-process dired-chmod-program
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
863 t perm-tmp filename)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
864 (progn
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
865 (setq errors (1+ errors))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
866 (dired-log (concat dired-chmod-program " " perm-tmp
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
867 " `" filename "' failed\n\n")))))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
868 (setq errors (1+ errors))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
869 (dired-log (concat "Cannot parse permission `" perms-new
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
870 "' for file `" filename "'\n\n")))))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
871 (goto-char (next-single-property-change (1+ (point)) prop-wanted
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
872 nil (point-max))))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
873 (cons changes errors)))
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
874
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
875 (provide 'wdired)
|
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
876
|
55109
043dd9a4d1b4
(wdired-mode-map): Move init into declaration. Fix `return' binding.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
877 ;; arch-tag: bc00902e-526f-4305-bc7f-8862a559184f
|
55098
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
878 ;;; wdired.el ends here
|