unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* Example using x-popup-menu needed
@ 2003-10-17  5:38 Dave Neubart
  2003-10-17 13:41 ` Barman Brakjoller
  2003-10-17 16:11 ` Bruce Ingalls
  0 siblings, 2 replies; 14+ messages in thread
From: Dave Neubart @ 2003-10-17  5:38 UTC (permalink / raw)


Hi All:

I need some help with  x-popup-menu.  I've searched through scores of 
.el files and the Emacs manuals looking for really simple examples --- 
but no luck.

Can someone give a very short, simple example of  using this function?

Thanks.

Dave.

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: Example using x-popup-menu needed
  2003-10-17  5:38 Example using x-popup-menu needed Dave Neubart
@ 2003-10-17 13:41 ` Barman Brakjoller
  2003-10-17 16:11 ` Bruce Ingalls
  1 sibling, 0 replies; 14+ messages in thread
From: Barman Brakjoller @ 2003-10-17 13:41 UTC (permalink / raw)


> I need some help with  x-popup-menu.  I've searched through scores of 
> .el files and the Emacs manuals looking for really simple examples --- 
> but no luck.
> 
> Can someone give a very short, simple example of  using this function?

How about this, which is quite hand too:

(defun my-bookmark-menu-jump ()
  (interactive)
  (bookmark-jump (x-popup-menu 
                  (list '(400 200) (selected-window)) 
                  (bookmark-menu-build-paned-menu 
                   "Select bookmark" 
                   (bookmark-all-names)))))

/Mathias

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: Example using x-popup-menu needed
  2003-10-17  5:38 Example using x-popup-menu needed Dave Neubart
  2003-10-17 13:41 ` Barman Brakjoller
@ 2003-10-17 16:11 ` Bruce Ingalls
  2003-10-17 16:32   ` Martin Stemplinger
                     ` (4 more replies)
  1 sibling, 5 replies; 14+ messages in thread
From: Bruce Ingalls @ 2003-10-17 16:11 UTC (permalink / raw)


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)

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: Example using x-popup-menu needed
  2003-10-17 16:11 ` Bruce Ingalls
@ 2003-10-17 16:32   ` Martin Stemplinger
  2003-10-17 18:14     ` Bruce Ingalls
  2003-10-17 16:50   ` Ian Zimmerman
                     ` (3 subsequent siblings)
  4 siblings, 1 reply; 14+ messages in thread
From: Martin Stemplinger @ 2003-10-17 16:32 UTC (permalink / raw)


On Fr Okt 17 2003 at 18:11, Bruce Ingalls
<bingalls@fit-zones.NO-SPAM.com> wrote: 

>    (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)
>

Really cool! But the function redo doesn't exist on my emacs
(GNU Emacs 21.3.50.1 (i386-msvc-nt5.1.2600) of 2003-09-12 on
ALABANDA).

Any idea?
-- 
Remove NOSPAM to reply by mail

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: Example using x-popup-menu needed
  2003-10-17 16:11 ` Bruce Ingalls
  2003-10-17 16:32   ` Martin Stemplinger
@ 2003-10-17 16:50   ` Ian Zimmerman
  2003-10-17 18:11     ` Bruce Ingalls
  2003-10-17 20:07   ` Kevin Rodgers
                     ` (2 subsequent siblings)
  4 siblings, 1 reply; 14+ messages in thread
From: Ian Zimmerman @ 2003-10-17 16:50 UTC (permalink / raw)



Bruce> key (but I am about to bind to M-g, anyway)

If this is code for public consumption, please don't.

Try C-x b *Group* C-h k M-g

-- 
Wer Schoenheit angeschaut mit Augen, hat dem Tode schon Anheim gegeben.
Von Platen.

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: Example using x-popup-menu needed
  2003-10-17 16:50   ` Ian Zimmerman
@ 2003-10-17 18:11     ` Bruce Ingalls
  2003-10-17 20:07       ` Stefan Monnier
  0 siblings, 1 reply; 14+ messages in thread
From: Bruce Ingalls @ 2003-10-17 18:11 UTC (permalink / raw)


Ian Zimmerman wrote:
> Bruce> key (but I am about to bind to M-g, anyway)
> 
> If this is code for public consumption, please don't.
> 
> Try C-x b *Group* C-h k M-g

