emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: non-local exits in redisplay


From: Eli Zaretskii
Subject: Re: non-local exits in redisplay
Date: Mon, 12 Oct 2020 20:01:55 +0300

> From: Akira Kyle <ak@akirakyle.com>
> 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.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]