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

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

Re: HOWTO add new menu item to the beggining of the menu


From: TomSW
Subject: Re: HOWTO add new menu item to the beggining of the menu
Date: Wed, 24 Jun 2009 06:08:22 -0700 (PDT)
User-agent: G2/1.0

On Jun 23, 4:46 pm, Michal <rabbi...@tenbit.pl> wrote:
> Hallo Group Readers!
>
> I have NO problem adding new item to the end of the menu. For example:
>
> (define-key c-mode-map [tool-bar csearch-forw]
>               `(menu-item "csearch forward" csearch-forward
>                           :image (image :type xpm :file 
> "/tmp/right-arrow.xpm")))
>
> But how to add it to be the first element in a menu?

You're actually adding a toolbar icon, not a menu item: your code
doesn't affect the "C" menu, only the tool bar.
easy-menu-add-item lets you add an item before another one, but I
don't know a predefined way to find the first item in a menu. How
about:

(eval-after-load "cc-mode"
  `(let* ((command-name "csearch forward")
          (command      'csearch-forward)
          (icon         "right-arrow")
          (c-menu-map   (lookup-key c-mode-map [menu-bar C]))
          (first-item   (catch :first
                          (map-keymap (lambda (key def) (throw :first
key))
                                      c-menu-map))))
     ;; add the menu item at the top
     (easy-menu-add-item c-menu-map nil
                         `[,command-name ,command t]
                         first-item)
     ;; add it to the tool bar
     (tool-bar-add-item-from-menu command icon c-mode-map)))

regards,
Tom SW


reply via email to

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