This is for public consumption. I tried C-M-g, but Emacs
seems to think that this is the same as M-g (or C-g, can't
remember which)
S-C-g nor S-M-g don't seem to distinguish, either.

I reckon that leaves "C-c g" as a global binding.

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: Example using x-popup-menu needed
  2003-10-17 16:32   ` Martin Stemplinger
@ 2003-10-17 18:14     ` Bruce Ingalls
  0 siblings, 0 replies; 14+ messages in thread
From: Bruce Ingalls @ 2003-10-17 18:14 UTC (permalink / raw)


Martin Stemplinger wrote:

> Really cool! But the function redo doesn't exist on my emacs
> (GNU Emacs 21.3.50.1 (i386-msvc-nt5.1.2600) of 2003-09-12 on
> ALABANDA).
> 
> Any idea?

If you like that, take a look at
<url: http://emacro.sourceforge.net/ >
I defun redo in e-macs.el (maybe e-functions.el)

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: Example using x-popup-menu needed
  2003-10-17 18:11     ` Bruce Ingalls
@ 2003-10-17 20:07       ` Stefan Monnier
  0 siblings, 0 replies; 14+ messages in thread
From: Stefan Monnier @ 2003-10-17 20:07 UTC (permalink / raw)


> This is for public consumption. I tried C-M-g, but Emacs
> seems to think that this is the same as M-g (or C-g, can't
> remember which)

After the years you've spent in this newsgroup, you should know better:
it's the text terminal you're using that thinks it's a good idea to send
the same byte-sequence to Emacs in the two cases.  Emacs can't do anything
about it.  But if you use a windowing system, the problem should disappear.

> S-C-g nor S-M-g don't seem to distinguish, either.

You mean C-G and M-G ?  Same thing (except that M-G is downgraded to M-g
by Emacs if there's no binding for M-G).

> I reckon that leaves "C-c g" as a global binding.

-- Stefan "who overloads C-s for that"

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: Example using x-popup-menu needed
  2003-10-17 16:11 ` Bruce Ingalls
  2003-10-17 16:32   ` Martin Stemplinger
  2003-10-17 16:50   ` Ian Zimmerman
@ 2003-10-17 20:07   ` Kevin Rodgers
  2003-10-17 21:26     ` Kevin Rodgers
  2003-10-17 20:14   ` Stefan Monnier
  2003-12-02 20:50   ` Kai Grossjohann
  4 siblings, 1 reply; 14+ messages in thread
From: Kevin Rodgers @ 2003-10-17 20:07 UTC (permalink / raw)


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

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: Example using x-popup-menu needed
  2003-10-17 16:11 ` Bruce Ingalls
                     ` (2 preceding siblings ...)
  2003-10-17 20:07   ` Kevin Rodgers
@ 2003-10-17 20:14   ` Stefan Monnier
  2003-10-18 13:45     ` Martin Stemplinger
  2003-12-02 20:50   ` Kai Grossjohann
  4 siblings, 1 reply; 14+ messages in thread
From: Stefan Monnier @ 2003-10-17 20:14 UTC (permalink / raw)


>    (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))
                            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
why do such unnecessary copying ?

>   (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))))))

You mean (x-popup-menu
          t (list menu-title
                  (cons menu-title
                        (mapcar (lambda (item)
                                  (if (consp item) item
                                    (cons item item)))
                                item-list))))

>      (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)")
> 	 ))))))

You mean

  (call-interactively
   (choose-from-menu "Commands"
                     '(("Copy             C-insert" . copy-region-as-kill)
                       ("Goto Line"                 . goto-line)
                       ("Paste/Yank       S-insert" . yank)
                       ("Redo"                      . redo)
                       ("Search Files"              . grep)
                       ("Undo             C-_"      . undo)
                       ("Word Completion  M-/"      . dabbrev-expand))))

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

If you define `right-popup' as a menu keymap, you'll save yourself
the trouble of calling the commands and you'll get the hotkeys for free.


        Stefan

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: Example using x-popup-menu needed
  2003-10-17 20:07   ` Kevin Rodgers
@ 2003-10-17 21:26     ` Kevin Rodgers
  0 siblings, 0 replies; 14+ messages in thread
From: Kevin Rodgers @ 2003-10-17 21:26 UTC (permalink / raw)


Kevin Rodgers wrote:

> (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))

