From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Stephen Berman Newsgroups: gmane.emacs.bugs Subject: bug#27243: dired-auto-revert-buffer jumps point to beginning of buffer Date: Mon, 05 Jun 2017 15:37:47 +0200 Message-ID: <87d1aiy2qc.fsf@rosalinde> References: <87shjf48se.fsf@epsilon> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: blaine.gmane.org 1496669898 18630 195.159.176.226 (5 Jun 2017 13:38:18 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Mon, 5 Jun 2017 13:38:18 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.0.50 (gnu/linux) Cc: 27243@debbugs.gnu.org To: Antoine Levitt Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Mon Jun 05 15:38:14 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 1dHsCz-0004bT-O9 for geb-bug-gnu-emacs@m.gmane.org; Mon, 05 Jun 2017 15:38:13 +0200 Original-Received: from localhost ([::1]:33442 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dHsD5-0007M2-8B for geb-bug-gnu-emacs@m.gmane.org; Mon, 05 Jun 2017 09:38:19 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:56475) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dHsCr-0007Ib-Od for bug-gnu-emacs@gnu.org; Mon, 05 Jun 2017 09:38:11 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dHsCo-0006yK-Kq for bug-gnu-emacs@gnu.org; Mon, 05 Jun 2017 09:38:05 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:53966) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dHsCo-0006yB-G3 for bug-gnu-emacs@gnu.org; Mon, 05 Jun 2017 09:38:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1dHsCo-0007YU-AF for bug-gnu-emacs@gnu.org; Mon, 05 Jun 2017 09:38:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Stephen Berman Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 05 Jun 2017 13:38: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.149666987829033 (code B ref 27243); Mon, 05 Jun 2017 13:38:02 +0000 Original-Received: (at 27243) by debbugs.gnu.org; 5 Jun 2017 13:37:58 +0000 Original-Received: from localhost ([127.0.0.1]:56643 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dHsCk-0007YC-J6 for submit@debbugs.gnu.org; Mon, 05 Jun 2017 09:37:58 -0400 Original-Received: from mout.gmx.net ([212.227.15.15]:63973) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dHsCi-0007Xy-4a for 27243@debbugs.gnu.org; Mon, 05 Jun 2017 09:37:56 -0400 Original-Received: from rosalinde ([83.135.13.98]) by mail.gmx.com (mrgmx002 [212.227.17.190]) with ESMTPSA (Nemesis) id 0M7Hao-1e3lUo3eYI-00x0T6; Mon, 05 Jun 2017 15:37:49 +0200 In-Reply-To: <87shjf48se.fsf@epsilon> (Antoine Levitt's message of "Sun, 04 Jun 2017 16:45:05 -0700") X-Provags-ID: V03:K0:BEGIeCJyDJxAGZZy6n4zNYAtbFocX1oaSTmCtFx7gHPpruoAgNY w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: 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:133293 Archived-At: --=-=-= Content-Type: text/plain On Sun, 04 Jun 2017 16:45:05 -0700 Antoine Levitt wrote: > Tested on git master, the bug is not present on 25. > > Recipe from emacs -Q: > > (setq dired-auto-revert-buffer t) > > open dired, open a folder, C-x b back to the previous dired buffer, open > the same folder again, see point jump back to the beginning of buffer. > > I'm not sure why, since dired-auto-revert-buffer just seems to call > revert-buffer, which does not jump point. 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. One way to fix this is to make dired-restore-positions restore not only point but also window-point. The attached patch does this. Steve Berman --=-=-= Content-Type: text/x-patch Content-Disposition: inline Content-Description: dired-restore-positions patch diff --git a/lisp/dired.el b/lisp/dired.el index 8396652d50..26d3d76817 100644 --- a/lisp/dired.el +++ b/lisp/dired.el @@ -1382,9 +1382,13 @@ dired-restore-positions (let* ((buf-file-pos (nth 0 positions)) (buffer (nth 0 buf-file-pos))) (unless (and (nth 1 buf-file-pos) - (dired-goto-file (nth 1 buf-file-pos))) + (prog1 (dired-goto-file (nth 1 buf-file-pos)) + (set-window-buffer nil buffer) + (set-window-point (selected-window) (nth 2 buf-file-pos)))) (goto-char (nth 2 buf-file-pos)) - (dired-move-to-filename)) + (dired-move-to-filename) + (set-window-buffer nil buffer) + (set-window-point (selected-window) (nth 2 buf-file-pos))) (dolist (win-file-pos (nth 1 positions)) ;; Ensure that window still displays the original buffer. (when (eq (window-buffer (nth 0 win-file-pos)) buffer) @@ -1392,7 +1396,8 @@ dired-restore-positions (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))))))) + (dired-move-to-filename) + (set-window-point nil (point)))))))) (defun dired-remember-marks (beg end) "Return alist of files and their marks, from BEG to END." --=-=-=--