[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Example using x-popup-menu needed
From: |
Bruce Ingalls |
Subject: |
Re: Example using x-popup-menu needed |
Date: |
Fri, 17 Oct 2003 16:11:16 GMT |
User-agent: |
Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.5b) Gecko/20030723 Thunderbird/0.1 |
Dave Neubart wrote:
Can someone give a very short, simple example of using this function?
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)
The example below is easy to edit, and gives Emacs a KDE/Gnome look & feel.
;;__________________________________________________________________________
;;;;;; choose-from-menu
;;From Sandip Chitale <sandipchitale(at)attbi(dot)com>
(defun choose-from-menu (menu-title menu-items)
"Choose from a list of choices from a popup menu.
See `popup-commands' which calls this"
(let ((item)
(item-list))
(while menu-items
(setq item (car menu-items))
(if (consp item)
(setq item-list (cons (cons (car item) (cdr item) ) item-list))
(setq item-list (cons (cons item item) item-list)))
(setq menu-items (cdr menu-items))
)
(x-popup-menu t (list menu-title (cons menu-title (nreverse
item-list))))))
;;__________________________________________________________________________
(defun right-popup ()
"Show a popup menu of commands. See also `choose-from-menu'."
(interactive)
(eval-expression
(car
(read-from-string
(choose-from-menu
"Commands"
(list
(cons "Copy C-insert" "(call-interactively
'copy-region-as-kill)")
(cons "Goto Line" "(call-interactively 'goto-line)")
(cons "Paste/yank S-insert" "(yank)")
(cons "Redo" "(redo)")
(cons "Search files" "(call-interactively 'grep)")
(cons "Undo C-_" "(undo)")
(cons "Word completion M-/" "(call-interactively 'dabbrev-expand)")
))))))
(global-set-key [mouse-3] 'right-popup)