Subject: Re: bug#4880: point moves in other dired windows

From: Juri Linkov <[email-masked]>
Date: Sat, 05 Dec 2009 21:42:16 +0200

> I do not understand, why we save the point of all
> "dired-buffers-for-dir" but only the point of the windows showing the
> current buffer.
> I'd prefer to resolve this discrepancy by only saving the current
> buffer's point (after all, the other buffer's won't be affected by the
> revert, right)?

Since other buffers of the same dir won't be reverted, then yes,
there is no point in saving their points.

Index: lisp/dired.el
===================================================================
RCS file: /sources/emacs/emacs/lisp/dired.el,v
retrieving revision 1.447
diff -c -r1.447 dired.el
*** lisp/dired.el	4 Dec 2009 21:45:34 -0000	1.447
--- lisp/dired.el	5 Dec 2009 19:39:39 -0000
***************
*** 1169,1187 ****
  ;; Some of these are also used when inserting subdirs.
  
  (defun dired-save-positions ()
!   "Return the current positions in all windows displaying this dired buffer.
! The positions have the form (WINDOW FILENAME POINT)."
!   (mapcar (lambda (w)
! 	    (list w
! 		  (with-selected-window w
! 		    (dired-get-filename nil t))
! 		  (window-point w)))
! 	  (get-buffer-window-list nil 0 t)))
  
  (defun dired-restore-positions (positions)
    "Restore POSITIONS saved with `dired-save-positions'."
!   (dolist (win-file-pos positions)
!     (with-selected-window (car win-file-pos)
        (unless (and (nth 1 win-file-pos)
  		   (dired-goto-file (nth 1 win-file-pos)))
  	(goto-char (nth 2 win-file-pos))
--- 1169,1201 ----
  ;; Some of these are also used when inserting subdirs.
  
  (defun dired-save-positions ()
!   "Return current positions in the buffer and all windows with this directory.
! The positions have the form (BUFFER-POSITION WINDOW-POSITIONS).
! 
! BUFFER-POSITION is the point position in the current dired buffer.
! The buffer position have the form (DIRED-FILENAME BUFFER-POINT).
! 
! WINDOW-POSITIONS are current positions in all windows displaying
! this dired buffer.  The window positions have the form (WINDOW
! DIRED-FILENAME WINDOW-POINT)."
!   (list
!    (list (dired-get-filename nil t) (point))
!    (mapcar (lambda (w)
! 	     (list w
! 		   (with-selected-window w
! 		     (dired-get-filename nil t))
! 		   (window-point w)))
! 	   (get-buffer-window-list nil 0 t))))
  
  (defun dired-restore-positions (positions)
    "Restore POSITIONS saved with `dired-save-positions'."
!   (let ((buf-file-pos (nth 0 positions)))
!     (unless (and (nth 0 buf-file-pos)
! 		 (dired-goto-file (nth 0 buf-file-pos)))
!       (goto-char (nth 1 buf-file-pos))
!       (dired-move-to-filename)))
!   (dolist (win-file-pos (nth 1 positions))
!     (with-selected-window (nth 0 win-file-pos)
        (unless (and (nth 1 win-file-pos)
  		   (dired-goto-file (nth 1 win-file-pos)))
  	(goto-char (nth 2 win-file-pos))

-- 
Juri Linkov
http://www.jurta.org/emacs/