GNU bug report logs - #60143
29.0.60; command `undo-redo` don't restore cursor position

Previous Next

Package: emacs;

Reported by: yinz Liu <liuyinz95 <at> gmail.com>

Date: Sat, 17 Dec 2022 03:35:04 UTC

Severity: wishlist

Found in version 29.0.60

To reply to this bug, email your comments to 60143 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#60143; Package emacs. (Sat, 17 Dec 2022 03:35:04 GMT) Full text and rfc822 format available.

Acknowledgement sent to yinz Liu <liuyinz95 <at> gmail.com>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Sat, 17 Dec 2022 03:35:04 GMT) Full text and rfc822 format available.

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

From: yinz Liu <liuyinz95 <at> gmail.com>
To: bug-gnu-emacs <at> gnu.org
Subject: 29.0.60; command `undo-redo` don't restore cursor position
Date: Sat, 17 Dec 2022 09:42:28 +0800
[Message part 1 (text/plain, inline)]
aaaa ! bbbb @ cccc #


1. when cursor at position "#", call `undo', cursor jump to "@"

2. when cursor at position "@", call `undo-redo', text "cccc" restore,

   but cursor still remain in "@", don't move to "#".


my workaround fow now:


in function primitive-undo
<https://github.com/emacs-mirror/emacs/blob/149e6e03b3f860c3d78031bf3377d8a4c99a7a64/lisp/simple.el#L3622-L3624>
 :


change L3624 to : `(goto-char (+ pos (length string)))`
[Message part 2 (text/html, inline)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#60143; Package emacs. (Sun, 18 Dec 2022 11:04:01 GMT) Full text and rfc822 format available.

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

From: Eli Zaretskii <eliz <at> gnu.org>
To: yinz Liu <liuyinz95 <at> gmail.com>, Stefan Monnier <monnier <at> iro.umontreal.ca>
Cc: 60143 <at> debbugs.gnu.org
Subject: Re: bug#60143: 29.0.60;
 command `undo-redo` don't restore cursor position
Date: Sun, 18 Dec 2022 13:03:43 +0200
> From: yinz Liu <liuyinz95 <at> gmail.com>
> Date: Sat, 17 Dec 2022 09:42:28 +0800
> 
> aaaa ! bbbb @ cccc #
> 
> 1. when cursor at position "#", call `undo', cursor jump to "@"
> 
> 2. when cursor at position "@", call `undo-redo', text "cccc" restore,
>    but cursor still remain in "@", don't move to "#".
> 
> my workaround fow now:
> 
> in function primitive-undo :
> 
> change L3624 to : `(goto-char (+ pos (length string)))`

That code is there for almost 10 years, and before that the C
implementation did the same.  The way the code is written, viz.:

               (goto-char pos)
               (insert string)
               (goto-char pos))

it is clear that the second goto-char is on purpose, since if we
delete it, we get the effect that you want; no need to goto anywhere
else, because 'insert' leaves point after the inserted text.

So I very much hesitate to change this.  Stefan, any comments? do you
happen to know why we return point to before the insertion?




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#60143; Package emacs. (Mon, 19 Dec 2022 01:43:01 GMT) Full text and rfc822 format available.

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

From: Stefan Monnier <monnier <at> iro.umontreal.ca>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: yinz Liu <liuyinz95 <at> gmail.com>, 60143 <at> debbugs.gnu.org
Subject: Re: bug#60143: 29.0.60; command `undo-redo` don't restore cursor
 position
Date: Sun, 18 Dec 2022 20:42:31 -0500
> So I very much hesitate to change this.  Stefan, any comments?

Changing that code is likely wrong, indeed.  If the undo doesn't get
you where you expected, it should usually be changed by adding an
additional record to the undo log.

That "record" is a simple integer indicating the position of point at
that moment (citing `C-h o buffer-undo-list`):

    An entry of the form POSITION indicates that point was at the buffer
    location given by the integer.  Undoing an entry of this form places
    point at POSITION.

As for whether we should add such a record in the OP's scenario, and how
to do that, I haven't looked at his scenario in enough detail to have
much to say about it.


        Stefan





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

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

From: Eli Zaretskii <eliz <at> gnu.org>
To: Stefan Monnier <monnier <at> iro.umontreal.ca>
Cc: liuyinz95 <at> gmail.com, 60143 <at> debbugs.gnu.org
Subject: Re: bug#60143: 29.0.60; command `undo-redo` don't restore cursor
 position
Date: Mon, 19 Dec 2022 05:35:49 +0200
> From: Stefan Monnier <monnier <at> iro.umontreal.ca>
> Cc: yinz Liu <liuyinz95 <at> gmail.com>,  60143 <at> debbugs.gnu.org
> Date: Sun, 18 Dec 2022 20:42:31 -0500
> 
> > So I very much hesitate to change this.  Stefan, any comments?
> 
> Changing that code is likely wrong, indeed.  If the undo doesn't get
> you where you expected, it should usually be changed by adding an
> additional record to the undo log.
> 
> That "record" is a simple integer indicating the position of point at
> that moment (citing `C-h o buffer-undo-list`):
> 
>     An entry of the form POSITION indicates that point was at the buffer
>     location given by the integer.  Undoing an entry of this form places
>     point at POSITION.
> 
> As for whether we should add such a record in the OP's scenario, and how
> to do that, I haven't looked at his scenario in enough detail to have
> much to say about it.

I don't think we record position of point before deletion.  Which is
why 'undo' in that scenario also ends up with point before the
recovered deletion.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#60143; Package emacs. (Mon, 19 Dec 2022 16:10:01 GMT) Full text and rfc822 format available.

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

From: Stefan Monnier <monnier <at> iro.umontreal.ca>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: liuyinz95 <at> gmail.com, 60143 <at> debbugs.gnu.org
Subject: Re: bug#60143: 29.0.60; command `undo-redo` don't restore cursor
 position
Date: Mon, 19 Dec 2022 11:09:09 -0500
Eli Zaretskii [2022-12-19 05:35:49] wrote:

>> From: Stefan Monnier <monnier <at> iro.umontreal.ca>
>> Cc: yinz Liu <liuyinz95 <at> gmail.com>,  60143 <at> debbugs.gnu.org
>> Date: Sun, 18 Dec 2022 20:42:31 -0500
>> 
>> > So I very much hesitate to change this.  Stefan, any comments?
>> 
>> Changing that code is likely wrong, indeed.  If the undo doesn't get
>> you where you expected, it should usually be changed by adding an
>> additional record to the undo log.
>> 
>> That "record" is a simple integer indicating the position of point at
>> that moment (citing `C-h o buffer-undo-list`):
>> 
>>     An entry of the form POSITION indicates that point was at the buffer
>>     location given by the integer.  Undoing an entry of this form places
>>     point at POSITION.
>> 
>> As for whether we should add such a record in the OP's scenario, and how
>> to do that, I haven't looked at his scenario in enough detail to have
>> much to say about it.
>
> I don't think we record position of point before deletion.

I think we do, at least sometimes:

    record_delete (ptrdiff_t beg, Lisp_Object string, bool record_markers)
    {
      [...]
      record_point (beg);


-- Stefan





Severity set to 'wishlist' from 'normal' Request was from Stefan Kangas <stefankangas <at> gmail.com> to control <at> debbugs.gnu.org. (Mon, 04 Sep 2023 15:13:01 GMT) Full text and rfc822 format available.

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

Previous Next


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