unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: martin rudalics <rudalics@gmx.at>
To: v88m@posteo.net, 33458@debbugs.gnu.org
Subject: bug#33458: 27.0.50; dired loses position when reverted from outside place
Date: Tue, 04 Dec 2018 09:33:26 +0100	[thread overview]
Message-ID: <5C063BD6.5020707@gmx.at> (raw)
In-Reply-To: <87k1l6f9li@posteo.net>

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

 > If dired buffer reverted from outside it, cursor jumps to begin of the
 > buffer once this buffer becomes current again.
 >
 > How to reproduce:
 >
 > 0. emacs -Q
 >
 > 1. Open some directory, say "DIR-A" in dired.
 >
 > 2. Move cursor to subdirectory, say "DIR-B", M-: (point) ;=> e.g. 225.
 >
 > 3. Dive into subdirectory "DIR-B".
 >
 > 4. Let's check position: M-: (with-current-buffer "DIR-A" (point)) ;=> 225, so cursor in the right place.
 >
 > 5. Revert original buffer: M-: (with-current-buffer "DIR-A" (dired-revert))
 >
 > 6. Check position again: M-: (with-current-buffer "DIR-A" (point)) ;=> 225, seems right here...
 >
 > 7. Switch back from the buffer with "DIR-B" to the buffer with "DIR-A".
 >
 > 8. Position lost! M-: (point) ;=> 1, but 225 expected.
 >
 > The issue very spunky if auto-revert-mode is used.
 >
 > Can't reproduce this issue with regular buffer, so it seems dired-specific.

The attached patch should fix this problem and the other ones with
'dired' that have been cited in this context.  Please try it.

Thanks, martin

[-- Attachment #2: dired.diffs --]
[-- Type: text/plain, Size: 2668 bytes --]

diff --git a/lisp/dired.el b/lisp/dired.el
index cbd85fe..e5dc862 100644
--- a/lisp/dired.el
+++ b/lisp/dired.el
@@ -1478,12 +1478,36 @@ dired-save-positions
                (list w
 		     (dired-get-filename nil t)
                      (line-number-at-pos (window-point w)))))
