comparison lisp/emacs-lisp/easymenu.el @ 30194:00cce196e38b

Doc fixes. (easy-menu-remove): Defalias to ignore.
author Dave Love <fx@gnu.org>
date Thu, 13 Jul 2000 19:03:45 +0000
parents 6413c7b9a6c3
children 584fa6f665f1
comparison
equal deleted inserted replaced
30193:f60faad8d9f7 30194:00cce196e38b
120 120
121 toggle: A checkbox. 121 toggle: A checkbox.
122 Prepend the name with `(*) ' or `( ) ' depending on if selected or not. 122 Prepend the name with `(*) ' or `( ) ' depending on if selected or not.
123 radio: A radio button. 123 radio: A radio button.
124 Prepend the name with `[X] ' or `[ ] ' depending on if selected or not. 124 Prepend the name with `[X] ' or `[ ] ' depending on if selected or not.
125 button: Surround the name with `[' and `]'. Use this for an item in the 125 button: Surround the name with `[' and `]'. Use this for an item in the
126 menu bar itself. 126 menu bar itself.
127 anything else means an ordinary menu item. 127 anything else means an ordinary menu item.
128 128
129 :selected SELECTED 129 :selected SELECTED
130 130
208 ((eq keyword :active) (setq enable (or arg ''nil))) 208 ((eq keyword :active) (setq enable (or arg ''nil)))
209 ((eq keyword :label) (setq label arg)) 209 ((eq keyword :label) (setq label arg))
210 ((eq keyword :help) (setq help arg)) 210 ((eq keyword :help) (setq help arg))
211 ((or (eq keyword :included) (eq keyword :visible)) 211 ((or (eq keyword :included) (eq keyword :visible))
212 (setq visible (or arg ''nil))))) 212 (setq visible (or arg ''nil)))))
213 (if (equal visible ''nil) nil ; Invisible menu entry, return nil. 213 (if (equal visible ''nil)
214 nil ; Invisible menu entry, return nil.
214 (if (and visible (not (easy-menu-always-true visible))) 215 (if (and visible (not (easy-menu-always-true visible)))
215 (setq prop (cons :visible (cons visible prop)))) 216 (setq prop (cons :visible (cons visible prop))))
216 (if (and enable (not (easy-menu-always-true enable))) 217 (if (and enable (not (easy-menu-always-true enable)))
217 (setq prop (cons :enable (cons enable prop)))) 218 (setq prop (cons :enable (cons enable prop))))
218 (if filter (setq prop (cons :filter (cons filter prop)))) 219 (if filter (setq prop (cons :filter (cons filter prop))))
240 (easy-menu-define-key-intern menu (car item) (cdr item) before)) 241 (easy-menu-define-key-intern menu (car item) (cdr item) before))
241 242
242 (defvar easy-menu-converted-items-table (make-hash-table :test 'equal)) 243 (defvar easy-menu-converted-items-table (make-hash-table :test 'equal))
243 244
244 (defun easy-menu-convert-item (item) 245 (defun easy-menu-convert-item (item)
245 ;; Memoize easy-menu-convert-item-1. 246 "Memoize the value returned by `easy-menu-convert-item-1' called on ITEM.
246 ;; This makes key-shortcut-caching work a *lot* better when this 247 This makes key-shortcut-caching work a *lot* better when this
247 ;; conversion is done from within a filter. 248 conversion is done from within a filter.
248 ;; This also helps when the NAME of the entry is recreated each time: 249 This also helps when the NAME of the entry is recreated each time:
249 ;; since the menu is built and traversed separately, the lookup 250 since the menu is built and traversed separately, the lookup
250 ;; would always fail because the key is `equal' but not `eq'. 251 would always fail because the key is `equal' but not `eq'."
251 (or (gethash item easy-menu-converted-items-table) 252 (or (gethash item easy-menu-converted-items-table)
252 (puthash item (easy-menu-convert-item-1 item) 253 (puthash item (easy-menu-convert-item-1 item)
253 easy-menu-converted-items-table))) 254 easy-menu-converted-items-table)))
254 255
255 (defun easy-menu-convert-item-1 (item) 256 (defun easy-menu-convert-item-1 (item)
256 ;; Parse an item description and add the item to a keymap. This is 257 "Parse an item description and add the item to a keymap.
257 ;; the function that is used for item definition by the other easy-menu 258 This is the function that is used for item definition by the other easy-menu
258 ;; functions. 259 functions.
259 ;; MENU is a sparse keymap i.e. a list starting with the symbol `keymap'. 260 MENU is a sparse keymap i.e. a list starting with the symbol `keymap'.
260 ;; ITEM defines an item as in `easy-menu-define'. 261 ITEM defines an item as in `easy-menu-define'.
261 ;; Optional argument BEFORE is nil or a key in MENU. If BEFORE is not nil 262 Optional argument BEFORE is nil or a key in MENU. If BEFORE is not nil
262 ;; put item before BEFORE in MENU, otherwise if item is already present in 263 put item before BEFORE in MENU, otherwise if item is already present in
263 ;; MENU, just change it, otherwise put it last in MENU. 264 MENU, just change it, otherwise put it last in MENU."
264 (let (name command label prop remove help) 265 (let (name command label prop remove help)
265 (cond 266 (cond
266 ((stringp item) ; An item or separator. 267 ((stringp item) ; An item or separator.
267 (setq label item)) 268 (setq label item))
268 ((consp item) ; A sub-menu 269 ((consp item) ; A sub-menu
355 (cons label 356 (cons label
356 (and name 357 (and name
357 (cons command prop)))))))) 358 (cons command prop))))))))
358 359
359 (defun easy-menu-define-key-intern (menu key item &optional before) 360 (defun easy-menu-define-key-intern (menu key item &optional before)
360 ;; This is the same as easy-menu-define-key, but it interns KEY and 361 "Like easy-menu-define-key, but interns KEY and BEFORE if they are strings."
361 ;; BEFORE if they are strings.
362 (easy-menu-define-key menu (if (stringp key) (intern key) key) item 362 (easy-menu-define-key menu (if (stringp key) (intern key) key) item
363 (if (stringp before) (intern before) before))) 363 (if (stringp before) (intern before) before)))
364 364
365 (defun easy-menu-define-key (menu key item &optional before) 365 (defun easy-menu-define-key (menu key item &optional before)
366 ;; Add binding in MENU for KEY => ITEM. Similar to `define-key-after'. 366 "Add binding in MENU for KEY => ITEM. Similar to `define-key-after'.
367 ;; If KEY is not nil then delete any duplications. If ITEM is nil, then 367 If KEY is not nil then delete any duplications. If ITEM is nil, then
368 ;; don't insert, only delete. 368 don't insert, only delete.
369 ;; Optional argument BEFORE is nil or a key in MENU. If BEFORE is not nil 369 Optional argument BEFORE is nil or a key in MENU. If BEFORE is not nil
370 ;; put binding before BEFORE in MENU, otherwise if binding is already 370 put binding before BEFORE in MENU, otherwise if binding is already
371 ;; present in MENU, just change it, otherwise put it last in MENU. 371 present in MENU, just change it, otherwise put it last in MENU.
372 ;; KEY and BEFORE don't have to be symbols, comparison is done with equal 372 KEY and BEFORE don't have to be symbols, comparison is done with equal
373 ;; not with eq. 373 not with eq."
374 (let ((inserted (null item)) ; Fake already inserted. 374 (let ((inserted (null item)) ; Fake already inserted.
375 tail done) 375 tail done)
376 (while (not done) 376 (while (not done)
377 (cond 377 (cond
378 ((or (setq done (or (null (cdr menu)) (keymapp (cdr menu)))) 378 ((or (setq done (or (null (cdr menu)) (keymapp (cdr menu))))
397 (setq inserted t) 397 (setq inserted t)
398 (setq menu (cdr menu)))) 398 (setq menu (cdr menu))))
399 (t (setq menu (cdr menu))))))) 399 (t (setq menu (cdr menu)))))))
400 400
401 (defun easy-menu-always-true (x) 401 (defun easy-menu-always-true (x)
402 ;; Return true if X never evaluates to nil. 402 "Return true if X never evaluates to nil."
403 (if (consp x) (and (eq (car x) 'quote) (cadr x)) 403 (if (consp x) (and (eq (car x) 'quote) (cadr x))
404 (or (eq x t) (not (symbolp x))))) 404 (or (eq x t) (not (symbolp x)))))
405 405
406 (defvar easy-menu-item-count 0) 406 (defvar easy-menu-item-count 0)
407 407
436 ;; XEmacs needs the following two functions to add and remove menus. 436 ;; XEmacs needs the following two functions to add and remove menus.
437 ;; In Emacs this is done automatically when switching keymaps, so 437 ;; In Emacs this is done automatically when switching keymaps, so
438 ;; here easy-menu-remove is a noop and easy-menu-add only precalculates 438 ;; here easy-menu-remove is a noop and easy-menu-add only precalculates
439 ;; equivalent keybindings (if easy-menu-precalculate-equivalent-keybindings 439 ;; equivalent keybindings (if easy-menu-precalculate-equivalent-keybindings
440 ;; is on). 440 ;; is on).
441 (defun easy-menu-remove (menu)) 441 (defalias 'easy-menu-remove 'ignore)
442 442
443 (defun easy-menu-add (menu &optional map) 443 (defun easy-menu-add (menu &optional map)
444 "Maybe precalculate equivalent key bindings. 444 "Maybe precalculate equivalent key bindings.
445 Do it if `easy-menu-precalculate-equivalent-keybindings' is on," 445 Do it if `easy-menu-precalculate-equivalent-keybindings' is on,"
446 (when easy-menu-precalculate-equivalent-keybindings 446 (when easy-menu-precalculate-equivalent-keybindings
503 (let ((ret (easy-menu-return-item map name))) 503 (let ((ret (easy-menu-return-item map name)))
504 (if ret (easy-menu-define-key-intern map name nil)) 504 (if ret (easy-menu-define-key-intern map name nil))
505 ret)) 505 ret))
506 506
507 (defun easy-menu-return-item (menu name) 507 (defun easy-menu-return-item (menu name)
508 ;; In menu MENU try to look for menu item with name NAME. 508 "In menu MENU try to look for menu item with name NAME.
509 ;; If a menu item is found, return (NAME . item), otherwise return nil. 509 If a menu item is found, return (NAME . item), otherwise return nil.
510 ;; If item is an old format item, a new format item is returned. 510 If item is an old format item, a new format item is returned."
511 (let ((item (lookup-key menu (vector (intern name)))) 511 (let ((item (lookup-key menu (vector (intern name))))
512 ret enable cache label) 512 ret enable cache label)
513 (cond 513 (cond
514 ((or (keymapp item) (eq (car-safe item) 'menu-item)) 514 ((or (keymapp item) (eq (car-safe item) 'menu-item))
515 (cons name item)) ; Keymap or new menu format 515 (cons name item)) ; Keymap or new menu format
533 (equal (car-safe (cdr-safe (cdr-safe (car submap)))) name)))) 533 (equal (car-safe (cdr-safe (cdr-safe (car submap)))) name))))
534 (setq submap (cdr submap))) 534 (setq submap (cdr submap)))
535 submap) 535 submap)
536 536
537 (defun easy-menu-get-map (map path &optional to-modify) 537 (defun easy-menu-get-map (map path &optional to-modify)
538 ;; Return a sparse keymap in which to add or remove an item. 538 "Return a sparse keymap in which to add or remove an item.
539 ;; MAP and PATH are as defined in `easy-menu-add-item'. 539 MAP and PATH are as defined in `easy-menu-add-item'.
540 540
541 ;; TO-MODIFY, if non-nil, is the name of the item the caller 541 TO-MODIFY, if non-nil, is the name of the item the caller
542 ;; wants to modify in the map that we return. 542 wants to modify in the map that we return.
543 ;; In some cases we use that to select between the local and global maps. 543 In some cases we use that to select between the local and global maps."
544 (if (null map) 544 (if (null map)
545 (let ((local (and (current-local-map) 545 (let ((local (and (current-local-map)
546 (lookup-key (current-local-map) 546 (lookup-key (current-local-map)
547 (vconcat '(menu-bar) (mapcar 'intern path))))) 547 (vconcat '(menu-bar) (mapcar 'intern path)))))
548 (global (lookup-key global-map 548 (global (lookup-key global-map