GNU bug report logs - #33532
26.1; set-window-configuration does not restore display start

Previous Next

Package: emacs;

Reported by: Markus Triska <triska <at> metalevel.at>

Date: Tue, 27 Nov 2018 22:12:02 UTC

Severity: normal

Merged with 33533

Found in version 26.1

To reply to this bug, email your comments to 33532 AT debbugs.gnu.org.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#33532; Package emacs. (Tue, 27 Nov 2018 22:12:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Markus Triska <triska <at> metalevel.at>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Tue, 27 Nov 2018 22:12:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Markus Triska <triska <at> metalevel.at>
To: bug-gnu-emacs <at> gnu.org
Subject: 26.1; set-window-configuration does not restore display start
Date: Tue, 27 Nov 2018 23:11:21 +0100
In "emacs -Q", please evaluate the following form:

    (let ((buf (get-buffer-create "buf")))
      (switch-to-buffer buf)
      (erase-buffer)
      (dotimes (x 10)
        (insert (format "x is %s\n" x)))
      (recenter 3)
      (sit-for 1)
      (let ((conf (current-window-configuration))
            (ws (window-start))
            (str (with-current-buffer buf (buffer-string))))
        (with-current-buffer buf
          (erase-buffer)
          (insert str))
        (set-window-configuration conf)
        (sit-for 1)
        (message "window-start: %s vs. %s" ws (window-start))))

This shows that after set-window-configuration, even though the buffer
content is the same as at the time the configuration was obtained, the
value of (window-start) differs from before: After the window
configuration is set, (window-start) is 1. I expect it to be 50 (i.e.,
the value at the time the configuration was obtained), because the
documentation of current-window-configuration states:

    This describes ... for each ... buffer, where display starts ...

If possible, could you please consider restoring window-start to the
exact same position? Thank you very much!

In GNU Emacs 26.1 (build 1, x86_64-pc-linux-gnu, X toolkit, Xaw scroll bars)
 of 2018-11-18 built on debian
Repository revision: 07f8f9bc5a51f5aa94eb099f3e15fbe0c20ea1ea
Windowing system distributor 'The X.Org Foundation', version 11.0.11902000
System Description:	Debian GNU/Linux 9.6 (stretch)






Merged 33532 33533. Request was from Glenn Morris <rgm <at> gnu.org> to control <at> debbugs.gnu.org. (Wed, 28 Nov 2018 00:48:01 GMT) Full text and rfc822 format available.

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#33532; Package emacs. (Wed, 28 Nov 2018 06:42:02 GMT) Full text and rfc822 format available.

Message #10 received at 33532 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Markus Triska <triska <at> metalevel.at>
Cc: 33532 <at> debbugs.gnu.org
Subject: Re: bug#33532: 26.1;
 set-window-configuration does not restore display start
Date: Wed, 28 Nov 2018 08:41:57 +0200
> From: Markus Triska <triska <at> metalevel.at>
> Date: Tue, 27 Nov 2018 23:11:21 +0100
> 
>     (let ((buf (get-buffer-create "buf")))
>       (switch-to-buffer buf)
>       (erase-buffer)
>       (dotimes (x 10)
>         (insert (format "x is %s\n" x)))
>       (recenter 3)
>       (sit-for 1)
>       (let ((conf (current-window-configuration))
>             (ws (window-start))
>             (str (with-current-buffer buf (buffer-string))))
>         (with-current-buffer buf
>           (erase-buffer)
>           (insert str))
>         (set-window-configuration conf)
>         (sit-for 1)
>         (message "window-start: %s vs. %s" ws (window-start))))
> 
> This shows that after set-window-configuration, even though the buffer
> content is the same as at the time the configuration was obtained, the
> value of (window-start) differs from before: After the window
> configuration is set, (window-start) is 1. I expect it to be 50 (i.e.,
> the value at the time the configuration was obtained), because the
> documentation of current-window-configuration states:

The window-start point is a marker, and is saved as such.  Your code
replaces the entire text of the buffer with something new, so all the
markers are invalidated.

How important is the use case of replacing buffer text with identical
text?  Because replacing with a different text will make preserving
window-start position based on its numerical value not really a
sensible thing, would it?  It could even be impossible, e.g. if the
same position happens to be in the middle of a sequence of composed
characters.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#33532; Package emacs. (Wed, 28 Nov 2018 17:14:02 GMT) Full text and rfc822 format available.

Message #13 received at 33532 <at> debbugs.gnu.org (full text, mbox):

From: Markus Triska <triska <at> metalevel.at>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: 33532 <at> debbugs.gnu.org
Subject: Re: bug#33532: 26.1;
 set-window-configuration does not restore display start
Date: Wed, 28 Nov 2018 18:13:57 +0100
Eli Zaretskii <eliz <at> gnu.org> writes:

> How important is the use case of replacing buffer text with identical
> text?  Because replacing with a different text will make preserving
> window-start position based on its numerical value not really a
> sensible thing, would it?  It could even be impossible, e.g. if the
> same position happens to be in the middle of a sequence of composed
> characters.

Please consider a use case that is described in the Emacs manual:

    In order to store a window configuration on disk and
    read it back in another Emacs session ...

In such use cases, I want to restore the exact same text in all buffers,
and then restore the window configuration, including display starts.

