I'm using both redraw-display and force-mode-line-update to try to force
the tool-bar to draw the icon (I know that I should'nt do this, I'm just
trying to figure if this is a bug); but the icon only appears when I
click one or two times with the mouse anywhere in the buffer.
> From: Caio Henrique <[hidden email]>
> Date: Mon, 14 Sep 2020 11:30:22 -0300
> 1. emacs -Q
> 2. paste and eval this:
> (tool-bar-add-item-from-menu 'undo-redo
> "redo" nil :vert-only t)
> I'm using both redraw-display and force-mode-line-update to try to force
> the tool-bar to draw the icon (I know that I should'nt do this, I'm just
> trying to figure if this is a bug)
(Calling force-mode-line-update won't help, because
tool-bar-add-item-from-menu does it internally.)
> but the icon only appears when I
> click one or two times with the mouse anywhere in the buffer.
I've now looked into this, and I'm quite sure it is not a redisplay
bug. The display engine faithfully inspects the tool-bar items each
time it is invoked after the above code runs, and each time it finds
that the tool-bar items haven't changed -- until they do.
Based on what I see, and on the modified recipe below, it looks like
we stick to the old value of the tool-bar items, like if we cached
them somewhere. Since I don't understand where is that "cache", I
don't really have a clear idea of what triggers the flushing of that
"cache", but one trigger I found is -- surprise! -- GC. To see this,
perform the following greatly simplified recipe:
M-x blink-cursor-mode RET
M-x global-eldoc-mode RET
(The last two commands are to make sure there are no redisplay cycles
except due to changes in buffers or strings.)
Finally, press F5: you should see the "redo" icon appear immediately.
Now repeat the same, in a fresh Emacs session, but this time remove
the call to garbage-collect from myfun, and instead do this before
evaluating the function and the global-set-key form:
M-x set-variable RET garbage-collection-messages RET t RET
Then evaluate the forms and press F5. The tool bar won't change. Now
do some random clicks, watching the echo area: you will see that the
tool bar is updated with the "redo" icon precisely when the "Garbage
collecting..." message appears in the echo area.
Maybe Stefan (CC'ed) can help us understand why this happens and how
GC is involved in this...
bug#43397: 28.0.50; Adding tool bar items: update tool bar
> From: Stefan Monnier <[hidden email]>
> Cc: Caio Henrique <[hidden email]>, [hidden email] > Date: Tue, 15 Sep 2020 16:05:53 -0400
> > Maybe Stefan (CC'ed) can help us understand why this happens and how
> > GC is involved in this...
> I'm afraid I don't know much more than you do here.
We are basically talking about modifying a keymap, since this is what
tool-bar-add-item and friends do. The question is: why isn't the
modified keymap immediately visible? why does the old keymap continue
to be visible until the next GC?