annotate lisp/wdired.el @ 61366:e94eb3df0922

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