[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: popup menu code
From: |
Bruce Ingalls |
Subject: |
Re: popup menu code |
Date: |
Fri, 24 Oct 2003 17:10:49 GMT |
User-agent: |
Mozilla/5.0 (X11; U; Linux i586; en-US; rv:1.5) Gecko/20031017 |
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)