Mercurial > emacs
annotate lisp/wdired.el @ 82140:b98604865ea0
Merge from emacs--rel--22
Patches applied:
* emacs--rel--22 (patch 70-73)
- Update from CVS
2007-07-25 Glenn Morris <rgm@gnu.org>
* Relicense all FSF files to GPLv3 or later.
Revision: emacs@sv.gnu.org/emacs--devo--0--patch-828
author | Miles Bader <miles@gnu.org> |
---|---|
date | Thu, 26 Jul 2007 05:28:10 +0000 |
parents | 8e5203081e80 9355f9b7bbff |
children | 06241457c4f0 |
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 | |
78236
9355f9b7bbff
Switch license to GPLv3 or later.
Glenn Morris <rgm@gnu.org>
parents:
75347
diff
changeset
|
14 ;; published by the Free Software Foundation; either version 3, or (at |
55098 | 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") |
55098 | 109 |
110 (defgroup wdired nil | |
111 "Mode to rename files by editing their names in dired buffers." | |
112 :group 'dired) | |
113 | |
114 (defcustom wdired-use-interactive-rename nil | |
68680
bdaa27dd39d3
(wdired-mode-map): Use remap.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68671
diff
changeset
|
115 "If non-nil, WDired requires confirmation before actually renaming files. |
61473 | 116 If nil, WDired doesn't require confirmation to change the file names, |
117 and the variable `wdired-confirm-overwrite' controls whether it is ok | |
118 to overwrite files without asking." | |
55098 | 119 :type 'boolean |
120 :group 'wdired) | |
121 | |
61473 | 122 (defcustom wdired-confirm-overwrite t |
68680
bdaa27dd39d3
(wdired-mode-map): Use remap.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68671
diff
changeset
|
123 "If nil the renames can overwrite files without asking. |
61473 | 124 This variable has no effect at all if `wdired-use-interactive-rename' |
125 is not nil." | |
55098 | 126 :type 'boolean |
127 :group 'wdired) | |
128 | |
61473 | 129 (defcustom wdired-use-dired-vertical-movement nil |
68680
bdaa27dd39d3
(wdired-mode-map): Use remap.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68671
diff
changeset
|
130 "If t, the \"up\" and \"down\" movement works as in Dired mode. |
55098 | 131 That is, always move the point to the beginning of the filename at line. |
132 | |
133 If `sometimes, only move to the beginning of filename if the point is | |
134 before it, and `track-eol' is honored. This behavior is very handy | |
135 when editing several filenames. | |
136 | |
137 If nil, \"up\" and \"down\" movement is done as in any other buffer." | |
138 :type '(choice (const :tag "As in any other mode" nil) | |
139 (const :tag "Smart cursor placement" sometimes) | |
140 (other :tag "As in dired mode" t)) | |
141 :group 'wdired) | |
142 | |
143 (defcustom wdired-allow-to-redirect-links t | |
68680
bdaa27dd39d3
(wdired-mode-map): Use remap.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68671
diff
changeset
|
144 "If non-nil, the target of the symbolic links are editable. |
55098 | 145 In systems without symbolic links support, this variable has no effect |
146 at all." | |
147 :type 'boolean | |
148 :group 'wdired) | |
149 | |
150 (defcustom wdired-allow-to-change-permissions nil | |
68680
bdaa27dd39d3
(wdired-mode-map): Use remap.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68671
diff
changeset
|
151 "If non-nil, the permissions bits of the files are editable. |
55098 | 152 |
153 If t, to change a single bit, put the cursor over it and press the | |
154 space bar, or left click over it. You can also hit the letter you want | |
155 to set: if this value is allowed, the character in the buffer will be | |
156 changed. Anyway, the point is advanced one position, so, for example, | |
61473 | 157 you can keep the <x> key pressed to give execution permissions to |
55098 | 158 everybody to that file. |
159 | |
160 If `advanced, the bits are freely editable. You can use | |
161 `string-rectangle', `query-replace', etc. You can put any value (even | |
162 newlines), but if you want your changes to be useful, you better put a | |
163 intelligible value. | |
164 | |
61473 | 165 Anyway, the real change of the permissions is done by the external |
55098 | 166 program `dired-chmod-program', which must exist." |
167 :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
|
168 (const :tag "Toggle/set bits" t) |
55098 | 169 (other :tag "Bits freely editable" advanced)) |
170 :group 'wdired) | |
171 | |
55109
043dd9a4d1b4
(wdired-mode-map): Move init into declaration. Fix `return' binding.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55107
diff
changeset
|
172 (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
|
173 (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
|
174 (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
|
175 (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
|
176 (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
|
177 (define-key map "\C-c\C-[" 'wdired-abort-changes) |
61473 | 178 (define-key map "\C-m" 'ignore) |
179 (define-key map "\C-j" 'ignore) | |
180 (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
|
181 (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
|
182 (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
|
183 (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
|
184 (define-key map "\C-n" 'wdired-next-line) |
55098 | 185 |
55109
043dd9a4d1b4
(wdired-mode-map): Move init into declaration. Fix `return' binding.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55107
diff
changeset
|
186 (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
|
187 (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
|
188 (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
|
189 '("Options" . wdired-customize)) |
043dd9a4d1b4
(wdired-mode-map): Move init into declaration. Fix `return' binding.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55107
diff
changeset
|
190 (define-key map [menu-bar wdired dashes] |
55098 | 191 '("--")) |
55109
043dd9a4d1b4
(wdired-mode-map): Move init into declaration. Fix `return' binding.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55107
diff
changeset
|
192 (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
|
193 '(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
|
194 :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
|
195 (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
|
196 '("Commit Changes" . wdired-finish-edit)) |
68680
bdaa27dd39d3
(wdired-mode-map): Use remap.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68671
diff
changeset
|
197 |
bdaa27dd39d3
(wdired-mode-map): Use remap.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68671
diff
changeset
|
198 (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
|
199 (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
|
200 (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
|
201 |
55109
043dd9a4d1b4
(wdired-mode-map): Move init into declaration. Fix `return' binding.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55107
diff
changeset
|
202 map)) |
55098 | 203 |
55109
043dd9a4d1b4
(wdired-mode-map): Move init into declaration. Fix `return' binding.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55107
diff
changeset
|
204 (defvar wdired-mode-hook nil |
61473 | 205 "Hooks run when changing to WDired mode.") |
55098 | 206 |
207 ;; Local variables (put here to avoid compilation gripes) | |
208 (defvar wdired-col-perm) ;; Column where the permission bits start | |
209 (defvar wdired-old-content) | |
67561
827930ad591b
(wdired-old-point): New internal variable.
Juri Linkov <juri@jurta.org>
parents:
65582
diff
changeset
|
210 (defvar wdired-old-point) |
55098 | 211 |
212 | |
213 (defun wdired-mode () | |
214 "\\<wdired-mode-map>File Names Editing mode. | |
215 | |
61473 | 216 Press \\[wdired-finish-edit] to make the changes to take effect |
217 and exit. To abort the edit, use \\[wdired-abort-changes]. | |
55098 | 218 |
61473 | 219 In this mode you can edit the names of the files, the target of |
220 the links and the permission bits of the files. You can use | |
221 \\[customize-group] RET wdired to customize WDired behavior. | |
55098 | 222 |
61473 | 223 The only editable texts in a WDired buffer are filenames, |
224 symbolic link targets, and filenames permission." | |
55098 | 225 (interactive) |
226 (error "This mode can be enabled only by `wdired-change-to-wdired-mode'")) | |
227 (put 'wdired-mode 'mode-class 'special) | |
228 | |
229 | |
230 ;;;###autoload | |
231 (defun wdired-change-to-wdired-mode () | |
232 "Put a dired buffer in a mode in which filenames are editable. | |
61473 | 233 \\<wdired-mode-map> |
234 This mode allows the user to change the names of the files, and after | |
235 typing \\[wdired-finish-edit] Emacs renames the files and directories | |
236 in disk. | |
55098 | 237 |
238 See `wdired-mode'." | |
239 (interactive) | |
72160
183934d15fbb
(wdired-change-to-wdired-mode, wdired-change-to-dired-mode):
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
69279
diff
changeset
|
240 (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
|
241 (error "Not a Dired buffer")) |
55098 | 242 (set (make-local-variable 'wdired-old-content) |
243 (buffer-substring (point-min) (point-max))) | |
67561
827930ad591b
(wdired-old-point): New internal variable.
Juri Linkov <juri@jurta.org>
parents:
65582
diff
changeset
|
244 (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
|
245 (set (make-local-variable 'query-replace-skip-read-only) t) |
55098 | 246 (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
|
247 (force-mode-line-update) |
55098 | 248 (setq buffer-read-only nil) |
249 (dired-unadvertise default-directory) | |
250 (add-hook 'kill-buffer-hook 'wdired-check-kill-buffer nil t) | |
251 (setq major-mode 'wdired-mode) | |
61473 | 252 (setq mode-name "Editable Dired") |
55098 | 253 (setq revert-buffer-function 'wdired-revert) |
254 ;; I temp disable undo for performance: since I'm going to clear the | |
255 ;; undo list, it can save more than a 9% of time with big | |
256 ;; directories because setting properties modify the undo-list. | |
257 (buffer-disable-undo) | |
258 (wdired-preprocess-files) | |
259 (if wdired-allow-to-change-permissions | |
260 (wdired-preprocess-perms)) | |
261 (if (and wdired-allow-to-redirect-links (fboundp 'make-symbolic-link)) | |
262 (wdired-preprocess-symlinks)) | |
263 (buffer-enable-undo) ; Performance hack. See above. | |
264 (set-buffer-modified-p nil) | |
265 (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
|
266 (run-mode-hooks 'wdired-mode-hook) |
67561
827930ad591b
(wdired-old-point): New internal variable.
Juri Linkov <juri@jurta.org>
parents:
65582
diff
changeset
|
267 (message "%s" (substitute-command-keys |
827930ad591b
(wdired-old-point): New internal variable.
Juri Linkov <juri@jurta.org>
parents:
65582
diff
changeset
|
268 "Press \\[wdired-finish-edit] when finished \ |
61030
6b0506554db8
(wdired-change-to-wdired-mode):
Juri Linkov <juri@jurta.org>
parents:
60141
diff
changeset
|
269 or \\[wdired-abort-changes] to abort changes"))) |
55098 | 270 |
271 | |
272 ;; Protect the buffer so only the filenames can be changed, and put | |
273 ;; properties so filenames (old and new) can be easily found. | |
274 (defun wdired-preprocess-files () | |
275 (put-text-property 1 2 'front-sticky t) | |
276 (save-excursion | |
277 (goto-char (point-min)) | |
278 (let ((b-protection (point)) | |
279 filename) | |
280 (while (not (eobp)) | |
281 (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
|
282 (when (and filename |
043dd9a4d1b4
(wdired-mode-map): Move init into declaration. Fix `return' binding.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55107
diff
changeset
|
283 (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
|
284 (dired-move-to-filename) |
74526
1a43c99020cb
(wdired-change-to-wdired-mode, wdired-finish-edit)
Chong Yidong <cyd@stupidchicken.com>
parents:
72160
diff
changeset
|
285 ;; 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
|
286 ;; the filename can't be modified. |
1a43c99020cb
(wdired-change-to-wdired-mode, wdired-finish-edit)
Chong Yidong <cyd@stupidchicken.com>
parents:
72160
diff
changeset
|
287 (add-text-properties |
1a43c99020cb
(wdired-change-to-wdired-mode, wdired-finish-edit)
Chong Yidong <cyd@stupidchicken.com>
parents:
72160
diff
changeset
|
288 (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
|
289 (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
|
290 (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
|
291 (put-text-property (point) (1+ (point)) 'end-name t)) |
55098 | 292 (forward-line)) |
293 (put-text-property b-protection (point-max) 'read-only t)))) | |
294 | |
295 ;; This code is a copy of some dired-get-filename lines. | |
296 (defsubst wdired-normalize-filename (file) | |
297 (setq file | |
55109
043dd9a4d1b4
(wdired-mode-map): Move init into declaration. Fix `return' binding.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55107
diff
changeset
|
298 ;; 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
|
299 ;; doing such unquoting? --Stef |
55098 | 300 (read (concat |
55109
043dd9a4d1b4
(wdired-mode-map): Move init into declaration. Fix `return' binding.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55107
diff
changeset
|
301 "\"" (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
|
302 "\\([^\\]\\|\\`\\)\"" "\\1\\\\\"" file) |
55098 | 303 "\""))) |
304 (and file buffer-file-coding-system | |
305 (not file-name-coding-system) | |
306 (not default-file-name-coding-system) | |
307 (setq file (encode-coding-string file buffer-file-coding-system))) | |
308 file) | |
309 | |
310 (defun wdired-get-filename (&optional no-dir old) | |
311 "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
|
312 Similar to `dired-get-filename' but it doesn't rely on regexps. It |
61473 | 313 relies on WDired buffer's properties. Optional arg NO-DIR with value |
55098 | 314 non-nil means don't include directory. Optional arg OLD with value |
315 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
|
316 ;; 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
|
317 (let (beg end file) |
1a43c99020cb
(wdired-change-to-wdired-mode, wdired-finish-edit)
Chong Yidong <cyd@stupidchicken.com>
parents:
72160
diff
changeset
|
318 (save-excursion |
1a43c99020cb
(wdired-change-to-wdired-mode, wdired-finish-edit)
Chong Yidong <cyd@stupidchicken.com>
parents:
72160
diff
changeset
|
319 (setq end (line-end-position)) |
1a43c99020cb
(wdired-change-to-wdired-mode, wdired-finish-edit)
Chong Yidong <cyd@stupidchicken.com>
parents:
72160
diff
changeset
|
320 (beginning-of-line) |
1a43c99020cb
(wdired-change-to-wdired-mode, wdired-finish-edit)
Chong Yidong <cyd@stupidchicken.com>
parents:
72160
diff
changeset
|
321 (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
|
322 (unless (eq beg end) |
1a43c99020cb
(wdired-change-to-wdired-mode, wdired-finish-edit)
Chong Yidong <cyd@stupidchicken.com>
parents:
72160
diff
changeset
|
323 (if old |
1a43c99020cb
(wdired-change-to-wdired-mode, wdired-finish-edit)
Chong Yidong <cyd@stupidchicken.com>
parents:
72160
diff
changeset
|
324 (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
|
325 (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
|
326 (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
|
327 (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
|
328 (if (or no-dir old) |
1a43c99020cb
(wdired-change-to-wdired-mode, wdired-finish-edit)
Chong Yidong <cyd@stupidchicken.com>
parents:
72160
diff
changeset
|
329 file |
1a43c99020cb
(wdired-change-to-wdired-mode, wdired-finish-edit)
Chong Yidong <cyd@stupidchicken.com>
parents:
72160
diff
changeset
|
330 (and file (> (length file) 0) |
1a43c99020cb
(wdired-change-to-wdired-mode, wdired-finish-edit)
Chong Yidong <cyd@stupidchicken.com>
parents:
72160
diff
changeset
|
331 (concat (dired-current-directory) file)))))) |
55098 | 332 |
333 | |
334 (defun wdired-change-to-dired-mode () | |
335 "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
|
336 (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
|
337 (error "Not a Wdired buffer")) |
55098 | 338 (let ((inhibit-read-only t)) |
74526
1a43c99020cb
(wdired-change-to-wdired-mode, wdired-finish-edit)
Chong Yidong <cyd@stupidchicken.com>
parents:
72160
diff
changeset
|
339 (remove-text-properties |
1a43c99020cb
(wdired-change-to-wdired-mode, wdired-finish-edit)
Chong Yidong <cyd@stupidchicken.com>
parents:
72160
diff
changeset
|
340 (point-min) (point-max) |
1a43c99020cb
(wdired-change-to-wdired-mode, wdired-finish-edit)
Chong Yidong <cyd@stupidchicken.com>
parents:
72160
diff
changeset
|
341 '(front-sticky nil rear-nonsticky nil read-only nil keymap nil))) |
55098 | 342 (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
|
343 (force-mode-line-update) |
55098 | 344 (setq buffer-read-only t) |
345 (setq major-mode 'dired-mode) | |
346 (setq mode-name "Dired") | |
347 (dired-advertise) | |
348 (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
|
349 (set (make-local-variable 'revert-buffer-function) 'dired-revert)) |
55098 | 350 |
351 | |
352 (defun wdired-abort-changes () | |
353 "Abort changes and return to dired mode." | |
354 (interactive) | |
355 (let ((inhibit-read-only t)) | |
356 (erase-buffer) | |
67561
827930ad591b
(wdired-old-point): New internal variable.
Juri Linkov <juri@jurta.org>
parents:
65582
diff
changeset
|
357 (insert wdired-old-content) |
827930ad591b
(wdired-old-point): New internal variable.
Juri Linkov <juri@jurta.org>
parents:
65582
diff
changeset
|
358 (goto-char wdired-old-point)) |
55098 | 359 (wdired-change-to-dired-mode) |
360 (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
|
361 (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
|
362 (message "Changes aborted")) |
55098 | 363 |
364 (defun wdired-finish-edit () | |
365 "Actually rename files based on your editing in the Dired buffer." | |
366 (interactive) | |
367 (wdired-change-to-dired-mode) | |
61473 | 368 (let ((overwrite (or (not wdired-confirm-overwrite) 1)) |
55098 | 369 (changes nil) |
370 (files-deleted nil) | |
371 (errors 0) | |
372 file-ori file-new tmp-value) | |
373 (save-excursion | |
74526
1a43c99020cb
(wdired-change-to-wdired-mode, wdired-finish-edit)
Chong Yidong <cyd@stupidchicken.com>
parents:
72160
diff
changeset
|
374 (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
|
375 (fboundp 'make-symbolic-link)) |
1a43c99020cb
(wdired-change-to-wdired-mode, wdired-finish-edit)
Chong Yidong <cyd@stupidchicken.com>
parents:
72160
diff
changeset
|
376 (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
|
377 (setq errors (cdr tmp-value)) |
1a43c99020cb
(wdired-change-to-wdired-mode, wdired-finish-edit)
Chong Yidong <cyd@stupidchicken.com>
parents:
72160
diff
changeset
|
378 (setq changes (car tmp-value))) |
1a43c99020cb
(wdired-change-to-wdired-mode, wdired-finish-edit)
Chong Yidong <cyd@stupidchicken.com>
parents:
72160
diff
changeset
|
379 (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
|
380 (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
|
381 (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
|
382 (setq errors (+ errors (cdr tmp-value))) |
1a43c99020cb
(wdired-change-to-wdired-mode, wdired-finish-edit)
Chong Yidong <cyd@stupidchicken.com>
parents:
72160
diff
changeset
|
383 (setq changes (or changes (car tmp-value)))) |
55098 | 384 (goto-char (point-max)) |
385 (while (not (bobp)) | |
386 (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
|
387 (when file-ori |
1a43c99020cb
(wdired-change-to-wdired-mode, wdired-finish-edit)
Chong Yidong <cyd@stupidchicken.com>
parents:
72160
diff
changeset
|
388 (setq file-new (wdired-get-filename))) |
1a43c99020cb
(wdired-change-to-wdired-mode, wdired-finish-edit)
Chong Yidong <cyd@stupidchicken.com>
parents:
72160
diff
changeset
|
389 (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
|
390 (setq changes t) |
1a43c99020cb
(wdired-change-to-wdired-mode, wdired-finish-edit)
Chong Yidong <cyd@stupidchicken.com>
parents:
72160
diff
changeset
|
391 (if (not file-new) ;empty filename! |
1a43c99020cb
(wdired-change-to-wdired-mode, wdired-finish-edit)
Chong Yidong <cyd@stupidchicken.com>
parents:
72160
diff
changeset
|
392 (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
|
393 (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
|
394 (if wdired-use-interactive-rename |
1a43c99020cb
(wdired-change-to-wdired-mode, wdired-finish-edit)
Chong Yidong <cyd@stupidchicken.com>
parents:
72160
diff
changeset
|
395 (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
|
396 ;; 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
|
397 ;; dired-backup-overwrite is locally bound, |
1a43c99020cb
(wdired-change-to-wdired-mode, wdired-finish-edit)
Chong Yidong <cyd@stupidchicken.com>
parents:
72160
diff
changeset
|
398 ;; 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
|
399 ;; 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
|
400 (require 'dired-aux) |
1a43c99020cb
(wdired-change-to-wdired-mode, wdired-finish-edit)
Chong Yidong <cyd@stupidchicken.com>
parents:
72160
diff
changeset
|
401 (condition-case err |
1a43c99020cb
(wdired-change-to-wdired-mode, wdired-finish-edit)
Chong Yidong <cyd@stupidchicken.com>
parents:
72160
diff
changeset
|
402 (let ((dired-backup-overwrite nil)) |
1a43c99020cb
(wdired-change-to-wdired-mode, wdired-finish-edit)
Chong Yidong <cyd@stupidchicken.com>
parents:
72160
diff
changeset
|
403 (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
|
404 overwrite)) |
1a43c99020cb
(wdired-change-to-wdired-mode, wdired-finish-edit)
Chong Yidong <cyd@stupidchicken.com>
parents:
72160
diff
changeset
|
405 (error |
1a43c99020cb
(wdired-change-to-wdired-mode, wdired-finish-edit)
Chong Yidong <cyd@stupidchicken.com>
parents:
72160
diff
changeset
|
406 (setq errors (1+ errors)) |
1a43c99020cb
(wdired-change-to-wdired-mode, wdired-finish-edit)
Chong Yidong <cyd@stupidchicken.com>
parents:
72160
diff
changeset
|
407 (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
|
408 file-new "' failed:\n%s\n") |
1a43c99020cb
(wdired-change-to-wdired-mode, wdired-finish-edit)
Chong Yidong <cyd@stupidchicken.com>
parents:
72160
diff
changeset
|
409 err)))))) |
55098 | 410 (forward-line -1))) |
411 (if changes | |
412 (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
|
413 (let ((inhibit-read-only t)) |
55098 | 414 (remove-text-properties (point-min) (point-max) |
415 '(old-name nil end-name nil old-link nil | |
416 end-link nil end-perm nil | |
417 old-perm nil perm-changed nil)) | |
418 (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
|
419 (when files-deleted |
1a43c99020cb
(wdired-change-to-wdired-mode, wdired-finish-edit)
Chong Yidong <cyd@stupidchicken.com>
parents:
72160
diff
changeset
|
420 (wdired-flag-for-deletion files-deleted)) |
1a43c99020cb
(wdired-change-to-wdired-mode, wdired-finish-edit)
Chong Yidong <cyd@stupidchicken.com>
parents:
72160
diff
changeset
|
421 (when (> errors 0) |
1a43c99020cb
(wdired-change-to-wdired-mode, wdired-finish-edit)
Chong Yidong <cyd@stupidchicken.com>
parents:
72160
diff
changeset
|
422 (dired-log-summary (format "%d rename actions failed" errors) nil))) |
55098 | 423 (set-buffer-modified-p nil) |
424 (setq buffer-undo-list nil)) | |
425 | |
68680
bdaa27dd39d3
(wdired-mode-map): Use remap.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68671
diff
changeset
|
426 ;; Rename a file, searching it in a modified dired buffer, in order |
55098 | 427 ;; 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
|
428 ;; "benefits". |
55098 | 429 (defun wdired-search-and-rename (filename-ori filename-new) |
430 (save-excursion | |
431 (goto-char (point-max)) | |
432 (forward-line -1) | |
433 (let ((exit-while nil) | |
434 curr-filename) | |
435 (while (not exit-while) | |
436 (setq curr-filename (wdired-get-filename)) | |
437 (if (and curr-filename | |
438 (equal (substitute-in-file-name curr-filename) filename-new)) | |
439 (progn | |
440 (setq exit-while t) | |
441 (let ((inhibit-read-only t)) | |
442 (dired-move-to-filename) | |
443 (search-forward (wdired-get-filename t) nil t) | |
444 (replace-match (file-name-nondirectory filename-ori) t t)) | |
445 (dired-do-create-files-regexp | |
446 (function dired-rename-file) | |
447 "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
|
448 (forward-line -1) |
1a43c99020cb
(wdired-change-to-wdired-mode, wdired-finish-edit)
Chong Yidong <cyd@stupidchicken.com>
parents:
72160
diff
changeset
|
449 (beginning-of-line) |
1a43c99020cb
(wdired-change-to-wdired-mode, wdired-finish-edit)
Chong Yidong <cyd@stupidchicken.com>
parents:
72160
diff
changeset
|
450 (setq exit-while (bobp))))))) |
55098 | 451 |
452 ;; marks a list of files for deletion | |
453 (defun wdired-flag-for-deletion (filenames-ori) | |
454 (save-excursion | |
455 (goto-char (point-min)) | |
456 (while (not (eobp)) | |
457 (if (member (dired-get-filename nil t) filenames-ori) | |
458 (dired-flag-file-deletion 1) | |
459 (forward-line))))) | |
460 | |
461 (defun wdired-customize () | |
61473 | 462 "Customize WDired options." |
55098 | 463 (interactive) |
464 (customize-apropos "wdired" 'groups)) | |
465 | |
466 (defun wdired-revert (&optional arg noconfirm) | |
61473 | 467 "Discard changes in the buffer and update it based on changes on disk. |
468 Optional arguments are ignored." | |
55098 | 469 (wdired-change-to-dired-mode) |
470 (revert-buffer) | |
471 (wdired-change-to-wdired-mode)) | |
472 | |
473 (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
|
474 ;; FIXME: Can't we use the normal mechanism for that? --Stef |
55098 | 475 (if (and |
476 (buffer-modified-p) | |
477 (not (y-or-n-p "Buffer changed. Discard changes and kill buffer? "))) | |
478 (error nil))) | |
479 | |
480 (defun wdired-next-line (arg) | |
481 "Move down lines then position at filename or the current column. | |
61473 | 482 See `wdired-use-dired-vertical-movement'. Optional prefix ARG |
55098 | 483 says how many lines to move; default is one line." |
484 (interactive "p") | |
485 (next-line arg) | |
61473 | 486 (if (or (eq wdired-use-dired-vertical-movement t) |
487 (and wdired-use-dired-vertical-movement | |
55098 | 488 (< (current-column) |
489 (save-excursion (dired-move-to-filename) | |
490 (current-column))))) | |
491 (dired-move-to-filename))) | |
492 | |
493 (defun wdired-previous-line (arg) | |
494 "Move up lines then position at filename or the current column. | |
61473 | 495 See `wdired-use-dired-vertical-movement'. Optional prefix ARG |
55098 | 496 says how many lines to move; default is one line." |
497 (interactive "p") | |
498 (previous-line arg) | |
61473 | 499 (if (or (eq wdired-use-dired-vertical-movement t) |
500 (and wdired-use-dired-vertical-movement | |
55098 | 501 (< (current-column) |
502 (save-excursion (dired-move-to-filename) | |
503 (current-column))))) | |
504 (dired-move-to-filename))) | |
505 | |
506 ;; Put the needed properties to allow the user to change links' targets | |
507 (defun wdired-preprocess-symlinks () | |
508 (let ((inhibit-read-only t)) | |
509 (save-excursion | |
510 (goto-char (point-min)) | |
511 (while (not (eobp)) | |
512 (if (looking-at dired-re-sym) | |
513 (progn | |
514 (re-search-forward " -> \\(.*\\)$") | |
515 (put-text-property (- (match-beginning 1) 2) | |
516 (1- (match-beginning 1)) 'old-link | |
517 (match-string-no-properties 1)) | |
518 (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
|
519 (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
|
520 (match-beginning 1) |
6be933449565
(wdired-preprocess-symlinks): Make the spaces after symlink arrows
Chong Yidong <cyd@stupidchicken.com>
parents:
74526
diff
changeset
|
521 'rear-nonsticky '(read-only)) |
6be933449565
(wdired-preprocess-symlinks): Make the spaces after symlink arrows
Chong Yidong <cyd@stupidchicken.com>
parents:
74526
diff
changeset
|
522 (put-text-property (match-beginning 1) |
55098 | 523 (match-end 1) 'read-only nil))) |
524 (forward-line) | |
525 (beginning-of-line))))) | |
526 | |
527 | |
528 (defun wdired-get-previous-link (&optional old move) | |
529 "Return the next symlink target. | |
530 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
|
531 (let (beg end target) |
1a43c99020cb
(wdired-change-to-wdired-mode, wdired-finish-edit)
Chong Yidong <cyd@stupidchicken.com>
parents:
72160
diff
changeset
|
532 (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
|
533 (if beg |
1a43c99020cb
(wdired-change-to-wdired-mode, wdired-finish-edit)
Chong Yidong <cyd@stupidchicken.com>
parents:
72160
diff
changeset
|
534 (progn |
1a43c99020cb
(wdired-change-to-wdired-mode, wdired-finish-edit)
Chong Yidong <cyd@stupidchicken.com>
parents:
72160
diff
changeset
|
535 (if old |
1a43c99020cb
(wdired-change-to-wdired-mode, wdired-finish-edit)
Chong Yidong <cyd@stupidchicken.com>
parents:
72160
diff
changeset
|
536 (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
|
537 (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
|
538 (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
|
539 (if move (goto-char (1- beg))))) |
1a43c99020cb
(wdired-change-to-wdired-mode, wdired-finish-edit)
Chong Yidong <cyd@stupidchicken.com>
parents:
72160
diff
changeset
|
540 (and target (wdired-normalize-filename target)))) |
1a43c99020cb
(wdired-change-to-wdired-mode, wdired-finish-edit)
Chong Yidong <cyd@stupidchicken.com>
parents:
72160
diff
changeset
|
541 |
55098 | 542 |
543 ;; 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
|
544 (defun wdired-do-symlink-changes () |
55098 | 545 (let ((changes nil) |
546 (errors 0) | |
547 link-to-ori link-to-new link-from) | |
548 (goto-char (point-max)) | |
549 (while (setq link-to-new (wdired-get-previous-link)) | |
550 (setq link-to-ori (wdired-get-previous-link t t)) | |
551 (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
|
552 (unless (equal link-to-new link-to-ori) |
bdaa27dd39d3
(wdired-mode-map): Use remap.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68671
diff
changeset
|
553 (setq changes t) |
bdaa27dd39d3
(wdired-mode-map): Use remap.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68671
diff
changeset
|
554 (if (equal link-to-new "") ;empty filename! |
bdaa27dd39d3
(wdired-mode-map): Use remap.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68671
diff
changeset
|
555 (setq link-to-new "/dev/null")) |
bdaa27dd39d3
(wdired-mode-map): Use remap.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68671
diff
changeset
|
556 (condition-case err |
bdaa27dd39d3
(wdired-mode-map): Use remap.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68671
diff
changeset
|
557 (progn |
bdaa27dd39d3
(wdired-mode-map): Use remap.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68671
diff
changeset
|
558 (delete-file link-from) |
bdaa27dd39d3
(wdired-mode-map): Use remap.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68671
diff
changeset
|
559 (make-symbolic-link |
bdaa27dd39d3
(wdired-mode-map): Use remap.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68671
diff
changeset
|
560 (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
|
561 (error |
bdaa27dd39d3
(wdired-mode-map): Use remap.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68671
diff
changeset
|
562 (setq errors (1+ errors)) |
bdaa27dd39d3
(wdired-mode-map): Use remap.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68671
diff
changeset
|
563 (dired-log (concat "Link `" link-from "' to `" |
bdaa27dd39d3
(wdired-mode-map): Use remap.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68671
diff
changeset
|
564 link-to-new "' failed:\n%s\n") |
bdaa27dd39d3
(wdired-mode-map): Use remap.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68671
diff
changeset
|
565 err))))) |
55098 | 566 (cons changes errors))) |
567 | |
568 ;; Perform a "case command" skipping read-only words. | |
569 (defun wdired-xcase-word (command arg) | |
570 (if (< arg 0) | |
571 (funcall command arg) | |
68680
bdaa27dd39d3
(wdired-mode-map): Use remap.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68671
diff
changeset
|
572 (while (> arg 0) |
bdaa27dd39d3
(wdired-mode-map): Use remap.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68671
diff
changeset
|
573 (condition-case err |
bdaa27dd39d3
(wdired-mode-map): Use remap.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68671
diff
changeset
|
574 (progn |
bdaa27dd39d3
(wdired-mode-map): Use remap.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68671
diff
changeset
|
575 (funcall command 1) |
bdaa27dd39d3
(wdired-mode-map): Use remap.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68671
diff
changeset
|
576 (setq arg (1- arg))) |
bdaa27dd39d3
(wdired-mode-map): Use remap.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68671
diff
changeset
|
577 (error |
75159
21d0aec573ef
(wdired-xcase-word): Skip non-word read-only characters.
Martin Rudalics <rudalics@gmx.at>
parents:
74528
diff
changeset
|
578 (if (forward-word) |
21d0aec573ef
(wdired-xcase-word): Skip non-word read-only characters.
Martin Rudalics <rudalics@gmx.at>
parents:
74528
diff
changeset
|
579 ;; 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
|
580 ;; 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
|
581 (skip-syntax-forward "^w") |
21d0aec573ef
(wdired-xcase-word): Skip non-word read-only characters.
Martin Rudalics <rudalics@gmx.at>
parents:
74528
diff
changeset
|
582 (setq arg 0))))))) |
55098 | 583 |
584 (defun wdired-downcase-word (arg) | |
61473 | 585 "WDired version of `downcase-word'. |
55098 | 586 Like original function but it skips read-only words." |
587 (interactive "p") | |
588 (wdired-xcase-word 'downcase-word arg)) | |
589 | |
590 (defun wdired-upcase-word (arg) | |
61473 | 591 "WDired version of `upcase-word'. |
55098 | 592 Like original function but it skips read-only words." |
593 (interactive "p") | |
594 (wdired-xcase-word 'upcase-word arg)) | |
595 | |
596 (defun wdired-capitalize-word (arg) | |
61473 | 597 "WDired version of `capitalize-word'. |
55098 | 598 Like original function but it skips read-only words." |
599 (interactive "p") | |
600 (wdired-xcase-word 'capitalize-word arg)) | |
601 | |
602 | |
603 ;; The following code deals with changing the access bits (or | |
604 ;; permissions) of the files. | |
605 | |
68680
bdaa27dd39d3
(wdired-mode-map): Use remap.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68671
diff
changeset
|
606 (defvar wdired-perm-mode-map |
bdaa27dd39d3
(wdired-mode-map): Use remap.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68671
diff
changeset
|
607 (let ((map (make-sparse-keymap))) |
bdaa27dd39d3
(wdired-mode-map): Use remap.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68671
diff
changeset
|
608 (define-key map " " 'wdired-toggle-bit) |
bdaa27dd39d3
(wdired-mode-map): Use remap.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68671
diff
changeset
|
609 (define-key map "r" 'wdired-set-bit) |
bdaa27dd39d3
(wdired-mode-map): Use remap.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68671
diff
changeset
|
610 (define-key map "w" 'wdired-set-bit) |
bdaa27dd39d3
(wdired-mode-map): Use remap.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68671
diff
changeset
|
611 (define-key map "x" 'wdired-set-bit) |
bdaa27dd39d3
(wdired-mode-map): Use remap.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68671
diff
changeset
|
612 (define-key map "-" 'wdired-set-bit) |
bdaa27dd39d3
(wdired-mode-map): Use remap.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68671
diff
changeset
|
613 (define-key map "S" '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 "T" '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 "s" 'wdired-set-bit) |
bdaa27dd39d3
(wdired-mode-map): Use remap.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68671
diff
changeset
|
618 (define-key map "l" 'wdired-set-bit) |
bdaa27dd39d3
(wdired-mode-map): Use remap.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68671
diff
changeset
|
619 (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
|
620 map)) |
55098 | 621 |
74526
1a43c99020cb
(wdired-change-to-wdired-mode, wdired-finish-edit)
Chong Yidong <cyd@stupidchicken.com>
parents:
72160
diff
changeset
|
622 ;; Put a keymap property to the permission bits of the files, and store the |
55098 | 623 ;; original name and permissions as a property |
68680
bdaa27dd39d3
(wdired-mode-map): Use remap.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68671
diff
changeset
|
624 (defun wdired-preprocess-perms () |
74526
1a43c99020cb
(wdired-change-to-wdired-mode, wdired-finish-edit)
Chong Yidong <cyd@stupidchicken.com>
parents:
72160
diff
changeset
|
625 (let ((inhibit-read-only t)) |
55098 | 626 (set (make-local-variable 'wdired-col-perm) nil) |
627 (save-excursion | |
628 (goto-char (point-min)) | |
629 (while (not (eobp)) | |
74526
1a43c99020cb
(wdired-change-to-wdired-mode, wdired-finish-edit)
Chong Yidong <cyd@stupidchicken.com>
parents:
72160
diff
changeset
|
630 (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
|
631 (wdired-get-filename) |
1a43c99020cb
(wdired-change-to-wdired-mode, wdired-finish-edit)
Chong Yidong <cyd@stupidchicken.com>
parents:
72160
diff
changeset
|
632 (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
|
633 (let ((begin (match-beginning 0)) |
1a43c99020cb
(wdired-change-to-wdired-mode, wdired-finish-edit)
Chong Yidong <cyd@stupidchicken.com>
parents:
72160
diff
changeset
|
634 (end (match-end 0))) |
1a43c99020cb
(wdired-change-to-wdired-mode, wdired-finish-edit)
Chong Yidong <cyd@stupidchicken.com>
parents:
72160
diff
changeset
|
635 (unless wdired-col-perm |
1a43c99020cb
(wdired-change-to-wdired-mode, wdired-finish-edit)
Chong Yidong <cyd@stupidchicken.com>
parents:
72160
diff
changeset
|
636 (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
|
637 (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
|
638 (progn |
1a43c99020cb
(wdired-change-to-wdired-mode, wdired-finish-edit)
Chong Yidong <cyd@stupidchicken.com>
parents:
72160
diff
changeset
|
639 (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
|
640 ;; make first permission bit writable |
1a43c99020cb
(wdired-change-to-wdired-mode, wdired-finish-edit)
Chong Yidong <cyd@stupidchicken.com>
parents:
72160
diff
changeset
|
641 (put-text-property |
1a43c99020cb
(wdired-change-to-wdired-mode, wdired-finish-edit)
Chong Yidong <cyd@stupidchicken.com>
parents:
72160
diff
changeset
|
642 (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
|
643 ;; 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
|
644 (add-text-properties |
1a43c99020cb
(wdired-change-to-wdired-mode, wdired-finish-edit)
Chong Yidong <cyd@stupidchicken.com>
parents:
72160
diff
changeset
|
645 (1+ begin) end |
1a43c99020cb
(wdired-change-to-wdired-mode, wdired-finish-edit)
Chong Yidong <cyd@stupidchicken.com>
parents:
72160
diff
changeset
|
646 `(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
|
647 (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
|
648 (put-text-property |
1a43c99020cb
(wdired-change-to-wdired-mode, wdired-finish-edit)
Chong Yidong <cyd@stupidchicken.com>
parents:
72160
diff
changeset
|
649 begin (1+ begin) 'old-perm (match-string-no-properties 0)))) |
55098 | 650 (forward-line) |
651 (beginning-of-line))))) | |
652 | |
653 (defun wdired-perm-allowed-in-pos (char pos) | |
654 (cond | |
655 ((= char ?-) t) | |
656 ((= char ?r) (= (% pos 3) 0)) | |
657 ((= char ?w) (= (% pos 3) 1)) | |
658 ((= char ?x) (= (% pos 3) 2)) | |
659 ((memq char '(?s ?S)) (memq pos '(2 5))) | |
660 ((memq char '(?t ?T)) (= pos 8)) | |
661 ((= char ?l) (= pos 5)))) | |
662 | |
663 (defun wdired-set-bit () | |
664 "Set a permission bit character." | |
665 (interactive) | |
666 (if (wdired-perm-allowed-in-pos last-command-char | |
667 (- (current-column) wdired-col-perm)) | |
668 (let ((new-bit (char-to-string last-command-char)) | |
669 (inhibit-read-only t) | |
670 (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
|
671 (put-text-property 0 1 'keymap wdired-perm-mode-map new-bit) |
55098 | 672 (put-text-property 0 1 'read-only t new-bit) |
673 (insert new-bit) | |
674 (delete-char 1) | |
74526
1a43c99020cb
(wdired-change-to-wdired-mode, wdired-finish-edit)
Chong Yidong <cyd@stupidchicken.com>
parents:
72160
diff
changeset
|
675 (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
|
676 (put-text-property (1- (point)) (point) 'rear-nonsticky '(keymap))) |
55098 | 677 (forward-char 1))) |
678 | |
68680
bdaa27dd39d3
(wdired-mode-map): Use remap.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68671
diff
changeset
|
679 (defun wdired-toggle-bit () |
55098 | 680 "Toggle the permission bit at point." |
681 (interactive) | |
682 (let ((inhibit-read-only t) | |
74526
1a43c99020cb
(wdired-change-to-wdired-mode, wdired-finish-edit)
Chong Yidong <cyd@stupidchicken.com>
parents:
72160
diff
changeset
|
683 (new-bit "-") |
55098 | 684 (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
|
685 (if (eq (char-after (point)) ?-) |
81639
8e5203081e80
* dired-aux.el: Remove `dired-call-process'.
Michael Albinus <michael.albinus@gmx.de>
parents:
75347
diff
changeset
|
686 (setq new-bit |
74526
1a43c99020cb
(wdired-change-to-wdired-mode, wdired-finish-edit)
Chong Yidong <cyd@stupidchicken.com>
parents:
72160
diff
changeset
|
687 (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
|
688 (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
|
689 "x")))) |
68680
bdaa27dd39d3
(wdired-mode-map): Use remap.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68671
diff
changeset
|
690 (put-text-property 0 1 'keymap wdired-perm-mode-map new-bit) |
55098 | 691 (put-text-property 0 1 'read-only t new-bit) |
692 (insert new-bit) | |
693 (delete-char 1) | |
74526
1a43c99020cb
(wdired-change-to-wdired-mode, wdired-finish-edit)
Chong Yidong <cyd@stupidchicken.com>
parents:
72160
diff
changeset
|
694 (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
|
695 (put-text-property (1- (point)) (point) 'rear-nonsticky '(keymap)))) |
55098 | 696 |
697 (defun wdired-mouse-toggle-bit (event) | |
698 "Toggle the permission bit that was left clicked." | |
699 (interactive "e") | |
700 (mouse-set-point event) | |
701 (wdired-toggle-bit)) | |
702 | |
703 ;; Allowed chars for 4000 bit are Ss in position 3 | |
704 ;; Allowed chars for 2000 bit are Ssl in position 6 | |
705 ;; Allowed chars for 1000 bit are Tt in position 9 | |
706 (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
|
707 (let ((nperm 0777)) |
1a43c99020cb
(wdired-change-to-wdired-mode, wdired-finish-edit)
Chong Yidong <cyd@stupidchicken.com>
parents:
72160
diff
changeset
|
708 (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
|
709 (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
|
710 (let ((p-bit (elt perms 3))) |
1a43c99020cb
(wdired-change-to-wdired-mode, wdired-finish-edit)
Chong Yidong <cyd@stupidchicken.com>
parents:
72160
diff
changeset
|
711 (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
|
712 (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
|
713 (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
|
714 (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
|
715 (let ((p-bit (elt perms 6))) |
1a43c99020cb
(wdired-change-to-wdired-mode, wdired-finish-edit)
Chong Yidong <cyd@stupidchicken.com>
parents:
72160
diff
changeset
|
716 (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
|
717 (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
|
718 (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
|
719 (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
|
720 (let ((p-bit (elt perms 9))) |
1a43c99020cb
(wdired-change-to-wdired-mode, wdired-finish-edit)
Chong Yidong <cyd@stupidchicken.com>
parents:
72160
diff
changeset
|
721 (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
|
722 (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
|
723 nperm)) |
55098 | 724 |
725 ;; Perform the changes in the permissions of the files that have | |
726 ;; changed. | |
727 (defun wdired-do-perm-changes () | |
728 (let ((changes nil) | |
729 (errors 0) | |
730 (prop-wanted (if (eq wdired-allow-to-change-permissions 'advanced) | |
731 'old-perm 'perm-changed)) | |
732 filename perms-ori perms-new perm-tmp) | |
733 (goto-char (next-single-property-change (point-min) prop-wanted | |
734 nil (point-max))) | |
735 (while (not (eobp)) | |
736 (setq perms-ori (get-text-property (point) 'old-perm)) | |
737 (setq perms-new (buffer-substring-no-properties | |
738 (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
|
739 (unless (equal perms-ori perms-new) |
bdaa27dd39d3
(wdired-mode-map): Use remap.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68671
diff
changeset
|
740 (setq changes t) |
bdaa27dd39d3
(wdired-mode-map): Use remap.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68671
diff
changeset
|
741 (setq filename (wdired-get-filename nil t)) |
bdaa27dd39d3
(wdired-mode-map): Use remap.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68671
diff
changeset
|
742 (if (= (length perms-new) 10) |
bdaa27dd39d3
(wdired-mode-map): Use remap.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68671
diff
changeset
|
743 (progn |
bdaa27dd39d3
(wdired-mode-map): Use remap.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68671
diff
changeset
|
744 (setq perm-tmp |
bdaa27dd39d3
(wdired-mode-map): Use remap.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68671
diff
changeset
|
745 (int-to-string (wdired-perms-to-number perms-new))) |
81639
8e5203081e80
* dired-aux.el: Remove `dired-call-process'.
Michael Albinus <michael.albinus@gmx.de>
parents:
75347
diff
changeset
|
746 (unless (equal 0 (process-file dired-chmod-program |
8e5203081e80
* dired-aux.el: Remove `dired-call-process'.
Michael Albinus <michael.albinus@gmx.de>
parents:
75347
diff
changeset
|
747 nil nil nil perm-tmp filename)) |
68680
bdaa27dd39d3
(wdired-mode-map): Use remap.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68671
diff
changeset
|
748 (setq errors (1+ errors)) |
bdaa27dd39d3
(wdired-mode-map): Use remap.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68671
diff
changeset
|
749 (dired-log (concat dired-chmod-program " " perm-tmp |
bdaa27dd39d3
(wdired-mode-map): Use remap.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68671
diff
changeset
|
750 " `" filename "' failed\n\n")))) |
bdaa27dd39d3
(wdired-mode-map): Use remap.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68671
diff
changeset
|
751 (setq errors (1+ errors)) |
bdaa27dd39d3
(wdired-mode-map): Use remap.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68671
diff
changeset
|
752 (dired-log (concat "Cannot parse permission `" perms-new |
bdaa27dd39d3
(wdired-mode-map): Use remap.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68671
diff
changeset
|
753 "' for file `" filename "'\n\n")))) |
55098 | 754 (goto-char (next-single-property-change (1+ (point)) prop-wanted |
755 nil (point-max)))) | |
756 (cons changes errors))) | |
757 | |
758 (provide 'wdired) | |
759 | |
68680
bdaa27dd39d3
(wdired-mode-map): Use remap.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68671
diff
changeset
|
760 ;; Local Variables: |
bdaa27dd39d3
(wdired-mode-map): Use remap.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68671
diff
changeset
|
761 ;; coding: latin-1 |
bdaa27dd39d3
(wdired-mode-map): Use remap.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68671
diff
changeset
|
762 ;; byte-compile-dynamic: t |
bdaa27dd39d3
(wdired-mode-map): Use remap.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68671
diff
changeset
|
763 ;; End: |
bdaa27dd39d3
(wdired-mode-map): Use remap.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
68671
diff
changeset
|
764 |
55109
043dd9a4d1b4
(wdired-mode-map): Move init into declaration. Fix `return' binding.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55107
diff
changeset
|
765 ;; arch-tag: bc00902e-526f-4305-bc7f-8862a559184f |
55098 | 766 ;;; wdired.el ends here |