unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Stefan Monnier via "Bug reports for GNU Emacs, the Swiss army knife of text editors" <bug-gnu-emacs@gnu.org>
To: Alan Mackenzie <acm@muc.de>
Cc: 51776@debbugs.gnu.org
Subject: bug#51776: master 9741924: In insert_file_contents, always set windows' point markers.
Date: Fri, 12 Nov 2021 19:27:29 -0500	[thread overview]
Message-ID: <jwv4k8g9afg.fsf-monnier+emacs@gnu.org> (raw)
In-Reply-To: <20211112184452.6C899209C6@vcs0.savannah.gnu.org> (Alan Mackenzie's message of "Fri, 12 Nov 2021 13:44:52 -0500 (EST)")

Hi Alan,

Alan Mackenzie [2021-11-12 13:44:52] wrote:
>     In insert_file_contents, always set windows' point markers.
>     This fixes bug #51776.
>
>     * src/fileio.c (restore_window_points): Restore a w->mpoint even
>     when that marker originally pointed into the unchanged area near
>     BOB or EOB.  This prevents that window's point being moved a long
>     way from its starting place due to the removal of the central part
>     of the buffer by insert_file_contents.

Hmm... my understanding of the code says that if `oldppos <= same_at_beg` then
your change is harmless but unnecessary because the marker
is still at `oldpos` anyway.

But when `oldppos > same_at_beg` your change is harmful because the
marker has properly preserved its exact position in the text whereas
your code will arbitrarily move it to `oldpos` (which is even
potentially past Z if the revert shortened the buffer).

So maybe the better fix is to just change

    XFIXNUM (oldpos) < same_at_end

into

    XFIXNUM (oldpos) <= same_at_end

Or am I missing something?

[ Not sure what we should do when `oldpos == same_at_beg == same_at_end`, OTOH.
  I suspect staying at `same_at_beg` might be the better choice in that
  case.  ]


        Stefan


>  src/fileio.c | 9 ++++++---
>  1 file changed, 6 insertions(+), 3 deletions(-)
>
> diff --git a/src/fileio.c b/src/fileio.c
> index 3c13d3f..a7b1649 100644
> --- a/src/fileio.c
> +++ b/src/fileio.c
> @@ -3827,6 +3827,7 @@ restore_window_points (Lisp_Object window_markers, ptrdiff_t inserted,
>  	Lisp_Object car = XCAR (window_markers);
>  	Lisp_Object marker = XCAR (car);
>  	Lisp_Object oldpos = XCDR (car);
> +	ptrdiff_t newpos;
>  	if (MARKERP (marker) && FIXNUMP (oldpos)
>  	    && XFIXNUM (oldpos) > same_at_start
>  	    && XFIXNUM (oldpos) < same_at_end)
> @@ -3834,10 +3835,12 @@ restore_window_points (Lisp_Object window_markers, ptrdiff_t inserted,
>  	    ptrdiff_t oldsize = same_at_end - same_at_start;
>  	    ptrdiff_t newsize = inserted;
>  	    double growth = newsize / (double)oldsize;
> -	    ptrdiff_t newpos
> -	      = same_at_start + growth * (XFIXNUM (oldpos) - same_at_start);
> -	    Fset_marker (marker, make_fixnum (newpos), Qnil);
> +	    newpos = same_at_start
> +	      + growth * (XFIXNUM (oldpos) - same_at_start);
>  	  }
> +	else
> +	  newpos = XFIXNUM (oldpos);
> +	Fset_marker (marker, make_fixnum (newpos), Qnil);
>        }
>  }
>  






       reply	other threads:[~2021-11-13  0:27 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20211112184451.21516.85178@vcs0.savannah.gnu.org>
     [not found] ` <20211112184452.6C899209C6@vcs0.savannah.gnu.org>
2021-11-13  0:27   ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors [this message]
2021-11-13 12:29     ` bug#51776: master 9741924: In insert_file_contents, always set windows' point markers Alan Mackenzie

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=jwv4k8g9afg.fsf-monnier+emacs@gnu.org \
    --to=bug-gnu-emacs@gnu.org \
    --cc=51776@debbugs.gnu.org \
    --cc=acm@muc.de \
    --cc=monnier@iro.umontreal.ca \
    /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).