annotate lisp/wdired.el @ 96285:cb6aa853e038

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