bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#11795: 24.1.50; wdired: C-c C-c loses marks and positions of renamed


From: Juri Linkov
Subject: bug#11795: 24.1.50; wdired: C-c C-c loses marks and positions of renamed files
Date: Fri, 23 Nov 2012 09:30:31 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (x86_64-pc-linux-gnu)

> 1.  When I prepend a letter z to the first file in a buffer, so that it
> will be under the last files after reverting, and I hit C-c C-c, then
> point is at another file afterwards.  This was an issue of the original
> report.

This is not a regression, so it could be fixed in the trunk
in the same way as for `wdired-old-marks', i.e. to store the original
value returned from `dired-save-positions', changing original filenames
to renamed filenames in the returned value, and calling
`dired-restore-positions' with the new value after `revert-buffer'.
A simple patch below does this.

> 2.  If renamed files are also visible in another dired buffer, they
> just disappear there.  That makes no sense.

The problem where other Dired buffers are not updated
in `wdired-finish-edit' is not a regression too.
WDired worked this way from its first version.

If you want, you could try to rewrite WDired so that it correctly
maintains consistency with renamed files without using `revert-buffer'
and by using `dired-add-file' like `dired-do-rename' does.

Your previous patch doesn't do this correctly - it inserts
duplicate file lines, so Dired displays two versions of the same file,
but fortunately `revert-buffer' fixes this mess.

Instead of this, much simpler would be to keep the current design
of WDired that uses `revert-buffer' to maintain consistency with renames.
Then a simpler fix would be to call `revert-buffer' in all other
Dired buffers that display renamed files by using

  (dired-fun-in-all-buffers dired-directory nil (function revert-buffer))

This patch for the trunk demonstrates how these problems could be fixed.
Do you see more problems with this approach?

=== modified file 'lisp/wdired.el'
--- lisp/wdired.el      2012-11-21 10:29:30 +0000
+++ lisp/wdired.el      2012-11-23 07:28:39 +0000
@@ -194,6 +194,7 @@ (defvar wdired-mode-hook nil
 (defvar wdired-col-perm) ;; Column where the permission bits start
 (defvar wdired-old-content)
 (defvar wdired-old-point)
+(defvar wdired-old-positions)
 (defvar wdired-old-marks)
 
 (defun wdired-mode ()
@@ -237,6 +238,8 @@ (defun wdired-change-to-wdired-mode ()
        (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-positions)
+       (dired-save-positions))
   (set (make-local-variable 'wdired-old-point) (point))
   (set (make-local-variable 'query-replace-skip-read-only) t)
   (add-hook 'isearch-filter-predicates 'wdired-isearch-filter-read-only nil t)
@@ -406,6 +409,8 @@ (defun wdired-finish-edit ()
                  (when mark
                    (push (cons (substitute-in-file-name file-new) mark)
                          wdired-old-marks))))
+             (when (equal (cadr (car wdired-old-positions)) file-old)
+               (setcar (cdr (car wdired-old-positions)) file-new))
               (push (cons file-old (substitute-in-file-name file-new))
                     files-renamed))))
        (forward-line -1)))
@@ -423,9 +428,12 @@ (defun wdired-finish-edit ()
                     (= (length files-renamed) 1))
            (setq dired-directory (cdr (car files-renamed))))
          ;; Re-sort the buffer.
-         (revert-buffer)
+         (if (stringp dired-directory)
+             (dired-fun-in-all-buffers dired-directory nil (function 
revert-buffer))
+           (revert-buffer))
          (let ((inhibit-read-only t))
-           (dired-mark-remembered wdired-old-marks)))
+           (dired-mark-remembered wdired-old-marks))
+         (dired-restore-positions wdired-old-positions))
       (let ((inhibit-read-only t))
        (remove-text-properties (point-min) (point-max)
                                '(old-name nil end-name nil old-link nil





reply via email to

[Prev in Thread] Current Thread [Next in Thread]