Mercurial > emacs
annotate lisp/wdired.el @ 90776:dd7c098af727
Merge from emacs--devo--0
Patches applied:
* emacs--devo--0 (patch 638-652)
- Update from CVS
- Merge from gnus--rel--5.10
* gnus--rel--5.10 (patch 202)
- Update from CVS
Revision: emacs@sv.gnu.org/emacs--unicode--0--patch-177
author | Miles Bader <miles@gnu.org> |
---|---|
date | Mon, 26 Feb 2007 23:03:45 +0000 |
parents | e3694f1cb928 |
children | 9355f9b7bbff 8e5203081e80 |
rev | line source |
---|---|
55098 | 1 ;;; wdired.el --- Rename files editing their names in dired buffers |
2 | |
75347 | 3 ;; Copyright (C) 2004, 2005, 2006, 2007 Free Software Foundation, Inc. |
55098 | 4 |
5 ;; Filename: wdired.el | |
61350
796b7fe4bfd8
(wdired-advise-functions, wdired-add-skip-in-replace)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
61030
diff
changeset
|
6 ;; Author: Juan León Lahoz García <juanleon1@gmail.com> |
796b7fe4bfd8
(wdired-advise-functions, wdired-add-skip-in-replace)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
61030
diff
changeset
|
7 ;; Version: 2.0 |
55098 | 8 ;; Keywords: dired, environment, files, renaming |
9 | |
10 ;; This file is part of GNU Emacs. | |
11 | |
12 ;; GNU Emacs is free software; you can redistribute it and/or | |
13 ;; modify it under the terms of the GNU General Public License as | |
14 ;; published by the Free Software Foundation; either version 2, or (at | |
15 ;; your option) any later version. | |
16 | |
17 ;; This program is distributed in the hope that it will be useful, but | |
18 ;; WITHOUT ANY WARRANTY; without even the implied warranty of | |
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
20 ;; General Public License for more details. | |
21 | |
22 ;; You should have received a copy of the GNU General Public License | |
23 ;; along with GNU Emacs; see the file COPYING. If not, write to the | |
64091 | 24 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
25 ;; Boston, MA 02110-1301, USA. | |
55098 | 26 |
27 ;;; Commentary: | |
28 | |
29 ;; wdired.el (the "w" is for writable) provides an alternative way of | |
30 ;; renaming files. | |
31 ;; | |
32 ;; Have you ever wished to use C-x r t (string-rectangle), M-% | |
68680
bdaa27dd39d3
(wdired-mode-map): Use remap.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68671
diff
changeset
|
33 ;; (query-replace), M-c (capitalize-word), etc... to change the name of |
61473 | 34 ;; the files in a "dired" buffer? Now you can do this. All the power |
35 ;; of Emacs commands are available to renaming files! | |
68680
bdaa27dd39d3
(wdired-mode-map): Use remap.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68671
diff
changeset
|
36 ;; |
55098 | 37 ;; This package provides a function that makes the filenames of a a |
38 ;; dired buffer editable, by changing the buffer mode (which inhibits | |
39 ;; all of the commands of dired mode). Here you can edit the names of | |
40 ;; one or more files and directories, and when you press C-c C-c, the | |
41 ;; renaming takes effect and you are back to dired mode. | |
42 ;; | |
61473 | 43 ;; Another things you can do with WDired: |
55098 | 44 ;; |
45 ;; - To move files to another directory (by typing their path, | |
46 ;; absolute or relative, as a part of the new filename). | |
47 ;; | |
48 ;; - To change the target of symbolic links. | |
49 ;; | |
50 ;; - To change the permission bits of the filenames (in systems with a | |
51 ;; working unix-alike `dired-chmod-program'). See and customize the | |
61473 | 52 ;; variable `wdired-allow-to-change-permissions'. To change a single |
55098 | 53 ;; char (toggling between its two more usual values) you can press |
61473 | 54 ;; the space bar over it or left-click the mouse. To set any char to |
55098 | 55 ;; an specific value (this includes the SUID, SGID and STI bits) you |
61473 | 56 ;; can use the key labeled as the letter you want. Please note that |
55098 | 57 ;; permissions of the links cannot be changed in that way, because |
58 ;; the change would affect to their targets, and this would not be | |
59 ;; WYSIWYG :-). | |
60 ;; | |
61 ;; - To mark files for deletion, by deleting their whole filename. | |
62 | |
63 ;;; Installation: | |
64 | |
65 ;; Add this file (byte-compiling it is recommended) to your load-path. | |
66 ;; Then add one of these set of lines (or similar ones) to your config: | |
67 ;; | |
68 ;; This is the easy way: | |
69 ;; | |
70 ;; (require 'wdired) | |
71 ;; (define-key dired-mode-map "r" 'wdired-change-to-wdired-mode) | |
72 ;; | |
61473 | 73 ;; This is the recommended way for faster Emacs startup time and lower |
74 ;; memory consumption: | |
55098 | 75 ;; |
76 ;; (autoload 'wdired-change-to-wdired-mode "wdired") | |
61473 | 77 ;; (eval-after-load "dired" |
55098 | 78 ;; '(lambda () |
79 ;; (define-key dired-mode-map "r" 'wdired-change-to-wdired-mode) | |
80 ;; (define-key dired-mode-map | |
81 ;; [menu-bar immediate wdired-change-to-wdired-mode] | |
82 ;; '("Edit File Names" . wdired-change-to-wdired-mode)))) | |
83 ;; | |
61473 | 84 ;; Type "M-x customize-group RET wdired" if you want to make changes |
85 ;; to the default behavior. | |
55098 | 86 |
87 ;;; Usage: | |
88 | |
89 ;; Then, you can start editing the names of the files by typing "r" | |
90 ;; (or whatever key you choose, or M-x wdired-change-to-wdired-mode). | |
91 ;; Use C-c C-c when finished or C-c C-k to abort. You can use also the | |
92 ;; menu options: in dired mode, "Edit File Names" under "Immediate". | |
93 ;; While editing the names, a new submenu "WDired" is available at top | |
94 ;; level. You can customize the behavior of this package from this | |
95 ;; menu. | |
96 | |
97 ;;; Change Log: | |
98 | |
61473 | 99 ;; Google is your friend (previous versions with complete changelogs |
100 ;; were posted to gnu.emacs.sources) | |
55098 | 101 |
102 ;;; Code: | |
103 | |
61473 | 104 (defvar dired-backup-overwrite) ; Only in Emacs 20.x this is a custom var |
55098 | 105 |
69279
45a2e01db282
(toplevel): Require `cl' at compile-time.
John Paul Wallington <jpw@pobox.com>
parents:
68680
diff
changeset
|
106 (eval-when-compile (require 'cl)) |
68680
bdaa27dd39d3
(wdired-mode-map): Use remap.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68671
diff
changeset
|
107 (require 'dired) |
bdaa27dd39d3
(wdired-mode-map): Use remap.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68671
diff
changeset
|
108 (autoload 'dired-do-create-files-regexp "dired-aux") |
bdaa27dd39d3
(wdired-mode-map): Use remap.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68671
diff
changeset
|
109 (autoload 'dired-call-process "dired-aux") |
55098 | 110 |
111 (defgroup wdired nil | |
112 "Mode to rename files by editing their names in dired buffers." | |
113 :group 'dired) | |
114 | |
115 (defcustom wdired-use-interactive-rename nil | |
68680
bdaa27dd39d3
(wdired-mode-map): Use remap.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68671
diff
changeset
|
116 "If non-nil, WDired requires confirmation before actually renaming files. |
61473 | 117 If nil, WDired doesn't require confirmation to change the file names, |
118 and the variable `wdired-confirm-overwrite' controls whether it is ok | |
119 to overwrite files without asking." | |
55098 | 120 :type 'boolean |
121 :group 'wdired) | |
122 | |
61473 | 123 (defcustom wdired-confirm-overwrite t |
68680
bdaa27dd39d3
(wdired-mode-map): Use remap.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68671
diff
changeset
|
124 "If nil the renames can overwrite files without asking. |
61473 | 125 This variable has no effect at all if `wdired-use-interactive-rename' |
126 is not nil." | |
55098 | 127 :type 'boolean |
128 :group 'wdired) | |
129 | |
61473 | 130 (defcustom wdired-use-dired-vertical-movement nil |
68680
bdaa27dd39d3
(wdired-mode-map): Use remap.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68671
diff
changeset
|
131 "If t, the \"up\" and \"down\" movement works as in Dired mode. |
55098 | 132 That is, always move the point to the beginning of the filename at line. |
133 | |
134 If `sometimes, only move to the beginning of filename if the point is | |
135 before it, and `track-eol' is honored. This behavior is very handy | |
136 when editing several filenames. | |
137 | |
138 If nil, \"up\" and \"down\" movement is done as in any other buffer." | |
139 :type '(choice (const :tag "As in any other mode" nil) | |
140 (const :tag "Smart cursor placement" sometimes) | |
141 (other :tag "As in dired mode" t)) | |
142 :group 'wdired) | |
143 | |
144 (defcustom wdired-allow-to-redirect-links t | |
68680
bdaa27dd39d3
(wdired-mode-map): Use remap.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68671
diff
changeset
|
145 "If non-nil, the target of the symbolic links are editable. |
55098 | 146 In systems without symbolic links support, this variable has no effect |
147 at all." | |
148 :type 'boolean | |
149 :group 'wdired) | |
150 | |
151 (defcustom wdired-allow-to-change-permissions nil | |
68680
bdaa27dd39d3
(wdired-mode-map): Use remap.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68671
diff
changeset
|
152 "If non-nil, the permissions bits of the files are editable. |
55098 | 153 |
154 If t, to change a single bit, put the cursor over it and press the | |
155 space bar, or left click over it. You can also hit the letter you want | |
156 to set: if this value is allowed, the character in the buffer will be | |
157 changed. Anyway, the point is advanced one position, so, for example, | |
61473 | 158 you can keep the <x> key pressed to give execution permissions to |
55098 | 159 everybody to that file. |
160 | |
161 If `advanced, the bits are freely editable. You can use | |
162 `string-rectangle', `query-replace', etc. You can put any value (even | |
163 newlines), but if you want your changes to be useful, you better put a | |
164 intelligible value. | |
165 | |
61473 | 166 Anyway, the real change of the permissions is done by the external |
55098 | 167 program `dired-chmod-program', which must exist." |
168 :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>
parents:
55107
diff
changeset
|
169 (const :tag "Toggle/set bits" t) |
55098 | 170 (other :tag "Bits freely editable" advanced)) |
171 :group 'wdired) | |
172 | |
55109
043dd9a4d1b4
(wdired-mode-map): Move init into declaration. Fix `return' binding.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55107
diff
changeset
|
173 (defvar wdired-mode-map |
043dd9a4d1b4
(wdired-mode-map): Move init into declaration. Fix `return' binding.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55107
diff
changeset
|
174 (let ((map (make-sparse-keymap))) |
043dd9a4d1b4
(wdired-mode-map): Move init into declaration. Fix `return' binding.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55107
diff
changeset
|
175 (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>
parents:
55107
diff
changeset
|
176 (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>
parents:
55107
diff
changeset
|
177 (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>
parents:
55107
diff
changeset
|
178 (define-key map "\C-c\C-[" 'wdired-abort-changes) |
61473 | 179 (define-key map "\C-m" 'ignore) |
180 (define-key map "\C-j" 'ignore) | |
181 (define-key map "\C-o" 'ignore) | |
55109
043dd9a4d1b4
(wdired-mode-map): Move init into declaration. Fix `return' binding.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55107
diff
changeset
|
182 (define-key map [up] 'wdired-previous-line) |
043dd9a4d1b4
(wdired-mode-map): Move init into declaration. Fix `return' binding.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55107
diff
changeset
|
183 (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>
parents:
55107
diff
changeset
|
184 (define-key map [down] 'wdired-next-line) |
043dd9a4d1b4
(wdired-mode-map): Move init into declaration. Fix `return' binding.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55107
diff
changeset
|
185 (define-key map "\C-n" 'wdired-next-line) |
55098 | 186 |
55109
043dd9a4d1b4
(wdired-mode-map): Move init into declaration. Fix `return' binding.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55107
diff
changeset
|
187 (define-key map [menu-bar wdired] |
043dd9a4d1b4
(wdired-mode-map): Move init into declaration. Fix `return' binding.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55107
diff
changeset
|
188 (cons "WDired" (make-sparse-keymap "WDired"))) |
043dd9a4d1b4
(wdired-mode-map): Move init into declaration. Fix `return' binding.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55107
diff
changeset
|
189 (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>
parents:
55107
diff
changeset
|
190 '("Options" . wdired-customize)) |
043dd9a4d1b4
(wdired-mode-map): Move init into declaration. Fix `return' binding.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55107
diff
changeset
|
191 (define-key map [menu-bar wdired dashes] |
55098 | 192 '("--")) |
55109
043dd9a4d1b4
(wdired-mode-map): Move init into declaration. Fix `return' binding.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55107
diff
changeset
|
193 (define-key map [menu-bar wdired wdired-abort-changes] |
68152
3a7458f9152d
(wdired-mode-map): Add help echo for wdired-abort-changes.
Nick Roberts <nickrob@snap.net.nz>
parents:
67561
diff
changeset
|
194 '(menu-item "Abort Changes" wdired-abort-changes |
3a7458f9152d
(wdired-mode-map): Add help echo for wdired-abort-changes.
Nick Roberts <nickrob@snap.net.nz>
parents:
67561
diff
changeset
|
195 :help "Abort changes and return to dired mode")) |
55109
043dd9a4d1b4
(wdired-mode-map): Move init into declaration. Fix `return' binding.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55107
diff
changeset
|
196 (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>
parents:
55107
diff
changeset
|
197 '("Commit Changes" . wdired-finish-edit)) |
68680
bdaa27dd39d3
(wdired-mode-map): Use remap.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68671
diff
changeset
|
198 |
bdaa27dd39d3
(wdired-mode-map): Use remap.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68671
diff
changeset
|
199 (define-key map [remap upcase-word] 'wdired-upcase-word) |
bdaa27dd39d3
(wdired-mode-map): Use remap.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68671
diff
changeset
|
200 (define-key map [remap capitalize-word] 'wdired-capitalize-word) |
bdaa27dd39d3
(wdired-mode-map): Use remap.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68671
diff
changeset
|
201 (define-key map [remap downcase-word] 'wdired-downcase-word) |
bdaa27dd39d3
(wdired-mode-map): Use remap.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68671
diff
changeset
|
202 |
55109
043dd9a4d1b4
(wdired-mode-map): Move init into declaration. Fix `return' binding.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55107
diff
changeset
|
203 map)) |
55098 | 204 |
55109
043dd9a4d1b4
(wdired-mode-map): Move init into declaration. Fix `return' binding.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55107
diff
changeset
|
205 (defvar wdired-mode-hook nil |
61473 | 206 "Hooks run when changing to WDired mode.") |
55098 | 207 |
208 ;; Local variables (put here to avoid compilation gripes) | |
209 (defvar wdired-col-perm) ;; Column where the permission bits start | |
210 (defvar wdired-old-content) | |
67561
827930ad591b
(wdired-old-point): New internal variable.
Juri Linkov <juri@jurta.org>
parents:
65582
diff
changeset
|
211 (defvar wdired-old-point) |
55098 | 212 |
213 | |
214 (defun wdired-mode () | |
215 "\\<wdired-mode-map>File Names Editing mode. | |
216 | |
61473 | 217 Press \\[wdired-finish-edit] to make the changes to take effect |
218 and exit. To abort the edit, use \\[wdired-abort-changes]. | |
55098 | 219 |
61473 | 220 In this mode you can edit the names of the files, the target of |
221 the links and the permission bits of the files. You can use | |
222 \\[customize-group] RET wdired to customize WDired behavior. | |
55098 | 223 |
61473 | 224 The only editable texts in a WDired buffer are filenames, |
225 symbolic link targets, and filenames permission." | |
55098 | 226 (interactive) |
227 (error "This mode can be enabled only by `wdired-change-to-wdired-mode'")) | |
228 (put 'wdired-mode 'mode-class 'special) | |
229 | |
230 | |
231 ;;;###autoload | |
232 (defun wdired-change-to-wdired-mode () | |
233 "Put a dired buffer in a mode in which filenames are editable. | |
61473 | 234 \\<wdired-mode-map> |
235 This mode allows the user to change the names of the files, and after | |
236 typing \\[wdired-finish-edit] Emacs renames the files and directories | |
237 in disk. | |
55098 | 238 |
239 See `wdired-mode'." | |
240 (interactive) | |
72160
183934d15fbb
(wdired-change-to-wdired-mode, wdired-change-to-dired-mode):
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
69279
diff
changeset
|
241 (or (eq major-mode 'dired-mode) |
183934d15fbb
(wdired-change-to-wdired-mode, wdired-change-to-dired-mode):
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
69279
diff
changeset
|
242 (error "Not a Dired buffer")) |
55098 | 243 (set (make-local-variable 'wdired-old-content) |
244 (buffer-substring (point-min) (point-max))) | |
67561
827930ad591b
(wdired-old-point): New internal variable.
Juri Linkov <juri@jurta.org>
parents:
65582
diff
changeset
|
245 (set (make-local-variable 'wdired-old-point) (point)) |
61350
796b7fe4bfd8
(wdired-advise-functions, wdired-add-skip-in-replace)
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
61030
diff
changeset
|
246 (set (make-local-variable 'query-replace-skip-read-only) t) |
55098 | 247 (use-local-map wdired-mode-map) |
55109
043dd9a4d1b4
(wdired-mode-map): Move init into declaration. Fix `return' binding.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55107
diff
changeset
|
248 (force-mode-line-update) |
55098 | 249 (setq buffer-read-only nil) |
250 (dired-unadvertise default-directory) | |
251 (add-hook 'kill-buffer-hook 'wdired-check-kill-buffer nil t) | |
252 (setq major-mode 'wdired-mode) | |
61473 | 253 (setq mode-name "Editable Dired") |
55098 | 254 (setq revert-buffer-function 'wdired-revert) |
255 ;; I temp disable undo for performance: since I'm going to clear the | |
256 ;; undo list, it can save more than a 9% of time with big | |
257 ;; directories because setting properties modify the undo-list. | |
258 (buffer-disable-undo) | |
259 (wdired-preprocess-files) | |
260 (if wdired-allow-to-change-permissions | |
261 (wdired-preprocess-perms)) | |
262 (if (and wdired-allow-to-redirect-links (fboundp 'make-symbolic-link)) | |
263 (wdired-preprocess-symlinks)) | |
264 (buffer-enable-undo) ; Performance hack. See above. | |
265 (set-buffer-modified-p nil) | |
266 (setq buffer-undo-list nil) | |
62746
0fe5c8d2cd65
(wdired-change-to-wdired-mode): Use run-mode-hooks.
Lute Kamstra <lute@gnu.org>
parents:
61473
diff
changeset
|
267 (run-mode-hooks 'wdired-mode-hook) |
67561
827930ad591b
(wdired-old-point): New internal variable.
Juri Linkov <juri@jurta.org>
parents:
65582
diff
changeset
|
268 (message "%s" (substitute-command-keys |
827930ad591b
(wdired-old-point): New internal variable.
Juri Linkov <juri@jurta.org>
parents:
65582
diff
changeset
|
269 "Press \\[wdired-finish-edit] when finished \ |
61030
6b0506554db8
(wdired-change-to-wdired-mode):
Juri Linkov <juri@jurta.org>
parents:
60141
diff
changeset
|
270 or \\[wdired-abort-changes] to abort changes"))) |
55098 | 271 |
272 | |
273 ;; Protect the buffer so only the filenames can be changed, and put | |
274 ;; properties so filenames (old and new) can be easily found. | |
275 (defun wdired-preprocess-files () | |
276 (put-text-property 1 2 'front-sticky t) | |
277 (save-excursion | |
278 (goto-char (point-min)) | |
279 (let ((b-protection (point)) | |
280 filename) | |
281 (while (not (eobp)) | |
282 (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>
parents:
55107
diff
changeset
|
283 (when (and filename |
043dd9a4d1b4
(wdired-mode-map): Move init into declaration. Fix `return' binding.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55107
diff
changeset
|
284 (not (member (file-name-nondirectory filename) '("." "..")))) |
043dd9a4d1b4
(wdired-mode-map): Move init into declaration. Fix `return' binding.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55107
diff
changeset
|
285 (dired-move-to-filename) |
74526
1a43c99020cb
(wdired-change-to-wdired-mode, wdired-finish-edit)
Chong Yidong <cyd@stupidchicken.com>
parents:
72160
diff
changeset
|
286 ;; The rear-nonsticky property below shall ensure that text preceding |
1a43c99020cb
(wdired-change-to-wdired-mode, wdired-finish-edit)
Chong Yidong <cyd@stupidchicken.com>
parents:
72160
diff
changeset
|
287 ;; the filename can't be modified. |
1a43c99020cb
(wdired-change-to-wdired-mode, wdired-finish-edit)
Chong Yidong <cyd@stupidchicken.com>
parents:
72160
diff
changeset
|
288 (add-text-properties |
1a43c99020cb
(wdired-change-to-wdired-mode, wdired-finish-edit)
Chong Yidong <cyd@stupidchicken.com>
parents:
72160
diff
changeset
|
289 (1- (point)) (point) `(old-name ,filename rear-nonsticky (read-only))) |
1a43c99020cb
(wdired-change-to-wdired-mode, wdired-finish-edit)
Chong Yidong <cyd@stupidchicken.com>
parents:
72160
diff
changeset
|
290 (put-text-property b-protection (point) 'read-only t) |
1a43c99020cb
(wdired-change-to-wdired-mode, wdired-finish-edit)
Chong Yidong <cyd@stupidchicken.com>
parents:
72160
diff
changeset
|
291 (setq b-protection (dired-move-to-end-of-filename t)) |
1a43c99020cb
(wdired-change-to-wdired-mode, wdired-finish-edit)
Chong Yidong <cyd@stupidchicken.com>
parents:
72160
diff
changeset
|
292 (put-text-property (point) (1+ (point)) 'end-name t)) |
55098 | 293 (forward-line)) |
294 (put-text-property b-protection (point-max) 'read-only t)))) | |
295 | |
296 ;; This code is a copy of some dired-get-filename lines. | |
297 (defsubst wdired-normalize-filename (file) | |
298 (setq file | |
55109
043dd9a4d1b4
(wdired-mode-map): Move init into declaration. Fix `return' binding.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55107
diff
changeset
|
299 ;; 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>
parents:
55107
diff
changeset
|
300 ;; doing such unquoting? --Stef |
55098 | 301 (read (concat |
55109
043dd9a4d1b4
(wdired-mode-map): Move init into declaration. Fix `return' binding.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55107
diff
changeset
|
302 "\"" (replace-regexp-in-string |
043dd9a4d1b4
(wdired-mode-map): Move init into declaration. Fix `return' binding.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55107
diff
changeset
|
303 "\\([^\\]\\|\\`\\)\"" "\\1\\\\\"" file) |
55098 | 304 "\""))) |
305 (and file buffer-file-coding-system | |
306 (not file-name-coding-system) | |
307 (not default-file-name-coding-system) | |
308 (setq file (encode-coding-string file buffer-file-coding-system))) | |
309 file) | |
310 | |
311 (defun wdired-get-filename (&optional no-dir old) | |
312 "Return the filename at line. | |
55109
043dd9a4d1b4
(wdired-mode-map): Move init into declaration. Fix `return' binding.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55107
diff
changeset
|
313 Similar to `dired-get-filename' but it doesn't rely on regexps. It |
61473 | 314 relies on WDired buffer's properties. Optional arg NO-DIR with value |
55098 | 315 non-nil means don't include directory. Optional arg OLD with value |
316 non-nil means return old filename." | |
55109
043dd9a4d1b4
(wdired-mode-map): Move init into declaration. Fix `return' binding.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55107
diff
changeset
|
317 ;; FIXME: Use dired-get-filename's new properties. |
74526
1a43c99020cb
(wdired-change-to-wdired-mode, wdired-finish-edit)
Chong Yidong <cyd@stupidchicken.com>
parents:
72160
diff
changeset
|
318 (let (beg end file) |
1a43c99020cb
(wdired-change-to-wdired-mode, wdired-finish-edit)
Chong Yidong <cyd@stupidchicken.com>
parents:
72160
diff
changeset
|
319 (save-excursion |
1a43c99020cb
(wdired-change-to-wdired-mode, wdired-finish-edit)
Chong Yidong <cyd@stupidchicken.com>
parents:
72160
diff
changeset
|
320 (setq end (line-end-position)) |
1a43c99020cb
(wdired-change-to-wdired-mode, wdired-finish-edit)
Chong Yidong <cyd@stupidchicken.com>
parents:
72160
diff
changeset
|
321 (beginning-of-line) |
1a43c99020cb
(wdired-change-to-wdired-mode, wdired-finish-edit)
Chong Yidong <cyd@stupidchicken.com>
parents:
72160
diff
changeset
|
322 (setq beg (next-single-property-change (point) 'old-name nil end)) |
1a43c99020cb
(wdired-change-to-wdired-mode, wdired-finish-edit)
Chong Yidong <cyd@stupidchicken.com>
parents:
72160
diff
changeset
|
323 (unless (eq beg end) |
1a43c99020cb
(wdired-change-to-wdired-mode, wdired-finish-edit)
Chong Yidong <cyd@stupidchicken.com>
parents:
72160
diff
changeset
|
324 (if old |
1a43c99020cb
(wdired-change-to-wdired-mode, wdired-finish-edit)
Chong Yidong <cyd@stupidchicken.com>
parents:
72160
diff
changeset
|
325 (setq file (get-text-property beg 'old-name)) |
1a43c99020cb
(wdired-change-to-wdired-mode, wdired-finish-edit)
Chong Yidong <cyd@stupidchicken.com>
parents:
72160
diff
changeset
|
326 (setq end (next-single-property-change (1+ beg) 'end-name)) |
1a43c99020cb
(wdired-change-to-wdired-mode, wdired-finish-edit)
Chong Yidong <cyd@stupidchicken.com>
parents:
72160
diff
changeset
|
327 (setq file (buffer-substring-no-properties (1+ beg) end))) |
1a43c99020cb
(wdired-change-to-wdired-mode, wdired-finish-edit)
Chong Yidong <cyd@stupidchicken.com>
parents:
72160
diff
changeset
|
328 (and file (setq file (wdired-normalize-filename file)))) |
1a43c99020cb
(wdired-change-to-wdired-mode, wdired-finish-edit)
Chong Yidong <cyd@stupidchicken.com>
parents:
72160
diff
changeset
|
329 (if (or no-dir old) |
1a43c99020cb
(wdired-change-to-wdired-mode, wdired-finish-edit)
Chong Yidong <cyd@stupidchicken.com>
parents:
72160
diff
changeset
|
330 file |
1a43c99020cb
(wdired-change-to-wdired-mode, wdired-finish-edit)
Chong Yidong <cyd@stupidchicken.com>
parents:
72160
diff
changeset
|
331 (and file (> (length file) 0) |
1a43c99020cb
(wdired-change-to-wdired-mode, wdired-finish-edit)
Chong Yidong <cyd@stupidchicken.com>
parents:
72160
diff
changeset
|
332 (concat (dired-current-directory) file)))))) |
55098 | 333 |
334 | |
335 (defun wdired-change-to-dired-mode () | |
336 "Change the mode back to dired." | |
72160
183934d15fbb
(wdired-change-to-wdired-mode, wdired-change-to-dired-mode):
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
69279
diff
changeset
|
337 (or (eq major-mode 'wdired-mode) |
183934d15fbb
(wdired-change-to-wdired-mode, wdired-change-to-dired-mode):
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
69279
diff
changeset
|
338 (error "Not a Wdired buffer")) |
55098 | 339 (let ((inhibit-read-only t)) |
74526
1a43c99020cb
(wdired-change-to-wdired-mode, wdired-finish-edit)
Chong Yidong <cyd@stupidchicken.com>
parents:
72160
diff
changeset
|
340 (remove-text-properties |
1a43c99020cb
(wdired-change-to-wdired-mode, wdired-finish-edit)
Chong Yidong <cyd@stupidchicken.com>
parents:
72160
diff
changeset
|
341 (point-min) (point-max) |
1a43c99020cb
(wdired-change-to-wdired-mode, wdired-finish-edit)
Chong Yidong <cyd@stupidchicken.com>
parents:
72160
diff
changeset
|
342 '(front-sticky nil rear-nonsticky nil read-only nil keymap nil))) |
55098 | 343 (use-local-map dired-mode-map) |
55109
043dd9a4d1b4
(wdired-mode-map): Move init into declaration. Fix `return' binding.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55107
diff
changeset
|
344 (force-mode-line-update) |
55098 | 345 (setq buffer-read-only t) |
346 (setq major-mode 'dired-mode) | |
347 (setq mode-name "Dired") | |
348 (dired-advertise) | |
349 (remove-hook 'kill-buffer-hook 'wdired-check-kill-buffer t) | |
68680
bdaa27dd39d3
(wdired-mode-map): Use remap.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68671
diff
changeset
|
350 (set (make-local-variable 'revert-buffer-function) 'dired-revert)) |
55098 | 351 |
352 | |
353 (defun wdired-abort-changes () | |
354 "Abort changes and return to dired mode." | |
355 (interactive) | |
356 (let ((inhibit-read-only t)) | |
357 (erase-buffer) | |
67561
827930ad591b
(wdired-old-point): New internal variable.
Juri Linkov <juri@jurta.org>
parents:
65582
diff
changeset
|
358 (insert wdired-old-content) |
827930ad591b
(wdired-old-point): New internal variable.
Juri Linkov <juri@jurta.org>
parents:
65582
diff
changeset
|
359 (goto-char wdired-old-point)) |
55098 | 360 (wdired-change-to-dired-mode) |
361 (set-buffer-modified-p nil) | |
55371
a96e9558b1ea
(wdired-change-to-wdired-mode): Quote wdired-mode-hook in run-hooks.
Lars Hansen <larsh@soem.dk>
parents:
55109
diff
changeset
|
362 (setq buffer-undo-list nil) |
a96e9558b1ea
(wdired-change-to-wdired-mode): Quote wdired-mode-hook in run-hooks.
Lars Hansen <larsh@soem.dk>
parents:
55109
diff
changeset
|
363 (message "Changes aborted")) |
55098 | 364 |
365 (defun wdired-finish-edit () | |
366 "Actually rename files based on your editing in the Dired buffer." | |
367 (interactive) | |
368 (wdired-change-to-dired-mode) | |
61473 | 369 (let ((overwrite (or (not wdired-confirm-overwrite) 1)) |
55098 | 370 (changes nil) |
371 (files-deleted nil) | |
372 (errors 0) | |
373 file-ori file-new tmp-value) | |
374 (save-excursion | |
74526
1a43c99020cb
(wdired-change-to-wdired-mode, wdired-finish-edit)
Chong Yidong <cyd@stupidchicken.com>
parents:
72160
diff
changeset
|
375 (when (and wdired-allow-to-redirect-links |
1a43c99020cb
(wdired-change-to-wdired-mode, wdired-finish-edit)
Chong Yidong <cyd@stupidchicken.com>
parents:
72160
diff
changeset
|
376 (fboundp 'make-symbolic-link)) |
1a43c99020cb
(wdired-change-to-wdired-mode, wdired-finish-edit)
Chong Yidong <cyd@stupidchicken.com>
parents:
72160
diff
changeset
|
377 (setq tmp-value (wdired-do-symlink-changes)) |
1a43c99020cb
(wdired-change-to-wdired-mode, wdired-finish-edit)
Chong Yidong <cyd@stupidchicken.com>
parents:
72160
diff
changeset
|
378 (setq errors (cdr tmp-value)) |
1a43c99020cb
(wdired-change-to-wdired-mode, wdired-finish-edit)
Chong Yidong <cyd@stupidchicken.com>
parents:
72160
diff
changeset
|
379 (setq changes (car tmp-value))) |
1a43c99020cb
(wdired-change-to-wdired-mode, wdired-finish-edit)
Chong Yidong <cyd@stupidchicken.com>
parents:
72160
diff
changeset
|
380 (when (and wdired-allow-to-change-permissions |
1a43c99020cb
(wdired-change-to-wdired-mode, wdired-finish-edit)
Chong Yidong <cyd@stupidchicken.com>
parents:
72160
diff
changeset
|
381 (boundp 'wdired-col-perm)) ; could have been changed |
1a43c99020cb
(wdired-change-to-wdired-mode, wdired-finish-edit)
Chong Yidong <cyd@stupidchicken.com>
parents:
72160
diff
changeset
|
382 (setq tmp-value (wdired-do-perm-changes)) |
1a43c99020cb
(wdired-change-to-wdired-mode, wdired-finish-edit)
Chong Yidong <cyd@stupidchicken.com>
parents:
72160
diff
changeset
|
383 (setq errors (+ errors (cdr tmp-value))) |
1a43c99020cb
(wdired-change-to-wdired-mode, wdired-finish-edit)
Chong Yidong <cyd@stupidchicken.com>
parents:
72160
diff
changeset
|
384 (setq changes (or changes (car tmp-value)))) |
55098 | 385 (goto-char (point-max)) |
386 (while (not (bobp)) | |
387 (setq file-ori (wdired-get-filename nil t)) | |
74526
1a43c99020cb
(wdired-change-to-wdired-mode, wdired-finish-edit)
Chong Yidong <cyd@stupidchicken.com>
parents:
72160
diff
changeset
|
388 (when file-ori |
1a43c99020cb
(wdired-change-to-wdired-mode, wdired-finish-edit)
Chong Yidong <cyd@stupidchicken.com>
parents:
72160
diff
changeset
|
389 (setq file-new (wdired-get-filename))) |
1a43c99020cb
(wdired-change-to-wdired-mode, wdired-finish-edit)
Chong Yidong <cyd@stupidchicken.com>
parents:
72160
diff
changeset
|
390 (when (and file-ori (not (equal file-new file-ori))) |
1a43c99020cb
(wdired-change-to-wdired-mode, wdired-finish-edit)
Chong Yidong <cyd@stupidchicken.com>
parents:
72160
diff
changeset
|
391 (setq changes t) |
1a43c99020cb
(wdired-change-to-wdired-mode, wdired-finish-edit)
Chong Yidong <cyd@stupidchicken.com>
parents:
72160
diff
changeset
|
392 (if (not file-new) ;empty filename! |
1a43c99020cb
(wdired-change-to-wdired-mode, wdired-finish-edit)
Chong Yidong <cyd@stupidchicken.com>
parents:
72160
diff
changeset
|
393 (setq files-deleted (cons file-ori files-deleted)) |
1a43c99020cb
(wdired-change-to-wdired-mode, wdired-finish-edit)
Chong Yidong <cyd@stupidchicken.com>
parents:
72160
diff
changeset
|
394 (setq file-new (substitute-in-file-name file-new)) |
1a43c99020cb
(wdired-change-to-wdired-mode, wdired-finish-edit)
Chong Yidong <cyd@stupidchicken.com>
parents:
72160
diff
changeset
|
395 (if wdired-use-interactive-rename |
1a43c99020cb
(wdired-change-to-wdired-mode, wdired-finish-edit)
Chong Yidong <cyd@stupidchicken.com>
parents:
72160
diff
changeset
|
396 (wdired-search-and-rename file-ori file-new) |
1a43c99020cb
(wdired-change-to-wdired-mode, wdired-finish-edit)
Chong Yidong <cyd@stupidchicken.com>
parents:
72160
diff
changeset
|
397 ;; If dired-rename-file autoloads dired-aux while |
1a43c99020cb
(wdired-change-to-wdired-mode, wdired-finish-edit)
Chong Yidong <cyd@stupidchicken.com>
parents:
72160
diff
changeset
|
398 ;; dired-backup-overwrite is locally bound, |
1a43c99020cb
(wdired-change-to-wdired-mode, wdired-finish-edit)
Chong Yidong <cyd@stupidchicken.com>
parents:
72160
diff
changeset
|
399 ;; dired-backup-overwrite won't be initialized. |
1a43c99020cb
(wdired-change-to-wdired-mode, wdired-finish-edit)
Chong Yidong <cyd@stupidchicken.com>
parents:
72160
diff
changeset
|
400 ;; So we must ensure dired-aux is loaded. |
1a43c99020cb
(wdired-change-to-wdired-mode, wdired-finish-edit)
Chong Yidong <cyd@stupidchicken.com>
parents:
72160
diff
changeset
|
401 (require 'dired-aux) |
1a43c99020cb
(wdired-change-to-wdired-mode, wdired-finish-edit)
Chong Yidong <cyd@stupidchicken.com>
parents:
72160
diff
changeset
|
402 (condition-case err |
1a43c99020cb
(wdired-change-to-wdired-mode, wdired-finish-edit)
Chong Yidong <cyd@stupidchicken.com>
parents:
72160
diff
changeset
|
403 (let ((dired-backup-overwrite nil)) |
1a43c99020cb
(wdired-change-to-wdired-mode, wdired-finish-edit)
Chong Yidong <cyd@stupidchicken.com>
parents:
72160
diff
changeset
|
404 (dired-rename-file file-ori file-new |
1a43c99020cb
(wdired-change-to-wdired-mode, wdired-finish-edit)
Chong Yidong <cyd@stupidchicken.com>
parents:
72160
diff
changeset
|
405 overwrite)) |
1a43c99020cb
(wdired-change-to-wdired-mode, wdired-finish-edit)
Chong Yidong <cyd@stupidchicken.com>
parents:
72160
diff
changeset
|
406 (error |
1a43c99020cb
(wdired-change-to-wdired-mode, wdired-finish-edit)
Chong Yidong <cyd@stupidchicken.com>
parents:
72160
diff
changeset
|
407 (setq errors (1+ errors)) |
1a43c99020cb
(wdired-change-to-wdired-mode, wdired-finish-edit)
Chong Yidong <cyd@stupidchicken.com>
parents:
72160
diff
changeset
|
408 (dired-log (concat "Rename `" file-ori "' to `" |
1a43c99020cb
(wdired-change-to-wdired-mode, wdired-finish-edit)
Chong Yidong <cyd@stupidchicken.com>
parents:
72160
diff
changeset
|
409 file-new "' failed:\n%s\n") |
1a43c99020cb
(wdired-change-to-wdired-mode, wdired-finish-edit)
Chong Yidong <cyd@stupidchicken.com>
parents:
72160
diff
changeset
|
410 err)))))) |
55098 | 411 (forward-line -1))) |
412 (if changes | |
413 (revert-buffer) ;The "revert" is necessary to re-sort the buffer | |
68680
bdaa27dd39d3
(wdired-mode-map): Use remap.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68671
diff
changeset
|
414 (let ((inhibit-read-only t)) |
55098 | 415 (remove-text-properties (point-min) (point-max) |
416 '(old-name nil end-name nil old-link nil | |
417 end-link nil end-perm nil | |
418 old-perm nil perm-changed nil)) | |
419 (message "(No changes to be performed)"))) | |
74526
1a43c99020cb
(wdired-change-to-wdired-mode, wdired-finish-edit)
Chong Yidong <cyd@stupidchicken.com>
parents:
72160
diff
changeset
|
420 (when files-deleted |
1a43c99020cb
(wdired-change-to-wdired-mode, wdired-finish-edit)
Chong Yidong <cyd@stupidchicken.com>
parents:
72160
diff
changeset
|
421 (wdired-flag-for-deletion files-deleted)) |
1a43c99020cb
(wdired-change-to-wdired-mode, wdired-finish-edit)
Chong Yidong <cyd@stupidchicken.com>
parents:
72160
diff
changeset
|
422 (when (> errors 0) |
1a43c99020cb
(wdired-change-to-wdired-mode, wdired-finish-edit)
Chong Yidong <cyd@stupidchicken.com>
parents:
72160
diff
changeset
|
423 (dired-log-summary (format "%d rename actions failed" errors) nil))) |
55098 | 424 (set-buffer-modified-p nil) |
425 (setq buffer-undo-list nil)) | |
426 | |
68680
bdaa27dd39d3
(wdired-mode-map): Use remap.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68671
diff
changeset
|
427 ;; Rename a file, searching it in a modified dired buffer, in order |
55098 | 428 ;; to be able to use `dired-do-create-files-regexp' and get its |
68680
bdaa27dd39d3
(wdired-mode-map): Use remap.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68671
diff
changeset
|
429 ;; "benefits". |
55098 | 430 (defun wdired-search-and-rename (filename-ori filename-new) |
431 (save-excursion | |
432 (goto-char (point-max)) | |
433 (forward-line -1) | |
434 (let ((exit-while nil) | |
435 curr-filename) | |
436 (while (not exit-while) | |
437 (setq curr-filename (wdired-get-filename)) | |
438 (if (and curr-filename | |
439 (equal (substitute-in-file-name curr-filename) filename-new)) | |
440 (progn | |
441 (setq exit-while t) | |
442 (let ((inhibit-read-only t)) | |
443 (dired-move-to-filename) | |
444 (search-forward (wdired-get-filename t) nil t) | |
445 (replace-match (file-name-nondirectory filename-ori) t t)) | |
446 (dired-do-create-files-regexp | |
447 (function dired-rename-file) | |
448 "Move" 1 ".*" filename-new nil t)) | |
74526
1a43c99020cb
(wdired-change-to-wdired-mode, wdired-finish-edit)
Chong Yidong <cyd@stupidchicken.com>
parents:
72160
diff
changeset
|
449 (forward-line -1) |
1a43c99020cb
(wdired-change-to-wdired-mode, wdired-finish-edit)
Chong Yidong <cyd@stupidchicken.com>
parents:
72160
diff
changeset
|
450 (beginning-of-line) |
1a43c99020cb
(wdired-change-to-wdired-mode, wdired-finish-edit)
Chong Yidong <cyd@stupidchicken.com>
parents:
72160
diff
changeset
|
451 (setq exit-while (bobp))))))) |
55098 | 452 |
453 ;; marks a list of files for deletion | |
454 (defun wdired-flag-for-deletion (filenames-ori) | |
455 (save-excursion | |
456 (goto-char (point-min)) | |
457 (while (not (eobp)) | |
458 (if (member (dired-get-filename nil t) filenames-ori) | |
459 (dired-flag-file-deletion 1) | |
460 (forward-line))))) | |
461 | |
462 (defun wdired-customize () | |
61473 | 463 "Customize WDired options." |
55098 | 464 (interactive) |
465 (customize-apropos "wdired" 'groups)) | |
466 | |
467 (defun wdired-revert (&optional arg noconfirm) | |
61473 | 468 "Discard changes in the buffer and update it based on changes on disk. |
469 Optional arguments are ignored." | |
55098 | 470 (wdired-change-to-dired-mode) |
471 (revert-buffer) | |
472 (wdired-change-to-wdired-mode)) | |
473 | |
474 (defun wdired-check-kill-buffer () | |
55109
043dd9a4d1b4
(wdired-mode-map): Move init into declaration. Fix `return' binding.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55107
diff
changeset
|
475 ;; FIXME: Can't we use the normal mechanism for that? --Stef |
55098 | 476 (if (and |
477 (buffer-modified-p) | |
478 (not (y-or-n-p "Buffer changed. Discard changes and kill buffer? "))) | |
479 (error nil))) | |
480 | |
481 (defun wdired-next-line (arg) | |
482 "Move down lines then position at filename or the current column. | |
61473 | 483 See `wdired-use-dired-vertical-movement'. Optional prefix ARG |
55098 | 484 says how many lines to move; default is one line." |
485 (interactive "p") | |
486 (next-line arg) | |
61473 | 487 (if (or (eq wdired-use-dired-vertical-movement t) |
488 (and wdired-use-dired-vertical-movement | |
55098 | 489 (< (current-column) |
490 (save-excursion (dired-move-to-filename) | |
491 (current-column))))) | |
492 (dired-move-to-filename))) | |
493 | |
494 (defun wdired-previous-line (arg) | |
495 "Move up lines then position at filename or the current column. | |
61473 | 496 See `wdired-use-dired-vertical-movement'. Optional prefix ARG |
55098 | 497 says how many lines to move; default is one line." |
498 (interactive "p") | |
499 (previous-line arg) | |
61473 | 500 (if (or (eq wdired-use-dired-vertical-movement t) |
501 (and wdired-use-dired-vertical-movement | |
55098 | 502 (< (current-column) |
503 (save-excursion (dired-move-to-filename) | |
504 (current-column))))) | |
505 (dired-move-to-filename))) | |
506 | |
507 ;; Put the needed properties to allow the user to change links' targets | |
508 (defun wdired-preprocess-symlinks () | |
509 (let ((inhibit-read-only t)) | |
510 (save-excursion | |
511 (goto-char (point-min)) | |
512 (while (not (eobp)) | |
513 (if (looking-at dired-re-sym) | |
514 (progn | |
515 (re-search-forward " -> \\(.*\\)$") | |
516 (put-text-property (- (match-beginning 1) 2) | |
517 (1- (match-beginning 1)) 'old-link | |
518 (match-string-no-properties 1)) | |
519 (put-text-property (match-end 1) (1+ (match-end 1)) 'end-link t) | |
74528
6be933449565
(wdired-preprocess-symlinks): Make the spaces after symlink arrows
Chong Yidong <cyd@stupidchicken.com>
parents:
74526
diff
changeset
|
520 (put-text-property (1- (match-beginning 1)) |
6be933449565
(wdired-preprocess-symlinks): Make the spaces after symlink arrows
Chong Yidong <cyd@stupidchicken.com>
parents:
74526
diff
changeset
|
521 (match-beginning 1) |
6be933449565
(wdired-preprocess-symlinks): Make the spaces after symlink arrows
Chong Yidong <cyd@stupidchicken.com>
parents:
74526
diff
changeset
|
522 'rear-nonsticky '(read-only)) |
6be933449565
(wdired-preprocess-symlinks): Make the spaces after symlink arrows
Chong Yidong <cyd@stupidchicken.com>
parents:
74526
diff
changeset
|
523 (put-text-property (match-beginning 1) |
55098 | 524 (match-end 1) 'read-only nil))) |
525 (forward-line) | |
526 (beginning-of-line))))) | |
527 | |
528 | |
529 (defun wdired-get-previous-link (&optional old move) | |
530 "Return the next symlink target. | |
531 If OLD, return the old target. If MOVE, move point before it." | |
74526
1a43c99020cb
(wdired-change-to-wdired-mode, wdired-finish-edit)
Chong Yidong <cyd@stupidchicken.com>
parents:
72160
diff
changeset
|
532 (let (beg end target) |
1a43c99020cb
(wdired-change-to-wdired-mode, wdired-finish-edit)
Chong Yidong <cyd@stupidchicken.com>
parents:
72160
diff
changeset
|
533 (setq beg (previous-single-property-change (point) 'old-link nil)) |
1a43c99020cb
(wdired-change-to-wdired-mode, wdired-finish-edit)
Chong Yidong <cyd@stupidchicken.com>
parents:
72160
diff
changeset
|
534 (if beg |
1a43c99020cb
(wdired-change-to-wdired-mode, wdired-finish-edit)
Chong Yidong <cyd@stupidchicken.com>
parents:
72160
diff
changeset
|
535 (progn |
1a43c99020cb
(wdired-change-to-wdired-mode, wdired-finish-edit)
Chong Yidong <cyd@stupidchicken.com>
parents:
72160
diff
changeset
|
536 (if old |
1a43c99020cb
(wdired-change-to-wdired-mode, wdired-finish-edit)
Chong Yidong <cyd@stupidchicken.com>
parents:
72160
diff
changeset
|
537 (setq target (get-text-property (1- beg) 'old-link)) |
1a43c99020cb
(wdired-change-to-wdired-mode, wdired-finish-edit)
Chong Yidong <cyd@stupidchicken.com>
parents:
72160
diff
changeset
|
538 (setq end (next-single-property-change beg 'end-link)) |
1a43c99020cb
(wdired-change-to-wdired-mode, wdired-finish-edit)
Chong Yidong <cyd@stupidchicken.com>
parents:
72160
diff
changeset
|
539 (setq target (buffer-substring-no-properties (1+ beg) end))) |
1a43c99020cb
(wdired-change-to-wdired-mode, wdired-finish-edit)
Chong Yidong <cyd@stupidchicken.com>
parents:
72160
diff
changeset
|
540 (if move (goto-char (1- beg))))) |
1a43c99020cb
(wdired-change-to-wdired-mode, wdired-finish-edit)
Chong Yidong <cyd@stupidchicken.com>
parents:
72160
diff
changeset
|
541 (and target (wdired-normalize-filename target)))) |
1a43c99020cb
(wdired-change-to-wdired-mode, wdired-finish-edit)
Chong Yidong <cyd@stupidchicken.com>
parents:
72160
diff
changeset
|
542 |
55098 | 543 |
544 ;; Perform the changes in the target of the changed links. | |
68680
bdaa27dd39d3
(wdired-mode-map): Use remap.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68671
diff
changeset
|
545 (defun wdired-do-symlink-changes () |
55098 | 546 (let ((changes nil) |
547 (errors 0) | |
548 link-to-ori link-to-new link-from) | |
549 (goto-char (point-max)) | |
550 (while (setq link-to-new (wdired-get-previous-link)) | |
551 (setq link-to-ori (wdired-get-previous-link t t)) | |
552 (setq link-from (wdired-get-filename nil t)) | |
68680
bdaa27dd39d3
(wdired-mode-map): Use remap.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68671
diff
changeset
|
553 (unless (equal link-to-new link-to-ori) |
bdaa27dd39d3
(wdired-mode-map): Use remap.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68671
diff
changeset
|
554 (setq changes t) |
bdaa27dd39d3
(wdired-mode-map): Use remap.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68671
diff
changeset
|
555 (if (equal link-to-new "") ;empty filename! |
bdaa27dd39d3
(wdired-mode-map): Use remap.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68671
diff
changeset
|
556 (setq link-to-new "/dev/null")) |
bdaa27dd39d3
(wdired-mode-map): Use remap.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68671
diff
changeset
|
557 (condition-case err |
bdaa27dd39d3
(wdired-mode-map): Use remap.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68671
diff
changeset
|
558 (progn |
bdaa27dd39d3
(wdired-mode-map): Use remap.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68671
diff
changeset
|
559 (delete-file link-from) |
bdaa27dd39d3
(wdired-mode-map): Use remap.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68671
diff
changeset
|
560 (make-symbolic-link |
bdaa27dd39d3
(wdired-mode-map): Use remap.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68671
diff
changeset
|
561 (substitute-in-file-name link-to-new) link-from)) |
bdaa27dd39d3
(wdired-mode-map): Use remap.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68671
diff
changeset
|
562 (error |
bdaa27dd39d3
(wdired-mode-map): Use remap.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68671
diff
changeset
|
563 (setq errors (1+ errors)) |
bdaa27dd39d3
(wdired-mode-map): Use remap.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68671
diff
changeset
|
564 (dired-log (concat "Link `" link-from "' to `" |
bdaa27dd39d3
(wdired-mode-map): Use remap.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68671
diff
changeset
|
565 link-to-new "' failed:\n%s\n") |
bdaa27dd39d3
(wdired-mode-map): Use remap.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68671
diff
changeset
|
566 err))))) |
55098 | 567 (cons changes errors))) |
568 | |
569 ;; Perform a "case command" skipping read-only words. | |
570 (defun wdired-xcase-word (command arg) | |
571 (if (< arg 0) | |
572 (funcall command arg) | |
68680
bdaa27dd39d3
(wdired-mode-map): Use remap.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68671
diff
changeset
|
573 (while (> arg 0) |
bdaa27dd39d3
(wdired-mode-map): Use remap.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68671
diff
changeset
|
574 (condition-case err |
bdaa27dd39d3
(wdired-mode-map): Use remap.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68671
diff
changeset
|
575 (progn |
bdaa27dd39d3
(wdired-mode-map): Use remap.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68671
diff
changeset
|
576 (funcall command 1) |
bdaa27dd39d3
(wdired-mode-map): Use remap.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68671
diff
changeset
|
577 (setq arg (1- arg))) |
bdaa27dd39d3
(wdired-mode-map): Use remap.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68671
diff
changeset
|
578 (error |
75159
21d0aec573ef
(wdired-xcase-word): Skip non-word read-only characters.
Martin Rudalics <rudalics@gmx.at>
parents:
74528
diff
changeset
|
579 (if (forward-word) |
21d0aec573ef
(wdired-xcase-word): Skip non-word read-only characters.
Martin Rudalics <rudalics@gmx.at>
parents:
74528
diff
changeset
|
580 ;; Skip any non-word characters to avoid triggering a read-only |
21d0aec573ef
(wdired-xcase-word): Skip non-word read-only characters.
Martin Rudalics <rudalics@gmx.at>
parents:
74528
diff
changeset
|
581 ;; error which would cause skipping the next word characters too. |
21d0aec573ef
(wdired-xcase-word): Skip non-word read-only characters.
Martin Rudalics <rudalics@gmx.at>
parents:
74528
diff
changeset
|
582 (skip-syntax-forward "^w") |
21d0aec573ef
(wdired-xcase-word): Skip non-word read-only characters.
Martin Rudalics <rudalics@gmx.at>
parents:
74528
diff
changeset
|
583 (setq arg 0))))))) |
55098 | 584 |
585 (defun wdired-downcase-word (arg) | |
61473 | 586 "WDired version of `downcase-word'. |
55098 | 587 Like original function but it skips read-only words." |
588 (interactive "p") | |
589 (wdired-xcase-word 'downcase-word arg)) | |
590 | |
591 (defun wdired-upcase-word (arg) | |
61473 | 592 "WDired version of `upcase-word'. |
55098 | 593 Like original function but it skips read-only words." |
594 (interactive "p") | |
595 (wdired-xcase-word 'upcase-word arg)) | |
596 | |
597 (defun wdired-capitalize-word (arg) | |
61473 | 598 "WDired version of `capitalize-word'. |
55098 | 599 Like original function but it skips read-only words." |
600 (interactive "p") | |
601 (wdired-xcase-word 'capitalize-word arg)) | |
602 | |
603 | |
604 ;; The following code deals with changing the access bits (or | |
605 ;; permissions) of the files. | |
606 | |
68680
bdaa27dd39d3
(wdired-mode-map): Use remap.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68671
diff
changeset
|
607 (defvar wdired-perm-mode-map |
bdaa27dd39d3
(wdired-mode-map): Use remap.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68671
diff
changeset
|
608 (let ((map (make-sparse-keymap))) |
bdaa27dd39d3
(wdired-mode-map): Use remap.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68671
diff
changeset
|
609 (define-key map " " 'wdired-toggle-bit) |
bdaa27dd39d3
(wdired-mode-map): Use remap.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68671
diff
changeset
|
610 (define-key map "r" 'wdired-set-bit) |
bdaa27dd39d3
(wdired-mode-map): Use remap.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68671
diff
changeset
|
611 (define-key map "w" 'wdired-set-bit) |
bdaa27dd39d3
(wdired-mode-map): Use remap.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68671
diff
changeset
|
612 (define-key map "x" 'wdired-set-bit) |
bdaa27dd39d3
(wdired-mode-map): Use remap.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68671
diff
changeset
|
613 (define-key map "-" 'wdired-set-bit) |
bdaa27dd39d3
(wdired-mode-map): Use remap.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68671
diff
changeset
|
614 (define-key map "S" 'wdired-set-bit) |
bdaa27dd39d3
(wdired-mode-map): Use remap.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68671
diff
changeset
|
615 (define-key map "s" 'wdired-set-bit) |
bdaa27dd39d3
(wdired-mode-map): Use remap.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68671
diff
changeset
|
616 (define-key map "T" 'wdired-set-bit) |
bdaa27dd39d3
(wdired-mode-map): Use remap.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68671
diff
changeset
|
617 (define-key map "t" 'wdired-set-bit) |
bdaa27dd39d3
(wdired-mode-map): Use remap.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68671
diff
changeset
|
618 (define-key map "s" 'wdired-set-bit) |
bdaa27dd39d3
(wdired-mode-map): Use remap.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68671
diff
changeset
|
619 (define-key map "l" 'wdired-set-bit) |
bdaa27dd39d3
(wdired-mode-map): Use remap.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68671
diff
changeset
|
620 (define-key map [down-mouse-1] 'wdired-mouse-toggle-bit) |
bdaa27dd39d3
(wdired-mode-map): Use remap.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68671
diff
changeset
|
621 map)) |
55098 | 622 |
74526
1a43c99020cb
(wdired-change-to-wdired-mode, wdired-finish-edit)
Chong Yidong <cyd@stupidchicken.com>
parents:
72160
diff
changeset
|
623 ;; Put a keymap property to the permission bits of the files, and store the |
55098 | 624 ;; original name and permissions as a property |
68680
bdaa27dd39d3
(wdired-mode-map): Use remap.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68671
diff
changeset
|
625 (defun wdired-preprocess-perms () |
74526
1a43c99020cb
(wdired-change-to-wdired-mode, wdired-finish-edit)
Chong Yidong <cyd@stupidchicken.com>
parents:
72160
diff
changeset
|
626 (let ((inhibit-read-only t)) |
55098 | 627 (set (make-local-variable 'wdired-col-perm) nil) |
628 (save-excursion | |
629 (goto-char (point-min)) | |
630 (while (not (eobp)) | |
74526
1a43c99020cb
(wdired-change-to-wdired-mode, wdired-finish-edit)
Chong Yidong <cyd@stupidchicken.com>
parents:
72160
diff
changeset
|
631 (when (and (not (looking-at dired-re-sym)) |
1a43c99020cb
(wdired-change-to-wdired-mode, wdired-finish-edit)
Chong Yidong <cyd@stupidchicken.com>
parents:
72160
diff
changeset
|
632 (wdired-get-filename) |
1a43c99020cb
(wdired-change-to-wdired-mode, wdired-finish-edit)
Chong Yidong <cyd@stupidchicken.com>
parents:
72160
diff
changeset
|
633 (re-search-forward dired-re-perms (line-end-position) 'eol)) |
1a43c99020cb
(wdired-change-to-wdired-mode, wdired-finish-edit)
Chong Yidong <cyd@stupidchicken.com>
parents:
72160
diff
changeset
|
634 (let ((begin (match-beginning 0)) |
1a43c99020cb
(wdired-change-to-wdired-mode, wdired-finish-edit)
Chong Yidong <cyd@stupidchicken.com>
parents:
72160
diff
changeset
|
635 (end (match-end 0))) |
1a43c99020cb
(wdired-change-to-wdired-mode, wdired-finish-edit)
Chong Yidong <cyd@stupidchicken.com>
parents:
72160
diff
changeset
|
636 (unless wdired-col-perm |
1a43c99020cb
(wdired-change-to-wdired-mode, wdired-finish-edit)
Chong Yidong <cyd@stupidchicken.com>
parents:
72160
diff
changeset
|
637 (setq wdired-col-perm (- (current-column) 9))) |
1a43c99020cb
(wdired-change-to-wdired-mode, wdired-finish-edit)
Chong Yidong <cyd@stupidchicken.com>
parents:
72160
diff
changeset
|
638 (if (eq wdired-allow-to-change-permissions 'advanced) |
1a43c99020cb
(wdired-change-to-wdired-mode, wdired-finish-edit)
Chong Yidong <cyd@stupidchicken.com>
parents:
72160
diff
changeset
|
639 (progn |
1a43c99020cb
(wdired-change-to-wdired-mode, wdired-finish-edit)
Chong Yidong <cyd@stupidchicken.com>
parents:
72160
diff
changeset
|
640 (put-text-property begin end 'read-only nil) |
1a43c99020cb
(wdired-change-to-wdired-mode, wdired-finish-edit)
Chong Yidong <cyd@stupidchicken.com>
parents:
72160
diff
changeset
|
641 ;; make first permission bit writable |
1a43c99020cb
(wdired-change-to-wdired-mode, wdired-finish-edit)
Chong Yidong <cyd@stupidchicken.com>
parents:
72160
diff
changeset
|
642 (put-text-property |
1a43c99020cb
(wdired-change-to-wdired-mode, wdired-finish-edit)
Chong Yidong <cyd@stupidchicken.com>
parents:
72160
diff
changeset
|
643 (1- begin) begin 'rear-nonsticky '(read-only))) |
1a43c99020cb
(wdired-change-to-wdired-mode, wdired-finish-edit)
Chong Yidong <cyd@stupidchicken.com>
parents:
72160
diff
changeset
|
644 ;; avoid that keymap applies to text following permissions |
1a43c99020cb
(wdired-change-to-wdired-mode, wdired-finish-edit)
Chong Yidong <cyd@stupidchicken.com>
parents:
72160
diff
changeset
|
645 (add-text-properties |
1a43c99020cb
(wdired-change-to-wdired-mode, wdired-finish-edit)
Chong Yidong <cyd@stupidchicken.com>
parents:
72160
diff
changeset
|
646 (1+ begin) end |
1a43c99020cb
(wdired-change-to-wdired-mode, wdired-finish-edit)
Chong Yidong <cyd@stupidchicken.com>
parents:
72160
diff
changeset
|
647 `(keymap ,wdired-perm-mode-map rear-nonsticky (keymap)))) |
1a43c99020cb
(wdired-change-to-wdired-mode, wdired-finish-edit)
Chong Yidong <cyd@stupidchicken.com>
parents:
72160
diff
changeset
|
648 (put-text-property end (1+ end) 'end-perm t) |
1a43c99020cb
(wdired-change-to-wdired-mode, wdired-finish-edit)
Chong Yidong <cyd@stupidchicken.com>
parents:
72160
diff
changeset
|
649 (put-text-property |
1a43c99020cb
(wdired-change-to-wdired-mode, wdired-finish-edit)
Chong Yidong <cyd@stupidchicken.com>
parents:
72160
diff
changeset
|
650 begin (1+ begin) 'old-perm (match-string-no-properties 0)))) |
55098 | 651 (forward-line) |
652 (beginning-of-line))))) | |
653 | |
654 (defun wdired-perm-allowed-in-pos (char pos) | |
655 (cond | |
656 ((= char ?-) t) | |
657 ((= char ?r) (= (% pos 3) 0)) | |
658 ((= char ?w) (= (% pos 3) 1)) | |
659 ((= char ?x) (= (% pos 3) 2)) | |
660 ((memq char '(?s ?S)) (memq pos '(2 5))) | |
661 ((memq char '(?t ?T)) (= pos 8)) | |
662 ((= char ?l) (= pos 5)))) | |
663 | |
664 (defun wdired-set-bit () | |
665 "Set a permission bit character." | |
666 (interactive) | |
667 (if (wdired-perm-allowed-in-pos last-command-char | |
668 (- (current-column) wdired-col-perm)) | |
669 (let ((new-bit (char-to-string last-command-char)) | |
670 (inhibit-read-only t) | |
671 (pos-prop (- (point) (- (current-column) wdired-col-perm)))) | |
68680
bdaa27dd39d3
(wdired-mode-map): Use remap.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68671
diff
changeset
|
672 (put-text-property 0 1 'keymap wdired-perm-mode-map new-bit) |
55098 | 673 (put-text-property 0 1 'read-only t new-bit) |
674 (insert new-bit) | |
675 (delete-char 1) | |
74526
1a43c99020cb
(wdired-change-to-wdired-mode, wdired-finish-edit)
Chong Yidong <cyd@stupidchicken.com>
parents:
72160
diff
changeset
|
676 (put-text-property (1- pos-prop) pos-prop 'perm-changed t) |
1a43c99020cb
(wdired-change-to-wdired-mode, wdired-finish-edit)
Chong Yidong <cyd@stupidchicken.com>
parents:
72160
diff
changeset
|
677 (put-text-property (1- (point)) (point) 'rear-nonsticky '(keymap))) |
55098 | 678 (forward-char 1))) |
679 | |
68680
bdaa27dd39d3
(wdired-mode-map): Use remap.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68671
diff
changeset
|
680 (defun wdired-toggle-bit () |
55098 | 681 "Toggle the permission bit at point." |
682 (interactive) | |
683 (let ((inhibit-read-only t) | |
74526
1a43c99020cb
(wdired-change-to-wdired-mode, wdired-finish-edit)
Chong Yidong <cyd@stupidchicken.com>
parents:
72160
diff
changeset
|
684 (new-bit "-") |
55098 | 685 (pos-prop (- (point) (- (current-column) wdired-col-perm)))) |
74526
1a43c99020cb
(wdired-change-to-wdired-mode, wdired-finish-edit)
Chong Yidong <cyd@stupidchicken.com>
parents:
72160
diff
changeset
|
686 (if (eq (char-after (point)) ?-) |
1a43c99020cb
(wdired-change-to-wdired-mode, wdired-finish-edit)
Chong Yidong <cyd@stupidchicken.com>
parents:
72160
diff
changeset
|
687 (setq new-bit |
1a43c99020cb
(wdired-change-to-wdired-mode, wdired-finish-edit)
Chong Yidong <cyd@stupidchicken.com>
parents:
72160
diff
changeset
|
688 (if (= (% (- (current-column) wdired-col-perm) 3) 0) "r" |
1a43c99020cb
(wdired-change-to-wdired-mode, wdired-finish-edit)
Chong Yidong <cyd@stupidchicken.com>
parents:
72160
diff
changeset
|
689 (if (= (% (- (current-column) wdired-col-perm) 3) 1) "w" |
1a43c99020cb
(wdired-change-to-wdired-mode, wdired-finish-edit)
Chong Yidong <cyd@stupidchicken.com>
parents:
72160
diff
changeset
|
690 "x")))) |
68680
bdaa27dd39d3
(wdired-mode-map): Use remap.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68671
diff
changeset
|
691 (put-text-property 0 1 'keymap wdired-perm-mode-map new-bit) |
55098 | 692 (put-text-property 0 1 'read-only t new-bit) |
693 (insert new-bit) | |
694 (delete-char 1) | |
74526
1a43c99020cb
(wdired-change-to-wdired-mode, wdired-finish-edit)
Chong Yidong <cyd@stupidchicken.com>
parents:
72160
diff
changeset
|
695 (put-text-property (1- pos-prop) pos-prop 'perm-changed t) |
1a43c99020cb
(wdired-change-to-wdired-mode, wdired-finish-edit)
Chong Yidong <cyd@stupidchicken.com>
parents:
72160
diff
changeset
|
696 (put-text-property (1- (point)) (point) 'rear-nonsticky '(keymap)))) |
55098 | 697 |
698 (defun wdired-mouse-toggle-bit (event) | |
699 "Toggle the permission bit that was left clicked." | |
700 (interactive "e") | |
701 (mouse-set-point event) | |
702 (wdired-toggle-bit)) | |
703 | |
704 ;; Allowed chars for 4000 bit are Ss in position 3 | |
705 ;; Allowed chars for 2000 bit are Ssl in position 6 | |
706 ;; Allowed chars for 1000 bit are Tt in position 9 | |
707 (defun wdired-perms-to-number (perms) | |
74526
1a43c99020cb
(wdired-change-to-wdired-mode, wdired-finish-edit)
Chong Yidong <cyd@stupidchicken.com>
parents:
72160
diff
changeset
|
708 (let ((nperm 0777)) |
1a43c99020cb
(wdired-change-to-wdired-mode, wdired-finish-edit)
Chong Yidong <cyd@stupidchicken.com>
parents:
72160
diff
changeset
|
709 (if (= (elt perms 1) ?-) (setq nperm (- nperm 400))) |
1a43c99020cb
(wdired-change-to-wdired-mode, wdired-finish-edit)
Chong Yidong <cyd@stupidchicken.com>
parents:
72160
diff
changeset
|
710 (if (= (elt perms 2) ?-) (setq nperm (- nperm 200))) |
1a43c99020cb
(wdired-change-to-wdired-mode, wdired-finish-edit)
Chong Yidong <cyd@stupidchicken.com>
parents:
72160
diff
changeset
|
711 (let ((p-bit (elt perms 3))) |
1a43c99020cb
(wdired-change-to-wdired-mode, wdired-finish-edit)
Chong Yidong <cyd@stupidchicken.com>
parents:
72160
diff
changeset
|
712 (if (memq p-bit '(?- ?S)) (setq nperm (- nperm 100))) |
1a43c99020cb
(wdired-change-to-wdired-mode, wdired-finish-edit)
Chong Yidong <cyd@stupidchicken.com>
parents:
72160
diff
changeset
|
713 (if (memq p-bit '(?s ?S)) (setq nperm (+ nperm 4000)))) |
1a43c99020cb
(wdired-change-to-wdired-mode, wdired-finish-edit)
Chong Yidong <cyd@stupidchicken.com>
parents:
72160
diff
changeset
|
714 (if (= (elt perms 4) ?-) (setq nperm (- nperm 40))) |
1a43c99020cb
(wdired-change-to-wdired-mode, wdired-finish-edit)
Chong Yidong <cyd@stupidchicken.com>
parents:
72160
diff
changeset
|
715 (if (= (elt perms 5) ?-) (setq nperm (- nperm 20))) |
1a43c99020cb
(wdired-change-to-wdired-mode, wdired-finish-edit)
Chong Yidong <cyd@stupidchicken.com>
parents:
72160
diff
changeset
|
716 (let ((p-bit (elt perms 6))) |
1a43c99020cb
(wdired-change-to-wdired-mode, wdired-finish-edit)
Chong Yidong <cyd@stupidchicken.com>
parents:
72160
diff
changeset
|
717 (if (memq p-bit '(?- ?S ?l)) (setq nperm (- nperm 10))) |
1a43c99020cb
(wdired-change-to-wdired-mode, wdired-finish-edit)
Chong Yidong <cyd@stupidchicken.com>
parents:
72160
diff
changeset
|
718 (if (memq p-bit '(?s ?S ?l)) (setq nperm (+ nperm 2000)))) |
1a43c99020cb
(wdired-change-to-wdired-mode, wdired-finish-edit)
Chong Yidong <cyd@stupidchicken.com>
parents:
72160
diff
changeset
|
719 (if (= (elt perms 7) ?-) (setq nperm (- nperm 4))) |
1a43c99020cb
(wdired-change-to-wdired-mode, wdired-finish-edit)
Chong Yidong <cyd@stupidchicken.com>
parents:
72160
diff
changeset
|
720 (if (= (elt perms 8) ?-) (setq nperm (- nperm 2))) |
1a43c99020cb
(wdired-change-to-wdired-mode, wdired-finish-edit)
Chong Yidong <cyd@stupidchicken.com>
parents:
72160
diff
changeset
|
721 (let ((p-bit (elt perms 9))) |
1a43c99020cb
(wdired-change-to-wdired-mode, wdired-finish-edit)
Chong Yidong <cyd@stupidchicken.com>
parents:
72160
diff
changeset
|
722 (if (memq p-bit '(?- ?T)) (setq nperm (- nperm 1))) |
1a43c99020cb
(wdired-change-to-wdired-mode, wdired-finish-edit)
Chong Yidong <cyd@stupidchicken.com>
parents:
72160
diff
changeset
|
723 (if (memq p-bit '(?t ?T)) (setq nperm (+ nperm 1000)))) |
1a43c99020cb
(wdired-change-to-wdired-mode, wdired-finish-edit)
Chong Yidong <cyd@stupidchicken.com>
parents:
72160
diff
changeset
|
724 nperm)) |
55098 | 725 |
726 ;; Perform the changes in the permissions of the files that have | |
727 ;; changed. | |
728 (defun wdired-do-perm-changes () | |
729 (let ((changes nil) | |
730 (errors 0) | |
731 (prop-wanted (if (eq wdired-allow-to-change-permissions 'advanced) | |
732 'old-perm 'perm-changed)) | |
733 filename perms-ori perms-new perm-tmp) | |
734 (goto-char (next-single-property-change (point-min) prop-wanted | |
735 nil (point-max))) | |
736 (while (not (eobp)) | |
737 (setq perms-ori (get-text-property (point) 'old-perm)) | |
738 (setq perms-new (buffer-substring-no-properties | |
739 (point) (next-single-property-change (point) 'end-perm))) | |
68680
bdaa27dd39d3
(wdired-mode-map): Use remap.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68671
diff
changeset
|
740 (unless (equal perms-ori perms-new) |
bdaa27dd39d3
(wdired-mode-map): Use remap.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68671
diff
changeset
|
741 (setq changes t) |
bdaa27dd39d3
(wdired-mode-map): Use remap.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68671
diff
changeset
|
742 (setq filename (wdired-get-filename nil t)) |
bdaa27dd39d3
(wdired-mode-map): Use remap.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68671
diff
changeset
|
743 (if (= (length perms-new) 10) |
bdaa27dd39d3
(wdired-mode-map): Use remap.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68671
diff
changeset
|
744 (progn |
bdaa27dd39d3
(wdired-mode-map): Use remap.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68671
diff
changeset
|
745 (setq perm-tmp |
bdaa27dd39d3
(wdired-mode-map): Use remap.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68671
diff
changeset
|
746 (int-to-string (wdired-perms-to-number perms-new))) |
bdaa27dd39d3
(wdired-mode-map): Use remap.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68671
diff
changeset
|
747 (unless (equal 0 (dired-call-process dired-chmod-program |
bdaa27dd39d3
(wdired-mode-map): Use remap.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68671
diff
changeset
|
748 t perm-tmp filename)) |
bdaa27dd39d3
(wdired-mode-map): Use remap.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68671
diff
changeset
|
749 (setq errors (1+ errors)) |
bdaa27dd39d3
(wdired-mode-map): Use remap.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68671
diff
changeset
|
750 (dired-log (concat dired-chmod-program " " perm-tmp |
bdaa27dd39d3
(wdired-mode-map): Use remap.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68671
diff
changeset
|
751 " `" filename "' failed\n\n")))) |
bdaa27dd39d3
(wdired-mode-map): Use remap.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68671
diff
changeset
|
752 (setq errors (1+ errors)) |
bdaa27dd39d3
(wdired-mode-map): Use remap.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68671
diff
changeset
|
753 (dired-log (concat "Cannot parse permission `" perms-new |
bdaa27dd39d3
(wdired-mode-map): Use remap.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68671
diff
changeset
|
754 "' for file `" filename "'\n\n")))) |
55098 | 755 (goto-char (next-single-property-change (1+ (point)) prop-wanted |
756 nil (point-max)))) | |
757 (cons changes errors))) | |
758 | |
759 (provide 'wdired) | |
760 | |
68680
bdaa27dd39d3
(wdired-mode-map): Use remap.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68671
diff
changeset
|
761 ;; Local Variables: |
bdaa27dd39d3
(wdired-mode-map): Use remap.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68671
diff
changeset
|
762 ;; coding: latin-1 |
bdaa27dd39d3
(wdired-mode-map): Use remap.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68671
diff
changeset
|
763 ;; byte-compile-dynamic: t |
bdaa27dd39d3
(wdired-mode-map): Use remap.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68671
diff
changeset
|
764 ;; End: |
bdaa27dd39d3
(wdired-mode-map): Use remap.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68671
diff
changeset
|
765 |
55109
043dd9a4d1b4
(wdired-mode-map): Move init into declaration. Fix `return' binding.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55107
diff
changeset
|
766 ;; arch-tag: bc00902e-526f-4305-bc7f-8862a559184f |
55098 | 767 ;;; wdired.el ends here |