+ if (MATRIX_ROW_DISPLAYS_TEXT_P (row)
+ && ((last_changed_charpos < CHARPOS (start)
+ && CHARPOS (start) == BEGV)
+ || (last_changed_charpos < CHARPOS (start) - 1
+ && FETCH_BYTE (BYTEPOS (start) - 1) == '\n')))
+ {
+ int Z_old, delta, Z_BYTE_old, delta_bytes;
+ struct glyph_row *r0;
+
+ /* Compute how many chars/bytes have been added to or removed
+ from the buffer. */
+ Z_old = MATRIX_ROW_END_CHARPOS (row) + XFASTINT (w->window_end_pos);
+ Z_BYTE_old = MATRIX_ROW_END_BYTEPOS (row) + w->window_end_bytepos;
+ delta = Z - Z_old;
+ delta_bytes = Z_BYTE - Z_BYTE_old;
+
+ /* Give up if PT is not in the window. Note that it already has
+ been checked at the start of try_window_id that PT is not in
+ front of the window start. */
+ if (PT >= MATRIX_ROW_END_CHARPOS (row) + delta)
+ GIVE_UP (13);
+
+ /* If window start is unchanged, we can reuse the whole matrix
+ as is, after adjusting glyph positions. No need to compute
+ the window end again, since its offset from Z hasn't changed. */
+ r0 = MATRIX_FIRST_TEXT_ROW (current_matrix);
+ if (CHARPOS (start) == MATRIX_ROW_START_CHARPOS (r0) + delta
+ && BYTEPOS (start) == MATRIX_ROW_START_BYTEPOS (r0) + delta_bytes)
+ {
+ /* Adjust positions in the glyph matrix. */
+ if (delta || delta_bytes)
+ {
+ struct glyph_row *r1
+ = MATRIX_BOTTOM_TEXT_ROW (current_matrix, w);
+ increment_matrix_positions (w->current_matrix,
+ MATRIX_ROW_VPOS (r0, current_matrix),
+ MATRIX_ROW_VPOS (r1, current_matrix),
+ delta, delta_bytes);
+ }
+
+ /* Set the cursor. */
+ row = row_containing_pos (w, PT, r0, NULL);
+ set_cursor_from_row (w, row, current_matrix, 0, 0, 0, 0);
+ return 1;
+ }
+ }
+
+ /* Handle the case that changes are all below what is displayed in
+ the window, and that PT is in the window. This shortcut cannot
+ be taken if ZV is visible in the window, and text has been added
+ there that is visible in the window. */
+ if (first_changed_charpos >= MATRIX_ROW_END_CHARPOS (row)
+ /* ZV is not visible in the window, or there are no
+ changes at ZV, actually. */
+ && (current_matrix->zv > MATRIX_ROW_END_CHARPOS (row)
+ || first_changed_charpos == last_changed_charpos))