In fact, the snippet illustrates an even simpler situation: It stores
the configuration in a variable, and the session keeps running.  I would
like to obtain the configuration, then close all buffers, and later
restore their contents (for example, from files), and then use
set-window-configuration to restore the original window configuration,
including all window-starts.

Could set-window-configuration be generalized to reliably restore the
window-starts also in such cases? If not, please consider adjusting the
documentation to make clear what this actually guarantees. In
particular, when are window-starts reliably restored, and when not?

Thank you and all the best,
Markus




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#33532; Package emacs. (Wed, 28 Nov 2018 17:42:02 GMT) Full text and rfc822 format available.

Message #16 received at 33532 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Markus Triska <triska <at> metalevel.at>
Cc: 33532 <at> debbugs.gnu.org
Subject: Re: bug#33532: 26.1;
 set-window-configuration does not restore display start
Date: Wed, 28 Nov 2018 19:41:56 +0200
> From: Markus Triska <triska <at> metalevel.at>
> Cc: 33532 <at> debbugs.gnu.org
> Date: Wed, 28 Nov 2018 18:13:57 +0100
> 
> Eli Zaretskii <eliz <at> gnu.org> writes:
> 
> > How important is the use case of replacing buffer text with identical
> > text?  Because replacing with a different text will make preserving
> > window-start position based on its numerical value not really a
> > sensible thing, would it?  It could even be impossible, e.g. if the
> > same position happens to be in the middle of a sequence of composed
> > characters.
> 
> Please consider a use case that is described in the Emacs manual:
> 
>     In order to store a window configuration on disk and
>     read it back in another Emacs session ...
> 
> In such use cases, I want to restore the exact same text in all buffers,
> and then restore the window configuration, including display starts.

Please propose how to do that.  If it can be done ion a useful manner,
I don't see why we shouldn't.

> In fact, the snippet illustrates an even simpler situation: It stores
> the configuration in a variable, and the session keeps running.  I would
> like to obtain the configuration, then close all buffers, and later
> restore their contents (for example, from files), and then use
> set-window-configuration to restore the original window configuration,
> including all window-starts.

Well, you get everything _excluding_ the window-start.  I think it's
still a bargain.

> Could set-window-configuration be generalized to reliably restore the
> window-starts also in such cases? If not, please consider adjusting the
> documentation to make clear what this actually guarantees. In
> particular, when are window-starts reliably restored, and when not?

As long as the buffer text exists, you will get the best approximation
to restoring window-start.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#33532; Package emacs. (Wed, 28 Nov 2018 17:59:02 GMT) Full text and rfc822 format available.

Message #19 received at 33532 <at> debbugs.gnu.org (full text, mbox):

From: Markus Triska <triska <at> metalevel.at>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: 33532 <at> debbugs.gnu.org
Subject: Re: bug#33532: 26.1;
 set-window-configuration does not restore display start
Date: Wed, 28 Nov 2018 18:58:30 +0100
Eli Zaretskii <eliz <at> gnu.org> writes:

>> In such use cases, I want to restore the exact same text in all buffers,
>> and then restore the window configuration, including display starts.
>
> Please propose how to do that.  If it can be done ion a useful manner,
> I don't see why we shouldn't.

In my opinion, one way to do it is to have current-window-configuration
store the window-start internally as an integer (instead of a marker),
denoting the position of the display start.

Then, set-window-configuration could set the window-start to that
position.

Would that work? At least that is how I currently work around the issue.

> Well, you get everything _excluding_ the window-start.  I think it's
> still a bargain.

It is! However, the documentation suggests that it is even better, when
it's currently not.

All the best,
Markus




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#33532; Package emacs. (Wed, 28 Nov 2018 18:30:02 GMT) Full text and rfc822 format available.

Message #22 received at 33532 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Markus Triska <triska <at> metalevel.at>
Cc: 33532 <at> debbugs.gnu.org
Subject: Re: bug#33532: 26.1;
 set-window-configuration does not restore display start
Date: Wed, 28 Nov 2018 20:29:59 +0200
> From: Markus Triska <triska <at> metalevel.at>
> Cc: 33532 <at> debbugs.gnu.org
> Date: Wed, 28 Nov 2018 18:58:30 +0100
> 
> In my opinion, one way to do it is to have current-window-configuration
> store the window-start internally as an integer (instead of a marker),
> denoting the position of the display start.
> 
> Then, set-window-configuration could set the window-start to that
> position.

How is this useful if the text has changed?  You are just starting
display from some random position, don't you?

> Would that work?

Not in general, no.

> At least that is how I currently work around the issue.

I don't think this could be a general solution.  But I'll let others
chime in and comment on this.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#33532; Package emacs. (Thu, 29 Nov 2018 08:33:01 GMT) Full text and rfc822 format available.

Message #25 received at 33532 <at> debbugs.gnu.org (full text, mbox):

From: martin rudalics <rudalics <at> gmx.at>
To: Markus Triska <triska <at> metalevel.at>, Eli Zaretskii <eliz <at> gnu.org>
Cc: 33532 <at> debbugs.gnu.org
Subject: Re: bug#33532: 26.1; set-window-configuration does not restore display
 start
