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: Akira Kyle
Subject: Re: non-local exits in redisplay
Date: Mon, 12 Oct 2020 13:19:25 -0600
User-agent: mu4e 1.4.13; emacs 28.0.50


On Mon, Oct 12, 2020 at 11:01 AM, Eli Zaretskii <eliz@gnu.org> wrote:

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.

Yes as I'm learning more about the interplay between the lisp interpreter and the complicated machinery of redisplay, I'm realizing there are many ways to shoot yoursef in the foot.

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".

Which isn't very satisfactory from a UI perspective. I suppose setting some flag in redisplay which could then be checked later in lisp to signal the error would be the obvious work around.

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.

Perhaps I'm really getting ahead of myself here...
I'll describe what my goal is for the xwidgets code, which is what ultimately prompted this question, in a new thread in case others might be interested in commenting on it.

Thanks!
Akira



reply via email to

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