unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Stephen Berman <stephen.berman@gmx.net>
To: Antoine Levitt <antoine.levitt@gmail.com>
Cc: 27243@debbugs.gnu.org
Subject: bug#27243: dired-auto-revert-buffer jumps point to beginning of buffer
Date: Mon, 05 Jun 2017 15:37:47 +0200	[thread overview]
Message-ID: <87d1aiy2qc.fsf@rosalinde> (raw)
In-Reply-To: <87shjf48se.fsf@epsilon> (Antoine Levitt's message of "Sun, 04 Jun 2017 16:45:05 -0700")

[-- Attachment #1: Type: text/plain, Size: 1966 bytes --]

On Sun, 04 Jun 2017 16:45:05 -0700 Antoine Levitt <antoine.levitt@gmail.com> 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):

(#<buffer test> #<marker at 1 in test> #<marker at 232 in test>)

which shows window-point on the first file name in the Dired listing,
but after erase-buffer it's now this:

(#<buffer test> #<marker at 1 in test> #<marker at 1 in test>)

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


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: dired-restore-positions patch --]
[-- Type: text/x-patch, Size: 1247 bytes --]

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."

  reply	other threads:[~2017-06-05 13:37 UTC|newest]

Thread overview: 48+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-06-04 23:45 bug#27243: dired-auto-revert-buffer jumps point to beginning of buffer Antoine Levitt
2017-06-05 13:37 ` Stephen Berman [this message]
2017-06-05 15:02   ` Eli Zaretskii
2017-06-05 15:15     ` Stephen Berman
2017-06-05 16:20       ` Eli Zaretskii
2017-06-10  8:24         ` Eli Zaretskii
     [not found]           ` <CABfD5m0==QAKYoJDkaPQxoyS1BQT-eTQJLmYZC6Z-V5A0jfeig@mail.gmail.com>
2017-06-10  8:45             ` Antoine Levitt
     [not found] ` <handler.27243.D27243.14970831096548.notifdone@debbugs.gnu.org>
2017-06-17 12:16   ` bug#27243: closed (Re: bug#27243: dired-auto-revert-buffer jumps point to beginning of buffer) Antoine Levitt
2017-06-17 13:32     ` Stephen Berman
2017-07-09 17:37       ` Antoine Levitt
2017-07-14  9:56         ` Stephen Berman
2017-07-15  5:52           ` John Wiegley
2017-07-15  7:18             ` Eli Zaretskii
2017-07-17  9:22         ` Stephen Berman
2017-07-22 15:28           ` Antoine Levitt
2017-07-22 16:55             ` Glenn Morris
2017-07-22 22:48               ` Stephen Berman
2017-07-22 22:48             ` bug#27243: another case: dired-auto-revert-buffer jumps point to beginning of buffer Stephen Berman
2017-07-23 14:43               ` Eli Zaretskii
2017-07-23 18:40                 ` martin rudalics
2017-07-23 18:58                   ` Eli Zaretskii
2017-07-23 21:09                     ` martin rudalics
2017-07-28  8:49                       ` Stephen Berman
2017-07-28  9:28                         ` Eli Zaretskii
2017-07-28 12:22                         ` martin rudalics
2017-07-28 13:02                         ` Stefan Monnier
2017-07-28 13:12                           ` Eli Zaretskii
2017-07-28 13:16                             ` Stefan Monnier
2017-07-28 13:41                               ` Eli Zaretskii
2017-07-28 14:14                               ` martin rudalics
2017-07-28 14:45                                 ` Eli Zaretskii
2017-07-28 14:54                                   ` Stephen Berman
2017-07-29 11:44                                   ` Stephen Berman
2020-05-25  4:21                                     ` Michael Heerdegen
     [not found]                                     ` <874ks4ekpg.fsf@web.de>
2020-05-25  7:26                                       ` Stephen Berman
2020-05-25 23:36                                         ` Michael Heerdegen
2020-05-27  1:23                                         ` Michael Heerdegen
2020-05-27  5:36                                           ` Michael Heerdegen
2020-05-27 14:52                                             ` martin rudalics
2020-05-27 17:01                                               ` Michael Heerdegen
2020-05-27 17:56                                                 ` martin rudalics
2020-05-30 22:11                                               ` Juri Linkov
2020-05-26  8:02                                       ` martin rudalics
2020-05-27  1:16                                         ` Michael Heerdegen
2017-07-15  7:36       ` bug#27243: closed (Re: bug#27243: dired-auto-revert-buffer jumps point to beginning of buffer) martin rudalics
2017-07-15 11:14         ` Stephen Berman
2017-07-15 13:59           ` martin rudalics
2017-07-17  9:28             ` Stephen Berman

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87d1aiy2qc.fsf@rosalinde \
    --to=stephen.berman@gmx.net \
    --cc=27243@debbugs.gnu.org \
    --cc=antoine.levitt@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).