Date: Thu, 29 Nov 2018 09:31:55 +0100
> Please consider a use case that is described in the Emacs manual:
>
>      In order to store a window configuration on disk and
>      read it back in another Emacs session ...

But the whole text is

  In order to store a window configuration on
  disk and read it back in another Emacs session, you can use the
  functions described next.

and the functions mentioned there are `window-state-get' and
`window-state-put'.  So you have to tell us what you want to fix: The
behavior of window configurations throughout one and the same Emacs
session (which uses markers to restore positions) or when restoring a
previous session (which relies on positions only).

> In such use cases, I want to restore the exact same text in all buffers,

What is "to restore the exact same text in all buffers"?  The text at
the time the configuration was stored in a register?  That one might
not be available any more.  Restoring a window configuration (or
state) can only use the buffer text as is and adjust positions
accordingly.

> and then restore the window configuration, including display starts.
>
> In fact, the snippet illustrates an even simpler situation: It stores
> the configuration in a variable, and the session keeps running.  I would
> like to obtain the configuration, then close all buffers,

I suppose you mean "kill all buffers" here.  This will implicitly make
the window start and point positions of any window that showed the
buffer previously and is stored in a configuration to point nowhere.
Furthermore, there is no guarantee that the same buffer will be shown
in that window when the configuration is restored.

> and later
> restore their contents (for example, from files), and then use
> set-window-configuration to restore the original window configuration,
> including all window-starts.

If you use window states instead of configurations then this should
work.  States store positions instead of markers.

> Could set-window-configuration be generalized to reliably restore the
> window-starts also in such cases? If not, please consider adjusting the
> documentation to make clear what this actually guarantees. In
> particular, when are window-starts reliably restored, and when not?

Emacs tries its best to do that.  But killing and reverting buffers,
among other operations, can defy such attempts.  So you either should
try 'window-state-get' and 'window-state-put' to do what you want or
save any positions separately before killing buffers and restore them
together with their buffers after restoring a configuration.

martin




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#33532; Package emacs. (Thu, 29 Nov 2018 18:10:01 GMT) Full text and rfc822 format available.

Message #28 received at 33532 <at> debbugs.gnu.org (full text, mbox):

From: Markus Triska <triska <at> metalevel.at>
To: martin rudalics <rudalics <at> gmx.at>
Cc: Eli Zaretskii <eliz <at> gnu.org>, 33532 <at> debbugs.gnu.org
Subject: Re: bug#33532: 26.1;
 set-window-configuration does not restore display start
Date: Thu, 29 Nov 2018 19:09:47 +0100
martin rudalics <rudalics <at> gmx.at> writes:

> and the functions mentioned there are `window-state-get' and
> `window-state-put'.

These functions have an analogous issue, which you can see with:

    (let ((buf (get-buffer-create "buf")))
      (switch-to-buffer buf)
      (erase-buffer)
      (dotimes (x 10)
        (insert (format "x is %s\n" x)))
      (recenter 3)
      (sit-for 1)
      (let ((conf (window-state-get))
            (ws (window-start))
            (str (with-current-buffer buf (buffer-string))))
        (with-current-buffer buf
          (erase-buffer)
          (insert str))
        (window-state-put conf)
        (sit-for 1)
        (message "window-start: %s vs. %s" ws (window-start))))

> So you have to tell us what you want to fix: The behavior of window
> configurations throughout one and the same Emacs session (which uses
> markers to restore positions) or when restoring a previous session
> (which relies on positions only).

If possible, please fix both. I filed the simpler case first, but both
functions are broken.  For now, I would like to concentrate on the case
that only involves variables in the same Emacs session, without saving
files to disk. I can file a separate issue for the other function.

> What is "to restore the exact same text in all buffers"?  The text at
> the time the configuration was stored in a register?

It means the buffer text that can be obtained for example with
(buffer-string), and can be restored exactly as it was at any time. The
snippet I posted illustrates this case.

> Restoring a window configuration (or state) can only use the buffer
> text as is and adjust positions accordingly.

This is what I am asking for, and what currently does not work. Please
see the snippet I posted for a reproducible test case: The buffer text
is what it was, but the start position is not restored.

> Furthermore, there is no guarantee that the same buffer will be shown
> in that window when the configuration is restored.

The fact that other guarantees are also broken is definitely
unfortunate. However, improving just the particular aspect I mentioned
would already be extremely helpful for my use case.

> If you use window states instead of configurations then this should
> work.  States store positions instead of markers.

Please see above: The snippet shows that it doesn't work. Also, I am
primarily interested in the window configuration, and the documentation
suggests that the window-start is saved (and restored).

If possible, please consider implementing this, or adjusting the
documentation so that it states what is actually guaranteed.

Thank you and all the best,
Markus




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#33532; Package emacs. (Thu, 29 Nov 2018 19:12:02 GMT) Full text and rfc822 format available.

Message #31 received at 33532 <at> debbugs.gnu.org (full text, mbox):

From: martin rudalics <rudalics <at> gmx.at>
To: Markus Triska <triska <at> metalevel.at>
Cc: Eli Zaretskii <eliz <at> gnu.org>, 33532 <at> debbugs.gnu.org
Subject: Re: bug#33532: 26.1; set-window-configuration does not restore display
 start
