From fb62728b7afa7024d4ca01e6f89b0267231cf607 Mon Sep 17 00:00:00 2001 From: Eli Zaretskii Date: Sat, 1 Jul 2017 10:22:45 +0300 Subject: [PATCH] Avoid slow redisplay under 'visual' mode of line numbers * src/xdisp.c (display_count_lines_visually): Avoid very slow redisplay when this function is invoked very far from point. Reported by Alex . --- src/xdisp.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/xdisp.c b/src/xdisp.c index aeccac2cb16..7bbe9d9ca3e 100644 --- a/src/xdisp.c +++ b/src/xdisp.c @@ -20783,7 +20783,14 @@ display_count_lines_visually (struct it *it) /* Need to disable visual mode temporarily, since otherwise the call to move_it_to will cause infinite recursion. */ specbind (Qdisplay_line_numbers, Qrelative); - move_it_to (&tem_it, to, -1, -1, -1, MOVE_TO_POS); + /* Some redisplay optimizations could invoke us very far from + PT, which will make the caller painfully slow. There should + be no need to go too far beyond the window's bottom, as any + such optimization will fail to show point anyway. */ + move_it_to (&tem_it, to, -1, + tem_it.last_visible_y + + (SCROLL_LIMIT + 10) * FRAME_LINE_HEIGHT (tem_it.f), + -1, MOVE_TO_POS | MOVE_TO_Y); unbind_to (count, Qnil); return IT_CHARPOS (*it) <= PT ? -tem_it.vpos : tem_it.vpos; } -- 2.39.2