* emacs 23, adding 2 buttons/icons to beginning of toolbar. howto?
@ 2009-06-24 13:53 Michal
2009-06-24 19:02 ` TomSW
0 siblings, 1 reply; 5+ messages in thread
From: Michal @ 2009-06-24 13:53 UTC (permalink / raw)
To: help-gnu-emacs
I wanted to add 2 buttons to toolbar. These buttons were expected
to go through (back and forward) a list of c-mode and c++-mode buffers.
So I added them to the end of toolbar related to c-mode and c++-mode.
Something like:
(setq emacs-images "/tmp")
(add-hook 'c-mode-hook
(lambda ()
(define-key c-mode-map [tool-bar csearch-forw]
`(menu-item "csearch forward" csearch-forward
:image (image :type xpm :file ,(concat emacs-images "/right-arrow.xpm"))))
(define-key c-mode-map [tool-bar csearch-back]
`(menu-item "csearch backward" csearch-backward
:image (image :type xpm :file ,(concat emacs-images "/left-arrow.xpm"))))))
(the same for c++-mode-hook).
It shortly turned out that when I run gdb, the length of toolbar changes
in c/c++ files "visited" by gdb.
When I am pressing my backward button on an on through let's say
non-gdb c/c++ files, I do not have to move mouse pointer because
position of my backward button does not change, but when next buffer
that is visited is gdb c/c++ one, then toolbar icons list is shorter
thus my backward button also gets moved and I have to move my mouse
pointer.
I see solving this by adding my 2 icons/buttons to the beginning of the
toolbar list, but how to do this, and how to do this only for c/c++
buffers also those visited by gdb?
best regards,
Michal
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: emacs 23, adding 2 buttons/icons to beginning of toolbar. howto?
2009-06-24 13:53 emacs 23, adding 2 buttons/icons to beginning of toolbar. howto? Michal
@ 2009-06-24 19:02 ` TomSW
2009-06-25 10:09 ` Michal
0 siblings, 1 reply; 5+ messages in thread
From: TomSW @ 2009-06-24 19:02 UTC (permalink / raw)
To: help-gnu-emacs
On Jun 24, 3:53 pm, Michal <rabbi...@tenbit.pl> wrote:
> It shortly turned out that when I run gdb, the length of toolbar changes
> in c/c++ files "visited" by gdb.
> When I am pressing my backward button on an on through let's say
> non-gdb c/c++ files, I do not have to move mouse pointer because
> position of my backward button does not change, but when next buffer
> that is visited is gdb c/c++ one, then toolbar icons list is shorter
> thus my backward button also gets moved and I have to move my mouse
> pointer.
Are your arrows in the toolbar at all, for gdb buffers? When I tried
the toolbar completely changes...
> I see solving this by adding my 2 icons/buttons to the beginning of the
> toolbar list, but how to do this, and how to do this only for c/c++
> buffers also those visited by gdb?
Tool bar items can be controlled by the variable tool-bar-map. By
making it local to a buffer you can have different toolbars in
different buffers, which is why it changes with gdb. The c modes use
the global value - if you want to change it just for those modes, you
have to make it buffer local in those modes...
How about:
;; Create a specific tool bar map for C modes
(defvar c-tool-bar-map (copy-keymap tool-bar-map))
;; Create a map just to contain the extra items
(let ((temp-map (make-sparse-keymap)))
;; add the items
(dolist (spec '(("right-arrow" csearch-forward)
("left-arrow" csearch-backward)))
(tool-bar-local-item (car spec)
(cadr spec)
(cadr spec)
temp-map))
;; now use easy-menu-add-item to tweak c-tool-bar-map
;; and gud-tool-bar-map
(dolist (map (list c-tool-bar-map gud-tool-bar-map))
(let ((first-item
(catch :first
(map-keymap (lambda (key def) (throw :first key))
map))))
;;
(map-keymap (lambda (key defn)
(easy-menu-add-item map nil (cons key defn) first-
item))
temp-map))))
;; tool-bar-map needs to be al ocal variable for c modes
(dolist (hook '(c-mode-hook c++-mode-hook))
(add-hook hook (lambda ()
(unless (local-variable-p 'tool-bar-map)
(set (make-local-variable 'tool-bar-map)
c-tool-bar-map)))
'append))
regards,
Tom SW
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: emacs 23, adding 2 buttons/icons to beginning of toolbar. howto?
2009-06-24 19:02 ` TomSW
@ 2009-06-25 10:09 ` Michal
2009-06-25 13:48 ` TomSW
0 siblings, 1 reply; 5+ messages in thread
From: Michal @ 2009-06-25 10:09 UTC (permalink / raw)
To: help-gnu-emacs
TomSW <tom.weissmann@gmail.com> writes:
>
> Are your arrows in the toolbar at all, for gdb buffers? When I tried
> the toolbar completely changes...
>
for GDB buffer they do not appear. I mean something else.
Just put the breakpoint in let's say main.cpp and run Your application.
When it stops in main.cpp switch Your cursor to main.cpp. You will see
that "arrow" button appeared there. But ALSO the remaining part of
buttons is the same as for *gud-main* buffer. Number of these buttons is
different from those present in main.cpp just after opening main.cpp.
So my arrow buttons are moved. Their position is different depending on
I am in some *.cpp buffer that has just been "hit" by gdb or it
wasn't.
>
> Tool bar items can be controlled by the variable tool-bar-map. By
> making it local to a buffer you can have different toolbars in
> different buffers, which is why it changes with gdb. The c modes use
> the global value - if you want to change it just for those modes, you
> have to make it buffer local in those modes...
>
> How about:
>
> ;; Create a specific tool bar map for C modes
> (defvar c-tool-bar-map (copy-keymap tool-bar-map))
>
>
> ;; Create a map just to contain the extra items
> (let ((temp-map (make-sparse-keymap)))
> ;; add the items
> (dolist (spec '(("right-arrow" csearch-forward)
> ("left-arrow" csearch-backward)))
> (tool-bar-local-item (car spec)
> (cadr spec)
> (cadr spec)
> temp-map))
> ;; now use easy-menu-add-item to tweak c-tool-bar-map
> ;; and gud-tool-bar-map
> (dolist (map (list c-tool-bar-map gud-tool-bar-map))
> (let ((first-item
> (catch :first
> (map-keymap (lambda (key def) (throw :first key))
> map))))
> ;;
> (map-keymap (lambda (key defn)
> (easy-menu-add-item map nil (cons key defn) first-
> item))
> temp-map))))
>
>
> ;; tool-bar-map needs to be al ocal variable for c modes
> (dolist (hook '(c-mode-hook c++-mode-hook))
> (add-hook hook (lambda ()
> (unless (local-variable-p 'tool-bar-map)
> (set (make-local-variable 'tool-bar-map)
> c-tool-bar-map)))
> 'append))
>
> regards,
> Tom SW
Thank You for Your code!
best regards,
Michal
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: emacs 23, adding 2 buttons/icons to beginning of toolbar. howto?
2009-06-25 10:09 ` Michal
@ 2009-06-25 13:48 ` TomSW
2009-06-25 16:16 ` Michal
0 siblings, 1 reply; 5+ messages in thread
From: TomSW @ 2009-06-25 13:48 UTC (permalink / raw)
To: help-gnu-emacs
On Jun 25, 12:09 pm, Michal <rabbi...@tenbit.pl> wrote:
> TomSW <tom.weissm...@gmail.com> writes:
>
> > Are your arrows in the toolbar at all, for gdb buffers? When I tried
> > the toolbar completely changes...
>
> for GDB buffer they do not appear. I mean something else.
> Just put the breakpoint in let's say main.cpp and run Your application.
> When it stops in main.cpp switch Your cursor to main.cpp. You will see
> that "arrow" button appeared there. But ALSO the remaining part of
> buttons is the same as for *gud-main* buffer. Number of these buttons is
> different from those present in main.cpp just after opening main.cpp.
> So my arrow buttons are moved. Their position is different depending on
> I am in some *.cpp buffer that has just been "hit" by gdb or it
> wasn't.
It works like this: the tool bar items are fetched from the active
keymaps, starting with global-map, then the current major mode's map.
The global map's tool bar items are generated from the value of tool-
bar-items. Consequently it's not possible to add items to the
beginning of the tool bar by specifying tool bar items in the major
mode map, you need to change the value of tool-bar-items (as stated in
the info documents), which is what info mode and gud do.
regards,
Tom SW
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: emacs 23, adding 2 buttons/icons to beginning of toolbar. howto?
2009-06-25 13:48 ` TomSW
@ 2009-06-25 16:16 ` Michal
0 siblings, 0 replies; 5+ messages in thread
From: Michal @ 2009-06-25 16:16 UTC (permalink / raw)
To: help-gnu-emacs
TomSW <tom.weissmann@gmail.com> writes:
> It works like this: the tool bar items are fetched from the active
> keymaps, starting with global-map, then the current major mode's map.
> The global map's tool bar items are generated from the value of tool-
> bar-items. Consequently it's not possible to add items to the
> beginning of the tool bar by specifying tool bar items in the major
> mode map, you need to change the value of tool-bar-items (as stated in
> the info documents), which is what info mode and gud do.
>
This explains all my questions about "why my arrow buttons appear here
and not there".
I will look into gud.el.gz to see how is it done.
Thank You very much
best regards,
Michal
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2009-06-25 16:16 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-06-24 13:53 emacs 23, adding 2 buttons/icons to beginning of toolbar. howto? Michal
2009-06-24 19:02 ` TomSW
2009-06-25 10:09 ` Michal
2009-06-25 13:48 ` TomSW
2009-06-25 16:16 ` Michal
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).