GNU bug report logs - #33871
27.0.50; Revert Dired window saved in window configuration

Previous Next

Package: emacs;

Reported by: Juri Linkov <juri <at> linkov.net>

Date: Tue, 25 Dec 2018 21:43:01 UTC

Severity: minor

Found in version 27.0.50

Fixed in version 30.0.50

Done: Juri Linkov <juri <at> linkov.net>

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: Juri Linkov <juri <at> linkov.net>
To: martin rudalics <rudalics <at> gmx.at>
Cc: 33871 <at> debbugs.gnu.org, Lars Ingebrigtsen <larsi <at> gnus.org>
Subject: bug#33871: 27.0.50; Revert Dired window saved in window configuration
Date: Thu, 17 Feb 2022 19:28:18 +0200
>> Instead of (goto-char p-m), after (set-window-configuration w-c)
>> something like this should be performed:
>>
>>    (dired-goto-file (car (cdr (assoc (current-buffer)
>>                                      (window-parameter nil 'dired-positions)))))
>
> Once more: Your scenario is
>
> (progn (dired "/tmp") (dired-next-line 1)
>        (split-window) (other-window 1)
>        (dired "/tmp") (dired-next-line 2)
>        (let ((w-c (current-window-configuration))
> 	     (p-m (point-marker)))
> 	 (view-emacs-todo) (delete-other-windows)
> 	 (with-current-buffer (get-buffer "tmp")
> 	   (revert-buffer))
> 	 (set-window-configuration w-c)
> 	 (goto-char p-m)))
>
> But this cannot work with dired buffers because they are reverted in a
> special way that does not care about 'window-point' and the like.  This
> means that the value of 'point-marker' you saved in p-m has become just
> meaningless after the 'revert-buffer' call.
>
> Basically, this is a hard problem we'll probably never be able to solve
> satisfactorily.

But this works fine:

  (progn (dired "/tmp") (dired-next-line 1)
         (split-window) (other-window 1)
         (dired "/tmp") (dired-next-line 2)
         (walk-windows
          (lambda (w)
            (set-window-parameter
             w 'dired-positions
             (list (with-selected-window w
                     (dired-get-filename nil t))
                   (window-start w)
                   (window-point w)))))
         (let ((w-c (current-window-configuration)))
           (view-emacs-todo) (delete-other-windows)
           (with-current-buffer (get-buffer "tmp")
             (revert-buffer))
           (set-window-configuration w-c)
           (walk-windows
            (lambda (w)
              (let ((pos (window-parameter w 'dired-positions)))
                (when pos
                  (with-selected-window w
                    (dired-goto-file (nth 0 pos)))
                  (set-window-start w (nth 1 pos))
                  (set-window-point w (nth 2 pos))))))))

> We could handle 'window-point' separately when saving and restoring
> window configurations and the window's buffer is a dired buffer.  For
> example, 'dired-revert' could call a function 'window-revert-timestamp'
> to store the current time of the revert operation for this window and
> 'current-window-configuration' (and 'window-state-get') would store
> their current time stamp in the configuration (or state).  Then
> 'set-window-configuration' (and 'window-state-put') could check whether
> a window's revert time stamp is larger than the time stamp stored in the
> configuration and not set point for that window when the revert time
> stamp is later.  Is it worth the hassle?

I think it's not worth the hassle.  The above solution is simpler.




This bug report was last modified 1 year and 102 days ago.

Previous Next


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