-	   (get-buffer-window-list nil 0 t))))
+	   (get-buffer-window-list nil 0 t))
+   ;; For each window that showed the current buffer before, scan its
+   ;; list of previous buffers.  For each association thus found save
+   ;; a triple <point, name, line> where 'point' is that window's
+   ;; window-point marker stored in the window's list of previous
+   ;; buffers, 'name' is the filename at the position of 'point' and
+   ;; 'line' is the line number at the position of 'point'.
+   (let ((buffer (current-buffer))
+         prevs)
+     (walk-windows
+      (lambda (window)
+        (let ((prev (assq buffer (window-prev-buffers window))))
+          (when prev
+            (with-current-buffer buffer
+              (save-excursion
+                (goto-char (nth 2 prev))
+                (setq prevs
+                      (cons
+                       (list (nth 2 prev)
+                             (dired-get-filename nil t)
+                             (line-number-at-pos (point)))
+                       prevs)))))))
+      'nomini t)
+     prevs)))
 
 (defun dired-restore-positions (positions)
   "Restore POSITIONS saved with `dired-save-positions'."
   (let* ((buf-file-pos (nth 0 positions))
-	 (buffer (nth 0 buf-file-pos)))
+	 (buffer (nth 0 buf-file-pos))
+         (prevs (nth 2 positions)))
     (unless (and (nth 1 buf-file-pos)
 		 (dired-goto-file (nth 1 buf-file-pos)))
       (goto-char (point-min))
@@ -1497,7 +1521,21 @@ dired-restore-positions
 		       (dired-goto-file (nth 1 win-file-pos)))
             (goto-char (point-min))
 	    (forward-line (1- (nth 2 win-file-pos)))
-	    (dired-move-to-filename)))))))
+	    (dired-move-to-filename)))))
+    (when prevs
+      (with-current-buffer buffer
+        (save-excursion
+          (dolist (prev prevs)
+            (let ((point (nth 0 prev)))
+              ;; Sanity check of the point marker.
+              (when (and (markerp point)
+                         (eq (marker-buffer point) buffer))
+                (unless (and (nth 0 prev)
+                             (dired-goto-file (nth 1 prev)))
+                  (goto-char (point-min))
+	          (forward-line (1- (nth 2 prev))))
+	        (dired-move-to-filename)
+                (move-marker point (point) buffer)))))))))
 
 (defun dired-remember-marks (beg end)
   "Return alist of files and their marks, from BEG to END."

  parent reply	other threads:[~2018-12-04  8:33 UTC|newest]

Thread overview: 65+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-11-21 20:40 bug#33458: 27.0.50; dired loses position when reverted from outside place v88m
2018-11-21 22:33 ` Stephen Berman
2018-11-22  9:07   ` v88m
2018-11-22  9:38     ` Stephen Berman
2018-11-23  7:41     ` martin rudalics
2018-11-23 15:40       ` v88m
2018-11-23 19:03         ` martin rudalics
2018-11-23 19:55           ` v88m
2018-11-25 20:45           ` Juri Linkov
2018-11-26  9:32             ` martin rudalics
2018-11-27  0:09               ` Juri Linkov
2018-11-27  8:08                 ` martin rudalics
2018-11-28  0:06                   ` Juri Linkov
2018-11-28  8:35                     ` martin rudalics
2018-11-28 23:45                       ` Juri Linkov
2018-11-29  7:41                         ` Eli Zaretskii
2018-11-29 22:33                           ` Juri Linkov
2018-11-30  7:05                             ` v88m
2018-12-01 22:33                               ` Juri Linkov
2018-11-30  8:21                             ` martin rudalics
2018-11-29  8:31                         ` martin rudalics
2018-11-29 22:46                           ` Juri Linkov
2018-11-30  7:10                             ` v88m
2018-11-30  8:22                               ` martin rudalics
2018-11-30  8:21                             ` martin rudalics
2018-12-01 22:30                               ` Juri Linkov
2018-12-02  8:33                                 ` martin rudalics
2018-12-04  8:33 ` martin rudalics [this message]
2018-12-04 14:41   ` v88m
2018-12-05  9:17     ` martin rudalics
2018-12-08  9:41       ` martin rudalics
2018-12-10  0:10         ` Juri Linkov
2018-12-10  7:58           ` martin rudalics
2018-12-10 23:59             ` Juri Linkov
2018-12-11  8:34               ` martin rudalics
2018-12-12  0:40                 ` Juri Linkov
2018-12-12  8:32                   ` martin rudalics
2018-12-12 23:29                     ` Juri Linkov
2018-12-13  9:02                       ` martin rudalics
2018-12-14  9:33                         ` martin rudalics
2018-12-16 23:49                           ` Juri Linkov
2018-12-17  8:06                             ` martin rudalics
2018-12-18  0:25                               ` Juri Linkov
2018-12-18  8:28                                 ` martin rudalics
2018-12-21  0:59                                   ` Juri Linkov
2018-12-21  9:15                                     ` martin rudalics
2018-12-22 23:36                                       ` Juri Linkov
2018-12-23  9:40                                         ` martin rudalics
2018-12-23 19:06                                           ` martin rudalics
2018-12-23 23:47                                             ` Juri Linkov
2018-12-24  8:15                                               ` martin rudalics
2018-12-25 21:25                                                 ` Juri Linkov
2018-12-26  9:42                                                   ` martin rudalics
2018-12-27  0:29                                                     ` Juri Linkov
2018-12-27  9:37                                                       ` martin rudalics
2020-08-22 14:49                                                         ` Lars Ingebrigtsen
2020-08-23 18:42                                                           ` Juri Linkov
2020-08-24 13:15                                                             ` Lars Ingebrigtsen
2018-12-13  7:39   ` v88m
2018-12-13  9:02     ` martin rudalics
2018-12-13  9:35       ` v88m
2018-12-13 10:10         ` martin rudalics
2018-12-14  8:25           ` v88m
2018-12-14  9:34             ` martin rudalics
2018-12-14 10:01               ` v88m

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=5C063BD6.5020707@gmx.at \
    --to=rudalics@gmx.at \
    --cc=33458@debbugs.gnu.org \
    --cc=v88m@posteo.net \
    /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).