GNU bug report logs - #4880
point moves in other dired windows

Previous Next

Package: emacs;

Reported by: Per Starbäck <per <at> starback.se>

Date: Fri, 6 Nov 2009 15:45:04 UTC

Severity: normal

Done: Stefan Monnier <monnier <at> IRO.UMontreal.CA>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 4880 in the body.
You can then email your comments to 4880 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-submit-list <at> lists.donarmstrong.com, Emacs Bugs <bug-gnu-emacs <at> gnu.org>:
bug#4880; Package emacs. (Fri, 06 Nov 2009 15:45:04 GMT) Full text and rfc822 format available.

Acknowledgement sent to Per Starbäck <per <at> starback.se>:
New bug report received and forwarded. Copy sent to Emacs Bugs <bug-gnu-emacs <at> gnu.org>. (Fri, 06 Nov 2009 15:45:04 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> emacsbugs.donarmstrong.com (full text, mbox):

From: Per Starbäck <per <at> starback.se>
To: bug-gnu-emacs <at> gnu.org
Subject: point moves in other dired windows
Date: Fri, 6 Nov 2009 16:35:32 +0100
I have done this in 23.1 and in the current cvs version:

emacs -q /tmp
C-x 2 g

Point in the *other* window now goes to the beginning of the buffer,
which was unexpected for me.

dired-revert saves the old point, but only for the current window. The
enclosed patch fixes it so that
dired-revert saves and restores the point in all windows showing that
dired buffer.

$ diff -c dired.el.~1.436~ dired.el
*** dired.el.~1.436~	2009-11-06 13:29:08.000000000 +0100
--- dired.el	2009-11-06 15:35:29.000000000 +0100
***************
*** 1103,1110 ****
  Preserves old cursor, marks/flags, hidden-p."
    (widen)				; just in case user narrowed
    (let ((modflag (buffer-modified-p))
! 	(opoint (point))
! 	(ofile (dired-get-filename nil t))
  	(mark-alist nil)		; save marked files
  	(hidden-subdirs (dired-remember-hidden))
  	(old-subdir-alist (cdr (reverse dired-subdir-alist))) ; except pwd
--- 1103,1109 ----
  Preserves old cursor, marks/flags, hidden-p."
    (widen)				; just in case user narrowed
    (let ((modflag (buffer-modified-p))
! 	(positions (dired-save-positions))
  	(mark-alist nil)		; save marked files
  	(hidden-subdirs (dired-remember-hidden))
  	(old-subdir-alist (cdr (reverse dired-subdir-alist))) ; except pwd
***************
*** 1124,1132 ****
      ;; ... run the hook for the whole buffer, and only after markers
      ;; have been reinserted (else omitting in dired-x would omit marked files)
      (run-hooks 'dired-after-readin-hook)	; no need to narrow
!     (or (and ofile (dired-goto-file ofile)) ; move cursor to where it
! 	(goto-char opoint))		; was before
!     (dired-move-to-filename)
      (save-excursion			; hide subdirs that were hidden
        (dolist (dir hidden-subdirs)
  	(if (dired-goto-subdir dir)
--- 1123,1129 ----
      ;; ... run the hook for the whole buffer, and only after markers
      ;; have been reinserted (else omitting in dired-x would omit marked files)
      (run-hooks 'dired-after-readin-hook)	; no need to narrow
!     (dired-restore-positions positions)
      (save-excursion			; hide subdirs that were hidden
        (dolist (dir hidden-subdirs)
  	(if (dired-goto-subdir dir)
***************
*** 1140,1145 ****
--- 1137,1161 ----
  ;; Subroutines of dired-revert
  ;; Some of these are also used when inserting subdirs.

+ (defun dired-save-positions ()
+   "Store the current positions in all windows displaying this dired buffer.
+ Store both filename (if any) and 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))
+ 	(dired-move-to-filename)))))
+
  (defun dired-remember-marks (beg end)
    "Return alist of files and their marks, from BEG to END."
    (if selective-display			; must unhide to make this work.




Reply sent to Stefan Monnier <monnier <at> IRO.UMontreal.CA>:
You have taken responsibility. (Thu, 12 Nov 2009 22:45:04 GMT) Full text and rfc822 format available.

Notification sent to Per Starbäck <per <at> starback.se>:
bug acknowledged by developer. (Thu, 12 Nov 2009 22:45:04 GMT) Full text and rfc822 format available.

Message #10 received at 4880-done <at> emacsbugs.donarmstrong.com (full text, mbox):

From: Stefan Monnier <monnier <at> IRO.UMontreal.CA>
To: Per Starbäck <per <at> starback.se>
Subject: Re: bug#4880: point moves in other dired windows
Date: Thu, 12 Nov 2009 17:38:51 -0500
> dired-revert saves the old point, but only for the current window. The
> enclosed patch fixes it so that dired-revert saves and restores the
> point in all windows showing that dired buffer.

Thank you, installed,


        Stefan



Information forwarded to bug-submit-list <at> lists.donarmstrong.com, Emacs Bugs <bug-gnu-emacs <at> gnu.org>:
bug#4880; Package emacs. (Fri, 04 Dec 2009 22:00:04 GMT) Full text and rfc822 format available.

Acknowledgement sent to Juri Linkov <juri <at> jurta.org>:
Extra info received and forwarded to list. Copy sent to Emacs Bugs <bug-gnu-emacs <at> gnu.org>. (Fri, 04 Dec 2009 22:00:04 GMT) Full text and rfc822 format available.

Message #15 received at 4880 <at> emacsbugs.donarmstrong.com (full text, mbox):

From: Juri Linkov <juri <at> jurta.org>
To: Stefan Monnier <monnier <at> IRO.UMontreal.CA>
Cc: Per Starbäck <per <at> starback.se>,
        4880 <at> debbugs.gnu.org
Subject: Re: bug#4880: point moves in other dired windows
Date: Fri, 04 Dec 2009 23:49:28 +0200
> Unfortunately, this doesn't work for dired buffers that are
> not displayed in a window.  This is a really annoying problem.

What about the following patch that also restores buffer's point positions
after dired-revert in hidden dired buffers?

Index: lisp/dired.el
===================================================================
RCS file: /sources/emacs/emacs/lisp/dired.el,v
retrieving revision 1.446
diff -c -r1.446 dired.el
*** lisp/dired.el	4 Dec 2009 05:00:44 -0000	1.446
--- lisp/dired.el	4 Dec 2009 21:49:19 -0000
***************
*** 1143,1161 ****
  ;; 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))
--- 1170,1211 ----
  ;; Some of these are also used when inserting subdirs.
  
  (defun dired-save-positions ()
!   "Return the current positions in all buffers and windows with this directory.
! The positions have the form (BUFFER-POSITIONS WINDOW-POSITIONS).
! 
! BUFFER-POSITIONS are positions in all dired buffers associated with
! the current directory.  The buffer positions have the form (BUFFER
! 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
!    (mapcar (lambda (buffer)
! 	     (cons buffer
! 		   (with-current-buffer buffer
! 		     (list
! 		      (dired-get-filename nil t)
! 		      (point)))))
! 	   (dired-buffers-for-dir
! 	    (if (consp dired-directory) (car dired-directory) dired-directory)))
!    (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 (buf-file-pos (nth 0 positions))
!     (with-current-buffer (nth 0 buf-file-pos)
!       (unless (and (nth 1 buf-file-pos)
! 		   (dired-goto-file (nth 1 buf-file-pos)))
! 	(goto-char (nth 2 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/



Information forwarded to bug-submit-list <at> lists.donarmstrong.com, Emacs Bugs <bug-gnu-emacs <at> gnu.org>:
bug#4880; Package emacs. (Sat, 05 Dec 2009 05:05:04 GMT) Full text and rfc822 format available.

Acknowledgement sent to Stefan Monnier <monnier <at> iro.umontreal.ca>:
Extra info received and forwarded to list. Copy sent to Emacs Bugs <bug-gnu-emacs <at> gnu.org>. (Sat, 05 Dec 2009 05:05:04 GMT) Full text and rfc822 format available.

Message #20 received at 4880 <at> emacsbugs.donarmstrong.com (full text, mbox):

From: Stefan Monnier <monnier <at> iro.umontreal.ca>
To: Juri Linkov <juri <at> jurta.org>
Cc: Per Starbäck <per <at> starback.se>,
        4880 <at> debbugs.gnu.org
Subject: Re: bug#4880: point moves in other dired windows
Date: Sat, 05 Dec 2009 00:00:47 -0500
> !   (list
> !    (mapcar (lambda (buffer)
> ! 	     (cons buffer
> ! 		   (with-current-buffer buffer
> ! 		     (list
> ! 		      (dired-get-filename nil t)
> ! 		      (point)))))
> ! 	   (dired-buffers-for-dir
> ! 	    (if (consp dired-directory) (car dired-directory) dired-directory)))
> !    (mapcar (lambda (w)
> ! 	     (list w
> ! 		   (with-selected-window w
> ! 		     (dired-get-filename nil t))
> ! 		   (window-point w)))
> ! 	   (get-buffer-window-list nil 0 t))))

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)?


        Stefan



Information forwarded to bug-submit-list <at> lists.donarmstrong.com, Emacs Bugs <bug-gnu-emacs <at> gnu.org>:
bug#4880; Package emacs. (Sat, 05 Dec 2009 19:55:09 GMT) Full text and rfc822 format available.

Acknowledgement sent to Juri Linkov <juri <at> jurta.org>:
Extra info received and forwarded to list. Copy sent to Emacs Bugs <bug-gnu-emacs <at> gnu.org>. (Sat, 05 Dec 2009 19:55:09 GMT) Full text and rfc822 format available.

Message #25 received at 4880 <at> emacsbugs.donarmstrong.com (full text, mbox):

From: Juri Linkov <juri <at> jurta.org>
To: Stefan Monnier <monnier <at> iro.umontreal.ca>
Cc: Per Starbäck <per <at> starback.se>,
        4880 <at> debbugs.gnu.org
Subject: Re: bug#4880: point moves in other dired windows
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/



Information forwarded to bug-submit-list <at> lists.donarmstrong.com, Emacs Bugs <bug-gnu-emacs <at> gnu.org>:
bug#4880; Package emacs. (Sat, 05 Dec 2009 21:15:06 GMT) Full text and rfc822 format available.

Acknowledgement sent to Stefan Monnier <monnier <at> iro.umontreal.ca>:
Extra info received and forwarded to list. Copy sent to Emacs Bugs <bug-gnu-emacs <at> gnu.org>. (Sat, 05 Dec 2009 21:15:06 GMT) Full text and rfc822 format available.

Message #30 received at 4880 <at> emacsbugs.donarmstrong.com (full text, mbox):

From: Stefan Monnier <monnier <at> iro.umontreal.ca>
To: Juri Linkov <juri <at> jurta.org>
Cc: Per Starbäck <per <at> starback.se>,
        4880 <at> debbugs.gnu.org
Subject: Re: bug#4880: point moves in other dired windows
Date: Sat, 05 Dec 2009 16:09:30 -0500
> Since other buffers of the same dir won't be reverted, then yes,
> there is no point in saving their points.

That looks good, thanks.  Just one more thing:

>   (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))

In restore, we should check that the window's buffer is still "our
buffer".  In some rare occasions, revert-buffer may cause some prompt or
other thing that may change some window's configuration, so better be
safe than sorry.
I know this is not a new problem in your code, but while we're here, can
you fix this other one as well (and then commit)?


        Stefan



Information forwarded to bug-submit-list <at> lists.donarmstrong.com, Emacs Bugs <bug-gnu-emacs <at> gnu.org>:
bug#4880; Package emacs. (Sat, 05 Dec 2009 23:30:06 GMT) Full text and rfc822 format available.

Acknowledgement sent to Juri Linkov <juri <at> jurta.org>:
Extra info received and forwarded to list. Copy sent to Emacs Bugs <bug-gnu-emacs <at> gnu.org>. (Sat, 05 Dec 2009 23:30:06 GMT) Full text and rfc822 format available.

Message #35 received at 4880 <at> emacsbugs.donarmstrong.com (full text, mbox):

From: Juri Linkov <juri <at> jurta.org>
To: Stefan Monnier <monnier <at> iro.umontreal.ca>
Cc: Per Starbäck <per <at> starback.se>,
        4880 <at> debbugs.gnu.org
Subject: Re: bug#4880: point moves in other dired windows
Date: Sun, 06 Dec 2009 01:22:19 +0200
> In restore, we should check that the window's buffer is still "our
> buffer".  In some rare occasions, revert-buffer may cause some prompt or
> other thing that may change some window's configuration, so better be
> safe than sorry.

Done.

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



bug archived. Request was from Debbugs Internal Request <bug-gnu-emacs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Fri, 29 Jan 2010 12:24:05 GMT) Full text and rfc822 format available.

This bug report was last modified 15 years and 145 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.