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.devel Subject: Re: non-local exits in redisplay Date: Mon, 12 Oct 2020 20:01:55 +0300 Message-ID: <83h7qz2xa4.fsf@gnu.org> References: <86h7r0v4ed.fsf@akirakyle.com> <86d01ouw4e.fsf@akirakyle.com> Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="23879"; mail-complaints-to="usenet@ciao.gmane.io" Cc: monnier@iro.umontreal.ca, emacs-devel@gnu.org To: Akira Kyle Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Mon Oct 12 19:02:42 2020 Return-path: Envelope-to: ged-emacs-devel@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 1kS1Dd-00066T-W6 for ged-emacs-devel@m.gmane-mx.org; Mon, 12 Oct 2020 19:02:41 +0200 Original-Received: from localhost ([::1]:59260 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kS1Dd-0000un-2N for ged-emacs-devel@m.gmane-mx.org; Mon, 12 Oct 2020 13:02:41 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:49210) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kS1Ct-0000SW-9G for emacs-devel@gnu.org; Mon, 12 Oct 2020 13:01:56 -0400 Original-Received: from fencepost.gnu.org ([2001:470:142:3::e]:46526) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kS1Cr-0001pX-KA; Mon, 12 Oct 2020 13:01:53 -0400 Original-Received: from [176.228.60.248] (port=2375 helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:RSA_AES_256_CBC_SHA1:256) (Exim 4.82) (envelope-from ) id 1kS1Co-0005Zp-34; Mon, 12 Oct 2020 13:01:50 -0400 In-Reply-To: <86d01ouw4e.fsf@akirakyle.com> (message from Akira Kyle on Sun, 11 Oct 2020 18:27:13 -0600) X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.io gmane.emacs.devel:257483 Archived-At: > From: Akira Kyle > Date: Sun, 11 Oct 2020 18:27:13 -0600 > Cc: emacs-devel@gnu.org > > > In `src/xdisp.c` there's things like `safe_call` (as well as > > `safe_call1` and `safe_call2`) for that. > > > > IIRC it uses the underlying condition-case machinery. > > > > That's exactly what I was looking for, thanks! > > Now the natural follow up question: Is it ok to use the error > functions which end up calling xsignal in redisplay when one is > sure it won't cause this sort of infinite loop? In my testing it > looks like the error message ends up displaying ok, but are there > any other gotchas I should look out for here? As Stefan mentions, you are well advised not to signal errors inside redisplay. The reason is simple: signaling an error always reenters redisplay immediately, because we need to display the error message. While that is a special kind of redisplay, it usually redraws at least one window, and can redraw more, depending on what exactly is on display. It is virtually impossible to predict when displaying the error signal message will hit the same error again; even if you seem to be able to get away with that in some situation, another user of your code might not be so lucky, if they use some specialized feature, like post-command-hooks that affect the display (it could be as simple as hl-line-mode or similar), or functions that run off timers that display something, or any number of other optional features, of which Emacs has a gazillion. So you really shouldn't signal errors from redisplay. the most you can do is silently deposit an error message in the *Messages* buffer (that's what the safe_call and friends do, btw) and hope that the user will look there at some point, e.g. because the display doesn't look "right". Can you explain why you'd need to signal an error from the display code? Maybe we can find some way of dealing with your problem that is better than just inserting a message in *Messages*. And one more thing: please don't over-use the safe_call facility as well, i.e. try not to call too much Lisp from the display engine. As convenient as that may sound, calling Lisp from display has its downsides. For starters, it produces more garbage, which triggers more frequent GCs, which slows down Emacs. So if you are tempted to call Lisp, try first to find an equivalent way of doing that in C (don't hesitate to ask questions if you cannot find it or are unsure how to do that), and only use Lisp if the alternative is not reasonable. Thanks.