From: Alan Mackenzie Date: Fri, 12 Nov 2021 18:43:22 +0000 (+0000) Subject: In insert_file_contents, always set windows' point markers. X-Git-Tag: emacs-29.0.90~3668^2~6 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=974192413f8a81171b8fd28dfd5c081ce06d3dec;p=emacs.git 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. --- 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); } }