From 974192413f8a81171b8fd28dfd5c081ce06d3dec Mon Sep 17 00:00:00 2001 From: Alan Mackenzie Date: Fri, 12 Nov 2021 18:43:22 +0000 Subject: [PATCH] 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. --- src/fileio.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/fileio.c b/src/fileio.c index 3c13d3fe416..a7b1649fae8 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); } } -- 2.39.2