all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* popup menu code
@ 2003-10-23 20:27 Bruce Ingalls
  2003-10-23 22:01 ` Stefan Monnier
  2003-10-23 22:14 ` Stefan Monnier
  0 siblings, 2 replies; 5+ messages in thread
From: Bruce Ingalls @ 2003-10-23 20:27 UTC (permalink / raw)


;;Thanks to your help, I made the following improvements to my popup menu.
;;However, because I must put when(mark-active) clauses in my code, this
;;prevents the keybindings from showing up.
;;Any way around this?
;;There are multiple keybindings to Copy. I'd rather not see [f17] (from 
memory)
;;Are hints available to show C-Ins, M-w or C-c, if cua.el is loaded?
;;Also note that this code does not work under XEmacs.
;;Finally, I suspect that my code for menu separators is not the best

(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 [redo] (cons "Redo" 'redo))

     (define-key menu [--] (cons "--" 'nil)) ;separator

;;Unfortunately, keybinding is not to when() clause, which must necessarily
;;surround the function
     (define-key menu [kill-region]
       (cons "Cut"
	    '(when (and mark-active (not buffer-read-only)
		       (call-interactively 'kill-region)))))
     (define-key menu [yank]
       (cons "Paste"
	    '(when (and mark-active (not buffer-read-only) 'yank))))
     (define-key menu [copy-region-as-kill]
       (cons "Copy" '(when mark-active 'copy-region-as-kill)))

;;    (define-key menu [-] (cons "-" 'nil)) ;separator
;;    (define-key menu [emacro-help]
;;      (cons (concat "EMacro v" emacro-version) 'emacro-help))
     menu))

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

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

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

* Re: popup menu code
  2003-10-23 20:27 popup menu code Bruce Ingalls
@ 2003-10-23 22:01 ` Stefan Monnier
  2003-10-24 17:10   ` Bruce Ingalls
  2003-10-23 22:14 ` Stefan Monnier
  1 sibling, 1 reply; 5+ messages in thread
From: Stefan Monnier @ 2003-10-23 22:01 UTC (permalink / raw)


>      (define-key menu [kill-region]
>        (cons "Cut"
> 	    '(when (and mark-active (not buffer-read-only)
> 		       (call-interactively 'kill-region)))))

Does this work?  I know it does in easy-menus, but I don't think it does
in your case.  But even if it does, it's a bad idea.
Better use an `activate' property.  Check out the elisp documentation.
More specifically, look for `menu-item' in the index.

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

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

IIRC, you can get rid of right-popup and just do

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


-- Stefan

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

* Re: popup menu code
  2003-10-23 20:27 popup menu code Bruce Ingalls
  2003-10-23 22:01 ` Stefan Monnier
@ 2003-10-23 22:14 ` Stefan Monnier
  1 sibling, 0 replies; 5+ messages in thread
From: Stefan Monnier @ 2003-10-23 22:14 UTC (permalink / raw)


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

If your right-popup-menu has submenus and your Emacs was compiled with
some particular flags (I think it happens if you compiled under X without
toolkit support), the above may fail when you select the sub-menu.

Better use `popup-menu' which takes care of those idiosyncrasies.


        Stefan

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

* Re: popup menu code
  2003-10-23 22:01 ` Stefan Monnier
@ 2003-10-24 17:10   ` Bruce Ingalls
  2003-10-24 17:32     ` Stefan Monnier
  0 siblings, 1 reply; 5+ messages in thread
From: Bruce Ingalls @ 2003-10-24 17:10 UTC (permalink / raw)


Stefan Monnier wrote:
> Does this work?  I know it does in easy-menus,...
I could not figure out, how to get easy-menu working for popups.
Having XEmacs portable code would be nice.

> Better use an `activate' property.  Check out the elisp documentation.
> More specifically, look for `menu-item' in the index.
I could not find activate nor menu-item from C-h a apropos.
I was a little overwhelmed, looking at advise's ad-activate

> IIRC, you can get rid of right-popup and just do
>   (global-set-key [mouse-3] right-popup-menu)
did not work for me.

However, thanks to your advice, I am happy with this reworked, working code
at bottom.
The only annoyance, is that I am picking up f16 & f20 as the (sun keyboard)
keybindings for cut and copy, likely from cua.el

;;__________________________________________________________________________
;;;;;;		Customize A Popup Menu

(defun menu-copy() "Wrapper to call `copy-region-as-kill' from menu."
   (interactive)
   (when mark-active 'copy-region-as-kill))
(defun menu-cut() "Wrapper to `call kill-region' from menu."
   (interactive)
   (when (and mark-active (not buffer-read-only)
	     (call-interactively 'kill-region))))
(defun menu-paste() "Wrapper to call `yank' from menu."
   (interactive)
   (when (not buffer-read-only) (call-interactively 'yank)))

(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 [redo] (cons "Redo" 'redo))

     (define-key menu [--] (cons "--" 'nil)) ;separator

     (define-key menu [menu-paste] (cons "Paste" 'yank))
     (define-key menu [menu-copy] (cons "Copy" 'copy-region-as-kill))
     (define-key menu [menu-cut] (cons "Cut" 'kill-region))

     (define-key menu [-] (cons "-" 'nil)) ;separator
     (define-key menu [emacro-help]
       (cons (concat "EMacro v" emacro-version) 'emacro-help))
     menu))

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

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

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

* Re: popup menu code
  2003-10-24 17:10   ` Bruce Ingalls
@ 2003-10-24 17:32     ` Stefan Monnier
  0 siblings, 0 replies; 5+ messages in thread
From: Stefan Monnier @ 2003-10-24 17:32 UTC (permalink / raw)


>> Better use an `activate' property.  Check out the elisp documentation.
>> More specifically, look for `menu-item' in the index.
> I could not find activate nor menu-item from C-h a apropos.
> I was a little overwhelmed, looking at advise's ad-activate

s/documentation/manual/

Really, you can't do any serious Elisp hacking without the online Emacs Lisp
Reference manual (which is bundled in the CVS repository).


        Stefan

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

end of thread, other threads:[~2003-10-24 17:32 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2003-10-23 20:27 popup menu code Bruce Ingalls
2003-10-23 22:01 ` Stefan Monnier
2003-10-24 17:10   ` Bruce Ingalls
2003-10-24 17:32     ` Stefan Monnier
2003-10-23 22:14 ` Stefan Monnier

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.