Date: Thu, 29 Nov 2018 20:11:12 +0100
> These functions have an analogous issue, which you can see with:
>
>      (let ((buf (get-buffer-create "buf")))
>        (switch-to-buffer buf)
>        (erase-buffer)
>        (dotimes (x 10)
>          (insert (format "x is %s\n" x)))
>        (recenter 3)
>        (sit-for 1)
>        (let ((conf (window-state-get))
>              (ws (window-start))
>              (str (with-current-buffer buf (buffer-string))))
>          (with-current-buffer buf
>            (erase-buffer)
>            (insert str))
>          (window-state-put conf)
>          (sit-for 1)
>          (message "window-start: %s vs. %s" ws (window-start))))

You have to call 'window-state-get' with the WRITABLE argument
non-nil, like (window-state-get nil t).  Otherwise, it gets you
markers just like 'current-window-configuration'.

Note that I did not disregard the remainder of your mail but please
let's continue the discussion after you tried my suggestion.

Thanks, martin




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#33532; Package emacs. (Fri, 30 Nov 2018 16:59:01 GMT) Full text and rfc822 format available.

Message #34 received at 33532 <at> debbugs.gnu.org (full text, mbox):

From: Markus Triska <triska <at> metalevel.at>
To: martin rudalics <rudalics <at> gmx.at>
Cc: Eli Zaretskii <eliz <at> gnu.org>, 33532 <at> debbugs.gnu.org
Subject: Re: bug#33532: 26.1;
 set-window-configuration does not restore display start
Date: Fri, 30 Nov 2018 17:58:39 +0100
martin rudalics <rudalics <at> gmx.at> writes:

> You have to call 'window-state-get' with the WRITABLE argument
> non-nil, like (window-state-get nil t).  Otherwise, it gets you
> markers just like 'current-window-configuration'.

Perfect! This is what I need also for current-window-configuration!
Also, could this be made the default? Or is there some advantage in
using markers instead of the actual positions that can be restored?

All the best,
Markus




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#33532; Package emacs. (Fri, 30 Nov 2018 17:48:02 GMT) Full text and rfc822 format available.

Message #37 received at 33532 <at> debbugs.gnu.org (full text, mbox):

From: martin rudalics <rudalics <at> gmx.at>
To: Markus Triska <triska <at> metalevel.at>
Cc: Juri Linkov <juri <at> jurta.org>, Eli Zaretskii <eliz <at> gnu.org>,
 33532 <at> debbugs.gnu.org
Subject: Re: bug#33532: 26.1; set-window-configuration does not restore display
 start
Date: Fri, 30 Nov 2018 18:47:30 +0100
> Perfect! This is what I need also for current-window-configuration!
> Also, could this be made the default? Or is there some advantage in
> using markers instead of the actual positions that can be restored?

First of all we need a "reasonable" use case.  The only purpose of a
form like

(let ((str (with-current-buffer buf (buffer-string))))
  (with-current-buffer buf
    (erase-buffer)
    (insert str)))

is to annihilate all marker positions in buf and I have yet to
understand why that could be useful.  I'm sure you have something more
reasonable in mind.  Once we have such a use case we can decide how to
best support it.

AFAICT Emacs' window configurations use window start and point markers
ever since.  And while they interfere with reverting buffers (see
Bug#33458 for a discussion) turning them into pure positions would
break far too many things as to make that the default.

We could store - in configurations and states - both, markers and
their corresponding pure positions.  Then if, when restoring a
configuration or state, a marker's position has dropped to 1 while the
corresponding saved pure position is > 1, use the the pure position
instead.  This should automatically fix your case and not violate any
others.  Juri what do you think?

martin




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#33532; Package emacs. (Fri, 30 Nov 2018 19:22:02 GMT) Full text and rfc822 format available.

Message #40 received at 33532 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Markus Triska <triska <at> metalevel.at>
Cc: rudalics <at> gmx.at, 33532 <at> debbugs.gnu.org
Subject: Re: bug#33532: 26.1;
 set-window-configuration does not restore display start
Date: Fri, 30 Nov 2018 21:20:50 +0200
> From: Markus Triska <triska <at> metalevel.at>
> Cc: Eli Zaretskii <eliz <at> gnu.org>,  33532 <at> debbugs.gnu.org
> Date: Fri, 30 Nov 2018 17:58:39 +0100
> 
> Or is there some advantage in using markers instead of the actual
> positions that can be restored?

Markers are much more useful default, because they preserve position
in text even if text is modified.  So in the usual cases markers are a
better default.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#33532; Package emacs. (Sat, 01 Dec 2018 23:08:01 GMT) Full text and rfc822 format available.

Message #43 received at 33532 <at> debbugs.gnu.org (full text, mbox):

From: Juri Linkov <juri <at> jurta.org>
To: martin rudalics <rudalics <at> gmx.at>
Cc: Eli Zaretskii <eliz <at> gnu.org>, 33532 <at> debbugs.gnu.org,
 Markus Triska <triska <at> metalevel.at>
Subject: Re: bug#33532: 26.1;
 set-window-configuration does not restore display start
Date: Sun, 02 Dec 2018 00:52:54 +0200
>> Perfect! This is what I need also for current-window-configuration!
>> Also, could this be made the default? Or is there some advantage in
>> using markers instead of the actual positions that can be restored?
>
> First of all we need a "reasonable" use case.  The only purpose of a
> form like
>
> (let ((str (with-current-buffer buf (buffer-string))))
>   (with-current-buffer buf
>     (erase-buffer)
>     (insert str)))
>
> is to annihilate all marker positions in buf and I have yet to
> understand why that could be useful.  I'm sure you have something more
> reasonable in mind.  Once we have such a use case we can decide how to
> best support it.
>
> AFAICT Emacs' window configurations use window start and point markers
> ever since.  And while they interfere with reverting buffers (see
> Bug#33458 for a discussion) turning them into pure positions would
> break far too many things as to make that the default.
>
> We could store - in configurations and states - both, markers and
> their corresponding pure positions.  Then if, when restoring a
> configuration or state, a marker's position has dropped to 1 while the
> corresponding saved pure position is > 1, use the the pure position
> instead.  This should automatically fix your case and not violate any
> others.  Juri what do you think?

I see no drawbacks, let's try storing both (maybe together with
metadata like dired-filename).




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#33532; Package emacs. (Sun, 02 Dec 2018 08:35:02 GMT) Full text and rfc822 format available.

Message #46 received at 33532 <at> debbugs.gnu.org (full text, mbox):

From: martin rudalics <rudalics <at> gmx.at>
To: Juri Linkov <juri <at> jurta.org>
Cc: Eli Zaretskii <eliz <at> gnu.org>, 33532 <at> debbugs.gnu.org,
 Markus Triska <triska <at> metalevel.at>
Subject: Re: bug#33532: 26.1; set-window-configuration does not restore display
 start
Date: Sun, 02 Dec 2018 09:34:39 +0100
>> We could store - in configurations and states - both, markers and
>> their corresponding pure positions.  Then if, when restoring a
>> configuration or state, a marker's position has dropped to 1 while the
>> corresponding saved pure position is > 1, use the the pure position
>> instead.  This should automatically fix your case and not violate any
>> others.  Juri what do you think?
>
> I see no drawbacks, let's try storing both (maybe together with
> metadata like dired-filename).