Oops, something got deleted:


   (call-interactively (or (car (x-popup-menu t right-popup-menu)) 'ignore)))

-- 
Kevin Rodgers

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: Example using x-popup-menu needed
  2003-10-17 20:14   ` Stefan Monnier
@ 2003-10-18 13:45     ` Martin Stemplinger
  0 siblings, 0 replies; 14+ messages in thread
From: Martin Stemplinger @ 2003-10-18 13:45 UTC (permalink / raw)


On Fr Okt 17 2003 at 22:14, Stefan Monnier <monnier@iro.umontreal.ca> wrote:

> You mean (x-popup-menu
>           t (list menu-title
>                   (cons menu-title
>                         (mapcar (lambda (item)
>                                   (if (consp item) item
>                                     (cons item item)))
>                                 item-list))))
>
>
> You mean
>
>   (call-interactively
>    (choose-from-menu "Commands"
>                      '(("Copy             C-insert" . copy-region-as-kill)
>                        ("Goto Line"                 . goto-line)
>                        ("Paste/Yank       S-insert" . yank)
>                        ("Redo"                      . redo)
>                        ("Search Files"              . grep)
>                        ("Undo             C-_"      . undo)
>                        ("Word Completion  M-/"      . dabbrev-expand))))
>
>>    (global-set-key [mouse-3] 'right-popup)
>
> If you define `right-popup' as a menu keymap, you'll save yourself
> the trouble of calling the commands and you'll get the hotkeys for free.
>
>
>         Stefan

Would you mind to post a complete example? I tried to insert your code
but obviously made some mistake :-(

Thanks
Martin
-- 
Remove NOSPAM to reply by mail

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: Example using x-popup-menu needed
  2003-10-17 16:11 ` Bruce Ingalls
                     ` (3 preceding siblings ...)
  2003-10-17 20:14   ` Stefan Monnier
@ 2003-12-02 20:50   ` Kai Grossjohann
  2003-12-03 18:29     ` Kevin Rodgers
  4 siblings, 1 reply; 14+ messages in thread
From: Kai Grossjohann @ 2003-12-02 20:50 UTC (permalink / raw)


Bruce Ingalls <bingalls@fit-zones.NO-SPAM.com> writes:

> (but I am about to bind to M-g, anyway)

I think C-x g is a good binding.  insert-register is also bound to C-x
r g and C-x r i, which are more logical bindings, anyway.  Thus, I
think that insert-register-compatibility-binding can be sacrificed :-)

What do people think?

Kai

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: Example using x-popup-menu needed
  2003-12-02 20:50   ` Kai Grossjohann
@ 2003-12-03 18:29     ` Kevin Rodgers
  0 siblings, 0 replies; 14+ messages in thread
From: Kevin Rodgers @ 2003-12-03 18:29 UTC (permalink / raw)


Kai Grossjohann wrote:

> I think C-x g is a good binding.  insert-register is also bound to C-x
> r g and C-x r i, which are more logical bindings, anyway.  Thus, I
> think that insert-register-compatibility-binding can be sacrificed :-)
> 
> What do people think?

Makes sense to me.  I'd also like a binding for goto-char: C-x G (C-x S-g).

-- 
Kevin Rodgers

^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2003-12-03 18:29 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2003-10-17  5:38 Example using x-popup-menu needed Dave Neubart
2003-10-17 13:41 ` Barman Brakjoller
2003-10-17 16:11 ` Bruce Ingalls
2003-10-17 16:32   ` Martin Stemplinger
2003-10-17 18:14     ` Bruce Ingalls
2003-10-17 16:50   ` Ian Zimmerman
2003-10-17 18:11     ` Bruce Ingalls
2003-10-17 20:07       ` Stefan Monnier
2003-10-17 20:07   ` Kevin Rodgers
2003-10-17 21:26     ` Kevin Rodgers
2003-10-17 20:14   ` Stefan Monnier
2003-10-18 13:45     ` Martin Stemplinger
2003-12-02 20:50   ` Kai Grossjohann
2003-12-03 18:29     ` Kevin Rodgers

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).