From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Eli Zaretskii Newsgroups: gmane.emacs.bugs Subject: bug#45898: 27.1; wedged in redisplay again Date: Sun, 12 Jun 2022 17:23:50 +0300 Message-ID: <83mteiufih.fsf@gnu.org> References: <46b65e3f-cf3d-a3f2-9a9a-100e58274ff6@jovi.net> <87h74wh9x7.fsf@gnus.org> <83bkv47evy.fsf@gnu.org> <87k09rbcmn.fsf@gnus.org> <83a6an5jt3.fsf@gnu.org> <8335gf5er3.fsf@gnu.org> <87leu686z4.fsf@gnus.org> <83sfoe2k0j.fsf@gnu.org> <87zgim6qtt.fsf@gnus.org> <83mtem2dc9.fsf@gnu.org> <87y1y63qmq.fsf@gnus.org> <83h74t3k5u.fsf@gnu.org> <87tu8sx569.fsf@gnus.org> <83v8t6us8t.fsf@gnu.org> <87zgiinptk.fsf@gnus.org> Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="9814"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Emacs-hacker2018@jovi.net, 45898@debbugs.gnu.org To: Lars Ingebrigtsen Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sun Jun 12 16:25:19 2022 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1o0OWk-0002Pc-R8 for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 12 Jun 2022 16:25:19 +0200 Original-Received: from localhost ([::1]:58950 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o0OWj-0003yy-EX for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 12 Jun 2022 10:25:17 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:49912) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o0OWU-0003yn-Bn for bug-gnu-emacs@gnu.org; Sun, 12 Jun 2022 10:25:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:34208) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1o0OWU-0001l9-3Q for bug-gnu-emacs@gnu.org; Sun, 12 Jun 2022 10:25:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1o0OWT-0001rN-Ty for bug-gnu-emacs@gnu.org; Sun, 12 Jun 2022 10:25:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Eli Zaretskii Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 12 Jun 2022 14:25:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 45898 X-GNU-PR-Package: emacs Original-Received: via spool by 45898-submit@debbugs.gnu.org id=B45898.16550438567091 (code B ref 45898); Sun, 12 Jun 2022 14:25:01 +0000 Original-Received: (at 45898) by debbugs.gnu.org; 12 Jun 2022 14:24:16 +0000 Original-Received: from localhost ([127.0.0.1]:56338 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1o0OVj-0001qG-S0 for submit@debbugs.gnu.org; Sun, 12 Jun 2022 10:24:16 -0400 Original-Received: from eggs.gnu.org ([209.51.188.92]:36706) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1o0OVg-0001q1-7X for 45898@debbugs.gnu.org; Sun, 12 Jun 2022 10:24:14 -0400 Original-Received: from fencepost.gnu.org ([2001:470:142:3::e]:47412) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o0OVa-0001jA-EY; Sun, 12 Jun 2022 10:24:06 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=References:Subject:In-Reply-To:To:From:Date: mime-version; bh=Ix1wmgLtCkLGlp68ObV4p4X4W2hgTQgJPVxyyzkAqig=; b=iGwEGehvWSNt r3fQE/OqUnZ5HjFQzTUqsTxAGouFC3BKcTxZg619g6Vt+ftrC/PlPyzZOBjAsgn0eSESdX0JuPT61 UHKs9I8SaB4/J4e3z3EoLlUttPwQj1yUF/FOhs3OD1LsMjCaQXr/ODLuYpkPaKN7wnb8hxVYRZr2r fHfvGiR8fV1m0nSMleNRy618VC/j/uMhKieHiPRsakdPnCYhopCwkzkjUXb/rB5VYJ4B44qOVOoCn kunXRP4tYVMcptO7RbJJevTpnI8fr4BxPRvVPI+cQ2Q0iyYRXF8faV/ztQ9g8vTLPyOlftX8qvXfY Nc/DWy9KAwvb3W0AP+5HVA==; Original-Received: from [87.69.77.57] (port=1473 helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o0OVZ-00061F-Sn; Sun, 12 Jun 2022 10:24:06 -0400 In-Reply-To: <87zgiinptk.fsf@gnus.org> (message from Lars Ingebrigtsen on Sun, 12 Jun 2022 12:23:03 +0200) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:234365 Archived-At: > From: Lars Ingebrigtsen > Cc: Emacs-hacker2018@jovi.net, 45898@debbugs.gnu.org > Date: Sun, 12 Jun 2022 12:23:03 +0200 > > >> Finding a safe way to interrupt redisplay is the problem, though. > > > > I have an idea and will work on it soon. > > Great! Here's the first cut. It still needs polishing and some testing, but let me know what you think: diff --git a/src/dispextern.h b/src/dispextern.h index c7399ca..a919f36 100644 --- a/src/dispextern.h +++ b/src/dispextern.h @@ -3505,6 +3505,8 @@ #define TRY_WINDOW_IGNORE_FONTS_CHANGE (1 << 1) extern bool buffer_flipping_blocked_p (void); +extern void update_redisplay_ticks (int, struct it *); + /* Defined in image.c */ #ifdef HAVE_WINDOW_SYSTEM diff --git a/src/xdisp.c b/src/xdisp.c index 2245326..6d4cb9f 100644 --- a/src/xdisp.c +++ b/src/xdisp.c @@ -3222,6 +3222,8 @@ init_iterator (struct it *it, struct window *w, it->cmp_it.id = -1; + update_redisplay_ticks (0, it); + /* Extra space between lines (on window systems only). */ if (base_face_id == DEFAULT_FACE_ID && FRAME_WINDOW_P (it->f)) @@ -8175,6 +8177,8 @@ get_next_display_element (struct it *it) set_iterator_to_next (struct it *it, bool reseat_p) { + update_redisplay_ticks (1, it); + switch (it->method) { case GET_FROM_BUFFER: @@ -16724,9 +16728,14 @@ #define AINC(a,i) \ list_of_error, redisplay_window_error); if (update_miniwindow_p) - internal_condition_case_1 (redisplay_window_1, - FRAME_MINIBUF_WINDOW (sf), list_of_error, - redisplay_window_error); + { + Lisp_Object mini_window = FRAME_MINIBUF_WINDOW (sf); + + displayed_buffer = XBUFFER (XWINDOW (mini_window)->contents); + internal_condition_case_1 (redisplay_window_1, mini_window, + list_of_error, + redisplay_window_error); + } /* Compare desired and current matrices, perform output. */ @@ -17156,6 +17165,43 @@ redisplay_window_1 (Lisp_Object window) redisplay_window (window, true); return Qnil; } + + +/*********************************************************************** + Aborting runaway redisplay + ***********************************************************************/ + +/* Update the redisplay-tick count for a window, and signal an error + if the tick count is above some threshold, indicating that + redisplay of the window takes "too long". + + TICKS is the amount of ticks to add to the window's current count; + zero means to initialize the count to zero. + + IT is the iterator used for redisplay work; it->w is the window we + are working on. */ +void +update_redisplay_ticks (int ticks, struct it *it) +{ + /* This keeps track of the window on which redisplay is working. */ + static struct window *cwindow; + static EMACS_INT window_ticks; + + /* We only initialize the count if this is a different window. + Otherwise, this is a call from init_iterator for the same window + we tracked before, and we should keep the count. */ + if (!ticks && it->w != cwindow) + { + cwindow = it->w; + window_ticks = 0; + } + if (ticks > 0) + window_ticks += ticks; + if (max_redisplay_ticks > 0 && window_ticks > max_redisplay_ticks) + error ("Window showing buffer %s takes too long to redisplay", + SSDATA (BVAR (XBUFFER (it->w->contents), name))); +} + /* Set cursor position of W. PT is assumed to be displayed in ROW. @@ -35777,7 +35823,7 @@ syms_of_xdisp (void) DEFSYM (Qinhibit_free_realized_faces, "inhibit-free-realized-faces"); - list_of_error = list1 (list2 (Qerror, Qvoid_variable)); + list_of_error = list1 (Qerror); staticpro (&list_of_error); /* Values of those variables at last redisplay are stored as @@ -36667,6 +36713,22 @@ syms_of_xdisp (void) This makes it easier to edit character sequences that are composed on display. */); composition_break_at_point = false; + + DEFVAR_INT ("max-redisplay-ticks", max_redisplay_ticks, + doc: /* Maximum number of redisplay ticks before aborting redisplay of a window. + +This allows to abort the display of a window if the amount of low-level +redisplay operations exceeds the value of this variable. When display of +a window is aborted due to this reason, the buffer shown in that window +will not have its windows redisplayed until the buffer is modified or until +you type \\[recenter-top-bottom] with one of its windows selected. +You can also decide to kill the buffer and visit it in some +other way, like udner `so-long-mode' or literally. + +The default value is zero, which disables this feature. +The recommended non-zero value is between 50000 and 200000, +depending on your patience and the speed of your system. */); + max_redisplay_ticks = 0; }