It will fail when a window is stowed away in a list or configuration
and the entire stretch of the buffer from 'point-min' up to some
position at or after the stored point position is deleted.  In that
case, the point of any window showing the buffer should rightfully
drop to 'point-min' but in our case it would go to the old position
when the buffer is re-shown in the window.  While this might be a rare
use case, it would be confusing nevertheless.

martin




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#33532; Package emacs. (Mon, 03 Dec 2018 01:29:03 GMT) Full text and rfc822 format available.

Message #49 received at 33532 <at> debbugs.gnu.org (full text, mbox):

From: Juri Linkov <juri <at> jurta.org>
To: martin rudalics <rudalics <at> gmx.at>
Cc: Eli Zaretskii <eliz <at> gnu.org>, 33532 <at> debbugs.gnu.org,
 Markus Triska <triska <at> metalevel.at>
Subject: Re: bug#33532: 26.1;
 set-window-configuration does not restore display start
Date: Mon, 03 Dec 2018 02:52:53 +0200
>>> We could store - in configurations and states - both, markers and
>>> their corresponding pure positions.  Then if, when restoring a
>>> configuration or state, a marker's position has dropped to 1 while the
>>> corresponding saved pure position is > 1, use the the pure position
>>> instead.  This should automatically fix your case and not violate any
>>> others.  Juri what do you think?
>>
>> I see no drawbacks, let's try storing both (maybe together with
>> metadata like dired-filename).
>
> It will fail when a window is stowed away in a list or configuration
> and the entire stretch of the buffer from 'point-min' up to some
> position at or after the stored point position is deleted.  In that
> case, the point of any window showing the buffer should rightfully
> drop to 'point-min' but in our case it would go to the old position
> when the buffer is re-shown in the window.  While this might be a rare
> use case, it would be confusing nevertheless.

I still think the problem is in markers dropping to 'point-min'.
Shouldn't a marker remember its previous position as a number
and try to restore it when this position becomes available again?




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#33532; Package emacs. (Mon, 03 Dec 2018 07:46:02 GMT) Full text and rfc822 format available.

Message #52 received at 33532 <at> debbugs.gnu.org (full text, mbox):

From: martin rudalics <rudalics <at> gmx.at>
To: Juri Linkov <juri <at> jurta.org>
Cc: Eli Zaretskii <eliz <at> gnu.org>, 33532 <at> debbugs.gnu.org,
 Markus Triska <triska <at> metalevel.at>
Subject: Re: bug#33532: 26.1; set-window-configuration does not restore display
 start
Date: Mon, 03 Dec 2018 08:45:38 +0100
[Message part 1 (text/plain, inline)]
> I still think the problem is in markers dropping to 'point-min'.

Due to the buffer erasing part when reverting the buffer.

> Shouldn't a marker remember its previous position as a number
> and try to restore it when this position becomes available again?

I think that Stefan's approach to restore windows' point markers does
that in a more sophisticated way.  I'll attach a patch.

But that patch does not address window configurations and states -
simply because it can't access them.  We need a different solution for
those.  And it obviously does not handle non-default reverters like
'dired'.

