aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Monnier2004-04-23 22:22:13 +0000
committerStefan Monnier2004-04-23 22:22:13 +0000
commitd549a7dfb249842ae4548705ba237f4edd7ebb1c (patch)
treefb349f919e54f80fe869d54677e822dfe57f8ed9
parent2ecab8401f08e857d860a4a579592916e1297217 (diff)
downloademacs-d549a7dfb249842ae4548705ba237f4edd7ebb1c.tar.gz
emacs-d549a7dfb249842ae4548705ba237f4edd7ebb1c.zip
(wdired-mode-map): Move init into declaration. Fix `return' binding.
(wdired-change-to-wdired-mode, wdired-change-to-dired-mode): Use force-mode-line-update. (wdired-get-filename): Use `unless'. (wdired-preprocess-files): Don't assume names have no \n and use / for dirsep. (wdired-normalize-filename): Use replace-regexp-in-string. (wdired-load-hooks): Remove. (wdired-mode-hooks): Rename to wdired-mode-hook.
-rw-r--r--lisp/wdired.el138
1 files changed, 65 insertions, 73 deletions
diff --git a/lisp/wdired.el b/lisp/wdired.el
index 16951fe2aa9..a8c36c2066f 100644
--- a/lisp/wdired.el
+++ b/lisp/wdired.el
@@ -30,7 +30,7 @@
30;; renaming files. 30;; renaming files.
31;; 31;;
32;; Have you ever wished to use C-x r t (string-rectangle), M-% 32;; Have you ever wished to use C-x r t (string-rectangle), M-%
33;; (query-replace), M-c (capitalize-word), etc to change the name of 33;; (query-replace), M-c (capitalize-word), etc. to change the name of
34;; the files in a "dired" buffer? Now you can do this. All the power 34;; the files in a "dired" buffer? Now you can do this. All the power
35;; of emacs commands are available to renaming files! 35;; of emacs commands are available to renaming files!
36;; 36;;
@@ -113,7 +113,7 @@
113;; - Another alternative way of editing permissions allowed, see 113;; - Another alternative way of editing permissions allowed, see
114;; `wdired-allow-to-change-permissions' for details. 114;; `wdired-allow-to-change-permissions' for details.
115;; 115;;
116;; - Now wdired doesn`t relies in regexp so much. As a consequence of 116;; - Now wdired doesn't rely on regexp so much. As a consequence of
117;; this, you can add newlines to filenames and symlinks targets 117;; this, you can add newlines to filenames and symlinks targets
118;; (although this is not very usual, IMHO). Please note that dired 118;; (although this is not very usual, IMHO). Please note that dired
119;; (at least in Emacs 21.1 and previous) does not work very well 119;; (at least in Emacs 21.1 and previous) does not work very well
@@ -121,8 +121,8 @@
121;; wdired mode. But you can activate it if you want. 121;; wdired mode. But you can activate it if you want.
122;; 122;;
123;; - Now `upcase-word' `capitalize-word' and `downcase-word' are not 123;; - Now `upcase-word' `capitalize-word' and `downcase-word' are not
124;; advised to work better with wdired mode, but the keys binded to 124;; advised to work better with wdired mode, but the keys bound to
125;; them use wdired versions of that commands. 125;; them use wdired versions of those commands.
126;; 126;;
127;; - Now "undo" actions are not inherited from wdired mode when 127;; - Now "undo" actions are not inherited from wdired mode when
128;; changing to dired mode. 128;; changing to dired mode.
@@ -158,7 +158,6 @@
158 158
159(eval-when-compile 159(eval-when-compile
160 (require 'advice) 160 (require 'advice)
161 (defvar make-symbolic-link) ;Avoid a compilation warning in NTEmacs
162 (defvar dired-backup-overwrite) ; Only in emacs 20.x this is a custom var 161 (defvar dired-backup-overwrite) ; Only in emacs 20.x this is a custom var
163 (set (make-local-variable 'byte-compile-dynamic) t)) 162 (set (make-local-variable 'byte-compile-dynamic) t))
164 163
@@ -238,49 +237,45 @@ intelligible value.
238Anyway, the real change of the permissions is done with the external 237Anyway, the real change of the permissions is done with the external
239program `dired-chmod-program', which must exist." 238program `dired-chmod-program', which must exist."
240 :type '(choice (const :tag "Not allowed" nil) 239 :type '(choice (const :tag "Not allowed" nil)
241 (const :tag "Toggle/set bits" t) 240 (const :tag "Toggle/set bits" t)
242 (other :tag "Bits freely editable" advanced)) 241 (other :tag "Bits freely editable" advanced))
243 :group 'wdired) 242 :group 'wdired)
244 243
245(define-key dired-mode-map [menu-bar immediate wdired-change-to-wdired-mode] 244(defvar wdired-mode-map
246 '("Edit File Names" . wdired-change-to-wdired-mode)) 245 (let ((map (make-sparse-keymap)))
247 246 (define-key map "\C-x\C-s" 'wdired-finish-edit)
248(defvar wdired-mode-map nil) 247 (define-key map "\C-c\C-c" 'wdired-finish-edit)
249(unless wdired-mode-map 248 (define-key map "\C-c\C-k" 'wdired-abort-changes)
250 (setq wdired-mode-map (make-sparse-keymap)) 249 (define-key map "\C-c\C-[" 'wdired-abort-changes)
251 (define-key wdired-mode-map "\C-x\C-s" 'wdired-finish-edit) 250 (define-key map "\C-m" 'wdired-newline)
252 (define-key wdired-mode-map "\C-c\C-c" 'wdired-finish-edit) 251 (define-key map "\C-j" 'wdired-newline)
253 (define-key wdired-mode-map "\C-c\C-k" 'wdired-abort-changes) 252 (define-key map "\C-o" 'wdired-newline)
254 (define-key wdired-mode-map "\C-c\C-[" 'wdired-abort-changes) 253 (define-key map [up] 'wdired-previous-line)
255 (define-key wdired-mode-map [return] 'wdired-newline) 254 (define-key map "\C-p" 'wdired-previous-line)
256 (define-key wdired-mode-map "\C-j" 'wdired-newline) 255 (define-key map [down] 'wdired-next-line)
257 (define-key wdired-mode-map "\C-o" 'wdired-newline) 256 (define-key map "\C-n" 'wdired-next-line)
258 (define-key wdired-mode-map [up] 'wdired-previous-line) 257
259 (define-key wdired-mode-map "\C-p" 'wdired-previous-line) 258 (define-key map [menu-bar wdired]
260 (define-key wdired-mode-map [down] 'wdired-next-line) 259 (cons "WDired" (make-sparse-keymap "WDired")))
261 (define-key wdired-mode-map "\C-n" 'wdired-next-line) 260 (define-key map [menu-bar wdired wdired-customize]
262 (define-key wdired-mode-map [menu-bar wdired] 261 '("Options" . wdired-customize))
263 (cons "WDired" (make-sparse-keymap "WDired"))) 262 (define-key map [menu-bar wdired dashes]
264 (define-key wdired-mode-map [menu-bar wdired wdired-customize]
265 '("Options" . wdired-customize))
266 (define-key wdired-mode-map [menu-bar wdired dashes]
267 '("--")) 263 '("--"))
268 (define-key wdired-mode-map [menu-bar wdired wdired-abort-changes] 264 (define-key map [menu-bar wdired wdired-abort-changes]
269 '("Abort Changes" . wdired-abort-changes)) 265 '("Abort Changes" . wdired-abort-changes))
270 (define-key wdired-mode-map [menu-bar wdired wdired-finish-edit] 266 (define-key map [menu-bar wdired wdired-finish-edit]
271 '("Validate Changes" . wdired-finish-edit)) 267 '("Commit Changes" . wdired-finish-edit))
272 (substitute-key-definition 'upcase-word 'wdired-upcase-word 268 ;; FIXME: Use the new remap trick.
273 wdired-mode-map global-map) 269 (substitute-key-definition 'upcase-word 'wdired-upcase-word
274 (substitute-key-definition 'capitalize-word 'wdired-capitalize-word 270 map global-map)
275 wdired-mode-map global-map) 271 (substitute-key-definition 'capitalize-word 'wdired-capitalize-word
276 (substitute-key-definition 'downcase-word 'wdired-downcase-word 272 map global-map)
277 wdired-mode-map global-map)) 273 (substitute-key-definition 'downcase-word 'wdired-downcase-word
278 274 map global-map)
279(defvar wdired-mode-hooks nil 275 map))
280 "Hooks run when changing to wdired mode.") 276
281 277(defvar wdired-mode-hook nil
282(defvar wdired-load-hooks nil 278 "Hook run when changing to wdired mode.")
283 "Hooks run after loading wdired code.")
284 279
285;; Local variables (put here to avoid compilation gripes) 280;; Local variables (put here to avoid compilation gripes)
286(defvar wdired-col-perm) ;; Column where the permission bits start 281(defvar wdired-col-perm) ;; Column where the permission bits start
@@ -307,7 +302,7 @@ not allowed, because the rest of the buffer is read-only."
307;;;###autoload 302;;;###autoload
308(defun wdired-change-to-wdired-mode () 303(defun wdired-change-to-wdired-mode ()
309 "Put a dired buffer in a mode in which filenames are editable. 304 "Put a dired buffer in a mode in which filenames are editable.
310In this mode the names of the files can be changed, and after 305In this mode the names of the files can be changed, and after
311typing C-c C-c the files and directories in disk are renamed. 306typing C-c C-c the files and directories in disk are renamed.
312 307
313See `wdired-mode'." 308See `wdired-mode'."
@@ -315,10 +310,9 @@ See `wdired-mode'."
315 (set (make-local-variable 'wdired-old-content) 310 (set (make-local-variable 'wdired-old-content)
316 (buffer-substring (point-min) (point-max))) 311 (buffer-substring (point-min) (point-max)))
317 (use-local-map wdired-mode-map) 312 (use-local-map wdired-mode-map)
318 (menu-bar-mode (or menu-bar-mode -1)) ;Force redisplay menu 313 (force-mode-line-update)
319 (setq buffer-read-only nil) 314 (setq buffer-read-only nil)
320 (dired-unadvertise default-directory) 315 (dired-unadvertise default-directory)
321 (make-local-hook 'kill-buffer-hook)
322 (add-hook 'kill-buffer-hook 'wdired-check-kill-buffer nil t) 316 (add-hook 'kill-buffer-hook 'wdired-check-kill-buffer nil t)
323 (setq major-mode 'wdired-mode) 317 (setq major-mode 'wdired-mode)
324 (setq mode-name "Edit filenames") 318 (setq mode-name "Edit filenames")
@@ -335,7 +329,7 @@ See `wdired-mode'."
335 (buffer-enable-undo) ; Performance hack. See above. 329 (buffer-enable-undo) ; Performance hack. See above.
336 (set-buffer-modified-p nil) 330 (set-buffer-modified-p nil)
337 (setq buffer-undo-list nil) 331 (setq buffer-undo-list nil)
338 (run-hooks wdired-mode-hooks) 332 (run-hooks wdired-mode-hook)
339 (message "Press C-c C-c when finished")) 333 (message "Press C-c C-c when finished"))
340 334
341 335
@@ -349,24 +343,24 @@ See `wdired-mode'."
349 filename) 343 filename)
350 (while (not (eobp)) 344 (while (not (eobp))
351 (setq filename (dired-get-filename nil t)) 345 (setq filename (dired-get-filename nil t))
352 (if (and filename (not (string-match "/\\.\\.?$" filename))) 346 (when (and filename
353 (progn 347 (not (member (file-name-nondirectory filename) '("." ".."))))
354 (dired-move-to-filename) 348 (dired-move-to-filename)
355 (put-text-property (- (point) 2) (1- (point)) 'old-name filename) 349 (put-text-property (- (point) 2) (1- (point)) 'old-name filename)
356 (put-text-property b-protection (1- (point)) 'read-only t) 350 (put-text-property b-protection (1- (point)) 'read-only t)
357 (setq b-protection (dired-move-to-end-of-filename t)))) 351 (setq b-protection (dired-move-to-end-of-filename t)))
358 (put-text-property (point) (1+ (point)) 'end-name t) 352 (put-text-property (point) (1+ (point)) 'end-name t)
359 (forward-line)) 353 (forward-line))
360 (put-text-property b-protection (point-max) 'read-only t)))) 354 (put-text-property b-protection (point-max) 'read-only t))))
361 355
362;; This code is a copy of some dired-get-filename lines. 356;; This code is a copy of some dired-get-filename lines.
363(defsubst wdired-normalize-filename (file) 357(defsubst wdired-normalize-filename (file)
364 (setq file 358 (setq file
359 ;; FIXME: shouldn't we check for a `b' argument or somesuch before
360 ;; doing such unquoting? --Stef
365 (read (concat 361 (read (concat
366 "\"" (or (dired-string-replace-match 362 "\"" (replace-regexp-in-string
367 "\\([^\\]\\|\\`\\)\"" file 363 "\\([^\\]\\|\\`\\)\"" "\\1\\\\\"" file)
368 "\\1\\\\\"" nil t)
369 file)
370 "\""))) 364 "\"")))
371 (and file buffer-file-coding-system 365 (and file buffer-file-coding-system
372 (not file-name-coding-system) 366 (not file-name-coding-system)
@@ -376,22 +370,22 @@ See `wdired-mode'."
376 370
377(defun wdired-get-filename (&optional no-dir old) 371(defun wdired-get-filename (&optional no-dir old)
378 "Return the filename at line. 372 "Return the filename at line.
379Similar to `dired-get-filename' but it doesn't relies in regexps. It 373Similar to `dired-get-filename' but it doesn't rely on regexps. It
380relies in wdired buffer's properties. Optional arg NO-DIR with value 374relies on wdired buffer's properties. Optional arg NO-DIR with value
381non-nil means don't include directory. Optional arg OLD with value 375non-nil means don't include directory. Optional arg OLD with value
382non-nil means return old filename." 376non-nil means return old filename."
377 ;; FIXME: Use dired-get-filename's new properties.
383 (let (beg end file) 378 (let (beg end file)
384 (save-excursion 379 (save-excursion
385 (setq end (progn (end-of-line) (point))) 380 (setq end (progn (end-of-line) (point)))
386 (beginning-of-line) 381 (beginning-of-line)
387 (setq beg (next-single-property-change (point) 'old-name nil end)) 382 (setq beg (next-single-property-change (point) 'old-name nil end))
388 (if (not (eq beg end)) 383 (unless (eq beg end)
389 (progn 384 (if old
390 (if old 385 (setq file (get-text-property beg 'old-name))
391 (setq file (get-text-property beg 'old-name)) 386 (setq end (next-single-property-change (1+ beg) 'end-name))
392 (setq end (next-single-property-change (1+ beg) 'end-name)) 387 (setq file (buffer-substring-no-properties (+ 2 beg) end)))
393 (setq file (buffer-substring-no-properties (+ 2 beg) end))) 388 (and file (setq file (wdired-normalize-filename file))))
394 (and file (setq file (wdired-normalize-filename file)))))
395 (if (or no-dir old) 389 (if (or no-dir old)
396 file 390 file
397 (and file (> (length file) 0) 391 (and file (> (length file) 0)
@@ -405,7 +399,7 @@ non-nil means return old filename."
405 '(read-only nil local-map nil))) 399 '(read-only nil local-map nil)))
406 (put-text-property 1 2 'front-sticky nil) 400 (put-text-property 1 2 'front-sticky nil)
407 (use-local-map dired-mode-map) 401 (use-local-map dired-mode-map)
408 (menu-bar-mode (or menu-bar-mode -1)) ;Force redisplay menu 402 (force-mode-line-update)
409 (setq buffer-read-only t) 403 (setq buffer-read-only t)
410 (setq major-mode 'dired-mode) 404 (setq major-mode 'dired-mode)
411 (setq mode-name "Dired") 405 (setq mode-name "Dired")
@@ -533,6 +527,7 @@ non-nil means return old filename."
533 (wdired-change-to-wdired-mode)) 527 (wdired-change-to-wdired-mode))
534 528
535(defun wdired-check-kill-buffer () 529(defun wdired-check-kill-buffer ()
530 ;; FIXME: Can't we use the normal mechanism for that? --Stef
536 (if (and 531 (if (and
537 (buffer-modified-p) 532 (buffer-modified-p)
538 (not (y-or-n-p "Buffer changed. Discard changes and kill buffer? "))) 533 (not (y-or-n-p "Buffer changed. Discard changes and kill buffer? ")))
@@ -872,9 +867,6 @@ commands. This advice only has effect in wdired mode."
872 (cons changes errors))) 867 (cons changes errors)))
873 868
874(provide 'wdired) 869(provide 'wdired)
875(run-hooks wdired-load-hooks)
876 870
871;; arch-tag: bc00902e-526f-4305-bc7f-8862a559184f
877;;; wdired.el ends here 872;;; wdired.el ends here
878
879
880;;; arch-tag: bc00902e-526f-4305-bc7f-8862a559184f