From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Eli Zaretskii Newsgroups: gmane.emacs.bugs Subject: bug#27243: dired-auto-revert-buffer jumps point to beginning of buffer Date: Mon, 05 Jun 2017 18:02:14 +0300 Message-ID: <83poeia361.fsf@gnu.org> References: <87shjf48se.fsf@epsilon> <87d1aiy2qc.fsf@rosalinde> Reply-To: Eli Zaretskii NNTP-Posting-Host: blaine.gmane.org X-Trace: blaine.gmane.org 1496674995 22312 195.159.176.226 (5 Jun 2017 15:03:15 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Mon, 5 Jun 2017 15:03:15 +0000 (UTC) Cc: 27243@debbugs.gnu.org, antoine.levitt@gmail.com To: Stephen Berman Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Mon Jun 05 17:03:11 2017 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dHtXD-0005Nq-Am for geb-bug-gnu-emacs@m.gmane.org; Mon, 05 Jun 2017 17:03:11 +0200 Original-Received: from localhost ([::1]:33812 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dHtXF-00015G-IA for geb-bug-gnu-emacs@m.gmane.org; Mon, 05 Jun 2017 11:03:13 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:50559) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dHtX9-00014z-IA for bug-gnu-emacs@gnu.org; Mon, 05 Jun 2017 11:03:08 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dHtX4-0006xE-IA for bug-gnu-emacs@gnu.org; Mon, 05 Jun 2017 11:03:07 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:55036) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dHtX4-0006wu-Eq for bug-gnu-emacs@gnu.org; Mon, 05 Jun 2017 11:03:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1dHtX4-0001H8-4a for bug-gnu-emacs@gnu.org; Mon, 05 Jun 2017 11:03:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Eli Zaretskii Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 05 Jun 2017 15:03:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 27243 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 27243-submit@debbugs.gnu.org id=B27243.14966749564867 (code B ref 27243); Mon, 05 Jun 2017 15:03:02 +0000 Original-Received: (at 27243) by debbugs.gnu.org; 5 Jun 2017 15:02:36 +0000 Original-Received: from localhost ([127.0.0.1]:57713 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dHtWe-0001GR-HP for submit@debbugs.gnu.org; Mon, 05 Jun 2017 11:02:36 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:59475) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dHtWc-0001GE-Oo for 27243@debbugs.gnu.org; Mon, 05 Jun 2017 11:02:35 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dHtWS-0006X3-Eo for 27243@debbugs.gnu.org; Mon, 05 Jun 2017 11:02:29 -0400 Original-Received: from fencepost.gnu.org ([2001:4830:134:3::e]:40531) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dHtWS-0006Wy-B3; Mon, 05 Jun 2017 11:02:24 -0400 Original-Received: from 84.94.185.246.cable.012.net.il ([84.94.185.246]:1239 helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:RSA_AES_256_CBC_SHA1:256) (Exim 4.82) (envelope-from ) id 1dHtWR-0001d1-KK; Mon, 05 Jun 2017 11:02:24 -0400 In-reply-to: <87d1aiy2qc.fsf@rosalinde> (message from Stephen Berman on Mon, 05 Jun 2017 15:37:47 +0200) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:133295 Archived-At: > From: Stephen Berman > Date: Mon, 05 Jun 2017 15:37:47 +0200 > Cc: 27243@debbugs.gnu.org > > I think I see why this happens. I assume when you opened "the same > folder again" you pressed RET on the line in the Dired listing. That > calls dired-find-file, which calls find-file, which first calls > find-file-noselect (to see if it's a live buffer), which calls (via > run-hook-with-args-until-success) dired-noselect, which calls (via > dired-internal-noselect) revert-buffer (since dired-auto-revert-buffer > is t), which calls dired-revert, which saves point (via > dired-save-positions) but then erases the buffer and inserts it anew -- > and this is the problem, because now continuing in find-file, it calls > switch-to-buffer (since it's a live buffer that you're revisiting), > which sets window-point by consulting window-prev-buffers. Prior to the > invocation of erase-buffer, window-prev-buffers contained this entry for > the buffer being reverted ("test" in my test case): > > (# # #) > > which shows window-point on the first file name in the Dired listing, > but after erase-buffer it's now this: > > (# # #) > > Since dired-revert restored the saved point (232) but does not return it > to the caller, switch-to-buffer does not have this information, but only > what window-prev-buffers shows, which is now 1. So that's what it sets > window-point to. Right, I see the same. > One way to fix this is to make dired-restore-positions restore not only > point but also window-point. The attached patch does this. An alternative is to bind switch-to-buffer-preserve-window-point to nil (the whole problem was caused by the fact that this variable is now non-nil by default, and dired-revert runs afoul of it, as you point out): --- lisp/dired.el~0 2017-02-28 06:27:41.000000000 +0200 +++ lisp/dired.el 2017-06-05 17:51:50.633645200 +0300 @@ -2126,7 +2126,11 @@ (interactive) ;; Bind `find-file-run-dired' so that the command works on directories ;; too, independent of the user's setting. - (let ((find-file-run-dired t)) + (let ((find-file-run-dired t) + (switch-to-buffer-preserve-window-point + (if dired-auto-revert-buffer + nil + switch-to-buffer-preserve-window-point))) (find-file (dired-get-file-for-visit)))) (defun dired-find-alternate-file () I'm not sure which solution is better. Maybe someone will come up with a more elegant one. Thanks.