help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: emacs 23, adding 2 buttons/icons to beginning of toolbar. howto?


From: TomSW
Subject: Re: emacs 23, adding 2 buttons/icons to beginning of toolbar. howto?
Date: Wed, 24 Jun 2009 12:02:56 -0700 (PDT)
User-agent: G2/1.0

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


reply via email to

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