unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Eli Zaretskii <eliz@gnu.org>
To: Caio Henrique <caiohcs0@gmail.com>,
	Stefan Monnier <monnier@iro.umontreal.ca>
Cc: 43397@debbugs.gnu.org
Subject: bug#43397: 28.0.50; Adding tool bar items: update tool bar
Date: Tue, 15 Sep 2020 18:27:17 +0300	[thread overview]
Message-ID: <83lfhb83hm.fsf@gnu.org> (raw)
In-Reply-To: <87h7s0jurl.fsf@gmail.com> (message from Caio Henrique on Mon, 14 Sep 2020 11:30:22 -0300)

> From: Caio Henrique <caiohcs0@gmail.com>
> Date: Mon, 14 Sep 2020 11:30:22 -0300
> 
> 1. emacs -Q
> 2. paste and eval this:
> (progn
>   (tool-bar-add-item-from-menu 'undo-redo
> 			       "redo" nil :vert-only t)
>   (redraw-display)
>   (force-mode-line-update))
> 
> 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:

  emacs -Q
  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.)

Then evaluate:

  (defun myfun ()
    (interactive)
    (tool-bar-add-item "redo" 'undo-redo 'undo-redo)
    (garbage-collect))

  (global-set-key [f5] 'myfun)

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





  parent reply	other threads:[~2020-09-15 15:27 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-14 14:30 bug#43397: 28.0.50; Adding tool bar items: update tool bar Caio Henrique
2020-09-14 21:44 ` Caio Henrique
2020-09-15 15:27 ` Eli Zaretskii [this message]
2020-09-15 20:05   ` Stefan Monnier
2020-09-16  2:26     ` Eli Zaretskii
2021-08-27 17:40   ` Lars Ingebrigtsen
2021-08-27 22:04     ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2021-08-28 15:30       ` Lars Ingebrigtsen
2022-05-03 15:28         ` Lars Ingebrigtsen
2022-05-03 15:41           ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-05-03 16:09             ` Lars Ingebrigtsen
2022-05-03 16:19               ` Lars Ingebrigtsen
2022-05-03 16:49                 ` Eli Zaretskii
2022-05-03 16:50                   ` Lars Ingebrigtsen
2022-05-03 16:31               ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-05-03 16:39                 ` Lars Ingebrigtsen
2022-05-03 16:46                   ` Lars Ingebrigtsen
2022-05-03 16:54                     ` Eli Zaretskii
2022-05-03 16:57                       ` Lars Ingebrigtsen
2022-05-03 17:53                   ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-05-03 18:58                     ` Lars Ingebrigtsen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=83lfhb83hm.fsf@gnu.org \
    --to=eliz@gnu.org \
    --cc=43397@debbugs.gnu.org \
    --cc=caiohcs0@gmail.com \
    --cc=monnier@iro.umontreal.ca \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).