martin
[fileio.diff (text/plain, attachment)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#33532; Package emacs. (Tue, 04 Dec 2018 00:06:02 GMT) Full text and rfc822 format available.

Message #55 received at 33532 <at> debbugs.gnu.org (full text, mbox):

From: Juri Linkov <juri <at> jurta.org>
To: martin rudalics <rudalics <at> gmx.at>
Cc: Eli Zaretskii <eliz <at> gnu.org>, 33532 <at> debbugs.gnu.org,
 Markus Triska <triska <at> metalevel.at>
Subject: Re: bug#33532: 26.1;
 set-window-configuration does not restore display start
Date: Tue, 04 Dec 2018 00:59:29 +0200
> But that patch does not address window configurations and states -
> simply because it can't access them.  We need a different solution for
> those.  And it obviously does not handle non-default reverters like
> 'dired'.

What do you think about implementing the same behavior for
markers like it's implemented by 'comint-move-point-for-output'?
I.e. the same way as 'comint-move-point-for-output' moves point
to the end of the output, after erasing the buffer markers could
move their positions towards their previous valid position until
there is enough reverted text that they reach the old position.

This is straightforward to implement.  I see print.c has a question
in the comments:

    case PVEC_MARKER:
      print_c_string ("#<marker ", printcharfun);
      /* Do you think this is necessary?  */
      if (XMARKER (obj)->insertion_type != 0)
	print_c_string ("(moves after insertion) ", printcharfun);

I think this is necessary.  And this 'insertion_type' could also
move after insertion until it reaches its old position in the
reverted buffer.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#33532; Package emacs. (Tue, 04 Dec 2018 06:42:02 GMT) Full text and rfc822 format available.

Message #58 received at 33532 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Juri Linkov <juri <at> jurta.org>
Cc: rudalics <at> gmx.at, 33532 <at> debbugs.gnu.org, triska <at> metalevel.at
Subject: Re: bug#33532: 26.1;
 set-window-configuration does not restore display start
Date: Tue, 04 Dec 2018 08:41:26 +0200
> From: Juri Linkov <juri <at> jurta.org>
> Cc: Markus Triska <triska <at> metalevel.at>,  Eli Zaretskii <eliz <at> gnu.org>,  33532 <at> debbugs.gnu.org
> Date: Tue, 04 Dec 2018 00:59:29 +0200
> 
> What do you think about implementing the same behavior for
> markers like it's implemented by 'comint-move-point-for-output'?
> I.e. the same way as 'comint-move-point-for-output' moves point
> to the end of the output, after erasing the buffer markers could
> move their positions towards their previous valid position until
> there is enough reverted text that they reach the old position.
> 
> This is straightforward to implement.

Is it?  Then perhaps I don't understand what "this" is, because
support for keeping the markers' positions is implemented on the C
level, and every insertion/deletion primitive runs the low-level code
which implements that.  I wouldn't call changes in that area
"straightforward" at all.

Please also keep in mind that markers are the basis for other
important features, like overlays and conversion of character to byte
positions and vice versa.  We need to consider the implications on all
those features.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#33532; Package emacs. (Tue, 04 Dec 2018 08:34:02 GMT) Full text and rfc822 format available.

Message #61 received at 33532 <at> debbugs.gnu.org (full text, mbox):

From: martin rudalics <rudalics <at> gmx.at>
To: Juri Linkov <juri <at> jurta.org>
Cc: Eli Zaretskii <eliz <at> gnu.org>, 33532 <at> debbugs.gnu.org,
 Markus Triska <triska <at> metalevel.at>
Subject: Re: bug#33532: 26.1; set-window-configuration does not restore display
 start
Date: Tue, 04 Dec 2018 09:33:14 +0100
[Message part 1 (text/plain, inline)]
> What do you think about implementing the same behavior for
> markers like it's implemented by 'comint-move-point-for-output'?
> I.e. the same way as 'comint-move-point-for-output' moves point
> to the end of the output, after erasing the buffer markers could
> move their positions towards their previous valid position until
> there is enough reverted text that they reach the old position.
>
> This is straightforward to implement.  I see print.c has a question
> in the comments:
>
>      case PVEC_MARKER:
>        print_c_string ("#<marker ", printcharfun);
>        /* Do you think this is necessary?  */
>        if (XMARKER (obj)->insertion_type != 0)
> 	print_c_string ("(moves after insertion) ", printcharfun);
>
> I think this is necessary.  And this 'insertion_type' could also
> move after insertion until it reaches its old position in the
> reverted buffer.

'auto-revert-tail-mode' already has

      (when buffer-file-name
        (setq eob (eobp))
        (walk-windows
         (lambda (window)
           (and (eq (window-buffer window) buffer)
                (= (window-point window) (point-max))
                (push window eoblist)))
         'no-mini t))

plus

      (when buffer-file-name
        (when eob (goto-char (point-max)))
        (dolist (window eoblist)
          (set-window-point window (point-max)))))

without changing the markers' point insertion types.  We can easily
extend that to handle a window's previous buffers' points.  But
changing the insertion type of markers is far too delicate with all
the implications Eli cited.  We should avoid that wherever possible.

BTW, the last patch I sent was needlessly complicated - a window's
next buffers don't have any markers.  I attach a better one.

martin
[fileio.diff (text/plain, attachment)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#33532; Package emacs. (Tue, 04 Dec 2018 21:48:04 GMT) Full text and rfc822 format available.

Message #64 received at 33532 <at> debbugs.gnu.org (full text, mbox):

From: Juri Linkov <juri <at> jurta.org>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: rudalics <at> gmx.at, 33532 <at> debbugs.gnu.org, triska <at> metalevel.at
Subject: Re: bug#33532: 26.1;
 set-window-configuration does not restore display start
Date: Tue, 04 Dec 2018 23:44:18 +0200
>> What do you think about implementing the same behavior for
>> markers like it's implemented by 'comint-move-point-for-output'?
>> I.e. the same way as 'comint-move-point-for-output' moves point
>> to the end of the output, after erasing the buffer markers could
>> move their positions towards their previous valid position until
>> there is enough reverted text that they reach the old position.
>> 
>> This is straightforward to implement.
>
> Is it?  Then perhaps I don't understand what "this" is, because
> support for keeping the markers' positions is implemented on the C
> level, and every insertion/deletion primitive runs the low-level code
> which implements that.  I wouldn't call changes in that area
> "straightforward" at all.

Straightforward because I thought it could reuse the existing
implementation of `insertion_type' that moves the marker
after text insertion.  Maybe I'm mistaken.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#33532; Package emacs. (Tue, 04 Dec 2018 21:48:05 GMT) Full text and rfc822 format available.

Message #67 received at 33532 <at> debbugs.gnu.org (full text, mbox):

From: Juri Linkov <juri <at> jurta.org>
To: martin rudalics <rudalics <at> gmx.at>
Cc: Eli Zaretskii <eliz <at> gnu.org>, 33532 <at> debbugs.gnu.org,
 Markus Triska <triska <at> metalevel.at>
Subject: Re: bug#33532: 26.1;
 set-window-configuration does not restore display start
Date: Tue, 04 Dec 2018 23:47:09 +0200
> 'auto-revert-tail-mode' already has
>
>       (when buffer-file-name
>         (setq eob (eobp))
>         (walk-windows
>          (lambda (window)
>            (and (eq (window-buffer window) buffer)
>                 (= (window-point window) (point-max))
>                 (push window eoblist)))
>          'no-mini t))
>
> plus
>
>       (when buffer-file-name
>         (when eob (goto-char (point-max)))
>         (dolist (window eoblist)
>           (set-window-point window (point-max)))))
>
> without changing the markers' point insertion types.  We can easily
> extend that to handle a window's previous buffers' points.

Again, no support for window configurations and non-writable window
states.  But maybe it's possible to access all buffer's windows,
even windows in window configurations/states, and changes their
window points, including previous buffers' points in window
configurations/states.

BTW, I understand why reverting a dired buffer moves its point-marker to
the beginning of the buffer in the selected window window restored from
a window configuration.  But I don't understand why point-marker is
moved to the end of the dired buffer in non-selected window restored
from a window configuration.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#33532; Package emacs. (Wed, 05 Dec 2018 09:18:02 GMT) Full text and rfc822 format available.

Message #70 received at 33532 <at> debbugs.gnu.org (full text, mbox):

From: martin rudalics <rudalics <at> gmx.at>
To: Juri Linkov <juri <at> jurta.org>
Cc: Eli Zaretskii <eliz <at> gnu.org>, 33532 <at> debbugs.gnu.org,
 Markus Triska <triska <at> metalevel.at>
Subject: Re: bug#33532: 26.1; set-window-configuration does not restore display
 start
Date: Wed, 05 Dec 2018 10:16:59 +0100
> Again, no support for window configurations and non-writable window
> states.  But maybe it's possible to access all buffer's windows,
> even windows in window configurations/states, and changes their
> window points, including previous buffers' points in window
> configurations/states.

How would we handle window configurations?  We could add a new
variable say 'window-configuration-list' and make sure that
configurations accessible from that variable are scanned by revert
buffer functions.  Applications and users would be responsible for
removing a configuration from that list when it's no more needed.

But we also need accessor/setter functions for Lisp slots like the
windows stored in the configuration and for any such window its list
of previous and next buffers (where "any such window" could be a
deleted one).  Doable but certainly non-trivial.

Window states would have to be handled in a similar way.  But there
the task would be simpler: Add a variable, say 'window-states-list'
and if a state is on that list, reverting a buffer could scan it right
away.  Doable but still requires some work.

> BTW, I understand why reverting a dired buffer moves its point-marker to
> the beginning of the buffer in the selected window window restored from
> a window configuration.  But I don't understand why point-marker is
> moved to the end of the dired buffer in non-selected window restored
> from a window configuration.

I have no idea either.

martin




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#33532; Package emacs. (Thu, 06 Dec 2018 01:04:02 GMT) Full text and rfc822 format available.

Message #73 received at 33532 <at> debbugs.gnu.org (full text, mbox):

From: Juri Linkov <juri <at> jurta.org>
To: martin rudalics <rudalics <at> gmx.at>
Cc: Eli Zaretskii <eliz <at> gnu.org>, 33532 <at> debbugs.gnu.org,
 Markus Triska <triska <at> metalevel.at>
Subject: Re: bug#33532: 26.1;
 set-window-configuration does not restore display start
Date: Thu, 06 Dec 2018 02:09:17 +0200
>> Again, no support for window configurations and non-writable window
>> states.  But maybe it's possible to access all buffer's windows,
>> even windows in window configurations/states, and changes their
>> window points, including previous buffers' points in window
>> configurations/states.
>
> How would we handle window configurations?  We could add a new
> variable say 'window-configuration-list' and make sure that
> configurations accessible from that variable are scanned by revert
> buffer functions.  Applications and users would be responsible for
> removing a configuration from that list when it's no more needed.
>
> But we also need accessor/setter functions for Lisp slots like the
> windows stored in the configuration and for any such window its list
> of previous and next buffers (where "any such window" could be a
> deleted one).  Doable but certainly non-trivial.
>
> Window states would have to be handled in a similar way.  But there
> the task would be simpler: Add a variable, say 'window-states-list'
> and if a state is on that list, reverting a buffer could scan it right
> away.  Doable but still requires some work.

Then maybe instead of immediately modifying values in windows (like
e.g. comint-postoutput-scroll-to-bottom uses get-buffer-window-list
and comint-adjust-window-point) and instead of trying to do the same
in window configurations/states, better would be to modify these values
when windows are restored from window configurations/states/prev-next-buffers?




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#33532; Package emacs. (Thu, 06 Dec 2018 09:11:01 GMT) Full text and rfc822 format available.

Message #76 received at 33532 <at> debbugs.gnu.org (full text, mbox):

From: martin rudalics <rudalics <at> gmx.at>
To: Juri Linkov <juri <at> jurta.org>
Cc: Eli Zaretskii <eliz <at> gnu.org>, 33532 <at> debbugs.gnu.org,
 Markus Triska <triska <at> metalevel.at>
Subject: Re: bug#33532: 26.1; set-window-configuration does not restore display
 start
Date: Thu, 06 Dec 2018 10:09:54 +0100
> Then maybe instead of immediately modifying values in windows (like
> e.g. comint-postoutput-scroll-to-bottom uses get-buffer-window-list
> and comint-adjust-window-point) and instead of trying to do the same
> in window configurations/states, better would be to modify these values
> when windows are restored from window configurations/states/prev-next-buffers?

That was my idea when I proposed to go to the buffer's point when
restoring a configuration/state and the buffer had been reverted since
the configuration was saved.  Note that a configuration already has to
display some live buffer when the one it stored got killed since it was
saved.  Still, it might not be what users want, especially if they use
configurations to show the same buffer in multiple windows.

Note in this context that the collector does not scan window
configurations specially (or at least I cannot see where it does that
or whether any pointers in a configuration are weak).  So if you save
many configurations (or states) and kill buffers often, the dead
buffer objects and the markers these configurations save - including
those from the windows' previous and next buffers - will steadily pile
up.  If someone knows better, please correct me.

martin




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#33532; Package emacs. (Fri, 07 Dec 2018 00:02:02 GMT) Full text and rfc822 format available.

Message #79 received at 33532 <at> debbugs.gnu.org (full text, mbox):

From: Juri Linkov <juri <at> jurta.org>
To: martin rudalics <rudalics <at> gmx.at>
Cc: Eli Zaretskii <eliz <at> gnu.org>, 33532 <at> debbugs.gnu.org,
 Markus Triska <triska <at> metalevel.at>
Subject: Re: bug#33532: 26.1;
 set-window-configuration does not restore display start
Date: Fri, 07 Dec 2018 01:38:39 +0200
>> Then maybe instead of immediately modifying values in windows (like
>> e.g. comint-postoutput-scroll-to-bottom uses get-buffer-window-list
>> and comint-adjust-window-point) and instead of trying to do the same
>> in window configurations/states, better would be to modify these values
>> when windows are restored from window configurations/states/prev-next-buffers?
>
> That was my idea when I proposed to go to the buffer's point when
> restoring a configuration/state and the buffer had been reverted since
> the configuration was saved.  Note that a configuration already has to
> display some live buffer when the one it stored got killed since it was
> saved.  Still, it might not be what users want, especially if they use
> configurations to show the same buffer in multiple windows.

Also writable states need better point restoring logic, so maybe
window configurations and writable/non-writable states should support
a hook-like functions that will return the window point when
the buffer is re-displayed in the window, so e.g. dired could
set window point to the dired-filename that was displayed in
that window previously.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#33532; Package emacs. (Tue, 25 Dec 2018 21:51:02 GMT) Full text and rfc822 format available.

Message #82 received at 33532 <at> debbugs.gnu.org (full text, mbox):

From: Juri Linkov <juri <at> jurta.org>
To: martin rudalics <rudalics <at> gmx.at>
Cc: 33532 <at> debbugs.gnu.org
Subject: Re: bug#33532: 26.1;
 set-window-configuration does not restore display start
Date: Tue, 25 Dec 2018 23:49:46 +0200
>> BTW, I understand why reverting a dired buffer moves its point-marker to
>> the beginning of the buffer in the selected window restored from
>> a window configuration.  But I don't understand why point-marker is
>> moved to the end of the dired buffer in non-selected window restored
>> from a window configuration.
>
> I have no idea either.

Please see a complete test case in bug#33871.




This bug report was last modified 6 years and 174 days ago.

Previous Next


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