Mercurial > emacs
comparison lisp/emacs-lisp/lmenu.el @ 18410:e414b2e486a3
(popup-menu): Redefine as macro.
(popup-menu-popup, popup-menu-internal): New function.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Mon, 23 Jun 1997 02:56:03 +0000 |
parents | 760c7139c19c |
children | 8941ce81cd7c |
comparison
equal
deleted
inserted
replaced
18409:009cc28fa3ec | 18410:e414b2e486a3 |
---|---|
1 ;;; lmenu.el --- emulate Lucid's menubar support | 1 ;;; lmenu.el --- emulate Lucid's menubar support |
2 | 2 |
3 ;; Copyright (C) 1992, 1993, 1994 Free Software Foundation, Inc. | 3 ;; Copyright (C) 1992, 1993, 1994, 1997 Free Software Foundation, Inc. |
4 | 4 |
5 ;; Keywords: emulations | 5 ;; Keywords: emulations |
6 | 6 |
7 ;; This file is part of GNU Emacs. | 7 ;; This file is part of GNU Emacs. |
8 | 8 |
122 (if name | 122 (if name |
123 (define-key menu (vector (intern name)) (cons name command))))) | 123 (define-key menu (vector (intern name)) (cons name command))))) |
124 (setq menu-items (cdr menu-items))) | 124 (setq menu-items (cdr menu-items))) |
125 menu)) | 125 menu)) |
126 | 126 |
127 (defun popup-menu (menu-desc) | 127 ;; The value of the cache-symbol for a menu |
128 ;; is | |
129 ;; unbound -- nothing computed | |
130 ;; (ORIG . TRANSL) | |
131 ;; ORIG is the original menu spec list | |
132 ;; and TRANSL is its translation. | |
133 | |
134 (defmacro popup-menu (arg) | |
128 "Pop up the given menu. | 135 "Pop up the given menu. |
129 A menu is a list of menu items, strings, and submenus. | 136 A menu is a list of menu items, strings, and submenus. |
130 | 137 |
131 The first element of a menu must be a string, which is the name of the | 138 The first element of a menu must be a string, which is the name of the |
132 menu. This is the string that will be displayed in the parent menu, if | 139 menu. This is the string that will be displayed in the parent menu, if |
187 | ':style' object-style | 194 | ':style' object-style |
188 | ':selected' form | 195 | ':selected' form |
189 menu-item := '[' name callback active-p [ suffix ] ']' | 196 menu-item := '[' name callback active-p [ suffix ] ']' |
190 | '[' name callback [ keyword ]+ ']' | 197 | '[' name callback [ keyword ]+ ']' |
191 menu := '(' name [ menu-item | menu | text ]+ ')'" | 198 menu := '(' name [ menu-item | menu | text ]+ ')'" |
192 (let ((menu (make-lucid-menu-keymap (car menu-desc) (cdr menu-desc))) | 199 (if (not (symbolp arg)) |
193 (pos (mouse-pixel-position)) | 200 `(popup-menu-internal ,arg nil) |
201 `(popup-menu-internal ,arg | |
202 ',(intern (concat "popup-menu-" (symbol-name arg)))))) | |
203 | |
204 (defun popup-menu-internal (menu cache-symbol) | |
205 (if (null cache-symbol) | |
206 ;; If no cache symbol, translate the menu afresh each time. | |
207 (popup-menu-popup (make-lucid-menu-keymap (car menu) (cdr menu))) | |
208 ;; We have a cache symbol. See if the cache is valid | |
209 ;; for the same menu we have now. | |
210 (or (and (boundp cache-symbol) | |
211 (consp (symbol-value cache-symbol)) | |
212 (equal (car (symbol-value cache-symbol)) | |
213 menu)) | |
214 ;; If not, update it. | |
215 (set cache-symbol | |
216 (cons menu (make-lucid-menu-keymap (car menu) (cdr menu))))) | |
217 ;; Use the menu in the cache. | |
218 (popup-menu-popup (cdr (symbol-value cache-symbol))))) | |
219 | |
220 ;; Pop up MENU-KEYMAP which was made by make-lucid-menu-keymap. | |
221 (defun popup-menu-popup (menu-keymap) | |
222 (let ((pos (mouse-pixel-position)) | |
194 answer cmd) | 223 answer cmd) |
195 (while (and menu | 224 (while (and menu-keymap |
196 (setq answer (x-popup-menu (list (list (nth 1 pos) | 225 (setq answer (x-popup-menu (list (list (nth 1 pos) |
197 (nthcdr 2 pos)) | 226 (nthcdr 2 pos)) |
198 (car pos)) | 227 (car pos)) |
199 menu))) | 228 menu-keymap))) |
200 (setq cmd (lookup-key menu (apply 'vector answer))) | 229 (setq cmd (lookup-key menu-keymap (apply 'vector answer))) |
201 (setq menu nil) | 230 (setq menu nil) |
202 (and cmd | 231 (and cmd |
203 (if (keymapp cmd) | 232 (if (keymapp cmd) |
204 (setq menu cmd) | 233 (setq menu-keymap cmd) |
205 (call-interactively cmd)))))) | 234 (call-interactively cmd)))))) |
206 | 235 |
207 (defun popup-dialog-box (data) | 236 (defun popup-dialog-box (data) |
208 "Pop up a dialog box. | 237 "Pop up a dialog box. |
209 A dialog box description is a list. | 238 A dialog box description is a list. |