From 7ebc5f5a07b71eada164b9e115eb40a2c03b0f95 Mon Sep 17 00:00:00 2001 From: Michael Heerdegen Date: Wed, 17 Oct 2012 11:11:49 +0200 Subject: [PATCH] When renaming a file with wdired move point with file and don't lose mark status (Bug#11795). * wdired.el (wdired-old-marks): New variable. (wdired-change-to-wdired-mode): Locally set wdired-old-marks. (wdired-do-renames): Move point with renamed file and don't lose mark status (Bug#11795). --- lisp/ChangeLog | 7 +++++++ lisp/wdired.el | 16 ++++++++++++---- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 437f8d57c9a..5a5549332ac 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,10 @@ +2012-10-17 Michael Heerdegen (tiny change) + + * wdired.el (wdired-old-marks): New variable. + (wdired-change-to-wdired-mode): Locally set wdired-old-marks. + (wdired-do-renames): Move point with renamed file and don't lose + mark status (Bug#11795). + 2012-10-16 Juri Linkov * replace.el (query-replace-help): Mention multi-buffer replacement diff --git a/lisp/wdired.el b/lisp/wdired.el index b893e8f6f2b..266d1993389 100644 --- a/lisp/wdired.el +++ b/lisp/wdired.el @@ -180,7 +180,7 @@ program `dired-chmod-program', which must exist." (defvar wdired-col-perm) ;; Column where the permission bits start (defvar wdired-old-content) (defvar wdired-old-point) - +(defvar wdired-old-marks) (defun wdired-mode () "Writable Dired (WDired) mode. @@ -221,6 +221,8 @@ See `wdired-mode'." (error "Not a Dired buffer")) (set (make-local-variable 'wdired-old-content) (buffer-substring (point-min) (point-max))) + (set (make-local-variable 'wdired-old-marks) + (dired-remember-marks (point-min) (point-max))) (set (make-local-variable 'wdired-old-point) (point)) (set (make-local-variable 'query-replace-skip-read-only) t) (set (make-local-variable 'isearch-filter-predicate) @@ -455,7 +457,8 @@ non-nil means return old filename." (push (cons tmp file-new) residue)))) (t (setq progress t) - (let ((file-ori (car rename))) + (let* ((file-ori (car rename)) + (old-mark (cdr (assoc file-ori wdired-old-marks)))) (if wdired-use-interactive-rename (wdired-search-and-rename file-ori file-new) ;; If dired-rename-file autoloads dired-aux while @@ -466,12 +469,17 @@ non-nil means return old filename." (condition-case err (let ((dired-backup-overwrite nil)) (dired-rename-file file-ori file-new - overwrite)) + overwrite) + (dired-remove-file file-ori) + (dired-add-file file-new (if (integerp dired-keep-marker-rename) + dired-keep-marker-rename + old-mark))) (error (setq errors (1+ errors)) (dired-log (concat "Rename `" file-ori "' to `" file-new "' failed:\n%s\n") - err))))))))) + err) + (dired-add-entry file-ori old-mark))))))))) errors))