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

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

Re: Example using x-popup-menu needed


From: Kevin Rodgers
Subject: Re: Example using x-popup-menu needed
Date: Fri, 17 Oct 2003 14:07:48 -0600
User-agent: Mozilla/5.0 (X11; U; SunOS i86pc; en-US; rv:0.9.4.1) Gecko/20020406 Netscape6/6.2.2

Bruce Ingalls wrote:

Here's an excerpt from <url: http://emacro.sf.net/ > which makes it *easy* to create popups, and there's a port to XEmacs there, too.
Unfortunately, it is not the *correct* way, which is to use keymaps.

What is delaying me from doing this the correct way, is that I haven't seen any simple keymaps, and I'm not sure, how to deal with commands such as "Goto Line" below, which is not bound to a key (but I am about to bind to M-g, anyway)

As the Defining Menus section of the Emacs Lisp manual says, you should
not provide the equivalent keyboard key sequence in the menu, because
Emacs calculates them automatically.

Here's the right way to do it:

(defvar right-popup-menu
  (let ((menu (make-sparse-keymap "Commands")))
    (define-key menu [dabbrev-expand] (cons "Complete word" 'dabbrev-expand))
    (define-key menu [undo] (cons "Undo" 'undo))
    (define-key menu [grep] (cons "Search files" 'grep))
    (define-key menu [redo] (cons "Redo" 'redo))
    (define-key menu [yank] (cons "Paste" 'yank))
    (define-key menu [goto-line] (cons "Goto line" 'goto-line))
    (define-key menu [copy-region-as-kill] (cons "Copy" 'copy-region-as-kill))
    menu))

(defun right-popup-command ()           ; event
  "Run the command selected from `right-popup-menu'."
(interactive) ; "e"
  (call-interactively (or (car (x-popup-menu t right-popup-menu))

(global-set-key [mouse-3] 'right-popup-command)

--
Kevin Rodgers



reply via email to

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