all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* how to redraw the tool bar
@ 2014-12-25 14:48 Bostjan Vilfan
  2014-12-26 19:37 ` Michael Heerdegen
  2014-12-27  1:50 ` Stefan Monnier
  0 siblings, 2 replies; 9+ messages in thread
From: Bostjan Vilfan @ 2014-12-25 14:48 UTC (permalink / raw)
  To: help-gnu-emacs; +Cc: bjvilfan

[-- Attachment #1: Type: text/plain, Size: 391 bytes --]

Hello,
I have the following problem with emacs: I like to employ tool bars in my work, and I add elements to them with tool-bar-add-item-from-menu or tool-bar-local-item. However, I notice that most of the time it takes some effort (multiple clicks) to make the changed tool bar appear. Is there any way I can force a redraw of the toolbar? Thanks in advance for an answer.
Regards,
bostjanv

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: how to redraw the tool bar
  2014-12-25 14:48 how to redraw the tool bar Bostjan Vilfan
@ 2014-12-26 19:37 ` Michael Heerdegen
  2014-12-27  1:50 ` Stefan Monnier
  1 sibling, 0 replies; 9+ messages in thread
From: Michael Heerdegen @ 2014-12-26 19:37 UTC (permalink / raw)
  To: help-gnu-emacs

Bostjan Vilfan <bostjanv@alum.mit.edu> writes:

> [...] Is there any way I can force a redraw of the toolbar? Thanks in
> advance for an answer.

I guess `redraw-frame' should do this.




^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: how to redraw the tool bar
  2014-12-25 14:48 how to redraw the tool bar Bostjan Vilfan
  2014-12-26 19:37 ` Michael Heerdegen
@ 2014-12-27  1:50 ` Stefan Monnier
  2014-12-27 22:08   ` Bostjan Vilfan
  1 sibling, 1 reply; 9+ messages in thread
From: Stefan Monnier @ 2014-12-27  1:50 UTC (permalink / raw)
  To: help-gnu-emacs

> I have the following problem with emacs: I like to employ tool bars in my
> work, and I add elements to them with tool-bar-add-item-from-menu or
> tool-bar-local-item. However, I notice that most of the time it takes some
> effort (multiple clicks) to make the changed tool bar appear. Is there any
> way I can force a redraw of the toolbar? Thanks in advance for an answer.

I think force-mode-line-update should do the trick,


        Stefan




^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: how to redraw the tool bar
  2014-12-27  1:50 ` Stefan Monnier
@ 2014-12-27 22:08   ` Bostjan Vilfan
  2014-12-31 22:13     ` Michael Heerdegen
  0 siblings, 1 reply; 9+ messages in thread
From: Bostjan Vilfan @ 2014-12-27 22:08 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: Emacs Help

Hello,
Thanks for the replies. Unfortunately, neither of the two suggestions
works. Therefore, I'm going to include some more detail, and perhaps
somebody can point to what I am doing wrong

The problem arose when I tried to build a toolbar for tex-mode. So I
included the following line in my init file:

(add-hook 'tex-mode-hook 'bv-tex-mode)

where bv-tex-mode is the following function:

(defun bv-tex-mode ()
   "hook for building TeX tool bar"
   (interactive nil)
;; copy global tool-bar-map using copy-sequence
   (let ((temp (copy-sequence tool-bar-map)))
     (make-local-variable 'tool-bar-map)
     (setq tool-bar-map temp)
   )
   (define-key global-map [tool-bar bvdotex] 'tex-file)
   (tool-bar-local-item  "tex" 'tex-file 'bvdotex tool-bar-map
                    :help "Process file with default tex command")
   (define-key global-map [tool-bar bvpdfview] 'bv-pdf-view)
   (tool-bar-local-item  "pdf" 'bv-pdf-view 'bvpdfview tool-bar-map
 :help "view pdf file")
   (redraw-frame)
)

This version uses redraw-frame; but the result with force-mode-line-update
was the same. In effect, when I load a tex file I have to use several
clicks before the new icons appear.

Regards,
bostjanv

On Sat, Dec 27, 2014 at 2:50 AM, Stefan Monnier <monnier@iro.umontreal.ca>
wrote:

> > I have the following problem with emacs: I like to employ tool bars in my
> > work, and I add elements to them with tool-bar-add-item-from-menu or
> > tool-bar-local-item. However, I notice that most of the time it takes
> some
> > effort (multiple clicks) to make the changed tool bar appear. Is there
> any
> > way I can force a redraw of the toolbar? Thanks in advance for an answer.
>
> I think force-mode-line-update should do the trick,
>
>
>         Stefan
>
>
>


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: how to redraw the tool bar
  2014-12-27 22:08   ` Bostjan Vilfan
@ 2014-12-31 22:13     ` Michael Heerdegen
  2015-01-01 15:35       ` bug#19480: (no subject) Eli Zaretskii
  0 siblings, 1 reply; 9+ messages in thread
From: Michael Heerdegen @ 2014-12-31 22:13 UTC (permalink / raw)
  To: Bostjan Vilfan; +Cc: Emacs Help, Stefan Monnier

Bostjan Vilfan <bjvilfan@gmail.com> writes:

> This version uses redraw-frame; but the result with force-mode-line-update
> was the same. In effect, when I load a tex file I have to use several
> clicks before the new icons appear.

Indeed, this doesn't work for me too.

Here is a small example for emacs -Q:

(progn
  (define-key global-map [tool-bar bvdotex] 'tex-file)
  (tool-bar-local-item  "save" 'tex-file 'bvdotex tool-bar-map
                        :help "Process file with default tex command"))

Evaluate it, and you have to "do some things" until the item is displayed.
No way of redisplay helps to force the displaying of the button, and it
seems to appear after a random command.

I guess all the Emacs modes set up the toolbar before it is actually
displayed.  Doing it afterwards doesn't seem to work reliably.  I don't
see such a limitation being described in the manual, so Bostjan, please
M-x report-emacs-bug, preferably including a simple recipe as above.


Thanks,

Michael.



^ permalink raw reply	[flat|nested] 9+ messages in thread

* bug#19480: (no subject)
  2014-12-31 22:13     ` Michael Heerdegen
@ 2015-01-01 15:35       ` Eli Zaretskii
  2015-01-01 20:37         ` Michael Heerdegen
  2022-05-03 16:58         ` bug#19480: Tool-bar modifications not reflected on display Lars Ingebrigtsen
  0 siblings, 2 replies; 9+ messages in thread
From: Eli Zaretskii @ 2015-01-01 15:35 UTC (permalink / raw)
  To: Michael Heerdegen; +Cc: bjvilfan, 19480

[Moved this here from help-gnu-emacs.  For the original thread, see
http://lists.gnu.org/archive/html/help-gnu-emacs/2014-12/msg00379.html.]

> From: Michael Heerdegen <michael_heerdegen@web.de>
> Date: Wed, 31 Dec 2014 23:13:54 +0100
> Cc: Emacs Help <help-gnu-emacs@gnu.org>,
> 	Stefan Monnier <monnier@iro.umontreal.ca>
> 
> Bostjan Vilfan <bjvilfan@gmail.com> writes:
> 
> (progn
>   (define-key global-map [tool-bar bvdotex] 'tex-file)
>   (tool-bar-local-item  "save" 'tex-file 'bvdotex tool-bar-map
>                         :help "Process file with default tex command"))
> 
> Evaluate it, and you have to "do some things" until the item is displayed.
> No way of redisplay helps to force the displaying of the button, and it
> seems to appear after a random command.
> 
> I guess all the Emacs modes set up the toolbar before it is actually
> displayed.  Doing it afterwards doesn't seem to work reliably.  I don't
> see such a limitation being described in the manual

This should fix the problem:

  (progn
    (define-key global-map [tool-bar bvdotex] 'tex-file)
    (tool-bar-local-item  "save" 'tex-file 'bvdotex tool-bar-map
			  :help "Process file with default tex command")
    (force-mode-line-update)
    (garbage-collect))

The last line is the reason that you need to "do some things" in order
for the tool bar to get updated: you need to eval enough stuff so that
Emacs enters GC.

This is a clear bug, and it has 2 parts, an easy one and a harder one.

The easy part is to add a call to force-mode-line-update to 2
functions that modify tool-bar-map (done in commit 5a9710f on the
emacs-24 branch).

The harder part, the one that requires a GC, has something to do with
the fact that we use a hash table to avoid recomputing tool-bar items
when the tool bar didn't change.  From tool-bar.el:

  (global-set-key [tool-bar]
		  `(menu-item ,(purecopy "tool bar") ignore
			      :filter tool-bar-make-keymap))

  (defconst tool-bar-keymap-cache (make-hash-table :weakness t :test 'equal))

  (defun tool-bar-make-keymap (&optional _ignore)
    "Generate an actual keymap from `tool-bar-map'.
  Its main job is to figure out which images to use based on the display's
  color capability and based on the available image libraries."
    (let ((key (cons (frame-terminal) tool-bar-map)))
      (or (gethash key tool-bar-keymap-cache)
	  (puthash key (tool-bar-make-keymap-1) tool-bar-keymap-cache))))

We started doing this in Emacs 23, and sure enough, this problem
didn't exist in Emacs 22, where just evaluating the original progn
above, without the last two lines, immediately caused the tool bar to
be updated.  Emacs 23 already exhibits the problem.

By stepping through tool-bar-make-keymap, I've discovered that after
the tool-bar-map is updated, gethash still returns non-nil, as if the
old value of tool-bar-map were still in effect.  So we don't recompute
the updated keymap from tool-bar-map, and redisplay doesn't think the
tool bar changed and should be redrawn.

Mind you, this is on MS-Windows, which represents the toolkits where
Emacs itself displays the tool bar; the GTK and NS builds might have
different or additional quirks.

I hope the above will give enough info to keymap experts to fix the
remaining problem (please do that on the emacs-24 branch).





^ permalink raw reply	[flat|nested] 9+ messages in thread

* bug#19480: (no subject)
  2015-01-01 15:35       ` bug#19480: (no subject) Eli Zaretskii
@ 2015-01-01 20:37         ` Michael Heerdegen
  2015-01-01 20:56           ` Eli Zaretskii
  2022-05-03 16:58         ` bug#19480: Tool-bar modifications not reflected on display Lars Ingebrigtsen
  1 sibling, 1 reply; 9+ messages in thread
From: Michael Heerdegen @ 2015-01-01 20:37 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: bjvilfan, 19480

Hi Eli,

> This should fix the problem:
>
>   (progn
>     (define-key global-map [tool-bar bvdotex] 'tex-file)
>     (tool-bar-local-item  "save" 'tex-file 'bvdotex tool-bar-map
> 			  :help "Process file with default tex command")
>     (force-mode-line-update)
>     (garbage-collect))

I can confirm that this avoids the problem under Debian Gnu/Linux using
the GTK+ toolkit.

Michael.





^ permalink raw reply	[flat|nested] 9+ messages in thread

* bug#19480: (no subject)
  2015-01-01 20:37         ` Michael Heerdegen
@ 2015-01-01 20:56           ` Eli Zaretskii
  0 siblings, 0 replies; 9+ messages in thread
From: Eli Zaretskii @ 2015-01-01 20:56 UTC (permalink / raw)
  To: Michael Heerdegen; +Cc: bjvilfan, 19480

> From: Michael Heerdegen <michael_heerdegen@web.de>
> Cc: bjvilfan@gmail.com,  19480@debbugs.gnu.org
> Date: Thu, 01 Jan 2015 21:37:52 +0100
> 
> Hi Eli,
> 
> > This should fix the problem:
> >
> >   (progn
> >     (define-key global-map [tool-bar bvdotex] 'tex-file)
> >     (tool-bar-local-item  "save" 'tex-file 'bvdotex tool-bar-map
> > 			  :help "Process file with default tex command")
> >     (force-mode-line-update)
> >     (garbage-collect))
> 
> I can confirm that this avoids the problem under Debian Gnu/Linux using
> the GTK+ toolkit.

Thanks for checking.





^ permalink raw reply	[flat|nested] 9+ messages in thread

* bug#19480: Tool-bar modifications not reflected on display
  2015-01-01 15:35       ` bug#19480: (no subject) Eli Zaretskii
  2015-01-01 20:37         ` Michael Heerdegen
@ 2022-05-03 16:58         ` Lars Ingebrigtsen
  1 sibling, 0 replies; 9+ messages in thread
From: Lars Ingebrigtsen @ 2022-05-03 16:58 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: Michael Heerdegen, bjvilfan, 19480, monnier

This was fixed for Emacs 29 in the bug#43397 bug report, so I'm also
closing this one.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no






^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2022-05-03 16:58 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-12-25 14:48 how to redraw the tool bar Bostjan Vilfan
2014-12-26 19:37 ` Michael Heerdegen
2014-12-27  1:50 ` Stefan Monnier
2014-12-27 22:08   ` Bostjan Vilfan
2014-12-31 22:13     ` Michael Heerdegen
2015-01-01 15:35       ` bug#19480: (no subject) Eli Zaretskii
2015-01-01 20:37         ` Michael Heerdegen
2015-01-01 20:56           ` Eli Zaretskii
2022-05-03 16:58         ` bug#19480: Tool-bar modifications not reflected on display Lars Ingebrigtsen

Code repositories for project(s) associated with this external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.