diff options
| author | Richard M. Stallman | 1998-05-23 04:26:39 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 1998-05-23 04:26:39 +0000 |
| commit | 545128a805d40f8ecb8d91bd651ae1d2c1bb9d21 (patch) | |
| tree | 24654cdf345fb9682b61ffee868806fff4082bf9 | |
| parent | 5fecb21aeb611cd5e77c229b7fcf2da5d3387142 (diff) | |
| download | emacs-545128a805d40f8ecb8d91bd651ae1d2c1bb9d21.tar.gz emacs-545128a805d40f8ecb8d91bd651ae1d2c1bb9d21.zip | |
(easy-menu-do-add-item): Small simplifications.
(easy-menu-precalculate-equivalent-keybindings): New customization variable.
(easy-menu-add): Precalculate key bindings if
`easy-menu-precalculate-equivalent-keybindings' is on.
| -rw-r--r-- | lisp/emacs-lisp/easymenu.el | 41 |
1 files changed, 30 insertions, 11 deletions
diff --git a/lisp/emacs-lisp/easymenu.el b/lisp/emacs-lisp/easymenu.el index 4d553f10965..9f175340b9e 100644 --- a/lisp/emacs-lisp/easymenu.el +++ b/lisp/emacs-lisp/easymenu.el | |||
| @@ -30,6 +30,17 @@ | |||
| 30 | 30 | ||
| 31 | ;;; Code: | 31 | ;;; Code: |
| 32 | 32 | ||
| 33 | (defcustom easy-menu-precalculate-equivalent-keybindings t | ||
| 34 | "Determine when equivalent key bindings are computed for easy-menu menus. | ||
| 35 | It can take some time to calculate the equivalent key bindings that are shown | ||
| 36 | in a menu. If the variable is on, then this calculation gives a (maybe | ||
| 37 | noticeable) delay when a mode is first entered. If the variable is off, then | ||
| 38 | this delay will come when a menu is displayed the first time. If you never use | ||
| 39 | menus, turn this variable off, otherwise it is probably better to keep it on." | ||
| 40 | :type 'boolean | ||
| 41 | :group 'menu | ||
| 42 | :version "20.3") | ||
| 43 | |||
| 33 | ;;;###autoload | 44 | ;;;###autoload |
| 34 | (defmacro easy-menu-define (symbol maps doc menu) | 45 | (defmacro easy-menu-define (symbol maps doc menu) |
| 35 | "Define a menu bar submenu in maps MAPS, according to MENU. | 46 | "Define a menu bar submenu in maps MAPS, according to MENU. |
| @@ -198,17 +209,17 @@ shadow\\(Double\\)?Etched\\(In\\|Out\\)\\(Dash\\)?\\)\\)$" | |||
| 198 | (setq prop (cddr prop))) | 209 | (setq prop (cddr prop))) |
| 199 | (setq command (symbol-function command))))) | 210 | (setq command (symbol-function command))))) |
| 200 | ((vectorp item) | 211 | ((vectorp item) |
| 201 | (let ((active (if (> (length item) 2) (or (aref item 2) ''nil) t)) | 212 | (let* ((ilen (length item)) |
| 202 | (no-name (not (symbolp (setq command (aref item 1))))) | 213 | (active (if (> ilen 2) (or (aref item 2) ''nil) t)) |
| 203 | cache cache-specified | 214 | (no-name (not (symbolp (setq command (aref item 1))))) |
| 204 | (count 2)) | 215 | cache cache-specified) |
| 205 | (setq label (setq name (aref item 0))) | 216 | (setq label (setq name (aref item 0))) |
| 206 | (if no-name (setq command (easy-menu-make-symbol command))) | 217 | (if no-name (setq command (easy-menu-make-symbol command))) |
| 207 | (if (and (symbolp active) (= ?: (aref (symbol-name active) 0))) | 218 | (if (and (symbolp active) (= ?: (aref (symbol-name active) 0))) |
| 208 | (let ((count 2) | 219 | (let ((count 2) |
| 209 | keyword arg suffix visible style selected keys) | 220 | keyword arg suffix visible style selected keys) |
| 210 | (setq active nil) | 221 | (setq active nil) |
| 211 | (while (> (length item) count) | 222 | (while (> ilen count) |
| 212 | (setq keyword (aref item count)) | 223 | (setq keyword (aref item count)) |
| 213 | (setq arg (aref item (1+ count))) | 224 | (setq arg (aref item (1+ count))) |
| 214 | (setq count (+ 2 count)) | 225 | (setq count (+ 2 count)) |
| @@ -241,11 +252,11 @@ shadow\\(Double\\)?Etched\\(In\\|Out\\)\\(Dash\\)?\\)\\)$" | |||
| 241 | (substring keys (match-end 1)))) | 252 | (substring keys (match-end 1)))) |
| 242 | (cmd (intern (substring keys (match-beginning 2) | 253 | (cmd (intern (substring keys (match-beginning 2) |
| 243 | (match-end 2))))) | 254 | (match-end 2))))) |
| 255 | (setq keys (and (or prefix postfix) | ||
| 256 | (cons prefix postfix))) | ||
| 244 | (setq keys | 257 | (setq keys |
| 245 | (and (or prefix postfix (not (eq command cmd))) | 258 | (and (or keys (not (eq command cmd))) |
| 246 | (cons cmd | 259 | (cons cmd keys)))) |
| 247 | (and (or prefix postfix) | ||
| 248 | (cons prefix postfix)))))) | ||
| 249 | (setq cache-specified nil)) | 260 | (setq cache-specified nil)) |
| 250 | (if keys (setq prop (cons :keys (cons keys prop))))) | 261 | (if keys (setq prop (cons :keys (cons keys prop))))) |
| 251 | (if (and visible (not (easy-menu-always-true visible))) | 262 | (if (and visible (not (easy-menu-always-true visible))) |
| @@ -333,10 +344,18 @@ to implement dynamic menus." | |||
| 333 | 344 | ||
| 334 | ;; XEmacs needs the following two functions to add and remove menus. | 345 | ;; XEmacs needs the following two functions to add and remove menus. |
| 335 | ;; In Emacs this is done automatically when switching keymaps, so | 346 | ;; In Emacs this is done automatically when switching keymaps, so |
| 336 | ;; here these functions are noops. | 347 | ;; here easy-menu-remove is a noop and easy-menu-add only precalculates |
| 348 | ;; equivalent keybindings (if easy-menu-precalculate-equivalent-keybindings | ||
| 349 | ;; is on). | ||
| 337 | (defun easy-menu-remove (menu)) | 350 | (defun easy-menu-remove (menu)) |
| 338 | 351 | ||
| 339 | (defun easy-menu-add (menu &optional map)) | 352 | (defun easy-menu-add (menu &optional map) |
| 353 | "Maybe precalculate equivalent key bindings. | ||
| 354 | Do it if `easy-menu-precalculate-equivalent-keybindings' is on," | ||
| 355 | (when easy-menu-precalculate-equivalent-keybindings | ||
| 356 | (if (and (symbolp menu) (not (keymapp menu)) (boundp menu)) | ||
| 357 | (setq menu (symbol-value menu))) | ||
| 358 | (if (keymapp menu) (x-popup-menu nil menu)))) | ||
| 340 | 359 | ||
| 341 | (defun easy-menu-add-item (menu path item &optional before) | 360 | (defun easy-menu-add-item (menu path item &optional before) |
| 342 | "At the end of the submenu of MENU with path PATH add ITEM. | 361 | "At the end of the submenu of MENU with path PATH add ITEM. |